gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r23062 - in Extractor/src/plugins: . testdata


From: gnunet
Subject: [GNUnet-SVN] r23062 - in Extractor/src/plugins: . testdata
Date: Fri, 3 Aug 2012 15:55:34 +0200

Author: grothoff
Date: 2012-08-03 15:55:34 +0200 (Fri, 03 Aug 2012)
New Revision: 23062

Added:
   Extractor/src/plugins/test_lib.c
   Extractor/src/plugins/test_lib.h
   Extractor/src/plugins/test_ogg.c
   Extractor/src/plugins/testdata/
   Extractor/src/plugins/testdata/ogg_courseclear.ogg
Modified:
   Extractor/src/plugins/Makefile.am
Log:
adding test for ogg

Modified: Extractor/src/plugins/Makefile.am
===================================================================
--- Extractor/src/plugins/Makefile.am   2012-08-03 13:55:22 UTC (rev 23061)
+++ Extractor/src/plugins/Makefile.am   2012-08-03 13:55:34 UTC (rev 23062)
@@ -11,59 +11,38 @@
 
 SUBDIRS = . 
 
+EXTRA_DIST = template_extractor.c \
+  testdata/courseclear.ogg
+
 if HAVE_VORBISFILE
- PLUGIN_OGG=libextractor_ogg.la
+PLUGIN_OGG=libextractor_ogg.la
+TEST_OGG=test_ogg
 endif
 
 plugin_LTLIBRARIES = \
   $(PLUGIN_OGG) 
-#  libextractor_id3.la \
-#  libextractor_id3v2.la \
-#  libextractor_ebml.la \
-#  libextractor_s3m.la \
-#  libextractor_png.la \
-#  libextractor_mp3.la
 
-libextractor_mp3_la_SOURCES = \
-  mp3_extractor.c 
-libextractor_mp3_la_LDFLAGS = \
-  $(PLUGINFLAGS)
-libextractor_mp3_la_LIBADD = \
-  $(top_builddir)/src/common/libextractor_common.la \
-  $(top_builddir)/src/main/libextractor.la \
-  $(LE_LIBINTL)
+if HAVE_ZZUF
+  fuzz_tests=fuzz_default.sh 
+endif
 
-libextractor_ebml_la_SOURCES = \
-  ebml_extractor.c 
-libextractor_ebml_la_LDFLAGS = \
-  $(top_builddir)/src/main/libextractor.la \
-  $(PLUGINFLAGS)
+check_PROGRAMS = \
+  $(TEST_OGG)
 
-libextractor_id3_la_SOURCES = \
-  id3_extractor.c 
-libextractor_id3_la_LDFLAGS = \
-  $(PLUGINFLAGS)
-libextractor_id3_la_LIBADD = \
-  $(top_builddir)/src/common/libextractor_common.la \
-  $(top_builddir)/src/main/libextractor.la \
-  $(LE_LIBINTL)
+TESTS = \
+  $(fuzz_tests) \
+  $(check_PROGRAMS)
 
-libextractor_id3v2_la_SOURCES = \
-  id3v2_extractor.c 
-libextractor_id3v2_la_LDFLAGS = \
-  $(PLUGINFLAGS)
-libextractor_id3v2_la_LIBADD = \
-  $(top_builddir)/src/main/libextractor.la \
-  $(top_builddir)/src/common/libextractor_common.la
 
-libextractor_s3m_la_SOURCES = \
-  s3m_extractor.c
-libextractor_s3m_la_LDFLAGS = \
-  $(PLUGINFLAGS)
-libextractor_s3m_la_LIBADD = \
-  $(top_builddir)/src/main/libextractor.la \
-  $(top_builddir)/src/common/libextractor_common.la
+noinst_LTLIBRARIES = \
+  libtest.la
 
+libtest_la_SOURCES = \
+  test_lib.c 
+libtest_la_LIBADD = \
+  $(top_builddir)/src/main/libextractor.la
+
+
 libextractor_ogg_la_SOURCES = \
   ogg_extractor.c
 libextractor_ogg_la_LDFLAGS = \
