[libdmapsharing] Add/modify test-related targets in build system



commit ebf63a5c3f8ed173ad57188c4234052cf7df72d8
Author: W. Michael Petullo <mike flyn org>
Date:   Mon Oct 9 14:54:49 2017 -0400

    Add/modify test-related targets in build system
    
    Signed-off-by: W. Michael Petullo <mike flyn org>

 configure.ac                        |    3 +
 libdmapsharing/Makefile.am          |   39 ++++++++----
 libdmapsharing/daap-connection.c    |   14 +---
 libdmapsharing/daap-connection.h    |    6 --
 libdmapsharing/daap-share.c         |    4 +-
 libdmapsharing/dmap-md5.c           |   15 +----
 libdmapsharing/dmap-md5.h           |    6 --
 libdmapsharing/dmap-utils.c         |   66 ++++++++++++++++++---
 libdmapsharing/dmap-utils.h         |    6 +-
 libdmapsharing/generate-test-suites |  110 +++++++++++++++++++++++++++++++++++
 tests/Makefile.am                   |    6 --
 tests/unit-test.c                   |   61 -------------------
 12 files changed, 209 insertions(+), 127 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 42961f6..05d2db9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -343,6 +343,9 @@ if ! test -n "$VALA_GEN_INTROSPECT" -a -n "$VAPIGEN" -a xyes = x"$found_introspe
        AC_WARN([will not build vapi])
 fi
 
+AC_PATH_PROG(PEDANSEE, pedansee)
+AM_CONDITIONAL(HAVE_PEDANSEE, test -n "$PEDANSEE")
+
 PKG_CHECK_MODULES(GTK, gtk+-2.0, HAVE_GTK=yes, HAVE_GTK=no)
 
 AC_SUBST(GTK_CFLAGS)
diff --git a/libdmapsharing/Makefile.am b/libdmapsharing/Makefile.am
index ad9e5ad..5660e51 100644
--- a/libdmapsharing/Makefile.am
+++ b/libdmapsharing/Makefile.am
@@ -1,7 +1,5 @@
 lib_LTLIBRARIES = libdmapsharing-3.0.la
 
-BUILT_SOURCES = dmap-marshal.c dmap-marshal.h dmap-enums.c dmap-enums.h
-
 libdmapsharing_3_0_la_SOURCES = \
        $(BUILT_SOURCES) \
        daap-connection.c \
@@ -109,20 +107,15 @@ noinst_HEADERS = \
        dmap-gst-wav-input-stream.h \
        gst-util.h
 
+BUILT_SOURCES = dmap-marshal.c dmap-marshal.h dmap-enums.c dmap-enums.h ../tests/unit-test.c
+
+CLEANFILES = $(BUILT_SOURCES)
+
 dmap-marshal.c: dmap-marshal.list
        @glib-genmarshal --prefix=dmap_marshal $(srcdir)/dmap-marshal.list --header --body > dmap-marshal.c
 
 dmap-marshal.h: dmap-marshal.list
        @glib-genmarshal --prefix=dmap_marshal $(srcdir)/dmap-marshal.list --header > dmap-marshal.h
-       
-dmap-enums.h: $(libdmapsharinginclude_HEADERS) Makefile
-       @glib-mkenums \
-                       --fhead "/* Automatically generated by glib-mkenums */\n\n#ifndef 
DMAP_ENUMS_H\n#define DMAP_ENUMS_H\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n\n" \
-                       --fprod "\n/* enumerations from \"@filename@\" */\n" \
-                       --vhead "GType @enum_name@_get_type (void) G_GNUC_CONST;\n#define 
DMAP_TYPE_@ENUMNAME@ (@enum_name@_get_type())\n" \
-                       --ftail "G_END_DECLS\n\n#endif /* !DMAP_ENUMS_H */" $(addprefix 
$(srcdir)/,$(libdmapsharinginclude_HEADERS)) > $@.tmp \
-       && sed -e "s/d_map/dmap/" -e "s/D_MAP/DMAP/" -e "s/d_acp/dacp/" -e "s/D_ACP/DACP/" $@.tmp > $@ \
-       && rm -f $@.tmp
 
 dmap-enums.c: $(libdmapsharinginclude_headers) Makefile dmap-enums.h
        @glib-mkenums \
