|
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 |
|
19 #include <wchar.h> |
|
20 #include <stddef.h> |
|
21 |
|
22 #include <iostream> |
|
23 #include <sstream> |
|
24 #include "indevicecfg.h" |
|
25 |
|
26 #include "cpixidxdb.h" |
|
27 |
|
28 #include "itk.h" |
|
29 //#include "xmllog.h" |
|
30 #include "config.h" |
|
31 #include "testutils.h" |
|
32 #include "suggestion.h" |
|
33 |
|
34 |
|
35 const char * docsToIndex[5] = { |
|
36 CORPUS_PATH "\\query\\query1.txt", |
|
37 CORPUS_PATH "\\query\\query2.txt", |
|
38 CORPUS_PATH "\\query\\query3.txt", |
|
39 CORPUS_PATH "\\query\\query4.txt", |
|
40 NULL |
|
41 }; |
|
42 |
|
43 void setupPlainQuery(Itk::TestMgr * testMgr) |
|
44 { |
|
45 cpix_Result |
|
46 result; |
|
47 |
|
48 cpix_IdxDb_dbgScrapAll(&result); |
|
49 ITK_ASSERT(testMgr, |
|
50 cpix_Succeeded(&result), |
|
51 "Could not get rid of all test qbac-idx pairs"); |
|
52 std::auto_ptr<FileIdxUtil> util( new FileIdxUtil ); |
|
53 util->init(true); |
|
54 cpix_Analyzer* analyzer = cpix_Analyzer_create(&result, L"standard"); |
|
55 if ( cpix_Failed( &result) ) ITK_PANIC("Analyzer could not be created"); |
|
56 for (int i = 0; docsToIndex[i]; i++) |
|
57 { |
|
58 util->indexFile( docsToIndex[i], analyzer, testMgr ); |
|
59 } |
|
60 util->flush(); |
|
61 cpix_Analyzer_destroy(analyzer); |
|
62 } |
|
63 |
|
64 void setupPrefixQuery(Itk::TestMgr * testMgr) |
|
65 { |
|
66 cpix_Result |
|
67 result; |
|
68 |
|
69 cpix_IdxDb_dbgScrapAll(&result); |
|
70 ITK_ASSERT(testMgr, |
|
71 cpix_Succeeded(&result), |
|
72 "Could not get rid of all test qbac-idx pairs"); |
|
73 std::auto_ptr<FileIdxUtil> util( new FileIdxUtil ); |
|
74 util->init(true); |
|
75 cpix_Analyzer* analyzer = cpix_Analyzer_create(&result, L"standard"); |
|
76 if ( cpix_Failed( &result) ) ITK_PANIC("Analyzer could not be created"); |
|
77 |
|
78 util->indexFile( CORPUS_PATH "\\query\\query5.txt", analyzer, testMgr ); |
|
79 |
|
80 util->flush(); |
|
81 util->indexFile( CORPUS_PATH "\\query\\query6.txt", analyzer, testMgr ); |
|
82 |
|
83 util->flush(); |
|
84 cpix_Analyzer_destroy(analyzer); |
|
85 } |
|
86 |
|
87 void testQuery(Itk::TestMgr * testMgr, const wchar_t *qryStr, int hitLen) |
|
88 { |
|
89 cpix_Result |
|
90 result; |
|
91 int32_t hitsLength = 0; |
|
92 |
|
93 std::auto_ptr<FileIdxUtil> util( new FileIdxUtil ); |
|
94 |
|
95 util->init(false); |
|
96 cpix_Analyzer* analyzer = cpix_Analyzer_create(&result, L"standard"); |
|
97 if ( cpix_Failed( &result) ) ITK_PANIC("Analyzer could not be created"); |
|
98 cpix_QueryParser |
|
99 * queryParser = cpix_QueryParser_create(&result, |
|
100 LCPIX_DEFAULT_FIELD, |
|
101 analyzer ); |
|
102 if (queryParser == NULL) |
|
103 { |
|
104 cpix_Analyzer_destroy( analyzer ); |
|
105 ITK_PANIC("Could not create query parser"); |
|
106 } |
|
107 |
|
108 |
|
109 |
|
110 cpix_Query* query = cpix_QueryParser_parse(queryParser, |
|
111 qryStr); |
|
112 if (cpix_Failed(queryParser) |
|
113 || query == NULL) |
|
114 { |
|
115 cpix_Analyzer_destroy(analyzer); |
|
116 cpix_ClearError(queryParser); |
|
117 cpix_QueryParser_destroy(queryParser); |
|
118 ITK_PANIC("Could not parse query string"); |
|
119 } |
|
120 cpix_QueryParser_destroy(queryParser); |
|
121 |
|
122 cpix_Hits |
|
123 * hits = cpix_IdxDb_search(util->idxDb(), |
|
124 query ); |
|
125 |
|
126 if (cpix_Succeeded(hits)) |
|
127 { |
|
128 hitsLength = cpix_Hits_length(hits); |
|
129 cpix_Hits_destroy( hits ); |
|
130 } |
|
131 if(hitsLength == hitLen ) |
|
132 { |
|
133 |
|
134 ITK_MSG(testMgr, "Query %S, returned %d hits. Passed \n",qryStr,hitsLength ); |
|
135 } |
|
136 else |
|
137 { |
|
138 |
|
139 ITK_MSG(testMgr, "Query %S, didnt return expected hits. Expected is %d hits. Returned is %d. Failed \n",qryStr,hitLen,hitsLength); |
|
140 } |
|
141 |
|
142 cpix_Query_destroy( query ); |
|
143 |
|
144 cpix_Analyzer_destroy(analyzer); |
|
145 } |
|
146 |
|
147 |
|
148 |
|
149 void CreatePlainQueryTest(Itk::TestMgr * testMgr) |
|
150 { |
|
151 bool val = true; |
|
152 setupPlainQuery(testMgr); |
|
153 testQuery(testMgr,L"Nokia", 2); |
|
154 testQuery(testMgr,L"iNdia", 1); |
|
155 testQuery(testMgr,L"\"London Finland\"", 1); |
|
156 testQuery(testMgr,L"Contents:Nokia", 2); |
|
157 testQuery(testMgr,L"Contents:Nokia AND country", 1); |
|
158 testQuery(testMgr,L"Contents:Nokia && country", 1); |
|
159 testQuery(testMgr,L"Nokia Selvaraj", 3); |
|
160 testQuery(testMgr,L"Lo?don", 1); |
|
161 testQuery(testMgr,L"countr?", 1); |
|
162 testQuery(testMgr,L"country?", 0); |
|
163 testQuery(testMgr,L"?india", 0); |
|
164 testQuery(testMgr,L"nok*", 2); |
|
165 testQuery(testMgr,L"count?ry", 0); |
|
166 testQuery(testMgr,L"roam~", 2); |
|
167 testQuery(testMgr,L"ro~am", 0); |
|
168 testQuery(testMgr,L"\"london country\"~10", 1); |
|
169 testQuery(testMgr,L"\"nokia country\"~2", 0); |
|
170 testQuery(testMgr,L"nokia basker", 3); |
|
171 testQuery(testMgr,L"Nokia^5 basker", 3); |
|
172 testQuery(testMgr,L"Nokia basker^5", 3); |
|
173 testQuery(testMgr,L"Nokia || basker", 3); |
|
174 testQuery(testMgr,L"Nokia OR basker", 3); |
|
175 testQuery(testMgr,L"Nokia AND basker", 0); |
|
176 testQuery(testMgr,L"Nokia && basker", 0); |
|
177 testQuery(testMgr,L"+nokia country", 2); |
|
178 testQuery(testMgr,L"+nokia roam", 2); |
|
179 testQuery(testMgr,L"Nokia !country", 1); |
|
180 testQuery(testMgr,L"nokia NOT country", 1); |
|
181 testQuery(testMgr,L"nokia NOT basker", 2); |
|
182 testQuery(testMgr,L"NOT India", 1); |
|
183 testQuery(testMgr,L"(india OR Mobile) AND Nokia", 2); |
|
184 testQuery(testMgr,L"(india OR Mobile) AND Country", 1); |
|
185 // create_xml(val,__func__,__FILE__,__LINE__); |
|
186 } |
|
187 |
|
188 void CreatePrefixQueryTest(Itk::TestMgr * testMgr) |
|
189 { |
|
190 bool val = true; |
|
191 setupPrefixQuery(testMgr); |
|
192 testQuery(testMgr,L"$prefix(\"new-notes\")", 1); |
|
193 testQuery(testMgr,L"$prefix(\"notes\")", 1); |
|
194 testQuery(testMgr,L"$prefix(\"new\")", 1); |
|
195 testQuery(testMgr,L"$prefix(\"-india\")", 1); |
|
196 testQuery(testMgr,L"$prefix(\"tamil-nadu\")", 1); |
|
197 testQuery(testMgr,L"$prefix(\"testing\")", 2); |
|
198 testQuery(testMgr,L"$prefix(\"*shankar\")", 2); |
|
199 testQuery(testMgr,L"$prefix(\"Ani*rban\")", 1); |
|
200 testQuery(testMgr,L"$prefix(\"kumar*\")", 1); |
|
201 testQuery(testMgr,L"$prefix(\"carrot^\")", 1); |
|
202 testQuery(testMgr,L"$prefix(\"carrot\")", 1); |
|
203 testQuery(testMgr,L"$prefix(\"ani\")", 1); |
|
204 testQuery(testMgr,L"$prefix(\"question\")", 1); |
|
205 testQuery(testMgr,L"$prefix(\"question?\")", 1); |
|
206 testQuery(testMgr,L"$prefix(\"|pipe\")", 1); |
|
207 testQuery(testMgr,L"$prefix(\"&&ambersend\")", 1); |
|
208 testQuery(testMgr,L"$prefix(\"!=Exclamation\")", 1); |
|
209 testQuery(testMgr,L"$prefix(\":colon\")", 1); |
|
210 testQuery(testMgr,L"$prefix(\"http:\\www.nokia.com\")", 1); |
|
211 testQuery(testMgr,L"$prefix(\"%percentage\")", 1); |
|
212 testQuery(testMgr,L"$prefix(\"(testing)\")", 2); |
|
213 testQuery(testMgr,L"$prefix(\"mail-id\")", 1); |
|
214 testQuery(testMgr,L"$prefix(\"mail id\")", 1); |
|
215 testQuery(testMgr,L"$prefix(\"shankar.rajendran@nokia.com\")", 1); |
|
216 testQuery(testMgr,L"$prefix(\"~tild\")", 1); |
|
217 testQuery(testMgr,L"$prefix(\"shankar\")", 2); |
|
218 testQuery(testMgr,L"$prefix(\"`singlequote\")", 1); |
|
219 testQuery(testMgr,L"$prefix(\"singlequote\")", 1); |
|
220 testQuery(testMgr,L"$prefix(\"\"doublequote\")", 1); |
|
221 testQuery(testMgr,L"$prefix(\"doublequote\")", 1); |
|
222 testQuery(testMgr,L"$prefix(\";semicolon\")", 1); |
|
223 testQuery(testMgr,L"$prefix(\"/slash\")", 1); |
|
224 testQuery(testMgr,L"$prefix(\"slash\")", 1); |
|
225 testQuery(testMgr,L"$prefix(\"\\backslash\")", 1); |
|
226 testQuery(testMgr,L"$prefix(\"backslash\")", 1); |
|
227 testQuery(testMgr,L"$prefix(\"[squarebracket]\")", 1); |
|
228 testQuery(testMgr,L"$prefix(\"{flowerbracket}\")", 1); |
|
229 testQuery(testMgr,L"$prefix(\"<lessthan\")", 1); |
|
230 testQuery(testMgr,L"$prefix(\">greaterthan\")", 1); |
|
231 testQuery(testMgr,L"$prefix(\"worked for motorola .\")", 1); |
|
232 |
|
233 } |
|
234 |
|
235 Itk::TesterBase * CreateQueryTests() |
|
236 { |
|
237 using namespace Itk; |
|
238 |
|
239 ContextTester |
|
240 * qryTests = new ContextTester("Query Tests", NULL); |
|
241 |
|
242 qryTests->add("PlainQueryTest", &CreatePlainQueryTest); |
|
243 qryTests->add("PrefixQueryTest", &CreatePrefixQueryTest); |
|
244 |
|
245 return qryTests; |
|
246 } |
|
247 |
|
248 |