@@ -73,18 +52,10 @@
   $(top_builddir)/src/common/libextractor_common.la \
   -lvorbisfile -lvorbis $(vorbisflag) -logg
 
-libextractor_png_la_SOURCES = \
-  png_extractor.c
-libextractor_png_la_LDFLAGS = \
-  $(PLUGINFLAGS)
-libextractor_png_la_LIBADD = \
-  $(top_builddir)/src/main/libextractor.la \
-  $(top_builddir)/src/common/libextractor_common.la
+test_ogg_SOURCES = \
+  test_ogg.c
+test_ogg_LDADD = \
+  $(top_builddir)/src/plugins/libtest.la
 
-EXTRA_DIST = template_extractor.c 
 
-if HAVE_ZZUF
-  fuzz_tests=fuzz_default.sh 
-endif
 
-TESTS = $(fuzz_tests)
\ No newline at end of file

Added: Extractor/src/plugins/test_lib.c
===================================================================
--- Extractor/src/plugins/test_lib.c                            (rev 0)
+++ Extractor/src/plugins/test_lib.c    2012-08-03 13:55:34 UTC (rev 23062)
@@ -0,0 +1,129 @@
+/*
+     This file is part of libextractor.
+     (C) 2012 Vidyut Samanta and Christian Grothoff
+
+     libextractor 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 3, or (at your
+     option) any later version.
+
+     libextractor 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 libextractor; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file plugins/test_lib.c
+ * @brief helper library for writing testcases
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "test_lib.h"
+
+
+/**
+ * Function that libextractor calls for each
+ * meta data item found.
+ *
+ * @param cls closure the 'struct SolutionData' we are currently working on
+ * @param plugin_name should be "test"
+ * @param type should be "COMMENT"
+ * @param format should be "UTF8"
+ * @param data_mime_type should be "<no mime>"
+ * @param data hello world or good bye
+ * @param data_len number of bytes in data
+ * @return 0 (always)
+ */ 
+static int
+process_replies (void *cls,
+                const char *plugin_name,
+                enum EXTRACTOR_MetaType type,
+                enum EXTRACTOR_MetaFormat format,
+                const char *data_mime_type,
+                const char *data,
+                size_t data_len)
+{
+  struct SolutionData *sd = cls;
+  unsigned int i;
+
+  for (i=0; -1 != sd[i].solved; i++)
+    {
+      if ( (0 != sd[i].solved) ||
+          (sd[i].type != type) ||
+          (sd[i].format != format) ||
+          (sd[i].data_len != data_len) ||
+          (0 != memcmp (sd[i].data, data, data_len)) )
+       continue;
+      if (NULL != sd[i].data_mime_type)
+       {
+         if (NULL == data_mime_type)
+           continue;
+         if (0 != strcmp (sd[i].data_mime_type, data_mime_type))
+           continue;
+       }
+      else
+       {
+         if (NULL != data_mime_type)
+           continue;
+       }
+      sd[i].solved = 1;
+      return 0;
+    }
+  fprintf (stderr, 
+          "Got additional meta data of type %d from plugin `%s'\n",
+          type,
+          plugin_name);
+  return 0;
+}
+
+
+/**
+ * Main function to be called to test a plugin.
+ *
+ * @param plugin_name name of the plugin to load
+ * @param ps array of problems the plugin should solve;
+ *        NULL in filename terminates the array. 
+ * @return 0 on success, 1 on failure
+ */
+int 
+ET_main (const char *plugin_name,
+        struct ProblemSet *ps)
+{
+  struct EXTRACTOR_PluginList *pl;
+  unsigned int i;
+  unsigned int j;
+  int ret;
+  
+  /* change environment to find plugins which may not yet be
+     not installed but should be in the current directory (or .libs)
+     on 'make check' */
+  if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/"))
+    fprintf (stderr, 
+            "Failed to update my environment, plugin loading may fail: %s\n",
+            strerror (errno));    
+  pl = EXTRACTOR_plugin_add_config (NULL, 
+                                   plugin_name,
+                                   EXTRACTOR_OPTION_IN_PROCESS);
+  for (i=0; NULL != ps[i].filename; i++)
+    EXTRACTOR_extract (pl,
+                      ps[i].filename,
+                      NULL, 0, 
+                      &process_replies,
+                      ps[i].solution);   
+  EXTRACTOR_plugin_remove_all (pl);
+  ret = 0;
+  for (i=0; NULL != ps[i].filename; i++)    
+    for (j=0; -1 != ps[i].solution[j].solved; j++)
+      if (0 == ps[i].solution[j].solved)
+       ret = 1;
+  return ret;
+}
+
+
+
+/* end of test_lib.c */

