aboutsummaryrefslogtreecommitdiff
path: root/src/datacache/test_datacache_api.c
diff options
context:
space:
mode:
authorgrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2009-07-26 19:15:11 +0000
committergrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2009-07-26 19:15:11 +0000
commit3f35baf68c7913844fd818f83494ba620738b4b7 (patch)
treec53bd60f71ee19fd919eb4500ac3b4223ce2917d /src/datacache/test_datacache_api.c
parenteddb74219df460bdb0cb1f9419d7412501b5ceb4 (diff)
fixing bugs, adding testcases
git-svn-id: https://gnunet.org/svn/gnunet@8788 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/datacache/test_datacache_api.c')
-rw-r--r--src/datacache/test_datacache_api.c130
1 files changed, 78 insertions, 52 deletions
diff --git a/src/datacache/test_datacache_api.c b/src/datacache/test_datacache_api.c
index d4fea584f8..124f75a12e 100644
--- a/src/datacache/test_datacache_api.c
+++ b/src/datacache/test_datacache_api.c
@@ -22,102 +22,128 @@
* @brief Test for the datacache implementations.
* @author Nils Durner
*/
-
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_datacache_lib.h"
-#if 0
+#define VERBOSE GNUNET_NO
+
#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0)
-static int error;
+static int ok;
+
static int
-checkIt (const GNUNET_HashCode * key,
- unsigned int type, unsigned int size, const char *data, void *cls)
+checkIt (void *cls,
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const char *data,
+ uint32_t type)
{
if (size != sizeof (GNUNET_HashCode))
{
printf ("ERROR: Invalid size\n");
- error = 2;
+ ok = 2;
}
if (0 != memcmp (data, cls, size))
{
printf ("ERROR: Invalid data\n");
- error = 3;
+ ok = 3;
}
return GNUNET_OK;
}
-/**
- * Add testcode here!
- */
-static int
-test (GNUNET_Dstore_ServiceAPI * api)
+
+static void
+run (void *cls,
+ struct GNUNET_SCHEDULER_Handle *sched,
+ char *const *args,
+ const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ struct GNUNET_DATACACHE_Handle *h;
GNUNET_HashCode k;
GNUNET_HashCode n;
- GNUNET_CronTime exp;
+ struct GNUNET_TIME_Absolute exp;
unsigned int i;
- exp = GNUNET_get_time () + 5 * GNUNET_CRON_MINUTES;
+ ok = 0;
+ h = GNUNET_DATACACHE_create (sched,
+ cfg,
+ "testcache");
+
+ ASSERT (NULL != h);
+ exp = GNUNET_TIME_absolute_get ();
+ exp.value += 5 * 60 * 1000;
memset (&k, 0, sizeof (GNUNET_HashCode));
for (i = 0; i < 100; i++)
{
- GNUNET_hash (&k, sizeof (GNUNET_HashCode), &n);
- ASSERT (GNUNET_OK == api->put (&k,
- i % 2,
- exp, sizeof (GNUNET_HashCode),
- (const char *) &n));
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h,
+ &k,
+ sizeof (GNUNET_HashCode),
+ (const char *) &n,
+ 1+i%16,
+ exp));
k = n;
}
memset (&k, 0, sizeof (GNUNET_HashCode));
for (i = 0; i < 100; i++)
{
- GNUNET_hash (&k, sizeof (GNUNET_HashCode), &n);
- ASSERT (1 == api->get (&k, i % 2, &checkIt, &n));
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ ASSERT (1 ==
+ GNUNET_DATACACHE_get (h, &k, 1+i%16,
+ &checkIt, &n));
k = n;
}
- return GNUNET_OK;
+ GNUNET_DATACACHE_destroy (h);
+ ASSERT (ok == 0);
+ return;
FAILURE:
- return GNUNET_SYSERR;
+ if (h != NULL)
+ GNUNET_DATACACHE_destroy (h);
+ ok = GNUNET_SYSERR;
}
-#define TEST_DB "/tmp/GNUnet_dstore_test/"
+
+static int
+check ()
+{
+ char *const argv[] = { "test-datacache-api",
+ "-c",
+ "test_datacache_api_data.conf",
+#if VERBOSE
+ "-L", "DEBUG",
#endif
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+ argv, "test-datacache-api", "nohelp",
+ options, &run, NULL);
+ if (ok != 0)
+ fprintf (stderr, "Missed some testcases: %d\n", ok);
+ return ok;
+}
+
int
main (int argc, char *argv[])
{
-#if 0
- GNUNET_Dstore_ServiceAPI *api;
- int ok;
- struct GNUNET_GC_Configuration *cfg;
- struct GNUNET_CronManager *cron;
-
- GNUNET_disable_entropy_gathering ();
- cfg = GNUNET_GC_create ();
- if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
- {
- GNUNET_GC_free (cfg);
- return -1;
- }
- cron = GNUNET_cron_create (NULL);
- GNUNET_CORE_init (NULL, cfg, cron, NULL);
- api = GNUNET_CORE_request_service ("dstore");
- if (api != NULL)
- {
- ok = test (api);
- GNUNET_CORE_release_service (api);
- }
- else
- ok = GNUNET_SYSERR;
- GNUNET_CORE_done ();
- if (ok == GNUNET_SYSERR)
- return 1;
- return error;
+ int ret;
+
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-datacache");
+ GNUNET_log_setup ("test-datacache-api",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
#endif
- return 0;
+ NULL);
+ ret = check ();
+
+ return ret;
}
/* end of test_datacache_api.c */