1 /* |
|
2 * Copyright (c) 2008-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 the License "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 /** |
|
20 @file |
|
21 @internalTechnology |
|
22 */ |
|
23 |
|
24 #include "tsifcommonunitteststep.h" |
|
25 #include "tsifsuitedefs.h" |
|
26 #include <usif/sif/sifcommon.h> |
|
27 #include <ct/rcpointerarray.h> |
|
28 #include <scs/cleanuputils.h> |
|
29 #include <s32mem.h> |
|
30 |
|
31 using namespace Usif; |
|
32 |
|
33 namespace |
|
34 { |
|
35 TInt PackCapabilitySet(const TCapabilitySet& aCapSet) |
|
36 { |
|
37 TInt caps=0; |
|
38 for (TInt c=0; c<ECapability_Limit; ++c) |
|
39 { |
|
40 if (aCapSet.HasCapability(TCapability(c))) |
|
41 { |
|
42 caps += (1<<c); |
|
43 } |
|
44 } |
|
45 return caps; |
|
46 } |
|
47 } |
|
48 |
|
49 CSifCommonUnitTestStep::~CSifCommonUnitTestStep() |
|
50 /** |
|
51 * Destructor |
|
52 */ |
|
53 { |
|
54 INFO_PRINTF1(_L("Cleanup in CSifCommonUnitTestStep::~CSifCommonUnitTestStep()")); |
|
55 } |
|
56 |
|
57 CSifCommonUnitTestStep::CSifCommonUnitTestStep() |
|
58 /** |
|
59 * Constructor |
|
60 */ |
|
61 { |
|
62 } |
|
63 |
|
64 void CSifCommonUnitTestStep::ImplTestStepL() |
|
65 /** |
|
66 * @return - TVerdict code |
|
67 * Override of base class pure virtual |
|
68 * Our implementation only gets called if the base class doTestStepPreambleL() did |
|
69 * not leave. That being the case, the current test result value will be EPass. |
|
70 */ |
|
71 { |
|
72 INFO_PRINTF1(_L("I am in CSifCommonUnitTestStep::doTestStep().")); |
|
73 |
|
74 SetTestStepResult(EFail); |
|
75 TestComponentInfoL(); |
|
76 |
|
77 TestOpaqueNamedParamsL(); |
|
78 |
|
79 SetTestStepResult(EPass); |
|
80 } |
|
81 |
|
82 |
|
83 |
|
84 void CSifCommonUnitTestStep::ImplTestStepPostambleL() |
|
85 /** |
|
86 * @return - TVerdict code |
|
87 * Override of base class virtual |
|
88 */ |
|
89 { |
|
90 } |
|
91 |
|
92 |
|
93 void CSifCommonUnitTestStep::ImplTestStepPreambleL() |
|
94 /** |
|
95 * @return - TVerdict code |
|
96 * Override of base class virtual |
|
97 */ |
|
98 { |
|
99 } |
|
100 |
|
101 void CSifCommonUnitTestStep::TestComponentInfoL() |
|
102 { |
|
103 TCapabilitySet capSet(ECapabilityReadDeviceData); |
|
104 RPointerArray<Usif::CComponentInfo::CApplicationInfo>* applications = NULL; |
|
105 CComponentInfo* compInfo = CComponentInfo::NewLC(); |
|
106 |
|
107 /* Internalize from an empty descriptor and read invalid root node */ |
|
108 TIpcArgs ipcArgs; |
|
109 compInfo->PrepareForIpcL(ipcArgs, 0); |
|
110 TDes8* des = reinterpret_cast<TDes8*>(ipcArgs.iArgs[0]); |
|
111 des->FillZ(1); |
|
112 TRAPD(err, compInfo->RootNodeL()); |
|
113 if (err != KErrNotFound) |
|
114 { |
|
115 INFO_PRINTF1(_L("Internalize from an empty descriptor and read invalid root node")); |
|
116 User::Leave(err); |
|
117 } |
|
118 CleanupStack::PopAndDestroy(compInfo); |
|
119 |
|
120 /* Add invalid child */ |
|
121 CComponentInfo::CNode* node = CComponentInfo::CNode::NewLC(KNullDesC, KNullDesC, KNullDesC, KNullDesC, EDeactivated, ENewComponent, 12345678, KNullDesC, ENotAuthenticated, capSet, 1234, EFalse, EFalse, applications); |
|
122 TRAP(err, node->AddChildL(NULL)); |
|
123 if (err != KErrArgument) |
|
124 { |
|
125 INFO_PRINTF1(_L("TestComponentInfoL: Add invalid child")); |
|
126 User::Leave(err); |
|
127 } |
|
128 /* Get empty GlobalComponentId */ |
|
129 if (node->GlobalComponentId() != KNullDesC) |
|
130 { |
|
131 INFO_PRINTF1(_L("TestComponentInfoL: Get empty GlobalComponentId")); |
|
132 User::Leave(KErrGeneral); |
|
133 } |
|
134 CleanupStack::PopAndDestroy(node); |
|
135 |
|
136 /* Overflow detection */ |
|
137 const TInt maxDescriptorLength = 256; |
|
138 const TInt tooBigLen = maxDescriptorLength + 1; |
|
139 const TInt maxSize = 1234; |
|
140 const TBool hasExe = EFalse; |
|
141 const TBool driveSelectionRequired = EFalse; |
|
142 |
|
143 HBufC* tooBigStr = HBufC::NewLC(tooBigLen); |
|
144 TPtr tooBigStrPtr = tooBigStr->Des(); |
|
145 tooBigStrPtr.FillZ(tooBigLen); |
|
146 |
|
147 // for SoftwareTypeName |
|
148 TRAP(err, CComponentInfo::CNode::NewLC(*tooBigStr, KNullDesC, KNullDesC, KNullDesC, EDeactivated, ENewComponent, 12345678, KNullDesC, ENotAuthenticated, capSet, maxSize, hasExe, driveSelectionRequired, applications)); |
|
149 if (err != KErrOverflow) |
|
150 { |
|
151 INFO_PRINTF1(_L("TestComponentInfoL: Overflow detection for SoftwareTypeName")); |
|
152 User::Leave(err); |
|
153 } |
|
154 |
|
155 // for ComponentName |
|
156 TRAP(err, CComponentInfo::CNode::NewLC(KNullDesC, *tooBigStr, KNullDesC, KNullDesC, EDeactivated, ENewComponent, 12345678, KNullDesC, ENotAuthenticated, capSet, maxSize, hasExe, driveSelectionRequired, applications)); |
|
157 if (err != KErrOverflow) |
|
158 { |
|
159 INFO_PRINTF1(_L("TestComponentInfoL: Overflow detection for ComponentName")); |
|
160 User::Leave(err); |
|
161 } |
|
162 |
|
163 // for Version |
|
164 TRAP(err, CComponentInfo::CNode::NewLC(KNullDesC, KNullDesC, *tooBigStr, KNullDesC, EDeactivated, ENewComponent, 12345678, KNullDesC, ENotAuthenticated, capSet, maxSize, hasExe, driveSelectionRequired, applications)); |
|
165 if (err != KErrOverflow) |
|
166 { |
|
167 INFO_PRINTF1(_L("TestComponentInfoL: Overflow detection for aVersion")); |
|
168 User::Leave(err); |
|
169 } |
|
170 |
|
171 // for Vendor |
|
172 TRAP(err, CComponentInfo::CNode::NewLC(KNullDesC, KNullDesC, KNullDesC, *tooBigStr, EDeactivated, ENewComponent, 12345678, KNullDesC, ENotAuthenticated, capSet, maxSize, hasExe, driveSelectionRequired, applications)); |
|
173 if (err != KErrOverflow) |
|
174 { |
|
175 INFO_PRINTF1(_L("TestComponentInfoL: Overflow detection for aVendor")); |
|
176 User::Leave(err); |
|
177 } |
|
178 |
|
179 // for GlobalComponentId |
|
180 TRAP(err, CComponentInfo::CNode::NewLC(KNullDesC, KNullDesC, KNullDesC, KNullDesC, EDeactivated, ENewComponent, 12345678, *tooBigStr, ENotAuthenticated, capSet, maxSize, hasExe, driveSelectionRequired, applications)); |
|
181 if (err != KErrOverflow) |
|
182 { |
|
183 INFO_PRINTF1(_L("TestComponentInfoL: Overflow detection for GlobalComponentId")); |
|
184 User::Leave(err); |
|
185 } |
|
186 |
|
187 CleanupStack::PopAndDestroy(tooBigStr); |
|
188 |
|
189 /* Testing embedded nodes */ |
|
190 compInfo = CComponentInfo::NewLC(); |
|
191 |
|
192 /* Set invalid root node */ |
|
193 TRAP(err, compInfo->SetRootNodeL(NULL)); |
|
194 if (err != KErrArgument) |
|
195 { |
|
196 INFO_PRINTF1(_L("TestComponentInfoL: Set invalid root node")); |
|
197 User::Leave(err); |
|
198 } |
|
199 |
|
200 CComponentInfo::CNode* emptyNode = CComponentInfo::CNode::NewLC(KNullDesC, KNullDesC, KNullDesC, KNullDesC, EDeactivated, ENewComponent, 12345678, KNullDesC, ENotAuthenticated, capSet, 1234, EFalse, EFalse, applications); |
|
201 const TDesC& globalComponentId(emptyNode->GlobalComponentId()); |
|
202 ASSERT(globalComponentId.Length() == 0); |
|
203 TRAP(err, compInfo->SetRootNodeAsChildL(*emptyNode)); |
|
204 if (err != KErrNotFound) |
|
205 { |
|
206 INFO_PRINTF1(_L("TestComponentInfoL: Set root node as child without a root node")); |
|
207 User::Leave(err); |
|
208 } |
|
209 CleanupStack::PopAndDestroy(emptyNode); |
|
210 |
|
211 // Create root node |
|
212 _LIT(KTxtRootSoftwareTypeName, "Test Software Type"); |
|
213 _LIT(KTxtRootComponentName, "Root Component"); |
|
214 _LIT(KTxtRootVersion, "1.0.0"); |
|
215 _LIT(KTxtRootVendor, "Symbian"); |
|
216 _LIT(KTxtRootGlobalComponentId, "Root Component Global Id"); |
|
217 CComponentInfo::CNode* root = CComponentInfo::CNode::NewLC(KTxtRootSoftwareTypeName, |
|
218 KTxtRootComponentName, KTxtRootVersion, KTxtRootVendor, EDeactivated, |
|
219 ENewComponent, 12345678, KTxtRootGlobalComponentId, ENotAuthenticated, capSet, maxSize, hasExe, driveSelectionRequired, applications); |
|
220 |
|
221 // Create an array of nodes |
|
222 RCPointerArray<CComponentInfo::CNode> children; |
|
223 CleanupClosePushL(children); |
|
224 |
|
225 // Create second child node |
|
226 _LIT(KTxtChild2SoftwareTypeName, "Test Software Type"); |
|
227 _LIT(KTxtChild2ComponentName, "Child2 Component"); |
|
228 _LIT(KTxtChild2Version, "1.2.0"); |
|
229 _LIT(KTxtChild2Vendor, "Symbian"); |
|
230 _LIT(KTxtChild2GlobalComponentId, "Child2 Component Global Id"); |
|
231 CComponentInfo::CNode* child2 = CComponentInfo::CNode::NewLC(KTxtChild2SoftwareTypeName, |
|
232 KTxtChild2ComponentName, KTxtChild2Version, KTxtChild2Vendor, EDeactivated, |
|
233 ENewComponent, 12345678, KTxtChild2GlobalComponentId, ENotAuthenticated, capSet, maxSize, hasExe, driveSelectionRequired, applications); |
|
234 children.AppendL(child2); |
|
235 CleanupStack::Pop(child2); |
|
236 |
|
237 // Create third child node |
|
238 _LIT(KTxtChild3SoftwareTypeName, "Test Software Type"); |
|
239 _LIT(KTxtChild3ComponentName, "Child3 Component"); |
|
240 _LIT(KTxtChild3Version, "1.3.0"); |
|
241 _LIT(KTxtChild3Vendor, "Symbian"); |
|
242 _LIT(KTxtChild3GlobalComponentId, "Child3 Component Global Id"); |
|
243 CComponentInfo::CNode* child3 = CComponentInfo::CNode::NewLC(KTxtChild3SoftwareTypeName, |
|
244 KTxtChild3ComponentName, KTxtChild3Version, KTxtChild3Vendor, EDeactivated, |
|
245 ENewComponent, 12345678, KTxtChild3GlobalComponentId, ENotAuthenticated, capSet, maxSize, hasExe, driveSelectionRequired, applications); |
|
246 children.AppendL(child3); |
|
247 CleanupStack::Pop(child3); |
|
248 |
|
249 // Create first child node |
|
250 _LIT(KTxtChild1SoftwareTypeName, "Test Software Type"); |
|
251 _LIT(KTxtChild1ComponentName, "Child1 Component"); |
|
252 _LIT(KTxtChild1Version, "1.1.0"); |
|
253 _LIT(KTxtChild1Vendor, "Symbian"); |
|
254 _LIT(KTxtChild1GlobalComponentId, "Child1 Component Global Id"); |
|
255 CComponentInfo::CNode* child1 = CComponentInfo::CNode::NewLC(KTxtChild1SoftwareTypeName, |
|
256 KTxtChild1ComponentName, KTxtChild1Version, KTxtChild1Vendor, EDeactivated, |
|
257 ENewComponent, 12345678, KTxtChild1GlobalComponentId, ENotAuthenticated, capSet, |
|
258 maxSize, hasExe, driveSelectionRequired, applications, &children); |
|
259 root->AddChildL(child1); |
|
260 CleanupStack::Pop(child1); |
|
261 CleanupStack::PopAndDestroy(&children); |
|
262 |
|
263 // Set the root node |
|
264 compInfo->SetRootNodeL(root); |
|
265 CleanupStack::Pop(root); |
|
266 |
|
267 // Check the content of the third node |
|
268 const CComponentInfo::CNode& rootNode = compInfo->RootNodeL(); |
|
269 const CComponentInfo::CNode& child1Node = *rootNode.Children()[0]; |
|
270 const CComponentInfo::CNode& child3Node = *child1Node.Children()[1]; |
|
271 |
|
272 if (child3Node.SoftwareTypeName() != KTxtChild3SoftwareTypeName || |
|
273 child3Node.ComponentName() != KTxtChild3ComponentName || |
|
274 child3Node.Version() != KTxtChild3Version || |
|
275 child3Node.Vendor() != KTxtChild3Vendor || |
|
276 child3Node.ScomoState() != EDeactivated || |
|
277 child3Node.InstallStatus() != ENewComponent || |
|
278 child3Node.ComponentId() != 12345678 || |
|
279 child3Node.GlobalComponentId() != KTxtChild3GlobalComponentId || |
|
280 child3Node.Authenticity() != ENotAuthenticated || |
|
281 PackCapabilitySet(child3Node.UserGrantableCaps()) != PackCapabilitySet(capSet) || |
|
282 child3Node.MaxInstalledSize() != maxSize || |
|
283 child3Node.Children().Count() != 0) |
|
284 { |
|
285 INFO_PRINTF1(_L("TestComponentInfoL: 'Testing embedded nodes' failed")); |
|
286 User::Leave(KErrGeneral); |
|
287 } |
|
288 |
|
289 CleanupStack::PopAndDestroy(compInfo); |
|
290 } |
|
291 |
|
292 void CSifCommonUnitTestStep::TestOpaqueNamedParamsL() |
|
293 { |
|
294 _LIT(KParamName1, "param 1"); |
|
295 _LIT(KParamName2, "param 2"); |
|
296 _LIT(KParamName3, "param 3"); |
|
297 _LIT(KParamName4, "param 4"); |
|
298 _LIT(KParamName5, "param 5"); |
|
299 |
|
300 _LIT(KStringValue1, "value 1"); |
|
301 _LIT(KStringValue2, "value 2"); |
|
302 _LIT(KStringValue3, "value 3"); |
|
303 |
|
304 const TInt KIntValue1 = 111; |
|
305 const TInt KIntValue2 = 222; |
|
306 const TInt KIntValue3 = 333; |
|
307 |
|
308 //String Array |
|
309 RPointerArray<HBufC> stringArray; |
|
310 CleanupResetAndDestroyPushL(stringArray); |
|
311 |
|
312 HBufC* stringPtr = KStringValue1().AllocLC(); |
|
313 stringArray.AppendL(stringPtr); |
|
314 CleanupStack::Pop(); |
|
315 |
|
316 stringPtr = KStringValue2().AllocLC(); |
|
317 stringArray.AppendL(stringPtr); |
|
318 CleanupStack::Pop(); |
|
319 |
|
320 stringPtr = KStringValue3().AllocLC(); |
|
321 stringArray.AppendL(stringPtr); |
|
322 CleanupStack::Pop(); |
|
323 |
|
324 //Int Array |
|
325 RArray<TInt> intArray; |
|
326 CleanupClosePushL(intArray); |
|
327 intArray.AppendL(KIntValue1); |
|
328 intArray.AppendL(KIntValue2); |
|
329 intArray.AppendL(KIntValue3); |
|
330 |
|
331 /* NewL */ |
|
332 COpaqueNamedParams* params1 = COpaqueNamedParams::NewL(); |
|
333 CleanupStack::PushL(params1); |
|
334 |
|
335 /* String operations */ |
|
336 |
|
337 // AddStringL for a new param |
|
338 params1->AddStringL(KParamName1, KStringValue2); |
|
339 // AddStringL for an already existing param |
|
340 params1->AddStringL(KParamName1, KStringValue1); |
|
341 // StringByName for an existing param |
|
342 if (params1->StringByNameL(KParamName1) != KStringValue1) |
|
343 { |
|
344 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'StringByName for an existing param' failed")); |
|
345 User::Leave(KErrGeneral); |
|
346 } |
|
347 // StringByName for a non-existing param |
|
348 if (params1->StringByNameL(KParamName2) != KNullDesC) |
|
349 { |
|
350 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'StringByName for a non-existing param' failed")); |
|
351 User::Leave(KErrGeneral); |
|
352 } |
|
353 // StringByNameL for an existing param |
|
354 if (params1->StringByNameL(KParamName1) != KStringValue1) |
|
355 { |
|
356 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'StringByNameL for an existing param' failed")); |
|
357 User::Leave(KErrGeneral); |
|
358 } |
|
359 //Added as string , trying to retrieve as int. |
|
360 TRAPD(err, params1->IntByNameL(KParamName1)); |
|
361 if(err != KErrNotFound) |
|
362 { |
|
363 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'IntByNameL for an existing param' failed")); |
|
364 User::Leave(KErrGeneral); |
|
365 } |
|
366 // StringByNameL for a non-existing param |
|
367 if (params1->StringByNameL(KParamName2) != KNullDesC) |
|
368 { |
|
369 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'StringByNameL for a non-existing param' failed")); |
|
370 User::Leave(KErrGeneral); |
|
371 } |
|
372 |
|
373 CleanupStack::PopAndDestroy(params1); |
|
374 |
|
375 /* NewLC */ |
|
376 COpaqueNamedParams* params2 = COpaqueNamedParams::NewLC(); |
|
377 |
|
378 /* Int operations */ |
|
379 |
|
380 // AddIntL for a new param |
|
381 params2->AddIntL(KParamName1, KIntValue2); |
|
382 // AddIntL for an already existing param |
|
383 params2->AddIntL(KParamName1, KIntValue1); |
|
384 // GetIntByName for an existing param |
|
385 TInt intValue1 = 0; |
|
386 if (!params2->GetIntByNameL(KParamName1, intValue1) || intValue1 != KIntValue1) |
|
387 { |
|
388 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'GetIntByName for an existing param' failed")); |
|
389 User::Leave(KErrGeneral); |
|
390 } |
|
391 // GetIntByName for a non-existing param |
|
392 if (params2->GetIntByNameL(KParamName2, intValue1)) |
|
393 { |
|
394 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'GetIntByName for a non-existing param' failed")); |
|
395 User::Leave(KErrGeneral); |
|
396 } |
|
397 // IntByNameL for an existing param |
|
398 if (params2->IntByNameL(KParamName1) != KIntValue1) |
|
399 { |
|
400 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'IntByNameL for an existing param' failed")); |
|
401 User::Leave(KErrGeneral); |
|
402 } |
|
403 // IntByNameL for a non-existing param |
|
404 TRAP(err, params2->IntByNameL(KParamName2)); |
|
405 if (err != KErrNotFound) |
|
406 { |
|
407 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'IntByNameL for a non-existing param' failed")); |
|
408 User::Leave(err); |
|
409 } |
|
410 |
|
411 /* GetNamesL & Count*/ |
|
412 params2->AddStringL(KParamName2, KStringValue2); |
|
413 params2->AddIntL(KParamName3, KIntValue3); |
|
414 RCPointerArray<HBufC> names; |
|
415 CleanupClosePushL(names); |
|
416 params2->GetNamesL(names); |
|
417 if (params2->CountL() != 3 || names.Count() != 3 || |
|
418 *names[0] != KParamName1 || *names[1] != KParamName2 || *names[2] != KParamName3) |
|
419 { |
|
420 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'GetNamesL & Count' failed")); |
|
421 User::Leave(KErrGeneral); |
|
422 } |
|
423 |
|
424 /* Overflow detection */ |
|
425 |
|
426 COpaqueNamedParams* params3 = COpaqueNamedParams::NewLC(); |
|
427 |
|
428 const TInt bigLen = 128; |
|
429 HBufC* bigStr = HBufC::NewLC(bigLen); |
|
430 TPtr bigStrPtr = bigStr->Des(); |
|
431 bigStrPtr.FillZ(bigLen); |
|
432 |
|
433 // Max acceptable length of descriptor |
|
434 const TInt maxGoodLen = 128/2; |
|
435 TRAP(err, params3->AddStringL(KParamName1, bigStr->Left(maxGoodLen))); |
|
436 if (err != KErrNone) |
|
437 { |
|
438 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'Overflow detection: Max acceptable length of descriptor'")); |
|
439 User::Leave(err); |
|
440 } |
|
441 |
|
442 // Too big descriptor - same param name |
|
443 const TInt tooBigLen = 128/2+1; |
|
444 TRAP(err, params3->AddStringL(KParamName1, bigStr->Left(tooBigLen))); |
|
445 if (err != KErrOverflow) |
|
446 { |
|
447 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'Overflow detection: Too big descriptor - updated param'")); |
|
448 User::Leave(err); |
|
449 } |
|
450 |
|
451 // Too big descriptor - different param name |
|
452 TRAP(err, params3->AddStringL(KParamName2, bigStr->Left(tooBigLen))); |
|
453 if (err != KErrOverflow) |
|
454 { |
|
455 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'Overflow detection: Too big descriptor - new param'")); |
|
456 User::Leave(err); |
|
457 } |
|
458 |
|
459 // Overflow in KMaxExternalizedSize |
|
460 params3->AddStringL(KParamName3, bigStr->Left(maxGoodLen)); |
|
461 params3->AddStringL(KParamName4, bigStr->Left(maxGoodLen)); |
|
462 params3->AddStringL(KParamName4, bigStr->Left(maxGoodLen)); // Add the same param to check overwriting |
|
463 TRAP(err, params3->AddStringL(KParamName5, bigStr->Left(maxGoodLen))); |
|
464 if (err != KErrOverflow) |
|
465 { |
|
466 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'Overflow detection: Overflow in KMaxExternalizedSize'")); |
|
467 User::Leave(err); |
|
468 } |
|
469 |
|
470 CleanupStack::PopAndDestroy(4, params2); |
|
471 |
|
472 COpaqueNamedParams* params4 = COpaqueNamedParams::NewLC(); |
|
473 |
|
474 params4->AddStringArrayL(KParamName1, stringArray); |
|
475 |
|
476 const RPointerArray<HBufC>& strArray = params4->StringArrayByNameL(KParamName1); |
|
477 if(*strArray[0] != KStringValue1 || *strArray[1] != KStringValue2 || *strArray[2] != KStringValue3) |
|
478 { |
|
479 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: StringArrayByNameL failed")); |
|
480 User::Leave(err); |
|
481 } |
|
482 |
|
483 TRAP(err, const RArray<TInt>& intArray1 = params4->IntArrayByNameL(KParamName1)); |
|
484 if(err != KErrNotFound) |
|
485 { |
|
486 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: IntArrayByNameL failed")); |
|
487 User::Leave(err); |
|
488 } |
|
489 //Append a big string ( greater than 128 bytes) |
|
490 HBufC* largeString = HBufC::NewLC(150); |
|
491 largeString->Des().FillZ(150); |
|
492 stringArray.AppendL(largeString); |
|
493 CleanupStack::Pop(); |
|
494 |
|
495 TRAP(err, params4->AddStringArrayL(KParamName1, stringArray)); |
|
496 |
|
497 if(err != KErrOverflow) |
|
498 { |
|
499 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: AddStringArrayL overflow check failed")); |
|
500 User::Leave(err); |
|
501 } |
|
502 |
|
503 stringArray.ResetAndDestroy(); |
|
504 // Few large strings |
|
505 HBufC* bigString2 = HBufC::NewLC(64); |
|
506 bigString2->Des().FillZ(64); |
|
507 stringArray.AppendL(bigString2); |
|
508 CleanupStack::Pop(); |
|
509 |
|
510 HBufC* bigString3 = HBufC::NewLC(64); |
|
511 bigString3->Des().FillZ(64); |
|
512 stringArray.AppendL(bigString3); |
|
513 CleanupStack::Pop(); |
|
514 |
|
515 HBufC* bigString4 = HBufC::NewLC(64); |
|
516 bigString4->Des().FillZ(64); |
|
517 stringArray.AppendL(bigString4); |
|
518 CleanupStack::Pop(); |
|
519 |
|
520 HBufC* bigString5 = HBufC::NewLC(64); |
|
521 bigString5->Des().FillZ(64); |
|
522 stringArray.AppendL(bigString5); |
|
523 CleanupStack::Pop(); |
|
524 |
|
525 TRAP(err, params4->AddStringArrayL(KParamName1, stringArray)); |
|
526 |
|
527 if(err != KErrOverflow) |
|
528 { |
|
529 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: AddStringArrayL overflow check failed")); |
|
530 User::Leave(err); |
|
531 } |
|
532 params4->AddIntArrayL(KParamName1, intArray); |
|
533 const RArray<TInt>& RefIntArray = params4->IntArrayByNameL(KParamName1); |
|
534 if(RefIntArray[0] != KIntValue1 || RefIntArray[1] != KIntValue2 || RefIntArray[2] != KIntValue3) |
|
535 { |
|
536 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: IntArrayByNameL failed")); |
|
537 User::Leave(err); |
|
538 } |
|
539 |
|
540 TRAP(err, const RPointerArray<HBufC>& strArray1 = params4->StringArrayByNameL(KParamName1)); |
|
541 if(err != KErrNotFound) |
|
542 { |
|
543 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: StringArrayByNameL failed")); |
|
544 User::Leave(err); |
|
545 } |
|
546 |
|
547 CleanupStack::PopAndDestroy(3, &stringArray); |
|
548 |
|
549 //Externalize, internalize tests. |
|
550 COpaqueNamedParams* params5 = COpaqueNamedParams::NewLC(); |
|
551 HBufC* testString = _L("TestString").AllocLC(); |
|
552 |
|
553 params5->AddStringL(_L("key1"), *testString); |
|
554 params5->AddIntL(_L("key2"), 23); |
|
555 |
|
556 RArray<TInt> intArray2; |
|
557 CleanupClosePushL(intArray2); |
|
558 intArray2.AppendL(100); |
|
559 intArray2.AppendL(200); |
|
560 |
|
561 RPointerArray<HBufC> stringArray2; |
|
562 CleanupResetAndDestroyPushL(stringArray2); |
|
563 const HBufC16* testString1 = _L("TestString1").AllocLC(); |
|
564 |
|
565 |
|
566 TInt err1 = stringArray2.Append(testString1); |
|
567 if (err1 != KErrNone) |
|
568 { |
|
569 CleanupStack::PopAndDestroy(); |
|
570 } |
|
571 else |
|
572 { |
|
573 CleanupStack::Pop(); |
|
574 } |
|
575 |
|
576 const HBufC16* testString2 = _L("TestString2").AllocLC(); |
|
577 TInt err2 = stringArray2.Append(testString2); |
|
578 if (err2 != KErrNone) |
|
579 { |
|
580 CleanupStack::PopAndDestroy(); |
|
581 } |
|
582 else |
|
583 { |
|
584 CleanupStack::Pop(); |
|
585 } |
|
586 params5->AddStringArrayL(_L("key3"), stringArray2); |
|
587 params5->AddIntArrayL(_L("key4"), intArray2); |
|
588 |
|
589 CBufFlat* externalizedBuffer = CBufFlat::NewL(150); |
|
590 CleanupStack::PushL(externalizedBuffer); |
|
591 |
|
592 RBufWriteStream writeStream(*externalizedBuffer); |
|
593 CleanupClosePushL(writeStream); |
|
594 |
|
595 params5->ExternalizeL(writeStream); |
|
596 |
|
597 COpaqueNamedParams* params6 = COpaqueNamedParams::NewLC(); |
|
598 |
|
599 RBufReadStream readStream(*externalizedBuffer); |
|
600 CleanupClosePushL(readStream); |
|
601 params6->InternalizeL(readStream); |
|
602 |
|
603 if(params6->IntByNameL(_L("key2"))!= 23 || (params6->StringByNameL(_L("key1")) != _L("TestString"))) |
|
604 { |
|
605 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: Internalize of int and string failed.")); |
|
606 User::Leave(err); |
|
607 } |
|
608 |
|
609 const RArray<TInt>& internalizedIntArray = params6->IntArrayByNameL(_L("key4")); |
|
610 |
|
611 if(internalizedIntArray[0] != 100 && internalizedIntArray[1] != 200) |
|
612 { |
|
613 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: Internalize of int array failed.")); |
|
614 User::Leave(err); |
|
615 } |
|
616 |
|
617 const RPointerArray<HBufC>& internalizedStringArray = params6->StringArrayByNameL(_L("key3")); |
|
618 |
|
619 if (err1 == KErrNone) |
|
620 { |
|
621 if(*internalizedStringArray[0] != _L("TestString1") && *internalizedStringArray[1] != _L("TestString2")) |
|
622 { |
|
623 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: Internalize of string array failed.")); |
|
624 User::Leave(err); |
|
625 } |
|
626 } |
|
627 else if (err2 == KErrNone) |
|
628 { |
|
629 if(*internalizedStringArray[0] != _L("TestString2")) |
|
630 { |
|
631 INFO_PRINTF1(_L("TestOpaqueNamedParamsL: Internalize of string array failed.")); |
|
632 User::Leave(err); |
|
633 } |
|
634 } |
|
635 |
|
636 CleanupStack::PopAndDestroy(8, params5); |
|
637 |
|
638 } |
|