r1698 - in trunk/src/target/OM-2007/applications/openmoko-rssreader: . tests

zecke at sita.openmoko.org zecke at sita.openmoko.org
Sat Apr 7 21:00:59 CEST 2007


Author: zecke
Date: 2007-04-07 21:00:58 +0200 (Sat, 07 Apr 2007)
New Revision: 1698

Added:
   trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/
   trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/Makefile.am
   trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/date_test.c
Modified:
   trunk/src/target/OM-2007/applications/openmoko-rssreader/Makefile.am
   trunk/src/target/OM-2007/applications/openmoko-rssreader/configure.ac
Log:
openmoko-rssreader: Start adding unit-tests for the non gui bits
    Start adding unit tests for the RSS RFC Date class. This mostly
    sets up autofoo to easily add new tests.


Modified: trunk/src/target/OM-2007/applications/openmoko-rssreader/Makefile.am
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/Makefile.am	2007-04-07 18:58:58 UTC (rev 1697)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/Makefile.am	2007-04-07 19:00:58 UTC (rev 1698)
@@ -1,2 +1,2 @@
-SUBDIRS = src data po
+SUBDIRS = src tests data po
 

Modified: trunk/src/target/OM-2007/applications/openmoko-rssreader/configure.ac
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/configure.ac	2007-04-07 18:58:58 UTC (rev 1697)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/configure.ac	2007-04-07 19:00:58 UTC (rev 1698)
@@ -14,7 +14,28 @@
 AC_SUBST(GETTEXT_PACKAGE)
 AM_GLIB_GNU_GETTEXT
 
+# unit testing (inspired by opensync)
+# enable gcov profiling
+GCOV_CPPFLAGS=""
+GCOV_LDFLAGS=""
+AC_ARG_ENABLE([profiling],
+  [AS_HELP_STRING([--enable-profiling], [enable gcov profiling])],
+  [case "${enableval}" in
+    yes) GCOV_PROFILING="yes"
+         GCOV_CPPFLAGS="-ftest-coverage -fprofile-arcs"
+         GCOV_LDFLAGS="-lgcov"
+        ;;
+    no)  ;;
+     *)  AC_MSG_ERROR([bad value ${enableval} for --enable-profiling]) ;;
+    esac],[GCOV_PROFILING="no"])
+AC_SUBST(GCOV_CPPFLAGS)
+AC_SUBST(GCOV_LDFLAGS)
+AM_CONDITIONAL(ENABLE_PROFILING, test "x${GCOV_PROFILING}" = "xyes")
 
+#check for check
+AM_PATH_CHECK([0.9.2], [ENABLE_TESTING="yes"], [ENABLE_TESTING="no"])
+AM_CONDITIONAL(ENABLE_TESTING, test "x${ENABLE_TESTING}" = "xyes")
+
 # base deps
 PKG_CHECK_MODULES(OPENMOKO, openmoko-libs >= 0.0.1)
 PKG_CHECK_MODULES(MRSS,     mrss          >= 0.17 )
@@ -25,5 +46,6 @@
 Makefile
 src/Makefile
 data/Makefile
+tests/Makefile
 po/Makefile.in
 ])

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/Makefile.am
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/Makefile.am	2007-04-07 18:58:58 UTC (rev 1697)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/Makefile.am	2007-04-07 19:00:58 UTC (rev 1698)
@@ -0,0 +1,12 @@
+AM_CFLAGS = -Wall -Werror -std=c99 @OPENMOKO_CFLAGS@ @MRSS_CFLAGS@ @GCOV_CPPFLAGS@
+INCLUDES  = -I$(top_srcdir)/src
+
+if ENABLE_TESTING
+TESTS = datetest
+check_PROGRAMS = datetest
+endif
+
+datatest_INCLUDES = @CHECK_CFLAGS@
+datetest_SOURCES  = date_test.c ../src/rfcdate.c
+datetest_LIBS     = @CHECK_LIBS@
+datetest_LDFLAGS  = -lcheck @GCOV_LDFLAGS@ @OPENMOKO_LIBS@

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/date_test.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/date_test.c	2007-04-07 18:58:58 UTC (rev 1697)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/date_test.c	2007-04-07 19:00:58 UTC (rev 1698)
@@ -0,0 +1,50 @@
+#include <check.h>
+#include <stdlib.h>
+
+#include <glib.h>
+#include "rfcdate.h"
+
+START_TEST (test_create_date)
+{
+    RSSRFCDate *date = RSS_RFC_DATE(rss_rfc_date_new ());
+    g_object_unref( G_OBJECT(date) );
+}
+END_TEST
+
+START_TEST (test_parsing_date)
+{
+    RSSRFCDate *date = RSS_RFC_DATE(rss_rfc_date_new ());
+
+    rss_rfc_date_set (date, "Wed, 26 Jan 83 07:57");
+    fail_unless (g_date_get_month (date->date) == G_DATE_JANUARY, "Seldom year number, seldom time");
+    fail_unless (g_date_get_day (date->date) == 26, "Parsed my birthday");
+    fail_unless (g_date_get_year (date->date) == 1983, "Parsed my birthyear");
+    fail_unless (date->timeval.tv_sec == (8*60*60+57*60), "Parsed my birthtime properly");
+}
+END_TEST
+
+Suite*
+date_suite (void)
+{
+    Suite *s = suite_create( "Date" );
+    TCase *tc_core = tcase_create ("Core");
+    tcase_add_test (tc_core, test_create_date);
+    tcase_add_test (tc_core, test_parsing_date);
+    suite_add_tcase (s, tc_core);
+
+
+    return s;
+}
+
+int
+main (void)
+{
+    g_type_init ();
+    Suite *s = date_suite ();
+    SRunner *sr = srunner_create (s);
+    srunner_run_all (sr, CK_NORMAL);
+    int number_failed = srunner_ntests_failed (sr);
+    srunner_free (sr);
+
+    return  (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}





More information about the commitlog mailing list