From 18c61112d7d6d475982cc6d1cafc024e29e720cc Mon Sep 17 00:00:00 2001 From: "Hong Jen Yee (PCMan)" Date: Mon, 20 Sep 2010 02:01:52 +0800 Subject: [PATCH] Try to integrate unit test provided by glib and gtk-doc. --- Makefile.am | 8 +- Makefile.decl | 90 ++++++++++++++++++++ autogen.sh | 12 +-- configure.ac | 7 ++ docs/Makefile.am | 3 + docs/reference/Makefile.am | 3 + docs/reference/libfm/Makefile.am | 139 +++++++++++++++++++++++++++++++ src/Makefile.am | 6 +- src/tests/Makefile.am | 23 +++++ src/tests/test-fm-path.c | 25 ++++++ 10 files changed, 308 insertions(+), 8 deletions(-) create mode 100644 Makefile.decl create mode 100644 docs/Makefile.am create mode 100644 docs/reference/Makefile.am create mode 100644 docs/reference/libfm/Makefile.am create mode 100644 src/tests/Makefile.am create mode 100644 src/tests/test-fm-path.c diff --git a/Makefile.am b/Makefile.am index 82574cfb..549d6da6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,8 +1,10 @@ +include $(top_srcdir)/Makefile.decl + NULL= -SUBDIRS=src po data +SUBDIRS=src po data docs -EXTRA_DIST = \ +EXTRA_DIST += \ libfm.pc.in \ libfm-gtk.pc.in \ $(NULL) @@ -12,3 +14,5 @@ pkgconfig_DATA = \ libfm.pc \ libfm-gtk.pc \ $(NULL) + +DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc diff --git a/Makefile.decl b/Makefile.decl new file mode 100644 index 00000000..f51dac4b --- /dev/null +++ b/Makefile.decl @@ -0,0 +1,90 @@ +# GLIB - Library of useful C routines + +#GTESTER = gtester # for non-GLIB packages +GTESTER = gtester # for the GLIB package +GTESTER_REPORT = gtester-report # for the GLIB package + +# initialize variables for unconditional += appending +EXTRA_DIST = +TEST_PROGS = + +### testing rules + +# test: run all tests in cwd and subdirs +test: test-nonrecursive +# if OS_UNIX + @ for subdir in $(SUBDIRS) . ; do \ + test "$$subdir" = "." -o "$$subdir" = "po" || \ + ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \ + done +# endif + +# test-nonrecursive: run tests only in cwd +test-nonrecursive: ${TEST_PROGS} +# if OS_UNIX + @test -z "${TEST_PROGS}" || MALLOC_CHECK_=2 MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256)) ${GTESTER} --verbose ${TEST_PROGS} +# endif + +# test-report: run tests in subdirs and generate report +# perf-report: run tests in subdirs with -m perf and generate report +# full-report: like test-report: with -m perf and -m slow +test-report perf-report full-report: ${TEST_PROGS} + @test -z "${TEST_PROGS}" || { \ + case $@ in \ + test-report) test_options="-k";; \ + perf-report) test_options="-k -m=perf";; \ + full-report) test_options="-k -m=perf -m=slow";; \ + esac ; \ + if test -z "$$GTESTER_LOGDIR" ; then \ + ${GTESTER} --verbose $$test_options -o test-report.xml ${TEST_PROGS} ; \ + elif test -n "${TEST_PROGS}" ; then \ + ${GTESTER} --verbose $$test_options -o `mktemp "$$GTESTER_LOGDIR/log-XXXXXX"` ${TEST_PROGS} ; \ + fi ; \ + } + @ ignore_logdir=true ; \ + if test -z "$$GTESTER_LOGDIR" ; then \ + GTESTER_LOGDIR=`mktemp -d "\`pwd\`/.testlogs-XXXXXX"`; export GTESTER_LOGDIR ; \ + ignore_logdir=false ; \ + fi ; \ + for subdir in $(SUBDIRS) . ; do \ + test "$$subdir" = "." -o "$$subdir" = "po" || \ + ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \ + done ; \ + $$ignore_logdir || { \ + echo '' > $@.xml ; \ + echo '' >> $@.xml ; \ + echo '' >> $@.xml ; \ + echo ' $(PACKAGE)' >> $@.xml ; \ + echo ' $(VERSION)' >> $@.xml ; \ + echo '' >> $@.xml ; \ + for lf in `ls -L "$$GTESTER_LOGDIR"/.` ; do \ + sed '1,1s/^?]*?>//' <"$$GTESTER_LOGDIR"/"$$lf" >> $@.xml ; \ + done ; \ + echo >> $@.xml ; \ + echo '' >> $@.xml ; \ + rm -rf "$$GTESTER_LOGDIR"/ ; \ + ${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $@.xml >$@.html ; \ + } +.PHONY: test test-report perf-report full-report test-nonrecursive + +.PHONY: lcov genlcov lcov-clean +# use recursive makes in order to ignore errors during check +lcov: + -$(MAKE) $(AM_MAKEFLAGS) -k check + $(MAKE) $(AM_MAKEFLAGS) genlcov + +# we have to massage the lcov.info file slightly to hide the effect of libtool +# placing the objects files in the .libs/ directory separate from the *.c +# we also have to delete tests/.libs/libmoduletestplugin_*.gcda +genlcov: + rm -f $(top_builddir)/tests/.libs/libmoduletestplugin_*.gcda + $(LTP) --directory $(top_builddir) --capture --output-file glib-lcov.info --test-name GLIB_PERF --no-checksum --compat-libtool + LANG=C $(LTP_GENHTML) --prefix $(top_builddir) --output-directory glib-lcov --title "GLib Code Coverage" --legend --show-details glib-lcov.info + +lcov-clean: + -$(LTP) --directory $(top_builddir) -z + -rm -rf glib-lcov.info glib-lcov + -find -name '*.gcda' -print | xargs rm + +# run tests in cwd as part of make check +check-local: test-nonrecursive diff --git a/autogen.sh b/autogen.sh index 56a2d3e2..d9b1ec33 100755 --- a/autogen.sh +++ b/autogen.sh @@ -6,11 +6,11 @@ AM_INSTALLED_VERSION=$($AUTOMAKE --version | sed -e '2,$ d' -e 's/.* \([0-9]*\.[ if [ "$AM_INSTALLED_VERSION" != "1.10" \ -a "$AM_INSTALLED_VERSION" != "1.11" ];then - echo - echo "You must have automake > 1.10 or 1.11 installed to compile gpicview." - echo "Install the appropriate package for your distribution," - echo "or get the source tarball at http://ftp.gnu.org/gnu/automake/" - exit 1 + echo + echo "You must have automake > 1.10 or 1.11 installed to compile gpicview." + echo "Install the appropriate package for your distribution," + echo "or get the source tarball at http://ftp.gnu.org/gnu/automake/" + exit 1 fi set -x @@ -26,4 +26,6 @@ AUTOMAKE=$AUTOMAKE intltoolize -c --automake --force $AUTOMAKE --add-missing --copy --include-deps ${AUTOCONF:-autoconf$AC_VERSION} +gtkdocize --flavour no-tmpl || exit 1 + rm -rf autom4te.cache diff --git a/configure.ac b/configure.ac index 580af443..8a898d41 100644 --- a/configure.ac +++ b/configure.ac @@ -81,6 +81,9 @@ if test x"$enable_udisks" = x"yes"; then AC_SUBST(DBUS_LIBS) fi +#check for gtk-doc +GTK_DOC_CHECK([1.14],[--flavour no-tmpl]) + AC_ARG_ENABLE(demo, [AC_HELP_STRING([--enable-demo], [build libfm-demo file manager @<:@default=no@:>@])], @@ -127,10 +130,14 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package.]) AC_CONFIG_FILES([ Makefile src/Makefile + src/tests/Makefile data/Makefile data/ui/Makefile data/libfm-pref-apps.desktop po/Makefile.in + docs/Makefile + docs/reference/Makefile + docs/reference/libfm/Makefile libfm.pc libfm-gtk.pc ]) diff --git a/docs/Makefile.am b/docs/Makefile.am new file mode 100644 index 00000000..3fe3167b --- /dev/null +++ b/docs/Makefile.am @@ -0,0 +1,3 @@ +include $(top_srcdir)/Makefile.decl + +SUBDIRS = reference diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am new file mode 100644 index 00000000..f8fad48e --- /dev/null +++ b/docs/reference/Makefile.am @@ -0,0 +1,3 @@ +include $(top_srcdir)/Makefile.decl + +SUBDIRS = libfm diff --git a/docs/reference/libfm/Makefile.am b/docs/reference/libfm/Makefile.am new file mode 100644 index 00000000..03321695 --- /dev/null +++ b/docs/reference/libfm/Makefile.am @@ -0,0 +1,139 @@ +## Process this file with automake to produce Makefile.in + +NULL= + +# We require automake 1.6 at least. +AUTOMAKE_OPTIONS = 1.6 + +# This is a blank Makefile.am for using gtk-doc. +# Copy this to your project's API docs directory and modify the variables to +# suit your project. See the GTK+ Makefiles in gtk+/docs/reference for examples +# of using the various options. + +# The name of the module, e.g. 'glib'. +DOC_MODULE=libfm + +# Uncomment for versioned docs and specify the version of the module, e.g. '2'. +#DOC_MODULE_VERSION=2 + + +# The top-level SGML file. You can change this if you want to. +DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.xml + +# The directory containing the source code. Relative to $(srcdir). +# gtk-doc will search all .c & .h files beneath here for inline comments +# documenting the functions and macros. +# e.g. DOC_SOURCE_DIR=../../../gtk +DOC_SOURCE_DIR= $(top_srcdir)/src + +# Extra options to pass to gtkdoc-scangobj. Not normally needed. +SCANGOBJ_OPTIONS= + +# Extra options to supply to gtkdoc-scan. +# e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED" +SCAN_OPTIONS= + +# Extra options to supply to gtkdoc-mkdb. +# e.g. MKDB_OPTIONS=--sgml-mode --output-format=xml +MKDB_OPTIONS=--sgml-mode --output-format=xml --name-space=fm + +# Extra options to supply to gtkdoc-mktmpl +# e.g. MKTMPL_OPTIONS=--only-section-tmpl +MKTMPL_OPTIONS= + +# Extra options to supply to gtkdoc-mkhtml +MKHTML_OPTIONS= + +# Extra options to supply to gtkdoc-fixref. Not normally needed. +# e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html +FIXXREF_OPTIONS= + +# Used for dependencies. The docs will be rebuilt if any of these change. +# e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h +# e.g. CFILE_GLOB=$(top_srcdir)/gtk/*.c +HFILE_GLOB= \ + $(top_srcdir)/src/*.h \ + $(top_srcdir)/src/base/*.h \ + $(top_srcdir)/src/job/*.h \ + $(top_srcdir)/src/gtk/*.h \ + $(NULL) + +CFILE_GLOB=$(top_srcdir)/src/*.c \ + $(top_srcdir)/src/base/*.c \ + $(top_srcdir)/src/job/*.c \ + $(top_srcdir)/src/gtk/*.c \ + $(NULL) + +# Extra header to include when scanning, which are not under DOC_SOURCE_DIR +# e.g. EXTRA_HFILES=$(top_srcdir}/contrib/extra.h +EXTRA_HFILES= + +# Header files to ignore when scanning. Use base file name, no paths +# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h +IGNORE_HFILES= \ + fm-marshal.h \ + fm-gtk-marshal.h \ + main-win.h \ + dbus-utils.h \ + fm-udisks.h \ + g-udisks-device.h \ + g-udisks-drive.h \ + g-udisks-mount.h \ + g-udisks-volume.h \ + g-udisks-volume-monitor.h \ + udisks-device.h \ + udisks.h \ + fm-app-lookup.h \ + exo-icon-view.h \ + exo-marshal.h \ + exo-private.h \ + exo-string.h \ + exo-tree-view.h \ + $(NULL) + +# Images to copy into HTML directory. +# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png +HTML_IMAGES= + +# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE). +# e.g. content_files=running.sgml building.sgml changes-2.0.sgml +content_files= + +# SGML files where gtk-doc abbrevations (#GtkWidget) are expanded +# These files must be listed here *and* in content_files +# e.g. expand_content_files=running.sgml +expand_content_files= + +# CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library. +# Only needed if you are using gtkdoc-scangobj to dynamically query widget +# signals and properties. +# e.g. GTKDOC_CFLAGS=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS) +# e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib) +GTKDOC_CFLAGS= \ + -I$(top_srcdir) \ + -I$(top_builddir) \ + $(GTK_CFLAGS) +GTKDOC_LIBS= \ + $(top_builddir)/src/libfm.la \ + $(top_builddir)/src/libfm-gtk.la \ + $(NULL) + +# This includes the standard gtk-doc make rules, copied by gtkdocize. +include $(top_srcdir)/gtk-doc.make + +# Other files to distribute +# e.g. EXTRA_DIST += version.xml.in +EXTRA_DIST += + +# Files not to distribute +# for --rebuild-types in $(SCAN_OPTIONS), e.g. $(DOC_MODULE).types +# for --rebuild-sections in $(SCAN_OPTIONS) e.g. $(DOC_MODULE)-sections.txt +#DISTCLEANFILES += + +# Comment this out if you want your docs-status tested during 'make check' +if ENABLE_GTK_DOC +#TESTS_ENVIRONMENT = cd $(srcsrc) && +#TESTS = $(GTKDOC_CHECK) +endif + +-include $(top_srcdir)/git.mk diff --git a/src/Makefile.am b/src/Makefile.am index bd45cc12..a50160ad 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,3 +1,7 @@ +include $(top_srcdir)/Makefile.decl + +SUBDIRS=tests + NULL= AM_CPPFLAGS = \ @@ -314,7 +318,7 @@ BUILT_SOURCES= \ gtk/fm-gtk-marshal.c \ $(NULL) -EXTRA_DIST = \ +EXTRA_DIST += \ base/fm-marshal.list \ gtk/fm-gtk-marshal.list \ demo/main-win-ui.c \ diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am new file mode 100644 index 00000000..9e14730c --- /dev/null +++ b/src/tests/Makefile.am @@ -0,0 +1,23 @@ +include $(top_srcdir)/Makefile.decl + +NULL= + +AM_CPPFLAGS = \ + -I../ \ + -I../base \ + -I../job \ + -I../gtk \ + $(GIO_CFLAGS) \ + $(MENU_CACHE_CFLAGS) \ + $(DBUS_CFLAGS) \ + -Werror-implicit-function-declaration \ + $(NULL) + +noinst_PROGRAMS = $(TEST_PROGS) + +TEST_PROGS += fm-path +fm_path_SOURCES = test-fm-path.c +fm_path_LDADD= \ + $(GLIB_LIBS) \ + $(top_builddir)/src/libfm.la \ + $(NULL) diff --git a/src/tests/test-fm-path.c b/src/tests/test-fm-path.c new file mode 100644 index 00000000..5a579926 --- /dev/null +++ b/src/tests/test-fm-path.c @@ -0,0 +1,25 @@ +#include + +//ignore for test disabled asserts +#ifdef G_DISABLE_ASSERT + #undef G_DISABLE_ASSERT +#endif + +static void double_slash_test_case(void) +{ + FmPath* path = fm_path_new("//tmp/lest"); + g_assert(path); + fm_path_unref(path); +} + +int +main (int argc, char *argv[]) +{ + g_type_init(); + g_test_init (&argc, &argv, NULL); // initialize test program + g_test_add_func ("/BasePath/Base Path New with Double Slash at beggining", + double_slash_test_case); + fm_init(NULL); + return g_test_run(); +} +