Merge lp:~charlesk/indicator-datetime/lp-985060 into lp:indicator-datetime/13.04

Proposed by Charles Kerr
Status: Merged
Approved by: Lars Karlitski
Approved revision: 195
Merged at revision: 196
Proposed branch: lp:~charlesk/indicator-datetime/lp-985060
Merge into: lp:indicator-datetime/13.04
Diff against target: 333 lines (+275/-5)
6 files modified
Makefile.am (+7/-5)
configure.ac (+22/-0)
m4/gtest.m4 (+63/-0)
tests/Makefile.am (+52/-0)
tests/Makefile.am.strings (+38/-0)
tests/test-indicator.cc (+93/-0)
To merge this branch: bzr merge lp:~charlesk/indicator-datetime/lp-985060
Reviewer Review Type Date Requested Status
Lars Karlitski (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+133161@code.launchpad.net

Commit message

Add scaffolding for Google Tests

Description of the change

Add scaffolding for Google Tests.

(Tests sold separately.)

This scaffolding is loosely based on indicator-power's test scaffolding.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Lars Karlitski (larsu) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile.am'
2--- Makefile.am 2012-03-27 22:17:43 +0000
3+++ Makefile.am 2012-11-07 00:35:23 +0000
4@@ -1,10 +1,12 @@
5 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
6
7-SUBDIRS = \
8- src \
9- data \
10- tests \
11- po
12+SUBDIRS = po data src
13+
14+if BUILD_TESTS
15+SUBDIRS += tests
16+# build src first
17+tests: src
18+endif
19
20 DISTCHECK_CONFIGURE_FLAGS = --enable-localinstall
21
22
23=== modified file 'configure.ac'
24--- configure.ac 2012-10-04 13:09:42 +0000
25+++ configure.ac 2012-11-07 00:35:23 +0000
26@@ -20,6 +20,7 @@
27 # Check for programs
28 AC_PROG_CC
29 AM_PROG_CC_C_O
30+AC_PROG_CXX
31 AC_HEADER_STDC
32
33 # Initialize libtool
34@@ -179,6 +180,26 @@
35 fi
36 AC_SUBST(DBUSSERVICEDIR)
37
38+###########################
39+# Google Test framework
40+###########################
41+
42+AC_ARG_ENABLE([tests],
43+ [AS_HELP_STRING([--disable-tests], [Disable test scripts and tools (default=auto)])],
44+ [enable_tests=${enableval}],
45+ [enable_tests=auto])
46+if test "x$enable_tests" != "xno"; then
47+ m4_include([m4/gtest.m4])
48+ CHECK_GTEST
49+ CHECK_XORG_GTEST
50+ if test "x$enable_tests" = "xauto"; then
51+ enable_tests=${have_gtest}
52+ elif test "x$enable_tests" = "xyes" && test "x$have_gtest" != "xyes"; then
53+ AC_MSG_ERROR([tests were requested but gtest is not installed.])
54+ fi
55+fi
56+AM_CONDITIONAL([BUILD_TESTS],[test "x$enable_tests" = "xyes"])
57+
58 ##############################
59 # Custom Junk
60 ##############################
61@@ -232,5 +253,6 @@
62 Indicator Dir: $INDICATORDIR
63 CC Panel: $have_ccpanel
64 CC Panel Dir: $CCPANELDIR
65+ Unit Tests: $enable_tests
66 gcov: $use_gcov
67 ])
68
69=== added file 'm4/gtest.m4'
70--- m4/gtest.m4 1970-01-01 00:00:00 +0000
71+++ m4/gtest.m4 2012-11-07 00:35:23 +0000
72@@ -0,0 +1,63 @@
73+# Copyright (C) 2012 Canonical, Ltd.
74+#
75+# Permission is hereby granted, free of charge, to any person obtaining a copy
76+# of this software and associated documentation files (the "Software"), to deal
77+# in the Software without restriction, including without limitation the rights
78+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
79+# copies of the Software, and to permit persons to whom the Software is
80+# furnished to do so, subject to the following conditions:
81+#
82+# The above copyright notice and this permission notice (including the next
83+# paragraph) shall be included in all copies or substantial portions of the
84+# Software.
85+#
86+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
87+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
88+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
89+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
90+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
91+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
92+# SOFTWARE.
93+
94+# Checks whether the gtest source is available on the system. Allows for
95+# adjusting the include and source path. Sets have_gtest=yes if the source is
96+# present. Sets GTEST_CPPFLAGS and GTEST_SOURCE to the preprocessor flags and
97+# source location respectively.
98+AC_DEFUN([CHECK_GTEST],
99+[
100+ AC_ARG_WITH([gtest-include-path],
101+ [AS_HELP_STRING([--with-gtest-include-path],
102+ [location of the Google test headers])],
103+ [GTEST_CPPFLAGS="-I$withval"])
104+
105+ AC_ARG_WITH([gtest-source-path],
106+ [AS_HELP_STRING([--with-gtest-source-path],
107+ [location of the Google test sources, defaults to /usr/src/gtest])],
108+ [GTEST_SOURCE="$withval"],
109+ [GTEST_SOURCE="/usr/src/gtest"])
110+
111+ GTEST_CPPFLAGS="$GTEST_CPPFLAGS -I$GTEST_SOURCE"
112+
113+ AC_LANG_PUSH([C++])
114+
115+ tmp_CPPFLAGS="$CPPFLAGS"
116+ CPPFLAGS="$CPPFLAGS $GTEST_CPPFLAGS"
117+
118+ AC_CHECK_HEADER([gtest/gtest.h])
119+
120+ CPPFLAGS="$tmp_CPPFLAGS"
121+
122+ AC_LANG_POP
123+
124+ AC_CHECK_FILES([$GTEST_SOURCE/src/gtest-all.cc]
125+ [$GTEST_SOURCE/src/gtest_main.cc],
126+ [have_gtest_source=yes],
127+ [have_gtest_source=no])
128+
129+ AS_IF([test "x$ac_cv_header_gtest_gtest_h" = xyes -a \
130+ "x$have_gtest_source" = xyes],
131+ [have_gtest=yes]
132+ [AC_SUBST(GTEST_CPPFLAGS)]
133+ [AC_SUBST(GTEST_SOURCE)],
134+ [have_gtest=no])
135+]) # CHECK_GTEST
136
137=== modified file 'tests/Makefile.am'
138--- tests/Makefile.am 2010-01-05 04:32:37 +0000
139+++ tests/Makefile.am 2012-11-07 00:35:23 +0000
140@@ -0,0 +1,52 @@
141+TESTS =
142+CLEANFILES =
143+BUILT_SOURCES =
144+check_PROGRAMS =
145+
146+###
147+###
148+###
149+
150+# stock UMB tests on user-visible strings
151+include $(srcdir)/Makefile.am.strings
152+
153+check_LIBRARIES = libgtest.a
154+nodist_libgtest_a_SOURCES = \
155+ $(GTEST_SOURCE)/src/gtest-all.cc \
156+ $(GTEST_SOURCE)/src/gtest_main.cc
157+
158+AM_CPPFLAGS = $(GTEST_CPPFLAGS) -I${top_srcdir}/src -Wall -Werror
159+AM_CXXFLAGS = $(GTEST_CXXFLAGS)
160+
161+###
162+###
163+###
164+
165+TEST_LIBS = \
166+ $(top_builddir)/src/.libs/libdatetime.so \
167+ $(INDICATOR_LIBS) \
168+ $(COVERAGE_LDFLAGS) \
169+ libgtest.a
170+
171+TEST_CPPFLAGS = \
172+ $(AM_CPPFLAGS) \
173+ $(INDICATOR_CFLAGS)
174+
175+BUILT_SOURCES += gschemas.compiled
176+CLEANFILES += gschemas.compiled
177+gschemas.compiled: Makefile
178+ @glib-compile-schemas --targetdir=$(abs_builddir) $(top_builddir)/data
179+
180+###
181+###
182+###
183+
184+TESTS += test-indicator
185+check_PROGRAMS += test-indicator
186+test_indicator_SOURCES = test-indicator.cc
187+test_indicator_LDADD = $(TEST_LIBS)
188+test_indicator_CPPFLAGS = $(TEST_CPPFLAGS) -DSCHEMA_DIR="\"$(top_builddir)/tests/\""
189+
190+###
191+###
192+###
193
194=== added file 'tests/Makefile.am.strings'
195--- tests/Makefile.am.strings 1970-01-01 00:00:00 +0000
196+++ tests/Makefile.am.strings 2012-11-07 00:35:23 +0000
197@@ -0,0 +1,38 @@
198+TESTS += \
199+ test-ellipsis \
200+ test-space-ellipsis \
201+ test-ascii-quotes
202+
203+#####
204+# Tests for there being proper ellipsis instead of three periods in a row
205+#####
206+test-ellipsis: $(top_srcdir)/po
207+ @echo "#!/bin/bash" > $@
208+ @echo "(cd $(top_srcdir)/po && make $(GETTEXT_PACKAGE).pot)" >> $@
209+ @echo "grep -c -e \"^msgid.*\.\.\.\\\"\" $(top_srcdir)/po/$(GETTEXT_PACKAGE).pot > /dev/null && echo \"Ellipsis found in user visible strings\" >&2 && exit 1" >> $@
210+ @echo "exit 0" >> $@
211+ @chmod +x $@
212+
213+#####
214+# Tests for there being a space before an ellipsis
215+#####
216+test-space-ellipsis: $(top_srcdir)/po
217+ @echo "#!/bin/bash" > $@
218+ @echo "(cd $(top_srcdir)/po && make $(GETTEXT_PACKAGE).pot)" >> $@
219+ @echo "grep -c -e \"^msgid.* …\\\"\" $(top_srcdir)/po/$(GETTEXT_PACKAGE).pot > /dev/null && echo \"Space before ellipsis found in user visible strings\" >&2 && exit 1" >> $@
220+ @echo "exit 0" >> $@
221+ @chmod +x $@
222+
223+#####
224+# Tests for ASCII quote types
225+#####
226+test-ascii-quotes: $(top_srcdir)/po
227+ @echo "#!/bin/bash" > $@
228+ @echo "(cd $(top_srcdir)/po && make $(GETTEXT_PACKAGE).pot)" >> $@
229+ @echo "grep -c -e \"^msgid \\\".*'.*\\\"\" $(top_srcdir)/po/$(GETTEXT_PACKAGE).pot > /dev/null && echo \"ASCII apostrophy found in user visible strings\" >&2 && exit 1" >> $@
230+ @echo "grep -c -e \"^msgid \\\".*\\\".*\\\"\" $(top_srcdir)/po/$(GETTEXT_PACKAGE).pot > /dev/null && echo \"ASCII quote found in user visible strings\" >&2 && exit 1" >> $@
231+ @echo "grep -c -e \"^msgid \\\".*\\\`.*\\\"\" $(top_srcdir)/po/$(GETTEXT_PACKAGE).pot > /dev/null && echo \"ASCII backtick found in user visible strings\" >&2 && exit 1" >> $@
232+ @echo "exit 0" >> $@
233+ @chmod +x $@
234+
235+CLEANFILES += $(TESTS)
236
237=== added file 'tests/test-indicator.cc'
238--- tests/test-indicator.cc 1970-01-01 00:00:00 +0000
239+++ tests/test-indicator.cc 2012-11-07 00:35:23 +0000
240@@ -0,0 +1,93 @@
241+/*
242+Copyright 2012 Canonical Ltd.
243+
244+Authors:
245+ Charles Kerr <charles.kerr@canonical.com>
246+
247+This program is free software: you can redistribute it and/or modify it
248+under the terms of the GNU General Public License version 3, as published
249+by the Free Software Foundation.
250+
251+This program is distributed in the hope that it will be useful, but
252+WITHOUT ANY WARRANTY; without even the implied warranties of
253+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
254+PURPOSE. See the GNU General Public License for more details.
255+
256+You should have received a copy of the GNU General Public License along
257+with this program. If not, see <http://www.gnu.org/licenses/>.
258+*/
259+
260+#include <gtest/gtest.h>
261+
262+#include <glib-object.h>
263+
264+/***
265+****
266+***/
267+
268+namespace
269+{
270+ void ensure_glib_initialized ()
271+ {
272+ static bool initialized = false;
273+
274+ if (G_UNLIKELY(!initialized))
275+ {
276+ initialized = true;
277+ g_type_init();
278+ g_setenv ("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE);
279+ }
280+ }
281+}
282+
283+/***
284+****
285+***/
286+
287+class IndicatorTest : public ::testing::Test
288+{
289+ private:
290+
291+ guint log_handler_id;
292+
293+ int log_count_ipower_actual;
294+
295+ static void log_count_func (const gchar *log_domain,
296+ GLogLevelFlags log_level,
297+ const gchar *message,
298+ gpointer user_data)
299+ {
300+ reinterpret_cast<IndicatorTest*>(user_data)->log_count_ipower_actual++;
301+ }
302+
303+ protected:
304+
305+ int log_count_ipower_expected;
306+
307+ protected:
308+
309+ virtual void SetUp()
310+ {
311+ const GLogLevelFlags flags = GLogLevelFlags(G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING);
312+ log_handler_id = g_log_set_handler ("Indicator-Power", flags, log_count_func, this);
313+ log_count_ipower_expected = 0;
314+ log_count_ipower_actual = 0;
315+
316+ ensure_glib_initialized ();
317+ }
318+
319+ virtual void TearDown()
320+ {
321+ ASSERT_EQ (log_count_ipower_expected, log_count_ipower_actual);
322+ g_log_remove_handler ("Indicator-Power", log_handler_id);
323+ }
324+};
325+
326+/***
327+****
328+***/
329+
330+TEST_F(IndicatorTest, HelloWorld)
331+{
332+ ASSERT_TRUE (TRUE);
333+}

Subscribers

People subscribed via source and target branches