- opaque mq structs
[oweals/gnunet.git] / src / fs / test_fs_directory.c
index d1ef263edb45eacc32137bc5ce624e89a9c20b88..95225d7c0ad59bbce0681f514eb91c711b0ba01a 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
 
      GNUnet 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, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
@@ -28,7 +28,7 @@
 #include <extractor.h>
 #include "gnunet_util_lib.h"
 #include "gnunet_fs_service.h"
 #include <extractor.h>
 #include "gnunet_util_lib.h"
 #include "gnunet_fs_service.h"
-#include "fs.h"
+#include "fs_api.h"
 
 #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; }
 
 
 #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; }
 
@@ -41,29 +41,25 @@ struct PCLS
 };
 
 static void
 };
 
 static void
-processor (void *cls,
-          const char *filename,
-          const struct GNUNET_FS_Uri *uri,
-          const struct GNUNET_CONTAINER_MetaData *md,
-           size_t length,
-          const void *data)
+processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
+           const struct GNUNET_CONTAINER_MetaData *md, size_t length,
+           const void *data)
 {
   struct PCLS *p = cls;
   int i;
 
   if (NULL == uri)
 {
   struct PCLS *p = cls;
   int i;
 
   if (NULL == uri)
-    return; /* ignore directory's meta data */
+    return;                     /* ignore directory's meta data */
   for (i = 0; i < p->max; i++)
   for (i = 0; i < p->max; i++)
+  {
+    if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], md) &&
+        GNUNET_FS_uri_test_equal (p->uri[i], uri))
     {
     {
-      if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i],
-                                                md) &&
-          GNUNET_FS_uri_test_equal (p->uri[i], uri))
-        {
-          p->pos++;
-          return;
-        }
+      p->pos++;
+      return;
     }
     }
-  fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__);
+  }
+  FPRINTF (stderr, "Error at %s:%d\n", __FILE__, __LINE__);
 }
 
 static int
 }
 
 static int
@@ -83,77 +79,77 @@ testDirectory (unsigned int i)
   char txt[128];
   int ret = 0;
   struct GNUNET_TIME_Absolute start;
   char txt[128];
   int ret = 0;
   struct GNUNET_TIME_Absolute start;
-  char *s;
+  const char *s;
 
   cls.max = i;
 
   cls.max = i;
-  uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri*) * i);
-  mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData*) * i);
+  uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri *) * i);
+  mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData *) * i);
   meta = GNUNET_CONTAINER_meta_data_create ();
   meta = GNUNET_CONTAINER_meta_data_create ();
-  GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_TITLE, "A title");
-  GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_AUTHOR, "An author");
+  GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE,
+                                     EXTRACTOR_METAFORMAT_UTF8, "text/plain",
+                                     "A title", strlen ("A title") + 1);
+  GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
+                                     EXTRACTOR_METATYPE_AUTHOR_NAME,
+                                     EXTRACTOR_METAFORMAT_UTF8, "text/plain",
+                                     "An author", strlen ("An author") + 1);
   for (p = 0; p < i; p++)
   for (p = 0; p < i; p++)
