]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
util/tests: add test for BINARY_ARRAY_SEARCH_V macro
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 19 Feb 2016 02:39:38 +0000 (15:39 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 9 Mar 2016 09:32:16 +0000 (10:32 +0100)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/util/tests/binsearch.c

index f8a02275ac9a1486163180b2986853c1655a8f1a..c6ef47e85d0402818d9e68fd542adaa4a385691e 100644 (file)
@@ -31,6 +31,30 @@ static int int_cmp(int a, int b)
        return a - b;
 }
 
+static bool test_binsearch_v(struct torture_context *tctx)
+{
+       int array[] = { -11, -7, 0, 1, 723, 1000000};
+       int misses[] = { -121, 17, -10, 10, -1, -723, 1000002};
+       int i;
+       int *result = NULL;
+
+       for (i = 0; i < ARRAY_SIZE(misses); i++) {
+               BINARY_ARRAY_SEARCH_V(array, ARRAY_SIZE(array),
+                                     misses[i], int_cmp, result);
+               torture_comment(tctx, "looking for misses[%d] == %d\n", i, misses[i]);
+               torture_assert(tctx, result == NULL, "failed to miss");
+       }
+
+       for (i = 0; i < ARRAY_SIZE(array); i++) {
+               BINARY_ARRAY_SEARCH_V(array, ARRAY_SIZE(array),
+                                     array[i], int_cmp, result);
+               torture_comment(tctx, "looking for array[%d] == %d, %p; got %p\n",
+                               i, array[i], &array[i], result);
+               torture_assert(tctx, result == &array[i],
+                              "failed to find element");
+       }
+       return true;
+}
 
 static bool test_binsearch_gte(struct torture_context *tctx)
 {