2 This file is part of GNUnet.
3 Copyright (C) 2013-2017 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.
16 * @file peerstore/test_peerstore_api_iterate.c
17 * @brief testcase for peerstore iteration operation
20 #include "gnunet_util_lib.h"
21 #include "gnunet_testing_lib.h"
22 #include "gnunet_peerstore_service.h"
26 static struct GNUNET_PEERSTORE_Handle *h;
27 static struct GNUNET_PEERSTORE_IterateContext *ic;
29 static char *ss = "test_peerstore_api_iterate";
30 static struct GNUNET_PeerIdentity p1;
31 static struct GNUNET_PeerIdentity p2;
32 static char *k1 = "test_peerstore_api_iterate_key1";
33 static char *k2 = "test_peerstore_api_iterate_key2";
34 static char *k3 = "test_peerstore_api_iterate_key3";
35 static char *val = "test_peerstore_api_iterate_val";
41 const struct GNUNET_PEERSTORE_Record *record,
46 GNUNET_PEERSTORE_iterate_cancel (ic);
54 GNUNET_assert (count == 3);
56 GNUNET_PEERSTORE_disconnect (h, GNUNET_NO);
57 GNUNET_SCHEDULER_shutdown ();
63 const struct GNUNET_PEERSTORE_Record *record,
68 GNUNET_PEERSTORE_iterate_cancel (ic);
76 GNUNET_assert (count == 2);
78 ic = GNUNET_PEERSTORE_iterate (h,
82 GNUNET_TIME_UNIT_FOREVER_REL,
90 const struct GNUNET_PEERSTORE_Record *record,
95 GNUNET_PEERSTORE_iterate_cancel (ic);
103 GNUNET_assert (count == 1);
105 ic = GNUNET_PEERSTORE_iterate (h,
109 GNUNET_TIME_UNIT_FOREVER_REL,
117 const struct GNUNET_CONFIGURATION_Handle *cfg,
118 struct GNUNET_TESTING_Peer *peer)
120 h = GNUNET_PEERSTORE_connect (cfg);
121 GNUNET_assert (NULL != h);
122 memset (&p1, 1, sizeof (p1));
123 memset (&p2, 2, sizeof (p2));
124 GNUNET_PEERSTORE_store (h,
130 GNUNET_TIME_UNIT_FOREVER_ABS,
131 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
134 GNUNET_PEERSTORE_store (h,
140 GNUNET_TIME_UNIT_FOREVER_ABS,
141 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
144 GNUNET_PEERSTORE_store (h,
150 GNUNET_TIME_UNIT_FOREVER_ABS,
151 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
154 ic = GNUNET_PEERSTORE_iterate (h,
158 GNUNET_TIME_UNIT_FOREVER_REL,
164 main (int argc, char *argv[])
167 GNUNET_TESTING_service_run ("test-gnunet-peerstore", "peerstore",
168 "test_peerstore_api_data.conf", &run, NULL))
173 /* end of test_peerstore_api_iterate.c */