aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore/test_peerstore_api_store.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/peerstore/test_peerstore_api_store.c')
-rw-r--r--src/peerstore/test_peerstore_api_store.c208
1 files changed, 104 insertions, 104 deletions
diff --git a/src/peerstore/test_peerstore_api_store.c b/src/peerstore/test_peerstore_api_store.c
index cecf13e05..f557aafa5 100644
--- a/src/peerstore/test_peerstore_api_store.c
+++ b/src/peerstore/test_peerstore_api_store.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
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 peerstore/test_peerstore_api_store.c 21 * @file peerstore/test_peerstore_api_store.c
22 * @brief testcase for peerstore store operation 22 * @brief testcase for peerstore store operation
@@ -41,40 +41,40 @@ static int count = 0;
41 41
42 42
43static void 43static void
44test3_cont2 (void *cls, 44test3_cont2(void *cls,
45 const struct GNUNET_PEERSTORE_Record *record, 45 const struct GNUNET_PEERSTORE_Record *record,
46 const char *emsg) 46 const char *emsg)
47{ 47{
48 if (NULL != emsg) 48 if (NULL != emsg)
49 return; 49 return;
50 if (NULL != record) 50 if (NULL != record)
51 { 51 {
52 GNUNET_assert ((strlen (val3) + 1) == record->value_size); 52 GNUNET_assert((strlen(val3) + 1) == record->value_size);
53 GNUNET_assert (0 == strcmp ((char *) val3, 53 GNUNET_assert(0 == strcmp((char *)val3,
54 (char *) record->value)); 54 (char *)record->value));
55 count++; 55 count++;
56 return; 56 return;
57 } 57 }
58 GNUNET_assert (count == 1); 58 GNUNET_assert(count == 1);
59 ok = 0; 59 ok = 0;
60 GNUNET_PEERSTORE_disconnect (h, GNUNET_YES); 60 GNUNET_PEERSTORE_disconnect(h, GNUNET_YES);
61 GNUNET_SCHEDULER_shutdown (); 61 GNUNET_SCHEDULER_shutdown();
62} 62}
63 63
64 64
65static void 65static void
66test3_cont (void *cls, 66test3_cont(void *cls,
67 int success) 67 int success)
68{ 68{
69 if (GNUNET_YES != success) 69 if (GNUNET_YES != success)
70 return; 70 return;
71 count = 0; 71 count = 0;
72 GNUNET_PEERSTORE_iterate (h, 72 GNUNET_PEERSTORE_iterate(h,
73 subsystem, 73 subsystem,
74 &pid, 74 &pid,
75 key, 75 key,
76 &test3_cont2, 76 &test3_cont2,
77 NULL); 77 NULL);
78} 78}
79 79
80 80
@@ -82,54 +82,54 @@ test3_cont (void *cls,
82 * Replace the previous 2 records 82 * Replace the previous 2 records
83 */ 83 */
84static void 84static void
85test3 () 85test3()
86{ 86{
87 GNUNET_PEERSTORE_store (h, 87 GNUNET_PEERSTORE_store(h,
88 subsystem, 88 subsystem,
89 &pid, 89 &pid,
90 key, 90 key,
91 val3, 91 val3,
92 strlen (val3) + 1, 92 strlen(val3) + 1,
93 GNUNET_TIME_UNIT_FOREVER_ABS, 93 GNUNET_TIME_UNIT_FOREVER_ABS,
94 GNUNET_PEERSTORE_STOREOPTION_REPLACE, 94 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
95 &test3_cont, 95 &test3_cont,
96 NULL); 96 NULL);
97} 97}
98 98
99 99
100static void 100static void
101test2_cont2 (void *cls, 101test2_cont2(void *cls,
102 const struct GNUNET_PEERSTORE_Record *record, 102 const struct GNUNET_PEERSTORE_Record *record,
103 const char *emsg) 103 const char *emsg)
104{ 104{
105 if (NULL != emsg) 105 if (NULL != emsg)
106 return; 106 return;
107 if (NULL != record) 107 if (NULL != record)
108 { 108 {
109 GNUNET_assert (((strlen (val1) + 1) == record->value_size) || 109 GNUNET_assert(((strlen(val1) + 1) == record->value_size) ||
110 ((strlen (val2) + 1) == record->value_size)); 110 ((strlen(val2) + 1) == record->value_size));
111 GNUNET_assert ((0 == strcmp ((char *) val1, (char *) record->value)) || 111 GNUNET_assert((0 == strcmp((char *)val1, (char *)record->value)) ||
112 (0 == strcmp ((char *) val2, (char *) record->value))); 112 (0 == strcmp((char *)val2, (char *)record->value)));
113 count++; 113 count++;
114 return; 114 return;
115 } 115 }
116 GNUNET_assert (count == 2); 116 GNUNET_assert(count == 2);
117 count = 0; 117 count = 0;
118 test3 (); 118 test3();
119} 119}
120 120
121 121
122static void 122static void
123test2_cont (void *cls, int success) 123test2_cont(void *cls, int success)
124{ 124{
125 if (GNUNET_YES != success) 125 if (GNUNET_YES != success)
126 return; 126 return;
127 count = 0; 127 count = 0;
128 GNUNET_PEERSTORE_iterate (h, 128 GNUNET_PEERSTORE_iterate(h,
129 subsystem, 129 subsystem,
130 &pid, key, 130 &pid, key,
131 &test2_cont2, 131 &test2_cont2,
132 NULL); 132 NULL);
133} 133}
134 134
135 135
@@ -137,53 +137,53 @@ test2_cont (void *cls, int success)
137 * Test storing a second value with the same key 137 * Test storing a second value with the same key
138 */ 138 */
139void 139void
140test2 () 140test2()
141{ 141{
142 GNUNET_PEERSTORE_store (h, 142 GNUNET_PEERSTORE_store(h,
143 subsystem, 143 subsystem,
144 &pid, 144 &pid,
145 key, 145 key,
146 val2, 146 val2,
147 strlen (val2) + 1, 147 strlen(val2) + 1,
148 GNUNET_TIME_UNIT_FOREVER_ABS, 148 GNUNET_TIME_UNIT_FOREVER_ABS,
149 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, 149 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
150 &test2_cont, 150 &test2_cont,
151 NULL); 151 NULL);
152} 152}
153 153
154 154
155static void 155static void
156test1_cont2 (void *cls, 156test1_cont2(void *cls,
157 const struct GNUNET_PEERSTORE_Record *record, 157 const struct GNUNET_PEERSTORE_Record *record,
158 const char *emsg) 158 const char *emsg)
159{ 159{
160 if (NULL != emsg) 160 if (NULL != emsg)
161 return; 161 return;
162 if (NULL != record) 162 if (NULL != record)
163 { 163 {
164 GNUNET_assert ((strlen (val1) + 1) == record->value_size); 164 GNUNET_assert((strlen(val1) + 1) == record->value_size);
165 GNUNET_assert (0 == strcmp ((char *) val1, (char *) record->value)); 165 GNUNET_assert(0 == strcmp((char *)val1, (char *)record->value));
166 count++; 166 count++;
167 return; 167 return;
168 } 168 }
169 GNUNET_assert (count == 1); 169 GNUNET_assert(count == 1);
170 count = 0; 170 count = 0;
171 test2 (); 171 test2();
172} 172}
173 173
174 174
175static void 175static void
176test1_cont (void *cls, int success) 176test1_cont(void *cls, int success)
177{ 177{
178 if (GNUNET_YES != success) 178 if (GNUNET_YES != success)
179 return; 179 return;
180 count = 0; 180 count = 0;
181 GNUNET_PEERSTORE_iterate (h, 181 GNUNET_PEERSTORE_iterate(h,
182 subsystem, 182 subsystem,
183 &pid, 183 &pid,
184 key, 184 key,
185 &test1_cont2, 185 &test1_cont2,
186 NULL); 186 NULL);
187} 187}
188 188
189 189
@@ -191,40 +191,40 @@ test1_cont (void *cls, int success)
191 * Store a single record 191 * Store a single record
192 */ 192 */
193static void 193static void
194test1 () 194test1()
195{ 195{
196 GNUNET_PEERSTORE_store (h, 196 GNUNET_PEERSTORE_store(h,
197 subsystem, 197 subsystem,
198 &pid, 198 &pid,
199 key, 199 key,
200 val1, 200 val1,
201 strlen (val1) + 1, 201 strlen(val1) + 1,
202 GNUNET_TIME_UNIT_FOREVER_ABS, 202 GNUNET_TIME_UNIT_FOREVER_ABS,
203 GNUNET_PEERSTORE_STOREOPTION_REPLACE, 203 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
204 &test1_cont, 204 &test1_cont,
205 NULL); 205 NULL);
206} 206}
207 207
208 208
209static void 209static void
210run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, 210run(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
211 struct GNUNET_TESTING_Peer *peer) 211 struct GNUNET_TESTING_Peer *peer)
212{ 212{
213 h = GNUNET_PEERSTORE_connect (cfg); 213 h = GNUNET_PEERSTORE_connect(cfg);
214 GNUNET_assert (NULL != h); 214 GNUNET_assert(NULL != h);
215 memset (&pid, 1, sizeof (pid)); 215 memset(&pid, 1, sizeof(pid));
216 test1 (); 216 test1();
217} 217}
218 218
219 219
220int 220int
221main (int argc, char *argv[]) 221main(int argc, char *argv[])
222{ 222{
223 if (0 != 223 if (0 !=
224 GNUNET_TESTING_service_run ("test-gnunet-peerstore", 224 GNUNET_TESTING_service_run("test-gnunet-peerstore",
225 "peerstore", 225 "peerstore",
226 "test_peerstore_api_data.conf", 226 "test_peerstore_api_data.conf",
227 &run, NULL)) 227 &run, NULL))
228 return 1; 228 return 1;
229 return ok; 229 return ok;
230} 230}