From bd1a508aeb9e498dd782678da420d5baf639b4c0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 15 May 2017 15:01:23 +0200 Subject: Make device with power supply has higher sorting priority. (LP: #1100546) --- tests/test-device.cc | 100 +++++++++++++++++++++++++++------------------------ tests/test-notify.cc | 9 +++-- 2 files changed, 59 insertions(+), 50 deletions(-) (limited to 'tests') 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. -- cgit v1.2.3