aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-08-22 23:51:20 -0500
committerCharles Kerr <charles.kerr@canonical.com>2013-08-22 23:51:20 -0500
commitc15ff1e02ea0a7ae1f68a66a31dc6ce7d8955575 (patch)
tree675a81a2edbcf0c7eca72e0b5887cb9d410404b4 /tests
parent3c2e7c88bd24441d87a52e702e2e1e985f9abcef (diff)
downloadayatana-indicator-power-c15ff1e02ea0a7ae1f68a66a31dc6ce7d8955575.tar.gz
ayatana-indicator-power-c15ff1e02ea0a7ae1f68a66a31dc6ce7d8955575.tar.bz2
ayatana-indicator-power-c15ff1e02ea0a7ae1f68a66a31dc6ce7d8955575.zip
add show-percentage feature, basing off Haw Loeung's patch.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-device.cc112
1 files changed, 79 insertions, 33 deletions
diff --git a/tests/test-device.cc b/tests/test-device.cc
index 987b201..e9a439d 100644
--- a/tests/test-device.cc
+++ b/tests/test-device.cc
@@ -69,26 +69,51 @@ class DeviceTest : public ::testing::Test
g_strfreev (names);
}
- void check_strings (const IndicatorPowerDevice * device,
- const char * expected_timestring,
- const char * expected_details,
- const char * expected_accessible)
+ void check_label (const IndicatorPowerDevice * device,
+ const char * expected_label)
{
- char * timestring = NULL;
- char * details = NULL;
- char * accessible = NULL;
-
- indicator_power_device_get_time_details (device, &timestring, &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);
+ char * label;
+
+ label = indicator_power_device_get_label (device);
+ EXPECT_STREQ (expected_label, label);
+
+ g_free (label);
}
-};
+ void check_header (const IndicatorPowerDevice * device,
+ const char * expected_time_and_percent,
+ const char * expected_time,
+ const char * expected_percent,
+ const char * expected_a11y)
+ {
+ char * label;
+ char * a11y;
+
+ indicator_power_device_get_header (device, true, true, &label, &a11y);
+ EXPECT_STREQ (expected_time_and_percent, label);
+ EXPECT_STREQ (expected_a11y, a11y);
+ g_free (label);
+ g_free (a11y);
+
+ indicator_power_device_get_header (device, true, false, &label, &a11y);
+ EXPECT_STREQ (expected_time, label);
+ EXPECT_STREQ (expected_a11y, a11y);
+ g_free (label);
+ g_free (a11y);
+
+ indicator_power_device_get_header (device, false, true, &label, &a11y);
+ EXPECT_STREQ (expected_percent, label);
+ EXPECT_STREQ (expected_a11y, a11y);
+ g_free (label);
+ g_free (a11y);
+
+ indicator_power_device_get_header (device, false, false, &label, &a11y);
+ ASSERT_TRUE (!label || !*label);
+ EXPECT_STREQ (expected_a11y, a11y);
+ g_free (label);
+ g_free (a11y);
+ }
+};
/***
****
@@ -456,13 +481,15 @@ TEST_F(DeviceTest, Labels)
g_setenv ("LANG", "en_US.UTF-8", TRUE);
// bad args: NULL device
- log_count_ipower_expected++;
- check_strings (NULL, NULL, NULL, NULL);
+ log_count_ipower_expected += 5;
+ check_label (NULL, NULL);
+ check_header (NULL, NULL, NULL, NULL, NULL);
// bad args: a GObject that isn't a device
- log_count_ipower_expected++;
+ log_count_ipower_expected += 5;
GObject * o = G_OBJECT(g_cancellable_new());
- check_strings ((IndicatorPowerDevice*)o, NULL, NULL, NULL);
+ check_label ((IndicatorPowerDevice*)o, NULL);
+ check_header (NULL, NULL, NULL, NULL, NULL);
g_object_unref (o);
/**
@@ -478,9 +505,11 @@ TEST_F(DeviceTest, Labels)
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%))");
+ check_label (device, "Battery (1:01 to charge)");
+ check_header (device, "(1:01, 50%)",
+ "(1:01)",
+ "(50%)",
+ "Battery (1 hour 1 minute to charge, 50%)");
// discharging, < 12 hours left
g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY,
@@ -488,25 +517,36 @@ TEST_F(DeviceTest, Labels)
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%))");
+ check_label (device, "Battery (1:01 left)");
+ check_header (device, "(1:01, 50%)",
+ "(1:01)",
+ "(50%)",
+ "Battery (1 hour 1 minute left, 50%)");
// discharging, > 12 hours left
+ // we don't show the clock time when > 12 hours dischargin
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");
+ check_label (device, "Battery");
+ check_header (device, "(50%)",
+ "",
+ "(50%)",
+ "Battery (50%)");
- // fully charged
+// 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)");
+ check_label (device, "Battery (charged)");
+ check_header (device, "(100%)",
+ "",
+ "(100%)",
+ "Battery (charged, 100%)");
// percentage but no time estimate
g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY,
@@ -514,7 +554,11 @@ TEST_F(DeviceTest, Labels)
INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,
INDICATOR_POWER_DEVICE_TIME, guint64(0),
NULL);
- check_strings (device, "(50%)", "Battery (50%)", "Battery (50%)");
+ check_label (device, "Battery (estimating…)");
+ check_header (device, "(estimating…, 50%)",
+ "(estimating…)",
+ "(50%)",
+ "Battery (estimating…, 50%)");
// no percentage, no time estimate
g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY,
@@ -522,7 +566,8 @@ TEST_F(DeviceTest, Labels)
INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0,
INDICATOR_POWER_DEVICE_TIME, guint64(0),
NULL);
- check_strings (device, "(not present)", "Battery (not present)", "Battery (not present)");
+ check_label (device, "Battery (not present)");
+ check_header (device, "", "", "", "Battery (not present)");
// power line
g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_LINE_POWER,
@@ -530,7 +575,8 @@ TEST_F(DeviceTest, Labels)
INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0,
INDICATOR_POWER_DEVICE_TIME, guint64(0),
NULL);
- check_strings (device, "", "AC Adapter", "AC Adapter");
+ check_label (device, "AC Adapter");
+ check_header (device, "", "", "", "AC Adapter");
// cleanup
g_object_unref(o);