Added: Extractor/src/plugins/test_lib.h
===================================================================
--- Extractor/src/plugins/test_lib.h                            (rev 0)
+++ Extractor/src/plugins/test_lib.h    2012-08-03 13:55:34 UTC (rev 23062)
@@ -0,0 +1,100 @@
+/*
+     This file is part of libextractor.
+     (C) 2012 Vidyut Samanta and Christian Grothoff
+
+     libextractor 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 3, or (at your
+     option) any later version.
+
+     libextractor 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 libextractor; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file plugins/test_lib.h
+ * @brief helper library for writing testcases
+ * @author Christian Grothoff
+ */
+#ifndef TEST_LIB_H
+#define TEST_LIB_H
+
+#include "extractor.h"
+
+/**
+ * Expected outcome from the plugin.
+ */
+struct SolutionData
+{
+  /**
+   * Expected type.
+   */
+  enum EXTRACTOR_MetaType type;
+
+  /**
+   * Expected format.
+   */
+  enum EXTRACTOR_MetaFormat format;
+
+  /**
+   * Expected data mime type.
+   */
+  const char *data_mime_type;
+
+  /**
+   * Expected meta data.
+   */
+  const char *data;
+
+  /**
+   * Expected number of bytes in meta data.
+   */
+  size_t data_len;
+
+  /**
+   * Internally used flag to say if this solution was
+   * provided by the plugin; 0 for no, 1 for yes; -1 to
+   * terminate the list.
+   */
+  int solved;
+};
+
+
+/**
+ * Set of problems 
+ */
+struct ProblemSet
+{
+  /**
+   * File to run the extractor on, NULL
+   * to terminate the array.
+   */
+  const char *filename;
+
+  /**
+   * Expected meta data.  Terminate array with -1 in 'solved'.
+   */
+  struct SolutionData *solution;
+
+};
+
+
+/**
+ * Main function to be called to test a plugin.
+ *
+ * @param plugin_name name of the plugin to load
+ * @param ps array of problems the plugin should solve;
+ *        NULL in filename terminates the array. 
+ * @return 0 on success, 1 on failure
+ */
+int 
+ET_main (const char *plugin_name,
+        struct ProblemSet *ps);
+
+#endif

Added: Extractor/src/plugins/test_ogg.c
===================================================================
--- Extractor/src/plugins/test_ogg.c                            (rev 0)
+++ Extractor/src/plugins/test_ogg.c    2012-08-03 13:55:34 UTC (rev 23062)
@@ -0,0 +1,53 @@
+/*
+     This file is part of libextractor.
+     (C) 2012 Vidyut Samanta and Christian Grothoff
+
+     libextractor 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 3, or (at your
+     option) any later version.
+
+     libextractor 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 libextractor; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file plugins/test_ogg.c
+ * @brief testcase for ogg plugin
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "test_lib.h"
+
+
+
+/**
+ * Main function for the OGG testcase.
+ *
+ * @param argc number of arguments (ignored)
+ * @param argv arguments (ignored)
+ * @return 0 on success
+ */
+int
+main (int argc, char *argv[])
+{
+  struct SolutionData courseclear_sol[] =
+    {
+      { 0, 0, NULL, NULL, 0, -1 }
+    };
+  struct ProblemSet ps[] =
+    {
+      { "testdata/ogg_courseclear.ogg",
+       courseclear_sol },
+      { NULL, NULL }
+    };
+  return ET_main ("ogg", ps);
+}
+
+/* end of test_ogg.c */

Copied: Extractor/src/plugins/testdata/ogg_courseclear.ogg (from rev 23057, 
Extractor/test/courseclear.ogg)
===================================================================
(Binary files differ)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]