Merge lp:~fourdollars/indicator-power/xenial into lp:indicator-power/16.04

Proposed by Shih-Yuan Lee
Status: Needs review
Proposed branch: lp:~fourdollars/indicator-power/xenial
Merge into: lp:indicator-power/16.04
Diff against target: 453 lines (+111/-52)
7 files modified
src/device-provider-upower.c (+5/-1)
src/device.c (+37/-5)
src/device.h (+4/-1)
src/service.c (+18/-6)
src/testing.c (+2/-1)
tests/test-device.cc (+39/-35)
tests/test-notify.cc (+6/-3)
To merge this branch: bzr merge lp:~fourdollars/indicator-power/xenial
Reviewer Review Type Date Requested Status
Indicator Applet Developers Pending
Review via email: mp+314127@code.launchpad.net

This proposal supersedes a proposal from 2017-01-05.

Commit message

Make device with power supply has higher sorting priority. (LP: #1100546)

To post a comment you must log in.

Unmerged revisions

293. By Shih-Yuan Lee

Make device with power supply has higher sorting priority. (LP: #1100546)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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-05 04:47:47 +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 2015-01-12 22:43:49 +0000
+++ src/device.c 2017-01-05 04:47:47 +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****
@@ -866,7 +893,8 @@
866 UpDeviceKind kind,893 UpDeviceKind kind,
867 gdouble percentage,894 gdouble percentage,
868 UpDeviceState state,895 UpDeviceState state,
869 time_t timestamp)896 time_t timestamp,
897 gboolean power_supply)
870{898{
871 GObject * o = g_object_new (INDICATOR_POWER_DEVICE_TYPE,899 GObject * o = g_object_new (INDICATOR_POWER_DEVICE_TYPE,
872 INDICATOR_POWER_DEVICE_KIND, kind,900 INDICATOR_POWER_DEVICE_KIND, kind,
@@ -874,6 +902,7 @@
874 INDICATOR_POWER_DEVICE_OBJECT_PATH, object_path,902 INDICATOR_POWER_DEVICE_OBJECT_PATH, object_path,
875 INDICATOR_POWER_DEVICE_PERCENTAGE, percentage,903 INDICATOR_POWER_DEVICE_PERCENTAGE, percentage,
876 INDICATOR_POWER_DEVICE_TIME, (guint64)timestamp,904 INDICATOR_POWER_DEVICE_TIME, (guint64)timestamp,
905 INDICATOR_POWER_DEVICE_POWER_SUPPLY, power_supply,
877 NULL);906 NULL);
878 return INDICATOR_POWER_DEVICE(o);907 return INDICATOR_POWER_DEVICE(o);
879}908}
@@ -881,7 +910,7 @@
881IndicatorPowerDevice *910IndicatorPowerDevice *
882indicator_power_device_new_from_variant (GVariant * v)911indicator_power_device_new_from_variant (GVariant * v)
883{912{
884 g_return_val_if_fail (g_variant_is_of_type (v, G_VARIANT_TYPE("(susdut)")), NULL);913 g_return_val_if_fail (g_variant_is_of_type (v, G_VARIANT_TYPE("(susdutb)")), NULL);
885914
886 UpDeviceKind kind = UP_DEVICE_KIND_UNKNOWN;915 UpDeviceKind kind = UP_DEVICE_KIND_UNKNOWN;
887 UpDeviceState state = UP_DEVICE_STATE_UNKNOWN;916 UpDeviceState state = UP_DEVICE_STATE_UNKNOWN;
@@ -889,18 +918,21 @@
889 const gchar * object_path = NULL;918 const gchar * object_path = NULL;
890 gdouble percentage = 0;919 gdouble percentage = 0;
891 guint64 time = 0;920 guint64 time = 0;
921 gboolean power_supply = FALSE;
892922
893 g_variant_get (v, "(&su&sdut)",923 g_variant_get (v, "(&su&sdutb)",
894 &object_path,924 &object_path,
895 &kind,925 &kind,
896 &icon,926 &icon,
897 &percentage,927 &percentage,
898 &state,928 &state,
899 &time);929 &time,
930 &power_supply);
900931
901 return indicator_power_device_new (object_path,932 return indicator_power_device_new (object_path,
902 kind,933 kind,
903 percentage,934 percentage,
904 state,935 state,
905 (time_t)time);936 (time_t)time,
937 power_supply);
906}938}
907939
=== modified file 'src/device.h'
--- src/device.h 2014-07-24 20:20:16 +0000
+++ src/device.h 2017-01-05 04:47:47 +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-01-02 02:19:45 +0000
+++ src/service.c 2017-01-05 04:47:47 +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,14 @@
183186
184 ret = 0;187 ret = 0;
185188
189 if (!ret)
190 {
191 if (a_power_supply == TRUE && b_power_supply == FALSE)
192 ret = -1;
193 else if (a_power_supply == FALSE && b_power_supply == TRUE)
194 ret = 1;
195 }
196
186 state = UP_DEVICE_STATE_DISCHARGING;197 state = UP_DEVICE_STATE_DISCHARGING;
187 if (!ret && (((a_state == state) && a_time) ||198 if (!ret && (((a_state == state) && a_time) ||
188 ((b_state == state) && b_time)))199 ((b_state == state) && b_time)))
@@ -1418,7 +1429,8 @@
1418 UP_DEVICE_KIND_BATTERY,1429 UP_DEVICE_KIND_BATTERY,
1419 percent,1430 percent,
1420 state,1431 state,
1421 time_left);1432 time_left,
1433 TRUE);
1422 }1434 }
14231435
1424 return device;1436 return device;
14251437
=== modified file 'src/testing.c'
--- src/testing.c 2014-10-14 19:50:47 +0000
+++ src/testing.c 2017-01-05 04:47:47 +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 2015-01-12 21:47:27 +0000
+++ tests/test-device.cc 2017-01-05 04:47:47 +0000
@@ -190,7 +190,8 @@
190 UP_DEVICE_KIND_BATTERY,190 UP_DEVICE_KIND_BATTERY,
191 50.0,191 50.0,
192 UP_DEVICE_STATE_CHARGING,192 UP_DEVICE_STATE_CHARGING,
193 30);193 30,
194 TRUE);
194 ASSERT_TRUE (device != NULL);195 ASSERT_TRUE (device != NULL);
195 ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));196 ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));
196 ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device));197 ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device));
@@ -198,6 +199,7 @@
198 ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));199 ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
199 ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));200 ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
200 ASSERT_EQ (30, indicator_power_device_get_time(device));201 ASSERT_EQ (30, indicator_power_device_get_time(device));
202 ASSERT_TRUE (indicator_power_device_get_power_supply(device));
201203
202 // cleanup204 // cleanup
203 g_object_unref (device);205 g_object_unref (device);
@@ -205,13 +207,14 @@
205207
206TEST_F(DeviceTest, NewFromVariant)208TEST_F(DeviceTest, NewFromVariant)
207{209{
208 auto variant = g_variant_new("(susdut)",210 auto variant = g_variant_new("(susdutb)",
209 "/object/path",211 "/object/path",
210 guint32(UP_DEVICE_KIND_BATTERY),212 guint32(UP_DEVICE_KIND_BATTERY),
211 "icon",213 "icon",
212 50.0,214 50.0,
213 guint32(UP_DEVICE_STATE_CHARGING),215 guint32(UP_DEVICE_STATE_CHARGING),
214 guint64(30));216 guint64(30),
217 TRUE);
215 IndicatorPowerDevice * device = indicator_power_device_new_from_variant (variant);218 IndicatorPowerDevice * device = indicator_power_device_new_from_variant (variant);
216 ASSERT_TRUE (variant != NULL);219 ASSERT_TRUE (variant != NULL);
217 ASSERT_TRUE (device != NULL);220 ASSERT_TRUE (device != NULL);
@@ -221,6 +224,7 @@
221 ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));224 ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
222 ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));225 ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
223 ASSERT_EQ (30, indicator_power_device_get_time(device));226 ASSERT_EQ (30, indicator_power_device_get_time(device));
227 ASSERT_TRUE (indicator_power_device_get_power_supply(device));
224228
225 // cleanup229 // cleanup
226 g_object_unref (device);230 g_object_unref (device);
@@ -709,26 +713,27 @@
709 UpDeviceState state;713 UpDeviceState state;
710 guint64 time;714 guint64 time;
711 double percentage;715 double percentage;
716 gboolean power_supply;
712 };717 };
713718
714 const Description descriptions[] = {719 const Description descriptions[] = {
715 { "/some/path/d0", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 10, 60.0 }, // 0720 { "/some/path/d0", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 10, 60.0, TRUE }, // 0
716 { "/some/path/d1", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 20, 80.0 }, // 1721 { "/some/path/d1", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 20, 80.0, TRUE }, // 1
717 { "/some/path/d2", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 30, 100.0 }, // 2722 { "/some/path/d2", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 30, 100.0, TRUE }, // 2
718723
719 { "/some/path/c0", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 10, 60.0 }, // 3724 { "/some/path/c0", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 10, 60.0, TRUE }, // 3
720 { "/some/path/c1", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 20, 80.0 }, // 4725 { "/some/path/c1", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 20, 80.0, TRUE }, // 4
721 { "/some/path/c2", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 30, 100.0 }, // 5726 { "/some/path/c2", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 30, 100.0, TRUE }, // 5
722727
723 { "/some/path/f0", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_FULLY_CHARGED, 0, 100.0 }, // 6728 { "/some/path/f0", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_FULLY_CHARGED, 0, 100.0, TRUE }, // 6
724 { "/some/path/m0", UP_DEVICE_KIND_MOUSE, UP_DEVICE_STATE_DISCHARGING, 20, 80.0 }, // 7729 { "/some/path/m0", UP_DEVICE_KIND_MOUSE, UP_DEVICE_STATE_DISCHARGING, 20, 80.0, FALSE }, // 7
725 { "/some/path/m1", UP_DEVICE_KIND_MOUSE, UP_DEVICE_STATE_FULLY_CHARGED, 0, 100.0 }, // 8730 { "/some/path/m1", UP_DEVICE_KIND_MOUSE, UP_DEVICE_STATE_FULLY_CHARGED, 0, 100.0, FALSE }, // 8
726 { "/some/path/pw", UP_DEVICE_KIND_LINE_POWER, UP_DEVICE_STATE_UNKNOWN, 0, 0.0 } // 9731 { "/some/path/pw", UP_DEVICE_KIND_LINE_POWER, UP_DEVICE_STATE_UNKNOWN, 0, 0.0, TRUE } // 9
727 };732 };
728733
729 std::vector<IndicatorPowerDevice*> devices;734 std::vector<IndicatorPowerDevice*> devices;
730 for(const auto& desc : descriptions)735 for(const auto& desc : descriptions)
731 devices.push_back(indicator_power_device_new(desc.path, desc.kind, desc.percentage, desc.state, time_t(desc.time)));736 devices.push_back(indicator_power_device_new(desc.path, desc.kind, desc.percentage, desc.state, time_t(desc.time), desc.power_supply));
732737
733 const struct {738 const struct {
734 std::vector<unsigned int> device_indices;739 std::vector<unsigned int> device_indices;
@@ -736,29 +741,26 @@
736 } tests[] = {741 } tests[] = {
737742
738 { { 0 }, descriptions[0] }, // 1 discharging743 { { 0 }, descriptions[0] }, // 1 discharging
739 { { 0, 1 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 20, 70.0 } }, // 2 discharging744 { { 0, 1 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 20, 70.0, TRUE } }, // 2 discharging
740 { { 1, 2 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 30, 90.0 } }, // 2 discharging745 { { 1, 2 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 30, 90.0, TRUE } }, // 2 discharging
741 { { 0, 1, 2 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 30, 80.0 } }, // 3 discharging746 { { 0, 1, 2 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 30, 80.0, TRUE } }, // 3 discharging
747 { { 0, 1, 2, 7 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 30, 80.0, TRUE } }, // ignore mouse
742748
743 { { 3 }, descriptions[3] }, // 1 charging749 { { 3 }, descriptions[3] }, // 1 charging
744 { { 3, 4 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 20, 70.0 } }, // 2 charging750 { { 3, 4 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 20, 70.0, TRUE } }, // 2 charging
745 { { 4, 5 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 30, 90.0 } }, // 2 charging751 { { 4, 5 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 30, 90.0, TRUE } }, // 2 charging
746 { { 3, 4, 5 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 30, 80.0 } }, // 3 charging752 { { 3, 4, 5 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 30, 80.0, TRUE } }, // 3 charging
753 { { 3, 4, 5, 8 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 30, 80.0, TRUE } }, // ignore mouse
747754
748 { { 6 }, descriptions[6] }, // 1 charged755 { { 6 }, descriptions[6] }, // 1 charged
749 { { 6, 0 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 10, 80.0 } }, // 1 charged, 1 discharging756 { { 6, 0 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 10, 80.0, TRUE } }, // 1 charged, 1 discharging
750 { { 6, 3 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 10, 80.0 } }, // 1 charged, 1 charging757 { { 6, 3 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 10, 80.0, TRUE } }, // 1 charged, 1 charging
751 { { 6, 0, 3 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 10, 73.3 } }, // 1 charged, 1 charging, 1 discharging758 { { 6, 0, 3 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 10, 73.3, TRUE } }, // 1 charged, 1 charging, 1 discharging
752759 { { 6, 0, 3, 7, 8 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 10, 73.3, TRUE } }, // ignore mouse
753 { { 0, 7 }, descriptions[0] }, // 1 discharging battery, 1 discharging mouse. pick the one with the least time left.760
754 { { 2, 7 }, descriptions[7] }, // 1 discharging battery, 1 discharging mouse. pick the one with the least time left.761 { { 0, 9 }, descriptions[0] }, // everything comes before power lines except devices without power supply
755762 { { 3, 9 }, descriptions[3] },
756 { { 0, 8 }, descriptions[0] }, // 1 discharging battery, 1 fully-charged mouse. pick the one that's discharging.763 { { 7, 9 }, descriptions[9] },
757 { { 6, 7 }, descriptions[7] }, // 1 discharging mouse, 1 fully-charged battery. pick the one that's discharging.
758
759 { { 0, 9 }, descriptions[0] }, // everything comes before power lines
760 { { 3, 9 }, descriptions[3] },
761 { { 7, 9 }, descriptions[7] }
762 };764 };
763 765
764 for(const auto& test : tests)766 for(const auto& test : tests)
@@ -775,6 +777,7 @@
775 EXPECT_EQ(x.state, indicator_power_device_get_state(primary));777 EXPECT_EQ(x.state, indicator_power_device_get_state(primary));
776 EXPECT_EQ(x.time, indicator_power_device_get_time(primary));778 EXPECT_EQ(x.time, indicator_power_device_get_time(primary));
777 EXPECT_EQ(int(ceil(x.percentage)), int(ceil(indicator_power_device_get_percentage(primary))));779 EXPECT_EQ(int(ceil(x.percentage)), int(ceil(indicator_power_device_get_percentage(primary))));
780 EXPECT_EQ(x.power_supply, indicator_power_device_get_power_supply(primary));
778 g_object_unref(primary);781 g_object_unref(primary);
779782
780 // reverse the list and repeat the test783 // reverse the list and repeat the test
@@ -786,6 +789,7 @@
786 EXPECT_EQ(x.state, indicator_power_device_get_state(primary));789 EXPECT_EQ(x.state, indicator_power_device_get_state(primary));
787 EXPECT_EQ(x.time, indicator_power_device_get_time(primary));790 EXPECT_EQ(x.time, indicator_power_device_get_time(primary));
788 EXPECT_EQ(int(ceil(x.percentage)), int(ceil(indicator_power_device_get_percentage(primary))));791 EXPECT_EQ(int(ceil(x.percentage)), int(ceil(indicator_power_device_get_percentage(primary))));
792 EXPECT_EQ(x.power_supply, indicator_power_device_get_power_supply(primary));
789 g_object_unref(primary);793 g_object_unref(primary);
790794
791 // cleanup795 // cleanup
792796
=== modified file 'tests/test-notify.cc'
--- tests/test-notify.cc 2016-01-02 01:37:51 +0000
+++ tests/test-notify.cc 2017-01-05 04:47:47 +0000
@@ -194,7 +194,8 @@
194 UP_DEVICE_KIND_BATTERY,194 UP_DEVICE_KIND_BATTERY,
195 50.0,195 50.0,
196 UP_DEVICE_STATE_DISCHARGING,196 UP_DEVICE_STATE_DISCHARGING,
197 30);197 30,
198 TRUE);
198199
199 // confirm that the power levels trigger at the right percentages200 // confirm that the power levels trigger at the right percentages
200 for (int i=100; i>=0; --i)201 for (int i=100; i>=0; --i)
@@ -272,7 +273,8 @@
272 UP_DEVICE_KIND_BATTERY,273 UP_DEVICE_KIND_BATTERY,
273 50.0,274 50.0,
274 UP_DEVICE_STATE_DISCHARGING,275 UP_DEVICE_STATE_DISCHARGING,
275 30);276 30,
277 TRUE);
276278
277 // set up a notifier and give it the battery so changing the battery's279 // set up a notifier and give it the battery so changing the battery's
278 // charge should show up on the bus.280 // charge should show up on the bus.
@@ -354,7 +356,8 @@
354 UP_DEVICE_KIND_BATTERY,356 UP_DEVICE_KIND_BATTERY,
355 percent_low + 1.0,357 percent_low + 1.0,
356 UP_DEVICE_STATE_DISCHARGING,358 UP_DEVICE_STATE_DISCHARGING,
357 30);359 30,
360 TRUE);
358361
359 // the file we expect to play on a low battery notification...362 // the file we expect to play on a low battery notification...
360 const char* expected_file = XDG_DATA_HOME "/" GETTEXT_PACKAGE "/sounds/" LOW_BATTERY_SOUND;363 const char* expected_file = XDG_DATA_HOME "/" GETTEXT_PACKAGE "/sounds/" LOW_BATTERY_SOUND;

Subscribers

People subscribed via source and target branches