@@ -135,7 +128,18 @@ dmap-enums.c: $(libdmapsharinginclude_headers) Makefile dmap-enums.h
        && sed -e "s/d_map/dmap/" -e "s/D_MAP/DMAP/" -e "s/d_acp/dacp/" -e "s/D_ACP/DACP/" $@.tmp > $@ \
        && rm -f $@.tmp
 
-CLEANFILES = $(BUILT_SOURCES)
+dmap-enums.h: $(libdmapsharinginclude_HEADERS) Makefile
+       @glib-mkenums \
+                       --fhead "/* Automatically generated by glib-mkenums */\n\n#ifndef 
DMAP_ENUMS_H\n#define DMAP_ENUMS_H\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n\n" \
+                       --fprod "\n/* enumerations from \"@filename@\" */\n" \
+                       --vhead "GType @enum_name@_get_type (void) G_GNUC_CONST;\n#define 
DMAP_TYPE_@ENUMNAME@ (@enum_name@_get_type())\n" \
+                       --ftail "G_END_DECLS\n\n#endif /* !DMAP_ENUMS_H */" $(addprefix 
$(srcdir)/,$(libdmapsharinginclude_HEADERS)) > $@.tmp \
+       && sed -e "s/d_map/dmap/" -e "s/D_MAP/DMAP/" -e "s/d_acp/dacp/" -e "s/D_ACP/DACP/" $@.tmp > $@ \
+       && rm -f $@.tmp
+
+../tests/unit-test.c: $(grep -l START_TEST *.c)
+       ./generate-test-suites
+       mv unit-test.c ../tests
 
 if HAVE_INTROSPECTION
 include $(INTROSPECTION_MAKEFILE)
@@ -164,4 +168,13 @@ typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
 CLEANFILES += $(gir_DATA) $(typelib_DATA)
 endif
 
-EXTRA_DIST = dmap-marshal.list
+check:
+if HAVE_PEDANSEE
+       set -e; for i in $(libdmapsharing_3_0_la_SOURCES) \
+                        $(libdmapsharinginclude_HEADERS) \
+                        $(noinst_HEADERS); do \
+               $(PEDANSEE) $(libdmapsharing_3_0_la_CFLAGS) $$i; \
+       done
+endif
+
+EXTRA_DIST = dmap-marshal.list generate-test-suites
diff --git a/libdmapsharing/daap-connection.c b/libdmapsharing/daap-connection.c
index d2c8b2f..f5767d7 100644
--- a/libdmapsharing/daap-connection.c
+++ b/libdmapsharing/daap-connection.c
@@ -186,6 +186,9 @@ daap_connection_init (DAAPConnection * connection)
 G_DEFINE_TYPE (DAAPConnection, daap_connection, DMAP_TYPE_CONNECTION);
 
 #ifdef HAVE_CHECK
+
+#include <check.h>
+
 START_TEST(test_get_protocol_version_cc)
 {
        DMAPConnection *conn = g_object_new (DAAP_TYPE_CONNECTION, NULL);
@@ -195,15 +198,6 @@ START_TEST(test_get_protocol_version_cc)
 }
 END_TEST
 
