diff options
Diffstat (limited to 'src/pq/test_pq.c')
-rw-r--r-- | src/pq/test_pq.c | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c index e588da45d..b3747dfc3 100644 --- a/src/pq/test_pq.c +++ b/src/pq/test_pq.c | |||
@@ -220,6 +220,64 @@ run_queries (struct GNUNET_PQ_Context *db) | |||
220 | } | 220 | } |
221 | 221 | ||
222 | 222 | ||
223 | static void | ||
224 | event_cb (void *cls, | ||
225 | const void *extra, | ||
226 | size_t extra_size) | ||
227 | { | ||
228 | unsigned int *cnt = cls; | ||
229 | |||
230 | GNUNET_assert (5 == extra_size); | ||
231 | GNUNET_assert (0 == memcmp ("world", | ||
232 | extra, | ||
233 | 5)); | ||
234 | (*cnt)++; | ||
235 | } | ||
236 | |||
237 | |||
238 | /** | ||
239 | * Run subscribe/notify tests. | ||
240 | * | ||
241 | * @param db database handle | ||
242 | * @return 0 on success | ||
243 | */ | ||
244 | static int | ||
245 | test_notify (struct GNUNET_PQ_Context *db) | ||
246 | { | ||
247 | struct GNUNET_PQ_EventHeaderP e1 = { | ||
248 | .size = htons (sizeof (e1)), | ||
249 | .type = htons (1) | ||
250 | }; | ||
251 | struct GNUNET_PQ_EventHeaderP e2 = { | ||
252 | .size = htons (sizeof (e2)), | ||
253 | .type = htons (2) | ||
254 | }; | ||
255 | unsigned int called = 0; | ||
256 | struct GNUNET_PQ_EventHandler *eh; | ||
257 | |||
258 | eh = GNUNET_PQ_event_listen (db, | ||
259 | &e1, | ||
260 | &event_cb, | ||
261 | &called); | ||
262 | GNUNET_assert (NULL != eh); | ||
263 | GNUNET_PQ_event_notify (db, | ||
264 | &e2, | ||
265 | "hello", | ||
266 | 5); | ||
267 | GNUNET_PQ_event_do_poll (db); | ||
268 | GNUNET_assert (0 == called); | ||
269 | GNUNET_PQ_event_notify (db, | ||
270 | &e1, | ||
271 | "world", | ||
272 | 5); | ||
273 | GNUNET_PQ_event_do_poll (db); | ||
274 | GNUNET_assert (1 == called); | ||
275 | GNUNET_PQ_event_listen_cancel (eh); | ||
276 | return 0; | ||
277 | } | ||
278 | |||
279 | |||
280 | |||
223 | int | 281 | int |
224 | main (int argc, | 282 | main (int argc, |
225 | const char *const argv[]) | 283 | const char *const argv[]) |
@@ -272,12 +330,14 @@ main (int argc, | |||
272 | return 1; | 330 | return 1; |
273 | } | 331 | } |
274 | ret = run_queries (db); | 332 | ret = run_queries (db); |
333 | ret |= test_notify (db); | ||
334 | ret |= test_notify (db); | ||
275 | #if TEST_RESTART | 335 | #if TEST_RESTART |
276 | fprintf (stderr, "Please restart Postgres database now!\n"); | 336 | fprintf (stderr, "Please restart Postgres database now!\n"); |
277 | sleep (60); | 337 | sleep (60); |
278 | ret = run_queries (db); | 338 | ret |= run_queries (db); |
279 | fprintf (stderr, "Result: %d (expect: 1 -- if you restarted the DB)\n", ret); | 339 | fprintf (stderr, "Result: %d (expect: 1 -- if you restarted the DB)\n", ret); |
280 | ret = run_queries (db); | 340 | ret |= run_queries (db); |
281 | fprintf (stderr, "Result: %d (expect: 0)\n", ret); | 341 | fprintf (stderr, "Result: %d (expect: 0)\n", ret); |
282 | #endif | 342 | #endif |
283 | { | 343 | { |