Update contrib.
1 // Copyright (c) 2005-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #include <bsul/inifile.h> // CIniDocument8, CIniDocument16
24 RTest test(_L("Ini File Parser and Generator"));
29 #define UNUSED_VAR(a) a=a
31 _LIT(KIniFile16,"z:\\resource\\testconfig16.ini") ;
33 void LeaveIfNoMemory(TInt ret)
35 if (ret==KErrNoMemory)
36 User::LeaveNoMemory();
39 void CheckResources(RFs& aFs, TInt aOriginalHandleCount)
41 UNUSED_VAR(aOriginalHandleCount);
42 //check we haven't leaked any handles
43 TInt processHandleCount = 0;
44 TInt threadHandleCount = 0;
45 RThread().HandleCount(processHandleCount, threadHandleCount);
46 test(threadHandleCount == aOriginalHandleCount);
47 //check we haven't leaked any files
48 aFs.ResourceCountMarkEnd();
51 TBool CompareFilesL(RFs& aFs,const TDesC& aFileNameA,const TDesC& aFileNameB)
53 TBool filesAreSame=FALSE;
55 User::LeaveIfError(fileA.Open(aFs,aFileNameA,EFileShareReadersOrWriters ));
56 CleanupClosePushL(fileA);
58 User::LeaveIfError(fileB.Open(aFs,aFileNameB,EFileShareReadersOrWriters ));
59 CleanupClosePushL(fileB);
63 fileA.Size(filesizeA);
64 fileB.Size(filesizeB);
65 if ( filesizeA == filesizeB)
67 HBufC8* aBufferPtrA=HBufC8::NewLC(filesizeA);
68 HBufC8* aBufferPtrB=HBufC8::NewLC(filesizeB);
69 TPtr8 asWriteableBufferA(aBufferPtrA->Des());
70 User::LeaveIfError(fileA.Read(0,asWriteableBufferA,filesizeA));
71 TPtr8 asWriteableBufferB(aBufferPtrB->Des());
72 User::LeaveIfError(fileB.Read(0,asWriteableBufferB,filesizeB));
73 if (asWriteableBufferA.Compare(asWriteableBufferB) == 0)
77 CleanupStack::PopAndDestroy(2);
79 CleanupStack::PopAndDestroy(2);
83 class CIniParser16Test :public CBase
85 typedef void (CIniParser16Test::*ClassFuncPtr8L) (void);
88 static CIniParser16Test* NewL();
98 //heavy create and delete
99 static void CreateDeleteTest1L();
100 static void CreateDeleteOOMTestL();
103 static void CreateDeleteTest2L();
104 static void CreateDeleteOOMTest2L();
121 //OOM consistency test
124 //class function utilities
125 static void DoBasicTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc);
126 static void DoOOMTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc);
127 static void DoOOMWithConsistencyCheckTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc,const TBool aShouldBeSame);
129 CIniParser16Test():iIniDocument(NULL){}
130 CIniDocument16* iIniDocument;
133 CIniParser16Test* CIniParser16Test::NewL()
135 CIniParser16Test* self=new (ELeave)CIniParser16Test();
136 CleanupStack::PushL(self);
137 self->iIniDocument=CIniDocument16::NewL(TheRFs,KIniFile16);
142 void CIniParser16Test::DoBasicTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc)
144 test.Next(aTestDesc);
147 // find out the number of open handles
148 TInt startProcessHandleCount;
149 TInt startThreadHandleCount;
150 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
152 CIniParser16Test* iniTest=CIniParser16Test::NewL();
154 CleanupStack::PushL(iniTest);
156 (iniTest->*testFuncL)();
158 CleanupStack::PopAndDestroy();
160 // check that no handles have leaked
161 TInt endProcessHandleCount;
162 TInt endThreadHandleCount;
163 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
165 test(startProcessHandleCount == endProcessHandleCount);
166 test(startThreadHandleCount == endThreadHandleCount);
171 void CIniParser16Test::DoOOMTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc)
173 test.Next(aTestDesc);
180 // find out the number of open handles
181 TInt startProcessHandleCount;
182 TInt startThreadHandleCount;
183 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
185 CIniParser16Test* iniTest=CIniParser16Test::NewL();
186 CleanupStack::PushL(iniTest);
188 __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
189 TRAP(err, (iniTest->*testFuncL)());
190 __UHEAP_SETFAIL(RHeap::ENone, 0);
192 CleanupStack::PopAndDestroy(iniTest);
194 // check that no handles have leaked
195 TInt endProcessHandleCount;
196 TInt endThreadHandleCount;
197 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
199 test(startProcessHandleCount == endProcessHandleCount);
200 test(startThreadHandleCount == endThreadHandleCount);
203 } while(err == KErrNoMemory);
206 test.Printf(_L("- succeeded at heap failure rate of %i\n"), tryCount);
209 void CIniParser16Test::CreateDeleteOOMTestL()
217 // find out the number of open handles
218 TInt startProcessHandleCount;
219 TInt startThreadHandleCount;
220 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
222 __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
224 CIniDocument16* ini=NULL;
225 TRAP(err,ini=CIniDocument16::NewL(TheRFs,KIniFile16));
229 __UHEAP_SETFAIL(RHeap::ENone, 0);
231 // check that no handles have leaked
232 TInt endProcessHandleCount;
233 TInt endThreadHandleCount;
234 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
235 test(startProcessHandleCount == endProcessHandleCount);
236 test(startThreadHandleCount == endThreadHandleCount);
239 } while(err == KErrNoMemory);
242 test.Printf(_L("- succeeded at heap failure rate of %i\n"), tryCount);
245 void CIniParser16Test::DoOOMWithConsistencyCheckTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc, const TBool aShouldBeSame)
247 test.Next(aTestDesc);
249 // find out the number of open handles
250 TInt startProcessHandleCount = 0;
251 TInt startThreadHandleCount = 0;
252 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
254 //Compare the results against this instance.
256 CIniDocument16* referenceDoc=NULL;
257 TRAP(err,referenceDoc=CIniDocument16::NewL(TheRFs,KIniFile16));
258 User::LeaveIfError(err);
259 CleanupStack::PushL(referenceDoc);
261 //Open a file and Externalise the reference oom to it.
262 User::LeaveIfError(referenceDoc->Externalise(_L("c:\\initest\\oom_ref16.ini")));
263 CIniParser16Test* iniTest=NULL;
265 for (TInt i = 1;;i++)
270 TRAP(err, iniTest=CIniParser16Test::NewL());
274 CleanupStack::PushL(iniTest);
276 TRAP(err, (iniTest->*testFuncL)());
279 test(iniTest->iIniDocument->CompareDocs(*referenceDoc));
280 CleanupStack::PopAndDestroy(iniTest);
281 __UHEAP_SETFAIL(RHeap::ENone, 0);
287 //Open a file and Externalise to it.
288 TRAP(err, iniTest->iIniDocument->Externalise(_L("c:\\initest\\oom16.ini")));
291 CleanupStack::PopAndDestroy(iniTest);
292 __UHEAP_SETFAIL(RHeap::ENone, 0);
299 TRAP(err, result=CompareFilesL(TheRFs,_L("c:\\initest\\oom_ref16.ini"), _L("c:\\initest\\oom16.ini")));
302 CleanupStack::PopAndDestroy(iniTest);
303 __UHEAP_SETFAIL(RHeap::ENone, 0);
307 test(result == aShouldBeSame);
310 CleanupStack::PopAndDestroy(iniTest);
311 //check we haven't leaked any heap memory
313 CheckResources(TheRFs, startThreadHandleCount);
315 if (err != KErrNoMemory)
317 test(err == KErrNone);
318 break; // we reach here if we are unable to create the OOM condition.
321 __UHEAP_SETFAIL(RHeap::ENone, 0);
324 CleanupStack::PopAndDestroy(referenceDoc);
326 test.Printf(_L("Completed consistency check."));
329 void CIniParser16Test::CreateDeleteTest1L()
333 CIniDocument16* ini=NULL;
334 //note only support 16 bit Little Endian ini file
335 ini=CIniDocument16::NewL(TheRFs,KIniFile16);
342 void CIniParser16Test::CreateDeleteOOMTest2L()
350 // find out the number of open handles
351 TInt startProcessHandleCount;
352 TInt startThreadHandleCount;
353 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
355 __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
357 CIniFile16* ini=NULL;
358 TRAP(err,ini=CIniFile16::NewL(TheRFs,KIniFile16));
362 __UHEAP_SETFAIL(RHeap::ENone, 0);
364 // check that no handles have leaked
365 TInt endProcessHandleCount;
366 TInt endThreadHandleCount;
367 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
368 test(startProcessHandleCount == endProcessHandleCount);
369 test(startThreadHandleCount == endThreadHandleCount);
372 } while(err == KErrNoMemory);
375 test.Printf(_L("- succeeded at heap failure rate of %i\n"), tryCount);
379 void CIniParser16Test::CreateDeleteTest2L()
383 CIniFile16* ini=NULL;
384 //note only support 16 bit Little Endian ini file
385 ini=CIniFile16::NewL(TheRFs,KIniFile16);
393 void CIniParser16Test::DoTest1L()
395 //Testing GetSectionList API
396 RArray<TPtrC16> sectionNames;
397 User::LeaveIfError(iIniDocument->GetSectionList(sectionNames));
398 test(sectionNames.Count()==8);
400 //Testing the sectionNames in name order
401 test(sectionNames[0].Compare(_L("1"))==0);
402 test(sectionNames[1].Compare(_L("MAPPINGS"))==0);
403 test(sectionNames[2].Compare(_L("MEDIA"))==0);
404 test(sectionNames[3].Compare(_L("OUTPUT_CHANNELS"))==0);
405 test(sectionNames[4].Compare(_L("SERVERS"))==0);
406 test(sectionNames[5].Compare(_L("SWTRACER"))==0);
407 test(sectionNames[6].Compare(_L("test_section"))==0);
408 test(sectionNames[7].Compare(_L("test_twosection"))==0);
409 sectionNames.Reset();
412 void CIniParser16Test::DoTest2L()
414 //Test GetKeyValue API
416 User::LeaveIfError(iIniDocument->GetKeyValue(_L("MEDIA"),_L("RDebug"),value));
417 test(value.Compare(_L("SwtRDebugPlugin.dll"))==0);
418 User::LeaveIfError(iIniDocument->GetKeyValue(_L("OUTPUT_CHANNELS"),_L("1"),value));
419 test(value.Compare(_L("RDebug"))==0);
420 User::LeaveIfError(iIniDocument->GetKeyValue(_L("1"),_L("new_setting"),value));
421 test(value.Compare(_L("value \\n value1\\t value2"))==0);
425 ret=iIniDocument->GetKeyValue(_L("mySection"),_L("mykey"),value);
426 LeaveIfNoMemory(ret);
427 test(ret==KErrNotFound);
429 ret=iIniDocument->GetKeyValue(_L("MEDIA"),_L("mykey"),value);
430 LeaveIfNoMemory(ret);
431 test(ret==KErrNotFound);
433 ret=iIniDocument->GetKeyValue(_L("SERVERS"),_L("SWTRACER"),value);
434 LeaveIfNoMemory(ret);
435 test(value.Length()==0);
438 void CIniParser16Test::DoTest3L()
440 //Test AddSection API
441 RArray<TPtrC16> sectionNames;
442 CleanupClosePushL(sectionNames);
443 User::LeaveIfError(iIniDocument->AddSection(_L("NEW-SECTION")));
444 User::LeaveIfError(iIniDocument->GetSectionList(sectionNames));
445 test(sectionNames.Count()==9);
448 User::LeaveIfError(iIniDocument->AddSection(_L("NeW-SECTION")));
449 User::LeaveIfError(iIniDocument->GetSectionList(sectionNames));
450 test(sectionNames.Count()==10);
451 //adding existing section, no duplicate allowed
452 TInt ret=iIniDocument->AddSection(_L("NEW-SECTION"));
453 LeaveIfNoMemory(ret);
454 test(ret==KErrAlreadyExists);
455 CleanupStack::PopAndDestroy();
458 void CIniParser16Test::DoTest4L()
460 //Test RemoveSection API
461 RArray<TPtrC16> sectionNames;
462 CleanupClosePushL(sectionNames);
465 User::LeaveIfError(iIniDocument->RemoveSection(_L("SERVERS")));
466 User::LeaveIfError(iIniDocument->GetSectionList(sectionNames));
467 test(sectionNames.Count()==7);
469 //check key inside section is also deleted
471 TInt ret=iIniDocument->GetKeyValue(_L("SERVERS"),_L("SWTRACER"),value);
472 LeaveIfNoMemory(ret);
473 test(ret==KErrNotFound);
476 ret=iIniDocument->RemoveSection(_L("AnySection"));
477 LeaveIfNoMemory(ret);
478 test(ret==KErrNotFound);
480 CleanupStack::PopAndDestroy();
483 void CIniParser16Test::DoTest5L()
487 //Modifying existing value
488 User::LeaveIfError(iIniDocument->SetKey(_L("MEDIA"),_L("RDebug"),_L("NewPlugin.dll")));
489 User::LeaveIfError(iIniDocument->GetKeyValue(_L("MEDIA"),_L("RDebug"),value));
490 test(value.Compare(_L("NewPlugin.dll"))==0);
492 //nonexist key should be created
493 User::LeaveIfError(iIniDocument->SetKey(_L("MEDIA"),_L("newplug"),_L("")));
494 User::LeaveIfError(iIniDocument->GetKeyValue(_L("MEDIA"),_L("newplug"),value));
495 test(value.Compare(_L(""))==0);
497 //nonexist section should be created
498 User::LeaveIfError(iIniDocument->SetKey(_L("unknown_section"),_L("unknown_key"),_L("unknown_value")));
499 User::LeaveIfError(iIniDocument->GetKeyValue(_L("unknown_section"),_L("unknown_key"),value));
500 test(value.Compare(_L("unknown_value"))==0);
502 //Testing Externalise to a New file
503 User::LeaveIfError(iIniDocument->Externalise(_L("c:\\initest\\output16_1.ini")));
505 //Try opening the written ini file now to ensure no corruption in writing
506 CIniDocument16* iniReRead=CIniDocument16::NewL(TheRFs,_L("c:\\initest\\output16_1.ini"));
507 CleanupStack::PushL(iniReRead);
508 User::LeaveIfError(iniReRead->GetKeyValue(_L("unknown_section"),_L("unknown_key"),value));
509 test(value.Compare(_L("unknown_value"))==0);
510 User::LeaveIfError(iniReRead->GetKeyValue(_L("MEDIA"),_L("newplug"),value));
511 test(value.Compare(_L(""))==0);
513 CleanupStack::PopAndDestroy(iniReRead);
516 void CIniParser16Test::DoTest6L()
518 //Testing RemoveKey API
520 //remove existing key
521 User::LeaveIfError(iIniDocument->RemoveKey(_L("OUTPUT_CHANNELS"),_L("1")));
522 TInt ret=iIniDocument->GetKeyValue(_L("OUTPUT_CHANNELS"),_L("1"),value);
523 LeaveIfNoMemory(ret);
524 test(ret==KErrNotFound);
526 //remove non-exist key
527 ret=iIniDocument->RemoveKey(_L("OUTPUT_CHANNELS"),_L("1"));
528 LeaveIfNoMemory(ret);
529 test(ret==KErrNotFound);
531 //remove non-exist section
532 ret=iIniDocument->RemoveKey(_L("Non-existSection"),_L("1"));
533 LeaveIfNoMemory(ret);
534 test(ret==KErrNotFound);
537 void CIniParser16Test::DoTest7L()
539 //Testing iterator class
540 CIniSecIter16* iIniSecIter=NULL;
544 TRAP(ret,iIniSecIter=CIniSecIter16::NewL(_L("Unknown"),iIniDocument));
545 LeaveIfNoMemory(ret);
546 test(ret==KErrNotFound);
549 TRAP(ret,iIniSecIter=CIniSecIter16::NewL(_L("Unknown"),NULL));
550 LeaveIfNoMemory(ret);
551 test(ret==KErrArgument);
554 iIniSecIter=CIniSecIter16::NewL(_L("test_section"),iIniDocument);
557 //test Next() and End();
558 test(!iIniSecIter->End());
559 test(iIniSecIter->Next(key,value));
560 test(key.Compare(_L("key1"))==0);
561 test(value.Compare(_L("value1"))==0);
562 test(!iIniSecIter->End());
563 test(iIniSecIter->Next(key,value));
564 test(key.Compare(_L("key2"))==0);
565 test(value.Compare(_L("value2"))==0);
566 test(!iIniSecIter->End());
567 test(iIniSecIter->Next(key,value));
568 test(key.Compare(_L("key3"))==0);
569 test(value.Compare(_L("value3"))==0);
570 test(!iIniSecIter->End());
571 test(iIniSecIter->Next(key,value));
572 test(key.Compare(_L("key4"))==0);
573 test(value.Compare(_L("value4"))==0);
574 test(!iIniSecIter->End());
575 test(iIniSecIter->Next(key,value));
576 test(key.Compare(_L("key5"))==0);
577 test(value.Compare(_L("value value value"))==0);
578 test(iIniSecIter->End());
579 test(iIniSecIter->Next(key,value)==EFalse);
582 iIniSecIter->Reset();
583 test(!iIniSecIter->End());
584 test(iIniSecIter->Next(key,value));
585 test(key.Compare(_L("key1"))==0);
586 test(value.Compare(_L("value1"))==0);
592 void CIniParser16Test::DoTest8L()
594 //Testing Externalise to ROM drive
595 TInt ret=iIniDocument->Externalise(_L("z:\\output16.ini"));
596 LeaveIfNoMemory(ret);
597 test(ret==KErrAccessDenied);
599 //Testing Externalise to a New file
600 User::LeaveIfError(iIniDocument->Externalise(_L("c:\\initest\\output16.ini")));
602 //Try opening the written ini file now to ensure no corruption in writing
603 CIniDocument16* output=CIniDocument16::NewL(TheRFs,_L("c:\\initest\\output16.ini"));
604 CleanupStack::PushL(output);
605 User::LeaveIfError(output->SetKey(_L("Test"),_L("Test"),_L("Test")));
607 //Testing Externaliseing to the already exist file
608 User::LeaveIfError(output->Externalise(_L("c:\\initest\\output16_1.ini")));
609 CleanupStack::PopAndDestroy();
611 //Opening an empty file and Externaliseing an empty file
612 output=CIniDocument16::NewL(TheRFs,_L("c:\\initest\\unknown16.ini"));
613 CleanupStack::PushL(output);
614 User::LeaveIfError(output->Externalise(_L("c:\\initest\\unknown16_1.ini")));
615 CleanupStack::PopAndDestroy();
617 // Read it back in and find the additions put in above.
618 CIniDocument16* iniReRead=NULL;
619 iniReRead=CIniDocument16::NewL(TheRFs,_L("c:\\initest\\output16_1.ini"));
620 CleanupStack::PushL(iniReRead);
623 User::LeaveIfError(iniReRead->GetKeyValue(_L("Test"),_L("Test"),value));
624 test(value.Compare(_L("Test"))==0);
626 CleanupStack::PopAndDestroy(iniReRead);
629 void CIniParser16Test::DoTest9L()
631 //Test for no leakage when handling corrupt file
632 CIniDocument16* ini=NULL;
633 TRAPD(err,ini=CIniDocument16::NewL(TheRFs,_L("z:\\resource\\corruptconfig16.ini")));
634 LeaveIfNoMemory(err);
635 test(err==KErrCorrupt);
639 void CIniParser16Test::DoTest10L()
642 //open existing ini file
643 CIniFile16* ini=CIniFile16::NewL(TheRFs, _L16("z:\\resource\\testconfig16.ini"));
644 CleanupStack::PushL(ini);
647 User::LeaveIfError(ini->FindVar(_L16("test_section"),_L16("key1"),value));
648 test(value.Compare(_L16("value1"))==0);
649 User::LeaveIfError(ini->FindVar(_L16("test_section"),_L16("key2"),value));
650 test(value.Compare(_L16("value2"))==0);
651 User::LeaveIfError(ini->FindVar(_L16("test_section"),_L16("key3"),value));
652 test(value.Compare(_L16("value3"))==0);
653 User::LeaveIfError(ini->FindVar(_L16("test_section"),_L16("key4"),value));
654 test(value.Compare(_L16("value4"))==0);
655 User::LeaveIfError(ini->FindVar(_L16("test_section"),_L16("key5"),value));
656 test(value.Compare(_L16("value value value"))==0);
659 User::LeaveIfError(ini->FindVar(_L16("SERVERS"),_L16("SWTRACER"),value));
660 test(value.Compare(_L16(""))==0);
663 User::LeaveIfError(ini->FindVar(_L16("1"),_L16("timestamps"),value));
664 test(value.Compare(_L16("0"))==0);
665 User::LeaveIfError(ini->FindVar(_L16("1"),_L16("setting"),value));
666 test(value.Compare(_L16("value"))==0);
668 CleanupStack::PopAndDestroy();
670 //open a non existing file
672 TRAP(ret,ini=CIniFile16::NewL(TheRFs,_L16("z:\\resource\\nonexist.ini")));
673 LeaveIfNoMemory(ret);
674 test(ret==KErrNotFound);
676 //open an empty ini file
677 ini=CIniFile16::NewL(TheRFs,_L16("z:\\resource\\empty16.ini"));
678 CleanupStack::PushL(ini);
680 ret=ini->FindVar(_L16("empty"),_L16("empty"),value);
681 LeaveIfNoMemory(ret);
682 test(ret==KErrNotFound);
684 CleanupStack::PopAndDestroy();
687 void CIniParser16Test::DoTest11L()
690 //open existing 8 bit ini file with 16 bit reader
693 TRAP(err,ini=CIniFile16::NewL(TheRFs,_L16("z:\\resource\\testconfig8.ini")));
694 test(err==KErrCorrupt || err==KErrNoMemory);
696 //open existing 8 bit ini file, but allow conversion to 16 bits
697 ini=CIniFile16::NewL(TheRFs,_L16("z:\\resource\\testconfig8.ini"),ETrue);
698 CleanupStack::PushL(ini);
701 User::LeaveIfError(ini->FindVar(_L16("test_section"),_L16("key1"),value));
702 test(value.Compare(_L16("value1"))==0);
703 User::LeaveIfError(ini->FindVar(_L16("test_section"),_L16("key2"),value));
704 test(value.Compare(_L16("value2"))==0);
705 User::LeaveIfError(ini->FindVar(_L16("test_section"),_L16("key3"),value));
706 test(value.Compare(_L16("value3"))==0);
707 User::LeaveIfError(ini->FindVar(_L16("test_section"),_L16("key4"),value));
708 test(value.Compare(_L16("value4"))==0);
709 User::LeaveIfError(ini->FindVar(_L16("test_section"),_L16("key5"),value));
710 test(value.Compare(_L16("value value value"))==0);
713 User::LeaveIfError(ini->FindVar(_L16("SERVERS"),_L16("SWTRACER"),value));
714 test(value.Compare(_L16(""))==0);
717 User::LeaveIfError(ini->FindVar(_L16("1"),_L16("timestamps"),value));
718 test(value.Compare(_L16("0"))==0);
719 User::LeaveIfError(ini->FindVar(_L16("1"),_L16("setting"),value));
720 test(value.Compare(_L16("value"))==0);
722 CleanupStack::PopAndDestroy();
725 void CIniParser16Test::DoTest12L()
728 // We are trying to invoke an OOM condition for a single operation to test that the operation is atomic.
729 // Under that condition the object should be rolled back to the original state. The resulting document should be the same
730 // as before the condition was invoked. If the test succeeded, a new section should be created at end
731 // (which is nice but not the real focus of the test).
732 User::LeaveIfError(iIniDocument->SetKey(_L16("unknown_section3"),_L16("unknown_key3"),_L16("unknown_value3")));
735 static void DeleteFilesL()
737 CFileMan* fileman=CFileMan::NewL(TheRFs);
739 fileman->Delete(_L("c:\\initest\\*"));
745 @SYMTestCaseID SYSLIB-BAFL-CT-1559
746 @SYMTestCaseDesc Test CIniParser16Test
747 @SYMTestPriority High
748 @SYMTestActions Perform component tests on CIniParser16Test (includes OOM)
749 Testing all the exported apis.
750 @SYMTestExpectedResults The test must not fail.
753 static void DoTestL()
755 TTime startTime(0), stopTime(0);
756 TTimeIntervalMicroSeconds timeTaken;
758 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1559 "));
761 //16 bit basic testing
762 CIniParser16Test::CreateDeleteTest1L();
763 CIniParser16Test::DoBasicTestL(&CIniParser16Test::DoTest1L,_L("GetSectionList16"));
764 CIniParser16Test::DoBasicTestL(&CIniParser16Test::DoTest2L,_L("GetKeyValue16"));
765 CIniParser16Test::DoBasicTestL(&CIniParser16Test::DoTest3L,_L("AddSection16"));
766 CIniParser16Test::DoBasicTestL(&CIniParser16Test::DoTest4L,_L("RemoveSection16"));
767 CIniParser16Test::DoBasicTestL(&CIniParser16Test::DoTest5L,_L("SetKeyValue16"));
768 CIniParser16Test::DoBasicTestL(&CIniParser16Test::DoTest6L,_L("RemoveKey16"));
769 CIniParser16Test::DoBasicTestL(&CIniParser16Test::DoTest7L,_L("IniSecIter16"));
770 CIniParser16Test::DoBasicTestL(&CIniParser16Test::DoTest8L,_L("Externalise16"));
771 CIniParser16Test::DoBasicTestL(&CIniParser16Test::DoTest9L,_L("Corrupt file16"));
773 CIniParser16Test::CreateDeleteOOMTestL();
774 CIniParser16Test::DoOOMTestL(&CIniParser16Test::DoTest1L,_L("GetSectionList16-OOM"));
775 CIniParser16Test::DoOOMTestL(&CIniParser16Test::DoTest2L,_L("GetKeyValue16-OOM"));
776 CIniParser16Test::DoOOMTestL(&CIniParser16Test::DoTest3L,_L("AddSection16-OOM"));
777 CIniParser16Test::DoOOMTestL(&CIniParser16Test::DoTest4L,_L("RemoveSection16-OOM"));
778 CIniParser16Test::DoOOMTestL(&CIniParser16Test::DoTest5L,_L("SetKeyValue16-OOM"));
779 CIniParser16Test::DoOOMTestL(&CIniParser16Test::DoTest6L,_L("RemoveKey16-OOM"));
780 CIniParser16Test::DoOOMTestL(&CIniParser16Test::DoTest7L,_L("IniSecIter16-OOM"));
781 CIniParser16Test::DoOOMTestL(&CIniParser16Test::DoTest8L,_L("Externalise16-OOM"));
782 CIniParser16Test::DoOOMTestL(&CIniParser16Test::DoTest9L,_L("Corrupt file16-OOM"));
784 //16 bit light basic testing
785 CIniParser16Test::CreateDeleteTest2L();
786 CIniParser16Test::DoBasicTestL(&CIniParser16Test::DoTest10L,_L("Light FindVar16"));
787 CIniParser16Test::DoBasicTestL(&CIniParser16Test::DoTest11L,_L("Load 16"));
788 //16 bit light OOM testing
789 CIniParser16Test::CreateDeleteOOMTest2L();
790 CIniParser16Test::DoOOMTestL(&CIniParser16Test::DoTest10L,_L("Light FindVar-OOM16"));
791 CIniParser16Test::DoOOMTestL(&CIniParser16Test::DoTest11L,_L("Load 16-OOM"));
792 stopTime.UniversalTime();
793 timeTaken = stopTime.MicroSecondsFrom(startTime);
794 test.Printf(_L("Time taken for Heavy= %d microseconds\n"), timeTaken.Int64() );
795 startTime.UniversalTime();
796 // Consistency checks
797 CIniParser16Test::DoOOMWithConsistencyCheckTestL(&CIniParser16Test::DoTest12L,_L("Consistency16-OOMC"), FALSE);
799 stopTime.UniversalTime();
800 timeTaken = stopTime.MicroSecondsFrom(startTime);
801 test.Printf(_L("Time taken for consistency checks= %d microseconds\n"), timeTaken.Int64() );
804 GLDEF_C TInt E32Main()
807 CTrapCleanup* trapCleanup=CTrapCleanup::New();
808 test(TheRFs.Connect()==KErrNone);
809 test.Start(_L("Ini File Parser Test"));
811 TRAPD(error, DoTestL());
812 test(error == KErrNone);