34 #include "iqrytype.h" |
34 #include "iqrytype.h" |
35 #include "cpixexc.h" |
35 #include "cpixexc.h" |
36 #include "cpixhits.h" |
36 #include "cpixhits.h" |
37 #include "idxdbdelta.h" |
37 #include "idxdbdelta.h" |
38 |
38 |
|
39 #include "std_log_result.h" |
|
40 |
39 void TestBaseAppClassCollision(Itk::TestMgr * testMgr) |
41 void TestBaseAppClassCollision(Itk::TestMgr * testMgr) |
40 { |
42 { |
41 cpix_Result |
43 cpix_Result |
42 result; |
44 result; |
43 |
45 char *xml_file = (char*)__FUNCTION__; |
|
46 assert_failed = 0; |
44 cpix_IdxDb_defineVolume(&result, |
47 cpix_IdxDb_defineVolume(&result, |
45 SMS_QBASEAPPCLASS, |
48 SMS_QBASEAPPCLASS, |
46 NULL); |
49 NULL); |
47 |
50 if(!cpix_Succeeded(&result)) |
|
51 assert_failed = 1; |
48 ITK_ASSERT(testMgr, |
52 ITK_ASSERT(testMgr, |
49 cpix_Succeeded(&result), |
53 cpix_Succeeded(&result), |
50 "Definition of volume (%s, %s) failed.", |
54 "Definition of volume (%s, %s) failed.", |
51 SMS_QBASEAPPCLASS, |
55 SMS_QBASEAPPCLASS, |
52 "<default>"); |
56 "<default>"); |
53 |
57 |
54 cpix_IdxDb_defineVolume(&result, |
58 cpix_IdxDb_defineVolume(&result, |
55 SMS_QBASEAPPCLASS, |
59 SMS_QBASEAPPCLASS, |
56 NULL); |
60 NULL); |
57 |
61 if(!cpix_Succeeded(&result)) |
|
62 assert_failed = 1; |
58 ITK_ASSERT(testMgr, |
63 ITK_ASSERT(testMgr, |
59 cpix_Succeeded(&result), |
64 cpix_Succeeded(&result), |
60 "Re-definition of identical volume (%s, %s) failed.", |
65 "Re-definition of identical volume (%s, %s) failed.", |
61 SMS_QBASEAPPCLASS, |
66 SMS_QBASEAPPCLASS, |
62 "<default>"); |
67 "<default>"); |
65 * dummyPath = "\\dummy\\path"; |
70 * dummyPath = "\\dummy\\path"; |
66 |
71 |
67 cpix_IdxDb_defineVolume(&result, |
72 cpix_IdxDb_defineVolume(&result, |
68 SMS_QBASEAPPCLASS, |
73 SMS_QBASEAPPCLASS, |
69 dummyPath); |
74 dummyPath); |
70 |
75 if(!cpix_Succeeded(&result)) |
|
76 assert_failed = 1; |
71 ITK_ASSERT(testMgr, |
77 ITK_ASSERT(testMgr, |
72 cpix_Failed(&result), |
78 cpix_Failed(&result), |
73 "Volume (%s, %s) definition should have failed.", |
79 "Volume (%s, %s) definition should have failed.", |
74 SMS_QBASEAPPCLASS, |
80 SMS_QBASEAPPCLASS, |
75 dummyPath); |
81 dummyPath); |
76 |
82 |
77 cpix_IdxDb_undefineVolume("@0:root foo bar"); |
83 cpix_IdxDb_undefineVolume("@0:root foo bar"); |
|
84 testResultXml(xml_file); |
78 } |
85 } |
79 |
86 |
80 |
87 |
81 #define DUMMY_QBASEAPPCLASS "@0:root dummy" |
88 #define DUMMY_QBASEAPPCLASS "@0:root dummy" |
82 #define DUMMY2_QBASEAPPCLASS "@0:root dummy2" |
89 #define DUMMY2_QBASEAPPCLASS "@0:root dummy2" |
85 |
92 |
86 void TestIdxDbPathCollision(Itk::TestMgr * testMgr) |
93 void TestIdxDbPathCollision(Itk::TestMgr * testMgr) |
87 { |
94 { |
88 cpix_Result |
95 cpix_Result |
89 result; |
96 result; |
90 |
97 char *xml_file = (char*)__FUNCTION__; |
|
98 assert_failed = 0; |
91 cpix_IdxDb_defineVolume(&result, |
99 cpix_IdxDb_defineVolume(&result, |
92 DUMMY_QBASEAPPCLASS, |
100 DUMMY_QBASEAPPCLASS, |
93 DUMMY_IDXDBPATH); |
101 DUMMY_IDXDBPATH); |
|
102 if(!cpix_Succeeded(&result)) |
|
103 assert_failed = 1; |
94 ITK_ASSERT(testMgr, |
104 ITK_ASSERT(testMgr, |
95 cpix_Succeeded(&result), |
105 cpix_Succeeded(&result), |
96 "Defining volume %s, %s failed.", |
106 "Defining volume %s, %s failed.", |
97 DUMMY_QBASEAPPCLASS, |
107 DUMMY_QBASEAPPCLASS, |
98 DUMMY_IDXDBPATH); |
108 DUMMY_IDXDBPATH); |
99 |
109 |
100 cpix_IdxDb_defineVolume(&result, |
110 cpix_IdxDb_defineVolume(&result, |
101 DUMMY2_QBASEAPPCLASS, |
111 DUMMY2_QBASEAPPCLASS, |
102 DUMMY_IDXDBPATH); |
112 DUMMY_IDXDBPATH); |
103 |
113 if(!cpix_Succeeded(&result)) |
|
114 assert_failed = 1; |
104 ITK_ASSERT(testMgr, |
115 ITK_ASSERT(testMgr, |
105 cpix_Failed(&result), |
116 cpix_Failed(&result), |
106 "Defining volume %s, %s should have failed.", |
117 "Defining volume %s, %s should have failed.", |
107 DUMMY2_QBASEAPPCLASS, |
118 DUMMY2_QBASEAPPCLASS, |
108 DUMMY_IDXDBPATH); |
119 DUMMY_IDXDBPATH); |
|
120 testResultXml(xml_file); |
109 } |
121 } |
110 |
122 |
111 |
123 |
112 |
124 |
113 void TestScrapAll(Itk::TestMgr * testMgr) |
125 void TestScrapAll(Itk::TestMgr * testMgr) |
114 { |
126 { |
115 cpix_Result |
127 cpix_Result |
116 result; |
128 result; |
|
129 char *xml_file = (char*)__FUNCTION__; |
|
130 assert_failed = 0; |
117 |
131 |
118 cpix_IdxDb_defineVolume(&result, |
132 cpix_IdxDb_defineVolume(&result, |
119 SMS_QBASEAPPCLASS, |
133 SMS_QBASEAPPCLASS, |
120 NULL); |
134 NULL); |
121 if (cpix_Succeeded(&result)) |
135 if (cpix_Succeeded(&result)) |
146 |
161 |
147 if (cpix_Succeeded(&result)) |
162 if (cpix_Succeeded(&result)) |
148 { |
163 { |
149 cpix_IdxDb_releaseDb(idxDb); |
164 cpix_IdxDb_releaseDb(idxDb); |
150 } |
165 } |
|
166 else |
|
167 { |
|
168 assert_failed = 1; |
|
169 } |
151 |
170 |
152 ITK_ASSERT(testMgr, |
171 ITK_ASSERT(testMgr, |
153 cpix_Failed(&result), |
172 cpix_Failed(&result), |
154 "Opening IdxDb(%s) should have failed now.", |
173 "Opening IdxDb(%s) should have failed now.", |
155 SMS_QBASEAPPCLASS); |
174 SMS_QBASEAPPCLASS); |
|
175 testResultXml(xml_file); |
156 } |
176 } |
157 |
177 |
158 const wchar_t * QryStrings[] = { |
178 const wchar_t * QryStrings[] = { |
159 |
179 |
160 // should pass: |
180 // should pass: |
214 |
235 |
215 printf("\to inner qry: '%S'\n", |
236 printf("\to inner qry: '%S'\n", |
216 qc.innerQryStr_.c_str()); |
237 qc.innerQryStr_.c_str()); |
217 |
238 |
218 } catch (CpixExc & cpixExc) { |
239 } catch (CpixExc & cpixExc) { |
|
240 assert_failed = 1; |
219 printf("Failed to parse: %S\n", |
241 printf("Failed to parse: %S\n", |
220 cpixExc.wWhat()); |
242 cpixExc.wWhat()); |
221 } catch (...) { |
243 } catch (...) { |
|
244 assert_failed = 1; |
222 printf("Failed t parse: for unknown reasons\n"); |
245 printf("Failed t parse: for unknown reasons\n"); |
223 } |
246 } |
224 } |
247 } |
|
248 testResultXml(xml_file); |
225 } |
249 } |
226 |
250 |
227 |
251 |
228 class PageContext : public Itk::ITestContext |
252 class PageContext : public Itk::ITestContext |
229 { |
253 { |
334 ITK_DBGMSG(mgr, |
360 ITK_DBGMSG(mgr, |
335 "."); |
361 "."); |
336 } |
362 } |
337 } |
363 } |
338 util_->flush(); |
364 util_->flush(); |
|
365 testResultXml(xml_file); |
339 } |
366 } |
340 |
367 |
341 |
368 |
342 void testSearchPages(Itk::TestMgr * mgr) |
369 void testSearchPages(Itk::TestMgr * mgr) |
343 { |
370 { |
344 cpix_Hits |
371 cpix_Hits |
345 * hits = cpix_IdxDb_search(util_->idxDb(), |
372 * hits = cpix_IdxDb_search(util_->idxDb(), |
346 query_); |
373 query_); |
347 |
374 char *xml_file = (char*)__FUNCTION__; |
|
375 assert_failed = 0; |
348 if (cpix_Failed(util_->idxDb())) |
376 if (cpix_Failed(util_->idxDb())) |
349 { |
377 { |
350 ITK_EXPECT(mgr, |
378 ITK_EXPECT(mgr, |
351 false, |
379 false, |
352 "Failed to search index"); |
380 "Failed to search index"); |
353 cpix_ClearError(util_->idxDb()); |
381 cpix_ClearError(util_->idxDb()); |
|
382 assert_failed = 1; |
354 } |
383 } |
355 else |
384 else |
356 { |
385 { |
357 int32_t |
386 int32_t |
358 hitsLength = cpix_Hits_length(hits); |
387 hitsLength = cpix_Hits_length(hits); |
360 ITK_EXPECT(mgr, |
389 ITK_EXPECT(mgr, |
361 expectedHitCount_ == hitsLength, |
390 expectedHitCount_ == hitsLength, |
362 "Did not get expected hitcounts (%d), but %d", |
391 "Did not get expected hitcounts (%d), but %d", |
363 expectedHitCount_, |
392 expectedHitCount_, |
364 hitsLength); |
393 hitsLength); |
365 |
394 if(expectedHitCount_ != hitsLength) |
|
395 { |
|
396 assert_failed = 1; |
|
397 } |
366 |
398 |
367 printf("Got %d hits\n", |
399 printf("Got %d hits\n", |
368 hitsLength); |
400 hitsLength); |
369 |
401 |
370 search(hits, |
402 search(hits, |
987 |
1020 |
988 void testStartStage(Itk::TestMgr * mgr) |
1021 void testStartStage(Itk::TestMgr * mgr) |
989 { |
1022 { |
990 using namespace lucene::index; |
1023 using namespace lucene::index; |
991 using namespace std; |
1024 using namespace std; |
992 |
1025 char *xml_file = (char*)__FUNCTION__; |
|
1026 assert_failed = 0; |
993 printf("Start state of index:\n"); |
1027 printf("Start state of index:\n"); |
994 |
1028 |
995 { |
1029 { |
996 auto_ptr<IndexReader> |
1030 auto_ptr<IndexReader> |
997 reader(IndexReader::open(deltaIdxDbPath_.c_str())); |
1031 reader(IndexReader::open(deltaIdxDbPath_.c_str())); |
1029 result = reader_.getReader()->deleteDocuments(term.get()); |
1064 result = reader_.getReader()->deleteDocuments(term.get()); |
1030 |
1065 |
1031 ITK_EXPECT(mgr, |
1066 ITK_EXPECT(mgr, |
1032 result == 1, |
1067 result == 1, |
1033 "Should have deleted exactly one doc"); |
1068 "Should have deleted exactly one doc"); |
1034 |
1069 if(result != 0) |
|
1070 assert_failed = 1; |
1035 printf("... deleted doc %S\n", |
1071 printf("... deleted doc %S\n", |
1036 DeltaSmsesToDelete[i]); |
1072 DeltaSmsesToDelete[i]); |
1037 } |
1073 } |
1038 } |
1074 } |
|
1075 testResultXml(xml_file); |
1039 } |
1076 } |
1040 |
1077 |
1041 |
1078 |
1042 |
1079 |
1043 struct TestCommitStageExc |
1080 struct TestCommitStageExc |
1083 |
1120 |
1084 void testCommitToDisk(Itk::TestMgr * mgr) |
1121 void testCommitToDisk(Itk::TestMgr * mgr) |
1085 { |
1122 { |
1086 using namespace lucene::search; |
1123 using namespace lucene::search; |
1087 using namespace Cpix::Impl; |
1124 using namespace Cpix::Impl; |
1088 |
1125 char *xml_file = (char*)__FUNCTION__; |
|
1126 assert_failed = 0; |
1089 // The TestCommitStageAction instance we give is to emulate |
1127 // The TestCommitStageAction instance we give is to emulate |
1090 // interrupting the committing-to-disk process at different |
1128 // interrupting the committing-to-disk process at different |
1091 // stages, and see if we can recover whatever information can |
1129 // stages, and see if we can recover whatever information can |
1092 // be from whatever has been committed to disk up to that |
1130 // be from whatever has been committed to disk up to that |
1093 // point. The interrupt is done by throwing a test exception |
1131 // point. The interrupt is done by throwing a test exception |
1125 ITK_EXPECT(mgr, |
1163 ITK_EXPECT(mgr, |
1126 Cpt::directoryexists(deltaIdxDbPath.c_str()), |
1164 Cpt::directoryexists(deltaIdxDbPath.c_str()), |
1127 "Complete, committed, updated idx dir should exist (%s): %s", |
1165 "Complete, committed, updated idx dir should exist (%s): %s", |
1128 test_.c_str(), |
1166 test_.c_str(), |
1129 deltaIdxDbPath.c_str()); |
1167 deltaIdxDbPath.c_str()); |
|
1168 if(!Cpt::directoryexists(deltaIdxDbPath.c_str())) |
|
1169 { |
|
1170 assert_failed = 1; |
|
1171 } |
1130 } |
1172 } |
1131 } |
1173 } |
1132 else |
1174 else |
1133 { |
1175 { |
|
1176 assert_failed = 1; |
1134 ITK_EXPECT(mgr, |
1177 ITK_EXPECT(mgr, |
1135 false, |
1178 false, |
1136 "Should have been interrupted at stage %d", |
1179 "Should have been interrupted at stage %d", |
1137 targetCommitStage_); |
1180 targetCommitStage_); |
1138 } |
1181 } |
1139 } |
1182 } |
1140 catch (TestCommitStageExc & exc) |
1183 catch (TestCommitStageExc & exc) |
1141 { |
1184 { |
|
1185 assert_failed = 1; |
1142 if (exc.commitStage_ == targetCommitStage_) |
1186 if (exc.commitStage_ == targetCommitStage_) |
1143 { |
1187 { |
1144 properlyInterrupted = true; |
1188 properlyInterrupted = true; |
1145 } |
1189 } |
1146 } |
1190 } |
1156 ITK_EXPECT(mgr, |
1200 ITK_EXPECT(mgr, |
1157 (insertBuf_ == NULL |
1201 (insertBuf_ == NULL |
1158 || insertBuf_->isEmpty() |
1202 || insertBuf_->isEmpty() |
1159 || targetCommitStage_ < CS_IBUF_COMMITTING), |
1203 || targetCommitStage_ < CS_IBUF_COMMITTING), |
1160 "Expected the (test) insert buffer to be closed"); |
1204 "Expected the (test) insert buffer to be closed"); |
1161 |
1205 if(!properlyInterrupted || (haveReader_ || reader_.isOpen() ) || !((insertBuf_ == NULL |
|
1206 || insertBuf_->isEmpty() || targetCommitStage_ < CS_IBUF_COMMITTING))) |
|
1207 { |
|
1208 assert_failed = 1; |
|
1209 } |
|
1210 testResultXml(xml_file); |
1162 } |
1211 } |
1163 |
1212 |
1164 |
1213 |
1165 void testRecoveredStage(Itk::TestMgr * ) |
1214 void testRecoveredStage(Itk::TestMgr * ) |
1166 { |
1215 { |
|
1216 char *xml_file = (char*)__FUNCTION__; |
|
1217 assert_failed = 0; |
1167 if (reader_.isOpen()) |
1218 if (reader_.isOpen()) |
1168 { |
1219 { |
1169 printf("Reader (either the original or the re-created):\n"); |
1220 printf("Reader (either the original or the re-created):\n"); |
1170 searchAndPrint(reader_.getReader()); |
1221 searchAndPrint(reader_.getReader()); |
1171 reader_.close(NULL); |
1222 reader_.close(NULL); |
1373 |
1425 |
1374 SuiteTester |
1426 SuiteTester |
1375 * whiteBox = new SuiteTester("whitebox"); |
1427 * whiteBox = new SuiteTester("whitebox"); |
1376 |
1428 |
1377 whiteBox->add("baccoll", |
1429 whiteBox->add("baccoll", |
1378 &TestBaseAppClassCollision); |
1430 &TestBaseAppClassCollision, |
|
1431 "baccoll"); |
1379 whiteBox->add("idpcoll", |
1432 whiteBox->add("idpcoll", |
1380 &TestIdxDbPathCollision); |
1433 &TestIdxDbPathCollision, |
|
1434 "idpcoll"); |
1381 whiteBox->add("scrapall", |
1435 whiteBox->add("scrapall", |
1382 &TestScrapAll); |
1436 &TestScrapAll, |
|
1437 "scrapall"); |
1383 |
1438 |
1384 whiteBox->add("unifiedSearchParse", |
1439 whiteBox->add("unifiedSearchParse", |
1385 &TestUnifiedSearchParse, |
1440 &TestUnifiedSearchParse, |
1386 "unifiedSearchParse"); |
1441 "unifiedSearchParse"); |
1387 |
1442 |