aboutsummaryrefslogtreecommitdiff
path: root/src/service/peerstore/test_peerstore_api_iterate.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/peerstore/test_peerstore_api_iterate.c')
-rw-r--r--src/service/peerstore/test_peerstore_api_iterate.c84
1 files changed, 56 insertions, 28 deletions
diff --git a/src/service/peerstore/test_peerstore_api_iterate.c b/src/service/peerstore/test_peerstore_api_iterate.c
index 59367a110..0fa58f3fd 100644
--- a/src/service/peerstore/test_peerstore_api_iterate.c
+++ b/src/service/peerstore/test_peerstore_api_iterate.c
@@ -21,6 +21,7 @@
21 * @file peerstore/test_peerstore_api_iterate.c 21 * @file peerstore/test_peerstore_api_iterate.c
22 * @brief testcase for peerstore iteration operation 22 * @brief testcase for peerstore iteration operation
23 */ 23 */
24#include "gnunet_common.h"
24#include "platform.h" 25#include "platform.h"
25#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
26#include "gnunet_testing_lib.h" 27#include "gnunet_testing_lib.h"
@@ -40,6 +41,13 @@ static char *k3 = "test_peerstore_api_iterate_key3";
40static char *val = "test_peerstore_api_iterate_val"; 41static char *val = "test_peerstore_api_iterate_val";
41static int count = 0; 42static int count = 0;
42 43
44static void
45finish (void *cls)
46{
47 GNUNET_PEERSTORE_disconnect (h);
48 GNUNET_SCHEDULER_shutdown ();
49}
50
43 51
44static void 52static void
45iter3_cb (void *cls, 53iter3_cb (void *cls,
@@ -58,8 +66,7 @@ iter3_cb (void *cls,
58 } 66 }
59 GNUNET_assert (count == 3); 67 GNUNET_assert (count == 3);
60 ok = 0; 68 ok = 0;
61 GNUNET_PEERSTORE_disconnect (h); 69 GNUNET_SCHEDULER_add_now (&finish, NULL);
62 GNUNET_SCHEDULER_shutdown ();
63} 70}
64 71
65 72
@@ -104,6 +111,7 @@ iter1_cb (void *cls,
104 count++; 111 count++;
105 return; 112 return;
106 } 113 }
114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u is count\n", count);
107 GNUNET_assert (count == 1); 115 GNUNET_assert (count == 1);
108 count = 0; 116 count = 0;
109 ic = GNUNET_PEERSTORE_iterate (h, 117 ic = GNUNET_PEERSTORE_iterate (h,
@@ -116,6 +124,50 @@ iter1_cb (void *cls,
116 124
117 125
118static void 126static void
127store_cont (void *cls, int success)
128{
129 GNUNET_assert (GNUNET_OK == success);
130 if (0 == count)
131 {
132 GNUNET_PEERSTORE_store (h,
133 ss,
134 &p1,
135 k2,
136 val,
137 strlen (val) + 1,
138 GNUNET_TIME_UNIT_FOREVER_ABS,
139 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
140 &store_cont,
141 NULL);
142 }
143 else if (1 == count)
144 {
145 GNUNET_PEERSTORE_store (h,
146 ss,
147 &p2,
148 k3,
149 val,
150 strlen (val) + 1,
151 GNUNET_TIME_UNIT_FOREVER_ABS,
152 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
153 &store_cont,
154 NULL);
155 }
156 else
157 {
158 count = 0;
159 ic = GNUNET_PEERSTORE_iterate (h,
160 ss,
161 &p1,
162 k1,
163 &iter1_cb, NULL);
164 return;
165 }
166 count++;
167}
168
169
170static void
119run (void *cls, 171run (void *cls,
120 const struct GNUNET_CONFIGURATION_Handle *cfg, 172 const struct GNUNET_CONFIGURATION_Handle *cfg,
121 struct GNUNET_TESTING_Peer *peer) 173 struct GNUNET_TESTING_Peer *peer)
@@ -124,6 +176,7 @@ run (void *cls,
124 GNUNET_assert (NULL != h); 176 GNUNET_assert (NULL != h);
125 memset (&p1, 1, sizeof(p1)); 177 memset (&p1, 1, sizeof(p1));
126 memset (&p2, 2, sizeof(p2)); 178 memset (&p2, 2, sizeof(p2));
179 count = 0;
127 GNUNET_PEERSTORE_store (h, 180 GNUNET_PEERSTORE_store (h,
128 ss, 181 ss,
129 &p1, 182 &p1,
@@ -132,33 +185,8 @@ run (void *cls,
132 strlen (val) + 1, 185 strlen (val) + 1,
133 GNUNET_TIME_UNIT_FOREVER_ABS, 186 GNUNET_TIME_UNIT_FOREVER_ABS,
134 GNUNET_PEERSTORE_STOREOPTION_REPLACE, 187 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
135 NULL, 188 &store_cont,
136 NULL);
137 GNUNET_PEERSTORE_store (h,
138 ss,
139 &p1,
140 k2,
141 val,
142 strlen (val) + 1,
143 GNUNET_TIME_UNIT_FOREVER_ABS,
144 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
145 NULL,
146 NULL); 189 NULL);
147 GNUNET_PEERSTORE_store (h,
148 ss,
149 &p2,
150 k3,
151 val,
152 strlen (val) + 1,
153 GNUNET_TIME_UNIT_FOREVER_ABS,
154 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
155 NULL,
156 NULL);
157 ic = GNUNET_PEERSTORE_iterate (h,
158 ss,
159 &p1,
160 k1,
161 &iter1_cb, NULL);
162} 190}
163 191
164 192