Merge lp:~charlesk/indicator-power/lp-1100546-not-present-mouse into lp:indicator-power

Proposed by Charles Kerr
Status: Merged
Approved by: Charles Kerr
Approved revision: 302
Merged at revision: 302
Proposed branch: lp:~charlesk/indicator-power/lp-1100546-not-present-mouse
Merge into: lp:indicator-power
Diff against target: 546 lines (+144/-73)
8 files modified
debian/changelog (+6/-0)
src/device-provider-upower.c (+5/-1)
src/device.c (+37/-5)
src/device.h (+4/-1)
src/service.c (+22/-6)
src/testing.c (+2/-1)
tests/test-device.cc (+62/-56)
tests/test-notify.cc (+6/-3)
To merge this branch: bzr merge lp:~charlesk/indicator-power/lp-1100546-not-present-mouse
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Review via email: mp+314869@code.launchpad.net

Commit message

When sorting devices by priority, give preference to devices that power the system.

Description of the change

When sorting devices by priority, give preference to devices that power the system.

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) wrote :

Self-approving as I'm just the code reviewer; Shih-Yuan Lee authored the patch and submitted as a debdiff.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2016-12-01 22:34:02 +0000
+++ debian/changelog 2017-01-16 19:06:20 +0000
@@ -1,3 +1,9 @@
1indicator-power (12.10.6+17.04.20161201-0ubuntu2) zesty; urgency=medium
2
3 * Make device with power supply has higher sorting priority. (LP: #1100546)
4
5 -- Shih-Yuan Lee (FourDollars) <fourdollars@ubuntu.com> Thu, 05 Jan 2017 11:54:01 +0800
6
1indicator-power (12.10.6+17.04.20161201-0ubuntu1) zesty; urgency=medium7indicator-power (12.10.6+17.04.20161201-0ubuntu1) zesty; urgency=medium
28
3 [ Michael Terry ]9 [ Michael Terry ]
410
=== modified file 'src/device-provider-upower.c'
--- src/device-provider-upower.c 2014-09-08 14:50:22 +0000
+++ src/device-provider-upower.c 2017-01-16 19:06:20 +0000
@@ -113,6 +113,7 @@
113 gint64 time_to_empty = 0;113 gint64 time_to_empty = 0;
114 gint64 time_to_full = 0;114 gint64 time_to_full = 0;
115 gint64 time;115 gint64 time;
116 gboolean power_supply = FALSE;
116 IndicatorPowerDevice * device;117 IndicatorPowerDevice * device;
117 priv_t * p = get_priv(data->self);118 priv_t * p = get_priv(data->self);
118 GVariant * dict = g_variant_get_child_value (response, 0);119 GVariant * dict = g_variant_get_child_value (response, 0);
@@ -122,6 +123,7 @@
122 g_variant_lookup (dict, "Percentage", "d", &percentage);123 g_variant_lookup (dict, "Percentage", "d", &percentage);
123 g_variant_lookup (dict, "TimeToEmpty", "x", &time_to_empty);124 g_variant_lookup (dict, "TimeToEmpty", "x", &time_to_empty);
124 g_variant_lookup (dict, "TimeToFull", "x", &time_to_full);125 g_variant_lookup (dict, "TimeToFull", "x", &time_to_full);
126 g_variant_lookup (dict, "PowerSupply", "b", &power_supply);
125 time = time_to_empty ? time_to_empty : time_to_full;127 time = time_to_empty ? time_to_empty : time_to_full;
126128
127 if ((device = g_hash_table_lookup (p->devices, data->path)))129 if ((device = g_hash_table_lookup (p->devices, data->path)))
@@ -131,6 +133,7 @@
131 INDICATOR_POWER_DEVICE_OBJECT_PATH, data->path,133 INDICATOR_POWER_DEVICE_OBJECT_PATH, data->path,
132 INDICATOR_POWER_DEVICE_PERCENTAGE, percentage,134 INDICATOR_POWER_DEVICE_PERCENTAGE, percentage,
133 INDICATOR_POWER_DEVICE_TIME, time,135 INDICATOR_POWER_DEVICE_TIME, time,
136 INDICATOR_POWER_DEVICE_POWER_SUPPLY, power_supply,
134 NULL);137 NULL);
135 }138 }
136 else139 else
@@ -139,7 +142,8 @@
139 kind,142 kind,
140 percentage,143 percentage,
141 state,144 state,
142 (time_t)time);145 (time_t)time,
146 power_supply);
143147
144 g_hash_table_insert (p->devices,148 g_hash_table_insert (p->devices,
145 g_strdup (data->path),149 g_strdup (data->path),
146150
=== modified file 'src/device.c'
--- src/device.c 2016-05-26 18:32:08 +0000
+++ src/device.c 2017-01-16 19:06:20 +0000
@@ -42,6 +42,7 @@
42 the time-remaining field for this device, or 0 if not applicable.42 the time-remaining field for this device, or 0 if not applicable.
43 This is used when generating the time-remaining string. */43 This is used when generating the time-remaining string. */
44 GTimer * inestimable;44 GTimer * inestimable;
45 gboolean power_supply;
45};46};
4647
47/* Properties */48/* Properties */
@@ -53,6 +54,7 @@
53 PROP_OBJECT_PATH,54 PROP_OBJECT_PATH,
54 PROP_PERCENTAGE,55 PROP_PERCENTAGE,
55 PROP_TIME,56 PROP_TIME,
57 PROP_POWER_SUPPLY,
56 N_PROPERTIES58 N_PROPERTIES
57};59};
5860
@@ -116,6 +118,12 @@
116 0,118 0,
117 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);119 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
118120
121 properties[PROP_POWER_SUPPLY] = g_param_spec_boolean (INDICATOR_POWER_DEVICE_POWER_SUPPLY,
122 "power supply",
123 "The device's power supply",
124 FALSE,
125 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
126
119 g_object_class_install_properties (object_class, N_PROPERTIES, properties);127 g_object_class_install_properties (object_class, N_PROPERTIES, properties);
120}128}
121129
@@ -132,6 +140,7 @@
132 priv->object_path = NULL;140 priv->object_path = NULL;
133 priv->percentage = 0.0;141 priv->percentage = 0.0;
134 priv->time = 0;142 priv->time = 0;
143 priv->power_supply = FALSE;
135144
136 self->priv = priv;145 self->priv = priv;
137}146}
@@ -190,6 +199,10 @@
190 g_value_set_uint64 (value, (guint64)priv->time);199 g_value_set_uint64 (value, (guint64)priv->time);
191 break;200 break;
192201
202 case PROP_POWER_SUPPLY:
203 g_value_set_boolean (value, priv->power_supply);
204 break;
205
193 default:206 default:
194 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, prop_id, pspec);207 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, prop_id, pspec);
195 break;208 break;
@@ -225,6 +238,10 @@
225 p->time = (time_t) g_value_get_uint64(value);238 p->time = (time_t) g_value_get_uint64(value);
226 break;239 break;
227240
241 case PROP_POWER_SUPPLY:
242 p->power_supply = g_value_get_boolean (value);
243 break;
244
228 default:245 default:
229 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, prop_id, pspec);246 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, prop_id, pspec);
230 break;247 break;
@@ -304,6 +321,16 @@
304 return device->priv->time;321 return device->priv->time;
305}322}
306323
324gboolean
325indicator_power_device_get_power_supply (const IndicatorPowerDevice * device)
326{
327 /* LCOV_EXCL_START */
328 g_return_val_if_fail (INDICATOR_IS_POWER_DEVICE(device), FALSE);
329 /* LCOV_EXCL_STOP */
330
331 return device->priv->power_supply;
332}
333
307/***334/***
308****335****
309****336****
@@ -867,7 +894,8 @@
867 UpDeviceKind kind,894 UpDeviceKind kind,
868 gdouble percentage,895 gdouble percentage,
869 UpDeviceState state,896 UpDeviceState state,
870 time_t timestamp)897 time_t timestamp,
898 gboolean power_supply)
871{899{
872 GObject * o = g_object_new (INDICATOR_POWER_DEVICE_TYPE,900 GObject * o = g_object_new (INDICATOR_POWER_DEVICE_TYPE,
873 INDICATOR_POWER_DEVICE_KIND, kind,901 INDICATOR_POWER_DEVICE_KIND, kind,
@@ -875,6 +903,7 @@
875 INDICATOR_POWER_DEVICE_OBJECT_PATH, object_path,903 INDICATOR_POWER_DEVICE_OBJECT_PATH, object_path,
876 INDICATOR_POWER_DEVICE_PERCENTAGE, percentage,904 INDICATOR_POWER_DEVICE_PERCENTAGE, percentage,
877 INDICATOR_POWER_DEVICE_TIME, (guint64)timestamp,905 INDICATOR_POWER_DEVICE_TIME, (guint64)timestamp,
906 INDICATOR_POWER_DEVICE_POWER_SUPPLY, power_supply,
878 NULL);907 NULL);
879 return INDICATOR_POWER_DEVICE(o);908 return INDICATOR_POWER_DEVICE(o);
880}909}
@@ -882,7 +911,7 @@
882IndicatorPowerDevice *911IndicatorPowerDevice *
883indicator_power_device_new_from_variant (GVariant * v)912indicator_power_device_new_from_variant (GVariant * v)
884{913{
885 g_return_val_if_fail (g_variant_is_of_type (v, G_VARIANT_TYPE("(susdut)")), NULL);914 g_return_val_if_fail (g_variant_is_of_type (v, G_VARIANT_TYPE("(susdutb)")), NULL);
886915
887 UpDeviceKind kind = UP_DEVICE_KIND_UNKNOWN;916 UpDeviceKind kind = UP_DEVICE_KIND_UNKNOWN;
888 UpDeviceState state = UP_DEVICE_STATE_UNKNOWN;917 UpDeviceState state = UP_DEVICE_STATE_UNKNOWN;
@@ -890,18 +919,21 @@
890 const gchar * object_path = NULL;919 const gchar * object_path = NULL;
891 gdouble percentage = 0;920 gdouble percentage = 0;
892 guint64 time = 0;921 guint64 time = 0;
922 gboolean power_supply = FALSE;
893923
894 g_variant_get (v, "(&su&sdut)",924 g_variant_get (v, "(&su&sdutb)",
895 &object_path,925 &object_path,
896 &kind,926 &kind,
897 &icon,927 &icon,
898 &percentage,928 &percentage,
899 &state,929 &state,
900 &time);930 &time,
931 &power_supply);
901932
902 return indicator_power_device_new (object_path,933 return indicator_power_device_new (object_path,
903 kind,934 kind,
904 percentage,935 percentage,
905 state,936 state,
906 (time_t)time);937 (time_t)time,
938 power_supply);
907}939}
908940
=== modified file 'src/device.h'
--- src/device.h 2014-07-24 20:20:16 +0000
+++ src/device.h 2017-01-16 19:06:20 +0000
@@ -44,6 +44,7 @@
44#define INDICATOR_POWER_DEVICE_OBJECT_PATH "object-path"44#define INDICATOR_POWER_DEVICE_OBJECT_PATH "object-path"
45#define INDICATOR_POWER_DEVICE_PERCENTAGE "percentage"45#define INDICATOR_POWER_DEVICE_PERCENTAGE "percentage"
46#define INDICATOR_POWER_DEVICE_TIME "time"46#define INDICATOR_POWER_DEVICE_TIME "time"
47#define INDICATOR_POWER_DEVICE_POWER_SUPPLY "power-supply"
4748
48typedef enum49typedef enum
49{50{
@@ -107,7 +108,8 @@
107 UpDeviceKind kind,108 UpDeviceKind kind,
108 gdouble percentage,109 gdouble percentage,
109 UpDeviceState state,110 UpDeviceState state,
110 time_t time);111 time_t time,
112 gboolean power_supply);
111113
112/**114/**
113 * Convenience wrapper around indicator_power_device_new()115 * Convenience wrapper around indicator_power_device_new()
@@ -121,6 +123,7 @@
121const gchar * indicator_power_device_get_object_path (const IndicatorPowerDevice * device);123const gchar * indicator_power_device_get_object_path (const IndicatorPowerDevice * device);
122gdouble indicator_power_device_get_percentage (const IndicatorPowerDevice * device);124gdouble indicator_power_device_get_percentage (const IndicatorPowerDevice * device);
123time_t indicator_power_device_get_time (const IndicatorPowerDevice * device);125time_t indicator_power_device_get_time (const IndicatorPowerDevice * device);
126gboolean indicator_power_device_get_power_supply (const IndicatorPowerDevice * device);
124127
125GStrv indicator_power_device_get_icon_names (const IndicatorPowerDevice * device);128GStrv indicator_power_device_get_icon_names (const IndicatorPowerDevice * device);
126GIcon * indicator_power_device_get_gicon (const IndicatorPowerDevice * device);129GIcon * indicator_power_device_get_gicon (const IndicatorPowerDevice * device);
127130
=== modified file 'src/service.c'
--- src/service.c 2016-05-26 18:21:09 +0000
+++ src/service.c 2017-01-16 19:06:20 +0000
@@ -162,11 +162,12 @@
162}162}
163163
164/* sort devices from most interesting to least interesting on this criteria:164/* sort devices from most interesting to least interesting on this criteria:
165 1. discharging items from least time remaining until most time remaining165 1. device that supplied the power to the system
166 2. charging items from most time left to charge to least time left to charge166 2. discharging items from least time remaining until most time remaining
167 3. charging items with an unknown time remaining167 3. charging items from most time left to charge to least time left to charge
168 4. discharging items with an unknown time remaining168 4. charging items with an unknown time remaining
169 5. batteries, then non-line power, then line-power */169 5. discharging items with an unknown time remaining
170 6. batteries, then non-line power, then line-power */
170static gint171static gint
171device_compare_func (gconstpointer ga, gconstpointer gb)172device_compare_func (gconstpointer ga, gconstpointer gb)
172{173{
@@ -174,6 +175,8 @@
174 int state;175 int state;
175 const IndicatorPowerDevice * a = ga;176 const IndicatorPowerDevice * a = ga;
176 const IndicatorPowerDevice * b = gb;177 const IndicatorPowerDevice * b = gb;
178 const gboolean a_power_supply = indicator_power_device_get_power_supply (a);
179 const gboolean b_power_supply = indicator_power_device_get_power_supply (b);
177 const int a_state = indicator_power_device_get_state (a);180 const int a_state = indicator_power_device_get_state (a);
178 const int b_state = indicator_power_device_get_state (b);181 const int b_state = indicator_power_device_get_state (b);
179 const gdouble a_percentage = indicator_power_device_get_percentage (a);182 const gdouble a_percentage = indicator_power_device_get_percentage (a);
@@ -183,6 +186,18 @@
183186
184 ret = 0;187 ret = 0;
185188
189 if (!ret && (a_power_supply != b_power_supply))
190 {
191 if (a_power_supply) /* a provides power to the system */
192 {
193 ret = -1;
194 }
195 else /* b provides power to the system */
196 {
197 ret = 1;
198 }
199 }
200
186 state = UP_DEVICE_STATE_DISCHARGING;201 state = UP_DEVICE_STATE_DISCHARGING;
187 if (!ret && (((a_state == state) && a_time) ||202 if (!ret && (((a_state == state) && a_time) ||
188 ((b_state == state) && b_time)))203 ((b_state == state) && b_time)))
@@ -1436,7 +1451,8 @@
1436 UP_DEVICE_KIND_BATTERY,1451 UP_DEVICE_KIND_BATTERY,
1437 percent,1452 percent,
1438 state,1453 state,
1439 time_left);1454 time_left,
1455 TRUE);
1440 }1456 }
14411457
1442 return device;1458 return device;
14431459
=== modified file 'src/testing.c'
--- src/testing.c 2014-10-14 19:50:47 +0000
+++ src/testing.c 2017-01-16 19:06:20 +0000
@@ -301,7 +301,8 @@
301 UP_DEVICE_KIND_BATTERY,301 UP_DEVICE_KIND_BATTERY,
302 50.0,302 50.0,
303 UP_DEVICE_STATE_DISCHARGING,303 UP_DEVICE_STATE_DISCHARGING,
304 60*30);304 60*30,
305 TRUE);
305306
306307
307 /* Mock Provider */308 /* Mock Provider */
308309
=== modified file 'tests/test-device.cc'
--- tests/test-device.cc 2016-05-26 19:02:10 +0000
+++ tests/test-device.cc 2017-01-16 19:06:20 +0000
@@ -205,7 +205,8 @@
205 UP_DEVICE_KIND_BATTERY,205 UP_DEVICE_KIND_BATTERY,
206 50.0,206 50.0,
207 UP_DEVICE_STATE_CHARGING,207 UP_DEVICE_STATE_CHARGING,
208 30);208 30,
209 TRUE);
209 ASSERT_TRUE (device != NULL);210 ASSERT_TRUE (device != NULL);
210 ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));211 ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));
211 ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device));212 ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device));
@@ -213,6 +214,7 @@
213 ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));214 ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
214 ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));215 ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
215 ASSERT_EQ (30, indicator_power_device_get_time(device));216 ASSERT_EQ (30, indicator_power_device_get_time(device));
217 ASSERT_TRUE (indicator_power_device_get_power_supply(device));
216218
217 // cleanup219 // cleanup
218 g_object_unref (device);220 g_object_unref (device);
@@ -220,13 +222,14 @@
220222
221TEST_F(DeviceTest, NewFromVariant)223TEST_F(DeviceTest, NewFromVariant)
222{224{
223 auto variant = g_variant_new("(susdut)",225 auto variant = g_variant_new("(susdutb)",
224 "/object/path",226 "/object/path",
225 guint32(UP_DEVICE_KIND_BATTERY),227 guint32(UP_DEVICE_KIND_BATTERY),
226 "icon",228 "icon",
227 50.0,229 50.0,
228 guint32(UP_DEVICE_STATE_CHARGING),230 guint32(UP_DEVICE_STATE_CHARGING),
229 guint64(30));231 guint64(30),
232 TRUE);
230 IndicatorPowerDevice * device = indicator_power_device_new_from_variant (variant);233 IndicatorPowerDevice * device = indicator_power_device_new_from_variant (variant);
231 ASSERT_TRUE (variant != NULL);234 ASSERT_TRUE (variant != NULL);
232 ASSERT_TRUE (device != NULL);235 ASSERT_TRUE (device != NULL);
@@ -236,6 +239,7 @@
236 ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));239 ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
237 ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));240 ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
238 ASSERT_EQ (30, indicator_power_device_get_time(device));241 ASSERT_EQ (30, indicator_power_device_get_time(device));
242 ASSERT_TRUE (indicator_power_device_get_power_supply(device));
239243
240 // cleanup244 // cleanup
241 g_object_unref (device);245 g_object_unref (device);
@@ -810,7 +814,8 @@
810 << ' ' << state2str(indicator_power_device_get_state(device))814 << ' ' << state2str(indicator_power_device_get_state(device))
811 << ' ' << indicator_power_device_get_time(device)<<'m'815 << ' ' << indicator_power_device_get_time(device)<<'m'
812 << ' ' << int(ceil(indicator_power_device_get_percentage(device)))<<'%'816 << ' ' << int(ceil(indicator_power_device_get_percentage(device)))<<'%'
813 << ' ' << (path ? path : "nopath");817 << ' ' << (path ? path : "nopath")
818 << ' ' << (indicator_power_device_get_power_supply(device) ? "1" : "0");
814819
815 return o.str();820 return o.str();
816 }821 }
@@ -818,13 +823,14 @@
818 IndicatorPowerDevice* str2device(const std::string& str)823 IndicatorPowerDevice* str2device(const std::string& str)
819 {824 {
820 auto tokens = g_strsplit(str.c_str(), " ", 0);825 auto tokens = g_strsplit(str.c_str(), " ", 0);
821 g_assert(5u == g_strv_length(tokens));826 g_assert(6u == g_strv_length(tokens));
822 const auto kind = str2kind(tokens[0]);827 const auto kind = str2kind(tokens[0]);
823 const auto state = str2state(tokens[1]);828 const auto state = str2state(tokens[1]);
824 const time_t time = atoi(tokens[2]);829 const time_t time = atoi(tokens[2]);
825 const double pct = strtod(tokens[3],nullptr);830 const double pct = strtod(tokens[3],nullptr);
826 const char* path = !g_strcmp0(tokens[4],"nopath") ? nullptr : tokens[4];831 const char* path = !g_strcmp0(tokens[4],"nopath") ? nullptr : tokens[4];
827 auto ret = indicator_power_device_new(path, kind, pct, state, time);832 const gboolean power_supply = atoi(tokens[5]);
833 auto ret = indicator_power_device_new(path, kind, pct, state, time, power_supply);
828 g_strfreev(tokens);834 g_strfreev(tokens);
829 return ret;835 return ret;
830 }836 }
@@ -847,100 +853,100 @@
847 } tests[] = {853 } tests[] = {
848 {854 {
849 "one discharging battery",855 "one discharging battery",
850 "battery discharging 10m 60% bat01",856 "battery discharging 10m 60% bat01 1",
851 { "battery discharging 10m 60% bat01" }857 { "battery discharging 10m 60% bat01 1" }
852 },858 },
853 {859 {
854 "merge two discharging batteries",860 "merge two discharging batteries",
855 "battery discharging 20m 70% nopath",861 "battery discharging 20m 70% nopath 1",
856 { "battery discharging 10m 60% bat01", "battery discharging 20m 80% bat02" }862 { "battery discharging 10m 60% bat01 1", "battery discharging 20m 80% bat02 1" }
857 },863 },
858 {864 {
859 "merge two other discharging batteries",865 "merge two other discharging batteries",
860 "battery discharging 30m 90% nopath",866 "battery discharging 30m 90% nopath 1",
861 { "battery discharging 20m 80% bat01", "battery discharging 30m 100% bat02" }867 { "battery discharging 20m 80% bat01 1", "battery discharging 30m 100% bat02 1" }
862 },868 },
863 {869 {
864 "merge three discharging batteries",870 "merge three discharging batteries",
865 "battery discharging 30m 80% nopath",871 "battery discharging 30m 80% nopath 1",
866 { "battery discharging 10m 60% bat01", "battery discharging 20m 80% bat02", "battery discharging 30m 100% bat03" }872 { "battery discharging 10m 60% bat01 1", "battery discharging 20m 80% bat02 1", "battery discharging 30m 100% bat03 1" }
867 },873 },
868 {874 {
869 "one charging battery",875 "one charging battery",
870 "battery charging 10m 60% bat01",876 "battery charging 10m 60% bat01 1",
871 { "battery charging 10m 60% bat01" }877 { "battery charging 10m 60% bat01 1" }
872 },878 },
873 {879 {
874 "merge two charging batteries",880 "merge two charging batteries",
875 "battery charging 20m 70% nopath",881 "battery charging 20m 70% nopath 1",
876 { "battery charging 10m 60% bat01", "battery charging 20m 80% bat02" }882 { "battery charging 10m 60% bat01 1", "battery charging 20m 80% bat02 1" }
877 },883 },
878 {884 {
879 "merge two other charging batteries",885 "merge two other charging batteries",
880 "battery charging 30m 90% nopath",886 "battery charging 30m 90% nopath 1",
881 { "battery charging 20m 80% bat01", "battery charging 30m 100% bat02" }887 { "battery charging 20m 80% bat01 1", "battery charging 30m 100% bat02 1" }
882 },888 },
883 {889 {
884 "merge three charging batteries",890 "merge three charging batteries",
885 "battery charging 30m 80% nopath",891 "battery charging 30m 80% nopath 1",
886 { "battery charging 10m 60% bat01", "battery charging 20m 80% bat02", "battery charging 30m 100% bat03" }892 { "battery charging 10m 60% bat01 1", "battery charging 20m 80% bat02 1", "battery charging 30m 100% bat03 1" }
887 },893 },
888 {894 {
889 "one charged battery",895 "one charged battery",
890 "battery charged 0m 100% bat01",896 "battery charged 0m 100% bat01 1",
891 { "battery charged 0m 100% bat01" }897 { "battery charged 0m 100% bat01 1" }
892 },898 },
893 {899 {
894 "merge one charged, one discharging",900 "merge one charged, one discharging",
895 "battery discharging 10m 80% nopath",901 "battery discharging 10m 80% nopath 1",
896 { "battery charged 0m 100% bat01", "battery discharging 10m 60% bat02" }902 { "battery charged 0m 100% bat01 1", "battery discharging 10m 60% bat02 1" }
897 },903 },
898 {904 {
899 "merged one charged, one charging",905 "merged one charged, one charging",
900 "battery charging 10m 80% nopath",906 "battery charging 10m 80% nopath 1",
901 { "battery charged 0m 100% bat01", "battery charging 10m 60% bat02" }907 { "battery charged 0m 100% bat01 1", "battery charging 10m 60% bat02 1" }
902 },908 },
903 {909 {
904 "merged one charged, one charging, one discharging",910 "merged one charged, one charging, one discharging",
905 "battery discharging 10m 74% nopath",911 "battery discharging 10m 74% nopath 1",
906 { "battery charged 0m 100% bat01", "battery charging 10m 60% bat02", "battery discharging 10m 60% bat03" }912 { "battery charged 0m 100% bat01 1", "battery charging 10m 60% bat02 1", "battery discharging 10m 60% bat03 1" }
907 },913 },
908 {914 {
909 "one discharging mouse and one discharging battery. pick the one with the least time left",915 "one discharging mouse and one discharging battery. ignore mouse because it doesn't supply the power",
910 "battery discharging 10m 60% bat01",916 "battery discharging 10m 60% bat01 1",
911 { "battery discharging 10m 60% bat01", "mouse discharging 20m 80% mouse01" }917 { "battery discharging 10m 60% bat01 1", "mouse discharging 20m 80% mouse01 0" }
912 },918 },
913 {919 {
914 "one discharging mouse and a different discharging battery. pick the one with the least time left",920 "one discharging mouse and a different discharging battery. ignore mouse because it doesn't supply the power",
915 "mouse discharging 20m 80% mouse01",921 "battery discharging 30m 100% bat01 1",
916 { "battery discharging 30m 100% bat01", "mouse discharging 20m 80% mouse01" }922 { "battery discharging 30m 100% bat01 1", "mouse discharging 20m 80% mouse01 0" }
917 },923 },
918 {924 {
919 "everything comes before power lines #1",925 "everything comes before power lines #1",
920 "battery discharging 10m 60% bat01",926 "battery discharging 10m 60% bat01 1",
921 { "battery discharging 10m 60% bat01", "line-power unknown 0m 0% lp01" }927 { "battery discharging 10m 60% bat01 1", "line-power unknown 0m 0% lp01 1" }
922 },928 },
923 {929 {
924 "everything comes before power lines #2",930 "everything comes before power lines #2",
925 "battery charging 10m 60% bat01",931 "battery charging 10m 60% bat01 1",
926 { "battery charging 10m 60% bat01", "line-power unknown 0m 0% lp01" }932 { "battery charging 10m 60% bat01 1", "line-power unknown 0m 0% lp01 1" }
927 },933 },
928 {934 {
929 "everything comes before power lines #2",935 "everything comes before power lines #3 except that the mouse doesn't supply the power",
930 "mouse discharging 20m 80% mouse01",936 "line-power unknown 0m 0% lp01 1",
931 { "mouse discharging 20m 80% mouse01", "line-power unknown 0m 0% lp01" }937 { "mouse discharging 20m 80% mouse01 0", "line-power unknown 0m 0% lp01 1" }
932 },938 },
933 {939 {
934 // https://bugs.launchpad.net/ubuntu/+source/indicator-power/+bug/1470080/comments/10940 // https://bugs.launchpad.net/ubuntu/+source/indicator-power/+bug/1470080/comments/10
935 "don't select a device with unknown state when we have another device with a known state...",941 "don't select a device with unknown state when we have another device with a known state...",
936 "battery charged 0m 100% bat01",942 "battery charged 0m 100% bat01 1",
937 { "battery charged 0m 100% bat01", "phone unknown 0m 61% phone01" }943 { "battery charged 0m 100% bat01 1", "phone unknown 0m 61% phone01 1" }
938 },944 },
939 {945 {
940 // https://bugs.launchpad.net/ubuntu/+source/indicator-power/+bug/1470080/comments/10946 // https://bugs.launchpad.net/ubuntu/+source/indicator-power/+bug/1470080/comments/10
941 "...but do select the unknown state device if nothing else is available",947 "...but do select the unknown state device if nothing else is available",
942 "phone unknown 0m 61% phone01",948 "phone unknown 0m 61% phone01 1",
943 { "phone unknown 0m 61% phone01" }949 { "phone unknown 0m 61% phone01 1" }
944 }950 }
945 };951 };
946 952
947953
=== modified file 'tests/test-notify.cc'
--- tests/test-notify.cc 2016-05-16 17:59:03 +0000
+++ tests/test-notify.cc 2017-01-16 19:06:20 +0000
@@ -235,7 +235,8 @@
235 UP_DEVICE_KIND_BATTERY,235 UP_DEVICE_KIND_BATTERY,
236 50.0,236 50.0,
237 UP_DEVICE_STATE_DISCHARGING,237 UP_DEVICE_STATE_DISCHARGING,
238 30);238 30,
239 TRUE);
239240
240 // confirm that the power levels trigger at the right percentages241 // confirm that the power levels trigger at the right percentages
241 for (int i=100; i>=0; --i)242 for (int i=100; i>=0; --i)
@@ -313,7 +314,8 @@
313 UP_DEVICE_KIND_BATTERY,314 UP_DEVICE_KIND_BATTERY,
314 50.0,315 50.0,
315 UP_DEVICE_STATE_DISCHARGING,316 UP_DEVICE_STATE_DISCHARGING,
316 30);317 30,
318 TRUE);
317319
318 // set up a notifier and give it the battery so changing the battery's320 // set up a notifier and give it the battery so changing the battery's
319 // charge should show up on the bus.321 // charge should show up on the bus.
@@ -385,7 +387,8 @@
385 UP_DEVICE_KIND_BATTERY,387 UP_DEVICE_KIND_BATTERY,
386 percent_low + 1.0,388 percent_low + 1.0,
387 UP_DEVICE_STATE_DISCHARGING,389 UP_DEVICE_STATE_DISCHARGING,
388 30);390 30,
391 TRUE);
389392
390 // the file we expect to play on a low battery notification...393 // the file we expect to play on a low battery notification...
391 const char* expected_file = XDG_DATA_HOME "/" GETTEXT_PACKAGE "/sounds/" LOW_BATTERY_SOUND;394 const char* expected_file = XDG_DATA_HOME "/" GETTEXT_PACKAGE "/sounds/" LOW_BATTERY_SOUND;

Subscribers

People subscribed via source and target branches