gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r23113 - Extractor/src/main


From: gnunet
Subject: [GNUnet-SVN] r23113 - Extractor/src/main
Date: Sun, 5 Aug 2012 16:33:32 +0200

Author: grothoff
Date: 2012-08-05 16:33:32 +0200 (Sun, 05 Aug 2012)
New Revision: 23113

Added:
   Extractor/src/main/test2_extractor.c
Modified:
   Extractor/src/main/Makefile.am
   Extractor/src/main/test_ipc.c
Log:
expanding IPC test to cover running with multiple plugins

Modified: Extractor/src/main/Makefile.am
===================================================================
--- Extractor/src/main/Makefile.am      2012-08-05 11:43:41 UTC (rev 23112)
+++ Extractor/src/main/Makefile.am      2012-08-05 14:33:32 UTC (rev 23113)
@@ -74,7 +74,8 @@
 TESTS_ENVIRONMENT += bindir=${bindir}
 
 tmp_LTLIBRARIES = \
-  libextractor_test.la 
+  libextractor_test.la \
+  libextractor_test2.la 
 
 libextractor_test_la_SOURCES = \
   test_extractor.c 
@@ -83,6 +84,14 @@
 libextractor_test_la_LIBADD = \
   $(LE_LIBINTL)
 
+libextractor_test2_la_SOURCES = \
+  test2_extractor.c 
+libextractor_test2_la_LDFLAGS = \
+  $(PLUGINFLAGS)
+libextractor_test2_la_LIBADD = \
+  $(LE_LIBINTL)
+
+
 check_PROGRAMS = \
  test_trivial \
  test_plugin_loading \

Added: Extractor/src/main/test2_extractor.c
===================================================================
--- Extractor/src/main/test2_extractor.c                                (rev 0)
+++ Extractor/src/main/test2_extractor.c        2012-08-05 14:33:32 UTC (rev 
23113)
@@ -0,0 +1,145 @@
+/*
+     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 main/test2_extractor.c
+ * @brief plugin for testing GNU libextractor
+ * Data file (or buffer) for this test must be 150 * 1024 bytes long,
+ * first 4 bytes must be "test", all other bytes should be equal to
+ * <FILE_OFFSET> % 256. The test client must return 0 after seeing
+ * "Hello World!" metadata, and return 1 after seeing "Goodbye!"
+ * metadata.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "extractor.h"
+#include <string.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+  
+
+/**
+ * Signature of the extract method that each plugin
+ * must provide.
+ *
+ * @param ec extraction context provided to the plugin
+ */
+void
+EXTRACTOR_test2_extract_method (struct EXTRACTOR_ExtractContext *ec)
+{
+  void *dp;
+
+  if ((NULL == ec->config) || (0 != strcmp (ec->config, "test2")))
+    return; /* only run in test mode */
+  if (4 != ec->read (ec->cls, &dp, 4))
+    {
+      fprintf (stderr, "Reading at offset 0 failed\n");
+      ABORT (); 
+    }
+  if (0 != strncmp ("test", dp, 4))
+    {
+      fprintf (stderr, "Unexpected data at offset 0\n");
+      ABORT (); 
+    }
+  if ( (1024 * 150 != ec->get_size (ec->cls)) &&
+       (UINT64_MAX != ec->get_size (ec->cls)) )
+    {
+      fprintf (stderr, "Unexpected file size returned (expected 150k)\n");
+      ABORT (); 
+    }              
+  if (1024 * 100 + 4 != ec->seek (ec->cls, 1024 * 100 + 4, SEEK_SET))
+    {
+      fprintf (stderr, "Failure to seek (SEEK_SET)\n");
+      ABORT ();
+    }
+  if (1 != ec->read (ec->cls, &dp, 1))
+    {
+      fprintf (stderr, "Failure to read at 100k + 4\n");
+      ABORT ();
+    }
+  if ((1024 * 100 + 4) % 256 != * (unsigned char *) dp)
+    {
+      fprintf (stderr, "Unexpected data at offset 100k + 4\n");
+      ABORT ();
+    }
+  if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) !=
+      ec->seek (ec->cls, - (1024 * 50 + 7), SEEK_CUR))
+    {
+      fprintf (stderr, "Failure to seek (SEEK_SET)\n");
+      ABORT ();
+    }
+  if (1 != ec->read (ec->cls, &dp, 1))
+    {
+      fprintf (stderr, "Failure to read at 50k - 3\n");
+      ABORT ();
+    }
+  if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) % 256 != * (unsigned char *) dp)
+    {
+      fprintf (stderr, "Unexpected data at offset 100k - 3\n");
+      ABORT ();
+    }
+  if (1024 * 150 != ec->seek (ec->cls, 0, SEEK_END))
+    {
+      fprintf (stderr, "Failure to seek (SEEK_END)\n");
+      ABORT ();
+    }
+  if (0 != ec->read (ec->cls, &dp, 1))
+    {
+      fprintf (stderr, "Failed to receive EOF at 150k\n");
+      ABORT ();
+    }
+  if (1024 * 150 - 2 != ec->seek (ec->cls, -2, SEEK_END))
+    {
+      fprintf (stderr, "Failure to seek (SEEK_END - 2)\n");
+      ABORT ();
+    }
+  if (1 != ec->read (ec->cls, &dp, 1))
+    {
+      fprintf (stderr, "Failure to read at 150k - 3\n");
+      ABORT ();
+    }
+  if ((1024 * 150 - 2) % 256 != * (unsigned char *) dp)
+    {
+      fprintf (stderr, "Unexpected data at offset 150k - 3\n");
+      ABORT ();
+    }
+  if (0 != ec->proc (ec->cls, "test2", EXTRACTOR_METATYPE_COMMENT,
+      EXTRACTOR_METAFORMAT_UTF8, "<no mime>", "Hello world!",
+      strlen ("Hello world!") + 1))
+    {
+      fprintf (stderr, "Unexpected return value from 'proc'\n");
+      ABORT ();
+    }
+  /* The test assumes that client orders us to stop extraction
+   * after seeing "Goodbye!".
+   */
+  if (1 != ec->proc (ec->cls, "test2", EXTRACTOR_METATYPE_COMMENT,
+      EXTRACTOR_METAFORMAT_UTF8, "<no mime>", "Goodbye!",
+      strlen ("Goodbye!") + 1))
+    {
+      fprintf (stderr, "Unexpected return value from 'proc'\n");
+      ABORT ();
+    }
+}
+
+/* end of test2_extractor.c */

Modified: Extractor/src/main/test_ipc.c
===================================================================
--- Extractor/src/main/test_ipc.c       2012-08-05 11:43:41 UTC (rev 23112)
+++ Extractor/src/main/test_ipc.c       2012-08-05 14:33:32 UTC (rev 23113)
@@ -63,6 +63,9 @@
       ret = 3;
       return 1;
     }
+  if (0 == strcmp (plugin_name,
+                  "test2"))
+    return 0; /* ignore 'test2' plugins */
   if (0 != strcmp (plugin_name,
                   "test"))
     {
@@ -148,6 +151,8 @@
             strerror (errno));    
   pl = EXTRACTOR_plugin_add_config (NULL, "test(test)",
                                    EXTRACTOR_OPTION_DEFAULT_POLICY);
+  pl = EXTRACTOR_plugin_add_config (pl, "test2(test2)",
+                                   EXTRACTOR_OPTION_DEFAULT_POLICY);
   if (NULL == pl)
     {
       fprintf (stderr, "failed to load test plugin\n");




reply via email to

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