|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <wchar.h> |
|
19 #include <stddef.h> |
|
20 |
|
21 #include <iostream> |
|
22 #include <algorithm> |
|
23 |
|
24 #include "cpixfstools.h" |
|
25 |
|
26 #include "itk.h" |
|
27 |
|
28 #include "cpixidxdb.h" |
|
29 |
|
30 #include "config.h" |
|
31 #include "suggestion.h" |
|
32 #include "testutils.h" |
|
33 #include "testcorpus.h" |
|
34 #include "setupsentry.h" |
|
35 |
|
36 |
|
37 class DeletionContext : public Itk::ITestContext |
|
38 { |
|
39 private: |
|
40 SmsIdxUtil * util_; |
|
41 cpix_Analyzer * analyzer_; |
|
42 cpix_QueryParser * queryParser_; |
|
43 cpix_Query * query_; |
|
44 |
|
45 |
|
46 public: |
|
47 virtual void setup() throw (Itk::PanicExc) |
|
48 { |
|
49 SetupSentry |
|
50 ss(*this); |
|
51 |
|
52 cpix_Result |
|
53 result; |
|
54 |
|
55 cpix_IdxDb_dbgScrapAll(&result); |
|
56 if (cpix_Failed(&result)) |
|
57 { |
|
58 ITK_PANIC("Could not dbg scrapp all indexes"); |
|
59 } |
|
60 |
|
61 util_ = new SmsIdxUtil; |
|
62 util_->init(); |
|
63 |
|
64 analyzer_ = cpix_CreateSimpleAnalyzer(&result); |
|
65 |
|
66 if (analyzer_ == NULL) |
|
67 { |
|
68 ITK_PANIC("Could not create analyzer"); |
|
69 } |
|
70 |
|
71 queryParser_ = cpix_QueryParser_create(&result, |
|
72 LBODY_FIELD, |
|
73 analyzer_); |
|
74 if (queryParser_ == NULL) |
|
75 { |
|
76 ITK_PANIC("Could not create query parser"); |
|
77 } |
|
78 |
|
79 query_ = cpix_QueryParser_parse(queryParser_, |
|
80 L"happy"); |
|
81 if (cpix_Failed(queryParser_) |
|
82 || query_ == NULL) |
|
83 { |
|
84 ITK_PANIC("Could not parse query string"); |
|
85 } |
|
86 |
|
87 ss.setupComplete(); |
|
88 } |
|
89 |
|
90 |
|
91 virtual void tearDown() throw() |
|
92 { |
|
93 cleanup(); |
|
94 } |
|
95 |
|
96 |
|
97 virtual ~DeletionContext() |
|
98 { |
|
99 cleanup(); |
|
100 } |
|
101 |
|
102 |
|
103 // |
|
104 // public operations |
|
105 // |
|
106 DeletionContext() |
|
107 : util_(NULL), |
|
108 analyzer_(NULL), |
|
109 queryParser_(NULL), |
|
110 query_(NULL) |
|
111 |
|
112 { |
|
113 ; |
|
114 } |
|
115 |
|
116 |
|
117 // |
|
118 // Test Member Function |
|
119 // |
|
120 void testAdd_00(Itk::TestMgr * testMgr) |
|
121 { |
|
122 testAddSms(testMgr, |
|
123 1, |
|
124 L"This is a happy message"); |
|
125 util_->flush(); |
|
126 testSearch(testMgr); |
|
127 } |
|
128 |
|
129 void testAdd_01(Itk::TestMgr * testMgr) |
|
130 { |
|
131 testAddSms(testMgr, |
|
132 2, |
|
133 L"This is another happy message"); |
|
134 util_->flush(); |
|
135 testSearch(testMgr); |
|
136 } |
|
137 |
|
138 void testFlush_02(Itk::TestMgr * testMgr) |
|
139 { |
|
140 testFlush(testMgr); |
|
141 } |
|
142 |
|
143 void testAdd_03(Itk::TestMgr * testMgr) |
|
144 { |
|
145 testAddSms(testMgr, |
|
146 3, |
|
147 L"This is a 3rd happy message"); |
|
148 util_->flush(); |
|
149 testSearch(testMgr); |
|
150 } |
|
151 |
|
152 void testDelete_04(Itk::TestMgr * testMgr) |
|
153 { |
|
154 testDeleteSms(3, |
|
155 testMgr); |
|
156 util_->flush(); |
|
157 testSearch(testMgr); |
|
158 } |
|
159 |
|
160 void testDelete_05(Itk::TestMgr * testMgr) |
|
161 { |
|
162 testDeleteSms(1, |
|
163 testMgr); |
|
164 util_->flush(); |
|
165 testSearch(testMgr); |
|
166 } |
|
167 |
|
168 void testReOpenIdx_06(Itk::TestMgr * testMgr) |
|
169 { |
|
170 testReOpenIdxDb(testMgr); |
|
171 testSearch(testMgr); |
|
172 } |
|
173 |
|
174 void testAdd_07(Itk::TestMgr * testMgr) |
|
175 { |
|
176 testAddSms(testMgr, |
|
177 4, |
|
178 L"This is the 4th happy message"); |
|
179 util_->flush(); |
|
180 testSearch(testMgr); |
|
181 } |
|
182 |
|
183 void testAdd_08(Itk::TestMgr * testMgr) |
|
184 { |
|
185 testAddSms(testMgr, |
|
186 5, |
|
187 L"This is the 5th happy message"); |
|
188 util_->flush(); |
|
189 testSearch(testMgr); |
|
190 } |
|
191 |
|
192 void testDelete_09(Itk::TestMgr * testMgr) |
|
193 { |
|
194 testDeleteSms(2, |
|
195 testMgr); |
|
196 util_->flush(); |
|
197 testSearch(testMgr); |
|
198 } |
|
199 |
|
200 void testDelete_10(Itk::TestMgr * testMgr) |
|
201 { |
|
202 testDeleteSms(4, |
|
203 testMgr); |
|
204 util_->flush(); |
|
205 testSearch(testMgr); |
|
206 } |
|
207 |
|
208 void testReOpenIdx_11(Itk::TestMgr * testMgr) |
|
209 { |
|
210 testReOpenIdxDb(testMgr); |
|
211 testSearch(testMgr); |
|
212 } |
|
213 |
|
214 |
|
215 |
|
216 private: |
|
217 // |
|
218 // private methods |
|
219 // |
|
220 void cleanup() |
|
221 { |
|
222 delete util_; |
|
223 util_ = NULL; |
|
224 |
|
225 cpix_Analyzer_destroy(analyzer_); |
|
226 analyzer_ = NULL; |
|
227 |
|
228 cpix_Query_destroy(query_); |
|
229 query_ = NULL; |
|
230 |
|
231 cpix_QueryParser_destroy(queryParser_); |
|
232 queryParser_ = NULL; |
|
233 } |
|
234 |
|
235 |
|
236 |
|
237 void testReOpenIdxDb(Itk::TestMgr *) |
|
238 { |
|
239 delete util_; |
|
240 util_ = NULL; |
|
241 |
|
242 util_ = new SmsIdxUtil; |
|
243 util_->init(false); // don't create |
|
244 } |
|
245 |
|
246 |
|
247 void testAddSms(Itk::TestMgr * testMgr, |
|
248 size_t docUid, |
|
249 const wchar_t * body) |
|
250 { |
|
251 using namespace Itk; |
|
252 |
|
253 util_->indexSms(docUid, |
|
254 body, |
|
255 analyzer_, |
|
256 testMgr); |
|
257 } |
|
258 |
|
259 |
|
260 void testFlush(Itk::TestMgr * testMgr) |
|
261 { |
|
262 cpix_IdxDb_flush(util_->idxDb()); |
|
263 |
|
264 ITK_EXPECT(testMgr, |
|
265 cpix_Succeeded(util_->idxDb()), |
|
266 "Could not flush idx"); |
|
267 } |
|
268 |
|
269 |
|
270 void testDeleteSms(size_t docUid, |
|
271 Itk::TestMgr * testMgr) |
|
272 { |
|
273 util_->deleteSms(docUid, |
|
274 testMgr); |
|
275 } |
|
276 |
|
277 |
|
278 void testSearch(Itk::TestMgr * testMgr) |
|
279 { |
|
280 using namespace Itk; |
|
281 |
|
282 cpix_Hits |
|
283 * hits = cpix_IdxDb_search(util_->idxDb(), |
|
284 query_); |
|
285 |
|
286 if (cpix_Failed(util_->idxDb())) |
|
287 { |
|
288 ITK_EXPECT(testMgr, |
|
289 false, |
|
290 "Failed to search"); |
|
291 cpix_ClearError(util_->idxDb()); |
|
292 } |
|
293 else |
|
294 { |
|
295 util_->printHits(hits, |
|
296 testMgr); |
|
297 cpix_Hits_destroy( hits ); |
|
298 } |
|
299 } |
|
300 |
|
301 |
|
302 }; |
|
303 |
|
304 |
|
305 |
|
306 Itk::TesterBase * CreateDeletionTests() |
|
307 { |
|
308 using namespace Itk; |
|
309 |
|
310 DeletionContext |
|
311 * context = new DeletionContext; |
|
312 |
|
313 ContextTester |
|
314 * contextTester = new ContextTester("deletion", |
|
315 context); |
|
316 |
|
317 #define TEST "00_add" |
|
318 contextTester->add(TEST, |
|
319 context, |
|
320 &DeletionContext::testAdd_00, |
|
321 TEST); |
|
322 #undef TEST |
|
323 |
|
324 #define TEST "01_add" |
|
325 contextTester->add(TEST, |
|
326 context, |
|
327 &DeletionContext::testAdd_01, |
|
328 TEST); |
|
329 #undef TEST |
|
330 |
|
331 #define TEST "02_flush" |
|
332 contextTester->add(TEST, |
|
333 context, |
|
334 &DeletionContext::testFlush_02); |
|
335 #undef TEST |
|
336 |
|
337 #define TEST "03_add" |
|
338 contextTester->add(TEST, |
|
339 context, |
|
340 &DeletionContext::testAdd_03, |
|
341 TEST); |
|
342 #undef TEST |
|
343 |
|
344 #define TEST "04_delete" |
|
345 contextTester->add(TEST, |
|
346 context, |
|
347 &DeletionContext::testDelete_04, |
|
348 TEST); |
|
349 #undef TEST |
|
350 |
|
351 #define TEST "05_delete" |
|
352 contextTester->add(TEST, |
|
353 context, |
|
354 &DeletionContext::testDelete_05, |
|
355 TEST); |
|
356 #undef TEST |
|
357 |
|
358 #define TEST "06_reopen" |
|
359 contextTester->add(TEST, |
|
360 context, |
|
361 &DeletionContext::testReOpenIdx_06, |
|
362 TEST); |
|
363 #undef TEST |
|
364 |
|
365 #define TEST "07_add" |
|
366 contextTester->add(TEST, |
|
367 context, |
|
368 &DeletionContext::testAdd_07, |
|
369 TEST); |
|
370 #undef TEST |
|
371 |
|
372 #define TEST "08_add" |
|
373 contextTester->add(TEST, |
|
374 context, |
|
375 &DeletionContext::testAdd_08, |
|
376 TEST); |
|
377 #undef TEST |
|
378 |
|
379 #define TEST "09_delete" |
|
380 contextTester->add(TEST, |
|
381 context, |
|
382 &DeletionContext::testDelete_09, |
|
383 TEST); |
|
384 #undef TEST |
|
385 |
|
386 #define TEST "10_delete" |
|
387 contextTester->add(TEST, |
|
388 context, |
|
389 &DeletionContext::testDelete_10, |
|
390 TEST); |
|
391 #undef TEST |
|
392 |
|
393 #define TEST "11_reopen" |
|
394 contextTester->add(TEST, |
|
395 context, |
|
396 &DeletionContext::testReOpenIdx_11, |
|
397 TEST); |
|
398 #undef TEST |
|
399 |
|
400 |
|
401 |
|
402 return contextTester; |
|
403 } |