set: introduce set_to_strv()
It is similar to set_get_strv(), but invalidates the set on success.
This commit is contained in:
@@ -400,4 +400,28 @@ TEST(set_fnmatch) {
|
||||
assert_se(!set_fnmatch(match, nomatch, "cccXX"));
|
||||
}
|
||||
|
||||
TEST(set_to_strv) {
|
||||
_cleanup_set_free_ Set *set = NULL;
|
||||
_cleanup_strv_free_ char **a = NULL;
|
||||
_cleanup_free_ char **b = NULL;
|
||||
char **v = STRV_MAKE("aaa", "bbb", "ccc");
|
||||
|
||||
ASSERT_NOT_NULL(a = set_to_strv(&set));
|
||||
ASSERT_TRUE(strv_isempty(a));
|
||||
ASSERT_NULL(set);
|
||||
a = strv_free(a);
|
||||
|
||||
ASSERT_OK(set_put_strdupv(&set, v));
|
||||
ASSERT_EQ(set_size(set), strv_length(v));
|
||||
|
||||
ASSERT_NOT_NULL(b = set_get_strv(set));
|
||||
ASSERT_EQ(strv_length(b), strv_length(v));
|
||||
ASSERT_TRUE(strv_equal_ignore_order(b, v));
|
||||
|
||||
ASSERT_NOT_NULL(a = set_to_strv(&set));
|
||||
ASSERT_EQ(strv_length(a), strv_length(v));
|
||||
ASSERT_TRUE(strv_equal_ignore_order(a, v));
|
||||
ASSERT_NULL(set);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
||||
Reference in New Issue
Block a user