[libdmapsharing] Add unit test framework Signed-off-by: W. Michael Petullo <mike flyn org>



commit 5d1413e66c933fe22e09a7e732f516c2740d8a00
Author: W. Michael Petullo <mike flyn org>
Date:   Tue May 24 10:30:12 2011 -0500

    Add unit test framework
    Signed-off-by: W. Michael Petullo <mike flyn org>

 .gitignore                       |    4 ++-
 TODO                             |    3 --
 config.h.in                      |    3 ++
 configure.ac                     |   16 +++++++---
 libdmapsharing/daap-connection.c |   23 +++++++++++++++
 libdmapsharing/daap-connection.h |    9 ++++++
 tests/Makefile.am                |   23 +++++++++++----
 tests/unit-test.c                |   58 ++++++++++++++++++++++++++++++++++++++
 8 files changed, 124 insertions(+), 15 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index aa3a1c6..d823284 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,6 +14,7 @@ ltmain.sh
 missing
 stamp-h.in
 stamp-h1
+ChangeLog
 
 docs/.hierarchy
 docs/Makefile
@@ -59,4 +60,5 @@ tests/dmapserve
 tests/dpapview
 tests/test-dmap-client
 tests/test-dmap-server
-tests/vala.stamp
+tests/unit-test
+tests/*.stamp
diff --git a/TODO b/TODO
index 771a06d..15722af 100644
--- a/TODO
+++ b/TODO
@@ -1,8 +1,5 @@
 = Short term ===================================================================
 
-Add more txt record handling to browser. Add comments indicating that
-we should subclass for DACP and RAOP.
-
 Noah: DNS-SD implementation
 	Finish browser side support.
 	Update MacPorts port to no longer require avahi.
diff --git a/config.h.in b/config.h.in
index 3e1f55f..771a672 100644
--- a/config.h.in
+++ b/config.h.in
@@ -6,6 +6,9 @@
 /* Define if mDNS/DNS-SD implementation uses Avahi 0.6 */
 #undef HAVE_AVAHI_0_6
 
+/* Define if check support is enabled */
+#undef HAVE_CHECK
+
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
diff --git a/configure.ac b/configure.ac
index 00eb9c1..b89b05a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -329,7 +329,11 @@ else
   AC_WARN(GStreamer app element not present, transcoding will not be supported.)
 fi
 
-AM_MAINTAINER_MODE
+AM_CONDITIONAL(USE_GSTREAMERAPP, test x"$HAVE_GSTREAMERAPP" = "xyes")
+
+AC_SUBST(GSTREAMERAPP_CFLAGS)
+AC_SUBST(GSTREAMERAPP_LIBS)
+
 AM_CONDITIONAL(HAVE_VALA, false)
 if test "x$USE_MAINTAINER_MODE" = "xyes" ; then
         AM_PROG_VALAC([0.11.4])
@@ -359,10 +363,12 @@ else
 	AC_WARN([Will not build dpapview])
 fi
 
-AM_CONDITIONAL(USE_GSTREAMERAPP, test x"$HAVE_GSTREAMERAPP" = "xyes")
-
-AC_SUBST(GSTREAMERAPP_CFLAGS)
-AC_SUBST(GSTREAMERAPP_LIBS)
+AM_CONDITIONAL(HAVE_CHECK, false)
+if test "x$USE_MAINTAINER_MODE" = "xyes" ; then
+	PKG_CHECK_MODULES([CHECK], [check >= 0.9.4],have_check=yes,have_check=no)
+	AC_DEFINE(HAVE_CHECK, 1, [Define if check support is enabled])
+	AM_CONDITIONAL(HAVE_CHECK, test x"$have_check" = "xyes")
+fi
 
 AC_CHECK_LIB(z, uncompress)
 
diff --git a/libdmapsharing/daap-connection.c b/libdmapsharing/daap-connection.c
index cfe3bdf..750b5f8 100644
--- a/libdmapsharing/daap-connection.c
+++ b/libdmapsharing/daap-connection.c
@@ -196,3 +196,26 @@ daap_connection_init (DAAPConnection * connection)
 }
 
 G_DEFINE_TYPE (DAAPConnection, daap_connection, DMAP_TYPE_CONNECTION);
+
+#ifdef HAVE_CHECK
+START_TEST(test_get_protocol_version_cc)
+{
+	DMAPConnection *conn = g_object_new (DAAP_TYPE_CONNECTION, NULL);
+	DMAPContentCode cc = get_protocol_version_cc (conn);
+	fail_unless (cc == DMAP_CC_APRO);
+	g_object_unref (conn);
+}
+END_TEST
+
+Suite *dmap_test_daap_connection_suite (void)
+{
+	TCase *tc;
+	Suite *s = suite_create("dmap_test_daap_connection_suite");
+
+	tc = tcase_create("test_get_protocol_version_cc");
+	tcase_add_test(tc, test_get_protocol_version_cc);
+	suite_add_tcase(s, tc);
+
+	return s;
+}
+#endif
diff --git a/libdmapsharing/daap-connection.h b/libdmapsharing/daap-connection.h
index a1e8ee8..ca251bf 100644
--- a/libdmapsharing/daap-connection.h
+++ b/libdmapsharing/daap-connection.h
@@ -22,6 +22,8 @@
 #include <libdmapsharing/dmap-connection.h>
 #include <libdmapsharing/dmap-db.h>
 
