u-blox / battery-charger-bq24295

Dependents:   example-battery-charger-bq24295 example-C030-out-of-box-demo example-C030-out-of-box-demo Amit

Revision:
3:340d65a1a133
Parent:
1:ed57b6ca43ab
Child:
5:bb17656c9b9d
diff -r f0bbe0269d67 -r 340d65a1a133 TESTS/unit_tests/default/main.cpp
--- a/TESTS/unit_tests/default/main.cpp	Tue Apr 11 09:56:38 2017 +0000
+++ b/TESTS/unit_tests/default/main.cpp	Tue Jun 06 12:59:11 2017 +0100
@@ -817,6 +817,50 @@
     TEST_ASSERT(pBatteryCharger->setChipThermalRegulationThreshold(originalTemperature));    
 }
 
+// Test that we can kick and set the watchdog
+void test_watchdog() {
+    BatteryChargerBq24295 * pBatteryCharger = new BatteryChargerBq24295();
+    int32_t initValue;
+    int32_t getValue = 0;
+    
+    // Call should fail if the battery charger has not been initialised
+    TEST_ASSERT_FALSE(pBatteryCharger->feedWatchdog());
+    TEST_ASSERT_FALSE(pBatteryCharger->getWatchdog(&getValue));
+    TEST_ASSERT_FALSE(pBatteryCharger->setWatchdog(0));
+    
+    // Initialise the battery charger
+    TEST_ASSERT(pBatteryCharger->init(gpI2C));
+    
+    // Save the initial value
+    TEST_ASSERT(pBatteryCharger->getWatchdog(&initValue));
+
+    // Check that we can feed the watchdog
+    TEST_ASSERT(pBatteryCharger->feedWatchdog());
+    
+    // Check that we can set all the watchdog values
+    TEST_ASSERT(pBatteryCharger->setWatchdog(81));
+    TEST_ASSERT(pBatteryCharger->getWatchdog(&getValue));
+    TEST_ASSERT_EQUAL_INT32(160, getValue);
+    TEST_ASSERT(pBatteryCharger->setWatchdog(80));
+    TEST_ASSERT(pBatteryCharger->getWatchdog(&getValue));
+    TEST_ASSERT_EQUAL_INT32(80, getValue);
+    TEST_ASSERT(pBatteryCharger->setWatchdog(41));
+    TEST_ASSERT(pBatteryCharger->getWatchdog(&getValue));
+    TEST_ASSERT_EQUAL_INT32(80, getValue);
+    TEST_ASSERT(pBatteryCharger->setWatchdog(40));
+    TEST_ASSERT(pBatteryCharger->getWatchdog(&getValue));
+    TEST_ASSERT_EQUAL_INT32(40, getValue);
+    TEST_ASSERT(pBatteryCharger->setWatchdog(1));
+    TEST_ASSERT(pBatteryCharger->getWatchdog(&getValue));
+    TEST_ASSERT_EQUAL_INT32(40, getValue);
+    TEST_ASSERT(pBatteryCharger->setWatchdog(0));
+    TEST_ASSERT(pBatteryCharger->getWatchdog(&getValue));
+    TEST_ASSERT_EQUAL_INT32(0, getValue);
+
+    // Put the initial value back when we're done
+    TEST_ASSERT (pBatteryCharger->setWatchdog(initValue));
+}
+
 // Test that we can enable and disable shipping mode
 void test_shipping_mode() {
     BatteryChargerBq24295 * pBatteryCharger = new BatteryChargerBq24295();
@@ -919,6 +963,7 @@
     Case("Fast charging safety timer", test_fast_charging_safety_timer),
     Case("Boost limits", test_boost_limits),
     Case("Chip thermal regulation threshold", test_chip_thermal_regulation_threshold),
+    Case("Watchdog", test_watchdog),
     Case("Shipping mode", test_shipping_mode),
     Case("Advanced", test_advanced)
 };