Merge lp:~charlesk/indicator-datetime/lp-1256061 into lp:indicator-datetime/14.04

Proposed by Charles Kerr on 2013-12-13
Status: Merged
Approved by: Ted Gould on 2013-12-13
Approved revision: 301
Merged at revision: 291
Proposed branch: lp:~charlesk/indicator-datetime/lp-1256061
Merge into: lp:indicator-datetime/14.04
Diff against target: 383 lines (+271/-21)
6 files modified
debian/control (+3/-0)
src/CMakeLists.txt (+1/-1)
src/utils.c (+30/-17)
tests/CMakeLists.txt (+19/-3)
tests/glib-fixture.h (+120/-0)
tests/test-formatter.cc (+98/-0)
To merge this branch: bzr merge lp:~charlesk/indicator-datetime/lp-1256061
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve on 2013-12-13
Ted Gould (community) 2013-12-13 Approve on 2013-12-13
Review via email: mp+198968@code.launchpad.net

Description of the Change

Make the phone profile's header format sensitive to whether the phone is running in a 12h or 24h locale, and use a 12h or 24h notation accordingly.

To post a comment you must log in.
297. By Charles Kerr on 2013-12-13

in tests/, remove a couple of rules that got pulled in from the dev branch but aren't necessary here

298. By Charles Kerr on 2013-12-13

in test-formatter, the 12h/24h unit test doesn't need our gschema, so remove it from this MP

299. By Charles Kerr on 2013-12-13

let's see what g_warning jenkins found.

Charles Kerr (charlesk) wrote :

Looks like the tests are failing because they don't have 12h and 24h locales configured when the tests run. Adding hooks into debian/ to ensure that's set up at build time....

300. By Charles Kerr on 2013-12-13

ensure that we have 12h and 24h locales installed at build time -- the unit tests need them

301. By Charles Kerr on 2013-12-13

