diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2012-06-01 13:21:08 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2012-06-01 13:21:08 -0500 |
commit | ea0293e260480be4ccb796a51c614966a253fdbe (patch) | |
tree | 6dd362ea8a5cf5c0f7898ec7922c1655e8941933 /tests | |
parent | 53d9c7e23ebe4a031af88a71a694643b02598b6e (diff) | |
download | ayatana-indicator-power-ea0293e260480be4ccb796a51c614966a253fdbe.tar.gz ayatana-indicator-power-ea0293e260480be4ccb796a51c614966a253fdbe.tar.bz2 ayatana-indicator-power-ea0293e260480be4ccb796a51c614966a253fdbe.zip |
Add unit tests for indicator_power_device_get_time_details()
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-device.cc | 89 |
1 files changed, 87 insertions, 2 deletions
diff --git a/tests/test-device.cc b/tests/test-device.cc index 0ea7177..3b3ff73 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -57,6 +57,25 @@ class DeviceTest : public ::testing::Test g_free (str); g_strfreev (names); } + + void check_strings (const IndicatorPowerDevice * device, + const char * expected_timestring, + const char * expected_details, + const char * expected_accessible) + { + char * timestring = NULL; + char * details = NULL; + char * accessible = NULL; + + indicator_power_device_get_time_details (device, ×tring, &details, &accessible); + EXPECT_STREQ (expected_timestring, timestring); + EXPECT_STREQ (expected_details, details); + EXPECT_STREQ (expected_accessible, accessible); + + g_free (accessible); + g_free (details); + g_free (timestring); + } }; @@ -346,8 +365,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-caution-symbolic;" "gpm-battery-000;" - "battery-caution;"); - + "battery-caution;"); /* state unknown */ g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_UNKNOWN, @@ -360,3 +378,70 @@ TEST_F(DeviceTest, IconNames) g_object_unref(o); } + +TEST_F(DeviceTest, Labels) +{ + // set our language so that i18n won't break these tests + char * real_lang = g_strdup(g_getenv ("LANG")); + g_setenv ("LANG", "en_US.UTF-8", TRUE); + + IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL)); + GObject * o = G_OBJECT(device); + + /* charging */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, guint64(60*61), + NULL); + check_strings (device, "(1:01)", + "Battery (1:01 to charge)", + "Battery (1 hour 1 minute to charge (50%))"); + + /* discharging, < 12 hours left */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, guint64(60*61), + NULL); + check_strings (device, "1:01", + "Battery (1:01 left)", + "Battery (1 hour 1 minute left (50%))"); + + /* discharging, > 12 hours left */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, guint64(60*60*13), + NULL); + check_strings (device, "13:00", "Battery", "Battery"); + + /* fully charged */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED, + INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + NULL); + check_strings (device, "", "Battery (charged)", "Battery (charged)"); + + /* percentage but no time estimate */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + NULL); + check_strings (device, "(50%)", "Battery (50%)", "Battery (50%)"); + + /* no percentage, no time estimate */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + NULL); + check_strings (device, "(not present)", "Battery (not present)", "Battery (not present)"); + + /* cleanup */ + g_object_unref(o); + g_setenv ("LANG", real_lang, TRUE); + g_free (real_lang); +} |