aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am38
-rw-r--r--tests/Makefile.am.strings38
-rw-r--r--tests/test-device.cc99
3 files changed, 175 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..87dd606
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,38 @@
+TESTS =
+CLEANFILES =
+check_PROGRAMS =
+
+AM_CPPFLAGS = $(GTEST_CPPFLAGS) -I${top_srcdir}/src -Wall -Werror
+AM_CXXFLAGS = $(GTEST_CXXFLAGS)
+
+###
+###
+###
+
+# stock UMB tests on user-visible strings
+include $(srcdir)/Makefile.am.strings
+
+###
+###
+###
+
+TESTS += test-device
+check_PROGRAMS += test-device
+test_device_SOURCES = test-device.cc
+test_device_LDADD = \
+ $(top_builddir)/src/libpower.la \
+ $(INDICATOR_LIBS) \
+ $(UPOWER_LIBS) \
+ $(COVERAGE_LDFLAGS) \
+ libgtest.a
+
+test_device_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ $(UPOWER_CFLAGS) \
+ $(INDICATOR_CFLAGS) \
+ $(COVERAGE_CFLAGS)
+
+check_LIBRARIES = libgtest.a
+nodist_libgtest_a_SOURCES = \
+ $(GTEST_SOURCE)/src/gtest-all.cc \
+ $(GTEST_SOURCE)/src/gtest_main.cc
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-device.cc b/tests/test-device.cc
new file mode 100644
index 0000000..02516f4
--- /dev/null
+++ b/tests/test-device.cc
@@ -0,0 +1,99 @@
+/*
+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 "device.h"
+
+namespace
+{
+ void ensure_glib_initialized ()
+ {
+ static bool initialized = false;
+
+ if (G_UNLIKELY(!initialized))
+ {
+ initialized = true;
+ g_type_init();
+ }
+ }
+}
+
+/***
+****
+***/
+
+TEST(DeviceTest, GObjectNew)
+{
+ ensure_glib_initialized ();
+
+ GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL));
+ ASSERT_TRUE (o != NULL);
+ ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(o));
+ g_clear_pointer (&o, g_object_unref);
+}
+
+TEST(DeviceTest, New)
+{
+ ensure_glib_initialized ();
+
+ IndicatorPowerDevice * device = indicator_power_device_new ("/object/path",
+ UP_DEVICE_KIND_BATTERY,
+ "icon",
+ 50.0,
+ UP_DEVICE_STATE_CHARGING,
+ 30);
+ ASSERT_TRUE (device != NULL);
+ ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));
+ ASSERT_EQ (indicator_power_device_get_kind(device), UP_DEVICE_KIND_BATTERY);
+ ASSERT_EQ (indicator_power_device_get_state(device), UP_DEVICE_STATE_CHARGING);
+ ASSERT_STREQ (indicator_power_device_get_object_path(device), "/object/path");
+ ASSERT_STREQ (indicator_power_device_get_icon(device), "icon");
+ ASSERT_EQ ((int)indicator_power_device_get_percentage(device), 50);
+ ASSERT_EQ (indicator_power_device_get_time(device), 30);
+
+ /* cleanup */
+ g_clear_pointer (&device, g_object_unref);
+}
+
+TEST(DeviceTest, NewFromVariant)
+{
+ ensure_glib_initialized ();
+
+ GVariant * variant = g_variant_new ("(susdut)",
+ "/object/path",
+ UP_DEVICE_KIND_BATTERY,
+ "icon",
+ 50.0,
+ UP_DEVICE_STATE_CHARGING,
+ 30);
+ IndicatorPowerDevice * device = indicator_power_device_new_from_variant (variant);
+ ASSERT_TRUE (variant != NULL);
+ ASSERT_TRUE (device != NULL);
+ ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));
+ ASSERT_EQ (indicator_power_device_get_kind(device), UP_DEVICE_KIND_BATTERY);
+ ASSERT_EQ (indicator_power_device_get_state(device), UP_DEVICE_STATE_CHARGING);
+ ASSERT_STREQ (indicator_power_device_get_object_path(device), "/object/path");
+ ASSERT_STREQ (indicator_power_device_get_icon(device), "icon");
+ ASSERT_EQ ((int)indicator_power_device_get_percentage(device), 50);
+ ASSERT_EQ (indicator_power_device_get_time(device), 30);
+
+ /* cleanup */
+ g_clear_pointer (&device, g_object_unref);
+ g_clear_pointer (&variant, g_variant_unref);
+}