From e555496b6486982a75429af159c6ecd556944ff6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 6 Nov 2012 13:42:53 -0600 Subject: add unit test (currently failing) to test for the bug reported in LP bug #1075192 --- tests/test-device.cc | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/test-device.cc b/tests/test-device.cc index 18bdc08..16194c9 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -587,19 +587,21 @@ TEST_F(DeviceTest, ChoosePrimary) sorted in order of preference wrt the spec's criteria. So tests[i] should be picked over any test with an index greater than i */ struct { + int kind; int state; guint64 time; double percentage; } tests[] = { - { UP_DEVICE_STATE_DISCHARGING, 49, 50.0 }, - { UP_DEVICE_STATE_DISCHARGING, 50, 50.0 }, - { UP_DEVICE_STATE_DISCHARGING, 50, 100.0 }, - { UP_DEVICE_STATE_DISCHARGING, 51, 50.0 }, - { UP_DEVICE_STATE_CHARGING, 50, 50.0 }, - { UP_DEVICE_STATE_CHARGING, 49, 50.0 }, - { UP_DEVICE_STATE_CHARGING, 49, 100.0 }, - { UP_DEVICE_STATE_CHARGING, 48, 50.0 }, - { UP_DEVICE_STATE_FULLY_CHARGED, 0, 50.0 } + { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 49, 50.0 }, + { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 50, 50.0 }, + { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 50, 100.0 }, + { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 51, 50.0 }, + { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 50, 50.0 }, + { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 49, 50.0 }, + { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 49, 100.0 }, + { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 48, 50.0 }, + { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_FULLY_CHARGED, 0, 50.0 }, + { UP_DEVICE_KIND_LINE_POWER, UP_DEVICE_STATE_UNKNOWN, 0, 0.0 } }; device_list = NULL; @@ -610,11 +612,13 @@ TEST_F(DeviceTest, ChoosePrimary) { for (int j=i+1; j Date: Tue, 6 Nov 2012 13:59:36 -0600 Subject: when choosing between two devices, always pick the one that's not a UP_DEVICE_KIND_LINE_POWER --- src/indicator-power.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 4118dcc..888e186 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -357,7 +357,8 @@ build_menu (IndicatorPower *self) 2. discharging items with an unknown time remaining 3. charging items from most time left to charge to least time left to charge 4. charging items with an unknown time remaining - 5. everything else */ + 5. everything except line-power, because it's not interesting + 6. line-power */ static gint device_compare_func (gconstpointer ga, gconstpointer gb) { @@ -418,6 +419,24 @@ device_compare_func (gconstpointer ga, gconstpointer gb) } } + if (!ret) /* make UP_DEVICE_KIND_LINE_POWER go last because it's not interesting */ + { + const UpDeviceKind a_kind = indicator_power_device_get_kind (a); + const UpDeviceKind b_kind = indicator_power_device_get_kind (b); + + if ((a_kind == UP_DEVICE_KIND_LINE_POWER) || (b_kind == UP_DEVICE_KIND_LINE_POWER)) + { + if (a_kind != UP_DEVICE_KIND_LINE_POWER) /* b is a line-power */ + { + ret = -1; + } + else if (b_kind != UP_DEVICE_KIND_LINE_POWER) /* a is a line-power */ + { + ret = 1; + } + } + } + if (!ret) ret = a_state - b_state; -- cgit v1.2.3 From 7b37016d3e8114cbb19c25121185e799a5fb342f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 6 Nov 2012 14:54:57 -0600 Subject: in TestDevice.ChoosePrimary, add another test (currently failing) to confirm that when indicator-datetime is choosing from devices that are neither charging nor discharging, batteries are more interesting than other devices, and other devices are more interesting than UP_DEVICE_KIND_LINE_POWER --- tests/test-device.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test-device.cc b/tests/test-device.cc index 16194c9..27cbf35 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -601,6 +601,7 @@ TEST_F(DeviceTest, ChoosePrimary) { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 49, 100.0 }, { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 48, 50.0 }, { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_FULLY_CHARGED, 0, 50.0 }, + { UP_DEVICE_KIND_KEYBOARD, UP_DEVICE_STATE_FULLY_CHARGED, 0, 50.0 }, { UP_DEVICE_KIND_LINE_POWER, UP_DEVICE_STATE_UNKNOWN, 0, 0.0 } }; -- cgit v1.2.3 From a2e4245288d1b1d55ed3deab8e76ec3cd2fbb3e5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 6 Nov 2012 14:56:52 -0600 Subject: when choosing a primary device from devices that are neither charging nor discharging, prefer batteries, then everything except line-power, then line power --- src/indicator-power.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 888e186..06f1c2e 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -352,13 +352,38 @@ build_menu (IndicatorPower *self) gtk_widget_show_all (GTK_WIDGET (priv->menu)); } +/* the higher the weight, the more interesting the device */ +static int +get_device_kind_weight (const IndicatorPowerDevice * device) +{ + UpDeviceKind kind; + static gboolean initialized = FALSE; + static int weights[UP_DEVICE_KIND_LAST]; + + kind = indicator_power_device_get_kind (device); + g_return_val_if_fail (0<=kind && kind weight_b) { - if (a_kind != UP_DEVICE_KIND_LINE_POWER) /* b is a line-power */ - { - ret = -1; - } - else if (b_kind != UP_DEVICE_KIND_LINE_POWER) /* a is a line-power */ - { - ret = 1; - } + ret = -1; + } + else if (weight_a < weight_b) + { + ret = 1; } } -- cgit v1.2.3 From a499914c45cf4bf2208c857f54783cfcd48c1427 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 7 Nov 2012 11:25:41 -0600 Subject: modify DeviceTest.Labels s.t. it fails (currently failing) if the 'short' string for an AC Adapter is nonempty. --- tests/test-device.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-device.cc b/tests/test-device.cc index 27cbf35..021404f 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -555,7 +555,7 @@ TEST_F(DeviceTest, Labels) INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, INDICATOR_POWER_DEVICE_TIME, guint64(0), NULL); - check_strings (device, "AC Adapter", "AC Adapter", "AC Adapter"); + check_strings (device, "", "AC Adapter", "AC Adapter"); // cleanup g_object_unref(o); -- cgit v1.2.3 From f446e2fbf12b6210faf76fb78d8020647834fbff Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 7 Nov 2012 11:29:51 -0600 Subject: change indicator_power_device_get_time_details() s.t. the 'short details' for an AC Adapter is an empty string. --- src/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/device.c b/src/device.c index 490ff1a..d028ab7 100644 --- a/src/device.c +++ b/src/device.c @@ -612,7 +612,7 @@ indicator_power_device_get_time_details (const IndicatorPowerDevice * device, { *details = g_strdup (device_name); *accessible_name = g_strdup (device_name); - *short_details = g_strdup (device_name); + *short_details = g_strdup (""); } else { -- cgit v1.2.3