Skip to content

Commit

Permalink
ldb: tests for <= and >= integer indexing with duplicates
Browse files Browse the repository at this point in the history
We need to make sure that duplicates are correctly returned (uSNChanged
for instance is UNIQUE but, we should be able to index on attributes
which are not unique).

Signed-off-by: Garming Sam <[email protected]>
Reviewed-by: Andrew Bartlett <[email protected]>
  • Loading branch information
GSam authored and abartlet committed Apr 8, 2019
1 parent 18438c8 commit 2e05fd7
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
43 changes: 43 additions & 0 deletions lib/ldb-samba/tests/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,49 @@ def assert_int32_expr(expr, py_expr=None):
assert_int32_expr(">=" + str(int32_max-1))
assert_int32_expr("=10", "==10")

def test_comparison_expression_duplicates(self):
self.l.samba_schema_attribute_add("int32attr", 0,
_ldb.SYNTAX_SAMBA_INT32)

int32_max = 2**31-1
int32_min = -2**31

test_nums = list(range(-5, 5)) * 3
test_nums += list(range(-20, 20, 5)) * 2
test_nums += list(range(-50, 50, 15))
test_nums = sorted(test_nums)

for i, n in enumerate(test_nums):
ouuid = 0x0123456789abcdef + i
ouuid_s = bytes(('0' + hex(ouuid)[2:]).encode())
self.l.add({"dn": "OU=COMPTESTOU{},DC=SAMBA,DC=ORG".format(i),
"objectUUID": ouuid_s,
"int32attr": str(n)})

def assert_int32_expr(expr, py_expr=None):
res = self.l.search(base="DC=SAMBA,DC=ORG",
scope=SCOPE_SUBTREE,
expression="(int32attr%s)" % (expr))

if not py_expr:
py_expr = expr
expect = [n for n in test_nums if eval(str(n) + py_expr)]
vals = sorted([int(r.get("int32attr")[0]) for r in res])
self.assertEqual(len(res), len(expect))
self.assertEqual(set(vals), set(expect))
self.assertEqual(expect, vals)

assert_int32_expr(">=-2")
assert_int32_expr("<=2")
assert_int32_expr(">=" + str(int32_min))
assert_int32_expr("<=" + str(int32_min))
assert_int32_expr("<=" + str(int32_min+1))
assert_int32_expr("<=" + str(int32_max))
assert_int32_expr(">=" + str(int32_max))
assert_int32_expr(">=" + str(int32_max-1))
assert_int32_expr("=-5", "==-5")
assert_int32_expr("=5", "==5")

# Run the same tests against an lmdb backend
class LdbLMDBIndexedComparisonExpressions(LdbTDBIndexedComparisonExpressions):

Expand Down
39 changes: 39 additions & 0 deletions lib/ldb/tests/python/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,45 @@ def assert_int64_expr(expr, py_expr=None):
assert_int64_expr(">=" + str(int64_max-1))
assert_int64_expr("=10", "==10")

def test_comparison_expression_duplicates(self):
int64_max = 2**63-1
int64_min = -2**63
test_nums = list(range(-5, 5)) * 3
test_nums += list(range(-20, 20, 5)) * 2
test_nums += list(range(-50, 50, 15))
test_nums = sorted(test_nums)

for (i, num) in enumerate(test_nums):
ouuid = 0x0123456789abcdef + i
ouuid_s = bytes(('0' + hex(ouuid)[2:]).encode())
self.l.add({"dn": "OU=COMPTESTOU{},DC=SAMBA,DC=ORG".format(i),
"objectUUID": ouuid_s,
"int64attr": str(num)})

def assert_int64_expr(expr, py_expr=None):
res = self.l.search(base="DC=SAMBA,DC=ORG",
scope=ldb.SCOPE_SUBTREE,
expression="(int64attr%s)" % (expr))

if not py_expr:
py_expr = expr
expect = [n for n in test_nums if eval(str(n) + py_expr)]
vals = sorted([int(r.get("int64attr")[0]) for r in res])
self.assertEqual(len(res), len(expect))
self.assertEqual(set(vals), set(expect))
self.assertEqual(expect, vals)

assert_int64_expr(">=-2")
assert_int64_expr("<=2")
assert_int64_expr(">=" + str(int64_min))
assert_int64_expr("<=" + str(int64_min))
assert_int64_expr("<=" + str(int64_min+1))
assert_int64_expr("<=" + str(int64_max))
assert_int64_expr(">=" + str(int64_max))
assert_int64_expr(">=" + str(int64_max-1))
assert_int64_expr("=-5", "==-5")
assert_int64_expr("=5", "==5")


# Run the ordered integer range tests against an lmdb backend
class OrderedIntegerRangeTestsLmdb(OrderedIntegerRangeTests):
Expand Down

0 comments on commit 2e05fd7

Please sign in to comment.