diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/util/test_strings.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/util/test_strings.c')
-rw-r--r-- | src/util/test_strings.c | 159 |
1 files changed, 85 insertions, 74 deletions
diff --git a/src/util/test_strings.c b/src/util/test_strings.c index 60887c587..90d06a473 100644 --- a/src/util/test_strings.c +++ b/src/util/test_strings.c | |||
@@ -25,12 +25,22 @@ | |||
25 | #include "gnunet_util_lib.h" | 25 | #include "gnunet_util_lib.h" |
26 | 26 | ||
27 | 27 | ||
28 | #define WANT(a, b) if (0 != strcmp(a, b)) { fprintf(stderr, "Got `%s', wanted `%s'\n", b, a); GNUNET_free(b); GNUNET_break(0); return 1; } else { GNUNET_free(b); } | 28 | #define WANT(a, b) if (0 != strcmp (a, b)) { fprintf (stderr, \ |
29 | #define WANTNF(a, b) do { if (0 != strcmp(a, b)) { fprintf(stderr, "Got `%s', wanted `%s'\n", b, a); GNUNET_break(0); return 1; } } while (0) | 29 | "Got `%s', wanted `%s'\n", \ |
30 | #define WANTB(a, b, l) if (0 != memcmp(a, b, l)) { GNUNET_break(0); return 1; } else { } | 30 | b, a); GNUNET_free (b); \ |
31 | GNUNET_break (0); \ | ||
32 | return 1; } else { GNUNET_free (b); \ | ||
33 | } | ||
34 | #define WANTNF(a, b) do { if (0 != strcmp (a, b)) { fprintf (stderr, \ | ||
35 | "Got `%s', wanted `%s'\n", \ | ||
36 | b, a); \ | ||
37 | GNUNET_break (0); return 1; \ | ||
38 | } } while (0) | ||
39 | #define WANTB(a, b, l) if (0 != memcmp (a, b, l)) { GNUNET_break (0); return 1; \ | ||
40 | } else { } | ||
31 | 41 | ||
32 | int | 42 | int |
33 | main(int argc, char *argv[]) | 43 | main (int argc, char *argv[]) |
34 | { | 44 | { |
35 | char buf[128]; | 45 | char buf[128]; |
36 | char *r; | 46 | char *r; |
@@ -42,89 +52,90 @@ main(int argc, char *argv[]) | |||
42 | struct GNUNET_TIME_Relative rtx; | 52 | struct GNUNET_TIME_Relative rtx; |
43 | const char *hdir; | 53 | const char *hdir; |
44 | 54 | ||
45 | GNUNET_log_setup("test_strings", "ERROR", NULL); | 55 | GNUNET_log_setup ("test_strings", "ERROR", NULL); |
46 | sprintf(buf, "4 %s", _(/* size unit */ "b")); | 56 | sprintf (buf, "4 %s", _ (/* size unit */ "b")); |
47 | b = GNUNET_STRINGS_byte_size_fancy(4); | 57 | b = GNUNET_STRINGS_byte_size_fancy (4); |
48 | WANT(buf, b); | 58 | WANT (buf, b); |
49 | sprintf(buf, "10 %s", _(/* size unit */ "KiB")); | 59 | sprintf (buf, "10 %s", _ (/* size unit */ "KiB")); |
50 | b = GNUNET_STRINGS_byte_size_fancy(10240); | 60 | b = GNUNET_STRINGS_byte_size_fancy (10240); |
51 | WANT(buf, b); | 61 | WANT (buf, b); |
52 | sprintf(buf, "10 %s", _(/* size unit */ "TiB")); | 62 | sprintf (buf, "10 %s", _ (/* size unit */ "TiB")); |
53 | b = GNUNET_STRINGS_byte_size_fancy(10240LL * 1024LL * 1024LL * 1024LL); | 63 | b = GNUNET_STRINGS_byte_size_fancy (10240LL * 1024LL * 1024LL * 1024LL); |
54 | WANT(buf, b); | 64 | WANT (buf, b); |
55 | sprintf(buf, "4 %s", _(/* time unit */ "ms")); | 65 | sprintf (buf, "4 %s", _ (/* time unit */ "ms")); |
56 | bc = GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_relative_multiply | 66 | bc = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply |
57 | (GNUNET_TIME_UNIT_MILLISECONDS, | 67 | (GNUNET_TIME_UNIT_MILLISECONDS, |
58 | 4), GNUNET_YES); | 68 | 4), GNUNET_YES); |
59 | WANTNF(buf, bc); | 69 | WANTNF (buf, bc); |
60 | sprintf(buf, "7 %s", _(/* time unit */ "s")); | 70 | sprintf (buf, "7 %s", _ (/* time unit */ "s")); |
61 | bc = GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_relative_multiply | 71 | bc = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply |
62 | (GNUNET_TIME_UNIT_MILLISECONDS, | 72 | (GNUNET_TIME_UNIT_MILLISECONDS, |
63 | 7 * 1000), GNUNET_YES); | 73 | 7 * 1000), GNUNET_YES); |
64 | WANTNF(buf, bc); | 74 | WANTNF (buf, bc); |
65 | sprintf(buf, "7 %s", _(/* time unit */ "h")); | 75 | sprintf (buf, "7 %s", _ (/* time unit */ "h")); |
66 | bc = GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_relative_multiply | 76 | bc = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply |
67 | (GNUNET_TIME_UNIT_MILLISECONDS, | 77 | (GNUNET_TIME_UNIT_MILLISECONDS, |
68 | 7 * 60 * 60 * 1000), GNUNET_YES); | 78 | 7 * 60 * 60 * 1000), |
69 | WANTNF(buf, bc); | 79 | GNUNET_YES); |
70 | 80 | WANTNF (buf, bc); | |
71 | hdir = getenv("HOME"); | 81 | |
72 | 82 | hdir = getenv ("HOME"); | |
73 | GNUNET_snprintf(buf, sizeof(buf), "%s%s", hdir, DIR_SEPARATOR_STR); | 83 | |
74 | b = GNUNET_STRINGS_filename_expand("~"); | 84 | GNUNET_snprintf (buf, sizeof(buf), "%s%s", hdir, DIR_SEPARATOR_STR); |
75 | GNUNET_assert(b != NULL); | 85 | b = GNUNET_STRINGS_filename_expand ("~"); |
76 | WANT(buf, b); | 86 | GNUNET_assert (b != NULL); |
77 | GNUNET_STRINGS_buffer_fill(buf, sizeof(buf), 3, "a", "btx", "c"); | 87 | WANT (buf, b); |
78 | WANTB("a\0btx\0c", buf, 8); | 88 | GNUNET_STRINGS_buffer_fill (buf, sizeof(buf), 3, "a", "btx", "c"); |
79 | if (6 != GNUNET_STRINGS_buffer_tokenize(buf, sizeof(buf), 2, &r, &b)) | 89 | WANTB ("a\0btx\0c", buf, 8); |
90 | if (6 != GNUNET_STRINGS_buffer_tokenize (buf, sizeof(buf), 2, &r, &b)) | ||
80 | return 1; | 91 | return 1; |
81 | r = GNUNET_strdup(r); | 92 | r = GNUNET_strdup (r); |
82 | WANT("a", r); | 93 | WANT ("a", r); |
83 | b = GNUNET_strdup(b); | 94 | b = GNUNET_strdup (b); |
84 | WANT("btx", b); | 95 | WANT ("btx", b); |
85 | if (0 != GNUNET_STRINGS_buffer_tokenize(buf, 2, 2, &r, &b)) | 96 | if (0 != GNUNET_STRINGS_buffer_tokenize (buf, 2, 2, &r, &b)) |
86 | return 1; | 97 | return 1; |
87 | at.abs_value_us = 5000000; | 98 | at.abs_value_us = 5000000; |
88 | bc = GNUNET_STRINGS_absolute_time_to_string(at); | 99 | bc = GNUNET_STRINGS_absolute_time_to_string (at); |
89 | /* bc should be something like "Wed Dec 31 17:00:05 1969" | 100 | /* bc should be something like "Wed Dec 31 17:00:05 1969" |
90 | * where the details of the day and hour depend on the timezone; | 101 | * where the details of the day and hour depend on the timezone; |
91 | * however, the "0:05 19" should always be there; hence: */ | 102 | * however, the "0:05 19" should always be there; hence: */ |
92 | if (NULL == strstr(bc, "0:05 19")) | 103 | if (NULL == strstr (bc, "0:05 19")) |
93 | { | 104 | { |
94 | fprintf(stderr, "Got %s\n", bc); | 105 | fprintf (stderr, "Got %s\n", bc); |
95 | GNUNET_break(0); | 106 | GNUNET_break (0); |
96 | return 1; | 107 | return 1; |
97 | } | 108 | } |
98 | b = GNUNET_STRINGS_to_utf8("TEST", 4, "ASCII"); | 109 | b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII"); |
99 | WANT("TEST", b); | 110 | WANT ("TEST", b); |
100 | 111 | ||
101 | at = GNUNET_TIME_UNIT_FOREVER_ABS; | 112 | at = GNUNET_TIME_UNIT_FOREVER_ABS; |
102 | bc = GNUNET_STRINGS_absolute_time_to_string(at); | 113 | bc = GNUNET_STRINGS_absolute_time_to_string (at); |
103 | GNUNET_assert(GNUNET_OK == | 114 | GNUNET_assert (GNUNET_OK == |
104 | GNUNET_STRINGS_fancy_time_to_absolute(bc, &atx)); | 115 | GNUNET_STRINGS_fancy_time_to_absolute (bc, &atx)); |
105 | GNUNET_assert(atx.abs_value_us == at.abs_value_us); | 116 | GNUNET_assert (atx.abs_value_us == at.abs_value_us); |
106 | 117 | ||
107 | at.abs_value_us = 50000000000; | 118 | at.abs_value_us = 50000000000; |
108 | bc = GNUNET_STRINGS_absolute_time_to_string(at); | 119 | bc = GNUNET_STRINGS_absolute_time_to_string (at); |
109 | 120 | ||
110 | GNUNET_assert(GNUNET_OK == | 121 | GNUNET_assert (GNUNET_OK == |
111 | GNUNET_STRINGS_fancy_time_to_absolute(bc, &atx)); | 122 | GNUNET_STRINGS_fancy_time_to_absolute (bc, &atx)); |
112 | 123 | ||
113 | if (atx.abs_value_us != at.abs_value_us) | 124 | if (atx.abs_value_us != at.abs_value_us) |
114 | { | 125 | { |
115 | GNUNET_assert(0); | 126 | GNUNET_assert (0); |
116 | } | 127 | } |
117 | 128 | ||
118 | GNUNET_log_skip(2, GNUNET_NO); | 129 | GNUNET_log_skip (2, GNUNET_NO); |
119 | b = GNUNET_STRINGS_to_utf8("TEST", 4, "unknown"); | 130 | b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "unknown"); |
120 | GNUNET_log_skip(0, GNUNET_YES); | 131 | GNUNET_log_skip (0, GNUNET_YES); |
121 | WANT("TEST", b); | 132 | WANT ("TEST", b); |
122 | 133 | ||
123 | GNUNET_assert(GNUNET_OK == | 134 | GNUNET_assert (GNUNET_OK == |
124 | GNUNET_STRINGS_fancy_time_to_relative("15m", &rt)); | 135 | GNUNET_STRINGS_fancy_time_to_relative ("15m", &rt)); |
125 | GNUNET_assert(GNUNET_OK == | 136 | GNUNET_assert (GNUNET_OK == |
126 | GNUNET_STRINGS_fancy_time_to_relative("15 m", &rtx)); | 137 | GNUNET_STRINGS_fancy_time_to_relative ("15 m", &rtx)); |
127 | GNUNET_assert(rt.rel_value_us == rtx.rel_value_us); | 138 | GNUNET_assert (rt.rel_value_us == rtx.rel_value_us); |
128 | 139 | ||
129 | return 0; | 140 | return 0; |
130 | } | 141 | } |