+  {
+    mds[p] = GNUNET_CONTAINER_meta_data_create ();
+    for (q = 0; q <= p; q++)
     {
     {
-      mds[p] = GNUNET_CONTAINER_meta_data_create ();
-      for (q = 0; q <= p; q++)
-        {
-          GNUNET_snprintf (txt, sizeof(txt), "%u -- %u\n", p, q);
-          GNUNET_CONTAINER_meta_data_insert (mds[p],
-                                   q %
-                                   EXTRACTOR_getHighestKeywordTypeNumber
-                                   (), txt);
-        }
-      GNUNET_snprintf (uri,
-                       sizeof(uri),
-                       "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
-                       p);
-      emsg = NULL;
-      uris[p] = GNUNET_FS_uri_parse (uri, &emsg);
-      if (uris[p] == NULL)
-        {
-          GNUNET_CONTAINER_meta_data_destroy (mds[p]);
-          while (--p > 0)
-            {
-              GNUNET_CONTAINER_meta_data_destroy (mds[p]);
-              GNUNET_FS_uri_destroy (uris[p]);
-            }
-          GNUNET_free (mds);
-          GNUNET_free (uris);
-         GNUNET_free (emsg);
-         GNUNET_CONTAINER_meta_data_destroy (meta);
-          ABORT ();             /* error in testcase */
-        }
-      GNUNET_assert (emsg == NULL);
+      GNUNET_snprintf (txt, sizeof (txt), "%u -- %u\n", p, q);
+      GNUNET_CONTAINER_meta_data_insert (mds[p], "<test>",
+                                         q % EXTRACTOR_metatype_get_max (),
+                                         EXTRACTOR_METAFORMAT_UTF8,
+                                         "text/plain", txt, strlen (txt) + 1);
     }
     }
+    GNUNET_snprintf (uri, sizeof (uri),
+                     "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
+                     p);
+    emsg = NULL;
+    uris[p] = GNUNET_FS_uri_parse (uri, &emsg);
+    if (uris[p] == NULL)
+    {
+      GNUNET_CONTAINER_meta_data_destroy (mds[p]);
+      while (--p > 0)
+      {
+        GNUNET_CONTAINER_meta_data_destroy (mds[p]);
+        GNUNET_FS_uri_destroy (uris[p]);
+      }
+      GNUNET_free (mds);
+      GNUNET_free (uris);
+      GNUNET_free (emsg);
+      GNUNET_CONTAINER_meta_data_destroy (meta);
+      ABORT ();                 /* error in testcase */
+    }
+    GNUNET_assert (emsg == NULL);
+  }
   start = GNUNET_TIME_absolute_get ();
   db = GNUNET_FS_directory_builder_create (meta);
   for (p = 0; p < i; p++)
     GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL);
   start = GNUNET_TIME_absolute_get ();
   db = GNUNET_FS_directory_builder_create (meta);
   for (p = 0; p < i; p++)
     GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL);
-  GNUNET_FS_directory_builder_finish (db,
-                                     &dlen,
-                                     (void**) &data);
-  s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start));
-  fprintf (stdout,
-          "Creating directory with %u entires and total size %llu took %s\n",
-          i,
-          (unsigned long long) dlen,
-          s);
-  GNUNET_free (s);
+  GNUNET_FS_directory_builder_finish (db, &dlen, (void **) &data);
+  s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
+                                              (start),
+                                             GNUNET_YES);
+  FPRINTF (stdout,
+           "Creating directory with %u entires and total size %llu took %s\n",
+           i, (unsigned long long) dlen, s);
   if (i < 100)
   if (i < 100)
-    {
-      cls.pos = 0;
-      cls.uri = uris;
-      cls.md = mds;
-      GNUNET_FS_directory_list_contents (dlen, data, 0, 
-                                        &processor, &cls);
-      GNUNET_assert (cls.pos == i);
-    }
+  {
+    cls.pos = 0;
+    cls.uri = uris;
+    cls.md = mds;
+    GNUNET_FS_directory_list_contents (dlen, data, 0, &processor, &cls);
+    GNUNET_assert (cls.pos == i);
+  }
   GNUNET_free (data);
   GNUNET_CONTAINER_meta_data_destroy (meta);
   for (p = 0; p < i; p++)
   GNUNET_free (data);
   GNUNET_CONTAINER_meta_data_destroy (meta);
   for (p = 0; p < i; p++)
-    {
-      GNUNET_CONTAINER_meta_data_destroy (mds[p]);
-      GNUNET_FS_uri_destroy (uris[p]);
-    }
+  {
+    GNUNET_CONTAINER_meta_data_destroy (mds[p]);
+    GNUNET_FS_uri_destroy (uris[p]);
+  }
   GNUNET_free (uris);
   GNUNET_free (mds);
   return ret;
   GNUNET_free (uris);
   GNUNET_free (mds);
   return ret;
@@ -166,15 +162,15 @@ main (int argc, char *argv[])
   int failureCount = 0;
   int i;
 
   int failureCount = 0;
   int i;
 
-  GNUNET_log_setup ("test_fs_directory", 
+  GNUNET_log_setup ("test_fs_directory",
 #if VERBOSE
 #if VERBOSE
-                   "DEBUG",
+                    "DEBUG",
 #else
 #else
-                   "WARNING",
+                    "WARNING",
 #endif
 #endif
-                   NULL);
+                    NULL);
   for (i = 17; i < 1000; i *= 2)
   for (i = 17; i < 1000; i *= 2)
-    failureCount += testDirectory (i);    
+    failureCount += testDirectory (i);
   if (failureCount != 0)
     return 1;
   return 0;
   if (failureCount != 0)
     return 1;
   return 0;