diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2012-03-20 18:00:22 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2012-03-20 18:00:22 -0500 |
commit | 3d7adc379fb82ac225b943724900671fc91abba5 (patch) | |
tree | 1270e09eb8b6a77235f5f2a0ae450a419feaaf17 | |
parent | 6177dacd1c6eeb61912c1c7db245bc58ae81bcee (diff) | |
parent | dcd64738bfb7a4060080526203fa68e9c176e48b (diff) | |
download | ayatana-indicator-messages-3d7adc379fb82ac225b943724900671fc91abba5.tar.gz ayatana-indicator-messages-3d7adc379fb82ac225b943724900671fc91abba5.tar.bz2 ayatana-indicator-messages-3d7adc379fb82ac225b943724900671fc91abba5.zip |
merge lp:~allanlesage/indicator-messages/TDD for automake cleanups and test-oriented fixes
-rw-r--r-- | Makefile.am | 47 | ||||
-rw-r--r-- | Makefile.am.coverage | 44 | ||||
-rw-r--r-- | configure.ac | 32 | ||||
-rw-r--r-- | m4/gcov.m4 | 23 | ||||
-rw-r--r-- | m4/gtest.m4 | 63 | ||||
-rw-r--r-- | test/Makefile.am | 86 | ||||
-rw-r--r-- | test/test-gtest.cpp | 12 |
7 files changed, 261 insertions, 46 deletions
diff --git a/Makefile.am b/Makefile.am index e31937a..bef67bd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,18 @@ SUBDIRS = \ data \ po +if BUILD_TESTS +SUBDIRS += \ + test + +# build src first +test: src + +endif + + + + DISTCHECK_CONFIGURE_FLAGS = --enable-localinstall --enable-deprecations dist-hook: @@ -33,37 +45,4 @@ dist-hook: fi -# Coverage targets - -.PHONY: clean-gcda -clean-gcda: - @echo Removing old coverage results - -find -name '*.gcda' -print | xargs -r rm - -.PHONY: coverage-html generate-coverage-html clean-coverage-html -coverage-html: clean-gcda - -$(MAKE) $(AM_MAKEFLAGS) -k check - $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html - -generate-coverage-html: - @echo Collecting coverage data - $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool - LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info - -clean-coverage-html: clean-gcda - -$(LCOV) --directory $(top_builddir) -z - -rm -rf coverage.info coveragereport - -.PHONY: coverage-xml generate-coverage-xml clean-coverage-xml -coverage-xml: clean-gcda - -$(MAKE) $(AM_MAKEFLAGS) -k check - $(MAKE) $(AM_MAKEFLAGS) generate-coverage-xml - -generate-coverage-xml: - @echo Generating coverage XML report - $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml - -clean-coverage-xml: clean-gcda - -rm -rf $(top_builddir)/coverage.xml - -clean-local: clean-coverage-html clean-coverage-xml +include $(top_srcdir)/Makefile.am.coverage diff --git a/Makefile.am.coverage b/Makefile.am.coverage new file mode 100644 index 0000000..9c59b95 --- /dev/null +++ b/Makefile.am.coverage @@ -0,0 +1,44 @@ + +# Coverage targets + +.PHONY: clean-gcda \ + coverage-html generate-coverage-html clean-coverage-html \ + coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr + +clean-local: clean-coverage-html clean-coverage-gcovr + +if HAVE_GCOV + +clean-gcda: + @echo Removing old coverage results + -find -name '*.gcda' -print | xargs -r rm + +coverage-html: clean-gcda + -$(MAKE) $(AM_MAKEFLAGS) -k check + $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html + +generate-coverage-html: + @echo Collecting coverage data + $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool + LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info + +clean-coverage-html: clean-gcda + -$(LCOV) --directory $(top_builddir) -z + -rm -rf coverage.info coveragereport + +if HAVE_GCOVR + +coverage-gcovr: clean-gcda + -$(MAKE) $(AM_MAKEFLAGS) -k check + $(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr + +generate-coverage-gcovr: + @echo Generating coverage GCOVR report + $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.gcovr + +clean-coverage-gcovr: clean-gcda + -rm -rf $(top_builddir)/coverage.gcovr + +endif # HAVE_GCOVR + +endif # HAVE_GCOV diff --git a/configure.ac b/configure.ac index 28f9091..a429d17 100644 --- a/configure.ac +++ b/configure.ac @@ -31,6 +31,9 @@ AS_IF([test "x$enable_deprecations" = xno], [CFLAGS="$CFLAGS -DG_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED -DGSEAL_ENABLE -DGTK_DISABLE_SINGLE_INCLUDES"] ) +# the Google Test targets are cpp +AC_PROG_CXX + ########################### # Dependencies ########################### @@ -42,6 +45,7 @@ PANEL_REQUIRED_VERSION=2.0.0 INDICATE_REQUIRED_VERSION=0.6.90 INDICATOR_REQUIRED_VERSION=0.3.19 DBUSMENUGTK_REQUIRED_VERSION=0.5.90 +GLIB_REQUIRED_VERSION=2.31.20 AC_ARG_WITH([gtk], [AS_HELP_STRING([--with-gtk], @@ -54,14 +58,18 @@ AS_IF([test "x$with_gtk" = x3], gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION indicate-0.7 >= $INDICATE_REQUIRED_VERSION - dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION) + dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION + glib-2.0 >= $GLIB_REQUIRED_VERSION + gmodule-2.0 >= $GLIB_REQUIRED_VERSION) ], [test "x$with_gtk" = x2], [PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION indicator-0.4 >= $INDICATOR_REQUIRED_VERSION indicate-0.7 >= $INDICATE_REQUIRED_VERSION - dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION) + dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION + glib-2.0 >= $GLIB_REQUIRED_VERSION + gmodule-2.0 >= $GLIB_REQUIRED_VERSION) ], [AC_MSG_FAILURE([Value for --with-indicator-gtk was neither 2 nor 3])] ) @@ -69,6 +77,15 @@ AC_SUBST(APPLET_CFLAGS) AC_SUBST(APPLET_LIBS) ########################### +# Test Dependencies +########################### + +AC_ARG_ENABLE([tests], + AC_HELP_STRING([--disable-tests], [Disable test scripts and tools]),, + [enable_tests=auto]) +AM_CONDITIONAL(BUILD_TESTS, test xyes = xyes) + +########################### # Status Provider Deps ########################### @@ -96,11 +113,21 @@ AC_SUBST(STATUS_PROVIDER_EMESENE_LIBS) m4_include([m4/gcov.m4]) AC_TDD_GCOV +AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes]) +AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes]) +AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes]) AC_SUBST(COVERAGE_CFLAGS) AC_SUBST(COVERAGE_CXXFLAGS) AC_SUBST(COVERAGE_LDFLAGS) ########################### +# Google Test framework +########################### + +m4_include([m4/gtest.m4]) +CHECK_GTEST + +########################### # Check to see if we're local ########################### @@ -189,6 +216,7 @@ data/icons/scalable/Makefile data/icons/scalable/status/Makefile data/icons/scalable/categories/Makefile po/Makefile.in +test/Makefile ]) ########################### @@ -5,11 +5,10 @@ # * gcovr # # Sets ac_cv_check_gcov to yes if tooling is present -# and reports the executables to the variables LCOV, GCOVR and GENHTML. +# and reports the executables to the variables LCOV, GCOVR and GENHTML. AC_DEFUN([AC_TDD_GCOV], -[AC_CACHE_CHECK([whether code coverage tools are available], ac_cv_check_gcov, [ -AC_ARG_ENABLE(gcov, + AC_ARG_ENABLE(gcov, AS_HELP_STRING([--enable-gcov], [enable coverage testing with gcov]), [use_gcov=$enableval], [use_gcov=no]) @@ -34,7 +33,6 @@ AC_ARG_ENABLE(gcov, lcov_version_list="1.6 1.7 1.8 1.9" AC_CHECK_PROG(LCOV, lcov, lcov) AC_CHECK_PROG(GENHTML, genhtml, genhtml) - AC_CHECK_PROG(GCOVR, gcovr, gcovr) if test "$LCOV"; then AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [ @@ -63,10 +61,8 @@ AC_ARG_ENABLE(gcov, AC_MSG_ERROR([Could not find genhtml from the lcov package]) fi - if test -z "$GCOVR"; then - AC_MSG_ERROR([Could not find gcovr; easy_install (or pip) gcovr]) - fi - + ac_cv_check_gcov=yes + ac_cv_check_lcov=yes # Remove all optimization flags from CFLAGS changequote({,}) @@ -78,6 +74,13 @@ AC_ARG_ENABLE(gcov, COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage" COVERAGE_LDFLAGS="-lgcov" -fi -])]) # AC_TDD_GCOV + # Check availability of gcovr + AC_CHECK_PROG(GCOVR, gcovr, gcovr) + if test -z "$GCOVR"; then + ac_cv_check_gcovr=no + else + ac_cv_check_gcovr=yes + fi +fi +]) # AC_TDD_GCOV 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/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..8986a40 --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,86 @@ + +check_LIBRARIES = libgtest.a +check_PROGRAMS = test-gtest + +TESTS = + +AM_CPPFLAGS = $(GTEST_CPPFLAGS) \ + -I${top_srcdir}/src + +nodist_libgtest_a_SOURCES = $(GTEST_SOURCE)/src/gtest-all.cc +libgtest_a_SOURCES = \ + $(GTEST_SOURCE)/src/gtest-all.cc \ + $(GTEST_SOURCE)/src/gtest_main.cc +libgtest_a_CPPFLAGS = \ + $(GTEST_CPPFLAGS) -w +libgtest_a_CXXFLAGS = \ + $(AM_CXXFLAGS) +libgtest_a_CPPFLAGS = \ + $(AM_CPPFLAGS) + +TESTS += test-gtest + +test_gtest_SOURCES = \ + $(top_srcdir)/src/launcher-menu-item.c \ + $(top_srcdir)/src/default-applications.c \ + $(top_srcdir)/src/seen-db.c \ + test-gtest.cpp +test_gtest_CPPFLAGS = \ + $(APPLET_CFLAGS) \ + $(AM_CPPFLAGS) +test_gtest_LDFLAGS = -pthread +test_gtest_LDADD = \ + $(APPLET_LIBS) \ + libgtest.a + + +###################################### +# Lib containing code under test +###################################### + +lib_LTLIBRARIES = \ + libindicator-messages-service.la + +libindicator_messages_service_la_HEADERS = \ + $(top_srcdir)/src/default-applications.h \ + $(top_srcdir)/src/messages-service-dbus.h \ + $(top_srcdir)/src/gen-messages-service.xml.h \ + $(top_srcdir)/src/im-menu-item.h \ + $(top_srcdir)/src/app-menu-item.h \ + $(top_srcdir)/src/launcher-menu-item.h \ + $(top_srcdir)/src/seen-db.h \ + $(top_srcdir)/src/dirs.h \ + $(top_srcdir)/src/dbus-data.h \ + $(top_srcdir)/src/status-items.h + +libindicator_messages_service_la_SOURCES = \ + $(top_srcdir)/src/default-applications.c \ + $(top_srcdir)/src/messages-service.c \ + $(top_srcdir)/src/messages-service-dbus.c \ + $(top_srcdir)/src/gen-messages-service.xml.c \ + $(top_srcdir)/src/im-menu-item.c \ + $(top_srcdir)/src/app-menu-item.c \ + $(top_srcdir)/src/launcher-menu-item.c \ + $(top_srcdir)/src/seen-db.c \ + $(top_srcdir)/src/status-items.c + +libindicator_messages_service_ladir = \ + $(includedir)/libindicator-messages-service/ + +libindicator_messages_service_la_CFLAGS = \ + $(APPLET_CFLAGS) \ + $(COVERAGE_CFLAGS) \ + -Wall \ + -Wl,-Bsymbolic-functions \ + -Wl,-z,defs \ + -Wl,--as-needed \ + -Werror \ + -DG_LOG_DOMAIN=\"Indicator-Messages\" \ + -DSTATUS_PROVIDER_DIR=\"$(STATUS_PROVIDER_DIR)\" + +libindicator_messages_service_la_LIBADD = \ + $(APPLET_LIBS) \ + $(top_builddir)/src/.libs/libindicator-messages-status-provider.la + +libindicator_messages_service_la_LDFLAGS = \ + $(COVERAGE_LDFLAGS) diff --git a/test/test-gtest.cpp b/test/test-gtest.cpp new file mode 100644 index 0000000..1cc97be --- /dev/null +++ b/test/test-gtest.cpp @@ -0,0 +1,12 @@ + +#include <glib.h> +#include <gtest/gtest.h> + +extern "C" { + #include "launcher-menu-item.h" +} + +TEST(LauncherMenuItem, NameInitialized) { + g_type_init(); + EXPECT_TRUE(true); +} |