diff options
author | Luca Boccassi <bluca@debian.org> | 2024-06-18 01:22:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-18 01:22:19 +0200 |
commit | 5d42acada4942197f91db49647826f25c14aae19 (patch) | |
tree | 0291988ca3a1aa9abb48b6d32a685e468b8a9451 /src/test | |
parent | Merge pull request #33359 from bluca/test_apparmor_unpriv (diff) | |
parent | tree-wide: replace strv_sort() + strv_uniq() -> strv_sort_uniq() (diff) | |
download | systemd-5d42acada4942197f91db49647826f25c14aae19.tar.xz systemd-5d42acada4942197f91db49647826f25c14aae19.zip |
Merge pull request #33376 from yuwata/strv_sort_uniq
strv: introduce strv_sort_uniq()
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-strv.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/test/test-strv.c b/src/test/test-strv.c index 65afefed3b..f7b6ee2bb2 100644 --- a/src/test/test-strv.c +++ b/src/test/test-strv.c @@ -527,6 +527,81 @@ TEST(strv_sort) { ASSERT_STREQ(input_table[4], "durian"); } +TEST(strv_sort_uniq) { + static const char* input_table[] = { + "durian", + "apple", + "citrus", + "CAPITAL LETTERS FIRST", + "banana", + "durian", + "apple", + "citrus", + "CAPITAL LETTERS FIRST", + "banana", + "durian", + "apple", + "citrus", + "CAPITAL LETTERS FIRST", + "banana", + NULL + }; + + _cleanup_strv_free_ char **a = NULL, **b = NULL, **c = NULL; + + ASSERT_NULL(strv_sort_uniq(a)); + + ASSERT_NOT_NULL(a = strv_new(NULL)); + assert_se(strv_sort_uniq(a) == a); + ASSERT_NULL(a[0]); + a = strv_free(a); + + ASSERT_NOT_NULL(a = strv_new("a", "a", "a", "a", "a")); + assert_se(strv_sort_uniq(a) == a); + ASSERT_STREQ(a[0], "a"); + ASSERT_NULL(a[1]); + a = strv_free(a); + + ASSERT_NOT_NULL(a = strv_new("a", "a", "a", "a", "b")); + assert_se(strv_sort_uniq(a) == a); + ASSERT_STREQ(a[0], "a"); + ASSERT_STREQ(a[1], "b"); + ASSERT_NULL(a[2]); + a = strv_free(a); + + ASSERT_NOT_NULL(a = strv_new("b", "a", "a", "a", "a")); + assert_se(strv_sort_uniq(a) == a); + ASSERT_STREQ(a[0], "a"); + ASSERT_STREQ(a[1], "b"); + ASSERT_NULL(a[2]); + a = strv_free(a); + + ASSERT_NOT_NULL(a = strv_new("a", "a", "b", "a", "b")); + assert_se(strv_sort_uniq(a) == a); + ASSERT_STREQ(a[0], "a"); + ASSERT_STREQ(a[1], "b"); + ASSERT_NULL(a[2]); + a = strv_free(a); + + ASSERT_NOT_NULL(a = strv_copy((char**) input_table)); + ASSERT_NOT_NULL(b = strv_copy((char**) input_table)); + ASSERT_NOT_NULL(c = strv_copy((char**) input_table)); + + assert_se(strv_sort_uniq(a) == a); + assert_se(strv_sort(strv_uniq(b)) == b); + assert_se(strv_uniq(strv_sort(c)) == c); + + assert_se(strv_equal(a, b)); + assert_se(strv_equal(a, c)); + + ASSERT_STREQ(a[0], "CAPITAL LETTERS FIRST"); + ASSERT_STREQ(a[1], "apple"); + ASSERT_STREQ(a[2], "banana"); + ASSERT_STREQ(a[3], "citrus"); + ASSERT_STREQ(a[4], "durian"); + ASSERT_NULL(a[5]); +} + TEST(strv_extend_strv_biconcat) { _cleanup_strv_free_ char **a = NULL, **b = NULL; |