From 4790f7b3cff3800df92b232aec1d779db52c72b1 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Wed, 28 Mar 2012 11:51:21 -0400 Subject: Add better dp_option tests --- src/tests/common.c | 26 ++++++++++++++++++++++++++ src/tests/common.h | 6 ++++++ src/tests/ipa_ldap_opt-tests.c | 17 +++++++++++++++++ 3 files changed, 49 insertions(+) (limited to 'src') diff --git a/src/tests/common.c b/src/tests/common.c index cd13507c1..118684ddb 100644 --- a/src/tests/common.c +++ b/src/tests/common.c @@ -41,3 +41,29 @@ tests_set_cwd(void) } } } + +/* Check that the option names of the two maps are the same + * and appear in the same order. + */ +errno_t +compare_dp_options(struct dp_option *map1, size_t size1, + struct dp_option *map2) +{ + size_t i; + + for (i = 0; i < size1; i++) { + /* Check for a valid option */ + if (map1[i].opt_name == NULL) return EINVAL; + + /* Check whether we've gone past the end of map2 */ + if (map2[i].opt_name == NULL) return ERANGE; + + /* Ensure that the option names are the same */ + if(strcmp(map1[i].opt_name, map2[i].opt_name) != 0) return EINVAL; + } + + /* Leftover options in map2 */ + if (map2[i].opt_name != NULL) return ERANGE; + + return EOK; +} diff --git a/src/tests/common.h b/src/tests/common.h index 576d705ba..d0c9abbe1 100644 --- a/src/tests/common.h +++ b/src/tests/common.h @@ -26,6 +26,8 @@ #define __TESTS_COMMON_H__ #include +#include "util/util.h" +#include "providers/data_provider.h" extern TALLOC_CTX *global_talloc_context; @@ -44,4 +46,8 @@ void leak_check_teardown(void); void tests_set_cwd(void); +errno_t +compare_dp_options(struct dp_option *map1, size_t size1, + struct dp_option *map2); + #endif /* !__TESTS_COMMON_H__ */ diff --git a/src/tests/ipa_ldap_opt-tests.c b/src/tests/ipa_ldap_opt-tests.c index 2497c97c2..c66a4738f 100644 --- a/src/tests/ipa_ldap_opt-tests.c +++ b/src/tests/ipa_ldap_opt-tests.c @@ -27,7 +27,9 @@ #include #include "providers/ipa/ipa_common.h" +#include "providers/ipa/ipa_opts.h" #include "providers/ldap/sdap.h" +#include "providers/ldap/ldap_opts.h" #include "providers/krb5/krb5_common.h" #include "tests/common.h" @@ -84,6 +86,20 @@ START_TEST(test_check_num_opts) } END_TEST +START_TEST(test_compare_opts) +{ + errno_t ret; + + ret = compare_dp_options(default_basic_opts, SDAP_OPTS_BASIC, + ipa_def_ldap_opts); + fail_unless(ret == EOK, "[%s]", strerror(ret)); + + ret = compare_dp_options(default_krb5_opts, KRB5_OPTS, + ipa_def_krb5_opts); + fail_unless(ret == EOK, "[%s]", strerror(ret)); +} +END_TEST + Suite *ipa_ldap_opt_suite (void) { Suite *s = suite_create ("ipa_ldap_opt"); @@ -91,6 +107,7 @@ Suite *ipa_ldap_opt_suite (void) TCase *tc_ipa_ldap_opt = tcase_create ("ipa_ldap_opt"); tcase_add_test (tc_ipa_ldap_opt, test_check_num_opts); + tcase_add_test (tc_ipa_ldap_opt, test_compare_opts); suite_add_tcase (s, tc_ipa_ldap_opt); TCase *tc_ipa_utils = tcase_create ("ipa_utils"); -- cgit