aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-11-06 18:28:32 -0600
committerCharles Kerr <charles.kerr@canonical.com>2012-11-06 18:28:32 -0600
commit7ebd1bec24a732a0f7069e727ff4036f6b925e99 (patch)
treea6c0d6c2b9e04ce2e93612a947f2d390045aea7e /tests
parentab006f93c2bf00a3bb7b33cebf26a12e46821fbb (diff)
downloadayatana-indicator-datetime-7ebd1bec24a732a0f7069e727ff4036f6b925e99.tar.gz
ayatana-indicator-datetime-7ebd1bec24a732a0f7069e727ff4036f6b925e99.tar.bz2
ayatana-indicator-datetime-7ebd1bec24a732a0f7069e727ff4036f6b925e99.zip
add Google Test scaffolding to indicator-datetime: autotools rules, support for finding the uninstalled copy of the gsettings schema, and a 'hello world' test.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am52
-rw-r--r--tests/Makefile.am.strings38
-rw-r--r--tests/test-indicator.cc93
3 files changed, 183 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e69de29..cc3b52a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -0,0 +1,52 @@
+TESTS =
+CLEANFILES =
+BUILT_SOURCES =
+check_PROGRAMS =
+
+###
+###
+###
+
+# stock UMB tests on user-visible strings
+include $(srcdir)/Makefile.am.strings
+
+check_LIBRARIES = libgtest.a
+nodist_libgtest_a_SOURCES = \
+ $(GTEST_SOURCE)/src/gtest-all.cc \
+ $(GTEST_SOURCE)/src/gtest_main.cc
+
+AM_CPPFLAGS = $(GTEST_CPPFLAGS) -I${top_srcdir}/src -Wall -Werror
+AM_CXXFLAGS = $(GTEST_CXXFLAGS)
+
+###
+###
+###
+
+TEST_LIBS = \
+ $(top_builddir)/src/.libs/libdatetime.so \
+ $(INDICATOR_LIBS) \
+ $(COVERAGE_LDFLAGS) \
+ libgtest.a
+
+TEST_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ $(INDICATOR_CFLAGS)
+
+BUILT_SOURCES += gschemas.compiled
+CLEANFILES += gschemas.compiled
+gschemas.compiled: Makefile
+ @glib-compile-schemas --targetdir=$(abs_builddir) $(top_builddir)/data
+
+###
+###
+###
+
+TESTS += test-indicator
+check_PROGRAMS += test-indicator
+test_indicator_SOURCES = test-indicator.cc
+test_indicator_LDADD = $(TEST_LIBS)
+test_indicator_CPPFLAGS = $(TEST_CPPFLAGS) -DSCHEMA_DIR="\"$(top_builddir)/tests/\""
+
+###
+###
+###
diff --git a/tests/Makefile.am.strings b/tests/Makefile.am.strings
new file mode 100644
index 0000000..26a23a8
--- /dev/null
+++ b/tests/Makefile.am.strings
@@ -0,0 +1,38 @@
+TESTS += \
+ test-ellipsis \
+ test-space-ellipsis \
+ test-ascii-quotes
+
+#####
+# Tests for there being proper ellipsis instead of three periods in a row
+#####
+test-ellipsis: $(top_srcdir)/po
+ @echo "#!/bin/bash" > $@
+ @echo "(cd $(top_srcdir)/po && make $(GETTEXT_PACKAGE).pot)" >> $@
+ @echo "grep -c -e \"^msgid.*\.\.\.\\\"\" $(top_srcdir)/po/$(GETTEXT_PACKAGE).pot > /dev/null && echo \"Ellipsis found in user visible strings\" >&2 && exit 1" >> $@
+ @echo "exit 0" >> $@
+ @chmod +x $@
+
+#####
+# Tests for there being a space before an ellipsis
+#####
+test-space-ellipsis: $(top_srcdir)/po
+ @echo "#!/bin/bash" > $@
+ @echo "(cd $(top_srcdir)/po && make $(GETTEXT_PACKAGE).pot)" >> $@
+ @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" >> $@
+ @echo "exit 0" >> $@
+ @chmod +x $@
+
+#####
+# Tests for ASCII quote types
+#####
+test-ascii-quotes: $(top_srcdir)/po
+ @echo "#!/bin/bash" > $@
+ @echo "(cd $(top_srcdir)/po && make $(GETTEXT_PACKAGE).pot)" >> $@
+ @echo "grep -c -e \"^msgid \\\".*'.*\\\"\" $(top_srcdir)/po/$(GETTEXT_PACKAGE).pot > /dev/null && echo \"ASCII apostrophy found in user visible strings\" >&2 && exit 1" >> $@
+ @echo "grep -c -e \"^msgid \\\".*\\\".*\\\"\" $(top_srcdir)/po/$(GETTEXT_PACKAGE).pot > /dev/null && echo \"ASCII quote found in user visible strings\" >&2 && exit 1" >> $@
+ @echo "grep -c -e \"^msgid \\\".*\\\`.*\\\"\" $(top_srcdir)/po/$(GETTEXT_PACKAGE).pot > /dev/null && echo \"ASCII backtick found in user visible strings\" >&2 && exit 1" >> $@
+ @echo "exit 0" >> $@
+ @chmod +x $@
+
+CLEANFILES += $(TESTS)
diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc
new file mode 100644
index 0000000..67a2780
--- /dev/null
+++ b/tests/test-indicator.cc
@@ -0,0 +1,93 @@
+/*
+Copyright 2012 Canonical Ltd.
+
+Authors:
+ Charles Kerr <charles.kerr@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <gtest/gtest.h>
+
+#include <glib-object.h>
+
+/***
+****
+***/
+
+namespace
+{
+ void ensure_glib_initialized ()
+ {
+ static bool initialized = false;
+
+ if (G_UNLIKELY(!initialized))
+ {
+ initialized = true;
+ g_type_init();
+ g_setenv ("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE);
+ }
+ }
+}
+
+/***
+****
+***/
+
+class IndicatorTest : public ::testing::Test
+{
+ private:
+
+ guint log_handler_id;
+
+ int log_count_ipower_actual;
+
+ static void log_count_func (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer user_data)
+ {
+ reinterpret_cast<IndicatorTest*>(user_data)->log_count_ipower_actual++;
+ }
+
+ protected:
+
+ int log_count_ipower_expected;
+
+ protected:
+
+ virtual void SetUp()
+ {
+ const GLogLevelFlags flags = GLogLevelFlags(G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING);
+ log_handler_id = g_log_set_handler ("Indicator-Power", flags, log_count_func, this);
+ log_count_ipower_expected = 0;
+ log_count_ipower_actual = 0;
+
+ ensure_glib_initialized ();
+ }
+
+ virtual void TearDown()
+ {
+ ASSERT_EQ (log_count_ipower_expected, log_count_ipower_actual);
+ g_log_remove_handler ("Indicator-Power", log_handler_id);
+ }
+};
+
+/***
+****
+***/
+
+TEST_F(IndicatorTest, HelloWorld)
+{
+ ASSERT_TRUE (TRUE);
+}