From 97d84f3a988b3e8cc4a212c9ac1fe6f8bf9068bb Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Wed, 28 Mar 2012 12:02:45 -0400
Subject: [PATCH 5/6] Add better tests for sdap_attr compability

---
 src/tests/common.c             |   26 ++++++++++++++++++++++++++
 src/tests/common.h             |    5 +++++
 src/tests/ipa_ldap_opt-tests.c |   38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/src/tests/common.c b/src/tests/common.c
index 118684ddb578c93d6d1b99b76b4c539c7ec7d812..3e4753e08be47431ff1999e0f986c6bbb0d2f590 100644
--- a/src/tests/common.c
+++ b/src/tests/common.c
@@ -67,3 +67,29 @@ compare_dp_options(struct dp_option *map1, size_t size1,
 
     return EOK;
 }
+
+/* Check that the option names of the two maps are the same
+ * and appear in the same order.
+ */
+errno_t
+compare_sdap_attr_maps(struct sdap_attr_map *map1, size_t size1,
+                       struct sdap_attr_map *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 d0c9abbe15a9d96c99918b9e7ac647b8545f8a91..f13181b751fef517f609c6208977cc82a825014e 100644
--- a/src/tests/common.h
+++ b/src/tests/common.h
@@ -28,6 +28,7 @@
 #include <talloc.h>
 #include "util/util.h"
 #include "providers/data_provider.h"
+#include "providers/ldap/sdap.h"
 
 extern TALLOC_CTX *global_talloc_context;
 
@@ -50,4 +51,8 @@ errno_t
 compare_dp_options(struct dp_option *map1, size_t size1,
                    struct dp_option *map2);
 
+errno_t
+compare_sdap_attr_maps(struct sdap_attr_map *map1, size_t size1,
+                       struct sdap_attr_map *map2);
+
 #endif /* !__TESTS_COMMON_H__ */
diff --git a/src/tests/ipa_ldap_opt-tests.c b/src/tests/ipa_ldap_opt-tests.c
index c66a4738ff221dd8a0bf5b4bd689c6c156fff550..3f94d68157ee9fb75ffc79f1888a7d43d4df599f 100644
--- a/src/tests/ipa_ldap_opt-tests.c
+++ b/src/tests/ipa_ldap_opt-tests.c
@@ -100,6 +100,43 @@ START_TEST(test_compare_opts)
 }
 END_TEST
 
+START_TEST(test_compare_sdap_attrs)
+{
+    errno_t ret;
+
+    /* General Attributes */
+    ret = compare_sdap_attr_maps(generic_attr_map, SDAP_AT_GENERAL,
+                                 ipa_attr_map);
+    fail_unless(ret == EOK, "[%s]", strerror(ret));
+
+    /* User Attributes */
+    ret = compare_sdap_attr_maps(rfc2307_user_map, SDAP_OPTS_USER,
+                                 ipa_user_map);
+    fail_unless(ret == EOK, "[%s]", strerror(ret));
+
+    /* Group Attributes */
+    ret = compare_sdap_attr_maps(rfc2307_group_map, SDAP_OPTS_GROUP,
+                                 ipa_group_map);
+    fail_unless(ret == EOK, "[%s]", strerror(ret));
+
+    /* Service Attributes */
+    ret = compare_sdap_attr_maps(service_map, SDAP_OPTS_SERVICES,
+                                 ipa_service_map);
+    fail_unless(ret == EOK, "[%s]", strerror(ret));
+
+    /* AutoFS Attributes */
+    ret = compare_sdap_attr_maps(rfc2307_autofs_mobject_map,
+                                 SDAP_OPTS_AUTOFS_MAP,
+                                 ipa_autofs_mobject_map);
+    fail_unless(ret == EOK, "[%s]", strerror(ret));
+
+    ret = compare_sdap_attr_maps(rfc2307_autofs_entry_map,
+                                 SDAP_OPTS_AUTOFS_ENTRY,
+                                 ipa_autofs_entry_map);
+    fail_unless(ret == EOK, "[%s]", strerror(ret));
+}
+END_TEST
+
 Suite *ipa_ldap_opt_suite (void)
 {
     Suite *s = suite_create ("ipa_ldap_opt");
@@ -108,6 +145,7 @@ Suite *ipa_ldap_opt_suite (void)
 
     tcase_add_test (tc_ipa_ldap_opt, test_check_num_opts);
     tcase_add_test (tc_ipa_ldap_opt, test_compare_opts);
+    tcase_add_test (tc_ipa_ldap_opt, test_compare_sdap_attrs);
     suite_add_tcase (s, tc_ipa_ldap_opt);
 
     TCase *tc_ipa_utils = tcase_create ("ipa_utils");
-- 
1.7.7.6

