diff options
Diffstat (limited to 'src/datacache/test_datacache.c')
-rw-r--r-- | src/datacache/test_datacache.c | 73 |
1 files changed, 55 insertions, 18 deletions
diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c index 12edb62f8..50e45012d 100644 --- a/src/datacache/test_datacache.c +++ b/src/datacache/test_datacache.c | |||
@@ -44,6 +44,11 @@ checkIt (void *cls, | |||
44 | unsigned int path_len, | 44 | unsigned int path_len, |
45 | const struct GNUNET_PeerIdentity *path) | 45 | const struct GNUNET_PeerIdentity *path) |
46 | { | 46 | { |
47 | (void) key; | ||
48 | (void) type; | ||
49 | (void) exp; | ||
50 | (void) path_len; | ||
51 | (void) path; | ||
47 | if (size != sizeof (struct GNUNET_HashCode)) | 52 | if (size != sizeof (struct GNUNET_HashCode)) |
48 | { | 53 | { |
49 | GNUNET_break (0); | 54 | GNUNET_break (0); |
@@ -59,17 +64,22 @@ checkIt (void *cls, | |||
59 | 64 | ||
60 | 65 | ||
61 | static void | 66 | static void |
62 | run (void *cls, char *const *args, const char *cfgfile, | 67 | run (void *cls, |
68 | char *const *args, | ||
69 | const char *cfgfile, | ||
63 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 70 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
64 | { | 71 | { |
65 | struct GNUNET_DATACACHE_Handle *h; | 72 | struct GNUNET_DATACACHE_Handle *h; |
66 | struct GNUNET_HashCode k; | 73 | struct GNUNET_HashCode k; |
67 | struct GNUNET_HashCode n; | 74 | struct GNUNET_HashCode n; |
68 | struct GNUNET_TIME_Absolute exp; | 75 | struct GNUNET_TIME_Absolute exp; |
69 | unsigned int i; | ||
70 | 76 | ||
77 | (void) cls; | ||
78 | (void) args; | ||
79 | (void) cfgfile; | ||
71 | ok = 0; | 80 | ok = 0; |
72 | h = GNUNET_DATACACHE_create (cfg, "testcache"); | 81 | h = GNUNET_DATACACHE_create (cfg, |
82 | "testcache"); | ||
73 | if (h == NULL) | 83 | if (h == NULL) |
74 | { | 84 | { |
75 | FPRINTF (stderr, | 85 | FPRINTF (stderr, |
@@ -81,7 +91,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
81 | exp = GNUNET_TIME_absolute_get (); | 91 | exp = GNUNET_TIME_absolute_get (); |
82 | exp.abs_value_us += 5 * 60 * 1000 * 1000LL; | 92 | exp.abs_value_us += 5 * 60 * 1000 * 1000LL; |
83 | memset (&k, 0, sizeof (struct GNUNET_HashCode)); | 93 | memset (&k, 0, sizeof (struct GNUNET_HashCode)); |
84 | for (i = 0; i < 100; i++) | 94 | for (unsigned int i = 0; i < 100; i++) |
85 | { | 95 | { |
86 | GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); | 96 | GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); |
87 | ASSERT (GNUNET_OK == | 97 | ASSERT (GNUNET_OK == |
@@ -93,26 +103,43 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
93 | 0, NULL)); | 103 | 0, NULL)); |
94 | k = n; | 104 | k = n; |
95 | } | 105 | } |
96 | memset (&k, 0, sizeof (struct GNUNET_HashCode)); | 106 | memset (&k, |
97 | for (i = 0; i < 100; i++) | 107 | 0, |
108 | sizeof (struct GNUNET_HashCode)); | ||
109 | for (unsigned int i = 0; i < 100; i++) | ||
98 | { | 110 | { |
99 | GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); | 111 | GNUNET_CRYPTO_hash (&k, |
100 | ASSERT (1 == GNUNET_DATACACHE_get (h, &k, 1 + i % 16, &checkIt, &n)); | 112 | sizeof (struct GNUNET_HashCode), |
113 | &n); | ||
114 | ASSERT (1 == GNUNET_DATACACHE_get (h, | ||
115 | &k, | ||
116 | 1 + i % 16, | ||
117 | &checkIt, | ||
118 | &n)); | ||
101 | k = n; | 119 | k = n; |
102 | } | 120 | } |
103 | 121 | ||
104 | memset (&k, 42, sizeof (struct GNUNET_HashCode)); | 122 | memset (&k, |
105 | GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); | 123 | 42, |
124 | sizeof (struct GNUNET_HashCode)); | ||
125 | GNUNET_CRYPTO_hash (&k, | ||
126 | sizeof (struct GNUNET_HashCode), | ||
127 | &n); | ||
106 | ASSERT (GNUNET_OK == | 128 | ASSERT (GNUNET_OK == |
107 | GNUNET_DATACACHE_put (h, | 129 | GNUNET_DATACACHE_put (h, |
108 | &k, | 130 | &k, |
109 | GNUNET_YES, | 131 | GNUNET_YES, |
110 | sizeof (struct GNUNET_HashCode), | 132 | sizeof (struct GNUNET_HashCode), |
111 | (const char *) &n, 792, | 133 | (const char *) &n, |
134 | 792, | ||
112 | GNUNET_TIME_UNIT_FOREVER_ABS, | 135 | GNUNET_TIME_UNIT_FOREVER_ABS, |
113 | 0, NULL)); | 136 | 0, |
114 | ASSERT (0 != GNUNET_DATACACHE_get (h, &k, 792, &checkIt, &n)); | 137 | NULL)); |
115 | 138 | ASSERT (0 != GNUNET_DATACACHE_get (h, | |
139 | &k, | ||
140 | 792, | ||
141 | &checkIt, | ||
142 | &n)); | ||
116 | GNUNET_DATACACHE_destroy (h); | 143 | GNUNET_DATACACHE_destroy (h); |
117 | ASSERT (ok == 0); | 144 | ASSERT (ok == 0); |
118 | return; | 145 | return; |
@@ -137,16 +164,26 @@ main (int argc, char *argv[]) | |||
137 | GNUNET_GETOPT_OPTION_END | 164 | GNUNET_GETOPT_OPTION_END |
138 | }; | 165 | }; |
139 | 166 | ||
167 | (void) argc; | ||
140 | GNUNET_log_setup ("test-datacache", | 168 | GNUNET_log_setup ("test-datacache", |
141 | "WARNING", | 169 | "WARNING", |
142 | NULL); | 170 | NULL); |
143 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 171 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); |
144 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datacache_data_%s.conf", | 172 | GNUNET_snprintf (cfg_name, |
173 | sizeof (cfg_name), | ||
174 | "test_datacache_data_%s.conf", | ||
145 | plugin_name); | 175 | plugin_name); |
146 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, | 176 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, |
147 | "test-datacache", "nohelp", options, &run, NULL); | 177 | xargv, |
178 | "test-datacache", | ||
179 | "nohelp", | ||
180 | options, | ||
181 | &run, | ||
182 | NULL); | ||
148 | if ( (0 != ok) && (77 != ok) ) | 183 | if ( (0 != ok) && (77 != ok) ) |
149 | FPRINTF (stderr, "Missed some testcases: %d\n", ok); | 184 | FPRINTF (stderr, |
185 | "Missed some testcases: %d\n", | ||
186 | ok); | ||
150 | return ok; | 187 | return ok; |
151 | } | 188 | } |
152 | 189 | ||