+#include "config.h"
+
 G_BEGIN_DECLS
 /**
  * DAAP_TYPE_CONNECTION:
@@ -90,5 +92,12 @@ DAAPConnection *daap_connection_new (const char *name,
 				     guint port,
 				     DMAPDb * db,
 				     DMAPRecordFactory * factory);
+
+#ifdef HAVE_CHECK
+#include <check.h>
+
+Suite *dmap_test_daap_connection_suite (void);
+#endif
+
 G_END_DECLS
 #endif /* __DAAP_CONNECTION_H */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index efbe44f..1f0f5e7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,6 +4,16 @@ if HAVE_GEE
 noinst_PROGRAMS += dacplisten dpapview dmapcopy dmapserve
 endif
 
+# Automake documentation mentions LDADD, but it does not work;
+# LIBS does.
+LIBS = $(top_builddir)/libdmapsharing/libdmapsharing-3.0.la
+
+if HAVE_CHECK
+noinst_PROGRAMS += unit-test
+
+LIBS += $(CHECK_LIBS)
+endif
+
 test_dmap_client_SOURCES = \
 	test-dmap-db.c \
 	test-daap-record.c \
@@ -13,7 +23,6 @@ test_dmap_client_SOURCES = \
 	test-dmap-client.c
 
 test_dmap_client_LDADD = \
-	$(top_builddir)/libdmapsharing/libdmapsharing-3.0.la \
 	$(GLIB_LIBS) \
 	$(GTHREAD_LIBS) \
 	$(GSTREAMERAPP_LIBS) \
@@ -34,7 +43,6 @@ test_dmap_server_SOURCES = \
 	test-dpap-record-factory.c
 
 test_dmap_server_LDADD = \
-	$(top_builddir)/libdmapsharing/libdmapsharing-3.0.la \
 	$(GLIB_LIBS) \
 	$(GTHREAD_LIBS) \
 	$(GSTREAMERAPP_LIBS) \
@@ -75,7 +83,6 @@ dacplisten_SOURCES = \
 	$(dacplisten_VALABUILTSOURCES)
 
 dacplisten_LDADD = \
-	$(top_builddir)/libdmapsharing/libdmapsharing-3.0.la \
 	$(GEE_LIBS)
 
 dpapview_VALASOURCES = \
@@ -89,7 +96,6 @@ dpapview_SOURCES = \
 	$(dpapview_VALABUILTSOURCES)
 
 dpapview_LDADD = \
-	$(top_builddir)/libdmapsharing/libdmapsharing-3.0.la \
 	$(GTK_LIBS) \
 	$(GEE_LIBS)
 
@@ -104,7 +110,6 @@ dmapcopy_SOURCES = \
 	$(dmapcopy_VALABUILTSOURCES)
 
 dmapcopy_LDADD = \
-	$(top_builddir)/libdmapsharing/libdmapsharing-3.0.la \
 	$(GEE_LIBS)
 
 dmapserve_VALASOURCES = \
@@ -119,9 +124,11 @@ dmapserve_SOURCES = \
 	$(dmapserve_VALABUILTSOURCES)
 
 dmapserve_LDADD = \
-	$(top_builddir)/libdmapsharing/libdmapsharing-3.0.la \
 	$(GEE_LIBS)
 
+unit_test_SOURCES = \
+	unit-test.c
+
 AM_CPPFLAGS = \
 	-I$(top_srcdir) \
 	$(GLIB_CFLAGS) \
@@ -137,6 +144,10 @@ INCLUDES = \
 	$(GTK_CFLAGS) \
 	$(GEE_CFLAGS)
 
+if HAVE_CHECK
+INCLUDES += $(CHECK_CFLAGS)
+endif
+
 noinst_HEADERS = \
 	test-dmap-container-record.h \
 	test-dmap-container-db.h \
diff --git a/tests/unit-test.c b/tests/unit-test.c
new file mode 100644
index 0000000..1e65aae
--- /dev/null
+++ b/tests/unit-test.c
@@ -0,0 +1,58 @@
+/*   FILE: unit-test.c -- Unit tests
+ * AUTHOR: W. Michael Petullo <mike flyn org>
+ *   DATE: 24 May 2011 
+ *
+ * Copyright (c) 2011 W. Michael Petullo <new flyn org>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <check.h>
+#include <glib.h>
+#include <stdlib.h>
+#include <libdmapsharing/dmap.h>
+
+static void
+debug_null (const char *log_domain,
+            GLogLevelFlags log_level,
+            const gchar *message,
+            gpointer user_data)
+{
+}
+
+void run_suite (Suite *s)
+{
+	int nf;
+	SRunner *sr;
+
+	sr = srunner_create(s);
+	srunner_run_all(sr, CK_NORMAL);
+	nf = srunner_ntests_failed(sr);
+	srunner_free(sr);
+	if (nf != 0)
+		exit (EXIT_FAILURE);
+}
+
+int main(void)
+{
+	g_type_init ();
+	g_log_set_handler ("libdmapsharing", G_LOG_LEVEL_DEBUG, debug_null, NULL);
+	g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, debug_null, NULL);
+
+	run_suite (dmap_test_daap_connection_suite());
+
+	exit (EXIT_SUCCESS);
+}



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