35 |
35 |
36 #include "config.h" |
36 #include "config.h" |
37 #include "testutils.h" |
37 #include "testutils.h" |
38 #include "suggestion.h" |
38 #include "suggestion.h" |
39 |
39 |
|
40 #include "std_log_result.h" |
|
41 |
40 const char * TermTestDocsToIndex[5] = { |
42 const char * TermTestDocsToIndex[5] = { |
41 FILE_TEST_CORPUS_PATH "\\en\\1.txt", |
43 FILE_TEST_CORPUS_PATH "\\en\\1.txt", |
42 FILE_TEST_CORPUS_PATH "\\en\\2.txt", |
44 FILE_TEST_CORPUS_PATH "\\en\\2.txt", |
43 FILE_TEST_CORPUS_PATH "\\en\\3.txt", |
45 FILE_TEST_CORPUS_PATH "\\en\\3.txt", |
44 FILE_TEST_CORPUS_PATH "\\en\\4.txt", |
46 FILE_TEST_CORPUS_PATH "\\en\\4.txt", |
68 cpix_IdxDb_dbgScrapAll(&result); |
70 cpix_IdxDb_dbgScrapAll(&result); |
69 |
71 |
70 ITK_ASSERT(testMgr, |
72 ITK_ASSERT(testMgr, |
71 cpix_Succeeded(&result), |
73 cpix_Succeeded(&result), |
72 "Could not get rid of all test qbac-idx pairs"); |
74 "Could not get rid of all test qbac-idx pairs"); |
73 |
75 if(!cpix_Succeeded(&result)) |
|
76 { |
|
77 assert_failed = 1; |
|
78 } |
74 std::auto_ptr<FileIdxUtil> util( new FileIdxUtil ); |
79 std::auto_ptr<FileIdxUtil> util( new FileIdxUtil ); |
75 |
80 |
76 util->init(); |
81 util->init(); |
77 |
82 |
78 cpix_Analyzer* analyzer = cpix_CreateSimpleAnalyzer(&result); |
83 cpix_Analyzer* analyzer = cpix_CreateSimpleAnalyzer(&result); |
79 |
84 |
80 if ( cpix_Failed( &result) ) ITK_PANIC("Analyzer could not be created"); |
85 if ( cpix_Failed( &result) ) ITK_PANIC("Analyzer could not be created"); |
|
86 if(!cpix_Succeeded(&result)) |
|
87 { |
|
88 assert_failed = 1; |
|
89 } |
81 |
90 |
82 for (int i = 0; TermTestDocsToIndex[i]; i++) |
91 for (int i = 0; TermTestDocsToIndex[i]; i++) |
83 { |
92 { |
84 util->indexFile( TermTestDocsToIndex[i], analyzer, testMgr ); |
93 util->indexFile( TermTestDocsToIndex[i], analyzer, testMgr ); |
85 } |
94 } |
98 LCPIX_DEFAULT_FIELD, |
107 LCPIX_DEFAULT_FIELD, |
99 analyzer ); |
108 analyzer ); |
100 if (queryParser == NULL) |
109 if (queryParser == NULL) |
101 { |
110 { |
102 cpix_Analyzer_destroy( analyzer ); |
111 cpix_Analyzer_destroy( analyzer ); |
103 ITK_PANIC("Could not create query parser"); |
112 assert_failed = 1; |
|
113 ITK_PANIC("Could not create query parser"); |
104 } |
114 } |
105 |
115 |
106 std::wostringstream queryString; |
116 std::wostringstream queryString; |
107 if ( appclassPrefix ) { |
117 if ( appclassPrefix ) { |
108 queryString<<L"$terms<5,'"<<appclassPrefix<<L"'>("<<TermsSearchParameters[i]<<L")"; |
118 queryString<<L"$terms<5,'"<<appclassPrefix<<L"'>("<<TermsSearchParameters[i]<<L")"; |
113 cpix_Query* query = cpix_QueryParser_parse(queryParser, |
123 cpix_Query* query = cpix_QueryParser_parse(queryParser, |
114 queryString.str().c_str()); |
124 queryString.str().c_str()); |
115 if (cpix_Failed(queryParser) |
125 if (cpix_Failed(queryParser) |
116 || query == NULL) |
126 || query == NULL) |
117 { |
127 { |
|
128 assert_failed = 1; |
118 cpix_Analyzer_destroy(analyzer); |
129 cpix_Analyzer_destroy(analyzer); |
119 cpix_ClearError(queryParser); |
130 cpix_ClearError(queryParser); |
120 cpix_QueryParser_destroy(queryParser); |
131 cpix_QueryParser_destroy(queryParser); |
121 ITK_PANIC("Could not parse query string"); |
132 ITK_PANIC("Could not parse query string"); |
122 } |
133 } |
160 } |
172 } |
161 |
173 |
162 if (cpix_Failed(queryParser_) |
174 if (cpix_Failed(queryParser_) |
163 || query == NULL) |
175 || query == NULL) |
164 { |
176 { |
|
177 assert_failed = 1; |
165 cpix_Analyzer_destroy(analyzer); |
178 cpix_Analyzer_destroy(analyzer); |
166 cpix_ClearError(queryParser_); |
179 cpix_ClearError(queryParser_); |
167 cpix_QueryParser_destroy(queryParser_); |
180 cpix_QueryParser_destroy(queryParser_); |
168 ITK_PANIC("Could not parse query string"); |
181 ITK_PANIC("Could not parse query string"); |
169 } |
182 } |
189 |
202 |
190 cpix_Analyzer_destroy( analyzer ); |
203 cpix_Analyzer_destroy( analyzer ); |
191 } |
204 } |
192 |
205 |
193 void TestAllTermSearch(Itk::TestMgr * testMgr) |
206 void TestAllTermSearch(Itk::TestMgr * testMgr) |
194 { |
207 { |
|
208 char *xml_file = (char*)__FUNCTION__; |
|
209 assert_failed = 0; |
195 TestAppclassFilteredTermSearch(testMgr, 0); |
210 TestAppclassFilteredTermSearch(testMgr, 0); |
|
211 testResultXml(xml_file); |
196 } |
212 } |
197 |
213 |
198 void TestMp3TermSearch(Itk::TestMgr * testMgr) |
214 void TestMp3TermSearch(Itk::TestMgr * testMgr) |
199 { |
215 { |
|
216 char *xml_file = (char*)__FUNCTION__; |
|
217 assert_failed = 0; |
200 TestAppclassFilteredTermSearch(testMgr, LMP3APPCLASS); |
218 TestAppclassFilteredTermSearch(testMgr, LMP3APPCLASS); |
|
219 testResultXml(xml_file); |
201 } |
220 } |
202 |
221 |
203 void TestTextTermSearch(Itk::TestMgr * testMgr) |
222 void TestTextTermSearch(Itk::TestMgr * testMgr) |
204 { |
223 { |
|
224 char *xml_file = (char*)__FUNCTION__; |
|
225 assert_failed = 0; |
205 TestAppclassFilteredTermSearch(testMgr, LTEXTAPPCLASS); |
226 TestAppclassFilteredTermSearch(testMgr, LTEXTAPPCLASS); |
|
227 testResultXml(xml_file); |
206 } |
228 } |
207 |
229 |
208 Itk::TesterBase * CreateTermSearchTests() |
230 Itk::TesterBase * CreateTermSearchTests() |
209 { |
231 { |
210 using namespace Itk; |
232 using namespace Itk; |
211 |
233 |
212 ContextTester |
234 SuiteTester |
213 * whiteBox = new ContextTester("terms", |
235 * whiteBox = new SuiteTester("terms"); // default context |
214 NULL); // default context |
|
215 |
236 |
216 whiteBox->add("allterms", |
237 whiteBox->add("allterms", |
217 &TestAllTermSearch, |
238 &TestAllTermSearch, |
218 "allterms"); |
239 "allterms"); |
219 |
240 |