|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "crecwebrecogtest.h" |
|
17 |
|
18 #include <apmrec.h> |
|
19 #include <apgcli.h> |
|
20 #include <flogger.h> |
|
21 |
|
22 const TInt KTestCaseCount = 8; |
|
23 const TInt KTestDataSize = 2048; |
|
24 _LIT8(KHtmlMimeType,"text/html"); |
|
25 _LIT8(KXmlMimeType,"text/xml"); |
|
26 |
|
27 CRecWebRecogTest* CRecWebRecogTest::NewL(TAny* aConstructionsParams) |
|
28 { |
|
29 TRecogTestConstructionParams* params = reinterpret_cast<TRecogTestConstructionParams*>(aConstructionsParams); |
|
30 CRecWebRecogTest* self = new(ELeave) CRecWebRecogTest(*params->iAppArcSession, *params->iLogger); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CRecWebRecogTest::~CRecWebRecogTest() |
|
38 { |
|
39 iFs.Close(); |
|
40 } |
|
41 |
|
42 CRecWebRecogTest::CRecWebRecogTest(RApaLsSession& aAppArc, RFileLogger& aLogger) |
|
43 : CEComRecogTest(), iAppArc(aAppArc), iLogger(aLogger) |
|
44 { |
|
45 iTestCaseTitle.Set(KNullDesC()); |
|
46 } |
|
47 |
|
48 void CRecWebRecogTest::ConstructL() |
|
49 { |
|
50 User::LeaveIfError(iFs.Connect()); |
|
51 } |
|
52 |
|
53 const TDesC& CRecWebRecogTest::TestPluginTitle() const |
|
54 { |
|
55 _LIT(KTxtTitle, "Web Recogniser Test"); |
|
56 return KTxtTitle(); |
|
57 } |
|
58 |
|
59 TInt CRecWebRecogTest::TestCaseCount() const |
|
60 { |
|
61 return KTestCaseCount; |
|
62 } |
|
63 |
|
64 const TDesC& CRecWebRecogTest::TestCaseTitle(TInt aIndex) |
|
65 { |
|
66 switch(aIndex) |
|
67 { |
|
68 case 0: |
|
69 { |
|
70 _LIT(KTxtTC1, "Recognise sample1.html"); |
|
71 iTestCaseTitle.Set(KTxtTC1); |
|
72 } break; |
|
73 case 1: |
|
74 { |
|
75 _LIT(KTxtTC2, "Recognise sample1"); |
|
76 iTestCaseTitle.Set(KTxtTC2); |
|
77 } break; |
|
78 case 2: |
|
79 { |
|
80 _LIT(KTxtTC3, "Recognise sample2.htm"); |
|
81 iTestCaseTitle.Set(KTxtTC3); |
|
82 } break; |
|
83 case 3: |
|
84 { |
|
85 _LIT(KTxtTC4, "Recognise sample2"); |
|
86 iTestCaseTitle.Set(KTxtTC4); |
|
87 } break; |
|
88 case 4: |
|
89 { |
|
90 _LIT(KTxtTC5, "Recognise sample3.xhtml"); |
|
91 iTestCaseTitle.Set(KTxtTC5); |
|
92 } break; |
|
93 case 5: |
|
94 { |
|
95 _LIT(KTxtTC6, "Recognise sample3"); |
|
96 iTestCaseTitle.Set(KTxtTC6); |
|
97 } break; |
|
98 case 6: |
|
99 { |
|
100 _LIT(KTxtTC7, "Recognise sample4.xml"); |
|
101 iTestCaseTitle.Set(KTxtTC7); |
|
102 } break; |
|
103 case 7: |
|
104 { |
|
105 _LIT(KTxtTC8, "Recognise sample4"); |
|
106 iTestCaseTitle.Set(KTxtTC8); |
|
107 } break; |
|
108 default: |
|
109 User::Invariant(); |
|
110 break; |
|
111 }; |
|
112 |
|
113 return iTestCaseTitle; |
|
114 } |
|
115 |
|
116 void CRecWebRecogTest::RunTestCaseL(TInt aIndex) |
|
117 { |
|
118 switch(aIndex) |
|
119 { |
|
120 case 0: |
|
121 { |
|
122 RunTestCase1L(); |
|
123 } break; |
|
124 case 1: |
|
125 { |
|
126 RunTestCase2L(); |
|
127 } break; |
|
128 case 2: |
|
129 { |
|
130 RunTestCase3L(); |
|
131 } break; |
|
132 case 3: |
|
133 { |
|
134 RunTestCase4L(); |
|
135 } break; |
|
136 case 4: |
|
137 { |
|
138 RunTestCase5L(); |
|
139 } break; |
|
140 case 5: |
|
141 { |
|
142 RunTestCase6L(); |
|
143 } break; |
|
144 case 6: |
|
145 { |
|
146 RunTestCase7L(); |
|
147 } break; |
|
148 case 7: |
|
149 { |
|
150 RunTestCase8L(); |
|
151 } break; |
|
152 default: |
|
153 User::Invariant(); |
|
154 break; |
|
155 }; |
|
156 } |
|
157 |
|
158 void CRecWebRecogTest::RunTestL(const TDesC& aTestData, const TDesC8& aExpectedType) |
|
159 { |
|
160 RFile testFile; |
|
161 CleanupClosePushL(testFile); |
|
162 User::LeaveIfError(testFile.Open(iFs, aTestData, EFileRead)); |
|
163 HBufC8* fileBuf = HBufC8::NewLC(KTestDataSize); |
|
164 TPtr8 fileBufDes = fileBuf->Des(); |
|
165 |
|
166 User::LeaveIfError(testFile.Read(fileBufDes)); |
|
167 |
|
168 TDataRecognitionResult recogResult; |
|
169 |
|
170 iAppArc.RecognizeData(aTestData, *fileBuf, recogResult); |
|
171 |
|
172 TPtrC8 dataTypeResult(recogResult.iDataType.Des8()); |
|
173 |
|
174 _LIT(KTxtData, "Data: %S"); |
|
175 iLogger.WriteFormat(KTxtData(), &aTestData); |
|
176 _LIT8(KTxtExpected, "Expected: %S"); |
|
177 iLogger.WriteFormat(KTxtExpected(), &aExpectedType); |
|
178 _LIT8(KTxtActual, "Actual : %S"); |
|
179 iLogger.WriteFormat(KTxtActual(), &dataTypeResult); |
|
180 LogConfidence(recogResult.iConfidence); |
|
181 |
|
182 if(dataTypeResult.CompareF(aExpectedType)!=0) |
|
183 User::Leave(KErrNotFound); |
|
184 |
|
185 CleanupStack::PopAndDestroy(2, &testFile); // fileBuf, testFile |
|
186 } |
|
187 |
|
188 void CRecWebRecogTest::RunTestCase1L() |
|
189 { |
|
190 _LIT(KTxtTestFile1Path, "z:\\recogtestdata\\sample1.html"); |
|
191 |
|
192 RunTestL(KTxtTestFile1Path(), KHtmlMimeType()); |
|
193 } |
|
194 |
|
195 void CRecWebRecogTest::RunTestCase2L() |
|
196 { |
|
197 _LIT(KTxtTestFile2Path, "z:\\recogtestdata\\sample1"); |
|
198 |
|
199 RunTestL(KTxtTestFile2Path(), KHtmlMimeType()); |
|
200 } |
|
201 |
|
202 void CRecWebRecogTest::RunTestCase3L() |
|
203 { |
|
204 _LIT(KTxtTestFile3Path, "z:\\recogtestdata\\sample2.htm"); |
|
205 |
|
206 RunTestL(KTxtTestFile3Path(), KHtmlMimeType()); |
|
207 } |
|
208 |
|
209 void CRecWebRecogTest::RunTestCase4L() |
|
210 { |
|
211 _LIT(KTxtTestFile4Path, "z:\\recogtestdata\\sample2"); |
|
212 |
|
213 RunTestL(KTxtTestFile4Path(), KHtmlMimeType()); |
|
214 } |
|
215 |
|
216 void CRecWebRecogTest::RunTestCase5L() |
|
217 { |
|
218 _LIT(KTxtTestFile5Path, "z:\\recogtestdata\\sample3.xhtml"); |
|
219 |
|
220 RunTestL(KTxtTestFile5Path(), KHtmlMimeType()); |
|
221 } |
|
222 |
|
223 void CRecWebRecogTest::RunTestCase6L() |
|
224 { |
|
225 _LIT(KTxtTestFile6Path, "z:\\recogtestdata\\sample3"); |
|
226 |
|
227 RunTestL(KTxtTestFile6Path(), KHtmlMimeType()); |
|
228 } |
|
229 |
|
230 void CRecWebRecogTest::RunTestCase7L() |
|
231 { |
|
232 _LIT(KTxtTestFile7Path, "z:\\recogtestdata\\sample4.xml"); |
|
233 |
|
234 RunTestL(KTxtTestFile7Path(), KXmlMimeType()); |
|
235 } |
|
236 |
|
237 void CRecWebRecogTest::RunTestCase8L() |
|
238 { |
|
239 _LIT(KTxtTestFile8Path, "z:\\recogtestdata\\sample4"); |
|
240 |
|
241 RunTestL(KTxtTestFile8Path(), KXmlMimeType()); |
|
242 } |
|
243 |
|
244 void CRecWebRecogTest::LogConfidence(TInt aConfidence) |
|
245 { |
|
246 TPtrC8 confidence; |
|
247 switch(aConfidence) |
|
248 { |
|
249 case CApaDataRecognizerType::ECertain: |
|
250 { |
|
251 _LIT8(KTxtCertain, "Certain"); |
|
252 confidence.Set(KTxtCertain()); |
|
253 } break; |
|
254 case CApaDataRecognizerType::EProbable: |
|
255 { |
|
256 _LIT8(KTxtProbable, "Probable"); |
|
257 confidence.Set(KTxtProbable()); |
|
258 } break; |
|
259 case CApaDataRecognizerType::EPossible: |
|
260 { |
|
261 _LIT8(KTxtPossible, "Possible"); |
|
262 confidence.Set(KTxtPossible()); |
|
263 } break; |
|
264 case CApaDataRecognizerType::EUnlikely: |
|
265 { |
|
266 _LIT8(KTxtUnlikely, "Unlikely"); |
|
267 confidence.Set(KTxtUnlikely()); |
|
268 } break; |
|
269 case CApaDataRecognizerType::ENotRecognized: |
|
270 { |
|
271 _LIT8(KTxtNotRecognized, "NotRecognized"); |
|
272 confidence.Set(KTxtNotRecognized()); |
|
273 } break; |
|
274 default: |
|
275 User::Invariant(); |
|
276 break; |
|
277 }; |
|
278 _LIT8(KTxtConfidence, "Confidence: %S"); |
|
279 iLogger.WriteFormat(KTxtConfidence(), &confidence); |
|
280 } |