try adding a build-dep of language-pack-en-base instead of configuring the locales in the unit test sandbox. (h/t seb)

Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2013-10-18 19:22:54 +0000
3+++ debian/control 2013-12-13 18:21:21 +0000
4@@ -2,12 +2,14 @@
5 Section: misc
6 Priority: optional
7 Maintainer: Ubuntu Desktop Team <ubuntu-desktop@lists.ubuntu.com>
8+# language-pack-en-base is for the unit tests s.t. we can test in 12h and 24h locales
9 Build-Depends: cmake,
10 dbus,
11 debhelper (>= 9),
12 dh-translations,
13 intltool (>= 0.35.0),
14 gnome-common,
15+ language-pack-en-base,
16 libxorg-gtest-dev,
17 libgtest-dev,
18 libglib2.0-dev (>= 2.35.4),
19@@ -25,6 +27,7 @@
20 libgnome-control-center-dev,
21 libtimezonemap1-dev,
22 liburl-dispatcher1-dev,
23+ locales,
24 Standards-Version: 3.9.3
25 Homepage: https://launchpad.net/indicator-datetime
26 # If you aren't a member of ~indicator-applet-developers but need to upload
27
28=== modified file 'src/CMakeLists.txt'
29--- src/CMakeLists.txt 2013-10-30 21:58:04 +0000
30+++ src/CMakeLists.txt 2013-12-13 18:21:21 +0000
31@@ -1,4 +1,4 @@
32-set (SERVICE_LIB "libindicatordatetimeservice")
33+set (SERVICE_LIB "indicatordatetimeservice")
34 set (SERVICE_EXEC "indicator-datetime-service")
35
36 add_definitions (-DTIMEZONE_FILE="/etc/timezone"
37
38=== modified file 'src/utils.c'
39--- src/utils.c 2013-10-30 22:29:43 +0000
40+++ src/utils.c 2013-12-13 18:21:21 +0000
41@@ -188,6 +188,31 @@
42 ****
43 ***/
44
45+static const gchar *
46+get_default_header_time_format (gboolean twelvehour, gboolean show_seconds)
47+{
48+ const gchar * fmt;
49+
50+ if (twelvehour && show_seconds)
51+ /* TRANSLATORS: a strftime(3) format for 12hr time w/seconds */
52+ fmt = T_("%l:%M:%S %p");
53+ else if (twelvehour)
54+ /* TRANSLATORS: a strftime(3) format for 12hr time */
55+ fmt = T_("%l:%M %p");
56+ else if (show_seconds)
57+ /* TRANSLATORS: a strftime(3) format for 24hr time w/seconds */
58+ fmt = T_("%H:%M:%S");
59+ else
60+ /* TRANSLATORS: a strftime(3) format for 24hr time */
61+ fmt = T_("%H:%M");
62+
63+ return fmt;
64+}
65+
66+/***
67+****
68+***/
69+
70 typedef enum
71 {
72 DATE_PROXIMITY_TODAY,
73@@ -293,8 +318,10 @@
74 const gchar*
75 get_terse_header_time_format_string (void)
76 {
77- /* a strftime(3) fmt string for a H:MM 12 hour time, eg "6:59 PM" */
78- return T_("%l:%M %p");
79+ const gboolean twelvehour = is_locale_12h ();
80+ const gboolean show_seconds = FALSE;
81+
82+ return get_default_header_time_format (twelvehour, show_seconds);
83 }
84
85 const gchar *
86@@ -374,7 +401,6 @@
87 {
88 gboolean twelvehour;
89 gboolean show_seconds;
90- const gchar * fmt;
91
92 g_return_val_if_fail (settings != NULL, NULL);
93
94@@ -395,20 +421,7 @@
95 break;
96 }
97
98- if (twelvehour && show_seconds)
99- /* TRANSLATORS: a strftime(3) format for 12hr time w/seconds */
100- fmt = T_("%l:%M:%S %p");
101- else if (twelvehour)
102- /* TRANSLATORS: a strftime(3) format for 12hr time */
103- fmt = T_("%l:%M %p");
104- else if (show_seconds)
105- /* TRANSLATORS: a strftime(3) format for 24hr time w/seconds */
106- fmt = T_("%H:%M:%S");
107- else
108- /* TRANSLATORS: a strftime(3) format for 24hr time */
109- fmt = T_("%H:%M");
110-
111- return fmt;
112+ return get_default_header_time_format (twelvehour, show_seconds);
113 }
114
115 gchar *
116
117=== modified file 'tests/CMakeLists.txt'
118--- tests/CMakeLists.txt 2013-10-18 19:22:54 +0000
119+++ tests/CMakeLists.txt 2013-12-13 18:21:21 +0000
120@@ -1,3 +1,12 @@
121+# build libgtest
122+add_library (gtest STATIC
123+ ${GTEST_SOURCE_DIR}/gtest-all.cc
124+ ${GTEST_SOURCE_DIR}/gtest_main.cc)
125+set_target_properties (gtest PROPERTIES INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES} ${GTEST_INCLUDE_DIR})
126+set_target_properties (gtest PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS} -w)
127+
128+SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -g ${CC_WARNING_ARGS}")
129+
130 # build the necessary schemas
131 set_directory_properties (PROPERTIES
132 ADDITIONAL_MAKE_CLEAN_FILES gschemas.compiled)
133@@ -12,12 +21,19 @@
134 OUTPUT_VARIABLE COMPILE_SCHEMA_EXECUTABLE
135 OUTPUT_STRIP_TRAILING_WHITESPACE)
136 add_custom_command (OUTPUT gschemas.compiled
137- DEPENDS ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.session.gschema.xml
138+ DEPENDS ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.datetime.gschema.xml
139 COMMAND cp -f ${CMAKE_SOURCE_DIR}/data/*gschema.xml ${SCHEMA_DIR}
140 COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR})
141
142-# look for hearder in our src dir, and also in the directories where we autogenerate files...
143+# look for headers in our src dir, and also in the directories where we autogenerate files...
144 include_directories (${CMAKE_SOURCE_DIR}/src)
145-include_directories (${CMAKE_CURRENT_BINARY_DIR} ${SERVICE_INCLUDE_DIRS})
146+include_directories (${CMAKE_CURRENT_BINARY_DIR})
147+include_directories (${SERVICE_DEPS_INCLUDE_DIRS})
148
149+# test-formatter
150+set (TEST_NAME test-formatter)
151+add_executable (${TEST_NAME} test-formatter.cc)
152+add_test (${TEST_NAME} ${TEST_NAME})
153+add_dependencies (${TEST_NAME} libindicatordatetimeservice)
154+target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS})
155
156
157=== added file 'tests/glib-fixture.h'
158--- tests/glib-fixture.h 1970-01-01 00:00:00 +0000
159+++ tests/glib-fixture.h 2013-12-13 18:21:21 +0000
160@@ -0,0 +1,120 @@
161+/*
162+ * Copyright 2013 Canonical Ltd.
163+ *
164+ * Authors:
165+ * Charles Kerr <charles.kerr@canonical.com>
166+ *
167+ * This program is free software: you can redistribute it and/or modify it
168+ * under the terms of the GNU General Public License version 3, as published
169+ * by the Free Software Foundation.
170+ *
171+ * This program is distributed in the hope that it will be useful, but
172+ * WITHOUT ANY WARRANTY; without even the implied warranties of
173+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
174+ * PURPOSE. See the GNU General Public License for more details.
175+ *
176+ * You should have received a copy of the GNU General Public License along
177+ * with this program. If not, see <http://www.gnu.org/licenses/>.
178+ */
179+
180+#include <map>
181+
182+#include <glib.h>
183+#include <glib/gstdio.h>
184+#include <gio/gio.h>
185+
186+#include <gtest/gtest.h>
187+
188+class GlibFixture : public ::testing::Test
189+{
190+ private:
191+
192+ GLogFunc realLogHandler;
193+
194+ protected:
195+
196+ std::map<GLogLevelFlags,int> logCounts;
197+
198+ void testLogCount (GLogLevelFlags log_level, int expected G_GNUC_UNUSED)
199+ {
200+ ASSERT_EQ (expected, logCounts[log_level]);
201+
202+ logCounts.erase (log_level);
203+ }
204+
205+ private:
206+
207+ static void default_log_handler (const gchar * log_domain,
208+ GLogLevelFlags log_level,
209+ const gchar * message,
210+ gpointer self)
211+ {
212+ g_print ("%s - %d - %s", log_domain, (int)log_level, message);
213+ static_cast<GlibFixture*>(self)->logCounts[log_level]++;
214+ }
215+
216+ protected:
217+
218+ virtual void SetUp ()
219+ {
220+ loop = g_main_loop_new (NULL, FALSE);
221+
222+ g_log_set_default_handler (default_log_handler, this);
223+
224+ // only use local, temporary settings
225+ g_setenv ("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE);
226+ g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
227+ g_debug ("SCHEMA_DIR is %s", SCHEMA_DIR);
228+ }
229+
230+ virtual void TearDown()
231+ {
232+ // confirm there aren't any unexpected log messages
233+ ASSERT_EQ (0, logCounts[G_LOG_LEVEL_ERROR]);
234+ ASSERT_EQ (0, logCounts[G_LOG_LEVEL_CRITICAL]);
235+ ASSERT_EQ (0, logCounts[G_LOG_LEVEL_WARNING]);
236+ ASSERT_EQ (0, logCounts[G_LOG_LEVEL_MESSAGE]);
237+ ASSERT_EQ (0, logCounts[G_LOG_LEVEL_INFO]);
238+
239+ // revert to glib's log handler
240+ g_log_set_default_handler (realLogHandler, this);
241+
242+ g_clear_pointer (&loop, g_main_loop_unref);
243+ }
244+
245+ private:
246+
247+ static gboolean
248+ wait_for_signal__timeout (gpointer name)
249+ {
250+ g_error ("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name);
251+ return G_SOURCE_REMOVE;
252+ }
253+
254+ protected:
255+
256+ /* convenience func to loop while waiting for a GObject's signal */
257+ void wait_for_signal (gpointer o, const gchar * signal, const int timeout_seconds=5)
258+ {
259+ // wait for the signal or for timeout, whichever comes first
260+ guint handler_id = g_signal_connect_swapped (o, signal,
261+ G_CALLBACK(g_main_loop_quit),
262+ loop);
263+ gulong timeout_id = g_timeout_add_seconds (timeout_seconds,
264+ wait_for_signal__timeout,
265+ loop);
266+ g_main_loop_run (loop);
267+ g_source_remove (timeout_id);
268+ g_signal_handler_disconnect (o, handler_id);
269+ }
270+
271+ /* convenience func to loop for N msec */
272+ void wait_msec (int msec=50)
273+ {
274+ guint id = g_timeout_add (msec, (GSourceFunc)g_main_loop_quit, loop);
275+ g_main_loop_run (loop);
276+ g_source_remove (id);
277+ }
278+
279+ GMainLoop * loop;
280+};
281
282=== added file 'tests/test-formatter.cc'
283--- tests/test-formatter.cc 1970-01-01 00:00:00 +0000
284+++ tests/test-formatter.cc 2013-12-13 18:21:21 +0000
285@@ -0,0 +1,98 @@
286+
287+/*
288+ * Copyright 2013 Canonical Ltd.
289+ *
290+ * Authors:
291+ * Charles Kerr <charles.kerr@canonical.com>
292+ *
293+ * This program is free software: you can redistribute it and/or modify it
294+ * under the terms of the GNU General Public License version 3, as published
295+ * by the Free Software Foundation.
296+ *
297+ * This program is distributed in the hope that it will be useful, but
298+ * WITHOUT ANY WARRANTY; without even the implied warranties of
299+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
300+ * PURPOSE. See the GNU General Public License for more details.
301+ *
302+ * You should have received a copy of the GNU General Public License along
303+ * with this program. If not, see <http://www.gnu.org/licenses/>.
304+ */
305+
306+#include <langinfo.h>
307+#include <locale.h>
308+
309+#include <glib/gi18n.h>
310+
311+#include "utils.h"
312+
313+#include "glib-fixture.h"
314+
315+/***
316+****
317+***/
318+
319+class FormatterFixture: public GlibFixture
320+{
321+ private:
322+
323+ typedef GlibFixture super;
324+ gchar * original_locale = nullptr;
325+
326+ protected:
327+
328+ virtual void SetUp ()
329+ {
330+ super::SetUp ();
331+
332+ original_locale = g_strdup (setlocale (LC_TIME, NULL));
333+ }
334+
335+ virtual void TearDown ()
336+ {
337+ setlocale (LC_TIME, original_locale);
338+ g_clear_pointer (&original_locale, g_free);
339+
340+ super::TearDown ();
341+ }
342+
343+ bool SetLocale (const char * expected_locale, const char * name)
344+ {
345+ setlocale (LC_TIME, expected_locale);
346+ const char * actual_locale = setlocale (LC_TIME, NULL);
347+ if (!g_strcmp0 (expected_locale, actual_locale))
348+ {
349+ return true;
350+ }
351+ else
352+ {
353+ g_warning ("Unable to set locale to %s; skipping %s locale tests.", expected_locale, name);
354+ return false;
355+ }
356+ }
357+
358+ inline bool Set24hLocale () { return SetLocale ("C", "24h"); }
359+ inline bool Set12hLocale () { return SetLocale ("en_US.utf8", "12h"); }
360+};
361+
362+
363+/**
364+ * Test the phone header format
365+ */
366+TEST_F (FormatterFixture, TestPhoneHeader)
367+{
368+ // test the default value in a 24h locale
369+ if (Set24hLocale ())
370+ {
371+ const gchar * format = get_terse_header_time_format_string ();
372+ ASSERT_NE (nullptr, format);
373+ ASSERT_STREQ ("%H:%M", format);
374+ }
375+
376+ // test the default value in a 12h locale
377+ if (Set12hLocale ())
378+ {
379+ const gchar * format = get_terse_header_time_format_string ();
380+ ASSERT_NE (nullptr, format);
381+ ASSERT_STREQ ("%l:%M %p", format);
382+ }
383+}

Subscribers

People subscribed via source and target branches