diff options
Diffstat (limited to 'src/util/test_strings_to_data.c')
-rw-r--r-- | src/util/test_strings_to_data.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/util/test_strings_to_data.c b/src/util/test_strings_to_data.c index d719e950a..71861b128 100644 --- a/src/util/test_strings_to_data.c +++ b/src/util/test_strings_to_data.c | |||
@@ -26,7 +26,7 @@ | |||
26 | 26 | ||
27 | 27 | ||
28 | int | 28 | int |
29 | main(int argc, char *argv[]) | 29 | main (int argc, char *argv[]) |
30 | { | 30 | { |
31 | char buf[1024]; | 31 | char buf[1024]; |
32 | char *end; | 32 | char *end; |
@@ -35,27 +35,29 @@ main(int argc, char *argv[]) | |||
35 | unsigned int i; | 35 | unsigned int i; |
36 | int ret = 0; | 36 | int ret = 0; |
37 | 37 | ||
38 | GNUNET_log_setup("util", "DEBUG", NULL); | 38 | GNUNET_log_setup ("util", "DEBUG", NULL); |
39 | for (i = 0; i < sizeof(src); i++) | 39 | for (i = 0; i < sizeof(src); i++) |
40 | { | ||
41 | memset (src, i, sizeof(src)); | ||
42 | memset (dst, i + 1, sizeof(dst)); | ||
43 | |||
44 | end = GNUNET_STRINGS_data_to_string (&src, i, buf, sizeof(buf)); | ||
45 | GNUNET_assert (NULL != end); | ||
46 | end[0] = '\0'; | ||
47 | if (GNUNET_OK != | ||
48 | GNUNET_STRINGS_string_to_data (buf, strlen (buf), dst, i)) | ||
49 | { | ||
50 | fprintf (stderr, "%u failed decode (%u bytes)\n", i, (unsigned | ||
51 | int) strlen (buf)); | ||
52 | ret = 1; | ||
53 | } | ||
54 | else if (0 != memcmp (src, dst, i)) | ||
40 | { | 55 | { |
41 | memset(src, i, sizeof(src)); | 56 | fprintf (stderr, "%u wrong decode (%u bytes)\n", i, (unsigned |
42 | memset(dst, i + 1, sizeof(dst)); | 57 | int) strlen (buf)); |
43 | 58 | ret = 1; | |
44 | end = GNUNET_STRINGS_data_to_string(&src, i, buf, sizeof(buf)); | ||
45 | GNUNET_assert(NULL != end); | ||
46 | end[0] = '\0'; | ||
47 | if (GNUNET_OK != | ||
48 | GNUNET_STRINGS_string_to_data(buf, strlen(buf), dst, i)) | ||
49 | { | ||
50 | fprintf(stderr, "%u failed decode (%u bytes)\n", i, (unsigned int)strlen(buf)); | ||
51 | ret = 1; | ||
52 | } | ||
53 | else if (0 != memcmp(src, dst, i)) | ||
54 | { | ||
55 | fprintf(stderr, "%u wrong decode (%u bytes)\n", i, (unsigned int)strlen(buf)); | ||
56 | ret = 1; | ||
57 | } | ||
58 | } | 59 | } |
60 | } | ||
59 | return ret; | 61 | return ret; |
60 | } | 62 | } |
61 | 63 | ||