libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 65a00302a29bb8711a9c61764ec8cb0fe749786e
parent e84f2a947b7429b3ce92bb081d945a9c16f3a1ea
Author: Heikki Lindholm <holin@iki.fi>
Date:   Sun, 22 Jun 2008 08:58:23 +0000

test with multiple files


Diffstat:
Msrc/test/multithreadtest.c | 92++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 56 insertions(+), 36 deletions(-)

diff --git a/src/test/multithreadtest.c b/src/test/multithreadtest.c @@ -78,26 +78,30 @@ compare_keywords_to_ref (EXTRACTOR_KeywordList * list) } static EXTRACTOR_KeywordList * -get_keywords_for_file (struct FileData *file) +get_keywords_for_file (const struct FileData *file) { EXTRACTOR_ExtractorList *el; EXTRACTOR_KeywordList *list; if (file->use_thumbnailer) - { - el = EXTRACTOR_addLibrary (NULL, "libextractor_mime"); - el = EXTRACTOR_loadConfigLibraries (el, "-libextractor_thumbnail"); - } + { + el = EXTRACTOR_addLibrary (NULL, "libextractor_mime"); + el = EXTRACTOR_loadConfigLibraries (el, "-libextractor_thumbnail"); + } else - { - el = EXTRACTOR_loadDefaultLibraries (); - } + { + el = EXTRACTOR_loadDefaultLibraries (); + } if (el == NULL) { printf ("ERROR: failed to load plugins!\n"); return NULL; } + errno = 0; list = EXTRACTOR_getKeywords (el, file->filename); + if (errno != 0) { + printf("ERROR: EXTRACTOR_getKeywords: %s\n", strerror(errno)); + } /*EXTRACTOR_printKeywords (stderr, list); */ EXTRACTOR_removeAll (el); @@ -114,7 +118,7 @@ test_plugins (void *arg) list = get_keywords_for_file (td->file); - if (list == NULL || compare_keywords_to_ref (list) != 0) + if ((list == NULL) || (compare_keywords_to_ref (list) != 0)) { printf ("ERROR: thread id %d failed keyword comparison!\n", td->id); failed = 1; @@ -126,10 +130,17 @@ test_plugins (void *arg) } static const struct FileData files[] = { - { TESTDATADIR "/CatherineCub2.png", 1 }, + { TESTDATADIR "/test.bmp", 0 }, + { TESTDATADIR "/test.jpg", 0 }, + { TESTDATADIR "/test.png", 0 }, + { TESTDATADIR "/test.sxw", 0 }, + { TESTDATADIR "/test.bmp", 1 }, + { TESTDATADIR "/test.png", 1 }, { NULL, 0 } }; +#define TEST_SECS 10 + int main (int argc, char *argv[]) { @@ -138,32 +149,41 @@ main (int argc, char *argv[]) struct TaskData td[num_tasks]; int ret = 0; int i; + int n; + + n = 0; + while ((files[n].filename != NULL) && (!failed)) { + printf("testing with '%s' for %d seconds\n", files[n].filename, TEST_SECS); + reference_list = get_keywords_for_file (&files[n]); + + for (i = 0; i < num_tasks; i++) + { + td[i].id = i; + td[i].file = &files[n]; + ret = pthread_create (&task_list[i], NULL, test_plugins, &td[i]); + if (ret != 0) + { + printf ("ERROR: pthread_create failed for thread %d\n", i); + num_tasks = i; + done = 1; + break; + } + } + if (!done) + sleep (TEST_SECS); + done = 1; + for (i = 0; i < num_tasks; i++) + { + if (pthread_join (task_list[i], NULL) != 0) + printf ("WARNING: pthread_join failed for thread %d\n", i); + } + + done = 0; + if (reference_list != NULL) + EXTRACTOR_freeKeywords (reference_list); + + n++; + } - reference_list = get_keywords_for_file (&files[0]); - - for (i = 0; i < num_tasks; i++) - { - td[i].id = i; - td[i].file = &files[0]; - ret = pthread_create (&task_list[i], NULL, test_plugins, &td[i]); - if (ret != 0) - { - printf ("ERROR: pthread_create failed for thread %d\n", i); - num_tasks = i; - done = 1; - break; - } - } - if (!done) - sleep (20); - done = 1; - for (i = 0; i < num_tasks; i++) - { - if (pthread_join (task_list[i], NULL) != 0) - printf ("WARNING: pthread_join failed for thread %d\n", i); - } - - if (reference_list != NULL) - EXTRACTOR_freeKeywords (reference_list); return failed; }