aboutsummaryrefslogtreecommitdiff
path: root/tests/test-device.cc
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-03-25 14:48:57 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-03-25 14:48:57 -0500
commit8fcb63c1e8fed2988f811c3352efa0077c950162 (patch)
treeb821822f4100b53b803261722aa4aa4716e2ba3b /tests/test-device.cc
parent9b33101ad8a9fc093e226c25e497fd8b1d51aee5 (diff)
parent6b9e3d4fb5e11d5d09bc376aa2a56db6a02b55ee (diff)
downloadayatana-indicator-power-8fcb63c1e8fed2988f811c3352efa0077c950162.tar.gz
ayatana-indicator-power-8fcb63c1e8fed2988f811c3352efa0077c950162.tar.bz2
ayatana-indicator-power-8fcb63c1e8fed2988f811c3352efa0077c950162.zip
sync to lp:indicator-power
Diffstat (limited to 'tests/test-device.cc')
-rw-r--r--tests/test-device.cc57
1 files changed, 36 insertions, 21 deletions
diff --git a/tests/test-device.cc b/tests/test-device.cc
index 010dd92..96bea80 100644
--- a/tests/test-device.cc
+++ b/tests/test-device.cc
@@ -73,11 +73,9 @@ class DeviceTest : public ::testing::Test
void check_label (const IndicatorPowerDevice * device,
const char * expected_label)
{
- char label[128];
- indicator_power_device_get_readable_text (device, label, sizeof(label));
- if (expected_label == nullptr)
- expected_label = "";
+ char * label = indicator_power_device_get_readable_text (device);
EXPECT_STREQ (expected_label, label);
+ g_free (label);
}
void check_header (const IndicatorPowerDevice * device,
@@ -86,23 +84,40 @@ class DeviceTest : public ::testing::Test
const char * expected_percent,
const char * expected_a11y)
{
- char a11y[128];
- char title[128];
+ char * a11y = NULL;
+ char * title = NULL;
- indicator_power_device_get_readable_title (device, title, sizeof(title), true, true);
- EXPECT_STREQ (expected_time_and_percent ? expected_time_and_percent : "", title);
+ title = indicator_power_device_get_readable_title (device, true, true);
+ if (expected_time_and_percent)
+ EXPECT_STREQ (expected_time_and_percent, title);
+ else
+ EXPECT_EQ(NULL, title);
+ g_free (title);
- indicator_power_device_get_readable_title (device, title, sizeof(title), true, false);
- EXPECT_STREQ (expected_time ? expected_time : "", title);
+ title = indicator_power_device_get_readable_title (device, true, false);
+ if (expected_time)
+ EXPECT_STREQ (expected_time, title);
+ else
+ EXPECT_EQ(NULL, title);
+ g_free (title);
- indicator_power_device_get_readable_title (device, title, sizeof(title), false, true);
- EXPECT_STREQ (expected_percent ? expected_percent : "", title);
+ title = indicator_power_device_get_readable_title (device, false, true);
+ if (expected_percent)
+ EXPECT_STREQ (expected_percent, title);
+ else
+ EXPECT_EQ(NULL, title);
+ g_free (title);
- indicator_power_device_get_readable_title (device, title, sizeof(title), false, false);
- EXPECT_STREQ ("", title);
+ title = indicator_power_device_get_readable_title (device, false, false);
+ EXPECT_EQ(NULL, title);
+ g_free (title);
- indicator_power_device_get_accessible_title (device, a11y, sizeof(a11y), false, false);
- EXPECT_STREQ (expected_a11y ? expected_a11y : "", a11y);
+ a11y = indicator_power_device_get_accessible_title (device, false, false);
+ if (expected_a11y)
+ EXPECT_STREQ (expected_a11y, a11y);
+ else
+ EXPECT_EQ(NULL, a11y);
+ g_free (a11y);
}
};
@@ -525,7 +540,7 @@ TEST_F(DeviceTest, Labels)
NULL);
check_label (device, "Battery");
check_header (device, "(50%)",
- "",
+ NULL,
"(50%)",
"Battery");
@@ -537,7 +552,7 @@ TEST_F(DeviceTest, Labels)
NULL);
check_label (device, "Battery (charged)");
check_header (device, "(100%)",
- "",
+ NULL,
"(100%)",
"Battery (charged)");
@@ -560,7 +575,7 @@ TEST_F(DeviceTest, Labels)
INDICATOR_POWER_DEVICE_TIME, guint64(0),
NULL);
check_label (device, "Battery");
- check_header (device, "", "", "", "Battery");
+ check_header (device, NULL, NULL, NULL, "Battery");
// power line
g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_LINE_POWER,
@@ -569,7 +584,7 @@ TEST_F(DeviceTest, Labels)
INDICATOR_POWER_DEVICE_TIME, guint64(0),
NULL);
check_label (device, "AC Adapter");
- check_header (device, "", "", "", "AC Adapter");
+ check_header (device, NULL, NULL, NULL, "AC Adapter");
// cleanup
g_object_unref(o);
@@ -635,7 +650,7 @@ TEST_F(DeviceTest, Inestimable___this_takes_80_seconds)
{
check_label (device, "Battery");
check_header (device, "(50%)",
- "",
+ NULL,
"(50%)",
"Battery");
}