aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2017-05-15 15:01:23 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2017-05-15 15:01:50 +0200
commitbd1a508aeb9e498dd782678da420d5baf639b4c0 (patch)
tree1b76d4f9435d12a34ab7241535bd673b082cc03f /tests
parentdbfed3a9b70091667233b884d5a7fa3098f4d104 (diff)
downloadayatana-indicator-power-bd1a508aeb9e498dd782678da420d5baf639b4c0.tar.gz
ayatana-indicator-power-bd1a508aeb9e498dd782678da420d5baf639b4c0.tar.bz2
ayatana-indicator-power-bd1a508aeb9e498dd782678da420d5baf639b4c0.zip
Make device with power supply has higher sorting priority. (LP: #1100546)
Diffstat (limited to 'tests')
-rw-r--r--tests/test-device.cc100
-rw-r--r--tests/test-notify.cc9
2 files changed, 59 insertions, 50 deletions
diff --git a/tests/test-device.cc b/tests/test-device.cc
index 12f89eb..bbe4f31 100644
--- a/tests/test-device.cc
+++ b/tests/test-device.cc
@@ -205,7 +205,8 @@ TEST_F(DeviceTest, New)
UP_DEVICE_KIND_BATTERY,
50.0,
UP_DEVICE_STATE_CHARGING,
- 30);
+ 30,
+ TRUE);
ASSERT_TRUE (device != NULL);
ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));
ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device));
@@ -213,6 +214,7 @@ TEST_F(DeviceTest, New)
ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
ASSERT_EQ (30, indicator_power_device_get_time(device));
+ ASSERT_TRUE (indicator_power_device_get_power_supply(device));
// cleanup
g_object_unref (device);
@@ -220,13 +222,14 @@ TEST_F(DeviceTest, New)
TEST_F(DeviceTest, NewFromVariant)
{
- auto variant = g_variant_new("(susdut)",
+ auto variant = g_variant_new("(susdutb)",
"/object/path",
guint32(UP_DEVICE_KIND_BATTERY),
"icon",
50.0,
guint32(UP_DEVICE_STATE_CHARGING),
- guint64(30));
+ guint64(30),
+ TRUE);
IndicatorPowerDevice * device = indicator_power_device_new_from_variant (variant);
ASSERT_TRUE (variant != NULL);
ASSERT_TRUE (device != NULL);
@@ -236,6 +239,7 @@ TEST_F(DeviceTest, NewFromVariant)
ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
ASSERT_EQ (30, indicator_power_device_get_time(device));
+ ASSERT_TRUE (indicator_power_device_get_power_supply(device));
// cleanup
g_object_unref (device);
@@ -810,7 +814,8 @@ namespace
<< ' ' << state2str(indicator_power_device_get_state(device))
<< ' ' << indicator_power_device_get_time(device)<<'m'
<< ' ' << int(ceil(indicator_power_device_get_percentage(device)))<<'%'
- << ' ' << (path ? path : "nopath");
+ << ' ' << (path ? path : "nopath")
+ << ' ' << (indicator_power_device_get_power_supply(device) ? "1" : "0");
return o.str();
}
@@ -818,13 +823,14 @@ namespace
IndicatorPowerDevice* str2device(const std::string& str)
{
auto tokens = g_strsplit(str.c_str(), " ", 0);
- g_assert(5u == g_strv_length(tokens));
+ g_assert(6u == g_strv_length(tokens));
const auto kind = str2kind(tokens[0]);
const auto state = str2state(tokens[1]);
const time_t time = atoi(tokens[2]);
const double pct = strtod(tokens[3],nullptr);
const char* path = !g_strcmp0(tokens[4],"nopath") ? nullptr : tokens[4];
- auto ret = indicator_power_device_new(path, kind, pct, state, time);
+ const gboolean power_supply = atoi(tokens[5]);
+ auto ret = indicator_power_device_new(path, kind, pct, state, time, power_supply);
g_strfreev(tokens);
return ret;
}
@@ -847,100 +853,100 @@ TEST_F(DeviceTest, ChoosePrimary)
} tests[] = {
{
"one discharging battery",
- "battery discharging 10m 60% bat01",
- { "battery discharging 10m 60% bat01" }
+ "battery discharging 10m 60% bat01 1",
+ { "battery discharging 10m 60% bat01 1" }
},
{
"merge two discharging batteries",
- "battery discharging 20m 70% nopath",
- { "battery discharging 10m 60% bat01", "battery discharging 20m 80% bat02" }
+ "battery discharging 20m 70% nopath 1",
+ { "battery discharging 10m 60% bat01 1", "battery discharging 20m 80% bat02 1" }
},
{
"merge two other discharging batteries",
- "battery discharging 30m 90% nopath",
- { "battery discharging 20m 80% bat01", "battery discharging 30m 100% bat02" }
+ "battery discharging 30m 90% nopath 1",
+ { "battery discharging 20m 80% bat01 1", "battery discharging 30m 100% bat02 1" }
},
{
"merge three discharging batteries",
- "battery discharging 30m 80% nopath",
- { "battery discharging 10m 60% bat01", "battery discharging 20m 80% bat02", "battery discharging 30m 100% bat03" }
+ "battery discharging 30m 80% nopath 1",
+ { "battery discharging 10m 60% bat01 1", "battery discharging 20m 80% bat02 1", "battery discharging 30m 100% bat03 1" }
},
{
"one charging battery",
- "battery charging 10m 60% bat01",
- { "battery charging 10m 60% bat01" }
+ "battery charging 10m 60% bat01 1",
+ { "battery charging 10m 60% bat01 1" }
},
{
"merge two charging batteries",
- "battery charging 20m 70% nopath",
- { "battery charging 10m 60% bat01", "battery charging 20m 80% bat02" }
+ "battery charging 20m 70% nopath 1",
+ { "battery charging 10m 60% bat01 1", "battery charging 20m 80% bat02 1" }
},
{
"merge two other charging batteries",
- "battery charging 30m 90% nopath",
- { "battery charging 20m 80% bat01", "battery charging 30m 100% bat02" }
+ "battery charging 30m 90% nopath 1",
+ { "battery charging 20m 80% bat01 1", "battery charging 30m 100% bat02 1" }
},
{
"merge three charging batteries",
- "battery charging 30m 80% nopath",
- { "battery charging 10m 60% bat01", "battery charging 20m 80% bat02", "battery charging 30m 100% bat03" }
+ "battery charging 30m 80% nopath 1",
+ { "battery charging 10m 60% bat01 1", "battery charging 20m 80% bat02 1", "battery charging 30m 100% bat03 1" }
},
{
"one charged battery",
- "battery charged 0m 100% bat01",
- { "battery charged 0m 100% bat01" }
+ "battery charged 0m 100% bat01 1",
+ { "battery charged 0m 100% bat01 1" }
},
{
"merge one charged, one discharging",
- "battery discharging 10m 80% nopath",
- { "battery charged 0m 100% bat01", "battery discharging 10m 60% bat02" }
+ "battery discharging 10m 80% nopath 1",
+ { "battery charged 0m 100% bat01 1", "battery discharging 10m 60% bat02 1" }
},
{
"merged one charged, one charging",
- "battery charging 10m 80% nopath",
- { "battery charged 0m 100% bat01", "battery charging 10m 60% bat02" }
+ "battery charging 10m 80% nopath 1",
+ { "battery charged 0m 100% bat01 1", "battery charging 10m 60% bat02 1" }
},
{
"merged one charged, one charging, one discharging",
- "battery discharging 10m 74% nopath",
- { "battery charged 0m 100% bat01", "battery charging 10m 60% bat02", "battery discharging 10m 60% bat03" }
+ "battery discharging 10m 74% nopath 1",
+ { "battery charged 0m 100% bat01 1", "battery charging 10m 60% bat02 1", "battery discharging 10m 60% bat03 1" }
},
{
- "one discharging mouse and one discharging battery. pick the one with the least time left",
- "battery discharging 10m 60% bat01",
- { "battery discharging 10m 60% bat01", "mouse discharging 20m 80% mouse01" }
+ "one discharging mouse and one discharging battery. ignore mouse because it doesn't supply the power",
+ "battery discharging 10m 60% bat01 1",
+ { "battery discharging 10m 60% bat01 1", "mouse discharging 20m 80% mouse01 0" }
},
{
- "one discharging mouse and a different discharging battery. pick the one with the least time left",
- "mouse discharging 20m 80% mouse01",
- { "battery discharging 30m 100% bat01", "mouse discharging 20m 80% mouse01" }
+ "one discharging mouse and a different discharging battery. ignore mouse because it doesn't supply the power",
+ "battery discharging 30m 100% bat01 1",
+ { "battery discharging 30m 100% bat01 1", "mouse discharging 20m 80% mouse01 0" }
},
{
"everything comes before power lines #1",
- "battery discharging 10m 60% bat01",
- { "battery discharging 10m 60% bat01", "line-power unknown 0m 0% lp01" }
+ "battery discharging 10m 60% bat01 1",
+ { "battery discharging 10m 60% bat01 1", "line-power unknown 0m 0% lp01 1" }
},
{
"everything comes before power lines #2",
- "battery charging 10m 60% bat01",
- { "battery charging 10m 60% bat01", "line-power unknown 0m 0% lp01" }
+ "battery charging 10m 60% bat01 1",
+ { "battery charging 10m 60% bat01 1", "line-power unknown 0m 0% lp01 1" }
},
{
- "everything comes before power lines #2",
- "mouse discharging 20m 80% mouse01",
- { "mouse discharging 20m 80% mouse01", "line-power unknown 0m 0% lp01" }
+ "everything comes before power lines #3 except that the mouse doesn't supply the power",
+ "line-power unknown 0m 0% lp01 1",
+ { "mouse discharging 20m 80% mouse01 0", "line-power unknown 0m 0% lp01 1" }
},
{
// https://bugs.launchpad.net/ubuntu/+source/indicator-power/+bug/1470080/comments/10
"don't select a device with unknown state when we have another device with a known state...",
- "battery charged 0m 100% bat01",
- { "battery charged 0m 100% bat01", "phone unknown 0m 61% phone01" }
+ "battery charged 0m 100% bat01 1",
+ { "battery charged 0m 100% bat01 1", "phone unknown 0m 61% phone01 1" }
},
{
// https://bugs.launchpad.net/ubuntu/+source/indicator-power/+bug/1470080/comments/10
"...but do select the unknown state device if nothing else is available",
- "phone unknown 0m 61% phone01",
- { "phone unknown 0m 61% phone01" }
+ "phone unknown 0m 61% phone01 1",
+ { "phone unknown 0m 61% phone01 1" }
}
};
diff --git a/tests/test-notify.cc b/tests/test-notify.cc
index acab34f..f8a5517 100644
--- a/tests/test-notify.cc
+++ b/tests/test-notify.cc
@@ -191,7 +191,8 @@ TEST_F(NotifyFixture, PercentageToLevel)
UP_DEVICE_KIND_BATTERY,
50.0,
UP_DEVICE_STATE_DISCHARGING,
- 30);
+ 30,
+ TRUE);
// confirm that the power levels trigger at the right percentages
for (int i=100; i>=0; --i)
@@ -269,7 +270,8 @@ TEST_F(NotifyFixture, LevelsDuringBatteryDrain)
UP_DEVICE_KIND_BATTERY,
50.0,
UP_DEVICE_STATE_DISCHARGING,
- 30);
+ 30,
+ TRUE);
// set up a notifier and give it the battery so changing the battery's
// charge should show up on the bus.
@@ -341,7 +343,8 @@ TEST_F(NotifyFixture, EventsThatChangeNotifications)
UP_DEVICE_KIND_BATTERY,
percent_low + 1.0,
UP_DEVICE_STATE_DISCHARGING,
- 30);
+ 30,
+ TRUE);
// set up a notifier and give it the battery so changing the battery's
// charge should show up on the bus.