aboutsummaryrefslogtreecommitdiff
path: root/src/datacache/test_datacache.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datacache/test_datacache.c')
-rw-r--r--src/datacache/test_datacache.c222
1 files changed, 111 insertions, 111 deletions
diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c
index 572a775df..30ef81a70 100644
--- a/src/datacache/test_datacache.c
+++ b/src/datacache/test_datacache.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/* 20/*
21 * @file datacache/test_datacache.c 21 * @file datacache/test_datacache.c
22 * @brief Test for the datacache implementations. 22 * @brief Test for the datacache implementations.
@@ -27,7 +27,7 @@
27#include "gnunet_datacache_lib.h" 27#include "gnunet_datacache_lib.h"
28#include "gnunet_testing_lib.h" 28#include "gnunet_testing_lib.h"
29 29
30#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0) 30#define ASSERT(x) do { if (!(x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE; } } while (0)
31 31
32static int ok; 32static int ok;
33 33
@@ -38,122 +38,122 @@ static const char *plugin_name;
38 38
39 39
40static int 40static int
41checkIt (void *cls, 41checkIt(void *cls,
42 const struct GNUNET_HashCode *key, 42 const struct GNUNET_HashCode *key,
43 size_t size, const char *data, 43 size_t size, const char *data,
44 enum GNUNET_BLOCK_Type type, 44 enum GNUNET_BLOCK_Type type,
45 struct GNUNET_TIME_Absolute exp, 45 struct GNUNET_TIME_Absolute exp,
46 unsigned int path_len, 46 unsigned int path_len,
47 const struct GNUNET_PeerIdentity *path) 47 const struct GNUNET_PeerIdentity *path)
48{ 48{
49 (void) key; 49 (void)key;
50 (void) type; 50 (void)type;
51 (void) exp; 51 (void)exp;
52 (void) path_len; 52 (void)path_len;
53 (void) path; 53 (void)path;
54 if (size != sizeof (struct GNUNET_HashCode)) 54 if (size != sizeof(struct GNUNET_HashCode))
55 { 55 {
56 GNUNET_break (0); 56 GNUNET_break(0);
57 ok = 2; 57 ok = 2;
58 } 58 }
59 if (0 != memcmp (data, cls, size)) 59 if (0 != memcmp(data, cls, size))
60 { 60 {
61 GNUNET_break (0); 61 GNUNET_break(0);
62 ok = 3; 62 ok = 3;
63 } 63 }
64 return GNUNET_OK; 64 return GNUNET_OK;
65} 65}
66 66
67 67
68static void 68static void
69run (void *cls, 69run(void *cls,
70 char *const *args, 70 char *const *args,
71 const char *cfgfile, 71 const char *cfgfile,
72 const struct GNUNET_CONFIGURATION_Handle *cfg) 72 const struct GNUNET_CONFIGURATION_Handle *cfg)
73{ 73{
74 struct GNUNET_DATACACHE_Handle *h; 74 struct GNUNET_DATACACHE_Handle *h;
75 struct GNUNET_HashCode k; 75 struct GNUNET_HashCode k;
76 struct GNUNET_HashCode n; 76 struct GNUNET_HashCode n;
77 struct GNUNET_TIME_Absolute exp; 77 struct GNUNET_TIME_Absolute exp;
78 78
79 (void) cls; 79 (void)cls;
80 (void) args; 80 (void)args;
81 (void) cfgfile; 81 (void)cfgfile;
82 ok = 0; 82 ok = 0;
83 h = GNUNET_DATACACHE_create (cfg, 83 h = GNUNET_DATACACHE_create(cfg,
84 "testcache"); 84 "testcache");
85 if (h == NULL) 85 if (h == NULL)
86 { 86 {
87 fprintf (stderr, 87 fprintf(stderr,
88 "%s", 88 "%s",
89 "Failed to initialize datacache. Database likely not setup, skipping test.\n"); 89 "Failed to initialize datacache. Database likely not setup, skipping test.\n");
90 ok = 77; /* mark test as skipped */ 90 ok = 77; /* mark test as skipped */
91 return; 91 return;
92 } 92 }
93 exp = GNUNET_TIME_absolute_get (); 93 exp = GNUNET_TIME_absolute_get();
94 exp.abs_value_us += 5 * 60 * 1000 * 1000LL; 94 exp.abs_value_us += 5 * 60 * 1000 * 1000LL;
95 memset (&k, 0, sizeof (struct GNUNET_HashCode)); 95 memset(&k, 0, sizeof(struct GNUNET_HashCode));
96 for (unsigned int i = 0; i < 100; i++) 96 for (unsigned int i = 0; i < 100; i++)
97 { 97 {
98 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); 98 GNUNET_CRYPTO_hash(&k, sizeof(struct GNUNET_HashCode), &n);
99 ASSERT (GNUNET_OK == 99 ASSERT(GNUNET_OK ==
100 GNUNET_DATACACHE_put (h, 100 GNUNET_DATACACHE_put(h,
101 &k, 101 &k,
102 GNUNET_YES, 102 GNUNET_YES,
103 sizeof (struct GNUNET_HashCode), 103 sizeof(struct GNUNET_HashCode),
104 (const char *) &n, 1 + i % 16, exp, 104 (const char *)&n, 1 + i % 16, exp,
105 0, NULL)); 105 0, NULL));
106 k = n; 106 k = n;
107 } 107 }
108 memset (&k, 108 memset(&k,
109 0, 109 0,
110 sizeof (struct GNUNET_HashCode)); 110 sizeof(struct GNUNET_HashCode));
111 for (unsigned int i = 0; i < 100; i++) 111 for (unsigned int i = 0; i < 100; i++)
112 { 112 {
113 GNUNET_CRYPTO_hash (&k, 113 GNUNET_CRYPTO_hash(&k,
114 sizeof (struct GNUNET_HashCode), 114 sizeof(struct GNUNET_HashCode),
115 &n); 115 &n);
116 ASSERT (1 == GNUNET_DATACACHE_get (h, 116 ASSERT(1 == GNUNET_DATACACHE_get(h,
117 &k, 117 &k,
118 1 + i % 16, 118 1 + i % 16,
119 &checkIt, 119 &checkIt,
120 &n)); 120 &n));
121 k = n; 121 k = n;
122 } 122 }
123 123
124 memset (&k, 124 memset(&k,
125 42, 125 42,
126 sizeof (struct GNUNET_HashCode)); 126 sizeof(struct GNUNET_HashCode));
127 GNUNET_CRYPTO_hash (&k, 127 GNUNET_CRYPTO_hash(&k,
128 sizeof (struct GNUNET_HashCode), 128 sizeof(struct GNUNET_HashCode),
129 &n); 129 &n);
130 ASSERT (GNUNET_OK == 130 ASSERT(GNUNET_OK ==
131 GNUNET_DATACACHE_put (h, 131 GNUNET_DATACACHE_put(h,
132 &k, 132 &k,
133 GNUNET_YES, 133 GNUNET_YES,
134 sizeof (struct GNUNET_HashCode), 134 sizeof(struct GNUNET_HashCode),
135 (const char *) &n, 135 (const char *)&n,
136 792, 136 792,
137 GNUNET_TIME_UNIT_FOREVER_ABS, 137 GNUNET_TIME_UNIT_FOREVER_ABS,
138 0, 138 0,
139 NULL)); 139 NULL));
140 ASSERT (0 != GNUNET_DATACACHE_get (h, 140 ASSERT(0 != GNUNET_DATACACHE_get(h,
141 &k, 141 &k,
142 792, 142 792,
143 &checkIt, 143 &checkIt,
144 &n)); 144 &n));
145 GNUNET_DATACACHE_destroy (h); 145 GNUNET_DATACACHE_destroy(h);
146 ASSERT (ok == 0); 146 ASSERT(ok == 0);
147 return; 147 return;
148FAILURE: 148FAILURE:
149 if (h != NULL) 149 if (h != NULL)
150 GNUNET_DATACACHE_destroy (h); 150 GNUNET_DATACACHE_destroy(h);
151 ok = GNUNET_SYSERR; 151 ok = GNUNET_SYSERR;
152} 152}
153 153
154 154
155int 155int
156main (int argc, char *argv[]) 156main(int argc, char *argv[])
157{ 157{
158 char cfg_name[PATH_MAX]; 158 char cfg_name[PATH_MAX];
159 char *const xargv[] = { 159 char *const xargv[] = {
@@ -166,26 +166,26 @@ main (int argc, char *argv[])
166 GNUNET_GETOPT_OPTION_END 166 GNUNET_GETOPT_OPTION_END
167 }; 167 };
168 168
169 (void) argc; 169 (void)argc;
170 GNUNET_log_setup ("test-datacache", 170 GNUNET_log_setup("test-datacache",
171 "WARNING", 171 "WARNING",
172 NULL); 172 NULL);
173 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 173 plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]);
174 GNUNET_snprintf (cfg_name, 174 GNUNET_snprintf(cfg_name,
175 sizeof (cfg_name), 175 sizeof(cfg_name),
176 "test_datacache_data_%s.conf", 176 "test_datacache_data_%s.conf",
177 plugin_name); 177 plugin_name);
178 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, 178 GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1,
179 xargv, 179 xargv,
180 "test-datacache", 180 "test-datacache",
181 "nohelp", 181 "nohelp",
182 options, 182 options,
183 &run, 183 &run,
184 NULL); 184 NULL);
185 if ( (0 != ok) && (77 != ok) ) 185 if ((0 != ok) && (77 != ok))
186 fprintf (stderr, 186 fprintf(stderr,
187 "Missed some testcases: %d\n", 187 "Missed some testcases: %d\n",
188 ok); 188 ok);
189 return ok; 189 return ok;
190} 190}
191 191