sl@0
|
1 |
// Copyright (c) 1997-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 the License "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 |
// e32test\system\t_regram.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32test.h>
|
sl@0
|
19 |
#include <e32svr.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
//
|
sl@0
|
22 |
// This test takes forever to run and destroys the internal Ram drive.
|
sl@0
|
23 |
//
|
sl@0
|
24 |
|
sl@0
|
25 |
LOCAL_D RTest test(_L("T_REGRAM"));
|
sl@0
|
26 |
|
sl@0
|
27 |
void deleteReg()
|
sl@0
|
28 |
//
|
sl@0
|
29 |
// Delete everything from the registry
|
sl@0
|
30 |
//
|
sl@0
|
31 |
{
|
sl@0
|
32 |
TUid uid;
|
sl@0
|
33 |
TRegistryIter riter;
|
sl@0
|
34 |
riter.Reset();
|
sl@0
|
35 |
while (riter.Next(uid)==KErrNone)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
TRegistryCategory cat(uid);
|
sl@0
|
38 |
cat.DeleteAllItems();
|
sl@0
|
39 |
}
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
TInt fillReg(const TDesC8 &aDes, TInt aEntries)
|
sl@0
|
43 |
//
|
sl@0
|
44 |
// Fill the registry with big nasty monsters
|
sl@0
|
45 |
// returns the number of entries made.
|
sl@0
|
46 |
//
|
sl@0
|
47 |
{
|
sl@0
|
48 |
TBuf8<0x100> buf=_L8("");
|
sl@0
|
49 |
TInt i;
|
sl@0
|
50 |
for (i=0; i<8; i++)
|
sl@0
|
51 |
buf.Append(_L8("Big_ nasty_ monster_ chasing_ me"));
|
sl@0
|
52 |
|
sl@0
|
53 |
TUid uid;
|
sl@0
|
54 |
uid=TUid::Uid(0x12345678);
|
sl@0
|
55 |
TRegistryCategory cat(uid);
|
sl@0
|
56 |
i=0;
|
sl@0
|
57 |
TBuf8<0x20> item;
|
sl@0
|
58 |
while (i<aEntries)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
item.Format(_L8("%S %08x"),&aDes,i);
|
sl@0
|
61 |
TInt r=cat.SetItem(item, buf);
|
sl@0
|
62 |
if (r!=KErrNone)
|
sl@0
|
63 |
break;
|
sl@0
|
64 |
i++;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
return i;
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
TInt shrinkReg(const TDesC8 &aDes, TInt aEntries)
|
sl@0
|
70 |
//
|
sl@0
|
71 |
// Delete aEntries entries from the registry
|
sl@0
|
72 |
// returns number of entries deleted.
|
sl@0
|
73 |
//
|
sl@0
|
74 |
{
|
sl@0
|
75 |
|
sl@0
|
76 |
|
sl@0
|
77 |
TUid uid;
|
sl@0
|
78 |
uid=TUid::Uid(0x12345678);
|
sl@0
|
79 |
TRegistryCategory cat(uid);
|
sl@0
|
80 |
TBuf8<0x20> item;
|
sl@0
|
81 |
TInt i=aEntries-1;
|
sl@0
|
82 |
while (i>=0)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
item.Format(_L8("%S %08x"),&aDes,i);
|
sl@0
|
85 |
TInt r=cat.DeleteItem(item);
|
sl@0
|
86 |
if (r!=KErrNone)
|
sl@0
|
87 |
break;
|
sl@0
|
88 |
i--;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
return aEntries-i-1;
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
TInt testReg(const TDesC8 &aDes, TInt aEntries)
|
sl@0
|
94 |
//
|
sl@0
|
95 |
// Test the first aEntries entries are set correctly
|
sl@0
|
96 |
//
|
sl@0
|
97 |
{
|
sl@0
|
98 |
TBuf8<0x100> buf=_L8("");
|
sl@0
|
99 |
TInt i;
|
sl@0
|
100 |
for (i=0; i<8; i++)
|
sl@0
|
101 |
buf.Append(_L8("Big_ nasty_ monster_ chasing_ me"));
|
sl@0
|
102 |
|
sl@0
|
103 |
TUid uid;
|
sl@0
|
104 |
uid=TUid::Uid(0x12345678);
|
sl@0
|
105 |
TRegistryCategory cat(uid);
|
sl@0
|
106 |
|
sl@0
|
107 |
TBuf8<0x20> item;
|
sl@0
|
108 |
TBuf8<0x100> res;
|
sl@0
|
109 |
i=0;
|
sl@0
|
110 |
while (i<aEntries)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
item.Format(_L8("%S %08x"),&aDes,i);
|
sl@0
|
113 |
if ((i&0x1f)==0)
|
sl@0
|
114 |
test.Printf(_L("."));
|
sl@0
|
115 |
res=cat.Item(item, _L8("Gone gone gone"));
|
sl@0
|
116 |
test(buf==res);
|
sl@0
|
117 |
i++;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
test.Printf(_L("\n"));
|
sl@0
|
120 |
return i;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
void test1()
|
sl@0
|
124 |
//
|
sl@0
|
125 |
// Test growing and shrinking the registry
|
sl@0
|
126 |
//
|
sl@0
|
127 |
{
|
sl@0
|
128 |
|
sl@0
|
129 |
test.Start(_L("Cleanout the registry"));
|
sl@0
|
130 |
deleteReg();
|
sl@0
|
131 |
|
sl@0
|
132 |
test.Next(_L("Grow the registry a bit"));
|
sl@0
|
133 |
TInt n=fillReg(_L8("Run Away"),40);
|
sl@0
|
134 |
test.Printf(_L("Made %d entries\n"), n);
|
sl@0
|
135 |
test.Next(_L("Test the content of the registry"));
|
sl@0
|
136 |
TInt m=testReg(_L8("Run Away"),n);
|
sl@0
|
137 |
test(n==m);
|
sl@0
|
138 |
test.Next(_L("Shrink it a bit"));
|
sl@0
|
139 |
m=shrinkReg(_L8("Run Away"),n);
|
sl@0
|
140 |
test.Printf(_L("Deleted %d entries\n"), m);
|
sl@0
|
141 |
test(n==m);
|
sl@0
|
142 |
|
sl@0
|
143 |
test.Next(_L("Fill the registry with guff"));
|
sl@0
|
144 |
test.Printf(_L("\tTHIS TEST TAKES AGES\n"));
|
sl@0
|
145 |
n=fillReg(_L8("Run Away"),0x7fffffff);
|
sl@0
|
146 |
test.Printf(_L("Made %d entries\n"), n);
|
sl@0
|
147 |
test.Next(_L("Test the content of the registry"));
|
sl@0
|
148 |
m=testReg(_L8("Run Away"),n);
|
sl@0
|
149 |
test.Next(_L("Shrink the registry"));
|
sl@0
|
150 |
m=shrinkReg(_L8("Run Away"),n);
|
sl@0
|
151 |
test.Printf(_L("Deleted %d entries\n"), m);
|
sl@0
|
152 |
test(n==m);
|
sl@0
|
153 |
|
sl@0
|
154 |
test.Next(_L("Grow a bigish registry"));
|
sl@0
|
155 |
n=fillReg(_L8("Lunge"),40);
|
sl@0
|
156 |
test.Next(_L("Save the registry"));
|
sl@0
|
157 |
TUint8* bigPtr=new TUint8[0x8000];
|
sl@0
|
158 |
TPtr8 big(bigPtr, 0x8000);
|
sl@0
|
159 |
TInt bigsize;
|
sl@0
|
160 |
TInt r=User::MachineConfiguration(big,bigsize);
|
sl@0
|
161 |
test(r==KErrNone);
|
sl@0
|
162 |
|
sl@0
|
163 |
test.Next(_L("Clear it"));
|
sl@0
|
164 |
deleteReg();
|
sl@0
|
165 |
|
sl@0
|
166 |
test.Next(_L("Grow a little registry"));
|
sl@0
|
167 |
m=fillReg(_L8("Groat"), 10);
|
sl@0
|
168 |
test.Next(_L("Save it"));
|
sl@0
|
169 |
TUint8* littlePtr=new TUint8[0x8000];
|
sl@0
|
170 |
TPtr8 little(littlePtr, 0x8000);
|
sl@0
|
171 |
TInt littlesize;
|
sl@0
|
172 |
r=User::MachineConfiguration(little,littlesize);
|
sl@0
|
173 |
test(r==KErrNone);
|
sl@0
|
174 |
|
sl@0
|
175 |
test.Next(_L("Set to big registry"));
|
sl@0
|
176 |
r=User::SetMachineConfiguration(big);
|
sl@0
|
177 |
test(r==KErrNone);
|
sl@0
|
178 |
test.Next(_L("Test it"));
|
sl@0
|
179 |
TInt i=testReg(_L8("Lunge"), n);
|
sl@0
|
180 |
test(n==i);
|
sl@0
|
181 |
|
sl@0
|
182 |
test.Next(_L("Set to little registry"));
|
sl@0
|
183 |
r=User::SetMachineConfiguration(little);
|
sl@0
|
184 |
test(r==KErrNone);
|
sl@0
|
185 |
test.Next(_L("Test it"));
|
sl@0
|
186 |
i=testReg(_L8("Groat"), m);
|
sl@0
|
187 |
test(i==m);
|
sl@0
|
188 |
|
sl@0
|
189 |
test.Next(_L("Set to big registry again"));
|
sl@0
|
190 |
deleteReg();
|
sl@0
|
191 |
r=User::SetMachineConfiguration(big);
|
sl@0
|
192 |
test(r==KErrNone);
|
sl@0
|
193 |
test.Next(_L("Test it"));
|
sl@0
|
194 |
i=testReg(_L8("Lunge"), n);
|
sl@0
|
195 |
test(n==i);
|
sl@0
|
196 |
|
sl@0
|
197 |
delete bigPtr;
|
sl@0
|
198 |
delete littlePtr;
|
sl@0
|
199 |
test.End();
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
void fillRamDrive(TBusLocalDrive &aRamDrive)
|
sl@0
|
203 |
//
|
sl@0
|
204 |
// Fill the ram drive with data
|
sl@0
|
205 |
//
|
sl@0
|
206 |
{
|
sl@0
|
207 |
|
sl@0
|
208 |
TLocalDriveCapsV2 info;
|
sl@0
|
209 |
TPckg<TLocalDriveCapsV2> infoPckg(info);
|
sl@0
|
210 |
test(aRamDrive.Caps(infoPckg)==KErrNone);
|
sl@0
|
211 |
TInt size=info.iSize.Low();
|
sl@0
|
212 |
TInt i;
|
sl@0
|
213 |
TPckgBuf<TInt> dataBuf;
|
sl@0
|
214 |
TInt &data=dataBuf();
|
sl@0
|
215 |
for (i=0; i<size; i+=4)
|
sl@0
|
216 |
{
|
sl@0
|
217 |
data=i;
|
sl@0
|
218 |
aRamDrive.Write(i, dataBuf);
|
sl@0
|
219 |
}
|
sl@0
|
220 |
}
|
sl@0
|
221 |
|
sl@0
|
222 |
void testRamDrive(TBusLocalDrive &aRamDrive)
|
sl@0
|
223 |
//
|
sl@0
|
224 |
// Test the data is still OK
|
sl@0
|
225 |
//
|
sl@0
|
226 |
{
|
sl@0
|
227 |
|
sl@0
|
228 |
TLocalDriveCapsV2 info;
|
sl@0
|
229 |
TPckg<TLocalDriveCapsV2> infoPckg(info);
|
sl@0
|
230 |
test(aRamDrive.Caps(infoPckg)==KErrNone);
|
sl@0
|
231 |
TInt size=info.iSize.Low();
|
sl@0
|
232 |
TInt i;
|
sl@0
|
233 |
TPckgBuf<TInt> dataBuf;
|
sl@0
|
234 |
TInt &data=dataBuf();
|
sl@0
|
235 |
for (i=0; i<size; i+=4)
|
sl@0
|
236 |
{
|
sl@0
|
237 |
aRamDrive.Read(i, sizeof(TInt), dataBuf);
|
sl@0
|
238 |
if (i&0x3ff==0)
|
sl@0
|
239 |
test.Printf(_L("."));
|
sl@0
|
240 |
// test.Printf(_L("%08x "), data);
|
sl@0
|
241 |
test(data==i);
|
sl@0
|
242 |
}
|
sl@0
|
243 |
test.Printf(_L("\n"));
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
void testGrow()
|
sl@0
|
247 |
{
|
sl@0
|
248 |
|
sl@0
|
249 |
test.Start(_L("Grow the registry a bit"));
|
sl@0
|
250 |
TInt n=fillReg(_L8("Run Away"),20);
|
sl@0
|
251 |
test(n==20);
|
sl@0
|
252 |
test.Next(_L("Test the content of the registry"));
|
sl@0
|
253 |
testReg(_L8("Run Away"),n);
|
sl@0
|
254 |
test(n==20);
|
sl@0
|
255 |
test.End();
|
sl@0
|
256 |
}
|
sl@0
|
257 |
|
sl@0
|
258 |
void setRamDriveSize(TBusLocalDrive aRamDrive, TInt aSize)
|
sl@0
|
259 |
{
|
sl@0
|
260 |
|
sl@0
|
261 |
TLocalDriveCapsV2 info;
|
sl@0
|
262 |
TPckg<TLocalDriveCapsV2> infoPckg(info);
|
sl@0
|
263 |
test(aRamDrive.Caps(infoPckg)==KErrNone);
|
sl@0
|
264 |
TInt oldsize=info.iSize.Low();
|
sl@0
|
265 |
if (aSize>oldsize)
|
sl@0
|
266 |
test(aRamDrive.Enlarge(aSize-oldsize)==KErrNone);
|
sl@0
|
267 |
else
|
sl@0
|
268 |
test(aRamDrive.ReduceSize(0,oldsize-aSize)==KErrNone);
|
sl@0
|
269 |
}
|
sl@0
|
270 |
|
sl@0
|
271 |
GLDEF_C TInt E32Main(void)
|
sl@0
|
272 |
//
|
sl@0
|
273 |
// Test the Ram Drive and the Registry
|
sl@0
|
274 |
//
|
sl@0
|
275 |
{
|
sl@0
|
276 |
|
sl@0
|
277 |
test.Title();
|
sl@0
|
278 |
|
sl@0
|
279 |
test.Start(_L("Connect to the Local Drive"));
|
sl@0
|
280 |
TBool changedFlag;
|
sl@0
|
281 |
TBusLocalDrive ramDrive;
|
sl@0
|
282 |
TInt r=ramDrive.Connect(0,changedFlag);
|
sl@0
|
283 |
test(r==KErrNone);
|
sl@0
|
284 |
|
sl@0
|
285 |
test.Next(_L("Test testing the ram drive"));
|
sl@0
|
286 |
fillRamDrive(ramDrive);
|
sl@0
|
287 |
testRamDrive(ramDrive);
|
sl@0
|
288 |
|
sl@0
|
289 |
test.Next(_L("Simple grow test"));
|
sl@0
|
290 |
fillRamDrive(ramDrive);
|
sl@0
|
291 |
testGrow();
|
sl@0
|
292 |
testRamDrive(ramDrive);
|
sl@0
|
293 |
test.Next(_L("Shrink"));
|
sl@0
|
294 |
deleteReg();
|
sl@0
|
295 |
testRamDrive(ramDrive);
|
sl@0
|
296 |
|
sl@0
|
297 |
{
|
sl@0
|
298 |
deleteReg();
|
sl@0
|
299 |
test.Next(_L("Grow the registry a bit"));
|
sl@0
|
300 |
TInt n=fillReg(_L8("Run Away"),40);
|
sl@0
|
301 |
test.Next(_L("Test the content of the registry"));
|
sl@0
|
302 |
TInt m=testReg(_L8("Run Away"),n);
|
sl@0
|
303 |
test(n==m);
|
sl@0
|
304 |
test.Next(_L("Shrink it a bit"));
|
sl@0
|
305 |
m=shrinkReg(_L8("Run Away"),n);
|
sl@0
|
306 |
test(n==m);
|
sl@0
|
307 |
test.Next(_L("test ram drive"));
|
sl@0
|
308 |
testRamDrive(ramDrive);
|
sl@0
|
309 |
}
|
sl@0
|
310 |
|
sl@0
|
311 |
/* test.Next(_L("Run the tests with the current ram drive size"));
|
sl@0
|
312 |
fillRamDrive(ramDrive);
|
sl@0
|
313 |
test1();
|
sl@0
|
314 |
testRamDrive(ramDrive);*/
|
sl@0
|
315 |
|
sl@0
|
316 |
test.Next(_L("Run the tests with no Ram Drive"));
|
sl@0
|
317 |
setRamDriveSize(ramDrive, 0);
|
sl@0
|
318 |
test1();
|
sl@0
|
319 |
|
sl@0
|
320 |
test.Next(_L("Run the tests with small ram drive"));
|
sl@0
|
321 |
setRamDriveSize(ramDrive, 0x3000);
|
sl@0
|
322 |
fillRamDrive(ramDrive);
|
sl@0
|
323 |
test1();
|
sl@0
|
324 |
testRamDrive(ramDrive);
|
sl@0
|
325 |
|
sl@0
|
326 |
test.Next(_L("Clear the registry"));
|
sl@0
|
327 |
deleteReg();
|
sl@0
|
328 |
|
sl@0
|
329 |
/* test.Next(_L("Run the tests with a big ram drive"));
|
sl@0
|
330 |
r=KErrGeneral;
|
sl@0
|
331 |
while (r==KErrNone)
|
sl@0
|
332 |
r=ramDrive.Enlarge(0x1000);
|
sl@0
|
333 |
test.Printf(_L("%d"), r);
|
sl@0
|
334 |
// test(r==KErrDiskFull);
|
sl@0
|
335 |
r=ramDrive.ReduceSize(0, 0x2000);
|
sl@0
|
336 |
test(r==KErrNone);
|
sl@0
|
337 |
fillRamDrive(ramDrive);
|
sl@0
|
338 |
test1();
|
sl@0
|
339 |
testRamDrive(ramDrive);*/
|
sl@0
|
340 |
|
sl@0
|
341 |
ramDrive.Disconnect();
|
sl@0
|
342 |
|
sl@0
|
343 |
test.End();
|
sl@0
|
344 |
return(KErrNone);
|
sl@0
|
345 |
}
|
sl@0
|
346 |
|