aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_strings.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-09-16 11:27:08 +0000
committerChristian Grothoff <christian@grothoff.org>2012-09-16 11:27:08 +0000
commitf736b24935d66733e9a53798fbc87dbc8aff9fca (patch)
treeb7f865216ca4b40a4a6e4535dfa6677700a27efc /src/util/test_strings.c
parentc5784d2c94adcf1fe80e88c9ab1c152ce2fcbe95 (diff)
downloadgnunet-f736b24935d66733e9a53798fbc87dbc8aff9fca.tar.gz
gnunet-f736b24935d66733e9a53798fbc87dbc8aff9fca.zip
-fixing #2546
Diffstat (limited to 'src/util/test_strings.c')
-rw-r--r--src/util/test_strings.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/util/test_strings.c b/src/util/test_strings.c
index 749650589..a77acaa59 100644
--- a/src/util/test_strings.c
+++ b/src/util/test_strings.c
@@ -27,6 +27,7 @@
27 27
28 28
29#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); } 29#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); }
30#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)
30#define WANTB(a,b,l) if (0 != memcmp(a,b,l)) { GNUNET_break(0); return 1;} else { } 31#define WANTB(a,b,l) if (0 != memcmp(a,b,l)) { GNUNET_break(0); return 1;} else { }
31 32
32int 33int
@@ -35,6 +36,7 @@ main (int argc, char *argv[])
35 char buf[128]; 36 char buf[128];
36 char *r; 37 char *r;
37 char *b; 38 char *b;
39 const char *bc;
38 struct GNUNET_TIME_Absolute at; 40 struct GNUNET_TIME_Absolute at;
39 struct GNUNET_TIME_Absolute atx; 41 struct GNUNET_TIME_Absolute atx;
40 const char *hdir; 42 const char *hdir;
@@ -50,20 +52,20 @@ main (int argc, char *argv[])
50 b = GNUNET_STRINGS_byte_size_fancy (10240LL * 1024LL * 1024LL * 1024LL); 52 b = GNUNET_STRINGS_byte_size_fancy (10240LL * 1024LL * 1024LL * 1024LL);
51 WANT (buf, b); 53 WANT (buf, b);
52 sprintf (buf, "4 %s", _( /* time unit */ "ms")); 54 sprintf (buf, "4 %s", _( /* time unit */ "ms"));
53 b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply 55 bc = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
54 (GNUNET_TIME_UNIT_MILLISECONDS, 56 (GNUNET_TIME_UNIT_MILLISECONDS,
55 4)); 57 4), GNUNET_YES);
56 WANT (buf, b); 58 WANTNF (buf, bc);
57 sprintf (buf, "7 %s", _( /* time unit */ "s")); 59 sprintf (buf, "7 %s", _( /* time unit */ "s"));
58 b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply 60 bc = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
59 (GNUNET_TIME_UNIT_MILLISECONDS, 61 (GNUNET_TIME_UNIT_MILLISECONDS,
60 7 * 1000)); 62 7 * 1000), GNUNET_YES);
61 WANT (buf, b); 63 WANTNF (buf, bc);
62 sprintf (buf, "7 %s", _( /* time unit */ "h")); 64 sprintf (buf, "7 %s", _( /* time unit */ "h"));
63 b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply 65 bc = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
64 (GNUNET_TIME_UNIT_MILLISECONDS, 66 (GNUNET_TIME_UNIT_MILLISECONDS,
65 7 * 60 * 60 * 1000)); 67 7 * 60 * 60 * 1000), GNUNET_YES);
66 WANT (buf, b); 68 WANTNF (buf, bc);
67#ifndef MINGW 69#ifndef MINGW
68 hdir = getenv ("HOME"); 70 hdir = getenv ("HOME");
69#else 71#else
@@ -84,27 +86,24 @@ main (int argc, char *argv[])
84 if (0 != GNUNET_STRINGS_buffer_tokenize (buf, 2, 2, &r, &b)) 86 if (0 != GNUNET_STRINGS_buffer_tokenize (buf, 2, 2, &r, &b))
85 return 1; 87 return 1;
86 at.abs_value = 5000; 88 at.abs_value = 5000;
87 r = GNUNET_STRINGS_absolute_time_to_string (at); 89 bc = GNUNET_STRINGS_absolute_time_to_string (at);
88 /* r should be something like "Wed Dec 31 17:00:05 1969" 90 /* bc should be something like "Wed Dec 31 17:00:05 1969"
89 * where the details of the day and hour depend on the timezone; 91 * where the details of the day and hour depend on the timezone;
90 * however, the "0:05 19" should always be there; hence: */ 92 * however, the "0:05 19" should always be there; hence: */
91 if (NULL == strstr (r, "0:05 19")) 93 if (NULL == strstr (bc, "0:05 19"))
92 { 94 {
93 FPRINTF (stderr, "Got %s\n", r); 95 FPRINTF (stderr, "Got %s\n", bc);
94 GNUNET_break (0); 96 GNUNET_break (0);
95 GNUNET_free (r);
96 return 1; 97 return 1;
97 } 98 }
98 GNUNET_free (r);
99 b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII"); 99 b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII");
100 WANT ("TEST", b); 100 WANT ("TEST", b);
101 101
102 at = GNUNET_TIME_UNIT_FOREVER_ABS; 102 at = GNUNET_TIME_UNIT_FOREVER_ABS;
103 b = GNUNET_STRINGS_absolute_time_to_string (at); 103 bc = GNUNET_STRINGS_absolute_time_to_string (at);
104 GNUNET_assert (GNUNET_OK == 104 GNUNET_assert (GNUNET_OK ==
105 GNUNET_STRINGS_fancy_time_to_absolute (b, &atx)); 105 GNUNET_STRINGS_fancy_time_to_absolute (bc, &atx));
106 GNUNET_assert (atx.abs_value == at.abs_value); 106 GNUNET_assert (atx.abs_value == at.abs_value);
107 GNUNET_free (b);
108 107
109#if ENABLE_NLS && HAVE_ICONV 108#if ENABLE_NLS && HAVE_ICONV
110 GNUNET_log_skip (2, GNUNET_NO); 109 GNUNET_log_skip (2, GNUNET_NO);