add keywords from metadata for files
[oweals/gnunet.git] / src / util / test_pseudonym.c
index a8b4575e34698ad8f7c358167e7141711c8770cd..0f68f9f053f12cf701b1cbb7085ebe8557746115 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
@@ -31,7 +31,7 @@
 #include "gnunet_disk_lib.h"
 #include "gnunet_pseudonym_lib.h"
 
 #include "gnunet_disk_lib.h"
 #include "gnunet_pseudonym_lib.h"
 
-#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_break(0); goto FAILURE; }
+#define CHECK(a) do { if (!(a)) { ok = GNUNET_NO; GNUNET_break(0); goto FAILURE; } } while (0)
 
 static struct GNUNET_CONTAINER_MetaData *meta;
 
 
 static struct GNUNET_CONTAINER_MetaData *meta;
 
@@ -79,12 +79,12 @@ fake_noti_callback (void *cls,
 
 static int
 false_callback (void *cls,
 
 static int
 false_callback (void *cls,
-        const GNUNET_HashCode *
-        pseudonym,
-        const struct GNUNET_CONTAINER_MetaData *md, int rating)
+               const GNUNET_HashCode *pseudonym,
+               const struct GNUNET_CONTAINER_MetaData *md, int rating)
 {
 {
-         return GNUNET_OK;
+  return GNUNET_OK;
 }
 }
+
 int
 main (int argc, char *argv[])
 {
 int
 main (int argc, char *argv[])
 {
@@ -94,7 +94,6 @@ main (int argc, char *argv[])
   GNUNET_HashCode rid2;
   GNUNET_HashCode fid;
   GNUNET_HashCode id3;
   GNUNET_HashCode rid2;
   GNUNET_HashCode fid;
   GNUNET_HashCode id3;
-  GNUNET_HashCode rid3;
 
   int old;
   int newVal;
 
   int old;
   int newVal;
@@ -112,7 +111,7 @@ main (int argc, char *argv[])
   GNUNET_log_setup ("test-pseudonym", "WARNING", NULL);
   ok = GNUNET_YES;
   GNUNET_CRYPTO_random_disable_entropy_gathering ();
   GNUNET_log_setup ("test-pseudonym", "WARNING", NULL);
   ok = GNUNET_YES;
   GNUNET_CRYPTO_random_disable_entropy_gathering ();
-  GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test");
+  (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test");
   cfg = GNUNET_CONFIGURATION_create ();
   if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf"))
     {
   cfg = GNUNET_CONFIGURATION_create ();
   if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf"))
     {
@@ -133,7 +132,13 @@ main (int argc, char *argv[])
   /* ACTUAL TEST CODE */
   old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL);
   meta = GNUNET_CONTAINER_meta_data_create ();
   /* ACTUAL TEST CODE */
   old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL);
   meta = GNUNET_CONTAINER_meta_data_create ();
-  GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_TITLE,"test");
+  GNUNET_CONTAINER_meta_data_insert (meta, 
+                                    "<test>",
+                                    EXTRACTOR_METATYPE_TITLE,
+                                    EXTRACTOR_METAFORMAT_UTF8,
+                                    "text/plain",
+                                    "test",
+                                    strlen("test")+1);
   GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1);
   GNUNET_PSEUDONYM_add (cfg, &id1, meta);
   CHECK (notiCount == 1);
   GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1);
   GNUNET_PSEUDONYM_add (cfg, &id1, meta);
   CHECK (notiCount == 1);
@@ -147,25 +152,31 @@ main (int argc, char *argv[])
   CHECK (notiCount == 3);
   newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok);
   CHECK (old < newVal);
   CHECK (notiCount == 3);
   newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok);
   CHECK (old < newVal);
-  GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_COMMENT, m));
+  GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (meta, 
+                                                                "<test>",
+                                                                EXTRACTOR_METATYPE_COMMENT,
+                                                                EXTRACTOR_METAFORMAT_UTF8,
+                                                                "text/plain",
+                                                                m,
+                                                                strlen(m)+1));
   GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3);
   GNUNET_PSEUDONYM_add (cfg, &id3, meta);
   GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3);
   GNUNET_PSEUDONYM_add (cfg, &id3, meta);
-  GNUNET_log_skip (1, GNUNET_NO);
   name3 = GNUNET_PSEUDONYM_id_to_name (cfg, &id3);
   name3 = GNUNET_PSEUDONYM_id_to_name (cfg, &id3);
-  GNUNET_log_skip (0, GNUNET_YES);
   name2 = GNUNET_PSEUDONYM_id_to_name (cfg, &id2);
   CHECK (name2 != NULL);
   name1 = GNUNET_PSEUDONYM_id_to_name (cfg, &id1);
   CHECK (name1 != NULL);
   CHECK (0 != strcmp (name1, name2));
   name2 = GNUNET_PSEUDONYM_id_to_name (cfg, &id2);
   CHECK (name2 != NULL);
   name1 = GNUNET_PSEUDONYM_id_to_name (cfg, &id1);
   CHECK (name1 != NULL);
   CHECK (0 != strcmp (name1, name2));
-  CHECK        (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, "fake", &rid2))
+  CHECK        (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, "fake", &rid2));
   CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2, &rid2));
   CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1));
   CHECK (0 == memcmp (&id1, &rid1, sizeof (GNUNET_HashCode)));
   CHECK (0 == memcmp (&id2, &rid2, sizeof (GNUNET_HashCode)));
 
   GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &fid);
   CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2, &rid2));
   CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1));
   CHECK (0 == memcmp (&id1, &rid1, sizeof (GNUNET_HashCode)));
   CHECK (0 == memcmp (&id2, &rid2, sizeof (GNUNET_HashCode)));
 
   GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &fid);
+  GNUNET_log_skip (1, GNUNET_NO);
   CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &fid, 0));
   CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &fid, 0));
+  GNUNET_log_skip (0, GNUNET_YES);
   noname = GNUNET_PSEUDONYM_id_to_name (cfg, &fid);
   CHECK (noname != NULL);
   CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &id1, 0));
   noname = GNUNET_PSEUDONYM_id_to_name (cfg, &fid);
   CHECK (noname != NULL);
   CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &id1, 0));
@@ -181,7 +192,7 @@ FAILURE:
   GNUNET_PSEUDONYM_discovery_callback_unregister (&noti_callback, &notiCount);
   GNUNET_CONTAINER_meta_data_destroy (meta);
   GNUNET_CONFIGURATION_destroy (cfg);
   GNUNET_PSEUDONYM_discovery_callback_unregister (&noti_callback, &notiCount);
   GNUNET_CONTAINER_meta_data_destroy (meta);
   GNUNET_CONFIGURATION_destroy (cfg);
-  GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test");
+  GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"));
   return (ok == GNUNET_YES) ? 0 : 1;
 }
 
   return (ok == GNUNET_YES) ? 0 : 1;
 }