From 705eb1b42bd83149592a284a035b54c3346936da Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 26 Apr 2012 14:34:38 -0500 Subject: add scaffolding for indicator-session-service Google Testing with libdbustest --- Makefile.am | 1 + configure.ac | 12 +++++++++ m4/gtest.m4 | 63 +++++++++++++++++++++++++++++++++++++++++++++ tests/Makefile.am | 19 ++++++++++++++ tests/test-service.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 166 insertions(+) create mode 100644 m4/gtest.m4 create mode 100644 tests/Makefile.am create mode 100644 tests/test-service.cc diff --git a/Makefile.am b/Makefile.am index bb27c84..b76302c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,7 @@ SUBDIRS = \ src \ data \ + tests \ po EXTRA_DIST = autogen.sh diff --git a/configure.ac b/configure.ac index 1ef7d50..4a1317e 100644 --- a/configure.ac +++ b/configure.ac @@ -14,6 +14,7 @@ IT_PROG_INTLTOOL([0.35.0]) AC_ISC_POSIX AC_PROG_CC +AC_PROG_CXX AM_PROG_CC_C_O AC_STDC_HEADERS AC_PROG_LIBTOOL @@ -32,6 +33,7 @@ GTK3_REQUIRED_VERSION=3.0 INDICATOR_REQUIRED_VERSION=0.3.19 DBUSMENUGTK_REQUIRED_VERSION=0.5.90 POLKIT_REQUIRED_VERSION=0.92 +DBUSTEST_REQUIRED_VERSION=0.0.5 AC_ARG_WITH([gtk], [AS_HELP_STRING([--with-gtk], @@ -87,6 +89,8 @@ AS_IF([test "x$with_gtk" = x3], [ AC_DEFINE(HAVE_GTK3, 1, [whether gtk3 is available]) ]) +PKG_CHECK_MODULES(LIBDBUSTEST, dbustest-1 >= DBUSTEST_REQUIRED_VERSION) + ########################### # GTK Logout Helper ########################### @@ -170,6 +174,13 @@ else fi AC_SUBST(DBUSSERVICEDIR) +########################### +# Google Test framework +########################### + +m4_include([m4/gtest.m4]) +CHECK_GTEST + ############################## # Custom Junk ############################## @@ -236,6 +247,7 @@ data/icons/scalable/Makefile data/icons/scalable/actions/Makefile data/icons/scalable/status/Makefile data/extra-sessions/Makefile +tests/Makefile po/Makefile.in ]) diff --git a/m4/gtest.m4 b/m4/gtest.m4 new file mode 100644 index 0000000..2de334c --- /dev/null +++ b/m4/gtest.m4 @@ -0,0 +1,63 @@ +# Copyright (C) 2012 Canonical, Ltd. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# Checks whether the gtest source is available on the system. Allows for +# adjusting the include and source path. Sets have_gtest=yes if the source is +# present. Sets GTEST_CPPFLAGS and GTEST_SOURCE to the preprocessor flags and +# source location respectively. +AC_DEFUN([CHECK_GTEST], +[ + AC_ARG_WITH([gtest-include-path], + [AS_HELP_STRING([--with-gtest-include-path], + [location of the Google test headers])], + [GTEST_CPPFLAGS="-I$withval"]) + + AC_ARG_WITH([gtest-source-path], + [AS_HELP_STRING([--with-gtest-source-path], + [location of the Google test sources, defaults to /usr/src/gtest])], + [GTEST_SOURCE="$withval"], + [GTEST_SOURCE="/usr/src/gtest"]) + + GTEST_CPPFLAGS="$GTEST_CPPFLAGS -I$GTEST_SOURCE" + + AC_LANG_PUSH([C++]) + + tmp_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $GTEST_CPPFLAGS" + + AC_CHECK_HEADER([gtest/gtest.h]) + + CPPFLAGS="$tmp_CPPFLAGS" + + AC_LANG_POP + + AC_CHECK_FILES([$GTEST_SOURCE/src/gtest-all.cc] + [$GTEST_SOURCE/src/gtest_main.cc], + [have_gtest_source=yes], + [have_gtest_source=no]) + + AS_IF([test "x$ac_cv_header_gtest_gtest_h" = xyes -a \ + "x$have_gtest_source" = xyes], + [have_gtest=yes] + [AC_SUBST(GTEST_CPPFLAGS)] + [AC_SUBST(GTEST_SOURCE)], + [have_gtest=no]) +]) # CHECK_GTEST diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..85df398 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,19 @@ +AM_CPPFLAGS = $(GTEST_CPPFLAGS) $(SESSIONSERVICE_CFLAGS) $(LIBDBUSTEST_CFLAGS) -I${top_srcdir}/src -Wall -Werror +AM_CXXFLAGS = $(GTEST_CXXFLAGS) + +check_PROGRAMS = test-service +test_service_SOURCES = test-service.cc +test_service_LDADD = $(SESSIONSERVICE_LIBS) $(LIBDBUSTEST_LIBS) libgtest.a + +check_LIBRARIES = libgtest.a +nodist_libgtest_a_SOURCES = \ + $(GTEST_SOURCE)/src/gtest-all.cc \ + $(GTEST_SOURCE)/src/gtest_main.cc + +check_SCRIPTS = test-service-runner.sh +test-service-runner.sh: Makefile.am + @echo "#!/bin/sh" > $@ + @echo $(top_builddir)/tests/test-service $(top_builddir)/src/indicator-session-service$(EXEEXT) 2\>/dev/null >> $@ + @chmod +x $@ + +TESTS = ${check_SCRIPTS} diff --git a/tests/test-service.cc b/tests/test-service.cc new file mode 100644 index 0000000..c3d2471 --- /dev/null +++ b/tests/test-service.cc @@ -0,0 +1,71 @@ +/* +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-shared-names.h" + +/*** +**** +***/ + +static const char * the_executable = NULL; + +/** + * Fixture class for testing indicator-session-service with Google Test. + */ +class SessionServiceTest: public IndicatorServiceTest +{ + public: + virtual ~SessionServiceTest() {} + SessionServiceTest(): IndicatorServiceTest(INDICATOR_SESSION_DBUS_NAME, + INDICATOR_SESSION_DBUS_OBJECT, + the_executable) { } + public: + virtual void SetUp() { + wait_seconds(1); + IndicatorServiceTest::SetUp(); + } + virtual void TearDown() { + IndicatorServiceTest::TearDown(); + } +}; + + +/** + * Basic sanity test to see if we can account for all our menuitems. + */ +TEST_F(SessionServiceTest, HelloWorld) +{ + ASSERT_TRUE(true); +} + + +int +main (int argc, char *argv[]) +{ + if (argc < 2) { + fprintf (stderr, "Usage: appname /path/to/indicator-session-service"); + return -1; + } + the_executable = argv[1]; + fprintf (stdout, "executable is '%s'\n", the_executable); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} -- cgit v1.2.3 From 6187dfbd140c6f3af8dce96c3cac1e86c6ff0442 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 26 Apr 2012 15:01:53 -0500 Subject: only require GTest and libdbustest if we're building the unit tests --- Makefile.am | 7 ++++++- configure.ac | 22 ++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Makefile.am b/Makefile.am index b76302c..c05a4f0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,9 +2,14 @@ SUBDIRS = \ src \ data \ - tests \ po +if BUILD_TESTS +SUBDIRS += tests +# build src first +test: src +endif + EXTRA_DIST = autogen.sh DISTCHECK_CONFIGURE_FLAGS = --enable-localinstall diff --git a/configure.ac b/configure.ac index 4a1317e..476fc2e 100644 --- a/configure.ac +++ b/configure.ac @@ -89,8 +89,6 @@ AS_IF([test "x$with_gtk" = x3], [ AC_DEFINE(HAVE_GTK3, 1, [whether gtk3 is available]) ]) -PKG_CHECK_MODULES(LIBDBUSTEST, dbustest-1 >= DBUSTEST_REQUIRED_VERSION) - ########################### # GTK Logout Helper ########################### @@ -178,8 +176,23 @@ AC_SUBST(DBUSSERVICEDIR) # Google Test framework ########################### -m4_include([m4/gtest.m4]) -CHECK_GTEST +AC_ARG_ENABLE([tests], + [AS_HELP_STRING([--disable-tests], [Disable test scripts and tools (default=auto)])], + [enable_tests=${enableval}], + [enable_tests=auto]) +if test "x$enable_tests" != "xno"; then + m4_include([m4/gtest.m4]) + CHECK_GTEST + if test "x$enable_tests" = "xauto"; then + enable_tests=${have_gtest} + elif test "x$enable_tests" = "xyes" && test "x$have_gtest" != "xyes"; then + AC_MSG_ERROR([tests were requested but gtest is not installed.]) + fi + if test "x$enable_tests" = "xyes"; then + PKG_CHECK_MODULES(LIBDBUSTEST, dbustest-1 >= DBUSTEST_REQUIRED_VERSION) + fi +fi +AM_CONDITIONAL([BUILD_TESTS],[test "x$enable_tests" = "xyes"]) ############################## # Custom Junk @@ -266,5 +279,6 @@ SUS Indicator Configuration: Indicator GTK: $with_gtk Logout Helper: $have_gtklogouthelper APT support: $enable_apt + Enable tests: $enable_tests Coverage reporting: $use_gcov ]) -- cgit v1.2.3 From 149989e0d32b29544c4d1b6a2dcef35645e29a62 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 26 Apr 2012 15:07:28 -0500 Subject: fix tyop --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index c05a4f0..ad42d8e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,7 +7,7 @@ SUBDIRS = \ if BUILD_TESTS SUBDIRS += tests # build src first -test: src +tests: src endif EXTRA_DIST = autogen.sh -- cgit v1.2.3 From 1bab86efd3e4637d61e20364c2859982605850b1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 26 Apr 2012 16:37:10 -0500 Subject: sync with the other indicatorsGTest automake rules --- configure.ac | 8 ++++++-- tests/Makefile.am | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 476fc2e..e90a05e 100644 --- a/configure.ac +++ b/configure.ac @@ -189,10 +189,14 @@ if test "x$enable_tests" != "xno"; then AC_MSG_ERROR([tests were requested but gtest is not installed.]) fi if test "x$enable_tests" = "xyes"; then - PKG_CHECK_MODULES(LIBDBUSTEST, dbustest-1 >= DBUSTEST_REQUIRED_VERSION) + PKG_CHECK_MODULES([TEST_SERVICE],[indicator-0.4 >= $INDICATOR_REQUIRED_VERSION + dbustest-1 >= $DBUSTEST_REQUIRED_VERSION + dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION]) fi fi AM_CONDITIONAL([BUILD_TESTS],[test "x$enable_tests" = "xyes"]) +AC_SUBST([TEST_SERVICE_CFLAGS]) +AC_SUBST([TEST_SERVICE_LDFLAGS]) ############################## # Custom Junk @@ -279,6 +283,6 @@ SUS Indicator Configuration: Indicator GTK: $with_gtk Logout Helper: $have_gtklogouthelper APT support: $enable_apt - Enable tests: $enable_tests + Unit Tests: $enable_tests Coverage reporting: $use_gcov ]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 85df398..c03af4c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,9 +1,10 @@ -AM_CPPFLAGS = $(GTEST_CPPFLAGS) $(SESSIONSERVICE_CFLAGS) $(LIBDBUSTEST_CFLAGS) -I${top_srcdir}/src -Wall -Werror +AM_CPPFLAGS = $(GTEST_CPPFLAGS) $(INDICATOR_CFLAGS) -I${top_srcdir}/src -Wall -Werror AM_CXXFLAGS = $(GTEST_CXXFLAGS) check_PROGRAMS = test-service test_service_SOURCES = test-service.cc -test_service_LDADD = $(SESSIONSERVICE_LIBS) $(LIBDBUSTEST_LIBS) libgtest.a +test_service_LDADD = $(TEST_SERVICE_LIBS) libgtest.a +test_service_CPPFLAGS = $(TEST_SERVICE_CFLAGS) $(AM_CPPFLAGS) check_LIBRARIES = libgtest.a nodist_libgtest_a_SOURCES = \ -- cgit v1.2.3 From 123a7fec04d313d4d420249ab24a38eb587c3ef7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 27 Apr 2012 09:43:45 -0500 Subject: Change the service path to be a define instead of passed on the command line --- tests/Makefile.am | 14 ++++++-------- tests/test-service.cc | 15 +-------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index c03af4c..628056b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,20 +1,18 @@ + AM_CPPFLAGS = $(GTEST_CPPFLAGS) $(INDICATOR_CFLAGS) -I${top_srcdir}/src -Wall -Werror AM_CXXFLAGS = $(GTEST_CXXFLAGS) +TESTS = test-service check_PROGRAMS = test-service test_service_SOURCES = test-service.cc test_service_LDADD = $(TEST_SERVICE_LIBS) libgtest.a -test_service_CPPFLAGS = $(TEST_SERVICE_CFLAGS) $(AM_CPPFLAGS) +test_service_CPPFLAGS = \ + $(TEST_SERVICE_CFLAGS) \ + $(AM_CPPFLAGS) \ + -DINDICATOR_SERVICE_PATH="\"$(top_builddir)/src/indicator-session-service\"" check_LIBRARIES = libgtest.a nodist_libgtest_a_SOURCES = \ $(GTEST_SOURCE)/src/gtest-all.cc \ $(GTEST_SOURCE)/src/gtest_main.cc -check_SCRIPTS = test-service-runner.sh -test-service-runner.sh: Makefile.am - @echo "#!/bin/sh" > $@ - @echo $(top_builddir)/tests/test-service $(top_builddir)/src/indicator-session-service$(EXEEXT) 2\>/dev/null >> $@ - @chmod +x $@ - -TESTS = ${check_SCRIPTS} diff --git a/tests/test-service.cc b/tests/test-service.cc index c3d2471..cb10070 100644 --- a/tests/test-service.cc +++ b/tests/test-service.cc @@ -36,7 +36,7 @@ class SessionServiceTest: public IndicatorServiceTest virtual ~SessionServiceTest() {} SessionServiceTest(): IndicatorServiceTest(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT, - the_executable) { } + INDICATOR_SERVICE_PATH) { } public: virtual void SetUp() { wait_seconds(1); @@ -56,16 +56,3 @@ TEST_F(SessionServiceTest, HelloWorld) ASSERT_TRUE(true); } - -int -main (int argc, char *argv[]) -{ - if (argc < 2) { - fprintf (stderr, "Usage: appname /path/to/indicator-session-service"); - return -1; - } - the_executable = argv[1]; - fprintf (stdout, "executable is '%s'\n", the_executable); - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} -- cgit v1.2.3 From f2298244150295340ce53a35ea6ff92433105f2c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 27 Apr 2012 09:47:59 -0500 Subject: Switch to using the xorg-gtest main so that we're running under a dummy Xserver --- configure.ac | 1 + tests/Makefile.am | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index e90a05e..3bac232 100644 --- a/configure.ac +++ b/configure.ac @@ -183,6 +183,7 @@ AC_ARG_ENABLE([tests], if test "x$enable_tests" != "xno"; then m4_include([m4/gtest.m4]) CHECK_GTEST + CHECK_XORG_GTEST if test "x$enable_tests" = "xauto"; then enable_tests=${have_gtest} elif test "x$enable_tests" = "xyes" && test "x$have_gtest" != "xyes"; then diff --git a/tests/Makefile.am b/tests/Makefile.am index 628056b..5eca08a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,10 @@ -AM_CPPFLAGS = $(GTEST_CPPFLAGS) $(INDICATOR_CFLAGS) -I${top_srcdir}/src -Wall -Werror +AM_CPPFLAGS = \ + $(GTEST_CPPFLAGS) \ + $(XORG_GTEST_CPPFLAGS) \ + $(INDICATOR_CFLAGS) \ + -I${top_srcdir}/src \ + -Wall -Werror AM_CXXFLAGS = $(GTEST_CXXFLAGS) TESTS = test-service @@ -13,6 +18,7 @@ test_service_CPPFLAGS = \ check_LIBRARIES = libgtest.a nodist_libgtest_a_SOURCES = \ + $(XORG_GTEST_SOURCE)/src/xorg-gtest-all.cpp \ $(GTEST_SOURCE)/src/gtest-all.cc \ - $(GTEST_SOURCE)/src/gtest_main.cc + $(XORG_GTEST_SOURCE)/src/xorg-gtest_main.cpp -- cgit v1.2.3