diff options
Diffstat (limited to 'src/util/test_bio.c')
-rw-r--r-- | src/util/test_bio.c | 142 |
1 files changed, 3 insertions, 139 deletions
diff --git a/src/util/test_bio.c b/src/util/test_bio.c index f18014719..90f0121d4 100644 --- a/src/util/test_bio.c +++ b/src/util/test_bio.c | |||
@@ -25,6 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | 26 | ||
27 | 27 | ||
28 | |||
28 | #include "platform.h" | 29 | #include "platform.h" |
29 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
30 | #define TESTSTRING "testString" | 31 | #define TESTSTRING "testString" |
@@ -39,25 +40,18 @@ test_normal_rw (void) | |||
39 | void *buffer; | 40 | void *buffer; |
40 | size_t buffer_size = 0; | 41 | size_t buffer_size = 0; |
41 | char *filename = GNUNET_DISK_mktemp ("gnunet-bio"); | 42 | char *filename = GNUNET_DISK_mktemp ("gnunet-bio"); |
42 | struct GNUNET_CONTAINER_MetaData *mdW; | ||
43 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; | ||
44 | char *rString = NULL; | 43 | char *rString = NULL; |
45 | int64_t wNum = TESTNUMBER64; | 44 | int64_t wNum = TESTNUMBER64; |
46 | int64_t rNum = 0; | 45 | int64_t rNum = 0; |
47 | 46 | ||
48 | mdW = GNUNET_CONTAINER_meta_data_create (); | ||
49 | GNUNET_CONTAINER_meta_data_add_publication_date (mdW); | ||
50 | |||
51 | struct GNUNET_BIO_WriteSpec ws[] = { | 47 | struct GNUNET_BIO_WriteSpec ws[] = { |
52 | GNUNET_BIO_write_spec_string ("test-normal-rw-string", TESTSTRING), | 48 | GNUNET_BIO_write_spec_string ("test-normal-rw-string", TESTSTRING), |
53 | GNUNET_BIO_write_spec_meta_data ("test-normal-rw-metadata", mdW), | ||
54 | GNUNET_BIO_write_spec_int64 ("test-normal-rw-int64", &wNum), | 49 | GNUNET_BIO_write_spec_int64 ("test-normal-rw-int64", &wNum), |
55 | GNUNET_BIO_write_spec_end (), | 50 | GNUNET_BIO_write_spec_end (), |
56 | }; | 51 | }; |
57 | 52 | ||
58 | struct GNUNET_BIO_ReadSpec rs[] = { | 53 | struct GNUNET_BIO_ReadSpec rs[] = { |
59 | GNUNET_BIO_read_spec_string ("test-normal-rw-string", &rString, 200), | 54 | GNUNET_BIO_read_spec_string ("test-normal-rw-string", &rString, 200), |
60 | GNUNET_BIO_read_spec_meta_data ("test-normal-rw-metadata", &mdR), | ||
61 | GNUNET_BIO_read_spec_int64 ("test-normal-rw-int64", &rNum), | 55 | GNUNET_BIO_read_spec_int64 ("test-normal-rw-int64", &rNum), |
62 | GNUNET_BIO_read_spec_end (), | 56 | GNUNET_BIO_read_spec_end (), |
63 | }; | 57 | }; |
@@ -73,11 +67,8 @@ test_normal_rw (void) | |||
73 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs)); | 67 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs)); |
74 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); | 68 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); |
75 | GNUNET_assert (0 == strcmp (TESTSTRING, rString)); | 69 | GNUNET_assert (0 == strcmp (TESTSTRING, rString)); |
76 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_meta_data_test_equal (mdR, | ||
77 | mdW)); | ||
78 | GNUNET_assert (wNum == rNum); | 70 | GNUNET_assert (wNum == rNum); |
79 | 71 | ||
80 | GNUNET_CONTAINER_meta_data_destroy (mdR); | ||
81 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | 72 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); |
82 | GNUNET_free (filename); | 73 | GNUNET_free (filename); |
83 | 74 | ||
@@ -97,14 +88,10 @@ test_normal_rw (void) | |||
97 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs)); | 88 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs)); |
98 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); | 89 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); |
99 | GNUNET_assert (0 == strcmp (TESTSTRING, rString)); | 90 | GNUNET_assert (0 == strcmp (TESTSTRING, rString)); |
100 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_meta_data_test_equal (mdR, | ||
101 | mdW)); | ||
102 | GNUNET_assert (wNum == rNum); | 91 | GNUNET_assert (wNum == rNum); |
103 | 92 | ||
104 | GNUNET_free (buffer); | 93 | GNUNET_free (buffer); |
105 | 94 | ||
106 | GNUNET_CONTAINER_meta_data_destroy (mdW); | ||
107 | GNUNET_CONTAINER_meta_data_destroy (mdR); | ||
108 | return 0; | 95 | return 0; |
109 | } | 96 | } |
110 | 97 | ||
@@ -200,45 +187,6 @@ test_bigstring_rw (void) | |||
200 | 187 | ||
201 | 188 | ||
202 | static int | 189 | static int |
203 | test_bigmeta_rw (void) | ||
204 | { | ||
205 | static char meta[1024 * 1024 * 10]; | ||
206 | struct GNUNET_BIO_WriteHandle *wh; | ||
207 | struct GNUNET_BIO_ReadHandle *rh; | ||
208 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); | ||
209 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; | ||
210 | |||
211 | memset (meta, 'b', sizeof (meta)); | ||
212 | meta[sizeof (meta) - 1] = '\0'; | ||
213 | |||
214 | wh = GNUNET_BIO_write_open_file (filename); | ||
215 | GNUNET_assert (NULL != wh); | ||
216 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, | ||
217 | "test-bigmeta-rw-int32", | ||
218 | sizeof (meta))); | ||
219 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write (wh, | ||
220 | "test-bigmeta-rw-bytes", | ||
221 | meta, | ||
222 | sizeof (meta))); | ||
223 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | ||
224 | |||
225 | rh = GNUNET_BIO_read_open_file (filename); | ||
226 | GNUNET_assert (NULL != rh); | ||
227 | GNUNET_assert (GNUNET_SYSERR == | ||
228 | GNUNET_BIO_read_meta_data (rh, | ||
229 | "test-bigmeta-rw-metadata", | ||
230 | &mdR)); | ||
231 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); | ||
232 | |||
233 | GNUNET_assert (NULL == mdR); | ||
234 | |||
235 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
236 | GNUNET_free (filename); | ||
237 | return 0; | ||
238 | } | ||
239 | |||
240 | |||
241 | static int | ||
242 | test_directory_r (void) | 190 | test_directory_r (void) |
243 | { | 191 | { |
244 | #ifdef LINUX | 192 | #ifdef LINUX |
@@ -267,12 +215,12 @@ test_nullfile_rw (void) | |||
267 | memset (filename, 'a', sizeof (filename)); | 215 | memset (filename, 'a', sizeof (filename)); |
268 | filename[sizeof (filename) - 1] = '\0'; | 216 | filename[sizeof (filename) - 1] = '\0'; |
269 | 217 | ||
270 | GNUNET_log_skip (2, GNUNET_NO); | 218 | GNUNET_log_skip (1, GNUNET_NO); |
271 | wh = GNUNET_BIO_write_open_file (filename); | 219 | wh = GNUNET_BIO_write_open_file (filename); |
272 | GNUNET_log_skip (0, GNUNET_YES); | 220 | GNUNET_log_skip (0, GNUNET_YES); |
273 | GNUNET_assert (NULL == wh); | 221 | GNUNET_assert (NULL == wh); |
274 | 222 | ||
275 | GNUNET_log_skip (2, GNUNET_NO); | 223 | GNUNET_log_skip (1, GNUNET_NO); |
276 | rh = GNUNET_BIO_read_open_file (filename); | 224 | rh = GNUNET_BIO_read_open_file (filename); |
277 | GNUNET_log_skip (0, GNUNET_YES); | 225 | GNUNET_log_skip (0, GNUNET_YES); |
278 | GNUNET_assert (NULL == rh); | 226 | GNUNET_assert (NULL == rh); |
@@ -290,11 +238,6 @@ test_fullfile_rw (void) | |||
290 | struct GNUNET_BIO_ReadHandle *rh; | 238 | struct GNUNET_BIO_ReadHandle *rh; |
291 | char *rString = NULL; | 239 | char *rString = NULL; |
292 | char rResult[200]; | 240 | char rResult[200]; |
293 | struct GNUNET_CONTAINER_MetaData *mdW; | ||
294 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; | ||
295 | |||
296 | mdW = GNUNET_CONTAINER_meta_data_create (); | ||
297 | GNUNET_CONTAINER_meta_data_add_publication_date (mdW); | ||
298 | 241 | ||
299 | struct GNUNET_BIO_WriteSpec ws[] = { | 242 | struct GNUNET_BIO_WriteSpec ws[] = { |
300 | GNUNET_BIO_write_spec_object ("test-fullfile-rw-bytes", | 243 | GNUNET_BIO_write_spec_object ("test-fullfile-rw-bytes", |
@@ -302,8 +245,6 @@ test_fullfile_rw (void) | |||
302 | strlen (TESTSTRING)), | 245 | strlen (TESTSTRING)), |
303 | GNUNET_BIO_write_spec_string ("test-fullfile-rw-string", | 246 | GNUNET_BIO_write_spec_string ("test-fullfile-rw-string", |
304 | TESTSTRING), | 247 | TESTSTRING), |
305 | GNUNET_BIO_write_spec_meta_data ("test-fullfile-rw-metadata", | ||
306 | mdW), | ||
307 | GNUNET_BIO_write_spec_end (), | 248 | GNUNET_BIO_write_spec_end (), |
308 | }; | 249 | }; |
309 | 250 | ||
@@ -314,8 +255,6 @@ test_fullfile_rw (void) | |||
314 | GNUNET_BIO_read_spec_string ("test-fullfile-rw-string", | 255 | GNUNET_BIO_read_spec_string ("test-fullfile-rw-string", |
315 | &rString, | 256 | &rString, |
316 | 200), | 257 | 200), |
317 | GNUNET_BIO_read_spec_meta_data ("test-fullfile-rw-metadata", | ||
318 | &mdR), | ||
319 | GNUNET_BIO_read_spec_end (), | 258 | GNUNET_BIO_read_spec_end (), |
320 | }; | 259 | }; |
321 | 260 | ||
@@ -330,7 +269,6 @@ test_fullfile_rw (void) | |||
330 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); | 269 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
331 | 270 | ||
332 | GNUNET_assert (NULL == rString); | 271 | GNUNET_assert (NULL == rString); |
333 | GNUNET_assert (NULL == mdR); | ||
334 | #endif | 272 | #endif |
335 | return 0; | 273 | return 0; |
336 | } | 274 | } |
@@ -368,69 +306,6 @@ test_fakestring_rw (void) | |||
368 | 306 | ||
369 | 307 | ||
370 | static int | 308 | static int |
371 | test_fakemeta_rw (void) | ||
372 | { | ||
373 | struct GNUNET_BIO_WriteHandle *wh; | ||
374 | struct GNUNET_BIO_ReadHandle *rh; | ||
375 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); | ||
376 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; | ||
377 | |||
378 | wh = GNUNET_BIO_write_open_file (filename); | ||
379 | GNUNET_assert (NULL != wh); | ||
380 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, | ||
381 | "test-fakestring-rw-int32", | ||
382 | 2)); | ||
383 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | ||
384 | |||
385 | rh = GNUNET_BIO_read_open_file (filename); | ||
386 | GNUNET_assert (NULL != rh); | ||
387 | GNUNET_assert (GNUNET_SYSERR == | ||
388 | GNUNET_BIO_read_meta_data (rh, | ||
389 | "test-fakestring-rw-metadata", | ||
390 | &mdR)); | ||
391 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); | ||
392 | |||
393 | GNUNET_assert (NULL == mdR); | ||
394 | |||
395 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
396 | GNUNET_free (filename); | ||
397 | return 0; | ||
398 | } | ||
399 | |||
400 | |||
401 | static int | ||
402 | test_fakebigmeta_rw (void) | ||
403 | { | ||
404 | struct GNUNET_BIO_WriteHandle *wh; | ||
405 | struct GNUNET_BIO_ReadHandle *rh; | ||
406 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); | ||
407 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; | ||
408 | int32_t wNum = 1024 * 1024 * 10; | ||
409 | |||
410 | wh = GNUNET_BIO_write_open_file (filename); | ||
411 | GNUNET_assert (NULL != wh); | ||
412 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, | ||
413 | "test-fakebigmeta-rw-int32", | ||
414 | wNum)); | ||
415 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | ||
416 | |||
417 | rh = GNUNET_BIO_read_open_file (filename); | ||
418 | GNUNET_assert (NULL != rh); | ||
419 | GNUNET_assert (GNUNET_SYSERR == | ||
420 | GNUNET_BIO_read_meta_data (rh, | ||
421 | "test-fakebigmeta-rw-metadata", | ||
422 | &mdR)); | ||
423 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); | ||
424 | |||
425 | GNUNET_assert (NULL == mdR); | ||
426 | |||
427 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
428 | GNUNET_free (filename); | ||
429 | return 0; | ||
430 | } | ||
431 | |||
432 | |||
433 | static int | ||
434 | check_string_rw (void) | 309 | check_string_rw (void) |
435 | { | 310 | { |
436 | GNUNET_assert (0 == test_nullstring_rw ()); | 311 | GNUNET_assert (0 == test_nullstring_rw ()); |
@@ -442,16 +317,6 @@ check_string_rw (void) | |||
442 | 317 | ||
443 | 318 | ||
444 | static int | 319 | static int |
445 | check_metadata_rw (void) | ||
446 | { | ||
447 | GNUNET_assert (0 == test_fakebigmeta_rw ()); | ||
448 | GNUNET_assert (0 == test_fakemeta_rw ()); | ||
449 | GNUNET_assert (0 == test_bigmeta_rw ()); | ||
450 | return 0; | ||
451 | } | ||
452 | |||
453 | |||
454 | static int | ||
455 | check_file_rw (void) | 320 | check_file_rw (void) |
456 | { | 321 | { |
457 | GNUNET_assert (0 == test_normal_rw ()); | 322 | GNUNET_assert (0 == test_normal_rw ()); |
@@ -467,7 +332,6 @@ main (int argc, char *argv[]) | |||
467 | { | 332 | { |
468 | GNUNET_log_setup ("test-bio", "WARNING", NULL); | 333 | GNUNET_log_setup ("test-bio", "WARNING", NULL); |
469 | GNUNET_assert (0 == check_file_rw ()); | 334 | GNUNET_assert (0 == check_file_rw ()); |
470 | GNUNET_assert (0 == check_metadata_rw ()); | ||
471 | GNUNET_assert (0 == check_string_rw ()); | 335 | GNUNET_assert (0 == check_string_rw ()); |
472 | return 0; | 336 | return 0; |
473 | } | 337 | } |