2 This file is part of GNUnet.
3 (C) 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file datastore/test_datastore_api.c
22 * @brief Test for the datastore implementation.
23 * @author Christian Grothoff
26 * - test multiple values under same key
28 * - test storage reservations
32 #include "gnunet_util_lib.h"
33 #include "gnunet_protocols.h"
34 #include "gnunet_datastore_service.h"
36 static struct GNUNET_DATASTORE_Handle *datastore;
38 static struct GNUNET_TIME_Absolute now;
51 static char buf[60000];
52 memset (buf, i, 8 * i);
78 static struct GNUNET_TIME_Absolute
79 get_expiration (int i)
81 struct GNUNET_TIME_Absolute av;
83 av.value = now.value - i * 1000;
89 check_success (void *cls,
93 GNUNET_assert (GNUNET_OK == success);
98 check_failure (void *cls,
102 GNUNET_assert (GNUNET_OK != success);
103 GNUNET_assert (NULL != msg);
108 check_value (void *cls,
109 const GNUNET_HashCode * key,
115 struct GNUNET_TIME_Absolute
116 expiration, uint64_t uid)
124 GNUNET_assert (size == get_size (i));
125 GNUNET_assert (0 == memcmp (data, get_data(i), size));
126 GNUNET_assert (type == get_type (i));
127 GNUNET_assert (priority == get_priority (i));
128 GNUNET_assert (anonymity == get_anonymity(i));
129 GNUNET_assert (expiration.value == get_expiration(i).value);
134 delete_value (void *cls,
135 const GNUNET_HashCode * key,
141 struct GNUNET_TIME_Absolute
142 expiration, uint64_t uid)
146 GNUNET_DATASTORE_remove (datastore,
153 GNUNET_DATASTORE_remove (datastore,
164 check_nothing (void *cls,
165 const GNUNET_HashCode * key,
171 struct GNUNET_TIME_Absolute
172 expiration, uint64_t uid)
174 GNUNET_assert (key == NULL);
181 struct GNUNET_SCHEDULER_Handle *sched,
183 const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *cfg)
189 datastore = GNUNET_DATASTORE_connect (cfg, sched);
191 for (i = 0; i < 256; i++)
193 memset (&key, 256 - i, sizeof (GNUNET_HashCode));
194 GNUNET_DATASTORE_put (datastore,
206 for (i = 255; i >= 0; i--)
208 memset (&key, 256 - i, sizeof (GNUNET_HashCode));
209 iptr = GNUNET_malloc(sizeof(int));
211 GNUNET_DATASTORE_get (datastore,
217 for (i = 255; i >= 0; i--)
219 memset (&key, 256 - i, sizeof (GNUNET_HashCode));
220 iptr = GNUNET_malloc(sizeof(int));
222 GNUNET_DATASTORE_get (datastore,
228 for (i = 255; i >= 0; i--)
230 memset (&key, 256 - i, sizeof (GNUNET_HashCode));
231 iptr = GNUNET_malloc(sizeof(int));
233 GNUNET_DATASTORE_get (datastore,
239 /* check reservations */
243 /* test multiple results */
245 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
253 int ok = 1 + 2 + 4 + 8;
255 char *const argv[] = { "test-datastore-api",
257 "test_datastore_api_data.conf",
263 struct GNUNET_GETOPT_CommandLineOption options[] = {
264 GNUNET_GETOPT_OPTION_END
266 pid = GNUNET_OS_start_process ("gnunet-service-datastore",
267 "gnunet-service-datastore",
271 "-c", "test_datastore_api_data.conf", NULL);
273 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
274 argv, "test-datastore-api", "nohelp",
276 if (0 != PLIBC_KILL (pid, SIGTERM))
278 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
281 GNUNET_OS_process_wait(pid);
283 fprintf (stderr, "Missed some testcases: %u\n", ok);
288 main (int argc, char *argv[])
292 GNUNET_log_setup ("test-datastore-api",
306 /* end of test_datastore_api.c */