mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-20 14:37:08 +01:00
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>
This commit is contained in:
parent
eb54282e39
commit
454f60399c
@ -482,9 +482,29 @@ test_make_absfilename_try (void)
|
|||||||
static void
|
static void
|
||||||
test_strsplit (void)
|
test_strsplit (void)
|
||||||
{
|
{
|
||||||
int test_count = 0;
|
struct {
|
||||||
void test (const char *s, char delim, char replacement,
|
const char *s;
|
||||||
const char *fields_expected[])
|
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;
|
char *s2;
|
||||||
int field_count;
|
int field_count;
|
||||||
@ -494,46 +514,28 @@ test_strsplit (void)
|
|||||||
|
|
||||||
/* Count the fields. */
|
/* Count the fields. */
|
||||||
for (field_count_expected = 0;
|
for (field_count_expected = 0;
|
||||||
fields_expected[field_count_expected];
|
tv[tidx].fields_expected[field_count_expected];
|
||||||
field_count_expected ++)
|
field_count_expected ++)
|
||||||
;
|
;
|
||||||
|
|
||||||
test_count ++;
|
|
||||||
|
|
||||||
/* We need to copy s since strsplit modifies it in place. */
|
/* We need to copy s since strsplit modifies it in place. */
|
||||||
s2 = xstrdup (s);
|
s2 = xstrdup (tv[tidx].s);
|
||||||
fields = strsplit (s2, delim, replacement, &field_count);
|
fields = strsplit (s2, tv[tidx].delim, tv[tidx].replacement,
|
||||||
|
&field_count);
|
||||||
|
|
||||||
if (field_count != field_count_expected)
|
if (field_count != field_count_expected)
|
||||||
fail (test_count * 1000);
|
fail (tidx * 1000);
|
||||||
|
|
||||||
for (i = 0; i < field_count_expected; i ++)
|
for (i = 0; i < field_count_expected; i ++)
|
||||||
if (strcmp (fields_expected[i], fields[i]) != 0)
|
if (strcmp (tv[tidx].fields_expected[i], fields[i]) != 0)
|
||||||
{
|
{
|
||||||
printf ("For field %d, expected '%s', but got '%s'\n",
|
printf ("For field %d, expected '%s', but got '%s'\n",
|
||||||
i, fields_expected[i], fields[i]);
|
i, tv[tidx].fields_expected[i], fields[i]);
|
||||||
fail (test_count * 1000 + i + 1);
|
fail (tidx * 1000 + i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
xfree (s2);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user