diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2014-01-28 14:51:58 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-01-29 14:08:51 +0100 |
commit | 37171a92dc9c5e4fe1a0663901fc965b49a78151 (patch) | |
tree | 506bebead173c4b4de0761495e5919d191fc4814 /src/tests/sysdb-tests.c | |
parent | 12213ca982ee3ad58f08e145532b500d7c4678d1 (diff) | |
download | sssd-37171a92dc9c5e4fe1a0663901fc965b49a78151.tar.gz sssd-37171a92dc9c5e4fe1a0663901fc965b49a78151.tar.xz sssd-37171a92dc9c5e4fe1a0663901fc965b49a78151.zip |
DB: Add sss_ldb_el_to_string_list
Diffstat (limited to 'src/tests/sysdb-tests.c')
-rw-r--r-- | src/tests/sysdb-tests.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c index ee0030c14..f7d84732a 100644 --- a/src/tests/sysdb-tests.c +++ b/src/tests/sysdb-tests.c @@ -4359,6 +4359,52 @@ START_TEST(test_sysdb_attrs_add_lc_name_alias) } END_TEST +START_TEST(test_sysdb_attrs_get_string_array) +{ + int ret; + struct sysdb_attrs *attrs; + const char **list; + const char *attrname = "test_attr"; + TALLOC_CTX *tmp_ctx; + struct ldb_message_element *el = NULL; + + tmp_ctx = talloc_new(NULL); + fail_unless(tmp_ctx != NULL, "talloc_new failed"); + + attrs = sysdb_new_attrs(NULL); + fail_unless(attrs != NULL, "sysdb_new_attrs failed"); + + ret = sysdb_attrs_add_string(attrs, attrname, "val1"); + fail_unless(ret == EOK, "sysdb_attrs_add_string failed"); + ret = sysdb_attrs_add_string(attrs, attrname, "val2"); + fail_unless(ret == EOK, "sysdb_attrs_add_string failed"); + + ret = sysdb_attrs_get_el_ext(attrs, attrname, false, &el); + fail_unless(ret == EOK, "sysdb_attrs_get_el_ext failed"); + + list = sss_ldb_el_to_string_list(tmp_ctx, el); + fail_if(list == NULL, ("sss_ldb_el_to_string_list failed\n")); + + ck_assert_str_eq(list[0], "val1"); + ck_assert_str_eq(list[1], "val2"); + fail_unless(list[2] == NULL, "Expected terminated list"); + + talloc_free(list); + + ret = sysdb_attrs_get_string_array(attrs, attrname, tmp_ctx, &list); + fail_unless(ret == EOK, "sysdb_attrs_get_string_array failed"); + + /* This test relies on values keeping the same order. It is the case + * with LDB, but if we ever switch from LDB, we need to amend the test + */ + ck_assert_str_eq(list[0], "val1"); + ck_assert_str_eq(list[1], "val2"); + fail_unless(list[2] == NULL, "Expected terminated list"); + + talloc_free(tmp_ctx); +} +END_TEST + START_TEST(test_sysdb_has_enumerated) { errno_t ret; @@ -5119,6 +5165,9 @@ Suite *create_sysdb_suite(void) tcase_add_test(tc_sysdb, test_sysdb_attrs_add_lc_name_alias); +/* ===== UTIL TESTS ===== */ + tcase_add_test(tc_sysdb, test_sysdb_attrs_get_string_array); + /* Add all test cases to the test suite */ suite_add_tcase(s, tc_sysdb); |