From 622c18549745d3824713fd9d7a4a0d89b31257a5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 May 2012 09:49:30 -0500 Subject: add private container struct IndicatorPowerDevice --- tests/Makefile.am | 38 ++++++++++++++++++ tests/Makefile.am.strings | 38 ++++++++++++++++++ tests/test-device.cc | 99 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 tests/Makefile.am create mode 100644 tests/Makefile.am.strings create mode 100644 tests/test-device.cc (limited to 'tests') 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 + +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 . +*/ + +#include +#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); +} -- cgit v1.2.3 From f434dc2f9579aeea0c7afe6fa8b78d56c560707f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 May 2012 10:00:15 -0500 Subject: add a 'hello world' test for instantiating IndicatorPower --- tests/Makefile.am | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 87dd606..341abdd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,9 +2,6 @@ TESTS = CLEANFILES = check_PROGRAMS = -AM_CPPFLAGS = $(GTEST_CPPFLAGS) -I${top_srcdir}/src -Wall -Werror -AM_CXXFLAGS = $(GTEST_CXXFLAGS) - ### ### ### @@ -12,27 +9,43 @@ AM_CXXFLAGS = $(GTEST_CXXFLAGS) # 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) + ### ### ### -TESTS += test-device -check_PROGRAMS += test-device -test_device_SOURCES = test-device.cc -test_device_LDADD = \ +TEST_LIBS = \ $(top_builddir)/src/libpower.la \ $(INDICATOR_LIBS) \ $(UPOWER_LIBS) \ $(COVERAGE_LDFLAGS) \ libgtest.a -test_device_CPPFLAGS = \ +TEST_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 +TESTS += test-device +check_PROGRAMS += test-device +test_device_SOURCES = test-device.cc +test_device_LDADD = $(TEST_LIBS) +test_device_CPPFLAGS = $(TEST_CPPFLAGS) + +TESTS += test-indicator +check_PROGRAMS += test-indicator +test_indicator_SOURCES = test-indicator.cc +test_indicator_LDADD = $(TEST_LIBS) +test_indicator_CPPFLAGS = $(TEST_CPPFLAGS) + +### +### +### -- cgit v1.2.3 From 4f74252ce9a8ae3e651cc9e61dc280da82f12d9b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 May 2012 10:15:28 -0500 Subject: add test-indicator.cc --- tests/test-indicator.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/test-indicator.cc (limited to 'tests') diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc new file mode 100644 index 0000000..2f16176 --- /dev/null +++ b/tests/test-indicator.cc @@ -0,0 +1,52 @@ +/* +Copyright 2012 Canonical Ltd. + +Authors: + Charles Kerr + +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 . +*/ + +#include + +#include "device.h" +#include "indicator-power.h" + +namespace +{ + void ensure_glib_initialized () + { + static bool initialized = false; + + if (G_UNLIKELY(!initialized)) + { + initialized = true; + g_type_init(); + } + } +} + +/*** +**** +***/ + +TEST(IndicatorTest, GObjectNew) +{ + ensure_glib_initialized (); + + GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_TYPE, NULL)); + ASSERT_TRUE (o != NULL); + ASSERT_TRUE (IS_INDICATOR_POWER(o)); + g_clear_pointer (&o, g_object_unref); +} + -- cgit v1.2.3 From f18b60b0ce389bee7fc4784b6714f28567397b42 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 May 2012 11:32:16 -0500 Subject: remove the g_clear_pointer() calls s.t. things will build and run on alesage's Jenkins setup running Precise --- tests/test-device.cc | 8 ++++---- tests/test-indicator.cc | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index 02516f4..4dde4af 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -45,7 +45,7 @@ TEST(DeviceTest, GObjectNew) 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); + g_object_unref (o); } TEST(DeviceTest, New) @@ -68,7 +68,7 @@ TEST(DeviceTest, New) ASSERT_EQ (indicator_power_device_get_time(device), 30); /* cleanup */ - g_clear_pointer (&device, g_object_unref); + g_object_unref (device); } TEST(DeviceTest, NewFromVariant) @@ -94,6 +94,6 @@ TEST(DeviceTest, NewFromVariant) ASSERT_EQ (indicator_power_device_get_time(device), 30); /* cleanup */ - g_clear_pointer (&device, g_object_unref); - g_clear_pointer (&variant, g_variant_unref); + g_object_unref (device); + g_variant_unref (variant); } diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index 2f16176..e3533e9 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -47,6 +47,6 @@ TEST(IndicatorTest, GObjectNew) GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_TYPE, NULL)); ASSERT_TRUE (o != NULL); ASSERT_TRUE (IS_INDICATOR_POWER(o)); - g_clear_pointer (&o, g_object_unref); + g_object_unref (o); } -- cgit v1.2.3 From d8484ce5caf9fd5f4efb30368ccc9b70b1f38710 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 May 2012 16:50:58 -0500 Subject: first draft of getting GSettings working in the unit tests before the schema is installed. --- tests/Makefile.am | 10 ++++++++-- tests/test-indicator.cc | 27 +++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 341abdd..8169e3a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,6 @@ TESTS = -CLEANFILES = +CLEANFILES = +BUILT_SOURCES = check_PROGRAMS = ### @@ -34,6 +35,11 @@ TEST_CPPFLAGS = \ $(INDICATOR_CFLAGS) \ $(COVERAGE_CFLAGS) +BUILT_SOURCES += gschemas.compiled +CLEANFILES += gschemas.compiled +gschemas.compiled: Makefile + @glib-compile-schemas --targetdir=$(abs_builddir) $(top_builddir)/data + TESTS += test-device check_PROGRAMS += test-device test_device_SOURCES = test-device.cc @@ -44,7 +50,7 @@ TESTS += test-indicator check_PROGRAMS += test-indicator test_indicator_SOURCES = test-indicator.cc test_indicator_LDADD = $(TEST_LIBS) -test_indicator_CPPFLAGS = $(TEST_CPPFLAGS) +test_indicator_CPPFLAGS = $(TEST_CPPFLAGS) -DSCHEMA_DIR="\"$(top_builddir)/tests/\"" ### ### diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index e3533e9..af494ee 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -22,6 +22,10 @@ with this program. If not, see . #include "device.h" #include "indicator-power.h" +/*** +**** +***/ + namespace { void ensure_glib_initialized () @@ -40,7 +44,27 @@ namespace **** ***/ -TEST(IndicatorTest, GObjectNew) +class IndicatorTest : public ::testing::Test +{ + protected: + + virtual void SetUp() + { + ensure_glib_initialized (); + g_setenv( "GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE); + g_message ("GSETTINGS_SCHEMA_DIR is %s", g_getenv("GSETTINGS_SCHEMA_DIR")); + } + + virtual void TearDown() + { + } +}; + +/*** +**** +***/ + +TEST_F(IndicatorTest, GObjectNew) { ensure_glib_initialized (); @@ -49,4 +73,3 @@ TEST(IndicatorTest, GObjectNew) ASSERT_TRUE (IS_INDICATOR_POWER(o)); g_object_unref (o); } - -- cgit v1.2.3 From 4c95f0b14ad44f39b8e8e0b01a959e2a82e297a9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 May 2012 18:21:34 -0500 Subject: add unit tests for getting/setting device properties --- tests/test-device.cc | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index 4dde4af..0a86478 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -48,6 +48,96 @@ TEST(DeviceTest, GObjectNew) g_object_unref (o); } +TEST(DeviceTest, Properties) +{ + int i; + gdouble d; + GObject * o; + gchar * str; + guint64 u64; + const gchar * key; + GValue string_value = G_VALUE_INIT; + GValue object_value = G_VALUE_INIT; + + ensure_glib_initialized (); + + g_value_init (&string_value, G_TYPE_STRING); + g_value_init (&object_value, G_TYPE_OBJECT); + g_value_set_string (&string_value, "i am a string"); + + o = G_OBJECT (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL)); + ASSERT_TRUE (o != NULL); + ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(o)); + + /* Test getting & setting a Device's properties. + * Also test that setting a property from an unrelated type has no effect. */ + + // KIND + key = INDICATOR_POWER_DEVICE_KIND; + g_object_set (o, key, UP_DEVICE_KIND_BATTERY, NULL); + g_object_get (o, key, &i, NULL); + ASSERT_EQ (i, UP_DEVICE_KIND_BATTERY); + g_object_set_property (o, key, &string_value); + g_object_get (o, key, &i, NULL); + ASSERT_EQ (i, UP_DEVICE_KIND_BATTERY); + + // STATE + key = INDICATOR_POWER_DEVICE_STATE; + g_object_set (o, key, UP_DEVICE_STATE_CHARGING, NULL); + g_object_get (o, key, &i, NULL); + ASSERT_EQ (i, UP_DEVICE_STATE_CHARGING); + g_object_set_property (o, key, &string_value); + g_object_get (o, key, &i, NULL); + ASSERT_EQ (i, UP_DEVICE_STATE_CHARGING); + + // OBJECT_PATH + key = INDICATOR_POWER_DEVICE_OBJECT_PATH; + g_object_set (o, key, "/object/path", NULL); + g_object_get (o, key, &str, NULL); + ASSERT_STREQ (str, "/object/path"); + g_free (str); + g_object_set_property (o, key, &object_value); + g_object_get (o, key, &str, NULL); + ASSERT_STREQ (str, "/object/path"); + g_free (str); + + // ICON + key = INDICATOR_POWER_DEVICE_ICON; + g_object_set (o, key, "something", NULL); + g_object_get (o, key, &str, NULL); + ASSERT_STREQ (str, "something"); + g_free (str); + str = NULL; + g_object_set_property (o, key, &object_value); + g_object_get (o, key, &str, NULL); + ASSERT_STREQ (str, "something"); + g_free (str); + str = NULL; + + // PERCENTAGE + key = INDICATOR_POWER_DEVICE_PERCENTAGE; + g_object_set (o, key, 50.0, NULL); + g_object_get (o, key, &d, NULL); + ASSERT_EQ((int)d, 50); + g_object_set_property (o, key, &object_value); + g_object_get (o, key, &d, NULL); + ASSERT_EQ((int)d, 50); + + // TIME + key = INDICATOR_POWER_DEVICE_TIME; + g_object_set (o, key, 30, NULL); + g_object_get (o, key, &u64, NULL); + ASSERT_EQ(u64, 30); + g_object_set_property (o, key, &object_value); + g_object_get (o, key, &u64, NULL); + ASSERT_EQ(u64, 30); + + // cleanup + g_object_unref (o); + g_value_unset (&object_value); + g_value_unset (&string_value); +} + TEST(DeviceTest, New) { ensure_glib_initialized (); -- cgit v1.2.3 From fd7ad85760663cf176e126d7e350b9f010630b9b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 May 2012 18:48:04 -0500 Subject: don't include the unit tests' code in coverage metrics --- tests/Makefile.am | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 8169e3a..b61bbe0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -23,7 +23,7 @@ AM_CXXFLAGS = $(GTEST_CXXFLAGS) ### TEST_LIBS = \ - $(top_builddir)/src/libpower.la \ + $(top_builddir)/src/.libs/libpower.a \ $(INDICATOR_LIBS) \ $(UPOWER_LIBS) \ $(COVERAGE_LDFLAGS) \ @@ -32,8 +32,7 @@ TEST_LIBS = \ TEST_CPPFLAGS = \ $(AM_CPPFLAGS) \ $(UPOWER_CFLAGS) \ - $(INDICATOR_CFLAGS) \ - $(COVERAGE_CFLAGS) + $(INDICATOR_CFLAGS) BUILT_SOURCES += gschemas.compiled CLEANFILES += gschemas.compiled -- cgit v1.2.3 From d2ba05cfd549a09ff8651c1700b8bf0a8e7d0451 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 May 2012 18:51:51 -0500 Subject: remove the tests that attempted to exercise the code removed in r151 --- tests/test-device.cc | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index 0a86478..70beeb7 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -56,39 +56,26 @@ TEST(DeviceTest, Properties) gchar * str; guint64 u64; const gchar * key; - GValue string_value = G_VALUE_INIT; - GValue object_value = G_VALUE_INIT; ensure_glib_initialized (); - g_value_init (&string_value, G_TYPE_STRING); - g_value_init (&object_value, G_TYPE_OBJECT); - g_value_set_string (&string_value, "i am a string"); - o = G_OBJECT (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL)); ASSERT_TRUE (o != NULL); ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(o)); - /* Test getting & setting a Device's properties. - * Also test that setting a property from an unrelated type has no effect. */ + /* Test getting & setting a Device's properties. */ // KIND key = INDICATOR_POWER_DEVICE_KIND; g_object_set (o, key, UP_DEVICE_KIND_BATTERY, NULL); g_object_get (o, key, &i, NULL); ASSERT_EQ (i, UP_DEVICE_KIND_BATTERY); - g_object_set_property (o, key, &string_value); - g_object_get (o, key, &i, NULL); - ASSERT_EQ (i, UP_DEVICE_KIND_BATTERY); // STATE key = INDICATOR_POWER_DEVICE_STATE; g_object_set (o, key, UP_DEVICE_STATE_CHARGING, NULL); g_object_get (o, key, &i, NULL); ASSERT_EQ (i, UP_DEVICE_STATE_CHARGING); - g_object_set_property (o, key, &string_value); - g_object_get (o, key, &i, NULL); - ASSERT_EQ (i, UP_DEVICE_STATE_CHARGING); // OBJECT_PATH key = INDICATOR_POWER_DEVICE_OBJECT_PATH; @@ -96,10 +83,6 @@ TEST(DeviceTest, Properties) g_object_get (o, key, &str, NULL); ASSERT_STREQ (str, "/object/path"); g_free (str); - g_object_set_property (o, key, &object_value); - g_object_get (o, key, &str, NULL); - ASSERT_STREQ (str, "/object/path"); - g_free (str); // ICON key = INDICATOR_POWER_DEVICE_ICON; @@ -107,35 +90,21 @@ TEST(DeviceTest, Properties) g_object_get (o, key, &str, NULL); ASSERT_STREQ (str, "something"); g_free (str); - str = NULL; - g_object_set_property (o, key, &object_value); - g_object_get (o, key, &str, NULL); - ASSERT_STREQ (str, "something"); - g_free (str); - str = NULL; // PERCENTAGE key = INDICATOR_POWER_DEVICE_PERCENTAGE; g_object_set (o, key, 50.0, NULL); g_object_get (o, key, &d, NULL); ASSERT_EQ((int)d, 50); - g_object_set_property (o, key, &object_value); - g_object_get (o, key, &d, NULL); - ASSERT_EQ((int)d, 50); // TIME key = INDICATOR_POWER_DEVICE_TIME; - g_object_set (o, key, 30, NULL); - g_object_get (o, key, &u64, NULL); - ASSERT_EQ(u64, 30); - g_object_set_property (o, key, &object_value); + g_object_set (o, key, (guint64)30, NULL); g_object_get (o, key, &u64, NULL); ASSERT_EQ(u64, 30); // cleanup g_object_unref (o); - g_value_unset (&object_value); - g_value_unset (&string_value); } TEST(DeviceTest, New) -- cgit v1.2.3 From 88d486192c176f938b09ee86c5cd6f95dfd02aba Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 May 2012 19:06:58 -0500 Subject: add unit tests confirming that the device accessor functions won't crash when you pass NULL for the device --- tests/test-device.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index 70beeb7..0102185 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -156,3 +156,17 @@ TEST(DeviceTest, NewFromVariant) g_object_unref (device); g_variant_unref (variant); } + +TEST(DeviceTest, BadAccessors) +{ + ensure_glib_initialized (); + + // test that these functions can handle being passed NULL pointers + IndicatorPowerDevice * device = NULL; + indicator_power_device_get_kind(device); + indicator_power_device_get_state(device); + indicator_power_device_get_object_path(device); + indicator_power_device_get_icon(device); + indicator_power_device_get_percentage(device); + indicator_power_device_get_time(device); +} -- cgit v1.2.3 From ebf2edadf40205a11998eb37c59cab1f2116d7f5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 May 2012 19:24:11 -0500 Subject: test passing bad non-NULL pointers to Device's accessors --- tests/test-device.cc | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index 0102185..3a7e8d0 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -163,10 +163,20 @@ TEST(DeviceTest, BadAccessors) // test that these functions can handle being passed NULL pointers IndicatorPowerDevice * device = NULL; - indicator_power_device_get_kind(device); - indicator_power_device_get_state(device); - indicator_power_device_get_object_path(device); - indicator_power_device_get_icon(device); - indicator_power_device_get_percentage(device); - indicator_power_device_get_time(device); + indicator_power_device_get_kind (device); + indicator_power_device_get_time (device); + indicator_power_device_get_icon (device); + indicator_power_device_get_state (device); + indicator_power_device_get_percentage (device); + indicator_power_device_get_object_path (device); + + // test that these functions can handle being passed non-device GObjects + device = g_cancellable_new (); + indicator_power_device_get_kind (device); + indicator_power_device_get_time (device); + indicator_power_device_get_icon (device); + indicator_power_device_get_state (device); + indicator_power_device_get_percentage (device); + indicator_power_device_get_object_path (device); + g_object_unref (device); } -- cgit v1.2.3 From 4d1bb110b97fc1e9835d295cfcd30c7125a2380d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 May 2012 19:27:59 -0500 Subject: ah, c++ is too smart for the last commit's implicit conversion. --- tests/test-device.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index 3a7e8d0..388460e 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -171,7 +171,7 @@ TEST(DeviceTest, BadAccessors) indicator_power_device_get_object_path (device); // test that these functions can handle being passed non-device GObjects - device = g_cancellable_new (); + device = reinterpret_cast(g_cancellable_new ()); indicator_power_device_get_kind (device); indicator_power_device_get_time (device); indicator_power_device_get_icon (device); -- cgit v1.2.3 From 34c756aa7a894ee9c12f3dce0b4ae6e4ac6a30a8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 25 May 2012 14:58:56 -0500 Subject: modify IndicatorPower to use IndicatorPowerDevices internally --- tests/test-indicator.cc | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index af494ee..3e9d97b 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -48,15 +48,32 @@ class IndicatorTest : public ::testing::Test { protected: + IndicatorPowerDevice * ac_device; + IndicatorPowerDevice * battery_device; + virtual void SetUp() { ensure_glib_initialized (); + g_setenv( "GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE); - g_message ("GSETTINGS_SCHEMA_DIR is %s", g_getenv("GSETTINGS_SCHEMA_DIR")); + + ac_device = indicator_power_device_new ( + "/org/freedesktop/UPower/devices/line_power_AC", + UP_DEVICE_KIND_LINE_POWER, + ". GThemedIcon ac-adapter-symbolic ac-adapter ", + 0.0, UP_DEVICE_STATE_UNKNOWN, 0); + + battery_device = indicator_power_device_new ( + "/org/freedesktop/UPower/devices/battery_BAT0", + UP_DEVICE_KIND_BATTERY, + ". GThemedIcon battery-good-symbolic gpm-battery-060 battery-good ", + 52.871712, UP_DEVICE_STATE_DISCHARGING, 8834); } virtual void TearDown() { + g_clear_object (&battery_device); + g_clear_object (&ac_device); } }; @@ -66,10 +83,18 @@ class IndicatorTest : public ::testing::Test TEST_F(IndicatorTest, GObjectNew) { - ensure_glib_initialized (); - GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_TYPE, NULL)); ASSERT_TRUE (o != NULL); ASSERT_TRUE (IS_INDICATOR_POWER(o)); g_object_unref (o); } + +TEST_F(IndicatorTest, SetDevices) +{ + IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + IndicatorPowerDevice * devices[] = { ac_device, battery_device }; + + indicator_power_set_devices (power, devices, G_N_ELEMENTS(devices)); + + g_object_unref (power); +} -- cgit v1.2.3 From 6bbfe3a79da52a5d03224bdb66faf0d41385158d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 25 May 2012 15:02:03 -0500 Subject: make Jenkins happy --- tests/test-indicator.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index 3e9d97b..c3f502a 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -72,8 +72,8 @@ class IndicatorTest : public ::testing::Test virtual void TearDown() { - g_clear_object (&battery_device); - g_clear_object (&ac_device); + g_object_unref (battery_device); + g_object_unref (ac_device); } }; -- cgit v1.2.3 From 676aef0608d08a7d2086742e0dbd6b05e2d548bd Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 26 May 2012 14:16:26 -0500 Subject: first draft of adding tests for a discharging battery --- tests/test-indicator.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests') diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index c3f502a..4b39579 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -98,3 +98,38 @@ TEST_F(IndicatorTest, SetDevices) g_object_unref (power); } + +TEST_F(IndicatorTest, DischargingStrings) +{ + IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + + // give the indicator a discharging battery with 1 hour of life left + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, guint64(60*60), + NULL); + indicator_power_set_devices (power, &battery_device, 1); + + GList * entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + IndicatorObjectEntry * entry = static_cast(entries->data); + ASSERT_STREQ(entry->accessible_desc, "Battery (1 hour left (50%))"); + ASSERT_STREQ(entry->name_hint, "indicator-power"); + g_list_free (entries); + + // give the indicator a discharging battery with over 12 hours of life left + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, guint64(60*60*12 + 1), + NULL); + indicator_power_set_devices (power, &battery_device, 1); + entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + entry = static_cast(entries->data); + g_list_free (entries); + + // cleanup + g_object_unref (power); +} -- cgit v1.2.3 From e0d1b3299edde62797fe6fa08be3740f24c7d38e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 26 May 2012 14:35:22 -0500 Subject: add coverage for various charging/discharging/charged states --- tests/test-indicator.cc | 104 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index 4b39579..ad619e2 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -110,7 +110,6 @@ TEST_F(IndicatorTest, DischargingStrings) INDICATOR_POWER_DEVICE_TIME, guint64(60*60), NULL); indicator_power_set_devices (power, &battery_device, 1); - GList * entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); ASSERT_EQ (g_list_length(entries), 1); IndicatorObjectEntry * entry = static_cast(entries->data); @@ -118,16 +117,115 @@ TEST_F(IndicatorTest, DischargingStrings) ASSERT_STREQ(entry->name_hint, "indicator-power"); g_list_free (entries); + // give the indicator a discharging battery with 2 hours of life left + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0, + INDICATOR_POWER_DEVICE_TIME, guint64(60*60*2), + NULL); + indicator_power_set_devices (power, &battery_device, 1); + entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + entry = static_cast(entries->data); + ASSERT_STREQ (entry->accessible_desc, "Battery (2 hours left (100%))"); + g_list_free (entries); + // give the indicator a discharging battery with over 12 hours of life left g_object_set (battery_device, - INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, - INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, INDICATOR_POWER_DEVICE_TIME, guint64(60*60*12 + 1), NULL); indicator_power_set_devices (power, &battery_device, 1); entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); ASSERT_EQ (g_list_length(entries), 1); entry = static_cast(entries->data); + ASSERT_STREQ (entry->accessible_desc, "Battery"); + g_list_free (entries); + + // give the indicator a discharging battery with 29 seconds left + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_TIME, guint64(29), + NULL); + indicator_power_set_devices (power, &battery_device, 1); + entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + entry = static_cast(entries->data); + ASSERT_STREQ (entry->accessible_desc, "Battery (Unknown time left (100%))"); + g_list_free (entries); + + // what happens if the time estimate isn't available + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + NULL); + indicator_power_set_devices (power, &battery_device, 1); + entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + entry = static_cast(entries->data); + ASSERT_STREQ (entry->accessible_desc, "Battery (50%)"); + g_list_free (entries); + + // what happens if the time estimate AND percentage isn't available + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, + NULL); + indicator_power_set_devices (power, &battery_device, 1); + entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + entry = static_cast(entries->data); + ASSERT_STREQ (entry->accessible_desc, "Battery (not present)"); + g_list_free (entries); + + // cleanup + g_object_unref (power); +} + +TEST_F(IndicatorTest, ChargingStrings) +{ + IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + + // give the indicator a discharging battery with 1 hour of life left + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, guint64(60*60), + NULL); + indicator_power_set_devices (power, &battery_device, 1); + GList * entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + IndicatorObjectEntry * entry = static_cast(entries->data); + ASSERT_STREQ(entry->accessible_desc, "Battery (1 hour to charge (50%))"); + g_list_free (entries); + + // give the indicator a discharging battery with 2 hours of life left + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_TIME, guint64(60*60*2), + NULL); + indicator_power_set_devices (power, &battery_device, 1); + entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + entry = static_cast(entries->data); + ASSERT_STREQ (entry->accessible_desc, "Battery (2 hours to charge (50%))"); + g_list_free (entries); + + // cleanup + g_object_unref (power); +} + +TEST_F(IndicatorTest, ChargedStrings) +{ + IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + + // give the indicator a discharging battery with 1 hour of life left + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED, + INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + NULL); + indicator_power_set_devices (power, &battery_device, 1); + GList * entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + ASSERT_EQ (g_list_length(entries), 1); + IndicatorObjectEntry * entry = static_cast(entries->data); + ASSERT_STREQ(entry->accessible_desc, "Battery (charged)"); g_list_free (entries); // cleanup -- cgit v1.2.3 From 29ec6d23c13cbe7487232b79700c5d5406c26014 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 26 May 2012 15:42:58 -0500 Subject: extract-method to simplify testing the accessible text --- tests/test-indicator.cc | 92 ++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 47 deletions(-) (limited to 'tests') diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index ad619e2..52e319f 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -75,6 +75,16 @@ class IndicatorTest : public ::testing::Test g_object_unref (battery_device); g_object_unref (ac_device); } + + const char* GetAccessibleDesc (IndicatorPower * power) const + { + GList * entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); + g_assert (g_list_length(entries) == 1); + IndicatorObjectEntry * entry = static_cast(entries->data); + const char * ret = entry->accessible_desc; + g_list_free (entries); + return ret; + } }; /*** @@ -109,13 +119,8 @@ TEST_F(IndicatorTest, DischargingStrings) INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, INDICATOR_POWER_DEVICE_TIME, guint64(60*60), NULL); - indicator_power_set_devices (power, &battery_device, 1); - GList * entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); - ASSERT_EQ (g_list_length(entries), 1); - IndicatorObjectEntry * entry = static_cast(entries->data); - ASSERT_STREQ(entry->accessible_desc, "Battery (1 hour left (50%))"); - ASSERT_STREQ(entry->name_hint, "indicator-power"); - g_list_free (entries); + indicator_power_set_devices (power, &battery_device, 1); + ASSERT_STREQ (GetAccessibleDesc(power), "Battery (1 hour left (50%))"); // give the indicator a discharging battery with 2 hours of life left g_object_set (battery_device, @@ -123,33 +128,21 @@ TEST_F(IndicatorTest, DischargingStrings) INDICATOR_POWER_DEVICE_TIME, guint64(60*60*2), NULL); indicator_power_set_devices (power, &battery_device, 1); - entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); - ASSERT_EQ (g_list_length(entries), 1); - entry = static_cast(entries->data); - ASSERT_STREQ (entry->accessible_desc, "Battery (2 hours left (100%))"); - g_list_free (entries); + ASSERT_STREQ (GetAccessibleDesc(power), "Battery (2 hours left (100%))"); // give the indicator a discharging battery with over 12 hours of life left g_object_set (battery_device, INDICATOR_POWER_DEVICE_TIME, guint64(60*60*12 + 1), NULL); indicator_power_set_devices (power, &battery_device, 1); - entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); - ASSERT_EQ (g_list_length(entries), 1); - entry = static_cast(entries->data); - ASSERT_STREQ (entry->accessible_desc, "Battery"); - g_list_free (entries); + ASSERT_STREQ (GetAccessibleDesc(power), "Battery"); // give the indicator a discharging battery with 29 seconds left g_object_set (battery_device, INDICATOR_POWER_DEVICE_TIME, guint64(29), NULL); indicator_power_set_devices (power, &battery_device, 1); - entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); - ASSERT_EQ (g_list_length(entries), 1); - entry = static_cast(entries->data); - ASSERT_STREQ (entry->accessible_desc, "Battery (Unknown time left (100%))"); - g_list_free (entries); + ASSERT_STREQ (GetAccessibleDesc(power), "Battery (Unknown time left (100%))"); // what happens if the time estimate isn't available g_object_set (battery_device, @@ -157,11 +150,7 @@ TEST_F(IndicatorTest, DischargingStrings) INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, NULL); indicator_power_set_devices (power, &battery_device, 1); - entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); - ASSERT_EQ (g_list_length(entries), 1); - entry = static_cast(entries->data); - ASSERT_STREQ (entry->accessible_desc, "Battery (50%)"); - g_list_free (entries); + ASSERT_STREQ (GetAccessibleDesc(power), "Battery (50%)"); // what happens if the time estimate AND percentage isn't available g_object_set (battery_device, @@ -169,11 +158,7 @@ TEST_F(IndicatorTest, DischargingStrings) INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, NULL); indicator_power_set_devices (power, &battery_device, 1); - entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); - ASSERT_EQ (g_list_length(entries), 1); - entry = static_cast(entries->data); - ASSERT_STREQ (entry->accessible_desc, "Battery (not present)"); - g_list_free (entries); + ASSERT_STREQ (GetAccessibleDesc(power), "Battery (not present)"); // cleanup g_object_unref (power); @@ -190,22 +175,14 @@ TEST_F(IndicatorTest, ChargingStrings) INDICATOR_POWER_DEVICE_TIME, guint64(60*60), NULL); indicator_power_set_devices (power, &battery_device, 1); - GList * entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); - ASSERT_EQ (g_list_length(entries), 1); - IndicatorObjectEntry * entry = static_cast(entries->data); - ASSERT_STREQ(entry->accessible_desc, "Battery (1 hour to charge (50%))"); - g_list_free (entries); + ASSERT_STREQ (GetAccessibleDesc(power), "Battery (1 hour to charge (50%))"); // give the indicator a discharging battery with 2 hours of life left g_object_set (battery_device, INDICATOR_POWER_DEVICE_TIME, guint64(60*60*2), NULL); indicator_power_set_devices (power, &battery_device, 1); - entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); - ASSERT_EQ (g_list_length(entries), 1); - entry = static_cast(entries->data); - ASSERT_STREQ (entry->accessible_desc, "Battery (2 hours to charge (50%))"); - g_list_free (entries); + ASSERT_STREQ (GetAccessibleDesc(power), "Battery (2 hours to charge (50%))"); // cleanup g_object_unref (power); @@ -222,12 +199,33 @@ TEST_F(IndicatorTest, ChargedStrings) INDICATOR_POWER_DEVICE_TIME, guint64(0), NULL); indicator_power_set_devices (power, &battery_device, 1); - GList * entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); - ASSERT_EQ (g_list_length(entries), 1); - IndicatorObjectEntry * entry = static_cast(entries->data); - ASSERT_STREQ(entry->accessible_desc, "Battery (charged)"); - g_list_free (entries); + ASSERT_STREQ (GetAccessibleDesc(power), "Battery (charged)"); + + // cleanup + g_object_unref (power); +} + +TEST_F(IndicatorTest, AvoidChargingBatteriesWithZeroSecondsLeft) +{ + IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED, + INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + NULL); + IndicatorPowerDevice * bad_battery_device = indicator_power_device_new ( + "/org/freedesktop/UPower/devices/battery_BAT0", + UP_DEVICE_KIND_BATTERY, + ". GThemedIcon battery-good-symbolic gpm-battery-060 battery-good ", + 53, UP_DEVICE_STATE_CHARGING, 0); + + IndicatorPowerDevice * devices[] = { battery_device, bad_battery_device }; + indicator_power_set_devices (power, devices, G_N_ELEMENTS(devices)); + ASSERT_STREQ (GetAccessibleDesc(power), "Battery (53%)"); // cleanup g_object_unref (power); + g_object_unref (bad_battery_device); } + -- cgit v1.2.3 From aeb6ab59af1f325261db754aade493a949d5a1e3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 26 May 2012 16:26:02 -0500 Subject: call g_object_run_dispose() in a standalone test to get coverage on the NULL / non-NULL branches of dispose()'s g_clear_pointer() calls --- tests/test-device.cc | 1 + tests/test-indicator.cc | 1 + 2 files changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index 388460e..132d762 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -45,6 +45,7 @@ TEST(DeviceTest, GObjectNew) GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL)); ASSERT_TRUE (o != NULL); ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(o)); + g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls g_object_unref (o); } diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index 52e319f..dedf54c 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -96,6 +96,7 @@ TEST_F(IndicatorTest, GObjectNew) GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_TYPE, NULL)); ASSERT_TRUE (o != NULL); ASSERT_TRUE (IS_INDICATOR_POWER(o)); + g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls g_object_unref (o); } -- cgit v1.2.3 From eda15ff15c3603deb748daaa59c9b28a576a9c4d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 26 May 2012 17:10:48 -0500 Subject: add coverage for DBusListener get_property() --- tests/test-indicator.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests') diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index dedf54c..2229d77 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -19,6 +19,7 @@ with this program. If not, see . #include +#include "dbus-listener.h" #include "device.h" #include "indicator-power.h" @@ -230,3 +231,19 @@ TEST_F(IndicatorTest, AvoidChargingBatteriesWithZeroSecondsLeft) g_object_unref (bad_battery_device); } +TEST_F(IndicatorTest, DbusListenerGetProperty) +{ + IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + GObject * dbus_listener = G_OBJECT(g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, + INDICATOR_POWER_DBUS_LISTENER_INDICATOR, power, + NULL)); + GObject * indicator = NULL; + g_object_get (dbus_listener, + INDICATOR_POWER_DBUS_LISTENER_INDICATOR, &indicator, + NULL); + ASSERT_EQ(INDICATOR_POWER(indicator), power); + + // cleanup + g_object_unref (dbus_listener); + g_object_unref (power); +} -- cgit v1.2.3 From 2f1281d4faa6bed2a0be484bd722504df290880c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 26 May 2012 17:49:13 -0500 Subject: add coverage for charging with >1 minute but <1 hour left --- tests/test-indicator.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index 2229d77..5875df6 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -115,6 +115,15 @@ TEST_F(IndicatorTest, DischargingStrings) { IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + // give the indicator a discharging battery with 30 minutes of life left + g_object_set (battery_device, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, guint64(60*30), + NULL); + indicator_power_set_devices (power, &battery_device, 1); + ASSERT_STREQ (GetAccessibleDesc(power), "Battery (30 minutes left (50%))"); + // give the indicator a discharging battery with 1 hour of life left g_object_set (battery_device, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, -- cgit v1.2.3 From 675cc7955e0e8834a3ea4bb46fb347bb744f24a7 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 27 May 2012 08:35:52 -0500 Subject: Add skeleton test for IndicatorPowerDbusListener --- tests/Makefile.am | 6 ++++ tests/test-dbus-listener.cc | 73 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 tests/test-dbus-listener.cc (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index b61bbe0..b6b543b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -45,6 +45,12 @@ test_device_SOURCES = test-device.cc test_device_LDADD = $(TEST_LIBS) test_device_CPPFLAGS = $(TEST_CPPFLAGS) +TESTS += test-dbus-listener +check_PROGRAMS += test-dbus-listener +test_dbus_listener_SOURCES = test-dbus-listener.cc +test_dbus_listener_LDADD = $(TEST_LIBS) +test_dbus_listener_CPPFLAGS = $(TEST_CPPFLAGS) + TESTS += test-indicator check_PROGRAMS += test-indicator test_indicator_SOURCES = test-indicator.cc diff --git a/tests/test-dbus-listener.cc b/tests/test-dbus-listener.cc new file mode 100644 index 0000000..869d08a --- /dev/null +++ b/tests/test-dbus-listener.cc @@ -0,0 +1,73 @@ +/* +Copyright 2012 Canonical Ltd. + +Authors: + Charles Kerr + +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 . +*/ + +#include + +#include "dbus-listener.h" +#include "device.h" + +/*** +**** +***/ + +namespace +{ + void ensure_glib_initialized () + { + static bool initialized = false; + + if (G_UNLIKELY(!initialized)) + { + initialized = true; + g_type_init(); + } + } +} + +/*** +**** +***/ + +class DbusListenerTest : public ::testing::Test +{ + protected: + + virtual void SetUp() + { + ensure_glib_initialized (); + } + + virtual void TearDown() + { + } +}; + +/*** +**** +***/ + +TEST_F(DbusListenerTest, GObjectNew) +{ + GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, NULL)); + ASSERT_TRUE (o != NULL); + ASSERT_TRUE (INDICATOR_IS_POWER_DBUS_LISTENER(o)); + g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls + g_object_unref (o); +} + -- cgit v1.2.3 From 23a2672a1a763cdef67ccc5cb9f8fec7daf021be Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 27 May 2012 09:22:28 -0500 Subject: use signals to decouple i-power and dbus-listener --- tests/test-indicator.cc | 60 +++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index 5875df6..50ae2c1 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -103,17 +103,22 @@ TEST_F(IndicatorTest, GObjectNew) TEST_F(IndicatorTest, SetDevices) { + GSList * devices; IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); - IndicatorPowerDevice * devices[] = { ac_device, battery_device }; - indicator_power_set_devices (power, devices, G_N_ELEMENTS(devices)); - + devices = NULL; + devices = g_slist_append (devices, ac_device); + devices = g_slist_append (devices, battery_device); + indicator_power_set_devices (power, devices); + g_slist_free (devices); + g_object_unref (power); } TEST_F(IndicatorTest, DischargingStrings) { IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + GSList * devices = g_slist_append (NULL, battery_device); // give the indicator a discharging battery with 30 minutes of life left g_object_set (battery_device, @@ -121,7 +126,7 @@ TEST_F(IndicatorTest, DischargingStrings) INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, INDICATOR_POWER_DEVICE_TIME, guint64(60*30), NULL); - indicator_power_set_devices (power, &battery_device, 1); + indicator_power_set_devices (power, devices); ASSERT_STREQ (GetAccessibleDesc(power), "Battery (30 minutes left (50%))"); // give the indicator a discharging battery with 1 hour of life left @@ -130,7 +135,7 @@ TEST_F(IndicatorTest, DischargingStrings) INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, INDICATOR_POWER_DEVICE_TIME, guint64(60*60), NULL); - indicator_power_set_devices (power, &battery_device, 1); + indicator_power_set_devices (power, devices); ASSERT_STREQ (GetAccessibleDesc(power), "Battery (1 hour left (50%))"); // give the indicator a discharging battery with 2 hours of life left @@ -138,21 +143,21 @@ TEST_F(IndicatorTest, DischargingStrings) INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0, INDICATOR_POWER_DEVICE_TIME, guint64(60*60*2), NULL); - indicator_power_set_devices (power, &battery_device, 1); + indicator_power_set_devices (power, devices); ASSERT_STREQ (GetAccessibleDesc(power), "Battery (2 hours left (100%))"); // give the indicator a discharging battery with over 12 hours of life left g_object_set (battery_device, INDICATOR_POWER_DEVICE_TIME, guint64(60*60*12 + 1), NULL); - indicator_power_set_devices (power, &battery_device, 1); + indicator_power_set_devices (power, devices); ASSERT_STREQ (GetAccessibleDesc(power), "Battery"); // give the indicator a discharging battery with 29 seconds left g_object_set (battery_device, INDICATOR_POWER_DEVICE_TIME, guint64(29), NULL); - indicator_power_set_devices (power, &battery_device, 1); + indicator_power_set_devices (power, devices); ASSERT_STREQ (GetAccessibleDesc(power), "Battery (Unknown time left (100%))"); // what happens if the time estimate isn't available @@ -160,7 +165,7 @@ TEST_F(IndicatorTest, DischargingStrings) INDICATOR_POWER_DEVICE_TIME, guint64(0), INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, NULL); - indicator_power_set_devices (power, &battery_device, 1); + indicator_power_set_devices (power, devices); ASSERT_STREQ (GetAccessibleDesc(power), "Battery (50%)"); // what happens if the time estimate AND percentage isn't available @@ -168,16 +173,18 @@ TEST_F(IndicatorTest, DischargingStrings) INDICATOR_POWER_DEVICE_TIME, guint64(0), INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, NULL); - indicator_power_set_devices (power, &battery_device, 1); + indicator_power_set_devices (power, devices); ASSERT_STREQ (GetAccessibleDesc(power), "Battery (not present)"); // cleanup + g_slist_free (devices); g_object_unref (power); } TEST_F(IndicatorTest, ChargingStrings) { IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + GSList * devices = g_slist_prepend (NULL, battery_device); // give the indicator a discharging battery with 1 hour of life left g_object_set (battery_device, @@ -185,23 +192,25 @@ TEST_F(IndicatorTest, ChargingStrings) INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, INDICATOR_POWER_DEVICE_TIME, guint64(60*60), NULL); - indicator_power_set_devices (power, &battery_device, 1); + indicator_power_set_devices (power, devices); ASSERT_STREQ (GetAccessibleDesc(power), "Battery (1 hour to charge (50%))"); // give the indicator a discharging battery with 2 hours of life left g_object_set (battery_device, INDICATOR_POWER_DEVICE_TIME, guint64(60*60*2), NULL); - indicator_power_set_devices (power, &battery_device, 1); + indicator_power_set_devices (power, devices); ASSERT_STREQ (GetAccessibleDesc(power), "Battery (2 hours to charge (50%))"); // cleanup + g_slist_free (devices); g_object_unref (power); } TEST_F(IndicatorTest, ChargedStrings) { IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + GSList * devices = g_slist_append (NULL, battery_device); // give the indicator a discharging battery with 1 hour of life left g_object_set (battery_device, @@ -209,10 +218,11 @@ TEST_F(IndicatorTest, ChargedStrings) INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0, INDICATOR_POWER_DEVICE_TIME, guint64(0), NULL); - indicator_power_set_devices (power, &battery_device, 1); + indicator_power_set_devices (power, devices); ASSERT_STREQ (GetAccessibleDesc(power), "Battery (charged)"); // cleanup + g_slist_free (devices); g_object_unref (power); } @@ -231,28 +241,14 @@ TEST_F(IndicatorTest, AvoidChargingBatteriesWithZeroSecondsLeft) ". GThemedIcon battery-good-symbolic gpm-battery-060 battery-good ", 53, UP_DEVICE_STATE_CHARGING, 0); - IndicatorPowerDevice * devices[] = { battery_device, bad_battery_device }; - indicator_power_set_devices (power, devices, G_N_ELEMENTS(devices)); + GSList * devices = NULL; + devices = g_slist_append (devices, battery_device); + devices = g_slist_append (devices, bad_battery_device); + indicator_power_set_devices (power, devices); ASSERT_STREQ (GetAccessibleDesc(power), "Battery (53%)"); // cleanup + g_slist_free (devices); g_object_unref (power); g_object_unref (bad_battery_device); } - -TEST_F(IndicatorTest, DbusListenerGetProperty) -{ - IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); - GObject * dbus_listener = G_OBJECT(g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, - INDICATOR_POWER_DBUS_LISTENER_INDICATOR, power, - NULL)); - GObject * indicator = NULL; - g_object_get (dbus_listener, - INDICATOR_POWER_DBUS_LISTENER_INDICATOR, &indicator, - NULL); - ASSERT_EQ(INDICATOR_POWER(indicator), power); - - // cleanup - g_object_unref (dbus_listener); - g_object_unref (power); -} -- cgit v1.2.3 From b9a6194c12bf39fb6317edc1126ea32e890da583 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 28 May 2012 11:33:07 -0500 Subject: add a mock GSD.Power to handle the GetPower requests --- tests/test-dbus-listener.cc | 170 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 169 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test-dbus-listener.cc b/tests/test-dbus-listener.cc index 869d08a..2cfe4a7 100644 --- a/tests/test-dbus-listener.cc +++ b/tests/test-dbus-listener.cc @@ -46,15 +46,33 @@ namespace class DbusListenerTest : public ::testing::Test { - protected: + public: + + GSList * devices; + GDBusConnection * connection; + GMainLoop * mainloop; + GTestDBus * bus; + bool bus_acquired; + bool name_acquired; virtual void SetUp() { + bus_acquired = false; + name_acquired = false; + connection = NULL; + devices = NULL; + ensure_glib_initialized (); + mainloop = g_main_loop_new (NULL, FALSE); + bus = g_test_dbus_new (G_TEST_DBUS_NONE); + g_test_dbus_up (bus); } virtual void TearDown() { + g_slist_free_full (devices, g_object_unref); + g_test_dbus_down (bus); + g_main_loop_unref (mainloop); } }; @@ -62,6 +80,7 @@ class DbusListenerTest : public ::testing::Test **** ***/ +/* TEST_F(DbusListenerTest, GObjectNew) { GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, NULL)); @@ -70,4 +89,153 @@ TEST_F(DbusListenerTest, GObjectNew) g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls g_object_unref (o); } +*/ +static void +on_bus_acquired (GDBusConnection *conn, const gchar * name, gpointer gself) +{ + g_debug ("bus acquired: %s, connection is %p", name, conn); + + DbusListenerTest * test = static_cast (gself); + test->connection = conn; + test->bus_acquired = true; +} + +static void +on_name_acquired (GDBusConnection * conn, const gchar * name, gpointer gself) +{ + g_debug ("name acquired: %s, connection is %p", name, conn); + + DbusListenerTest * test = static_cast (gself); + test->name_acquired = true; + g_main_loop_quit (test->mainloop); +} + +static void +on_name_lost (GDBusConnection * conn, const gchar * name, gpointer gself) +{ + g_debug ("name lost: %s, connection is %p", name, conn); + + DbusListenerTest * test = static_cast (gself); + test->name_acquired = false; + g_main_loop_quit (test->mainloop); +} + +static void +on_devices_enumerated (IndicatorPowerDbusListener * l, GSList * devices, gpointer gself) +{ + g_debug ("on_devices_enumerated"); + + DbusListenerTest * test = static_cast (gself); + test->name_acquired = false; + g_slist_foreach (devices, (GFunc)g_object_ref, NULL); + test->devices = g_slist_copy (devices); + g_main_loop_quit (test->mainloop); +} + +static void +gsd_power_handle_method_call (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + if (!g_strcmp0 (method_name, "GetDevices")) + { + /* create builder */ + GVariantBuilder * builder = g_variant_builder_new (G_VARIANT_TYPE("a(susdut)")); + + g_variant_builder_add (builder, "(susdut)", + "/org/freedesktop/UPower/devices/line_power_AC", + UP_DEVICE_KIND_LINE_POWER, + ". GThemedIcon ac-adapter-symbolic ac-adapter ", + 0.0, + UP_DEVICE_STATE_UNKNOWN, + 0); + g_variant_builder_add (builder, "(susdut)", + "/org/freedesktop/UPower/devices/battery_BAT0", + UP_DEVICE_KIND_BATTERY, + ". GThemedIcon battery-good-symbolic gpm-battery-060 battery-good ", + 52.871712, + UP_DEVICE_STATE_DISCHARGING, + 8834); + + GVariant * value = g_variant_builder_end (builder); + GVariant * tuple = g_variant_new_tuple (&value, 1); + g_dbus_method_invocation_return_value (invocation, tuple); + g_variant_builder_unref (builder); + } +} + +static const GDBusInterfaceVTable gsd_power_interface_vtable = +{ + gsd_power_handle_method_call, + NULL, /* GetProperty */ + NULL, /* SetProperty */ +}; + +TEST_F(DbusListenerTest, GnomeSettingsDaemon) +{ + // own org.gnome.SettingsDameon on the bus + const int name_ownership_id = g_bus_own_name ( + G_BUS_TYPE_SESSION, + GSD_SERVICE, + G_BUS_NAME_OWNER_FLAGS_NONE, + on_bus_acquired, + on_name_acquired, + on_name_lost, + this, NULL); + ASSERT_FALSE (bus_acquired); + ASSERT_FALSE (name_acquired); + ASSERT_TRUE (connection == NULL); + g_main_loop_run (mainloop); + ASSERT_TRUE (bus_acquired); + ASSERT_TRUE (name_acquired); + ASSERT_TRUE (G_IS_DBUS_CONNECTION(connection)); + + // register a mock org.gnome.SettingsDaemon.Power interface + const gchar introspection_xml[] = "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; + GDBusNodeInfo * introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL); + ASSERT_TRUE (introspection_data != NULL); + const int registration_id = g_dbus_connection_register_object (connection, + GSD_POWER_DBUS_PATH, + introspection_data->interfaces[0], + &gsd_power_interface_vtable, + NULL, NULL, NULL); + + // create an i-power dbus listener to watch for GSD + ASSERT_EQ (g_slist_length(devices), 0); + GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, NULL)); + ASSERT_TRUE (o != NULL); + ASSERT_TRUE (INDICATOR_IS_POWER_DBUS_LISTENER(o)); + g_signal_connect(o, INDICATOR_POWER_DBUS_LISTENER_DEVICES_ENUMERATED, + G_CALLBACK(on_devices_enumerated), this); + g_main_loop_run (mainloop); + + // test the devices should have gotten + ASSERT_EQ (g_slist_length(devices), 2); + IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE (g_slist_nth_data (devices, 0)); + ASSERT_EQ (indicator_power_device_get_kind(device), UP_DEVICE_KIND_LINE_POWER); + ASSERT_STREQ ("/org/freedesktop/UPower/devices/line_power_AC", indicator_power_device_get_object_path(device)); + device = INDICATOR_POWER_DEVICE (g_slist_nth_data (devices, 1)); + ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device)); + ASSERT_STREQ ("/org/freedesktop/UPower/devices/battery_BAT0", indicator_power_device_get_object_path(device)); + + // cleanup + g_object_unref (o); + g_dbus_connection_unregister_object (connection, registration_id); + g_bus_unown_name (name_ownership_id); +} -- cgit v1.2.3 From 7b8cd0982a266d589a7dcc0a76b04776d72e1bf4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 28 May 2012 19:37:43 -0500 Subject: add more tests to improve coverage: different device types, no primary device --- tests/test-dbus-listener.cc | 1 + tests/test-indicator.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) (limited to 'tests') diff --git a/tests/test-dbus-listener.cc b/tests/test-dbus-listener.cc index 2cfe4a7..62caeb0 100644 --- a/tests/test-dbus-listener.cc +++ b/tests/test-dbus-listener.cc @@ -235,6 +235,7 @@ TEST_F(DbusListenerTest, GnomeSettingsDaemon) ASSERT_STREQ ("/org/freedesktop/UPower/devices/battery_BAT0", indicator_power_device_get_object_path(device)); // cleanup + g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls g_object_unref (o); g_dbus_connection_unregister_object (connection, registration_id); g_bus_unown_name (name_ownership_id); diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index 50ae2c1..32d6f4f 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -252,3 +252,64 @@ TEST_F(IndicatorTest, AvoidChargingBatteriesWithZeroSecondsLeft) g_object_unref (power); g_object_unref (bad_battery_device); } + +TEST_F(IndicatorTest, OtherDevices) +{ + IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + + g_object_ref (battery_device); + GSList * devices = g_slist_append (NULL, battery_device); + + devices = g_slist_append (devices, indicator_power_device_new ( + "/org/freedesktop/UPower/devices/mouse", UP_DEVICE_KIND_MOUSE, + "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + devices = g_slist_append (devices, indicator_power_device_new ( + "/org/freedesktop/UPower/devices/ups", UP_DEVICE_KIND_UPS, + "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + devices = g_slist_append (devices, indicator_power_device_new ( + "/org/freedesktop/UPower/devices/keyboard", UP_DEVICE_KIND_KEYBOARD, + "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + devices = g_slist_append (devices, indicator_power_device_new ( + "/org/freedesktop/UPower/devices/pda", UP_DEVICE_KIND_PDA, + "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + devices = g_slist_append (devices, indicator_power_device_new ( + "/org/freedesktop/UPower/devices/phone", UP_DEVICE_KIND_PHONE, + "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + devices = g_slist_append (devices, indicator_power_device_new ( + "/org/freedesktop/UPower/devices/monitor", UP_DEVICE_KIND_MONITOR, + "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + devices = g_slist_append (devices, indicator_power_device_new ( + "/org/freedesktop/UPower/devices/media_player", UP_DEVICE_KIND_MEDIA_PLAYER, + "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + devices = g_slist_append (devices, indicator_power_device_new ( + "/org/freedesktop/UPower/devices/tablet", UP_DEVICE_KIND_TABLET, + "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + devices = g_slist_append (devices, indicator_power_device_new ( + "/org/freedesktop/UPower/devices/computer", UP_DEVICE_KIND_COMPUTER, + "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + devices = g_slist_append (devices, indicator_power_device_new ( + "/org/freedesktop/UPower/devices/unknown", UP_DEVICE_KIND_UNKNOWN, + "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + + indicator_power_set_devices (power, devices); + + // FIXME: this tests to confirm the code doesn't crash, + // but further tests would be helpful + + // cleanup + g_slist_free_full (devices, g_object_unref); + g_object_unref (power); +} + +TEST_F(IndicatorTest, NoDevices) +{ + IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL)); + + indicator_power_set_devices (power, NULL); + + // FIXME: this tests to confirm the code doesn't crash, + // but further tests would be helpful + + // cleanup + g_object_unref (power); +} -- cgit v1.2.3 From 8a37ae27c57386bb321f6d97cfc9883d03b9027a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 29 May 2012 13:29:32 -0500 Subject: add tests for gsd GetDevices returning (a) no devices and (b) an error --- tests/test-dbus-listener.cc | 326 ++++++++++++++++++++++++++------------------ 1 file changed, 196 insertions(+), 130 deletions(-) (limited to 'tests') diff --git a/tests/test-dbus-listener.cc b/tests/test-dbus-listener.cc index 62caeb0..4c6c607 100644 --- a/tests/test-dbus-listener.cc +++ b/tests/test-dbus-listener.cc @@ -46,14 +46,87 @@ namespace class DbusListenerTest : public ::testing::Test { - public: - + protected: GSList * devices; GDBusConnection * connection; GMainLoop * mainloop; GTestDBus * bus; + GDBusNodeInfo * gsd_power_introspection_data; + GVariant * get_devices_retval; bool bus_acquired; bool name_acquired; + int gsd_name_ownership_id; + int gsd_power_registration_id; + char * gsd_power_error_string; + + protected: + + static void + on_bus_acquired (GDBusConnection *conn, const gchar * name, gpointer gself) + { + g_debug ("bus acquired: %s, connection is %p", name, conn); + + DbusListenerTest * test = static_cast (gself); + test->connection = conn; + test->bus_acquired = true; + } + + static void + on_name_acquired (GDBusConnection * conn, const gchar * name, gpointer gself) + { + g_debug ("name acquired: %s, connection is %p", name, conn); + + DbusListenerTest * test = static_cast (gself); + test->name_acquired = true; + g_main_loop_quit (test->mainloop); + } + + static void + on_name_lost (GDBusConnection * conn, const gchar * name, gpointer gself) + { + g_debug ("name lost: %s, connection is %p", name, conn); + + DbusListenerTest * test = static_cast (gself); + test->name_acquired = false; + g_main_loop_quit (test->mainloop); + } + + protected: + + static void + on_devices_enumerated (IndicatorPowerDbusListener * l, GSList * devices, gpointer gself) + { + g_debug ("on_devices_enumerated"); + + DbusListenerTest * test = static_cast (gself); + test->name_acquired = false; + g_slist_foreach (devices, (GFunc)g_object_ref, NULL); + test->devices = g_slist_copy (devices); + g_main_loop_quit (test->mainloop); + } + + static void + gsd_power_handle_method_call (GDBusConnection * connection, + const gchar * sender, + const gchar * object_path, + const gchar * interface_name, + const gchar * method_name, + GVariant * parameters, + GDBusMethodInvocation * invocation, + gpointer gself) + { + DbusListenerTest * test = static_cast (gself); + g_assert (!g_strcmp0 (method_name, "GetDevices")); + if (test->gsd_power_error_string != NULL) { + const GQuark domain = g_quark_from_static_string ("mock-gsd-power"); + g_message ("returning an error"); + g_dbus_method_invocation_return_error_literal (invocation, domain, 0, test->gsd_power_error_string); + } else { + g_dbus_method_invocation_return_value (invocation, test->get_devices_retval); + } + } + + protected: virtual void SetUp() { @@ -61,15 +134,72 @@ class DbusListenerTest : public ::testing::Test name_acquired = false; connection = NULL; devices = NULL; + get_devices_retval = NULL; + gsd_power_error_string = NULL; + // bring up the test bus ensure_glib_initialized (); mainloop = g_main_loop_new (NULL, FALSE); bus = g_test_dbus_new (G_TEST_DBUS_NONE); g_test_dbus_up (bus); + + // own org.gnome.SettingsDameon on this test bus + gsd_name_ownership_id = g_bus_own_name ( + G_BUS_TYPE_SESSION, + GSD_SERVICE, + G_BUS_NAME_OWNER_FLAGS_NONE, + on_bus_acquired, + on_name_acquired, + on_name_lost, + this, NULL); + ASSERT_FALSE (bus_acquired); + ASSERT_FALSE (name_acquired); + ASSERT_TRUE (connection == NULL); + g_main_loop_run (mainloop); + ASSERT_TRUE (bus_acquired); + ASSERT_TRUE (name_acquired); + ASSERT_TRUE (G_IS_DBUS_CONNECTION(connection)); + + // parse the org.gnome.SettingsDaemon.Power interface + const gchar introspection_xml[] = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; + gsd_power_introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL); + ASSERT_TRUE (gsd_power_introspection_data != NULL); + + // Set up a mock GSD. + // All it really does is wait for calls to GetDevice and + // returns the get_devices_retval variant + const GDBusInterfaceVTable gsd_power_interface_vtable = { + gsd_power_handle_method_call, + NULL, /* GetProperty */ + NULL, /* SetProperty */ + }; + gsd_power_registration_id = g_dbus_connection_register_object (connection, + GSD_POWER_DBUS_PATH, + gsd_power_introspection_data->interfaces[0], + &gsd_power_interface_vtable, + this, NULL, NULL); } virtual void TearDown() { + g_free (gsd_power_error_string); + + g_dbus_connection_unregister_object (connection, gsd_power_registration_id); + + g_dbus_node_info_unref (gsd_power_introspection_data); + g_bus_unown_name (gsd_name_ownership_id); + g_slist_free_full (devices, g_object_unref); g_test_dbus_down (bus); g_main_loop_unref (mainloop); @@ -80,141 +210,82 @@ class DbusListenerTest : public ::testing::Test **** ***/ -/* -TEST_F(DbusListenerTest, GObjectNew) + +TEST_F(DbusListenerTest, GSDHasPowerAndBattery) { + // build a GetDevices retval that shows an AC line and a discharging battery + GVariantBuilder * builder = g_variant_builder_new (G_VARIANT_TYPE("a(susdut)")); + g_variant_builder_add (builder, "(susdut)", + "/org/freedesktop/UPower/devices/line_power_AC", + UP_DEVICE_KIND_LINE_POWER, + ". GThemedIcon ac-adapter-symbolic ac-adapter ", + 0.0, + UP_DEVICE_STATE_UNKNOWN, + 0); + g_variant_builder_add (builder, "(susdut)", + "/org/freedesktop/UPower/devices/battery_BAT0", + UP_DEVICE_KIND_BATTERY, + ". GThemedIcon battery-good-symbolic gpm-battery-060 battery-good ", + 52.871712, + UP_DEVICE_STATE_DISCHARGING, + 8834); + GVariant * value = g_variant_builder_end (builder); + get_devices_retval = g_variant_new_tuple (&value, 1); + g_variant_builder_unref (builder); + + // create an i-power dbus listener to watch for GSD + ASSERT_EQ (g_slist_length(devices), 0); GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, NULL)); ASSERT_TRUE (o != NULL); ASSERT_TRUE (INDICATOR_IS_POWER_DBUS_LISTENER(o)); - g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls - g_object_unref (o); -} -*/ - -static void -on_bus_acquired (GDBusConnection *conn, const gchar * name, gpointer gself) -{ - g_debug ("bus acquired: %s, connection is %p", name, conn); - - DbusListenerTest * test = static_cast (gself); - test->connection = conn; - test->bus_acquired = true; -} + g_signal_connect(o, INDICATOR_POWER_DBUS_LISTENER_DEVICES_ENUMERATED, + G_CALLBACK(on_devices_enumerated), this); + g_main_loop_run (mainloop); -static void -on_name_acquired (GDBusConnection * conn, const gchar * name, gpointer gself) -{ - g_debug ("name acquired: %s, connection is %p", name, conn); + // test the devices should have gotten + ASSERT_EQ (g_slist_length(devices), 2); + IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE (g_slist_nth_data (devices, 0)); + ASSERT_EQ (indicator_power_device_get_kind(device), UP_DEVICE_KIND_LINE_POWER); + ASSERT_STREQ ("/org/freedesktop/UPower/devices/line_power_AC", indicator_power_device_get_object_path(device)); + device = INDICATOR_POWER_DEVICE (g_slist_nth_data (devices, 1)); + ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device)); + ASSERT_STREQ ("/org/freedesktop/UPower/devices/battery_BAT0", indicator_power_device_get_object_path(device)); - DbusListenerTest * test = static_cast (gself); - test->name_acquired = true; - g_main_loop_quit (test->mainloop); + // cleanup + g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls + g_object_unref (o); } -static void -on_name_lost (GDBusConnection * conn, const gchar * name, gpointer gself) +TEST_F(DbusListenerTest, GSDHasNoDevices) { - g_debug ("name lost: %s, connection is %p", name, conn); + GVariantBuilder * builder = g_variant_builder_new (G_VARIANT_TYPE("a(susdut)")); + GVariant * value = g_variant_builder_end (builder); + get_devices_retval = g_variant_new_tuple (&value, 1); + g_variant_builder_unref (builder); - DbusListenerTest * test = static_cast (gself); - test->name_acquired = false; - g_main_loop_quit (test->mainloop); -} + // create an i-power dbus listener to watch for GSD + ASSERT_EQ (g_slist_length(devices), 0); + GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, NULL)); + ASSERT_TRUE (o != NULL); + ASSERT_TRUE (INDICATOR_IS_POWER_DBUS_LISTENER(o)); + g_signal_connect(o, INDICATOR_POWER_DBUS_LISTENER_DEVICES_ENUMERATED, + G_CALLBACK(on_devices_enumerated), this); + g_main_loop_run (mainloop); -static void -on_devices_enumerated (IndicatorPowerDbusListener * l, GSList * devices, gpointer gself) -{ - g_debug ("on_devices_enumerated"); + // test the devices should have gotten + ASSERT_EQ (g_slist_length(devices), 0); - DbusListenerTest * test = static_cast (gself); - test->name_acquired = false; - g_slist_foreach (devices, (GFunc)g_object_ref, NULL); - test->devices = g_slist_copy (devices); - g_main_loop_quit (test->mainloop); -} + // FIXME: this test improves coverage and confirms that the code + // doesn't crash, but more meaningful tests would be better too. -static void -gsd_power_handle_method_call (GDBusConnection *connection, - const gchar *sender, - const gchar *object_path, - const gchar *interface_name, - const gchar *method_name, - GVariant *parameters, - GDBusMethodInvocation *invocation, - gpointer user_data) -{ - if (!g_strcmp0 (method_name, "GetDevices")) - { - /* create builder */ - GVariantBuilder * builder = g_variant_builder_new (G_VARIANT_TYPE("a(susdut)")); - - g_variant_builder_add (builder, "(susdut)", - "/org/freedesktop/UPower/devices/line_power_AC", - UP_DEVICE_KIND_LINE_POWER, - ". GThemedIcon ac-adapter-symbolic ac-adapter ", - 0.0, - UP_DEVICE_STATE_UNKNOWN, - 0); - g_variant_builder_add (builder, "(susdut)", - "/org/freedesktop/UPower/devices/battery_BAT0", - UP_DEVICE_KIND_BATTERY, - ". GThemedIcon battery-good-symbolic gpm-battery-060 battery-good ", - 52.871712, - UP_DEVICE_STATE_DISCHARGING, - 8834); - - GVariant * value = g_variant_builder_end (builder); - GVariant * tuple = g_variant_new_tuple (&value, 1); - g_dbus_method_invocation_return_value (invocation, tuple); - g_variant_builder_unref (builder); - } + // cleanup + g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls + g_object_unref (o); } -static const GDBusInterfaceVTable gsd_power_interface_vtable = +TEST_F(DbusListenerTest, GSDReturnsError) { - gsd_power_handle_method_call, - NULL, /* GetProperty */ - NULL, /* SetProperty */ -}; - -TEST_F(DbusListenerTest, GnomeSettingsDaemon) -{ - // own org.gnome.SettingsDameon on the bus - const int name_ownership_id = g_bus_own_name ( - G_BUS_TYPE_SESSION, - GSD_SERVICE, - G_BUS_NAME_OWNER_FLAGS_NONE, - on_bus_acquired, - on_name_acquired, - on_name_lost, - this, NULL); - ASSERT_FALSE (bus_acquired); - ASSERT_FALSE (name_acquired); - ASSERT_TRUE (connection == NULL); - g_main_loop_run (mainloop); - ASSERT_TRUE (bus_acquired); - ASSERT_TRUE (name_acquired); - ASSERT_TRUE (G_IS_DBUS_CONNECTION(connection)); - - // register a mock org.gnome.SettingsDaemon.Power interface - const gchar introspection_xml[] = "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - ""; - GDBusNodeInfo * introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL); - ASSERT_TRUE (introspection_data != NULL); - const int registration_id = g_dbus_connection_register_object (connection, - GSD_POWER_DBUS_PATH, - introspection_data->interfaces[0], - &gsd_power_interface_vtable, - NULL, NULL, NULL); + gsd_power_error_string = g_strdup ("no devices for you lol"); // create an i-power dbus listener to watch for GSD ASSERT_EQ (g_slist_length(devices), 0); @@ -226,17 +297,12 @@ TEST_F(DbusListenerTest, GnomeSettingsDaemon) g_main_loop_run (mainloop); // test the devices should have gotten - ASSERT_EQ (g_slist_length(devices), 2); - IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE (g_slist_nth_data (devices, 0)); - ASSERT_EQ (indicator_power_device_get_kind(device), UP_DEVICE_KIND_LINE_POWER); - ASSERT_STREQ ("/org/freedesktop/UPower/devices/line_power_AC", indicator_power_device_get_object_path(device)); - device = INDICATOR_POWER_DEVICE (g_slist_nth_data (devices, 1)); - ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device)); - ASSERT_STREQ ("/org/freedesktop/UPower/devices/battery_BAT0", indicator_power_device_get_object_path(device)); + ASSERT_EQ (g_slist_length(devices), 0); + + // FIXME: this test improves coverage and confirms that the code + // doesn't crash, but more meaningful tests would be better too. // cleanup g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls g_object_unref (o); - g_dbus_connection_unregister_object (connection, registration_id); - g_bus_unown_name (name_ownership_id); } -- cgit v1.2.3 From ab87d8f8eaf75dda49dbd6e9ef56bf94dcf98e28 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 29 May 2012 17:28:15 -0500 Subject: add a test to make sure that the listener responds to a PropertiesChanged signal --- tests/test-dbus-listener.cc | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'tests') diff --git a/tests/test-dbus-listener.cc b/tests/test-dbus-listener.cc index 4c6c607..8bf74bf 100644 --- a/tests/test-dbus-listener.cc +++ b/tests/test-dbus-listener.cc @@ -306,3 +306,65 @@ TEST_F(DbusListenerTest, GSDReturnsError) g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls g_object_unref (o); } + +/* This test emits a PropertiesChanged signal and confirms that + the dbus listener asks for a fresh set of devices as a result. */ +TEST_F(DbusListenerTest, GSDPropChanged) +{ + gsd_power_error_string = g_strdup ("no devices for you lol"); + + // create an i-power dbus listener to watch for GSD + ASSERT_EQ (g_slist_length(devices), 0); + GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, NULL)); + ASSERT_TRUE (INDICATOR_IS_POWER_DBUS_LISTENER(o)); + g_signal_connect(o, INDICATOR_POWER_DBUS_LISTENER_DEVICES_ENUMERATED, + G_CALLBACK(on_devices_enumerated), this); + g_main_loop_run (mainloop); + // test the devices should have gotten + ASSERT_EQ (g_slist_length(devices), 0); + + // build a GetDevices retval that shows an AC line and a discharging battery + g_clear_pointer (&gsd_power_error_string, g_free); + GVariantBuilder * builder = g_variant_builder_new (G_VARIANT_TYPE("a(susdut)")); + g_variant_builder_add (builder, "(susdut)", + "/org/freedesktop/UPower/devices/line_power_AC", + UP_DEVICE_KIND_LINE_POWER, + ". GThemedIcon ac-adapter-symbolic ac-adapter ", + 0.0, + UP_DEVICE_STATE_UNKNOWN, + 0); + g_variant_builder_add (builder, "(susdut)", + "/org/freedesktop/UPower/devices/battery_BAT0", + UP_DEVICE_KIND_BATTERY, + ". GThemedIcon battery-good-symbolic gpm-battery-060 battery-good ", + 52.871712, + UP_DEVICE_STATE_DISCHARGING, + 8834); + GVariant * value = g_variant_builder_end (builder); + get_devices_retval = g_variant_new_tuple (&value, 1); + g_variant_builder_unref (builder); + + // tell the listener that some property changed + GVariantBuilder props_builder; + g_variant_builder_init (&props_builder, G_VARIANT_TYPE ("a{sv}")); + GVariant * props_changed = g_variant_new ("(s@a{sv}@as)", GSD_POWER_DBUS_INTERFACE, + g_variant_builder_end (&props_builder), + g_variant_new_strv (NULL, 0)); + g_variant_ref_sink (props_changed); + GError * error = NULL; + g_dbus_connection_emit_signal (connection, + NULL, + GSD_POWER_DBUS_PATH, + "org.freedesktop.DBus.Properties", + "PropertiesChanged", + props_changed, + &error); + ASSERT_TRUE(error == NULL); + + // give i-power's dbus listener a chance to ask for a fresh device list + g_main_loop_run (mainloop); + ASSERT_EQ (g_slist_length(devices), 2); + + // cleanup + g_object_unref (o); +} -- cgit v1.2.3 From b18b5862fb4e69773bf89328f4c65fdd344d8f1a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 May 2012 13:00:31 -0500 Subject: Add indicator_power_device_get_icon_names(). The main goal of this change is to make it possible to test the device's icon. A secondary goal is to clarify in the code how indicator-power's icons differ from the ones recommended by GSD. --- tests/test-device.cc | 201 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 196 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index 132d762..b11188c 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -34,11 +34,37 @@ namespace } } +class DeviceTest : public ::testing::Test +{ + protected: + + virtual void SetUp() + { + ensure_glib_initialized (); + } + + virtual void TearDown() + { + } + + protected: + + void check_icon_names (const IndicatorPowerDevice * device, const char * expected) + { + char ** names = indicator_power_device_get_icon_names (device); + char * str = g_strjoinv (";", names); + ASSERT_STREQ (expected, str); + g_free (str); + g_strfreev (names); + } +}; + + /*** **** ***/ -TEST(DeviceTest, GObjectNew) +TEST_F(DeviceTest, GObjectNew) { ensure_glib_initialized (); @@ -49,7 +75,7 @@ TEST(DeviceTest, GObjectNew) g_object_unref (o); } -TEST(DeviceTest, Properties) +TEST_F(DeviceTest, Properties) { int i; gdouble d; @@ -108,7 +134,7 @@ TEST(DeviceTest, Properties) g_object_unref (o); } -TEST(DeviceTest, New) +TEST_F(DeviceTest, New) { ensure_glib_initialized (); @@ -131,7 +157,7 @@ TEST(DeviceTest, New) g_object_unref (device); } -TEST(DeviceTest, NewFromVariant) +TEST_F(DeviceTest, NewFromVariant) { ensure_glib_initialized (); @@ -158,7 +184,7 @@ TEST(DeviceTest, NewFromVariant) g_variant_unref (variant); } -TEST(DeviceTest, BadAccessors) +TEST_F(DeviceTest, BadAccessors) { ensure_glib_initialized (); @@ -181,3 +207,168 @@ TEST(DeviceTest, BadAccessors) indicator_power_device_get_object_path (device); g_object_unref (device); } + +/*** +**** +***/ + +TEST_F(DeviceTest, IconNames) +{ + IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL)); + GObject * o = G_OBJECT(device); + + /* power */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_LINE_POWER, + NULL); + check_icon_names (device, "ac-adapter-symbolic;" + "ac-adapter;"); + + /* monitor */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_MONITOR, + NULL); + check_icon_names (device, "gpm-monitor-symbolic;" + "gpm-monitor;"); + + /* empty battery */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_EMPTY, + NULL); + check_icon_names (device, "battery-empty-symbolic;" + "gpm-battery-empty;" + "gpm-battery-000;" + "battery-empty;"); + + /* charged battery */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED, + NULL); + check_icon_names (device, "battery-full-charged-symbolic;battery-full-charging-symbolic;" + "gpm-battery-full;gpm-battery-100;" + "battery-full-charged;battery-full-charging;"); + + /* charging battery, 95% */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 95.0, + NULL); + check_icon_names (device, "battery-caution-charging-symbolic;" + "gpm-battery-000-charging;" + "battery-caution-charging;"); + + /* charging battery, 85% */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0, + NULL); + check_icon_names (device, "battery-caution-charging-symbolic;" + "gpm-battery-000-charging;" + "battery-caution-charging;"); + + /* charging battery, 50% */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + NULL); + check_icon_names (device, "battery-caution-charging-symbolic;" + "gpm-battery-000-charging;" + "battery-caution-charging;"); + + /* charging battery, 25% */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0, + NULL); + check_icon_names (device, "battery-caution-charging-symbolic;" + "gpm-battery-000-charging;" + "battery-caution-charging;"); + + /* charging battery, 5% */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0, + NULL); + check_icon_names (device, "battery-caution-charging-symbolic;" + "gpm-battery-000-charging;" + "battery-caution-charging;"); + + + /* discharging battery, 95% */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 95.0, + NULL); + check_icon_names (device, "battery-full-symbolic;" + "gpm-battery-100;" + "battery-full;"); + + /* discharging battery, 85% */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0, + NULL); + check_icon_names (device, "battery-full-symbolic;" + "gpm-battery-080;" + "battery-full;"); + + /* discharging battery, 50% -- 1 hour left */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60), + NULL); + check_icon_names (device, "battery-good-symbolic;" + "gpm-battery-060;" + "battery-good;"); + + /* discharging battery, 25% -- 1 hour left */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0, + INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60), + NULL); + check_icon_names (device, "battery-good-symbolic;" + "gpm-battery-040;" + "battery-good;"); + + /* discharging battery, 25% -- 15 minutes left */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0, + INDICATOR_POWER_DEVICE_TIME, (guint64)(60*15), + NULL); + check_icon_names (device, "battery-low-symbolic;" + "gpm-battery-020;" + "battery-low;"); + + /* discharging battery, 5% -- 1 hour left */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0, + INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60), + NULL); + check_icon_names (device, "battery-good-symbolic;" + "gpm-battery-040;" + "battery-good;"); + + /* discharging battery, 5% -- 15 minutes left */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0, + INDICATOR_POWER_DEVICE_TIME, (guint64)(60*15), + NULL); + check_icon_names (device, "battery-caution-symbolic;" + "gpm-battery-000;" + "battery-caution;"); + + /* state unknown */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_UNKNOWN, + NULL); + check_icon_names (device, "battery-missing-symbolic;" + "gpm-battery-missing;" + "battery-missing;"); + + /* cleanup */ + g_object_unref(o); +} + -- cgit v1.2.3 From 97867c31fd3f4767fe891de31786b7b32d6dd35a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 May 2012 13:08:27 -0500 Subject: remove IndicatorPowerDevice's now-unused device icon string. --- tests/test-device.cc | 12 ------------ tests/test-indicator.cc | 23 ++++++++++------------- 2 files changed, 10 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index b11188c..0ea7177 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -111,13 +111,6 @@ TEST_F(DeviceTest, Properties) ASSERT_STREQ (str, "/object/path"); g_free (str); - // ICON - key = INDICATOR_POWER_DEVICE_ICON; - g_object_set (o, key, "something", NULL); - g_object_get (o, key, &str, NULL); - ASSERT_STREQ (str, "something"); - g_free (str); - // PERCENTAGE key = INDICATOR_POWER_DEVICE_PERCENTAGE; g_object_set (o, key, 50.0, NULL); @@ -140,7 +133,6 @@ TEST_F(DeviceTest, New) IndicatorPowerDevice * device = indicator_power_device_new ("/object/path", UP_DEVICE_KIND_BATTERY, - "icon", 50.0, UP_DEVICE_STATE_CHARGING, 30); @@ -149,7 +141,6 @@ TEST_F(DeviceTest, New) 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); @@ -175,7 +166,6 @@ TEST_F(DeviceTest, NewFromVariant) 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); @@ -192,7 +182,6 @@ TEST_F(DeviceTest, BadAccessors) IndicatorPowerDevice * device = NULL; indicator_power_device_get_kind (device); indicator_power_device_get_time (device); - indicator_power_device_get_icon (device); indicator_power_device_get_state (device); indicator_power_device_get_percentage (device); indicator_power_device_get_object_path (device); @@ -201,7 +190,6 @@ TEST_F(DeviceTest, BadAccessors) device = reinterpret_cast(g_cancellable_new ()); indicator_power_device_get_kind (device); indicator_power_device_get_time (device); - indicator_power_device_get_icon (device); indicator_power_device_get_state (device); indicator_power_device_get_percentage (device); indicator_power_device_get_object_path (device); diff --git a/tests/test-indicator.cc b/tests/test-indicator.cc index 32d6f4f..b9f7321 100644 --- a/tests/test-indicator.cc +++ b/tests/test-indicator.cc @@ -61,13 +61,11 @@ class IndicatorTest : public ::testing::Test ac_device = indicator_power_device_new ( "/org/freedesktop/UPower/devices/line_power_AC", UP_DEVICE_KIND_LINE_POWER, - ". GThemedIcon ac-adapter-symbolic ac-adapter ", 0.0, UP_DEVICE_STATE_UNKNOWN, 0); battery_device = indicator_power_device_new ( "/org/freedesktop/UPower/devices/battery_BAT0", UP_DEVICE_KIND_BATTERY, - ". GThemedIcon battery-good-symbolic gpm-battery-060 battery-good ", 52.871712, UP_DEVICE_STATE_DISCHARGING, 8834); } @@ -238,7 +236,6 @@ TEST_F(IndicatorTest, AvoidChargingBatteriesWithZeroSecondsLeft) IndicatorPowerDevice * bad_battery_device = indicator_power_device_new ( "/org/freedesktop/UPower/devices/battery_BAT0", UP_DEVICE_KIND_BATTERY, - ". GThemedIcon battery-good-symbolic gpm-battery-060 battery-good ", 53, UP_DEVICE_STATE_CHARGING, 0); GSList * devices = NULL; @@ -262,34 +259,34 @@ TEST_F(IndicatorTest, OtherDevices) devices = g_slist_append (devices, indicator_power_device_new ( "/org/freedesktop/UPower/devices/mouse", UP_DEVICE_KIND_MOUSE, - "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + 0, UP_DEVICE_STATE_UNKNOWN, 0)); devices = g_slist_append (devices, indicator_power_device_new ( "/org/freedesktop/UPower/devices/ups", UP_DEVICE_KIND_UPS, - "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + 0, UP_DEVICE_STATE_UNKNOWN, 0)); devices = g_slist_append (devices, indicator_power_device_new ( "/org/freedesktop/UPower/devices/keyboard", UP_DEVICE_KIND_KEYBOARD, - "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + 0, UP_DEVICE_STATE_UNKNOWN, 0)); devices = g_slist_append (devices, indicator_power_device_new ( "/org/freedesktop/UPower/devices/pda", UP_DEVICE_KIND_PDA, - "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + 0, UP_DEVICE_STATE_UNKNOWN, 0)); devices = g_slist_append (devices, indicator_power_device_new ( "/org/freedesktop/UPower/devices/phone", UP_DEVICE_KIND_PHONE, - "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + 0, UP_DEVICE_STATE_UNKNOWN, 0)); devices = g_slist_append (devices, indicator_power_device_new ( "/org/freedesktop/UPower/devices/monitor", UP_DEVICE_KIND_MONITOR, - "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + 0, UP_DEVICE_STATE_UNKNOWN, 0)); devices = g_slist_append (devices, indicator_power_device_new ( "/org/freedesktop/UPower/devices/media_player", UP_DEVICE_KIND_MEDIA_PLAYER, - "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + 0, UP_DEVICE_STATE_UNKNOWN, 0)); devices = g_slist_append (devices, indicator_power_device_new ( "/org/freedesktop/UPower/devices/tablet", UP_DEVICE_KIND_TABLET, - "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + 0, UP_DEVICE_STATE_UNKNOWN, 0)); devices = g_slist_append (devices, indicator_power_device_new ( "/org/freedesktop/UPower/devices/computer", UP_DEVICE_KIND_COMPUTER, - "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + 0, UP_DEVICE_STATE_UNKNOWN, 0)); devices = g_slist_append (devices, indicator_power_device_new ( "/org/freedesktop/UPower/devices/unknown", UP_DEVICE_KIND_UNKNOWN, - "unused", 0, UP_DEVICE_STATE_UNKNOWN, 0)); + 0, UP_DEVICE_STATE_UNKNOWN, 0)); indicator_power_set_devices (power, devices); -- cgit v1.2.3 From ea0293e260480be4ccb796a51c614966a253fdbe Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 1 Jun 2012 13:21:08 -0500 Subject: Add unit tests for indicator_power_device_get_time_details() --- tests/test-device.cc | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index 0ea7177..3b3ff73 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -57,6 +57,25 @@ class DeviceTest : public ::testing::Test g_free (str); g_strfreev (names); } + + void check_strings (const IndicatorPowerDevice * device, + const char * expected_timestring, + const char * expected_details, + const char * expected_accessible) + { + char * timestring = NULL; + char * details = NULL; + char * accessible = NULL; + + indicator_power_device_get_time_details (device, ×tring, &details, &accessible); + EXPECT_STREQ (expected_timestring, timestring); + EXPECT_STREQ (expected_details, details); + EXPECT_STREQ (expected_accessible, accessible); + + g_free (accessible); + g_free (details); + g_free (timestring); + } }; @@ -346,8 +365,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-caution-symbolic;" "gpm-battery-000;" - "battery-caution;"); - + "battery-caution;"); /* state unknown */ g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_UNKNOWN, @@ -360,3 +378,70 @@ TEST_F(DeviceTest, IconNames) g_object_unref(o); } + +TEST_F(DeviceTest, Labels) +{ + // set our language so that i18n won't break these tests + char * real_lang = g_strdup(g_getenv ("LANG")); + g_setenv ("LANG", "en_US.UTF-8", TRUE); + + IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL)); + GObject * o = G_OBJECT(device); + + /* charging */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, guint64(60*61), + NULL); + check_strings (device, "(1:01)", + "Battery (1:01 to charge)", + "Battery (1 hour 1 minute to charge (50%))"); + + /* discharging, < 12 hours left */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, guint64(60*61), + NULL); + check_strings (device, "1:01", + "Battery (1:01 left)", + "Battery (1 hour 1 minute left (50%))"); + + /* discharging, > 12 hours left */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, guint64(60*60*13), + NULL); + check_strings (device, "13:00", "Battery", "Battery"); + + /* fully charged */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED, + INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + NULL); + check_strings (device, "", "Battery (charged)", "Battery (charged)"); + + /* percentage but no time estimate */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + NULL); + check_strings (device, "(50%)", "Battery (50%)", "Battery (50%)"); + + /* no percentage, no time estimate */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, + INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + NULL); + check_strings (device, "(not present)", "Battery (not present)", "Battery (not present)"); + + /* cleanup */ + g_object_unref(o); + g_setenv ("LANG", real_lang, TRUE); + g_free (real_lang); +} -- cgit v1.2.3 From 560aa0ec6f3b4f845e6cc0e6b3c25197d1905794 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 1 Jun 2012 13:38:16 -0500 Subject: Add coverage test for AC Adapters in indicator_power_device_get_time_details() --- tests/test-device.cc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index 3b3ff73..1233133 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -440,6 +440,14 @@ TEST_F(DeviceTest, Labels) NULL); check_strings (device, "(not present)", "Battery (not present)", "Battery (not present)"); + /* power line */ + g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_LINE_POWER, + INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_UNKNOWN, + INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, + INDICATOR_POWER_DEVICE_TIME, guint64(0), + NULL); + check_strings (device, "AC Adapter", "AC Adapter", "AC Adapter"); + /* cleanup */ g_object_unref(o); g_setenv ("LANG", real_lang, TRUE); -- cgit v1.2.3 From 5b17593fb388ab9febc2e4bc26d8054a34dd58c0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 1 Jun 2012 13:43:40 -0500 Subject: Fix edge case in indicator_power_device_get_icon_names() that returned a bad value if the caller passed in a NULL pointer as a device. Added regression test. --- tests/test-device.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index 1233133..525eee0 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -224,6 +224,9 @@ TEST_F(DeviceTest, IconNames) IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL)); GObject * o = G_OBJECT(device); + /* bad arguments */ + ASSERT_TRUE (indicator_power_device_get_icon_names (NULL) == NULL); + /* power */ g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_LINE_POWER, NULL); -- cgit v1.2.3 From 0b46d0852fa764f5a9cc5d7a71c279ed56c1401d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 1 Jun 2012 13:57:03 -0500 Subject: In indicator_power_device_get_time_details(), add a test for non-devices being passed in. --- tests/test-device.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index 525eee0..5d68880 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -388,8 +388,20 @@ TEST_F(DeviceTest, Labels) char * real_lang = g_strdup(g_getenv ("LANG")); g_setenv ("LANG", "en_US.UTF-8", TRUE); + /* bad args: NULL device */ + check_strings (NULL, NULL, NULL, NULL); + + /* bad args: a GObject that isn't a device */ + GObject * o = G_OBJECT(g_cancellable_new()); + check_strings ((IndicatorPowerDevice*)o, NULL, NULL, NULL); + g_object_unref (o); + + /** + *** + **/ + IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL)); - GObject * o = G_OBJECT(device); + o = G_OBJECT(device); /* charging */ g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, -- cgit v1.2.3 From b1080101b59542f27922d7b184b7b21e27919a85 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 1 Jun 2012 13:58:43 -0500 Subject: use C++-style comments in test-device.cc --- tests/test-device.cc | 64 ++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index 5d68880..cc0d9c5 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -109,7 +109,7 @@ TEST_F(DeviceTest, Properties) ASSERT_TRUE (o != NULL); ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(o)); - /* Test getting & setting a Device's properties. */ + // Test getting & setting a Device's properties. // KIND key = INDICATOR_POWER_DEVICE_KIND; @@ -163,7 +163,7 @@ TEST_F(DeviceTest, New) ASSERT_EQ ((int)indicator_power_device_get_percentage(device), 50); ASSERT_EQ (indicator_power_device_get_time(device), 30); - /* cleanup */ + // cleanup g_object_unref (device); } @@ -188,7 +188,7 @@ TEST_F(DeviceTest, NewFromVariant) ASSERT_EQ ((int)indicator_power_device_get_percentage(device), 50); ASSERT_EQ (indicator_power_device_get_time(device), 30); - /* cleanup */ + // cleanup g_object_unref (device); g_variant_unref (variant); } @@ -224,22 +224,22 @@ TEST_F(DeviceTest, IconNames) IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL)); GObject * o = G_OBJECT(device); - /* bad arguments */ + // bad arguments ASSERT_TRUE (indicator_power_device_get_icon_names (NULL) == NULL); - /* power */ + // power g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_LINE_POWER, NULL); check_icon_names (device, "ac-adapter-symbolic;" "ac-adapter;"); - /* monitor */ + // monitor g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_MONITOR, NULL); check_icon_names (device, "gpm-monitor-symbolic;" "gpm-monitor;"); - /* empty battery */ + // empty battery g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_EMPTY, NULL); @@ -248,7 +248,7 @@ TEST_F(DeviceTest, IconNames) "gpm-battery-000;" "battery-empty;"); - /* charged battery */ + // charged battery g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED, NULL); @@ -256,7 +256,7 @@ TEST_F(DeviceTest, IconNames) "gpm-battery-full;gpm-battery-100;" "battery-full-charged;battery-full-charging;"); - /* charging battery, 95% */ + // charging battery, 95% g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 95.0, @@ -265,7 +265,7 @@ TEST_F(DeviceTest, IconNames) "gpm-battery-000-charging;" "battery-caution-charging;"); - /* charging battery, 85% */ + // charging battery, 85% g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0, @@ -274,7 +274,7 @@ TEST_F(DeviceTest, IconNames) "gpm-battery-000-charging;" "battery-caution-charging;"); - /* charging battery, 50% */ + // charging battery, 50% g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, @@ -283,7 +283,7 @@ TEST_F(DeviceTest, IconNames) "gpm-battery-000-charging;" "battery-caution-charging;"); - /* charging battery, 25% */ + // charging battery, 25% g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0, @@ -292,7 +292,7 @@ TEST_F(DeviceTest, IconNames) "gpm-battery-000-charging;" "battery-caution-charging;"); - /* charging battery, 5% */ + // charging battery, 5% g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0, @@ -302,7 +302,7 @@ TEST_F(DeviceTest, IconNames) "battery-caution-charging;"); - /* discharging battery, 95% */ + // discharging battery, 95% g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 95.0, @@ -311,7 +311,7 @@ TEST_F(DeviceTest, IconNames) "gpm-battery-100;" "battery-full;"); - /* discharging battery, 85% */ + // discharging battery, 85% g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0, @@ -320,7 +320,7 @@ TEST_F(DeviceTest, IconNames) "gpm-battery-080;" "battery-full;"); - /* discharging battery, 50% -- 1 hour left */ + // discharging battery, 50% -- 1 hour left g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, @@ -330,7 +330,7 @@ TEST_F(DeviceTest, IconNames) "gpm-battery-060;" "battery-good;"); - /* discharging battery, 25% -- 1 hour left */ + // discharging battery, 25% -- 1 hour left g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0, @@ -340,7 +340,7 @@ TEST_F(DeviceTest, IconNames) "gpm-battery-040;" "battery-good;"); - /* discharging battery, 25% -- 15 minutes left */ + // discharging battery, 25% -- 15 minutes left g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0, @@ -350,7 +350,7 @@ TEST_F(DeviceTest, IconNames) "gpm-battery-020;" "battery-low;"); - /* discharging battery, 5% -- 1 hour left */ + // discharging battery, 5% -- 1 hour left g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0, @@ -360,7 +360,7 @@ TEST_F(DeviceTest, IconNames) "gpm-battery-040;" "battery-good;"); - /* discharging battery, 5% -- 15 minutes left */ + // discharging battery, 5% -- 15 minutes left g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0, @@ -369,7 +369,7 @@ TEST_F(DeviceTest, IconNames) check_icon_names (device, "battery-caution-symbolic;" "gpm-battery-000;" "battery-caution;"); - /* state unknown */ + // state unknown g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_UNKNOWN, NULL); @@ -377,7 +377,7 @@ TEST_F(DeviceTest, IconNames) "gpm-battery-missing;" "battery-missing;"); - /* cleanup */ + // cleanup g_object_unref(o); } @@ -388,10 +388,10 @@ TEST_F(DeviceTest, Labels) char * real_lang = g_strdup(g_getenv ("LANG")); g_setenv ("LANG", "en_US.UTF-8", TRUE); - /* bad args: NULL device */ + // bad args: NULL device check_strings (NULL, NULL, NULL, NULL); - /* bad args: a GObject that isn't a device */ + // bad args: a GObject that isn't a device GObject * o = G_OBJECT(g_cancellable_new()); check_strings ((IndicatorPowerDevice*)o, NULL, NULL, NULL); g_object_unref (o); @@ -403,7 +403,7 @@ TEST_F(DeviceTest, Labels) IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL)); o = G_OBJECT(device); - /* charging */ + // charging g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, @@ -413,7 +413,7 @@ TEST_F(DeviceTest, Labels) "Battery (1:01 to charge)", "Battery (1 hour 1 minute to charge (50%))"); - /* discharging, < 12 hours left */ + // discharging, < 12 hours left g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, @@ -423,7 +423,7 @@ TEST_F(DeviceTest, Labels) "Battery (1:01 left)", "Battery (1 hour 1 minute left (50%))"); - /* discharging, > 12 hours left */ + // discharging, > 12 hours left g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, @@ -431,7 +431,7 @@ TEST_F(DeviceTest, Labels) NULL); check_strings (device, "13:00", "Battery", "Battery"); - /* fully charged */ + // fully charged g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED, INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0, @@ -439,7 +439,7 @@ TEST_F(DeviceTest, Labels) NULL); check_strings (device, "", "Battery (charged)", "Battery (charged)"); - /* percentage but no time estimate */ + // percentage but no time estimate g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, @@ -447,7 +447,7 @@ TEST_F(DeviceTest, Labels) NULL); check_strings (device, "(50%)", "Battery (50%)", "Battery (50%)"); - /* no percentage, no time estimate */ + // no percentage, no time estimate g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, @@ -455,7 +455,7 @@ TEST_F(DeviceTest, Labels) NULL); check_strings (device, "(not present)", "Battery (not present)", "Battery (not present)"); - /* power line */ + // power line g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_LINE_POWER, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_UNKNOWN, INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, @@ -463,7 +463,7 @@ TEST_F(DeviceTest, Labels) NULL); check_strings (device, "AC Adapter", "AC Adapter", "AC Adapter"); - /* cleanup */ + // cleanup g_object_unref(o); g_setenv ("LANG", real_lang, TRUE); g_free (real_lang); -- cgit v1.2.3 From 9091bba8ac0ac70107bfe27276b1d6e9e3471fc8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 6 Jun 2012 16:00:06 -0500 Subject: reimplement indicator_power_device_get_icon_names() since our CA is incompatible with reusing code from GSD. --- tests/test-device.cc | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/test-device.cc b/tests/test-device.cc index cc0d9c5..2c88ea1 100644 --- a/tests/test-device.cc +++ b/tests/test-device.cc @@ -231,13 +231,13 @@ TEST_F(DeviceTest, IconNames) g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_LINE_POWER, NULL); check_icon_names (device, "ac-adapter-symbolic;" - "ac-adapter;"); + "ac-adapter"); // monitor g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_MONITOR, NULL); check_icon_names (device, "gpm-monitor-symbolic;" - "gpm-monitor;"); + "gpm-monitor"); // empty battery g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, @@ -246,7 +246,7 @@ TEST_F(DeviceTest, IconNames) check_icon_names (device, "battery-empty-symbolic;" "gpm-battery-empty;" "gpm-battery-000;" - "battery-empty;"); + "battery-empty"); // charged battery g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, @@ -254,7 +254,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-full-charged-symbolic;battery-full-charging-symbolic;" "gpm-battery-full;gpm-battery-100;" - "battery-full-charged;battery-full-charging;"); + "battery-full-charged;battery-full-charging"); // charging battery, 95% g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, @@ -263,7 +263,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-caution-charging-symbolic;" "gpm-battery-000-charging;" - "battery-caution-charging;"); + "battery-caution-charging"); // charging battery, 85% g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, @@ -272,7 +272,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-caution-charging-symbolic;" "gpm-battery-000-charging;" - "battery-caution-charging;"); + "battery-caution-charging"); // charging battery, 50% g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, @@ -281,7 +281,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-caution-charging-symbolic;" "gpm-battery-000-charging;" - "battery-caution-charging;"); + "battery-caution-charging"); // charging battery, 25% g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, @@ -290,7 +290,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-caution-charging-symbolic;" "gpm-battery-000-charging;" - "battery-caution-charging;"); + "battery-caution-charging"); // charging battery, 5% g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, @@ -299,7 +299,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-caution-charging-symbolic;" "gpm-battery-000-charging;" - "battery-caution-charging;"); + "battery-caution-charging"); // discharging battery, 95% @@ -309,7 +309,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-full-symbolic;" "gpm-battery-100;" - "battery-full;"); + "battery-full"); // discharging battery, 85% g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, @@ -318,7 +318,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-full-symbolic;" "gpm-battery-080;" - "battery-full;"); + "battery-full"); // discharging battery, 50% -- 1 hour left g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, @@ -328,7 +328,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-good-symbolic;" "gpm-battery-060;" - "battery-good;"); + "battery-good"); // discharging battery, 25% -- 1 hour left g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, @@ -338,7 +338,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-good-symbolic;" "gpm-battery-040;" - "battery-good;"); + "battery-good"); // discharging battery, 25% -- 15 minutes left g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, @@ -348,7 +348,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-low-symbolic;" "gpm-battery-020;" - "battery-low;"); + "battery-low"); // discharging battery, 5% -- 1 hour left g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, @@ -358,7 +358,7 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-good-symbolic;" "gpm-battery-040;" - "battery-good;"); + "battery-good"); // discharging battery, 5% -- 15 minutes left g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, @@ -368,14 +368,14 @@ TEST_F(DeviceTest, IconNames) NULL); check_icon_names (device, "battery-caution-symbolic;" "gpm-battery-000;" - "battery-caution;"); + "battery-caution"); // state unknown g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_UNKNOWN, NULL); check_icon_names (device, "battery-missing-symbolic;" "gpm-battery-missing;" - "battery-missing;"); + "battery-missing"); // cleanup g_object_unref(o); -- cgit v1.2.3 From 2343edb9f2a49354ab3d46a2fec85b840daf0709 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 3 Jul 2012 17:20:35 -0500 Subject: disable test-dbus-listener for now --- tests/Makefile.am | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index b6b543b..0c60247 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -45,11 +45,11 @@ test_device_SOURCES = test-device.cc test_device_LDADD = $(TEST_LIBS) test_device_CPPFLAGS = $(TEST_CPPFLAGS) -TESTS += test-dbus-listener -check_PROGRAMS += test-dbus-listener -test_dbus_listener_SOURCES = test-dbus-listener.cc -test_dbus_listener_LDADD = $(TEST_LIBS) -test_dbus_listener_CPPFLAGS = $(TEST_CPPFLAGS) +#TESTS += test-dbus-listener +#check_PROGRAMS += test-dbus-listener +#test_dbus_listener_SOURCES = test-dbus-listener.cc +#test_dbus_listener_LDADD = $(TEST_LIBS) +#test_dbus_listener_CPPFLAGS = $(TEST_CPPFLAGS) TESTS += test-indicator check_PROGRAMS += test-indicator -- cgit v1.2.3