From: Sebastian B. <sb...@us...> - 2014-01-19 18:42:47
|
Update of /cvsroot/simplemail/simplemail/tests In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv23825/tests Modified Files: index_unittest.c Log Message: Added function to check whether all suffixes of a string are contained in a index. Use it for Zauberlehrling. Index: index_unittest.c =================================================================== RCS file: /cvsroot/simplemail/simplemail/tests/index_unittest.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- index_unittest.c 19 Jan 2014 18:35:24 -0000 1.10 +++ index_unittest.c 19 Jan 2014 18:42:44 -0000 1.11 @@ -183,6 +183,31 @@ CU_ASSERT(0); } +/*******************************************************/ + +static int test_index_contains_all_suffixes_callback(int did, void *userdata) +{ + (*(int*)userdata) = 1; +} + +static void test_index_contains_all_suffixes(struct index *index, const char *text, int did) +{ + int i; + int textl = strlen(text); + for (i=0; i<textl; i++) + { + int called = 0; + index_find_documents(index, test_index_contains_all_suffixes_callback, &called, 1, text + i); + CU_ASSERT(called == 1); + if (called != 1) + { + fprintf(stderr, "Offset %d couldn't be found\n", i); + } + } +} + +/*******************************************************/ + static void test_index_for_algorithm(struct index_algorithm *alg, const char *name) { struct index *index; @@ -204,6 +229,8 @@ ok = index_put_document(index,20,zauberlehrling); CU_ASSERT(ok != 0); + test_index_contains_all_suffixes(index, zauberlehrling, 20); + text = read_file_contents("of-human-bondage.txt"); CU_ASSERT(text != NULL); |