Merge lp:~unity-api-team/indicator-power/16.04-lp1559731 into lp:indicator-power/16.04

Proposed by Antti Kaijanmäki on 2016-07-08
Status: Approved
Approved by: Antti Kaijanmäki on 2016-07-08
Approved revision: 293
Proposed branch: lp:~unity-api-team/indicator-power/16.04-lp1559731
Merge into: lp:indicator-power/16.04
Diff against target: 223 lines (+40/-28)
2 files modified
src/device.c (+1/-1)
tests/test-device.cc (+39/-27)
To merge this branch: bzr merge lp:~unity-api-team/indicator-power/16.04-lp1559731
Reviewer Review Type Date Requested Status
Indicator Applet Developers 2016-07-08 Pending
Review via email: mp+299521@code.launchpad.net

Commit message

Fix the fallback power icon so the battery icon doesn't show red above 20% even when the Suru icon theme isn't present.

To post a comment you must log in.

Unmerged revisions

293. By Antti Kaijanmäki on 2016-07-08

backport

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/device.c'
2--- src/device.c 2015-01-12 22:43:49 +0000
3+++ src/device.c 2016-07-08 09:42:34 +0000
4@@ -340,7 +340,7 @@
5 if (percentage >= 90) return "100";
6 if (percentage >= 70) return "080";
7 if (percentage >= 50) return "060";
8- if (percentage >= 30) return "040";
9+ if (percentage > 20) return "040"; /* don't round down to 20: see bug #1559731 */
10 if (percentage >= 10) return "020";
11 return "000";
12 }
13
14=== modified file 'tests/test-device.cc'
15--- tests/test-device.cc 2015-01-12 21:47:27 +0000
16+++ tests/test-device.cc 2016-07-08 09:42:34 +0000
17@@ -61,13 +61,16 @@
18
19 protected:
20
21- void check_icon_names (const IndicatorPowerDevice * device, const char * expected)
22+ static std::string get_icon_names_from_device(const IndicatorPowerDevice* device)
23 {
24+ std::string ret;
25 char ** names = indicator_power_device_get_icon_names (device);
26 char * str = g_strjoinv (";", names);
27- ASSERT_STREQ (expected, str);
28+ if (str != nullptr)
29+ ret = str;
30 g_free (str);
31 g_strfreev (names);
32+ return ret;
33 }
34
35 void check_label (const IndicatorPowerDevice * device,
36@@ -121,6 +124,13 @@
37 }
38 };
39
40+#define EXPECT_ICON_NAMES_EQ(expected_in,device_in) \
41+ do { \
42+ const std::string tmp_expected {expected_in}; \
43+ const std::string tmp_actual {get_icon_names_from_device(device_in)}; \
44+ EXPECT_EQ(tmp_expected, tmp_actual); \
45+ } while(0)
46+
47 /***
48 ****
49 ***/
50@@ -266,14 +276,16 @@
51 // power
52 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_LINE_POWER,
53 NULL);
54- check_icon_names (device, "ac-adapter-symbolic;"
55- "ac-adapter");
56+ EXPECT_ICON_NAMES_EQ("ac-adapter-symbolic;"
57+ "ac-adapter",
58+ device);
59
60 // monitor
61 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_MONITOR,
62 NULL);
63- check_icon_names (device, "gpm-monitor-symbolic;"
64- "gpm-monitor");
65+ EXPECT_ICON_NAMES_EQ("gpm-monitor-symbolic;"
66+ "gpm-monitor",
67+ device);
68
69 // devices that hold a charge
70 struct {
71@@ -301,7 +313,7 @@
72 g_string_append_printf (expected, "gpm-%s-empty;", kind_str);
73 g_string_append_printf (expected, "gpm-%s-000;", kind_str);
74 g_string_append_printf (expected, "%s-empty", kind_str);
75- check_icon_names (device, expected->str);
76+ EXPECT_ICON_NAMES_EQ(expected->str, device);
77 g_string_truncate (expected, 0);
78
79 // charged
80@@ -314,7 +326,7 @@
81 g_string_append_printf (expected, "gpm-%s-100;", kind_str);
82 g_string_append_printf (expected, "%s-full-charged;", kind_str);
83 g_string_append_printf (expected, "%s-full-charging", kind_str);
84- check_icon_names (device, expected->str);
85+ EXPECT_ICON_NAMES_EQ(expected->str, device);
86 g_string_truncate (expected, 0);
87
88 // charging, 95%
89@@ -326,7 +338,7 @@
90 g_string_append_printf (expected, "gpm-%s-100-charging;", kind_str);
91 g_string_append_printf (expected, "%s-full-charging-symbolic;", kind_str);
92 g_string_append_printf (expected, "%s-full-charging", kind_str);
93- check_icon_names (device, expected->str);
94+ EXPECT_ICON_NAMES_EQ(expected->str, device);
95 g_string_truncate (expected, 0);
96
97 // charging, 85%
98@@ -340,7 +352,7 @@
99 g_string_append_printf (expected, "gpm-%s-080-charging;", kind_str);
100 g_string_append_printf (expected, "%s-full-charging-symbolic;", kind_str);
101 g_string_append_printf (expected, "%s-full-charging", kind_str);
102- check_icon_names (device, expected->str);
103+ EXPECT_ICON_NAMES_EQ(expected->str, device);
104 g_string_truncate (expected, 0);
105
106 // charging, 50%
107@@ -354,7 +366,7 @@
108 g_string_append_printf (expected, "gpm-%s-060-charging;", kind_str);
109 g_string_append_printf (expected, "%s-good-charging-symbolic;", kind_str);
110 g_string_append_printf (expected, "%s-good-charging", kind_str);
111- check_icon_names (device, expected->str);
112+ EXPECT_ICON_NAMES_EQ(expected->str, device);
113 g_string_truncate (expected, 0);
114
115 // charging, 25%
116@@ -364,11 +376,11 @@
117 NULL);
118 g_string_append_printf (expected, "%s-030-charging;", kind_str);
119 g_string_append_printf (expected, "gpm-%s-030-charging;", kind_str);
120- g_string_append_printf (expected, "%s-020-charging;", kind_str);
121- g_string_append_printf (expected, "gpm-%s-020-charging;", kind_str);
122+ g_string_append_printf (expected, "%s-040-charging;", kind_str);
123+ g_string_append_printf (expected, "gpm-%s-040-charging;", kind_str);
124 g_string_append_printf (expected, "%s-low-charging-symbolic;", kind_str);
125 g_string_append_printf (expected, "%s-low-charging", kind_str);
126- check_icon_names (device, expected->str);
127+ EXPECT_ICON_NAMES_EQ(expected->str, device);
128 g_string_truncate (expected, 0);
129
130 // charging, 5%
131@@ -382,7 +394,7 @@
132 g_string_append_printf (expected, "gpm-%s-000-charging;", kind_str);
133 g_string_append_printf (expected, "%s-caution-charging-symbolic;", kind_str);
134 g_string_append_printf (expected, "%s-caution-charging", kind_str);
135- check_icon_names (device, expected->str);
136+ EXPECT_ICON_NAMES_EQ(expected->str, device);
137 g_string_truncate (expected, 0);
138
139 // discharging, 95%
140@@ -394,7 +406,7 @@
141 g_string_append_printf (expected, "gpm-%s-100;", kind_str);
142 g_string_append_printf (expected, "%s-full-symbolic;", kind_str);
143 g_string_append_printf (expected, "%s-full", kind_str);
144- check_icon_names (device, expected->str);
145+ EXPECT_ICON_NAMES_EQ(expected->str, device);
146 g_string_truncate (expected, 0);
147
148 // discharging, 85%
149@@ -408,7 +420,7 @@
150 g_string_append_printf (expected, "gpm-%s-080;", kind_str);
151 g_string_append_printf (expected, "%s-full-symbolic;", kind_str);
152 g_string_append_printf (expected, "%s-full", kind_str);
153- check_icon_names (device, expected->str);
154+ EXPECT_ICON_NAMES_EQ(expected->str, device);
155 g_string_truncate (expected, 0);
156
157 // discharging, 50% -- 1 hour left
158@@ -423,7 +435,7 @@
159 g_string_append_printf (expected, "gpm-%s-060;", kind_str);
160 g_string_append_printf (expected, "%s-good-symbolic;", kind_str);
161 g_string_append_printf (expected, "%s-good", kind_str);
162- check_icon_names (device, expected->str);
163+ EXPECT_ICON_NAMES_EQ(expected->str, device);
164 g_string_truncate (expected, 0);
165
166 // discharging, 25% -- 1 hour left
167@@ -434,11 +446,11 @@
168 NULL);
169 g_string_append_printf (expected, "%s-030;", kind_str);
170 g_string_append_printf (expected, "gpm-%s-030;", kind_str);
171- g_string_append_printf (expected, "%s-020;", kind_str);
172- g_string_append_printf (expected, "gpm-%s-020;", kind_str);
173+ g_string_append_printf (expected, "%s-040;", kind_str);
174+ g_string_append_printf (expected, "gpm-%s-040;", kind_str);
175 g_string_append_printf (expected, "%s-low-symbolic;", kind_str);
176 g_string_append_printf (expected, "%s-low", kind_str);
177- check_icon_names (device, expected->str);
178+ EXPECT_ICON_NAMES_EQ(expected->str, device);
179 g_string_truncate (expected, 0);
180
181 // discharging, 25% -- 15 minutes left
182@@ -449,11 +461,11 @@
183 NULL);
184 g_string_append_printf (expected, "%s-030;", kind_str);
185 g_string_append_printf (expected, "gpm-%s-030;", kind_str);
186- g_string_append_printf (expected, "%s-020;", kind_str);
187- g_string_append_printf (expected, "gpm-%s-020;", kind_str);
188+ g_string_append_printf (expected, "%s-040;", kind_str);
189+ g_string_append_printf (expected, "gpm-%s-040;", kind_str);
190 g_string_append_printf (expected, "%s-low-symbolic;", kind_str);
191 g_string_append_printf (expected, "%s-low", kind_str);
192- check_icon_names (device, expected->str);
193+ EXPECT_ICON_NAMES_EQ(expected->str, device);
194 g_string_truncate (expected, 0);
195
196 // discharging, 5% -- 1 hour left
197@@ -468,7 +480,7 @@
198 g_string_append_printf (expected, "gpm-%s-000;", kind_str);
199 g_string_append_printf (expected, "%s-caution-symbolic;", kind_str);
200 g_string_append_printf (expected, "%s-caution", kind_str);
201- check_icon_names (device, expected->str);
202+ EXPECT_ICON_NAMES_EQ(expected->str, device);
203 g_string_truncate (expected, 0);
204
205 // discharging, 5% -- 15 minutes left
206@@ -483,7 +495,7 @@
207 g_string_append_printf (expected, "gpm-%s-000;", kind_str);
208 g_string_append_printf (expected, "%s-caution-symbolic;", kind_str);
209 g_string_append_printf (expected, "%s-caution", kind_str);
210- check_icon_names (device, expected->str);
211+ EXPECT_ICON_NAMES_EQ(expected->str, device);
212 g_string_truncate (expected, 0);
213
214 // state unknown
215@@ -493,7 +505,7 @@
216 g_string_append_printf (expected, "%s-missing-symbolic;", kind_str);
217 g_string_append_printf (expected, "gpm-%s-missing;", kind_str);
218 g_string_append_printf (expected, "%s-missing", kind_str);
219- check_icon_names (device, expected->str);
220+ EXPECT_ICON_NAMES_EQ(expected->str, device);
221 g_string_truncate (expected, 0);
222 }
223 g_string_free (expected, TRUE);

Subscribers

People subscribed via source and target branches