aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Makefile.am81
-rw-r--r--src/plugins/test_lib.c129
-rw-r--r--src/plugins/test_lib.h100
-rw-r--r--src/plugins/test_ogg.c53
-rw-r--r--src/plugins/testdata/ogg_courseclear.oggbin0 -> 125695 bytes
5 files changed, 308 insertions, 55 deletions
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index ebd3507..bc1fc4e 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -11,58 +11,37 @@ PLUGINFLAGS = $(makesymbolic) $(LE_PLUGIN_LDFLAGS)
11 11
12SUBDIRS = . 12SUBDIRS = .
13 13
14EXTRA_DIST = template_extractor.c \
15 testdata/courseclear.ogg
16
14if HAVE_VORBISFILE 17if HAVE_VORBISFILE
15 PLUGIN_OGG=libextractor_ogg.la 18PLUGIN_OGG=libextractor_ogg.la
19TEST_OGG=test_ogg
16endif 20endif
17 21
18plugin_LTLIBRARIES = \ 22plugin_LTLIBRARIES = \
19 $(PLUGIN_OGG) 23 $(PLUGIN_OGG)
20# libextractor_id3.la \
21# libextractor_id3v2.la \
22# libextractor_ebml.la \
23# libextractor_s3m.la \
24# libextractor_png.la \
25# libextractor_mp3.la
26
27libextractor_mp3_la_SOURCES = \
28 mp3_extractor.c
29libextractor_mp3_la_LDFLAGS = \
30 $(PLUGINFLAGS)
31libextractor_mp3_la_LIBADD = \
32 $(top_builddir)/src/common/libextractor_common.la \
33 $(top_builddir)/src/main/libextractor.la \
34 $(LE_LIBINTL)
35 24
36libextractor_ebml_la_SOURCES = \ 25if HAVE_ZZUF
37 ebml_extractor.c 26 fuzz_tests=fuzz_default.sh
38libextractor_ebml_la_LDFLAGS = \ 27endif
39 $(top_builddir)/src/main/libextractor.la \
40 $(PLUGINFLAGS)
41 28
42libextractor_id3_la_SOURCES = \ 29check_PROGRAMS = \
43 id3_extractor.c 30 $(TEST_OGG)
44libextractor_id3_la_LDFLAGS = \
45 $(PLUGINFLAGS)
46libextractor_id3_la_LIBADD = \
47 $(top_builddir)/src/common/libextractor_common.la \
48 $(top_builddir)/src/main/libextractor.la \
49 $(LE_LIBINTL)
50 31
51libextractor_id3v2_la_SOURCES = \ 32TESTS = \
52 id3v2_extractor.c 33 $(fuzz_tests) \
53libextractor_id3v2_la_LDFLAGS = \ 34 $(check_PROGRAMS)
54 $(PLUGINFLAGS) 35
55libextractor_id3v2_la_LIBADD = \ 36
56 $(top_builddir)/src/main/libextractor.la \ 37noinst_LTLIBRARIES = \
57 $(top_builddir)/src/common/libextractor_common.la 38 libtest.la
39
40libtest_la_SOURCES = \
41 test_lib.c
42libtest_la_LIBADD = \
43 $(top_builddir)/src/main/libextractor.la
58 44
59libextractor_s3m_la_SOURCES = \
60 s3m_extractor.c
61libextractor_s3m_la_LDFLAGS = \
62 $(PLUGINFLAGS)
63libextractor_s3m_la_LIBADD = \
64 $(top_builddir)/src/main/libextractor.la \
65 $(top_builddir)/src/common/libextractor_common.la
66 45
67libextractor_ogg_la_SOURCES = \ 46libextractor_ogg_la_SOURCES = \
68 ogg_extractor.c 47 ogg_extractor.c
@@ -73,18 +52,10 @@ libextractor_ogg_la_LIBADD = \
73 $(top_builddir)/src/common/libextractor_common.la \ 52 $(top_builddir)/src/common/libextractor_common.la \
74 -lvorbisfile -lvorbis $(vorbisflag) -logg 53 -lvorbisfile -lvorbis $(vorbisflag) -logg
75 54
76libextractor_png_la_SOURCES = \ 55test_ogg_SOURCES = \
77 png_extractor.c 56 test_ogg.c
78libextractor_png_la_LDFLAGS = \ 57test_ogg_LDADD = \
79 $(PLUGINFLAGS) 58 $(top_builddir)/src/plugins/libtest.la
80libextractor_png_la_LIBADD = \
81 $(top_builddir)/src/main/libextractor.la \
82 $(top_builddir)/src/common/libextractor_common.la
83 59
84EXTRA_DIST = template_extractor.c
85 60
86if HAVE_ZZUF
87 fuzz_tests=fuzz_default.sh
88endif
89 61
90TESTS = $(fuzz_tests) \ No newline at end of file
diff --git a/src/plugins/test_lib.c b/src/plugins/test_lib.c
new file mode 100644
index 0000000..512cf39
--- /dev/null
+++ b/src/plugins/test_lib.c
@@ -0,0 +1,129 @@
1/*
2 This file is part of libextractor.
3 (C) 2012 Vidyut Samanta and Christian Grothoff
4
5 libextractor is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 libextractor is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with libextractor; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file plugins/test_lib.c
22 * @brief helper library for writing testcases
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include "test_lib.h"
27
28
29/**
30 * Function that libextractor calls for each
31 * meta data item found.
32 *
33 * @param cls closure the 'struct SolutionData' we are currently working on
34 * @param plugin_name should be "test"
35 * @param type should be "COMMENT"
36 * @param format should be "UTF8"
37 * @param data_mime_type should be "<no mime>"
38 * @param data hello world or good bye
39 * @param data_len number of bytes in data
40 * @return 0 (always)
41 */
42static int
43process_replies (void *cls,
44 const char *plugin_name,
45 enum EXTRACTOR_MetaType type,
46 enum EXTRACTOR_MetaFormat format,
47 const char *data_mime_type,
48 const char *data,
49 size_t data_len)
50{
51 struct SolutionData *sd = cls;
52 unsigned int i;
53
54 for (i=0; -1 != sd[i].solved; i++)
55 {
56 if ( (0 != sd[i].solved) ||
57 (sd[i].type != type) ||
58 (sd[i].format != format) ||
59 (sd[i].data_len != data_len) ||
60 (0 != memcmp (sd[i].data, data, data_len)) )
61 continue;
62 if (NULL != sd[i].data_mime_type)
63 {
64 if (NULL == data_mime_type)
65 continue;
66 if (0 != strcmp (sd[i].data_mime_type, data_mime_type))
67 continue;
68 }
69 else
70 {
71 if (NULL != data_mime_type)
72 continue;
73 }
74 sd[i].solved = 1;
75 return 0;
76 }
77 fprintf (stderr,
78 "Got additional meta data of type %d from plugin `%s'\n",
79 type,
80 plugin_name);
81 return 0;
82}
83
84
85/**
86 * Main function to be called to test a plugin.
87 *
88 * @param plugin_name name of the plugin to load
89 * @param ps array of problems the plugin should solve;
90 * NULL in filename terminates the array.
91 * @return 0 on success, 1 on failure
92 */
93int
94ET_main (const char *plugin_name,
95 struct ProblemSet *ps)
96{
97 struct EXTRACTOR_PluginList *pl;
98 unsigned int i;
99 unsigned int j;
100 int ret;
101
102 /* change environment to find plugins which may not yet be
103 not installed but should be in the current directory (or .libs)
104 on 'make check' */
105 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/"))
106 fprintf (stderr,
107 "Failed to update my environment, plugin loading may fail: %s\n",
108 strerror (errno));
109 pl = EXTRACTOR_plugin_add_config (NULL,
110 plugin_name,
111 EXTRACTOR_OPTION_IN_PROCESS);
112 for (i=0; NULL != ps[i].filename; i++)
113 EXTRACTOR_extract (pl,
114 ps[i].filename,
115 NULL, 0,
116 &process_replies,
117 ps[i].solution);
118 EXTRACTOR_plugin_remove_all (pl);
119 ret = 0;
120 for (i=0; NULL != ps[i].filename; i++)
121 for (j=0; -1 != ps[i].solution[j].solved; j++)
122 if (0 == ps[i].solution[j].solved)
123 ret = 1;
124 return ret;
125}
126
127
128
129/* end of test_lib.c */
diff --git a/src/plugins/test_lib.h b/src/plugins/test_lib.h
new file mode 100644
index 0000000..2416d57
--- /dev/null
+++ b/src/plugins/test_lib.h
@@ -0,0 +1,100 @@
1/*
2 This file is part of libextractor.
3 (C) 2012 Vidyut Samanta and Christian Grothoff
4
5 libextractor is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 libextractor is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with libextractor; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file plugins/test_lib.h
22 * @brief helper library for writing testcases
23 * @author Christian Grothoff
24 */
25#ifndef TEST_LIB_H
26#define TEST_LIB_H
27
28#include "extractor.h"
29
30/**
31 * Expected outcome from the plugin.
32 */
33struct SolutionData
34{
35 /**
36 * Expected type.
37 */
38 enum EXTRACTOR_MetaType type;
39
40 /**
41 * Expected format.
42 */
43 enum EXTRACTOR_MetaFormat format;
44
45 /**
46 * Expected data mime type.
47 */
48 const char *data_mime_type;
49
50 /**
51 * Expected meta data.
52 */
53 const char *data;
54
55 /**
56 * Expected number of bytes in meta data.
57 */
58 size_t data_len;
59
60 /**
61 * Internally used flag to say if this solution was
62 * provided by the plugin; 0 for no, 1 for yes; -1 to
63 * terminate the list.
64 */
65 int solved;
66};
67
68
69/**
70 * Set of problems
71 */
72struct ProblemSet
73{
74 /**
75 * File to run the extractor on, NULL
76 * to terminate the array.
77 */
78 const char *filename;
79
80 /**
81 * Expected meta data. Terminate array with -1 in 'solved'.
82 */
83 struct SolutionData *solution;
84
85};
86
87
88/**
89 * Main function to be called to test a plugin.
90 *
91 * @param plugin_name name of the plugin to load
92 * @param ps array of problems the plugin should solve;
93 * NULL in filename terminates the array.
94 * @return 0 on success, 1 on failure
95 */
96int
97ET_main (const char *plugin_name,
98 struct ProblemSet *ps);
99
100#endif
diff --git a/src/plugins/test_ogg.c b/src/plugins/test_ogg.c
new file mode 100644
index 0000000..0c3c11b
--- /dev/null
+++ b/src/plugins/test_ogg.c
@@ -0,0 +1,53 @@
1/*
2 This file is part of libextractor.
3 (C) 2012 Vidyut Samanta and Christian Grothoff
4
5 libextractor is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 libextractor is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with libextractor; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file plugins/test_ogg.c
22 * @brief testcase for ogg plugin
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include "test_lib.h"
27
28
29
30/**
31 * Main function for the OGG testcase.
32 *
33 * @param argc number of arguments (ignored)
34 * @param argv arguments (ignored)
35 * @return 0 on success
36 */
37int
38main (int argc, char *argv[])
39{
40 struct SolutionData courseclear_sol[] =
41 {
42 { 0, 0, NULL, NULL, 0, -1 }
43 };
44 struct ProblemSet ps[] =
45 {
46 { "testdata/ogg_courseclear.ogg",
47 courseclear_sol },
48 { NULL, NULL }
49 };
50 return ET_main ("ogg", ps);
51}
52
53/* end of test_ogg.c */
diff --git a/src/plugins/testdata/ogg_courseclear.ogg b/src/plugins/testdata/ogg_courseclear.ogg
new file mode 100644
index 0000000..ac5be40
--- /dev/null
+++ b/src/plugins/testdata/ogg_courseclear.ogg
Binary files differ