diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2014-01-28 14:51:58 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-01-29 17:27:55 +0100 |
commit | 407a7e05f9077ccaefe5412f794347e4c9da94bb (patch) | |
tree | eadce60bcc5a1843edfb93aab1c5326a5b9e1900 /src/tests | |
parent | ff4ca560f597303c62b83cc484f33e114e52ba0a (diff) | |
download | sssd-407a7e05f9077ccaefe5412f794347e4c9da94bb.tar.gz sssd-407a7e05f9077ccaefe5412f794347e4c9da94bb.tar.xz sssd-407a7e05f9077ccaefe5412f794347e4c9da94bb.zip |
DB: Add sss_ldb_el_to_string_list
Diffstat (limited to 'src/tests')
-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 63ffac82e..69b09c7d4 100644 --- a/src/tests/sysdb-tests.c +++ b/src/tests/sysdb-tests.c @@ -4449,6 +4449,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; @@ -5217,6 +5263,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); |