Commit ebf63a5c authored by W. Michael Petullo's avatar W. Michael Petullo

Add/modify test-related targets in build system

Signed-off-by: W. Michael Petullo's avatarW. Michael Petullo <mike@flyn.org>
parent b5ff4460
......@@ -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)
......
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
......@@ -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
......@@ -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 */
......@@ -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 {
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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
#!/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
......@@ -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 \
......
/* 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>
Suite *dmap_test_dmap_md5_suite (void);
Suite *dmap_test_daap_connection_suite (void);
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);
run_suite (dmap_test_daap_connection_suite ());
run_suite (dmap_test_dmap_md5_suite ());
exit (EXIT_SUCCESS);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment