summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>2017-07-06 12:41:07 +1200
committerStefan Metzmacher <metze@samba.org>2017-07-23 10:27:22 +0200
commitbed75c17ca4d19aa8f02c0daa1ce9e6659f03b8c (patch)
tree23109a4fbec8b589e670e226e025d62b623b3e36 /lib
parent7eda7c5d16b857d5cc18546a118e15ed69a5d3fb (diff)
downloadsamba-bed75c17ca4d19aa8f02c0daa1ce9e6659f03b8c.tar.gz
ldb/tests: more thoroughly test empty ldb_msg elements
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Fri Jul 7 20:10:37 CEST 2017 on sn-devel-144 (cherry picked from commit 4b3de6118569eb9a1d4f233eca112d0d207c1087)
Diffstat (limited to 'lib')
-rw-r--r--lib/ldb/tests/ldb_msg.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/lib/ldb/tests/ldb_msg.c b/lib/ldb/tests/ldb_msg.c
index e665d5545b2..f8de418e0dc 100644
--- a/lib/ldb/tests/ldb_msg.c
+++ b/lib/ldb/tests/ldb_msg.c
@@ -87,6 +87,11 @@ static void test_ldb_msg_find_duplicate_val(void **state)
ret = ldb_msg_add_empty(msg, "el1", 0, &el);
assert_int_equal(ret, LDB_SUCCESS);
+ /* An empty message contains no duplicates */
+ ret = ldb_msg_find_duplicate_val(NULL, test_ctx, el, &dupe, 0);
+ assert_int_equal(ret, LDB_SUCCESS);
+ assert_null(dupe);
+
for (i = 0; i < 5; i++) {
add_uint_value(test_ctx, msg, "el1", i);
}
@@ -176,19 +181,19 @@ static void _assert_element_equal(struct ldb_message_element *a,
static void test_ldb_msg_find_common_values(void **state)
{
/* we only use the state as a talloc context */
- struct ldb_message_element *el, *el2, *el3, *el4, *el2b;
+ struct ldb_message_element *el, *el2, *el3, *el4, *el2b, *empty;
struct ldb_message_element *orig, *orig2, *orig3, *orig4;
int ret;
const uint32_t remove_dupes = LDB_MSG_FIND_COMMON_REMOVE_DUPLICATES;
el = new_msg_element(*state, "test", 0, 4);
el2 = new_msg_element(*state, "test", 4, 4);
el3 = new_msg_element(*state, "test", 6, 4);
+ empty = new_msg_element(*state, "test", 0, 0);
orig = new_msg_element(*state, "test", 0, 4);
orig2 = new_msg_element(*state, "test", 4, 4);
orig3 = new_msg_element(*state, "test", 6, 4);
/* first round is with short value arrays, using quadratic method */
-
/* we expect no collisions here */
ret = ldb_msg_find_common_values(NULL, *state, el, el2, 0);
assert_int_equal(ret, LDB_SUCCESS);
@@ -256,7 +261,7 @@ static void test_ldb_msg_find_common_values(void **state)
assert_element_equal(el2, orig2);
assert_int_equal(el3->num_values, 0);
- /* seeing as we have an empty element, try permutations therewith.
+ /* permutations involving empty elements.
everything should succeed. */
ret = ldb_msg_find_common_values(NULL, *state, el3, el2, 0);
assert_int_equal(ret, LDB_SUCCESS);
@@ -264,10 +269,19 @@ static void test_ldb_msg_find_common_values(void **state)
assert_int_equal(ret, LDB_SUCCESS);
ret = ldb_msg_find_common_values(NULL, *state, el2, el3, 0);
assert_int_equal(ret, LDB_SUCCESS);
+ assert_int_equal(el2->num_values, orig2->num_values);
ret = ldb_msg_find_common_values(NULL, *state, el3, el2, remove_dupes);
assert_int_equal(ret, LDB_SUCCESS);
+ assert_int_equal(el2->num_values, orig2->num_values);
+ assert_int_equal(el3->num_values, 0); /* el3 is now empty */
ret = ldb_msg_find_common_values(NULL, *state, el2, el3, remove_dupes);
assert_int_equal(ret, LDB_SUCCESS);
+ ret = ldb_msg_find_common_values(NULL, *state, el3, empty, 0);
+ assert_int_equal(ret, LDB_SUCCESS);
+ ret = ldb_msg_find_common_values(NULL, *state, empty, empty, 0);
+ assert_int_equal(ret, LDB_SUCCESS);
+ ret = ldb_msg_find_common_values(NULL, *state, empty, el3, 0);
+ assert_int_equal(ret, LDB_SUCCESS);
assert_element_equal(el2, orig2);
assert_element_equal(el, orig);
@@ -329,6 +343,18 @@ static void test_ldb_msg_find_common_values(void **state)
orig2 = new_msg_element(*state, "test", 12, 2);
assert_element_equal(el2, orig2);
+ /* test the empty el against the full elements */
+ ret = ldb_msg_find_common_values(NULL, *state, el, empty, 0);
+ assert_int_equal(ret, LDB_SUCCESS);
+ ret = ldb_msg_find_common_values(NULL, *state, empty, el, 0);
+ assert_int_equal(ret, LDB_SUCCESS);
+ ret = ldb_msg_find_common_values(NULL, *state, el, empty, remove_dupes);
+ assert_int_equal(ret, LDB_SUCCESS);
+ ret = ldb_msg_find_common_values(NULL, *state, empty, el, remove_dupes);
+ assert_int_equal(ret, LDB_SUCCESS);
+ assert_element_equal(el, orig);
+ assert_element_equal(empty, el3);
+
/* make sure an identical element with a different name is rejected */
el2 = new_msg_element(*state, "fish", 12, 2);
ret = ldb_msg_find_common_values(NULL, *state, el2, el, remove_dupes);