[totem] gst: Add test suite for time helpers



commit bd743e6448499dc2e417d17c6f2a4803bdea41bb
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Apr 4 11:00:10 2013 +0200

    gst: Add test suite for time helpers
    
    It's pretty small, but will stop us from doing stupid things.

 Makefile.decl       |   53 +++++++++++++++++++++++++++++++++++++++++++++++
 src/gst/Makefile.am |   14 ++++++++++++
 src/gst/test-time.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 124 insertions(+), 0 deletions(-)
---
diff --git a/Makefile.decl b/Makefile.decl
new file mode 100644
index 0000000..aab33c3
--- /dev/null
+++ b/Makefile.decl
@@ -0,0 +1,53 @@
+GTESTER        = gtester               # in $PATH for non-GLIB packages
+GTESTER_REPORT = gtester-report                # in $PATH for non-GLIB packages
+
+# initialize variables for unconditional += appending
+TEST_PROGS =
+
+# test: run all tests in cwd and subdirs
+test:  ${TEST_PROGS}
+       @test -z "${TEST_PROGS}" || ${GTESTER} --verbose ${TEST_PROGS}
+       @ for subdir in $(SUBDIRS) . ; do \
+           test "$$subdir" = "." -o "$$subdir" = "po" || \
+           ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
+         done
+
+# 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 ; \
+           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
+# run make test as part of make check
+check-local: test
diff --git a/src/gst/Makefile.am b/src/gst/Makefile.am
index c5f1159..2e3c4cb 100644
--- a/src/gst/Makefile.am
+++ b/src/gst/Makefile.am
@@ -51,6 +51,20 @@ libtotemtimehelpers_la_CFLAGS =      \
 libtotemtimehelpers_la_LIBADD = $(TIME_HELPER_LIBS)
 libtotemtimehelpers_la_LDFLAGS= -no-undefined
 
+include $(top_srcdir)/Makefile.decl
+
+pwd=`pwd`
+INCLUDES = \
+       -I$(top_srcdir)/plparse \
+       -DTEST_SRCDIR=\""$(srcdir)/"\"
+
+noinst_PROGRAMS = $(TEST_PROGS)
+
+TEST_PROGS                     += test-time
+test_time_SOURCES               = test-time.c
+test_time_CFLAGS                = $(HELPER_CFLAGS) $(AM_CFLAGS)
+test_time_LDADD                         = libtotemtimehelpers.la $(HELPER_LIBS)
+
 EXTRA_DIST = totem-time-helpers.h
 
 -include $(top_srcdir)/git.mk
diff --git a/src/gst/test-time.c b/src/gst/test-time.c
new file mode 100644
index 0000000..8fd9f77
--- /dev/null
+++ b/src/gst/test-time.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright Bastien Nocera <hadess hadess net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301  USA.
+ */
+
+#include "config.h"
+
+#include <locale.h>
+#include <glib.h>
+
+#include "totem-time-helpers.h"
+
+static void
+test_time (void)
+{
+       g_assert_cmpstr (totem_time_to_string (0, FALSE, FALSE), ==, "0:00");
+       g_assert_cmpstr (totem_time_to_string (500, FALSE, FALSE), ==, "0:00");
+       g_assert_cmpstr (totem_time_to_string (500, TRUE, FALSE), ==, "-0:01");
+       g_assert_cmpstr (totem_time_to_string (1250, FALSE, FALSE), ==, "0:01");
+       g_assert_cmpstr (totem_time_to_string (1250, TRUE, FALSE), ==, "-0:02");
+}
+
+static void
+log_handler (const char *log_domain, GLogLevelFlags log_level, const char *message, gpointer user_data)
+{
+       g_test_message ("%s", message);
+}
+
+int
+main (int argc, char *argv[])
+{
+       setlocale (LC_ALL, "en_US.UTF-8");
+
+       g_test_init (&argc, &argv, NULL);
+       g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=";);
+
+       /* We need to handle log messages produced by g_message so they're interpreted correctly by the 
GTester framework */
+       g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, log_handler, 
NULL);
+
+       g_test_add_func ("/time", test_time);
+
+       return g_test_run ();
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]