diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-03-26 10:06:47 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-03-30 08:26:30 +1000 |
commit | 7f4df04d59b1182fb8497f16dc5588bd6e1d4225 (patch) | |
tree | ba4b14f4903f81714701e948fabe0a9521a03383 /test/test-utils.c | |
parent | 4da9349a918848585e2fea57a295382b67f71cfa (diff) | |
download | libinput-7f4df04d59b1182fb8497f16dc5588bd6e1d4225.tar.gz |
tools/record: deduplicate the device opening logic
With a new helper function strv_from_argv we can re-use the device opening
loop for all the use-cases we have.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'test/test-utils.c')
-rw-r--r-- | test/test-utils.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/test-utils.c b/test/test-utils.c index dbd58031..882ee6c7 100644 --- a/test/test-utils.c +++ b/test/test-utils.c @@ -1022,6 +1022,44 @@ START_TEST(strsplit_test) } END_TEST +START_TEST(strargv_test) +{ + struct argv_test { + int argc; + char *argv[10]; + int expected; + } tests[] = { + { 0, {NULL}, 0 }, + { 1, {"hello", "World"}, 1 }, + { 2, {"hello", "World"}, 2 }, + { 2, {"", " "}, 2 }, + { 2, {"", NULL}, 0 }, + { 2, {NULL, NULL}, 0 }, + { 1, {NULL, NULL}, 0 }, + { 3, {"hello", NULL, "World"}, 0 }, + }; + struct argv_test *t; + + ARRAY_FOR_EACH(tests, t) { + char **strv = strv_from_argv(t->argc, t->argv); + + if (t->expected == 0) { + ck_assert(strv == NULL); + } else { + int count = 0; + char **s = strv; + while (*s) { + ck_assert_str_eq(*s, t->argv[count]); + count++; + s++; + } + ck_assert_int_eq(t->expected, count); + strv_free(strv); + } + } +} +END_TEST + START_TEST(kvsplit_double_test) { struct kvsplit_dbl_test { @@ -1378,6 +1416,7 @@ litest_utils_suite(void) tcase_add_test(tc, safe_atou_base_8_test); tcase_add_test(tc, safe_atod_test); tcase_add_test(tc, strsplit_test); + tcase_add_test(tc, strargv_test); tcase_add_test(tc, kvsplit_double_test); tcase_add_test(tc, strjoin_test); tcase_add_test(tc, strstrip_test); |