sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // @internalComponent sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "IniTemplate.h" sl@0: #include "IniParserImpl.h" sl@0: sl@0: RTest test(_L("Ini Parser Unit Test")); sl@0: RFs TheRFs; sl@0: sl@0: using namespace BSUL; sl@0: sl@0: typedef void (*ClassFuncPtr8L) (void); sl@0: sl@0: //utils class for testing sl@0: static void DoBasicTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc) sl@0: { sl@0: test.Next(aTestDesc); sl@0: sl@0: __UHEAP_MARK; sl@0: // find out the number of open handles sl@0: TInt startProcessHandleCount; sl@0: TInt startThreadHandleCount; sl@0: RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); sl@0: sl@0: (testFuncL)(); sl@0: sl@0: // check that no handles have leaked sl@0: TInt endProcessHandleCount; sl@0: TInt endThreadHandleCount; sl@0: RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); sl@0: sl@0: test(startProcessHandleCount == endProcessHandleCount); sl@0: test(startThreadHandleCount == endThreadHandleCount); sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: static void DoOOMTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc) sl@0: { sl@0: test.Next(aTestDesc); sl@0: sl@0: TInt err; sl@0: TInt tryCount = 0; sl@0: do sl@0: { sl@0: __UHEAP_MARK; sl@0: // find out the number of open handles sl@0: TInt startProcessHandleCount; sl@0: TInt startThreadHandleCount; sl@0: RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); sl@0: sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); sl@0: TRAP(err, testFuncL()); sl@0: __UHEAP_SETFAIL(RHeap::ENone, 0); sl@0: sl@0: // check that no handles have leaked sl@0: TInt endProcessHandleCount; sl@0: TInt endThreadHandleCount; sl@0: RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); sl@0: sl@0: test(startProcessHandleCount == endProcessHandleCount); sl@0: test(startThreadHandleCount == endThreadHandleCount); sl@0: sl@0: __UHEAP_MARKEND; sl@0: } while(err == KErrNoMemory); sl@0: sl@0: test(err==KErrNone); sl@0: test.Printf(_L("- succeeded at heap failure rate of %i\n"), tryCount); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-1555 sl@0: @SYMTestCaseDesc Test CIniKeyX sl@0: @SYMTestPriority High sl@0: @SYMTestActions Create, compare and delete CIniKeyX. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ PREQ505 sl@0: */ sl@0: static void DoTest1L() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1555 ")); sl@0: //basic constructor sl@0: CIniKey8* key1=CIniKey8::NewL(_L8("mykey"),_L8("myvalue")); sl@0: CleanupStack::PushL(key1); sl@0: CIniKey8* key2=CIniKey8::NewL(_L8("nykey"),_L8("myvalue")); sl@0: CleanupStack::PushL(key2); sl@0: sl@0: //Compare key sl@0: test(CIniKey8::CompareKey(*key1,*key2)<0); sl@0: test(CIniKey8::CompareKey(*key2,*key1)>0); sl@0: sl@0: //test key name and value sl@0: test(key1->KeyName().Compare(_L8("mykey"))==0); sl@0: test(key1->KeyValue().Compare(_L8("myvalue"))==0); sl@0: sl@0: //SetKeyValue sl@0: key1->SetKeyValue(_L8("newvalue")); sl@0: test(key1->KeyValue().Compare(_L8("newvalue"))==0); sl@0: sl@0: CleanupStack::PopAndDestroy(2); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-1556 sl@0: @SYMTestCaseDesc Test CiniSectionX sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test CiniSectionX by using compare section, InsertKeyL etc. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ PREQ505 sl@0: */ sl@0: static void DoTest2L() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1556 ")); sl@0: //basic constructor sl@0: CIniSection16* section1=CIniSection16::NewLC(_L("abc")); sl@0: CIniSection16* section2=CIniSection16::NewLC(_L("cde")); sl@0: CIniSection16* section3=CIniSection16::NewLC(_L("ABC")); sl@0: sl@0: //compare section sl@0: test(CIniSection16::CompareSection(*section1,*section2)<0); sl@0: test(CIniSection16::CompareSection(*section2,*section1)>0); sl@0: //case sensitive sl@0: test(CIniSection16::CompareSection(*section3,*section1)<0); sl@0: sl@0: //no key yet, this will create one sl@0: section1->InsertKeyL(_L("newkey"),_L("XXXX")); sl@0: sl@0: //InsertKeyL(will leave with KErrAlreadyExists) sl@0: TRAPD(err,section1->InsertKeyL(_L("newkey"),_L("keyvalue"))); sl@0: if (err==KErrNoMemory) sl@0: User::LeaveNoMemory(); sl@0: test(err==KErrAlreadyExists); sl@0: test(section1->KeyCount()==1); sl@0: section1->InsertKeyL(_L("key2"),_L("keyval2")); sl@0: test(section1->KeyCount()==2); sl@0: sl@0: //KeyValueL sl@0: TPtrC value; sl@0: TRAP(err,value.Set(section2->KeyValueL(_L("unknownkey")))); sl@0: if (err==KErrNoMemory) sl@0: User::LeaveNoMemory(); sl@0: test(err==KErrNotFound); sl@0: value.Set(section1->KeyValueL(_L("newkey"))); sl@0: test(value.Compare(_L("XXXX"))==0); sl@0: sl@0: sl@0: //FindKeyL(ordered list) sl@0: CIniKey16* myKey=NULL; sl@0: TRAP(err, myKey=section1->FindKeyL(_L("newkey"))); sl@0: if (err==KErrNoMemory) sl@0: User::LeaveNoMemory(); sl@0: test(myKey!= NULL); sl@0: TRAP(err,section1->FindKeyL(_L("tommy"))); sl@0: if (err==KErrNoMemory) sl@0: User::LeaveNoMemory(); sl@0: test(err==KErrNotFound); sl@0: sl@0: //RemoveKeyL sl@0: TRAP(err,section1->RemoveKeyL(_L("unknownkey"))); sl@0: if (err==KErrNoMemory) sl@0: User::LeaveNoMemory(); sl@0: test(err==KErrNotFound); sl@0: section1->RemoveKeyL(_L("key2")); sl@0: test(section1->KeyCount()==1); sl@0: sl@0: CleanupStack::PopAndDestroy(3); sl@0: } sl@0: sl@0: sl@0: static void DoTestL() sl@0: { sl@0: //basic test sl@0: DoBasicTestL(&DoTest1L,_L("CIniKey basic test")); sl@0: DoBasicTestL(&DoTest2L,_L("CIniSection basic test")); sl@0: sl@0: //oom test sl@0: DoOOMTestL(&DoTest1L,_L("CIniKey OOM test")); sl@0: DoOOMTestL(&DoTest2L,_L("CIniSection OOM test")); sl@0: } sl@0: sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: CTrapCleanup* trapCleanup=CTrapCleanup::New(); sl@0: test(TheRFs.Connect()==KErrNone); sl@0: test.Start(_L("Ini Parser Unit Test")); sl@0: sl@0: TRAPD(error, DoTestL()); sl@0: test(error == KErrNone); sl@0: sl@0: sl@0: TheRFs.Close(); sl@0: test.End(); sl@0: test.Close(); sl@0: delete trapCleanup; sl@0: __UHEAP_MARKEND; sl@0: return error; sl@0: } sl@0: