|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // @internalComponent |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32base.h> |
|
20 #include <e32test.h> |
|
21 #include <f32file.h> |
|
22 #include <s32file.h> |
|
23 #include "IniTemplate.h" |
|
24 #include "IniParserImpl.h" |
|
25 |
|
26 RTest test(_L("Ini Parser Unit Test")); |
|
27 RFs TheRFs; |
|
28 |
|
29 using namespace BSUL; |
|
30 |
|
31 typedef void (*ClassFuncPtr8L) (void); |
|
32 |
|
33 //utils class for testing |
|
34 static void DoBasicTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc) |
|
35 { |
|
36 test.Next(aTestDesc); |
|
37 |
|
38 __UHEAP_MARK; |
|
39 // find out the number of open handles |
|
40 TInt startProcessHandleCount; |
|
41 TInt startThreadHandleCount; |
|
42 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
43 |
|
44 (testFuncL)(); |
|
45 |
|
46 // check that no handles have leaked |
|
47 TInt endProcessHandleCount; |
|
48 TInt endThreadHandleCount; |
|
49 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
50 |
|
51 test(startProcessHandleCount == endProcessHandleCount); |
|
52 test(startThreadHandleCount == endThreadHandleCount); |
|
53 |
|
54 __UHEAP_MARKEND; |
|
55 } |
|
56 |
|
57 static void DoOOMTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc) |
|
58 { |
|
59 test.Next(aTestDesc); |
|
60 |
|
61 TInt err; |
|
62 TInt tryCount = 0; |
|
63 do |
|
64 { |
|
65 __UHEAP_MARK; |
|
66 // find out the number of open handles |
|
67 TInt startProcessHandleCount; |
|
68 TInt startThreadHandleCount; |
|
69 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
70 |
|
71 __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); |
|
72 TRAP(err, testFuncL()); |
|
73 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
74 |
|
75 // check that no handles have leaked |
|
76 TInt endProcessHandleCount; |
|
77 TInt endThreadHandleCount; |
|
78 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
79 |
|
80 test(startProcessHandleCount == endProcessHandleCount); |
|
81 test(startThreadHandleCount == endThreadHandleCount); |
|
82 |
|
83 __UHEAP_MARKEND; |
|
84 } while(err == KErrNoMemory); |
|
85 |
|
86 test(err==KErrNone); |
|
87 test.Printf(_L("- succeeded at heap failure rate of %i\n"), tryCount); |
|
88 } |
|
89 |
|
90 /** |
|
91 @SYMTestCaseID SYSLIB-BAFL-CT-1555 |
|
92 @SYMTestCaseDesc Test CIniKeyX |
|
93 @SYMTestPriority High |
|
94 @SYMTestActions Create, compare and delete CIniKeyX. |
|
95 @SYMTestExpectedResults The test must not fail. |
|
96 @SYMREQ PREQ505 |
|
97 */ |
|
98 static void DoTest1L() |
|
99 { |
|
100 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1555 ")); |
|
101 //basic constructor |
|
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); |
|
106 |
|
107 //Compare key |
|
108 test(CIniKey8::CompareKey(*key1,*key2)<0); |
|
109 test(CIniKey8::CompareKey(*key2,*key1)>0); |
|
110 |
|
111 //test key name and value |
|
112 test(key1->KeyName().Compare(_L8("mykey"))==0); |
|
113 test(key1->KeyValue().Compare(_L8("myvalue"))==0); |
|
114 |
|
115 //SetKeyValue |
|
116 key1->SetKeyValue(_L8("newvalue")); |
|
117 test(key1->KeyValue().Compare(_L8("newvalue"))==0); |
|
118 |
|
119 CleanupStack::PopAndDestroy(2); |
|
120 } |
|
121 |
|
122 /** |
|
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. |
|
128 @SYMREQ PREQ505 |
|
129 */ |
|
130 static void DoTest2L() |
|
131 { |
|
132 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1556 ")); |
|
133 //basic constructor |
|
134 CIniSection16* section1=CIniSection16::NewLC(_L("abc")); |
|
135 CIniSection16* section2=CIniSection16::NewLC(_L("cde")); |
|
136 CIniSection16* section3=CIniSection16::NewLC(_L("ABC")); |
|
137 |
|
138 //compare section |
|
139 test(CIniSection16::CompareSection(*section1,*section2)<0); |
|
140 test(CIniSection16::CompareSection(*section2,*section1)>0); |
|
141 //case sensitive |
|
142 test(CIniSection16::CompareSection(*section3,*section1)<0); |
|
143 |
|
144 //no key yet, this will create one |
|
145 section1->InsertKeyL(_L("newkey"),_L("XXXX")); |
|
146 |
|
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); |
|
155 |
|
156 //KeyValueL |
|
157 TPtrC value; |
|
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); |
|
164 |
|
165 |
|
166 //FindKeyL(ordered list) |
|
167 CIniKey16* myKey=NULL; |
|
168 TRAP(err, myKey=section1->FindKeyL(_L("newkey"))); |
|
169 if (err==KErrNoMemory) |
|
170 User::LeaveNoMemory(); |
|
171 test(myKey!= NULL); |
|
172 TRAP(err,section1->FindKeyL(_L("tommy"))); |
|
173 if (err==KErrNoMemory) |
|
174 User::LeaveNoMemory(); |
|
175 test(err==KErrNotFound); |
|
176 |
|
177 //RemoveKeyL |
|
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); |
|
184 |
|
185 CleanupStack::PopAndDestroy(3); |
|
186 } |
|
187 |
|
188 |
|
189 static void DoTestL() |
|
190 { |
|
191 //basic test |
|
192 DoBasicTestL(&DoTest1L,_L("CIniKey basic test")); |
|
193 DoBasicTestL(&DoTest2L,_L("CIniSection basic test")); |
|
194 |
|
195 //oom test |
|
196 DoOOMTestL(&DoTest1L,_L("CIniKey OOM test")); |
|
197 DoOOMTestL(&DoTest2L,_L("CIniSection OOM test")); |
|
198 } |
|
199 |
|
200 |
|
201 GLDEF_C TInt E32Main() |
|
202 { |
|
203 __UHEAP_MARK; |
|
204 CTrapCleanup* trapCleanup=CTrapCleanup::New(); |
|
205 test(TheRFs.Connect()==KErrNone); |
|
206 test.Start(_L("Ini Parser Unit Test")); |
|
207 |
|
208 TRAPD(error, DoTestL()); |
|
209 test(error == KErrNone); |
|
210 |
|
211 |
|
212 TheRFs.Close(); |
|
213 test.End(); |
|
214 test.Close(); |
|
215 delete trapCleanup; |
|
216 __UHEAP_MARKEND; |
|
217 return error; |
|
218 } |
|
219 |