From 46f92bac64882fdec51524252fb0e3afa5fff0ad Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 25 Oct 2012 14:55:48 +0200 Subject: the device kind string wasn't being used in some icon names. --- tests/test-device.cc | 341 +++++++++++++++++++++++++++++---------------------- 1 file changed, 196 insertions(+), 145 deletions(-) (limited to 'tests/test-device.cc') diff --git a/tests/test-device.cc b/tests/test-device.cc index eb087dc..4c6a6f2 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -239,154 +239,205 @@ TEST_F(DeviceTest, IconNames) check_icon_names (device, "gpm-monitor-symbolic;" "gpm-monitor"); - // empty battery - g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_EMPTY, - NULL); - check_icon_names (device, "battery-empty-symbolic;" - "gpm-battery-empty;" - "gpm-battery-000;" - "battery-empty"); - - // charged battery - g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED, - NULL); - check_icon_names (device, "battery-full-charged-symbolic;" - "battery-full-charging-symbolic;" - "gpm-battery-full;" - "gpm-battery-100;" - "battery-full-charged;" - "battery-full-charging"); - - // charging battery, 95% - g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, - INDICATOR_POWER_DEVICE_PERCENTAGE, 95.0, - NULL); - check_icon_names (device, "battery-caution-charging-symbolic;" - "gpm-battery-000-charging;" - "battery-caution-charging"); - - // charging battery, 85% - g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, - INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0, - NULL); - check_icon_names (device, "battery-caution-charging-symbolic;" - "gpm-battery-000-charging;" - "battery-caution-charging"); - - // charging battery, 50% - g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, - INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, - NULL); - check_icon_names (device, "battery-caution-charging-symbolic;" - "gpm-battery-000-charging;" - "battery-caution-charging"); - - // charging battery, 25% - g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, - INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0, - NULL); - check_icon_names (device, "battery-caution-charging-symbolic;" - "gpm-battery-000-charging;" - "battery-caution-charging"); - - // charging battery, 5% - g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, - INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0, - NULL); - check_icon_names (device, "battery-caution-charging-symbolic;" - "gpm-battery-000-charging;" - "battery-caution-charging"); - - - // discharging battery, 95% - g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, - INDICATOR_POWER_DEVICE_PERCENTAGE, 95.0, - NULL); - check_icon_names (device, "battery-100;" - "gpm-battery-100;" - "battery-full-symbolic;" - "battery-full"); - - // discharging battery, 85% - g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, - INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0, - NULL); - check_icon_names (device, "battery-080;" - "gpm-battery-080;" - "battery-full-symbolic;" - "battery-full"); - - // discharging battery, 50% -- 1 hour left - 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), - NULL); - check_icon_names (device, "battery-060;" - "gpm-battery-060;" - "battery-good-symbolic;" - "battery-good"); - - // discharging battery, 25% -- 1 hour left - g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, - INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0, - INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60), - NULL); - check_icon_names (device, "battery-040;" - "gpm-battery-040;" - "battery-good-symbolic;" - "battery-good"); - - // discharging battery, 25% -- 15 minutes left - g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, - INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0, - INDICATOR_POWER_DEVICE_TIME, (guint64)(60*15), - NULL); - check_icon_names (device, "battery-020;" - "gpm-battery-020;" - "battery-low-symbolic;" - "battery-low"); - - // discharging battery, 5% -- 1 hour left - g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, - INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0, - INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60), - NULL); - check_icon_names (device, "battery-040;" - "gpm-battery-040;" - "battery-good-symbolic;" - "battery-good"); + // devices that hold a charge + struct { + int kind; + const gchar * kind_str; + } devices[] = { + { UP_DEVICE_KIND_BATTERY, "battery" }, + { UP_DEVICE_KIND_UPS, "ups" }, + { UP_DEVICE_KIND_MOUSE, "mouse" }, + { UP_DEVICE_KIND_KEYBOARD, "keyboard" }, + { UP_DEVICE_KIND_PHONE, "phone" } + }; + + GString * expected = g_string_new (NULL); + for (int i=0, n=G_N_ELEMENTS(devices); istr); + g_string_truncate (expected, 0); + + // charged + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED, + NULL); + g_string_append_printf (expected, "%s-full-charged-symbolic;", kind_str); + g_string_append_printf (expected, "%s-full-charging-symbolic;", kind_str); + g_string_append_printf (expected, "gpm-%s-full;", kind_str); + g_string_append_printf (expected, "gpm-%s-100;", kind_str); + g_string_append_printf (expected, "%s-full-charged;", kind_str); + g_string_append_printf (expected, "%s-full-charging", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + + // charging, 95% + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 95.0, + NULL); + + g_string_append_printf (expected, "%s-caution-charging-symbolic;", kind_str); + g_string_append_printf (expected, "gpm-%s-000-charging;", kind_str); + g_string_append_printf (expected, "%s-caution-charging", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + + // charging, 85% + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0, + NULL); + g_string_append_printf (expected, "%s-caution-charging-symbolic;", kind_str); + g_string_append_printf (expected, "gpm-%s-000-charging;", kind_str); + g_string_append_printf (expected, "%s-caution-charging", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + + // charging, 50% + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + NULL); + g_string_append_printf (expected, "%s-caution-charging-symbolic;", kind_str); + g_string_append_printf (expected, "gpm-%s-000-charging;", kind_str); + g_string_append_printf (expected, "%s-caution-charging", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + + // charging, 25% + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0, + NULL); + g_string_append_printf (expected, "%s-caution-charging-symbolic;", kind_str); + g_string_append_printf (expected, "gpm-%s-000-charging;", kind_str); + g_string_append_printf (expected, "%s-caution-charging", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + + // charging, 5% + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0, + NULL); + g_string_append_printf (expected, "%s-caution-charging-symbolic;", kind_str); + g_string_append_printf (expected, "gpm-%s-000-charging;", kind_str); + g_string_append_printf (expected, "%s-caution-charging", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + + // discharging, 95% + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 95.0, NULL); - check_icon_names (device, "battery-000;" - "gpm-battery-000;" - "battery-caution-symbolic;" - "battery-caution"); - - // state unknown - g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_UNKNOWN, + g_string_append_printf (expected, "%s-100;", kind_str); + g_string_append_printf (expected, "gpm-%s-100;", kind_str); + g_string_append_printf (expected, "%s-full-symbolic;", kind_str); + g_string_append_printf (expected, "%s-full", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + + // discharging, 85% + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0, + NULL); + g_string_append_printf (expected, "%s-080;", kind_str); + g_string_append_printf (expected, "gpm-%s-080;", kind_str); + g_string_append_printf (expected, "%s-full-symbolic;", kind_str); + g_string_append_printf (expected, "%s-full", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + + // discharging, 50% -- 1 hour left + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60), + NULL); + g_string_append_printf (expected, "%s-060;", kind_str); + g_string_append_printf (expected, "gpm-%s-060;", kind_str); + g_string_append_printf (expected, "%s-good-symbolic;", kind_str); + g_string_append_printf (expected, "%s-good", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + + // discharging, 25% -- 1 hour left + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0, + INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60), + NULL); + g_string_append_printf (expected, "%s-040;", kind_str); + g_string_append_printf (expected, "gpm-%s-040;", kind_str); + g_string_append_printf (expected, "%s-good-symbolic;", kind_str); + g_string_append_printf (expected, "%s-good", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + + // discharging, 25% -- 15 minutes left + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0, + INDICATOR_POWER_DEVICE_TIME, (guint64)(60*15), + NULL); + g_string_append_printf (expected, "%s-020;", kind_str); + g_string_append_printf (expected, "gpm-%s-020;", kind_str); + g_string_append_printf (expected, "%s-low-symbolic;", kind_str); + g_string_append_printf (expected, "%s-low", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + + // discharging, 5% -- 1 hour left + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0, + INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60), NULL); - check_icon_names (device, "battery-missing-symbolic;" - "gpm-battery-missing;" - "battery-missing"); + g_string_append_printf (expected, "%s-040;", kind_str); + g_string_append_printf (expected, "gpm-%s-040;", kind_str); + g_string_append_printf (expected, "%s-good-symbolic;", kind_str); + g_string_append_printf (expected, "%s-good", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + + // discharging, 5% -- 15 minutes left + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0, + INDICATOR_POWER_DEVICE_TIME, (guint64)(60*15), + NULL); + g_string_append_printf (expected, "%s-000;", kind_str); + g_string_append_printf (expected, "gpm-%s-000;", kind_str); + g_string_append_printf (expected, "%s-caution-symbolic;", kind_str); + g_string_append_printf (expected, "%s-caution", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + + // state unknown + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_UNKNOWN, + NULL); + g_string_append_printf (expected, "%s-missing-symbolic;", kind_str); + g_string_append_printf (expected, "gpm-%s-missing;", kind_str); + g_string_append_printf (expected, "%s-missing", kind_str); + check_icon_names (device, expected->str); + g_string_truncate (expected, 0); + } + g_string_free (expected, TRUE); // cleanup g_object_unref(o); -- cgit v1.2.3 From b7b7ffd56c91ae9622ffebfec4ea4400c96d2fce Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 26 Oct 2012 10:02:14 +0200 Subject: Select the primary device based on the spec's criteria. Add tests to confirm. --- tests/test-device.cc | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'tests/test-device.cc') diff --git a/tests/test-device.cc b/tests/test-device.cc index 4c6a6f2..c310a58 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -19,6 +19,7 @@ with this program. If not, see . #include #include "device.h" +#include "indicator-power.h" namespace { @@ -530,3 +531,77 @@ TEST_F(DeviceTest, Labels) g_setenv ("LANG", real_lang, TRUE); g_free (real_lang); } + +static void +set_device_charge_state (IndicatorPowerDevice * device, int state, int time, double pct) +{ + g_object_set (device, INDICATOR_POWER_DEVICE_STATE, state, + INDICATOR_POWER_DEVICE_PERCENTAGE, pct, + INDICATOR_POWER_DEVICE_TIME, guint64(time), + NULL); +} + + +/* The menu title should tell you at a glance what you need to know most: what + device will lose power soonest (and optionally when), or otherwise which + device will take longest to charge (and optionally how long it will take). */ +TEST_F(DeviceTest, ChoosePrimary) +{ + GSList * devices; + IndicatorPowerDevice * a; + IndicatorPowerDevice * b; + + a = indicator_power_device_new ("/org/freedesktop/UPower/devices/mouse", + UP_DEVICE_KIND_MOUSE, + 0.0, + UP_DEVICE_STATE_DISCHARGING, + 0); + b = indicator_power_device_new ("/org/freedesktop/UPower/devices/battery", + UP_DEVICE_KIND_BATTERY, + 0.0, + UP_DEVICE_STATE_DISCHARGING, + 0); + + devices = NULL; + devices = g_slist_append (devices, a); + devices = g_slist_append (devices, b); + + /* Both discharging, same charge %, different times left before empty. + Confirm that the one with less time is chosen. */ + set_device_charge_state (a, UP_DEVICE_STATE_DISCHARGING, 99, 50.0); + set_device_charge_state (b, UP_DEVICE_STATE_DISCHARGING, 100, 50.0); + ASSERT_EQ (a, indicator_power_choose_primary_device(devices)); + + /* Both discharging, different charge % and times left. + Confirm that the one with less time is chosen. */ + set_device_charge_state (a, UP_DEVICE_STATE_DISCHARGING, 99, 50.0); + set_device_charge_state (b, UP_DEVICE_STATE_DISCHARGING, 100, 49.0); + ASSERT_EQ (a, indicator_power_choose_primary_device(devices)); + + /* Both discharging, different charge %, same times left. + Confirm that the one with less charge is chosen. */ + set_device_charge_state (a, UP_DEVICE_STATE_DISCHARGING, 100, 49.0); + set_device_charge_state (b, UP_DEVICE_STATE_DISCHARGING, 100, 50.0); + ASSERT_EQ (a, indicator_power_choose_primary_device(devices)); + + /* Both are charging, have the same charge percentage, and differnt times left (to charge). + * Confirm that the one with the most time left is chosen. */ + set_device_charge_state (a, UP_DEVICE_STATE_CHARGING, 49, 50.0); + set_device_charge_state (b, UP_DEVICE_STATE_CHARGING, 50, 50.0); + ASSERT_EQ (b, indicator_power_choose_primary_device(devices)); + + /* Both are charging, with different charges and time left. + Confirm that the one with the most time left is chosen. */ + set_device_charge_state (a, UP_DEVICE_STATE_CHARGING, 49, 50.0); + set_device_charge_state (b, UP_DEVICE_STATE_CHARGING, 50, 49.0); + ASSERT_EQ (b, indicator_power_choose_primary_device(devices)); + + /* Both are charging, have the same time left, and different charges. + * Confirm that the one with less charge is chosen. */ + set_device_charge_state (a, UP_DEVICE_STATE_CHARGING, 50, 50.0); + set_device_charge_state (b, UP_DEVICE_STATE_CHARGING, 50, 49.0); + ASSERT_EQ (b, indicator_power_choose_primary_device(devices)); + + // cleanup + g_slist_free_full (devices, g_object_unref); +} -- cgit v1.2.3 From a842e7b5cc66311c6cff51f3e07d1c7930b8153a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 26 Oct 2012 10:53:32 +0200 Subject: fix comment typo --- tests/test-device.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test-device.cc') diff --git a/tests/test-device.cc b/tests/test-device.cc index c310a58..88c43fc 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -584,7 +584,7 @@ TEST_F(DeviceTest, ChoosePrimary) set_device_charge_state (b, UP_DEVICE_STATE_DISCHARGING, 100, 50.0); ASSERT_EQ (a, indicator_power_choose_primary_device(devices)); - /* Both are charging, have the same charge percentage, and differnt times left (to charge). + /* Both are charging, have the same charge percentage, and different times left (to charge). * Confirm that the one with the most time left is chosen. */ set_device_charge_state (a, UP_DEVICE_STATE_CHARGING, 49, 50.0); set_device_charge_state (b, UP_DEVICE_STATE_CHARGING, 50, 50.0); -- cgit v1.2.3