aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2023-06-02 16:51:39 +0200
committerÖzgür Kesim <oec-taler@kesim.org>2023-06-02 16:51:39 +0200
commitaac3e643d17fa7a0cc336faf4286bbbeba2f3eac (patch)
tree90eaab563687c2bf14efc08de84c9795a99bc87a
parent212b47afc212d613d6c8378b61c3a085e1495ab1 (diff)
downloadgnunet-aac3e643d17fa7a0cc336faf4286bbbeba2f3eac.tar.gz
gnunet-aac3e643d17fa7a0cc336faf4286bbbeba2f3eac.zip
pq: better tests for array specs
-rw-r--r--src/pq/test_pq.c90
1 files changed, 47 insertions, 43 deletions
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c
index c97474814..7188b9b8e 100644
--- a/src/pq/test_pq.c
+++ b/src/pq/test_pq.c
@@ -172,11 +172,10 @@ run_queries (struct GNUNET_PQ_Context *db)
172 u16 = 16; 172 u16 = 16;
173 u32 = 32; 173 u32 = 32;
174 u64 = 64; 174 u64 = 64;
175 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, 175 for (int i = 0; i < 3; i++)
176 &ahc[0], 176 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
177 sizeof(ahc[0])); 177 &ahc[i],
178 GNUNET_memcpy (&ahc[1], &ahc[0], sizeof(ahc[0])); 178 sizeof(ahc[i]));
179 GNUNET_memcpy (&ahc[2], &ahc[0], sizeof(ahc[0]));
180 179
181 /* FIXME: test GNUNET_PQ_result_spec_variable_size */ 180 /* FIXME: test GNUNET_PQ_result_spec_variable_size */
182 { 181 {
@@ -343,45 +342,50 @@ run_queries (struct GNUNET_PQ_Context *db)
343 GNUNET_break (got_null); 342 GNUNET_break (got_null);
344 343
345 /* Check arrays */ 344 /* Check arrays */
345 GNUNET_break (num_bool == 5);
346 for (size_t i = 0; i < num_bool; i++)
347 GNUNET_break (arr_bools[i] == ab[i]);
348
349 GNUNET_break (num_u16 == 3);
350 for (size_t i = 0; i < num_u16; i++)
351 GNUNET_break (arr_u16[i] == ai2[i]);
352
353 GNUNET_break (num_u32 == 3);
354 for (size_t i = 0; i < num_u32; i++)
355 GNUNET_break (arr_u32[i] == ai4[i]);
356
357 GNUNET_break (num_u64 == 3);
358 for (size_t i = 0; i < num_u64; i++)
359 GNUNET_break (arr_u64[i] == ai8[i]);
360
361 GNUNET_break (num_abs == 2);
362 for (size_t i = 0; i < num_abs; i++)
363 GNUNET_break (arr_abs[i].abs_value_us == ata[i].abs_value_us);
364
365 GNUNET_break (num_rel == 2);
366 for (size_t i = 0; i < num_rel; i++)
367 GNUNET_break (arr_rel[i].rel_value_us == atr[i].rel_value_us);
368
369 GNUNET_break (num_tstmp == 2);
370 for (size_t i = 0; i < num_tstmp; i++)
371 GNUNET_break (arr_tstmp[i].abs_time.abs_value_us ==
372 ats[i].abs_time.abs_value_us);
373
374 GNUNET_break (num_str == 3);
375 GNUNET_break (0 == strcmp (arr_str, as[0]));
376 GNUNET_break (0 == strcmp (arr_str + 4, as[1]));
377 GNUNET_break (0 == strcmp (arr_str + 8, as[2]));
378
379 GNUNET_break (num_hash == 3);
380 for (size_t i = 0; i < num_hash; i++)
381 GNUNET_break (0 == GNUNET_memcmp (&arr_hash[i], &ahc[i]));
382
383 GNUNET_break (num_buf == 3);
384 for (size_t i = 0; i < num_buf; i++)
346 { 385 {
347 GNUNET_break (num_bool == 5); 386 GNUNET_break (0 == memcmp (((char *) arr_buf) + i * sizeof(ahc[i]),
348 GNUNET_break (arr_bools[0]); 387 &ahc[i],
349 GNUNET_break (! arr_bools[1]); 388 sizeof(ahc[i])));
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 } 389 }
386 390
387 GNUNET_PQ_cleanup_result (results_select); 391 GNUNET_PQ_cleanup_result (results_select);