2 This file is part of GNUnet.
3 Copyright (C) 2006, 2009, 2010 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file datacache/test_datacache.c
22 * @brief Test for the datacache implementations.
26 #include "gnunet_util_lib.h"
27 #include "gnunet_datacache_lib.h"
28 #include "gnunet_testing_lib.h"
30 #define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0)
35 * Name of plugin under test.
37 static const char *plugin_name;
42 const struct GNUNET_HashCode *key,
43 size_t size, const char *data,
44 enum GNUNET_BLOCK_Type type,
45 struct GNUNET_TIME_Absolute exp,
46 unsigned int path_len,
47 const struct GNUNET_PeerIdentity *path)
54 if (size != sizeof (struct GNUNET_HashCode))
59 if (0 != memcmp (data, cls, size))
72 const struct GNUNET_CONFIGURATION_Handle *cfg)
74 struct GNUNET_DATACACHE_Handle *h;
75 struct GNUNET_HashCode k;
76 struct GNUNET_HashCode n;
77 struct GNUNET_TIME_Absolute exp;
83 h = GNUNET_DATACACHE_create (cfg,
89 "Failed to initialize datacache. Database likely not setup, skipping test.\n");
90 ok = 77; /* mark test as skipped */
93 exp = GNUNET_TIME_absolute_get ();
94 exp.abs_value_us += 5 * 60 * 1000 * 1000LL;
95 memset (&k, 0, sizeof (struct GNUNET_HashCode));
96 for (unsigned int i = 0; i < 100; i++)
98 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n);
100 GNUNET_DATACACHE_put (h,
103 sizeof (struct GNUNET_HashCode),
104 (const char *) &n, 1 + i % 16, exp,
110 sizeof (struct GNUNET_HashCode));
111 for (unsigned int i = 0; i < 100; i++)
113 GNUNET_CRYPTO_hash (&k,
114 sizeof (struct GNUNET_HashCode),
116 ASSERT (1 == GNUNET_DATACACHE_get (h,
126 sizeof (struct GNUNET_HashCode));
127 GNUNET_CRYPTO_hash (&k,
128 sizeof (struct GNUNET_HashCode),
131 GNUNET_DATACACHE_put (h,
134 sizeof (struct GNUNET_HashCode),
137 GNUNET_TIME_UNIT_FOREVER_ABS,
140 ASSERT (0 != GNUNET_DATACACHE_get (h,
145 GNUNET_DATACACHE_destroy (h);
150 GNUNET_DATACACHE_destroy (h);
156 main (int argc, char *argv[])
158 char cfg_name[PATH_MAX];
159 char *const xargv[] = {
165 struct GNUNET_GETOPT_CommandLineOption options[] = {
166 GNUNET_GETOPT_OPTION_END
170 GNUNET_log_setup ("test-datacache",
173 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
174 GNUNET_snprintf (cfg_name,
176 "test_datacache_data_%s.conf",
178 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
185 if ( (0 != ok) && (77 != ok) )
187 "Missed some testcases: %d\n",
192 /* end of test_datacache.c */