- update fs
[oweals/gnunet.git] / src / fs / test_fs_uri.c
index b7a58ec0f38a08c7a7a7b504646d10d59c8e18ef..2fc5b2a2d4649673ab82b6d2a92b3b215397ad14 100644 (file)
      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      Boston, MA 02111-1307, USA.
 */
-
 /**
  * @file fs/test_fs_uri.c
  * @brief Test for fs_uri.c
  * @author Christian Grothoff
  */
-
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_fs_service.h"
 #include "fs_api.h"
 
-#define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; }
 
 static int
 testKeyword ()
@@ -41,26 +38,26 @@ testKeyword ()
   if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/++", &emsg)))
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
   GNUNET_free (emsg);
   ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/foo+bar", &emsg);
   if (ret == NULL)
   {
     GNUNET_free (emsg);
-    ABORT ();
+    GNUNET_assert (0);
   }
   if (!GNUNET_FS_uri_test_ksk (ret))
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
   if ((2 != ret->data.ksk.keywordCount) ||
       (0 != strcmp (" foo", ret->data.ksk.keywords[0])) ||
       (0 != strcmp (" bar", ret->data.ksk.keywords[1])))
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
 
   uri = GNUNET_FS_uri_to_string (ret);
@@ -68,13 +65,14 @@ testKeyword ()
   {
     GNUNET_free (uri);
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
   GNUNET_free (uri);
   GNUNET_FS_uri_destroy (ret);
   return 0;
 }
 
+
 static int
 testLocation ()
 {
@@ -136,6 +134,7 @@ testLocation ()
   GNUNET_free (uric);
   if (uri2 == NULL)
   {
+    fprintf (stderr, "URI parsing failed: %s\n", emsg);
     GNUNET_break (0);
     GNUNET_FS_uri_destroy (uri);
     GNUNET_CONFIGURATION_destroy (cfg);
@@ -157,12 +156,18 @@ testLocation ()
   return 0;
 }
 
+
 static int
 testNamespace (int i)
 {
   char *uri;
   struct GNUNET_FS_Uri *ret;
   char *emsg;
+  struct GNUNET_CRYPTO_EcdsaPrivateKey *ph;
+  struct GNUNET_CRYPTO_EcdsaPublicKey id;
+  char buf[1024];
+  char ubuf[1024];
+  char *sret;
 
   if (NULL !=
       (ret =
@@ -170,7 +175,7 @@ testNamespace (int i)
                             &emsg)))
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
   GNUNET_free (emsg);
   if (NULL !=
@@ -179,49 +184,56 @@ testNamespace (int i)
        ("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3V/test", &emsg)))
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
   GNUNET_free (emsg);
   if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/sks/test", &emsg)))
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
   GNUNET_free (emsg);
-  ret =
-      GNUNET_FS_uri_parse
-      ("gnunet://fs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test",
-       &emsg);
-  if (ret == NULL)
+  ph = GNUNET_CRYPTO_ecdsa_key_create ();
+  GNUNET_CRYPTO_ecdsa_key_get_public (ph, &id);
+  sret = GNUNET_STRINGS_data_to_string (&id, sizeof (id),
+                                       ubuf, sizeof (ubuf) - 1);
+  GNUNET_assert (NULL != sret);
+  sret[0] = '\0';
+  GNUNET_snprintf (buf, sizeof (buf),
+                  "gnunet://fs/sks/%s/test",
+                  ubuf);
+  ret = GNUNET_FS_uri_parse (buf, &emsg);
+  if (NULL == ret)
   {
     GNUNET_free (emsg);
-    ABORT ();
+    GNUNET_assert (0);
   }
   if (GNUNET_FS_uri_test_ksk (ret))
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
   if (!GNUNET_FS_uri_test_sks (ret))
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
 
   uri = GNUNET_FS_uri_to_string (ret);
   if (0 !=
       strcmp (uri,
-              "gnunet://fs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test"))
+              buf))
   {
     GNUNET_FS_uri_destroy (ret);
     GNUNET_free (uri);
-    ABORT ();
+    GNUNET_assert (0);
   }
   GNUNET_free (uri);
   GNUNET_FS_uri_destroy (ret);
   return 0;
 }
 
+
 static int
 testFile (int i)
 {
@@ -236,7 +248,7 @@ testFile (int i)
         &emsg)))
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
   GNUNET_free (emsg);
   if (NULL !=
@@ -246,7 +258,7 @@ testFile (int i)
         &emsg)))
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
   GNUNET_free (emsg);
   if (NULL !=
@@ -256,7 +268,7 @@ testFile (int i)
         &emsg)))
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
   GNUNET_free (emsg);
   ret =
@@ -266,22 +278,22 @@ testFile (int i)
   if (ret == NULL)
   {
     GNUNET_free (emsg);
-    ABORT ();
+    GNUNET_assert (0);
   }
   if (GNUNET_FS_uri_test_ksk (ret))
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
   if (GNUNET_FS_uri_test_sks (ret))
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
   if (GNUNET_ntohll (ret->data.chk.file_length) != 42)
   {
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
 
   uri = GNUNET_FS_uri_to_string (ret);
@@ -291,13 +303,14 @@ testFile (int i)
   {
     GNUNET_free (uri);
     GNUNET_FS_uri_destroy (ret);
-    ABORT ();
+    GNUNET_assert (0);
   }
   GNUNET_free (uri);
   GNUNET_FS_uri_destroy (ret);
   return 0;
 }
 
+
 int
 main (int argc, char *argv[])
 {
@@ -305,13 +318,8 @@ main (int argc, char *argv[])
   int i;
 
   GNUNET_log_setup ("test_fs_uri",
-#if VERBOSE
-                    "DEBUG",
-#else
                     "WARNING",
-#endif
                     NULL);
-  GNUNET_CRYPTO_random_disable_entropy_gathering ();
   failureCount += testKeyword ();
   failureCount += testLocation ();
   for (i = 0; i < 255; i++)