diff options
author | Werner Koch <wk@gnupg.org> | 2015-04-13 09:57:33 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2015-04-13 09:57:33 +0200 |
commit | 454f60399c7318fffd3de2afadd58c7a490178bd (patch) | |
tree | d2adb5142b634753a09dbc434cf8cefa50e5b06e | |
parent | build: Update gpg-error.m4. (diff) | |
download | gnupg2-454f60399c7318fffd3de2afadd58c7a490178bd.tar.xz gnupg2-454f60399c7318fffd3de2afadd58c7a490178bd.zip |
common: Do without nested fucntions to support non-gcc.
* common/t-stringhelp.c (test_strsplit): Remove nested function.
Signed-off-by: Werner Koch <wk@gnupg.org>
-rw-r--r-- | common/t-stringhelp.c | 106 |
1 files changed, 54 insertions, 52 deletions
diff --git a/common/t-stringhelp.c b/common/t-stringhelp.c index f5b6cd99e..9d1d20c96 100644 --- a/common/t-stringhelp.c +++ b/common/t-stringhelp.c @@ -482,58 +482,60 @@ test_make_absfilename_try (void) static void test_strsplit (void) { - int test_count = 0; - void test (const char *s, char delim, char replacement, - const char *fields_expected[]) - { - char *s2; - int field_count; - char **fields; - int field_count_expected; - int i; - - /* Count the fields. */ - for (field_count_expected = 0; - fields_expected[field_count_expected]; - field_count_expected ++) - ; - - test_count ++; - - /* We need to copy s since strsplit modifies it in place. */ - s2 = xstrdup (s); - fields = strsplit (s2, delim, replacement, &field_count); - - if (field_count != field_count_expected) - fail (test_count * 1000); - - for (i = 0; i < field_count_expected; i ++) - if (strcmp (fields_expected[i], fields[i]) != 0) - { - printf ("For field %d, expected '%s', but got '%s'\n", - i, fields_expected[i], fields[i]); - fail (test_count * 1000 + i + 1); - } - - xfree (s2); - } - - { - const char *expected_result[] = - { "a", "bc", "cde", "fghi", "jklmn", "", "foo", "", NULL }; - test ("a:bc:cde:fghi:jklmn::foo:", ':', '\0', expected_result); - } - - { - const char *expected_result[] = - { "!a!bc!!def!", "a!bc!!def!", "bc!!def!", "!def!", "def!", "", NULL }; - test (",a,bc,,def,", ',', '!', expected_result); - } - - { - const char *expected_result[] = { "", NULL }; - test ("", ':', ',', expected_result); - } + struct { + const char *s; + char delim; + char replacement; + const char *fields_expected[10]; + } tv[] = { + { + "a:bc:cde:fghi:jklmn::foo:", ':', '\0', + { "a", "bc", "cde", "fghi", "jklmn", "", "foo", "", NULL } + }, + { + ",a,bc,,def,", ',', '!', + { "!a!bc!!def!", "a!bc!!def!", "bc!!def!", "!def!", "def!", "", NULL } + }, + { + "", ':', ',', + { "", NULL } + } + }; + + int tidx; + + for (tidx = 0; tidx < DIM(tv); tidx++) + { + char *s2; + int field_count; + char **fields; + int field_count_expected; + int i; + + /* Count the fields. */ + for (field_count_expected = 0; + tv[tidx].fields_expected[field_count_expected]; + field_count_expected ++) + ; + + /* We need to copy s since strsplit modifies it in place. */ + s2 = xstrdup (tv[tidx].s); + fields = strsplit (s2, tv[tidx].delim, tv[tidx].replacement, + &field_count); + + if (field_count != field_count_expected) + fail (tidx * 1000); + + for (i = 0; i < field_count_expected; i ++) + if (strcmp (tv[tidx].fields_expected[i], fields[i]) != 0) + { + printf ("For field %d, expected '%s', but got '%s'\n", + i, tv[tidx].fields_expected[i], fields[i]); + fail (tidx * 1000 + i + 1); + } + + xfree (s2); + } } int |