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