From e0d1b3299edde62797fe6fa08be3740f24c7d38e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 26 May 2012 14:35:22 -0500 Subject: add coverage for various charging/discharging/charged states --- tests/test-indicator.cc | 104 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 3 deletions(-) diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index 4b39579..ad619e2 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -110,7 +110,6 @@ TEST_F(IndicatorTest, DischargingStrings) INDICATOR_POWER_DEVICE_TIME, guint64(60*60), NULL); indicator_power_set_devices (power, &battery_device, 1); - GList * entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); ASSERT_EQ (g_list_length(entries), 1); IndicatorObjectEntry * entry = static_cast(entries->data); @@ -118,16 +117,115 @@ TEST_F(IndicatorTest, DischargingStrings) ASSERT_STREQ(entry->name_hint, "indicator-power"); g_list_free (entries); + // give the indicator a discharging battery with 2 hours of life left + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0, + INDICATOR_POWER_DEVICE_TIME, guint64(60*60*2), + NULL); + indicator_power_set_devices (power, &battery_device, 1); + entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + entry = static_cast(entries->data); + ASSERT_STREQ (entry->accessible_desc, "Battery (2 hours left (100%))"); + g_list_free (entries); + // give the indicator a discharging battery with over 12 hours of life left g_object_set (battery_device, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, - INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, INDICATOR_POWER_DEVICE_TIME, guint64(60*60*12 + 1), NULL); indicator_power_set_devices (power, &battery_device, 1); entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); ASSERT_EQ (g_list_length(entries), 1); entry = static_cast(entries->data); + ASSERT_STREQ (entry->accessible_desc, "Battery"); + g_list_free (entries); + + // give the indicator a discharging battery with 29 seconds left + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_TIME, guint64(29), + NULL); + indicator_power_set_devices (power, &battery_device, 1); + entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + entry = static_cast(entries->data); + ASSERT_STREQ (entry->accessible_desc, "Battery (Unknown time left (100%))"); + g_list_free (entries); + + // what happens if the time estimate isn't available + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + NULL); + indicator_power_set_devices (power, &battery_device, 1); + entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + entry = static_cast(entries->data); + ASSERT_STREQ (entry->accessible_desc, "Battery (50%)"); + g_list_free (entries); + + // what happens if the time estimate AND percentage isn't available + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, + NULL); + indicator_power_set_devices (power, &battery_device, 1); + entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + entry = static_cast(entries->data); + ASSERT_STREQ (entry->accessible_desc, "Battery (not present)"); + g_list_free (entries); + + // cleanup + g_object_unref (power); +} + +TEST_F(IndicatorTest, ChargingStrings) +{ + IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + + // give the indicator a discharging battery with 1 hour of life left + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, guint64(60*60), + NULL); + indicator_power_set_devices (power, &battery_device, 1); + GList * entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + IndicatorObjectEntry * entry = static_cast(entries->data); + ASSERT_STREQ(entry->accessible_desc, "Battery (1 hour to charge (50%))"); + g_list_free (entries); + + // give the indicator a discharging battery with 2 hours of life left + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_TIME, guint64(60*60*2), + NULL); + indicator_power_set_devices (power, &battery_device, 1); + entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + entry = static_cast(entries->data); + ASSERT_STREQ (entry->accessible_desc, "Battery (2 hours to charge (50%))"); + g_list_free (entries); + + // cleanup + g_object_unref (power); +} + +TEST_F(IndicatorTest, ChargedStrings) +{ + IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + + // give the indicator a discharging battery with 1 hour of life left + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED, + INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + NULL); + indicator_power_set_devices (power, &battery_device, 1); + GList * entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + IndicatorObjectEntry * entry = static_cast(entries->data); + ASSERT_STREQ(entry->accessible_desc, "Battery (charged)"); g_list_free (entries); // cleanup -- cgit v1.2.3