dovecot-2.2: lib: test-array - test new lsearch helper

dovecot at dovecot.org dovecot at dovecot.org
Mon Jan 5 20:20:34 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/fa815914dce6
changeset: 18133:fa815914dce6
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Jan 05 22:13:59 2015 +0200
description:
lib: test-array - test new lsearch helper
Just piggy-back on to the current reverse test, as that's got an array
nicely set up for us already.

Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib/test-array.c |  19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diffs (40 lines):

diff -r 1bbec03202e0 -r fa815914dce6 src/lib/test-array.c
--- a/src/lib/test-array.c	Mon Jan 05 22:12:48 2015 +0200
+++ b/src/lib/test-array.c	Mon Jan 05 22:13:59 2015 +0200
@@ -32,11 +32,17 @@
 	test_end();
 }
 
+static int test_int_compare(const int *key, const int *elem)
+{
+	return (*key < *elem) ? -1 :
+		(*key > *elem) ? 1 :
+		0;
+}
 static void test_array_reverse(void)
 {
 	ARRAY(int) intarr;
 	int input[] = { -1234567890, -272585721, 272485922, 824725652 };
-	const int *output;
+	const int tmpi = 999, *output;
 	unsigned int i, j;
 
 	test_begin("array reverse");
@@ -51,6 +57,17 @@
 			test_assert(input[i-j-1] == output[j]);
 	}
 	test_end();
+
+	test_begin("array_lsearch");
+	for (i = 0; i < N_ELEMENTS(input); i++) {
+		output = array_lsearch(&intarr, &input[i], test_int_compare);
+		test_assert(output != NULL);
+		j = array_ptr_to_idx(&intarr, output);
+		test_assert_idx(j == N_ELEMENTS(input) - 1 - i, i);
+	}
+	output = array_lsearch(&intarr, &tmpi, test_int_compare);
+	test_assert(output == NULL);
+	test_end();
 }
 static int test_compare_ushort(const unsigned short *c1, const unsigned short *c2)
 {


More information about the dovecot-cvs mailing list