From: Sebastian B. <sb...@us...> - 2014-01-19 18:35:26
|
Update of /cvsroot/simplemail/simplemail/tests In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv22931/tests Modified Files: index_unittest.c makefile Added Files: of-human-bondage.txt.gz Log Message: Added "Of Human Bondage" for testing purposes. --- NEW FILE: of-human-bondage.txt.gz --- (This appears to be a binary file; contents omitted.) Index: index_unittest.c =================================================================== RCS file: /cvsroot/simplemail/simplemail/tests/index_unittest.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- index_unittest.c 19 Jan 2014 18:34:17 -0000 1.9 +++ index_unittest.c 19 Jan 2014 18:35:24 -0000 1.10 @@ -128,6 +128,48 @@ /*******************************************************/ + +/** + * Read the content of the file given by the filename. + * + * @param filename the name of the file which should be read. + * + * @return the contents or NULL on an error. The returned + * value must be freed with free() when no longer in use. + */ +static char *read_file_contents(const char *filename) +{ + long size; + char *ret = NULL; + char *contents = NULL; + FILE *fh; + + if (!(fh = fopen(filename,"r"))) + return NULL; + + fseek(fh,0,SEEK_END); + size = ftell(fh); + if (size < 1) + goto out; + fseek(fh,0,SEEK_SET); + + if (!(contents = malloc(size+1))) + goto out; + if ((fread(contents, 1, size, fh) != size)) + goto out; + contents[size] = 0; + + ret = contents; + contents = NULL; +out: + fclose(fh); + free(contents); + return ret; +} + + +/*******************************************************/ + static int test_index_naive_callback_called; static int test_index_naive_callback(int did, void *userdata) @@ -144,6 +186,7 @@ static void test_index_for_algorithm(struct index_algorithm *alg, const char *name) { struct index *index; + char *text; int ok; int nd; @@ -161,6 +204,12 @@ ok = index_put_document(index,20,zauberlehrling); CU_ASSERT(ok != 0); + text = read_file_contents("of-human-bondage.txt"); + CU_ASSERT(text != NULL); + + ok = index_put_document(index,32,text); + CU_ASSERT(ok != 0); + nd = index_find_documents(index,test_index_naive_callback,NULL,1,"very"); CU_ASSERT(test_index_naive_callback_called == 1); CU_ASSERT(nd == 1); @@ -172,6 +221,7 @@ CU_ASSERT(nd == 0); index_dispose(index); + free(text); } /*******************************************************/ Index: makefile =================================================================== RCS file: /cvsroot/simplemail/simplemail/tests/makefile,v retrieving revision 1.41 retrieving revision 1.42 diff -u -d -r1.41 -r1.42 --- makefile 24 Dec 2013 09:23:38 -0000 1.41 +++ makefile 19 Jan 2014 18:35:24 -0000 1.42 @@ -45,6 +45,11 @@ perl gen-stubs.pl <test-objs/$@error >$@stubs.c $(CC) $@stubs.c unittest_tmpl.c -DUNITTEST_TABLE=\"$@_table.c\" -DUNITTEST_FILE=\"$<\" $(CFLAGS) -lcunit -L. -l$(SIMPLEMAIL_LIB) $(GLIB_LDFLAGS) $(GTK_LDFLAGS) -o $@ +of-human-bondage.txt: of-human-bondage.txt.gz + gzip -c -d $< >$@ + +index_unittest: of-human-bondage.txt + .PHONY: all all: files $(TESTEXES) memleaks |