tolerate additional IPv4 address now available for gnunet.org
[oweals/gnunet.git] / src / util / test_container_meta_data.c
index cee550f96d172557cbbca149a3e5efd1179c61f4..416ea7db904b933766e036c9e0d1e9e495098f24 100644 (file)
@@ -1,21 +1,21 @@
 /*
      This file is part of GNUnet.
-     (C) 2003, 2004, 2006, 2009, 2010 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2003, 2004, 2006, 2009, 2010 GNUnet e.V.
 
-     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 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet 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.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 
 /**
  */
 
 #include "platform.h"
-#include "gnunet_common.h"
-#include "gnunet_container_lib.h"
+#include "gnunet_util_lib.h"
 
 #define ABORT(m) { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); if (m != NULL) GNUNET_CONTAINER_meta_data_destroy(m); return 1; }
 
+
 static int
 testMeta (int i)
 {
@@ -41,20 +41,17 @@ testMeta (int i)
 
   m = GNUNET_CONTAINER_meta_data_create ();
   if (GNUNET_OK !=
-      GNUNET_CONTAINER_meta_data_insert (m,
-                                         "<test>",
-                                         EXTRACTOR_METATYPE_TITLE,
+      GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_TITLE,
                                          EXTRACTOR_METAFORMAT_UTF8,
-                                         "text/plain",
-                                         "TestTitle", strlen ("TestTitle") + 1))
+                                         "text/plain", "TestTitle",
+                                         strlen ("TestTitle") + 1))
     ABORT (m);
   if (GNUNET_OK !=
-      GNUNET_CONTAINER_meta_data_insert (m,
-                                         "<test>",
+      GNUNET_CONTAINER_meta_data_insert (m, "<test>",
                                          EXTRACTOR_METATYPE_AUTHOR_NAME,
                                          EXTRACTOR_METAFORMAT_UTF8,
-                                         "text/plain",
-                                         "TestTitle", strlen ("TestTitle") + 1))
+                                         "text/plain", "TestTitle",
+                                         strlen ("TestTitle") + 1))
     ABORT (m);
   if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_TITLE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1))   /* dup! */
     ABORT (m);
@@ -63,8 +60,7 @@ testMeta (int i)
   if (2 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
     ABORT (m);
   if (GNUNET_OK !=
-      GNUNET_CONTAINER_meta_data_delete (m,
-                                         EXTRACTOR_METATYPE_AUTHOR_NAME,
+      GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME,
                                          "TestTitle", strlen ("TestTitle") + 1))
     ABORT (m);
   if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME, "TestTitle", strlen ("TestTitle") + 1))        /* already gone */
@@ -72,8 +68,7 @@ testMeta (int i)
   if (1 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
     ABORT (m);
   if (GNUNET_OK !=
-      GNUNET_CONTAINER_meta_data_delete (m,
-                                         EXTRACTOR_METATYPE_TITLE,
+      GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE,
                                          "TestTitle", strlen ("TestTitle") + 1))
     ABORT (m);
   if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE, "TestTitle", strlen ("TestTitle") + 1))      /* already gone */
