|
1 // Copyright (c) 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 /** |
|
17 @file texmlparser2step.cpp |
|
18 @internalTechnology |
|
19 */ |
|
20 |
|
21 #include "texmlparser2step.h" |
|
22 #include "tetestcontenthandler.h" |
|
23 #include "libxml2_globals_private.h" |
|
24 #include <e32cmn.h> |
|
25 #include <xml/parserfeature.h> |
|
26 #include <xml/matchdata.h> |
|
27 |
|
28 using namespace Xml; |
|
29 /** |
|
30 * Class CXmlParser2Step implementation |
|
31 */ |
|
32 _LIT(KSimpleXmlFile, "z:\\testdata\\xmlexample.xml"); |
|
33 #ifdef _DEBUG |
|
34 _LIT(KCorruptXm1File, "z:\\testdata\\corruptxml1.xml"); |
|
35 #endif |
|
36 |
|
37 /** |
|
38 * Constructor. Sets the test step name so that it can be |
|
39 * differentiated from within doTestStepL() |
|
40 */ |
|
41 CXmlParser2Step::CXmlParser2Step(const TDesC& aStepName) |
|
42 { |
|
43 SetTestStepName(aStepName); |
|
44 } |
|
45 |
|
46 /** |
|
47 * TEF invokes doTestStepL interface along with the step name |
|
48 * to let appropriate action to be taken for the test step. |
|
49 */ |
|
50 TVerdict CXmlParser2Step::doTestStepL(void) |
|
51 { |
|
52 if (TestStepName() == KXmlParser2SetContentSink) |
|
53 { |
|
54 INFO_PRINTF1(KXmlParser2SetContentSink); |
|
55 SetTestStepResult(TestKXmlParser2SetContentSink()); |
|
56 } |
|
57 else if (TestStepName() == KXmlParser2OOMTests) |
|
58 { |
|
59 INFO_PRINTF1(KXmlParser2OOMTests); |
|
60 SetTestStepResult(TestKXmlParser2OOMTests()); |
|
61 } |
|
62 else if (TestStepName() == KXmlParser2OOMTests2) |
|
63 { |
|
64 INFO_PRINTF1(KXmlParser2OOMTests2); |
|
65 SetTestStepResult(TestKXmlParser2OOMTests2()); |
|
66 } |
|
67 else if (TestStepName() == KXmlParser2OOMTests3) |
|
68 { |
|
69 INFO_PRINTF1(KXmlParser2OOMTests3); |
|
70 SetTestStepResult(TestKXmlParser2OOMTests3()); |
|
71 } |
|
72 else if (TestStepName() == KXmlParser2OOMTests4) |
|
73 { |
|
74 INFO_PRINTF1(KXmlParser2OOMTests4); |
|
75 SetTestStepResult(TestKXmlParser2OOMTests4()); |
|
76 } |
|
77 return TestStepResult(); |
|
78 } |
|
79 |
|
80 TVerdict CXmlParser2Step::TestKXmlParser2SetContentSink() |
|
81 { |
|
82 RFs fs; |
|
83 User::LeaveIfError(fs.Connect()); |
|
84 |
|
85 CTestContentHandler *sax = CTestContentHandler::NewL(); |
|
86 RFile handle; |
|
87 TInt err; |
|
88 TRAP(err,handle.Open(fs, KSimpleXmlFile, EFileShareReadersOnly)); |
|
89 if (err != KErrNone) |
|
90 { |
|
91 INFO_PRINTF1(_L("Error opening test XML file")); |
|
92 User::Leave(err); |
|
93 } |
|
94 CleanupClosePushL(handle); |
|
95 CMatchData *matchData = CMatchData::NewL(); |
|
96 matchData->SetMimeTypeL(_L8("text/xml")); |
|
97 matchData->SetVariantL(_L8("libxml2")); |
|
98 CParser *parser = CParser::NewL(*matchData, *sax); |
|
99 TInt retVal = KErrNone; |
|
100 //Valid feature |
|
101 retVal = parser->EnableFeature(EReportNamespaceMapping); |
|
102 if (retVal != KErrNone) |
|
103 { |
|
104 INFO_PRINTF1(_L("Error Enabling valid feature")); |
|
105 return EFail; |
|
106 } |
|
107 //Invalid feature |
|
108 TInt EInvalidFeatureId = 0x1111; |
|
109 retVal = parser->EnableFeature(EInvalidFeatureId); |
|
110 if (retVal != KErrNotSupported) |
|
111 { |
|
112 INFO_PRINTF1(_L("Unexpected error while enabling invalid feature")); |
|
113 return EFail; |
|
114 } |
|
115 //Valid feature |
|
116 retVal = parser->DisableFeature(EReportNamespaces); |
|
117 if (retVal != KErrNone) |
|
118 { |
|
119 INFO_PRINTF1(_L("Error Disabling valid feature")); |
|
120 return EFail; |
|
121 } |
|
122 |
|
123 //Invalid feature |
|
124 retVal = parser->DisableFeature(EInvalidFeatureId); |
|
125 if (retVal != KErrNotSupported) |
|
126 { |
|
127 INFO_PRINTF1(_L("Unexpected error while disabling invalid feature")); |
|
128 return EFail; |
|
129 } |
|
130 RContentProcessorUids *uid = new (ELeave)RContentProcessorUids; |
|
131 const TUid KXmlContProcUid = |
|
132 { |
|
133 0x20021CE5 //UID3 |
|
134 }; |
|
135 uid->Append(KXmlContProcUid); |
|
136 TRAP(err, parser->SetProcessorChainL(*uid)); |
|
137 if (err != KErrNone) |
|
138 { |
|
139 INFO_PRINTF1(_L("Error Setting up processor chain")); |
|
140 return EFail; |
|
141 } |
|
142 TRAP(err,ParseL(*parser, handle)); |
|
143 if (err != KErrNone) |
|
144 { |
|
145 INFO_PRINTF1(_L("Error Parsing")); |
|
146 return EFail; |
|
147 } |
|
148 delete parser; |
|
149 fs.Close(); |
|
150 CleanupStack::Pop(&handle); |
|
151 return EPass; |
|
152 } |
|
153 /** |
|
154 * This test step should be run only on debug builds owing to the |
|
155 * __UHEAP macros that are defined only in debug builds. |
|
156 */ |
|
157 TVerdict CXmlParser2Step::TestKXmlParser2OOMTests() |
|
158 { |
|
159 #ifdef _DEBUG |
|
160 RFs fs; |
|
161 User::LeaveIfError(fs.Connect()); |
|
162 CTestContentHandler *sax = CTestContentHandler::NewL(); |
|
163 RFile handle; |
|
164 TInt err; |
|
165 CleanupClosePushL(handle); |
|
166 TRAP(err,handle.Open(fs, KSimpleXmlFile, EFileShareReadersOnly)); |
|
167 if (err != KErrNone) |
|
168 { |
|
169 INFO_PRINTF1(_L("Error opening test XML file")); |
|
170 User::Leave(err); |
|
171 } |
|
172 |
|
173 CMatchData *matchData = CMatchData::NewL(); |
|
174 matchData->SetMimeTypeL(_L8("text/xml")); |
|
175 matchData->SetVariantL(_L8("libxml2")); |
|
176 CParser *parser = CParser::NewL(*matchData, *sax); |
|
177 CleanupStack::PushL(parser); |
|
178 |
|
179 __UHEAP_SETFAIL(RHeap::EDeterministic, 40); |
|
180 TRAP(err,ParseL(*parser, handle)); |
|
181 //it could be a random error |
|
182 if (err == KErrNone) |
|
183 { |
|
184 return EFail; |
|
185 } |
|
186 INFO_PRINTF1(_L("Tests passed at Heap failure rate :40")); |
|
187 parser->ParseBeginL(); |
|
188 __UHEAP_SETFAIL(RHeap::EDeterministic, 50); |
|
189 TRAP(err,ParseL(*parser, handle)); |
|
190 //it could be a random error |
|
191 if (err == KErrNone) |
|
192 { |
|
193 return EFail; |
|
194 } |
|
195 INFO_PRINTF1(_L("Tests passed at Heap failure rate :50")); |
|
196 parser->ParseBeginL(); |
|
197 __UHEAP_SETFAIL(RHeap::EDeterministic, 100); |
|
198 TRAP(err,ParseL(*parser, handle)); |
|
199 //it could be a random error |
|
200 if (err == KErrNone) |
|
201 { |
|
202 return EFail; |
|
203 } |
|
204 INFO_PRINTF1(_L("Tests passed at Heap failure rate :100")); |
|
205 parser->ParseBeginL(); |
|
206 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
207 fs.Close(); |
|
208 CleanupStack::Pop(parser); |
|
209 CleanupStack::Pop(&handle); |
|
210 #else |
|
211 INFO_PRINTF1(_L("This test is meant to be run only in DEBUG builds. Returning EPASS")); |
|
212 #endif |
|
213 return EPass; |
|
214 } |
|
215 |
|
216 /** |
|
217 * This test step should be run only on debug builds owing to the |
|
218 * __UHEAP macros that are defined only in debug builds. |
|
219 */ |
|
220 TVerdict CXmlParser2Step::TestKXmlParser2OOMTests2() |
|
221 { |
|
222 #ifdef _DEBUG |
|
223 RFs fs; |
|
224 User::LeaveIfError(fs.Connect()); |
|
225 CTestContentHandler *sax = CTestContentHandler::NewL(); |
|
226 RFile handle; |
|
227 TInt err; |
|
228 CleanupClosePushL(handle); |
|
229 TRAP(err,handle.Open(fs, KSimpleXmlFile, EFileShareReadersOnly)); |
|
230 if (err != KErrNone) |
|
231 { |
|
232 INFO_PRINTF1(_L("Error opening test XML file")); |
|
233 User::Leave(err); |
|
234 } |
|
235 |
|
236 CMatchData *matchData = CMatchData::NewL(); |
|
237 matchData->SetMimeTypeL(_L8("text/xml")); |
|
238 matchData->SetVariantL(_L8("libxml2")); |
|
239 CParser *parser = CParser::NewL(*matchData, *sax); |
|
240 CleanupStack::PushL(parser); |
|
241 |
|
242 __UHEAP_SETFAIL(RHeap::EDeterministic, 1); |
|
243 TRAP(err,ParseL(*parser, handle)); |
|
244 if (err != KErrNoMemory) |
|
245 { |
|
246 return EFail; |
|
247 } |
|
248 INFO_PRINTF1(_L("Tests passed at Heap failure rate :1")); |
|
249 __UHEAP_SETFAIL(RHeap::EDeterministic, 33); |
|
250 TRAP(err,ParseL(*parser, handle)); |
|
251 //it could be a random error |
|
252 if (err == KErrNone) |
|
253 { |
|
254 return EFail; |
|
255 } |
|
256 INFO_PRINTF1(_L("Tests passed at Heap failure rate :33")); |
|
257 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
258 |
|
259 fs.Close(); |
|
260 CleanupStack::Pop(parser); |
|
261 CleanupStack::Pop(&handle); |
|
262 #else |
|
263 INFO_PRINTF1(_L("This test is meant to be run only in DEBUG builds. Returning EPASS")); |
|
264 #endif |
|
265 return EPass; |
|
266 } |
|
267 /** |
|
268 * This test step should be run only on debug builds owing to the |
|
269 * __UHEAP macros that are defined only in debug builds. |
|
270 */ |
|
271 TVerdict CXmlParser2Step::TestKXmlParser2OOMTests3() |
|
272 { |
|
273 #ifdef _DEBUG |
|
274 RFs fs; |
|
275 User::LeaveIfError(fs.Connect()); |
|
276 CTestContentHandler *sax = CTestContentHandler::NewL(); |
|
277 RFile handle; |
|
278 TInt err; |
|
279 CleanupClosePushL(handle); |
|
280 TRAP(err,handle.Open(fs, KSimpleXmlFile, EFileShareReadersOnly)); |
|
281 if (err != KErrNone) |
|
282 { |
|
283 INFO_PRINTF1(_L("Error opening test XML file")); |
|
284 User::Leave(err); |
|
285 } |
|
286 |
|
287 CMatchData *matchData = CMatchData::NewL(); |
|
288 matchData->SetMimeTypeL(_L8("text/xml")); |
|
289 matchData->SetVariantL(_L8("libxml2")); |
|
290 CParser *parser = CParser::NewL(*matchData, *sax); |
|
291 CleanupStack::PushL(parser); |
|
292 |
|
293 __UHEAP_SETFAIL(RHeap::EDeterministic, 32); |
|
294 TRAP(err,ParseL(*parser, handle)); |
|
295 //it could be a random error |
|
296 if (err == KErrNone) |
|
297 { |
|
298 return EFail; |
|
299 } |
|
300 INFO_PRINTF1(_L("Tests passed at Heap failure rate :32")); |
|
301 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
302 |
|
303 fs.Close(); |
|
304 CleanupStack::Pop(parser); |
|
305 CleanupStack::Pop(&handle); |
|
306 #else |
|
307 INFO_PRINTF1(_L("This test is meant to be run only in DEBUG builds. Returning EPASS")); |
|
308 #endif |
|
309 return EPass; |
|
310 } |
|
311 |
|
312 TVerdict CXmlParser2Step::TestKXmlParser2OOMTests4() |
|
313 { |
|
314 #ifdef _DEBUG |
|
315 RFs fs; |
|
316 User::LeaveIfError(fs.Connect()); |
|
317 CTestContentHandler *sax = CTestContentHandler::NewL(); |
|
318 RFile handle; |
|
319 TInt err; |
|
320 CleanupClosePushL(handle); |
|
321 TRAP(err,handle.Open(fs, KCorruptXm1File, EFileShareReadersOnly)); |
|
322 if (err != KErrNone) |
|
323 { |
|
324 INFO_PRINTF1(_L("Error opening test XML file")); |
|
325 User::Leave(err); |
|
326 } |
|
327 |
|
328 CMatchData *matchData = CMatchData::NewL(); |
|
329 CleanupStack::PushL(matchData); |
|
330 matchData->SetMimeTypeL(_L8("text/xml")); |
|
331 matchData->SetVariantL(_L8("libxml2")); |
|
332 CParser *parser = CParser::NewL(*matchData, *sax); |
|
333 CleanupStack::PushL(parser); |
|
334 |
|
335 __UHEAP_SETFAIL(RHeap::EDeterministic, 72); |
|
336 |
|
337 TRAP(err,ParseL(*parser, handle);); |
|
338 TInt EXmlTagMismatch = -993; //copied from xmlparseerrors.h |
|
339 if (err != EXmlTagMismatch) |
|
340 { |
|
341 return EFail; |
|
342 } |
|
343 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
344 |
|
345 fs.Close(); |
|
346 CleanupStack::Pop(parser); |
|
347 CleanupStack::Pop(matchData); |
|
348 CleanupStack::Pop(&handle); |
|
349 #else |
|
350 INFO_PRINTF1(_L("This test is meant to be run only in DEBUG builds. Returning EPASS")); |
|
351 #endif |
|
352 return EPass; |
|
353 } |