static int test_split_quoted_strings_edge(void) { gboolean success = TRUE; struct trial trials[] = { { "", { "", NULL, } }, { " ", { "", "", NULL } }, { " x", { "", "x", NULL } }, { "x ", { "x", "", NULL } }, { "x\\ y", { "x y", NULL } }, { "\\", { "", NULL } }, /* inv */ { "z\\", { "z", NULL } }, /* inv */ { "z\"", { "z", NULL } }, /* inv */ { "\" \" \"", { " ", "", NULL } }, /* inv */ { NULL, { NULL, } }, }; struct trial *trial = trials; while (trial->combined) { char **tokens = split_quoted_strings(trial->combined); success = compare_strv(trial->expected, tokens, "split_quoted_strings", trial->combined) && success; g_strfreev(tokens); trial++; } return success; }
static int test_split_quoted_strings(void) { char **iter1, **iter2, **iter3; gboolean success = TRUE; char *middle_strings[] = { "", "foo", "\"foo\"", "sp aces", NULL, }; /* the idea here is to loop over all triples of strings, forming a * string by quoting them with quote_string and inserting a space, then * re-splitting with split_quoted_string. This should get us back to our * starting point. */ for (iter1 = quotable_strings; *iter1; iter1++) { for (iter2 = middle_strings; *iter2; iter2++) { for (iter3 = quotable_strings; *iter3; iter3++) { char *q1 = quote_string(*iter1); char *q2 = quote_string(*iter2); char *q3 = quote_string(*iter3); const char *expected[4] = { *iter1, *iter2, *iter3, NULL }; char *combined = vstralloc(q1, " ", q2, " ", q3, NULL); char **tokens; tokens = split_quoted_strings(combined); success = compare_strv(expected, tokens, "split_quoted_strings", combined) && success; amfree(q1); amfree(q2); amfree(q3); amfree(combined); g_strfreev(tokens); } } } return success; }
int main (int argc, char *argv[]) { DBusGConnection *bus; g_type_init (); bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL); compare_ints (); compare_strings (); compare_strv (); compare_garrays (); compare_ptrarrays (); compare_str_hash (); compare_gvalue_hash (); compare_ip6_addresses (); return 0; }