-bringing copyright tags up to FSF standard
[oweals/gnunet.git] / src / namestore / test_namestore_api_lookup_shadow.c
index 6f9fd563877dc3cd449fdf7c40605790892176b9..9e46849476c90ddc63a7825ecf389d08dd6fab37 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2012 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
      Boston, MA 02111-1307, USA.
 */
 /**
- * @file namestore/test_namestore_api.c
- * @brief testcase for namestore_api.c: store a record and perform a lookup
+ * @file namestore/test_namestore_api_lookup_shadow_filter.c
+ * @brief testcase for namestore_api.c: store a shadow record and perform a lookup
+ * test passes if test returns the record but without the shadow flag since no
+ * other valid record is available
  */
 #include "platform.h"
 #include "gnunet_namecache_service.h"
@@ -39,7 +41,7 @@ static struct GNUNET_NAMESTORE_Handle *nsh;
 
 static struct GNUNET_NAMECACHE_Handle *nch;
 
-static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
+static struct GNUNET_SCHEDULER_Task * endbadly_task;
 
 static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
 
@@ -51,6 +53,7 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
 
 static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
 
+static char *directory;
 
 static void
 cleanup ()
@@ -113,15 +116,44 @@ rd_decrypt_cb (void *cls,
 {
   char rd_cmp_data[TEST_RECORD_DATALEN];
 
-  GNUNET_assert (1 == rd_count);
-  GNUNET_assert (NULL != rd);
-
+  if (1 != rd_count)
+  {
+    GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    GNUNET_break (0);
+    return;
+  }
+  if (NULL == rd)
+  {
+    GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    GNUNET_break (0);
+    return;
+  }
   memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN);
 
-  GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type);
-  GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size);
-  GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN));
-  GNUNET_assert (GNUNET_GNSRECORD_RF_SHADOW_RECORD == rd[0].flags);
+  if (TEST_RECORD_TYPE != rd[0].record_type)
+  {
+    GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    GNUNET_break (0);
+    return;
+  }
+  if (TEST_RECORD_DATALEN != rd[0].data_size)
+  {
+    GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    GNUNET_break (0);
+    return;
+  }
+  if (0 != memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN))
+  {
+    GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    GNUNET_break (0);
+    return;
+  }
+  if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags))
+  {
+    GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    GNUNET_break (0);
+    return;
+  }
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Block was decrypted successfully \n");
@@ -139,17 +171,17 @@ name_lookup_proc (void *cls,
   ncqe = NULL;
   GNUNET_assert (NULL != cls);
 
-  if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
+  if (endbadly_task != NULL)
   {
     GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_NO_TASK;
+    endbadly_task = NULL;
   }
 
   if (NULL == block)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
              _("Namestore returned no block\n"));
-    if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
+    if (endbadly_task != NULL)
       GNUNET_SCHEDULER_cancel (endbadly_task);
     endbadly_task =  GNUNET_SCHEDULER_add_now (&endbadly, NULL);
     return;
@@ -194,6 +226,11 @@ run (void *cls,
   char *hostkey_file;
   const char * name = "dummy.dummy.gnunet";
 
+  directory = NULL;
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
+  GNUNET_DISK_directory_remove (directory);
+
   endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
                                                &endbadly, NULL);
   GNUNET_asprintf (&hostkey_file,
@@ -206,7 +243,6 @@ run (void *cls,
   GNUNET_assert (privkey != NULL);
   GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
 
-
   rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
   rd.record_type = TEST_RECORD_TYPE;
   rd.data_size = TEST_RECORD_DATALEN;
@@ -225,7 +261,6 @@ run (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
              _("Namestore cannot store no block\n"));
   }
-
   GNUNET_free ((void *)rd.data);
 }
 
@@ -239,9 +274,16 @@ main (int argc, char *argv[])
                                "test_namestore_api.conf",
                                &run,
                                NULL))
-    return 1;
+  {
+    res = 1;
+  }
+  if (NULL != directory)
+  {
+      GNUNET_DISK_directory_remove (directory);
+      GNUNET_free (directory);
+  }
   return res;
 }
 
 
-/* end of test_namestore_api_lookup_public.c */
+/* end of test_namestore_api_lookup_shadow_filter.c */