aboutsummaryrefslogtreecommitdiff
path: root/src/pq/test_pq.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pq/test_pq.c')
-rw-r--r--src/pq/test_pq.c108
1 files changed, 107 insertions, 1 deletions
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c
index a6354c7c0..c97474814 100644
--- a/src/pq/test_pq.c
+++ b/src/pq/test_pq.c
@@ -23,6 +23,7 @@
23 * @author Christian Grothoff <christian@grothoff.org> 23 * @author Christian Grothoff <christian@grothoff.org>
24 */ 24 */
25#include "gnunet_common.h" 25#include "gnunet_common.h"
26#include "gnunet_pq_lib.h"
26#include "gnunet_time_lib.h" 27#include "gnunet_time_lib.h"
27#include "platform.h" 28#include "platform.h"
28#include "pq.h" 29#include "pq.h"
@@ -154,7 +155,7 @@ run_queries (struct GNUNET_PQ_Context *db)
154 uint16_t ai2[3] = {42, 0x0001, 0xFFFF}; 155 uint16_t ai2[3] = {42, 0x0001, 0xFFFF};
155 uint32_t ai4[3] = {42, 0x00010000, 0xFFFFFFFF}; 156 uint32_t ai4[3] = {42, 0x00010000, 0xFFFFFFFF};
156 uint64_t ai8[3] = {42, 0x0001000000000000, 0xFFFFFFFFFFFFFFFF}; 157 uint64_t ai8[3] = {42, 0x0001000000000000, 0xFFFFFFFFFFFFFFFF};
157 const char *as[] = {"foo", "bar", "buz"}; 158 const char *as[] = {"foo", "bar", "buzz"};
158 const struct GNUNET_TIME_Absolute ata[2] = {GNUNET_TIME_absolute_get (), 159 const struct GNUNET_TIME_Absolute ata[2] = {GNUNET_TIME_absolute_get (),
159 GNUNET_TIME_absolute_get ()}; 160 GNUNET_TIME_absolute_get ()};
160 const struct GNUNET_TIME_Relative atr[2] = {GNUNET_TIME_relative_get_hour_ (), 161 const struct GNUNET_TIME_Relative atr[2] = {GNUNET_TIME_relative_get_hour_ (),
@@ -208,6 +209,27 @@ run_queries (struct GNUNET_PQ_Context *db)
208 GNUNET_PQ_query_param_end 209 GNUNET_PQ_query_param_end
209 }; 210 };
210 bool got_null = false; 211 bool got_null = false;
212 size_t num_bool;
213 bool *arr_bools;
214 size_t num_u16;
215 uint16_t *arr_u16;
216 size_t num_u32;
217 uint32_t *arr_u32;
218 size_t num_u64;
219 uint64_t *arr_u64;
220 size_t num_abs;
221 struct GNUNET_TIME_Absolute *arr_abs;
222 size_t num_rel;
223 struct GNUNET_TIME_Relative *arr_rel;
224 size_t num_tstmp;
225 struct GNUNET_TIME_Timestamp *arr_tstmp;
226 size_t num_str;
227 char *arr_str;
228 size_t num_hash;
229 struct GNUNET_HashCode *arr_hash;
230 size_t num_buf;
231 void *arr_buf;
232 size_t *sz_buf;
211 struct GNUNET_PQ_ResultSpec results_select[] = { 233 struct GNUNET_PQ_ResultSpec results_select[] = {
212 GNUNET_PQ_result_spec_rsa_public_key ("pub", &pub2), 234 GNUNET_PQ_result_spec_rsa_public_key ("pub", &pub2),
213 GNUNET_PQ_result_spec_rsa_signature ("sig", &sig2), 235 GNUNET_PQ_result_spec_rsa_signature ("sig", &sig2),
@@ -221,6 +243,47 @@ run_queries (struct GNUNET_PQ_Context *db)
221 GNUNET_PQ_result_spec_allow_null ( 243 GNUNET_PQ_result_spec_allow_null (
222 GNUNET_PQ_result_spec_uint64 ("unn", &uzzz), 244 GNUNET_PQ_result_spec_uint64 ("unn", &uzzz),
223 &got_null), 245 &got_null),
246 GNUNET_PQ_result_spec_array_bool (db,
247 "arr_bool",
248 &num_bool,
249 &arr_bools),
250 GNUNET_PQ_result_spec_array_uint16 (db,
251 "arr_int2",
252 &num_u16,
253 &arr_u16),
254 GNUNET_PQ_result_spec_array_uint32 (db,
255 "arr_int4",
256 &num_u32,
257 &arr_u32),
258 GNUNET_PQ_result_spec_array_uint64 (db,
259 "arr_int8",
260 &num_u64,
261 &arr_u64),
262 GNUNET_PQ_result_spec_array_abs_time (db,
263 "arr_abs_time",
264 &num_abs,
265 &arr_abs),
266 GNUNET_PQ_result_spec_array_rel_time (db,
267 "arr_rel_time",
268 &num_rel,
269 &arr_rel),
270 GNUNET_PQ_result_spec_array_timestamp (db,
271 "arr_timestamp",
272 &num_tstmp,
273 &arr_tstmp),
274 GNUNET_PQ_result_spec_auto_array_from_type (db,
275 "arr_bytea",
276 &num_hash,
277 arr_hash),
278 GNUNET_PQ_result_spec_array_variable_size (db,
279 "arr_bytea",
280 &num_buf,
281 &sz_buf,
282 &arr_buf),
283 GNUNET_PQ_result_spec_array_string (db,
284 "arr_varchar",
285 &num_str,
286 &arr_str),
224 GNUNET_PQ_result_spec_end 287 GNUNET_PQ_result_spec_end
225 }; 288 };
226 289
@@ -278,6 +341,49 @@ run_queries (struct GNUNET_PQ_Context *db)
278 GNUNET_break (64 == u642); 341 GNUNET_break (64 == u642);
279 GNUNET_break (42 == uzzz); 342 GNUNET_break (42 == uzzz);
280 GNUNET_break (got_null); 343 GNUNET_break (got_null);
344
345 /* Check arrays */
346 {
347 GNUNET_break (num_bool == 5);
348 GNUNET_break (arr_bools[0]);
349 GNUNET_break (! arr_bools[1]);
350 GNUNET_break (! arr_bools[2]);
351 GNUNET_break (arr_bools[3]);
352 GNUNET_break (! arr_bools[4]);
353
354 GNUNET_break (num_u16 == 3);
355 GNUNET_break (arr_u16[0] == 42);
356 GNUNET_break (arr_u16[1] == 0x0001);
357 GNUNET_break (arr_u16[2] == 0xFFFF);
358
359 GNUNET_break (num_u32 == 3);
360 GNUNET_break (arr_u32[0] == 42);
361 GNUNET_break (arr_u32[1] == 0x00010000);
362 GNUNET_break (arr_u32[2] == 0xFFFFFFFF);
363
364 GNUNET_break (num_u64 == 3);
365 GNUNET_break (arr_u64[0] == 42);
366 GNUNET_break (arr_u64[1] == 0x0001000000000000);
367 GNUNET_break (arr_u64[2] == 0xFFFFFFFFFFFFFFFF);
368
369 GNUNET_break (num_str == 3);
370 GNUNET_break (0 == strcmp (arr_str, "foo"));
371 GNUNET_break (0 == strcmp (arr_str + 4, "bar"));
372 GNUNET_break (0 == strcmp (arr_str + 8, "buzz"));
373
374 GNUNET_break (num_hash == 3);
375 GNUNET_break (0 == GNUNET_memcmp (&arr_hash[0], &arr_hash[1]));
376 GNUNET_break (0 == GNUNET_memcmp (&arr_hash[1], &arr_hash[2]));
377
378 GNUNET_break (num_buf == 3);
379 {
380 char *ptr = arr_buf;
381 GNUNET_break (0 == memcmp (ptr, &ptr[sz_buf[0]], sz_buf[0]));
382 ptr += sz_buf[0];
383 GNUNET_break (0 == memcmp (ptr, &ptr[sz_buf[1]], sz_buf[1]));
384 }
385 }
386
281 GNUNET_PQ_cleanup_result (results_select); 387 GNUNET_PQ_cleanup_result (results_select);
282 PQclear (result); 388 PQclear (result);
283 389