@@ -82,12 +77,10 @@ testMeta (int i)
     ABORT (m);
   for (j = 0; j < i; j++)
   {
-    GNUNET_snprintf (val,
-                     sizeof (val),
-                     "%s.%d", "A teststring that should compress well.", j);
+    GNUNET_snprintf (val, sizeof (val), "%s.%d",
+                     "A teststring that should compress well.", j);
     if (GNUNET_OK !=
-        GNUNET_CONTAINER_meta_data_insert (m,
-                                           "<test>",
+        GNUNET_CONTAINER_meta_data_insert (m, "<test>",
                                            EXTRACTOR_METATYPE_UNKNOWN,
                                            EXTRACTOR_METAFORMAT_UTF8,
                                            "text/plain", val, strlen (val) + 1))
@@ -98,9 +91,9 @@ testMeta (int i)
 
   size = GNUNET_CONTAINER_meta_data_get_serialized_size (m);
   sval = NULL;
-  if (size != GNUNET_CONTAINER_meta_data_serialize (m,
-                                                    &sval, size,
-                                                    GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
+  if (size !=
+      GNUNET_CONTAINER_meta_data_serialize (m, &sval, size,
+                                            GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
   {
     GNUNET_free_non_null (sval);
     ABORT (m);
@@ -113,12 +106,15 @@ testMeta (int i)
   for (j = 0; j < i; j++)
   {
     GNUNET_snprintf (val,
-                     sizeof (val), "%s.%d",
-                     "A teststring that should compress well.", j);
+                     sizeof (val),
+                     "%s.%d",
+                     "A teststring that should compress well.",
+                     j);
     if (GNUNET_OK !=
         GNUNET_CONTAINER_meta_data_delete (m,
                                            EXTRACTOR_METATYPE_UNKNOWN,
-                                           val, strlen (val) + 1))
+                                           val,
+                                           strlen (val) + 1))
     {
       ABORT (m);
     }
@@ -129,7 +125,8 @@ testMeta (int i)
   return 0;
 }
 
-int
+
+static int
 testMetaMore (int i)
 {
   struct GNUNET_CONTAINER_MetaData *meta;
@@ -142,17 +139,16 @@ testMetaMore (int i)
   for (q = 0; q <= i; q++)
   {
     GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q);
-    GNUNET_CONTAINER_meta_data_insert (meta,
-                                       "<test>",
-                                       q % EXTRACTOR_metatype_get_max (),
-                                       EXTRACTOR_METAFORMAT_UTF8,
-                                       "text/plain", txt, strlen (txt) + 1);
+    GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
+                                       q % 42 /* EXTRACTOR_metatype_get_max () */,
+                                       EXTRACTOR_METAFORMAT_UTF8, "text/plain",
+                                       txt, strlen (txt) + 1);
   }
   size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
   data = GNUNET_malloc (size * 4);
-  if (size != GNUNET_CONTAINER_meta_data_serialize (meta,
-                                                    &data, size * 4,
-                                                    GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
+  if (size !=
+      GNUNET_CONTAINER_meta_data_serialize (meta, &data, size * 4,
+                                            GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
   {
     GNUNET_free (data);
     ABORT (meta);
@@ -162,6 +158,7 @@ testMetaMore (int i)
   return 0;
 }
 
+
 static int
 testMetaLink ()
 {
@@ -171,25 +168,23 @@ testMetaLink ()
 
   m = GNUNET_CONTAINER_meta_data_create ();
   if (GNUNET_OK !=
-      GNUNET_CONTAINER_meta_data_insert (m,
-                                         "<test>",
+      GNUNET_CONTAINER_meta_data_insert (m, "<test>",
                                          EXTRACTOR_METATYPE_UNKNOWN,
                                          EXTRACTOR_METAFORMAT_UTF8,
-                                         "text/plain",
-                                         "link", strlen ("link") + 1))
+                                         "text/plain", "link",
+                                         strlen ("link") + 1))
     ABORT (m);
   if (GNUNET_OK !=
-      GNUNET_CONTAINER_meta_data_insert (m,
-                                         "<test>",
+      GNUNET_CONTAINER_meta_data_insert (m, "<test>",
                                          EXTRACTOR_METATYPE_FILENAME,
                                          EXTRACTOR_METAFORMAT_UTF8,
-                                         "text/plain",
-                                         "lib-link.m4",
+                                         "text/plain", "lib-link.m4",
                                          strlen ("lib-link.m4") + 1))
     ABORT (m);
   val = NULL;
-  size = GNUNET_CONTAINER_meta_data_serialize (m, &val, (size_t) - 1,
-                                               GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
+  size =
+      GNUNET_CONTAINER_meta_data_serialize (m, &val, (size_t) - 1,
+                                            GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
   GNUNET_CONTAINER_meta_data_destroy (m);
   m = GNUNET_CONTAINER_meta_data_deserialize (val, size);
   GNUNET_free (val);
@@ -199,7 +194,8 @@ testMetaLink ()
   return 0;
 }
 
-int
+
+static int
 check ()
 {
   struct GNUNET_CONTAINER_MetaData *meta;
@@ -215,17 +211,13 @@ check ()
   for (q = 0; q <= i; q++)
   {
     GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q);
-    GNUNET_CONTAINER_meta_data_insert (meta,
-                                       "<test>",
+    GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
                                        EXTRACTOR_METATYPE_UNKNOWN,
-                                       EXTRACTOR_METAFORMAT_UTF8,
-                                       "text/plain",
+                                       EXTRACTOR_METAFORMAT_UTF8, "text/plain",
                                        "TestTitle", strlen ("TestTitle") + 1);
-    GNUNET_CONTAINER_meta_data_insert (meta2,
-                                       "<test>",
+    GNUNET_CONTAINER_meta_data_insert (meta2, "<test>",
                                        EXTRACTOR_METATYPE_UNKNOWN,
-                                       EXTRACTOR_METAFORMAT_UTF8,
-                                       "text/plain",
+                                       EXTRACTOR_METAFORMAT_UTF8, "text/plain",
                                        "TestTitle", strlen ("TestTitle") + 1);
   }
 
@@ -303,9 +295,10 @@ check ()
   }
 
   //check meta_data_get_first_by_types
-  str = GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
-                                                       EXTRACTOR_METATYPE_UNKNOWN,
-                                                       -1);
+  str =
+      GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
+                                                     EXTRACTOR_METATYPE_UNKNOWN,
+                                                     -1);
   GNUNET_assert (NULL != str);
   if (str[0] != 'T')
   {
@@ -359,4 +352,5 @@ main (int argc, char *argv[])
   return 0;
 }
 
+
 /* end of test_container_meta_data.c */