-Suite *dmap_test_daap_connection_suite (void)
-{
-       TCase *tc;
-       Suite *s = suite_create("test_daap_connection_suite");
+#include "daap-connection-suite.c"
 
-       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 ea7d743..8f0425c 100644
--- a/libdmapsharing/daap-connection.h
+++ b/libdmapsharing/daap-connection.h
@@ -91,11 +91,5 @@ DAAPConnection *daap_connection_new (const char *name,
                                     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/libdmapsharing/daap-share.c b/libdmapsharing/daap-share.c
index b363e7e..4e266a6 100644
--- a/libdmapsharing/daap-share.c
+++ b/libdmapsharing/daap-share.c
@@ -326,7 +326,7 @@ static gboolean should_transcode (const gchar *format, const gboolean has_video,
                goto done;
        }
 
-       format2 = dmap_mime_to_format (transcode_mimetype);
+       format2 = dmap_utils_mime_to_format (transcode_mimetype);
        if (NULL == format2) {
                g_warning ("Configured to transcode, but target format is bad");
                goto done;
@@ -588,7 +588,7 @@ add_entry_to_mlcl (gpointer id, DMAPRecord * record, gpointer _mb)
                              &transcode_mimetype, NULL);
                // Not presently transcoding videos (see also same comments elsewhere).
                if (! has_video && transcode_mimetype) {
-                       format = g_strdup (dmap_mime_to_format
+                       format = g_strdup (dmap_utils_mime_to_format
                                           (transcode_mimetype));
                        g_free (transcode_mimetype);
                } else {
diff --git a/libdmapsharing/dmap-md5.c b/libdmapsharing/dmap-md5.c
index 92dd5ba..0e38d21 100644
--- a/libdmapsharing/dmap-md5.c
+++ b/libdmapsharing/dmap-md5.c
@@ -525,6 +525,9 @@ void dmap_hash_progressive_final (DMAPHashContext *context,
 }
 
 #ifdef HAVE_CHECK
+
+#include <check.h>
+
 START_TEST(test_dmap_hash_generate_v3_h2)
 {
        guchar hash[33] = { 0 };
@@ -558,16 +561,6 @@ START_TEST(test_dmap_hash_progressive)
 }
 END_TEST
 
-Suite *dmap_test_dmap_md5_suite (void)
-{
-       TCase *tc;
-       Suite *s = suite_create("test_dmap_hash_generate");
+#include "dmap-md5-suite.c"
 
-       tc = tcase_create("test_dmap_hash_generate_v3_h2");
-       tcase_add_test(tc, test_dmap_hash_generate_v3_h2);
-       tcase_add_test(tc, test_dmap_hash_progressive);
-       suite_add_tcase(s, tc);
-
-       return s;
-}
 #endif
diff --git a/libdmapsharing/dmap-md5.h b/libdmapsharing/dmap-md5.h
index dd6697c..b28bf49 100644
--- a/libdmapsharing/dmap-md5.h
+++ b/libdmapsharing/dmap-md5.h
@@ -52,11 +52,5 @@ void dmap_hash_generate              (short version_major,
                                       guchar *out,
                                       gint request_id);
 
-#ifdef HAVE_CHECK
-#include <check.h>
-
-Suite *dmap_test_daap_connection_suite (void);
-#endif
-
 G_END_DECLS
 #endif
diff --git a/libdmapsharing/dmap-utils.c b/libdmapsharing/dmap-utils.c
index 67743f1..3d60f7d 100644
--- a/libdmapsharing/dmap-utils.c
+++ b/libdmapsharing/dmap-utils.c
@@ -18,21 +18,69 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <string.h>
 
 #include "dmap-utils.h"
 
 gchar *
-dmap_mime_to_format (const gchar * transcode_mimetype)
+dmap_utils_mime_to_format (const gchar * transcode_mimetype)
 {
-        if (!transcode_mimetype) {
-                return NULL;
-        } else if (!strcmp (transcode_mimetype, "audio/wav")) {
-                return g_strdup ("wav");
+       gchar *format = NULL;
+
+       if (NULL == transcode_mimetype) {
+               goto done;
+       }
+
+        if (!strcmp (transcode_mimetype, "audio/wav")) {
+                format = g_strdup ("wav");
         } else if (!strcmp (transcode_mimetype, "audio/mp3")) {
-                return g_strdup ("mp3");
+                format = g_strdup ("mp3");
         } else if (!strcmp (transcode_mimetype, "video/quicktime")) {
-                return g_strdup ("mp4");
-        } else
-                return NULL;
+                format = g_strdup ("mp4");
+        }
+
+done:
+       return format;
+}
+
+#ifdef HAVE_CHECK
+
+#include <check.h>
+
+START_TEST(test_dmap_utils_mime_to_format_wav)
+{
+       ck_assert_str_eq(dmap_utils_mime_to_format("audio/wav"), "wav");
+}
+END_TEST
+
+START_TEST(test_dmap_utils_mime_to_format_mp3)
+{
+       ck_assert_str_eq(dmap_utils_mime_to_format("audio/mp3"), "mp3");
 }
+END_TEST
+
+START_TEST(test_dmap_utils_mime_to_format_quicktime)
+{
+       ck_assert_str_eq(dmap_utils_mime_to_format("video/quicktime"), "mp4");
+}
+END_TEST
+
+START_TEST(test_dmap_utils_mime_to_format_null)
+{
+       ck_assert_ptr_null(dmap_utils_mime_to_format(NULL));
+}
+END_TEST
+
+START_TEST(test_dmap_utils_mime_to_format_bad)
+{
+       ck_assert_ptr_null(dmap_utils_mime_to_format("bad/mime"));
+}
+END_TEST
+
+#include "dmap-utils-suite.c"
+
+#endif
diff --git a/libdmapsharing/dmap-utils.h b/libdmapsharing/dmap-utils.h
index 1b32505..aa6d737 100644
--- a/libdmapsharing/dmap-utils.h
+++ b/libdmapsharing/dmap-utils.h
@@ -17,13 +17,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA*
  */
 
-#ifndef __DMAP_UTILS_H__
-#define __DMAP_UTILS_H__
+#ifndef _DMAP_UTILS_H
+#define _DMAP_UTILS_H
 
 #include <glib.h>
 #include <libsoup/soup.h>
 
-gchar * dmap_mime_to_format (const gchar * transcode_mimetype);
+gchar * dmap_utils_mime_to_format (const gchar * transcode_mimetype);
 
 G_END_DECLS
 #endif
diff --git a/libdmapsharing/generate-test-suites b/libdmapsharing/generate-test-suites
new file mode 100755
index 0000000..0c42f3d
--- /dev/null
+++ b/libdmapsharing/generate-test-suites
@@ -0,0 +1,110 @@
+#!/bin/sh
+
+# Generate test suite for each source file containing "^START_TEST":
+for f in *.c; do
+       tests=$(grep ^START_TEST $f | cut -c 12- | sed 's/.$//')
+       suitefn=$(echo ${f%.*} | sed 's/-/_/g')
+
+       # Continue if no tests.
+        if [ -z "$tests" ]; then
+                continue
+        fi
+
+        cat <<EOF > ${f%.*}-suite.c
+/* Machine-generated by $0; do not edit. */
+
+Suite *dmap_test_${suitefn}(void)
+{
+        TCase *tc;
+        Suite *s = suite_create("${suitefn}");
+
+EOF
+        for t in $tests; do
+                cat <<EOF >> ${f%.*}-suite.c
+        tc = tcase_create("$t");
+        tcase_add_test(tc, $t);
+        suite_add_tcase(s, tc);
+
+EOF
+        done
+
+        cat <<EOF >> ${f%.*}-suite.c
+        return s;
+}
+EOF
+done
+
+# Generate unit-test.c which invokes each test suite:
+cat <<EOF > unit-test.c
+/* Machine-generated by $0; do not edit. */
+
+#include <check.h>
+#include <glib.h>
+#include <stdlib.h>
+#include <libdmapsharing/dmap.h>
+
+EOF
+
+for f in *.c; do
+        # Get list of tests in given source file.
+        tests=$(grep ^START_TEST $f | cut -c 12- | sed 's/.$//')
+       suitefn=$(echo ${f%.*} | sed 's/-/_/g')
+
+        # Continue if no tests.
+        if [ -z "$tests" ]; then
+                continue
+        fi
+        cat <<EOF >> unit-test.c
+Suite *dmap_test_${suitefn}(void);
+EOF
+done
+
+cat <<EOF >> unit-test.c
+
+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_log_set_handler ("libdmapsharing", G_LOG_LEVEL_DEBUG, debug_null, NULL);
+        g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, debug_null, NULL);
+EOF
+
+for f in *.c; do
+        # Get list of tests in given source file.
+        tests=$(grep ^START_TEST $f | cut -c 12- | sed 's/.$//')
+       suitefn=$(echo ${f%.*} | sed 's/-/_/g')
+
+        # Continue if no tests.
+        if [ -z "$tests" ]; then
+                continue
+        fi
+        cat <<EOF >> unit-test.c
+        run_suite(dmap_test_${suitefn}());
+EOF
+done
+
+cat <<EOF >> unit-test.c
+
+        exit (EXIT_SUCCESS);
+}
+EOF
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 425c1ab..3853408 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -11,8 +11,6 @@ LIBS = $(top_builddir)/libdmapsharing/libdmapsharing-3.0.la
 
 if HAVE_CHECK
 noinst_PROGRAMS += unit-test
-
-LIBS += $(CHECK_LIBS)
 endif
 endif
 
@@ -152,10 +150,6 @@ INCLUDES = \
        $(GTK_CFLAGS) \
        $(GEE_CFLAGS)
 
-if HAVE_CHECK
-INCLUDES += $(CHECK_CFLAGS)
-endif
-
 noinst_HEADERS = \
        test-dmap-container-record.h \
        test-dmap-container-db.h \


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