Skip to content

Commit

Permalink
Try to integrate unit test provided by glib and gtk-doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
PCMan committed Sep 19, 2010
1 parent 4bec7ab commit 18c6111
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 8 deletions.
8 changes: 6 additions & 2 deletions 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)
Expand All @@ -12,3 +14,5 @@ pkgconfig_DATA = \
libfm.pc \
libfm-gtk.pc \
$(NULL)

DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc
90 changes: 90 additions & 0 deletions 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 version="1.0"?>' > $@.xml ; \
echo '<report-collection>' >> $@.xml ; \
echo '<info>' >> $@.xml ; \
echo ' <package>$(PACKAGE)</package>' >> $@.xml ; \
echo ' <version>$(VERSION)</version>' >> $@.xml ; \
echo '</info>' >> $@.xml ; \
for lf in `ls -L "$$GTESTER_LOGDIR"/.` ; do \
sed '1,1s/^<?xml\b[^>?]*?>//' <"$$GTESTER_LOGDIR"/"$$lf" >> $@.xml ; \
done ; \
echo >> $@.xml ; \
echo '</report-collection>' >> $@.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
12 changes: 7 additions & 5 deletions autogen.sh
Expand Up @@ -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
Expand All @@ -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
7 changes: 7 additions & 0 deletions configure.ac
Expand Up @@ -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@:>@])],
Expand Down Expand Up @@ -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
])
Expand Down
3 changes: 3 additions & 0 deletions docs/Makefile.am
@@ -0,0 +1,3 @@
include $(top_srcdir)/Makefile.decl

SUBDIRS = reference
3 changes: 3 additions & 0 deletions docs/reference/Makefile.am
@@ -0,0 +1,3 @@
include $(top_srcdir)/Makefile.decl

SUBDIRS = libfm
139 changes: 139 additions & 0 deletions 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
6 changes: 5 additions & 1 deletion src/Makefile.am
@@ -1,3 +1,7 @@
include $(top_srcdir)/Makefile.decl

SUBDIRS=tests

NULL=

AM_CPPFLAGS = \
Expand Down Expand Up @@ -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 \
Expand Down
23 changes: 23 additions & 0 deletions 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)
25 changes: 25 additions & 0 deletions src/tests/test-fm-path.c
@@ -0,0 +1,25 @@
#include <fm.h>

//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();
}

0 comments on commit 18c6111

Please sign in to comment.