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.
23 #include "IniTemplate.h"
24 #include "IniParserImpl.h"
26 RTest test(_L("Ini Parser Unit Test"));
31 typedef void (*ClassFuncPtr8L) (void);
33 //utils class for testing
34 static void DoBasicTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc)
39 // find out the number of open handles
40 TInt startProcessHandleCount;
41 TInt startThreadHandleCount;
42 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
46 // check that no handles have leaked
47 TInt endProcessHandleCount;
48 TInt endThreadHandleCount;
49 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
51 test(startProcessHandleCount == endProcessHandleCount);
52 test(startThreadHandleCount == endThreadHandleCount);
57 static void DoOOMTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc)
66 // find out the number of open handles
67 TInt startProcessHandleCount;
68 TInt startThreadHandleCount;
69 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
71 __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
72 TRAP(err, testFuncL());
73 __UHEAP_SETFAIL(RHeap::ENone, 0);
75 // check that no handles have leaked
76 TInt endProcessHandleCount;
77 TInt endThreadHandleCount;
78 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
80 test(startProcessHandleCount == endProcessHandleCount);
81 test(startThreadHandleCount == endThreadHandleCount);
84 } while(err == KErrNoMemory);
87 test.Printf(_L("- succeeded at heap failure rate of %i\n"), tryCount);
91 @SYMTestCaseID SYSLIB-BAFL-CT-1555
92 @SYMTestCaseDesc Test CIniKeyX
94 @SYMTestActions Create, compare and delete CIniKeyX.
95 @SYMTestExpectedResults The test must not fail.
98 static void DoTest1L()
100 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1555 "));
102 CIniKey8* key1=CIniKey8::NewL(_L8("mykey"),_L8("myvalue"));
103 CleanupStack::PushL(key1);
104 CIniKey8* key2=CIniKey8::NewL(_L8("nykey"),_L8("myvalue"));
105 CleanupStack::PushL(key2);
108 test(CIniKey8::CompareKey(*key1,*key2)<0);
109 test(CIniKey8::CompareKey(*key2,*key1)>0);
111 //test key name and value
112 test(key1->KeyName().Compare(_L8("mykey"))==0);
113 test(key1->KeyValue().Compare(_L8("myvalue"))==0);
116 key1->SetKeyValue(_L8("newvalue"));
117 test(key1->KeyValue().Compare(_L8("newvalue"))==0);
119 CleanupStack::PopAndDestroy(2);
123 @SYMTestCaseID SYSLIB-BAFL-CT-1556
124 @SYMTestCaseDesc Test CiniSectionX
125 @SYMTestPriority High
126 @SYMTestActions Test CiniSectionX by using compare section, InsertKeyL etc.
127 @SYMTestExpectedResults The test must not fail.
130 static void DoTest2L()
132 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1556 "));
134 CIniSection16* section1=CIniSection16::NewLC(_L("abc"));
135 CIniSection16* section2=CIniSection16::NewLC(_L("cde"));
136 CIniSection16* section3=CIniSection16::NewLC(_L("ABC"));
139 test(CIniSection16::CompareSection(*section1,*section2)<0);
140 test(CIniSection16::CompareSection(*section2,*section1)>0);
142 test(CIniSection16::CompareSection(*section3,*section1)<0);
144 //no key yet, this will create one
145 section1->InsertKeyL(_L("newkey"),_L("XXXX"));
147 //InsertKeyL(will leave with KErrAlreadyExists)
148 TRAPD(err,section1->InsertKeyL(_L("newkey"),_L("keyvalue")));
149 if (err==KErrNoMemory)
150 User::LeaveNoMemory();
151 test(err==KErrAlreadyExists);
152 test(section1->KeyCount()==1);
153 section1->InsertKeyL(_L("key2"),_L("keyval2"));
154 test(section1->KeyCount()==2);
158 TRAP(err,value.Set(section2->KeyValueL(_L("unknownkey"))));
159 if (err==KErrNoMemory)
160 User::LeaveNoMemory();
161 test(err==KErrNotFound);
162 value.Set(section1->KeyValueL(_L("newkey")));
163 test(value.Compare(_L("XXXX"))==0);
166 //FindKeyL(ordered list)
167 CIniKey16* myKey=NULL;
168 TRAP(err, myKey=section1->FindKeyL(_L("newkey")));
169 if (err==KErrNoMemory)
170 User::LeaveNoMemory();
172 TRAP(err,section1->FindKeyL(_L("tommy")));
173 if (err==KErrNoMemory)
174 User::LeaveNoMemory();
175 test(err==KErrNotFound);
178 TRAP(err,section1->RemoveKeyL(_L("unknownkey")));
179 if (err==KErrNoMemory)
180 User::LeaveNoMemory();
181 test(err==KErrNotFound);
182 section1->RemoveKeyL(_L("key2"));
183 test(section1->KeyCount()==1);
185 CleanupStack::PopAndDestroy(3);
189 static void DoTestL()
192 DoBasicTestL(&DoTest1L,_L("CIniKey basic test"));
193 DoBasicTestL(&DoTest2L,_L("CIniSection basic test"));
196 DoOOMTestL(&DoTest1L,_L("CIniKey OOM test"));
197 DoOOMTestL(&DoTest2L,_L("CIniSection OOM test"));
201 GLDEF_C TInt E32Main()
204 CTrapCleanup* trapCleanup=CTrapCleanup::New();
205 test(TheRFs.Connect()==KErrNone);
206 test.Start(_L("Ini Parser Unit Test"));
208 TRAPD(error, DoTestL());
209 test(error == KErrNone);