Update contrib.
1 // Copyright (c) 1997-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 the License "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.
14 // e32test\system\t_regram.cpp
22 // This test takes forever to run and destroys the internal Ram drive.
25 LOCAL_D RTest test(_L("T_REGRAM"));
29 // Delete everything from the registry
35 while (riter.Next(uid)==KErrNone)
37 TRegistryCategory cat(uid);
42 TInt fillReg(const TDesC8 &aDes, TInt aEntries)
44 // Fill the registry with big nasty monsters
45 // returns the number of entries made.
48 TBuf8<0x100> buf=_L8("");
51 buf.Append(_L8("Big_ nasty_ monster_ chasing_ me"));
54 uid=TUid::Uid(0x12345678);
55 TRegistryCategory cat(uid);
60 item.Format(_L8("%S %08x"),&aDes,i);
61 TInt r=cat.SetItem(item, buf);
69 TInt shrinkReg(const TDesC8 &aDes, TInt aEntries)
71 // Delete aEntries entries from the registry
72 // returns number of entries deleted.
78 uid=TUid::Uid(0x12345678);
79 TRegistryCategory cat(uid);
84 item.Format(_L8("%S %08x"),&aDes,i);
85 TInt r=cat.DeleteItem(item);
93 TInt testReg(const TDesC8 &aDes, TInt aEntries)
95 // Test the first aEntries entries are set correctly
98 TBuf8<0x100> buf=_L8("");
101 buf.Append(_L8("Big_ nasty_ monster_ chasing_ me"));
104 uid=TUid::Uid(0x12345678);
105 TRegistryCategory cat(uid);
112 item.Format(_L8("%S %08x"),&aDes,i);
114 test.Printf(_L("."));
115 res=cat.Item(item, _L8("Gone gone gone"));
119 test.Printf(_L("\n"));
125 // Test growing and shrinking the registry
129 test.Start(_L("Cleanout the registry"));
132 test.Next(_L("Grow the registry a bit"));
133 TInt n=fillReg(_L8("Run Away"),40);
134 test.Printf(_L("Made %d entries\n"), n);
135 test.Next(_L("Test the content of the registry"));
136 TInt m=testReg(_L8("Run Away"),n);
138 test.Next(_L("Shrink it a bit"));
139 m=shrinkReg(_L8("Run Away"),n);
140 test.Printf(_L("Deleted %d entries\n"), m);
143 test.Next(_L("Fill the registry with guff"));
144 test.Printf(_L("\tTHIS TEST TAKES AGES\n"));
145 n=fillReg(_L8("Run Away"),0x7fffffff);
146 test.Printf(_L("Made %d entries\n"), n);
147 test.Next(_L("Test the content of the registry"));
148 m=testReg(_L8("Run Away"),n);
149 test.Next(_L("Shrink the registry"));
150 m=shrinkReg(_L8("Run Away"),n);
151 test.Printf(_L("Deleted %d entries\n"), m);
154 test.Next(_L("Grow a bigish registry"));
155 n=fillReg(_L8("Lunge"),40);
156 test.Next(_L("Save the registry"));
157 TUint8* bigPtr=new TUint8[0x8000];
158 TPtr8 big(bigPtr, 0x8000);
160 TInt r=User::MachineConfiguration(big,bigsize);
163 test.Next(_L("Clear it"));
166 test.Next(_L("Grow a little registry"));
167 m=fillReg(_L8("Groat"), 10);
168 test.Next(_L("Save it"));
169 TUint8* littlePtr=new TUint8[0x8000];
170 TPtr8 little(littlePtr, 0x8000);
172 r=User::MachineConfiguration(little,littlesize);
175 test.Next(_L("Set to big registry"));
176 r=User::SetMachineConfiguration(big);
178 test.Next(_L("Test it"));
179 TInt i=testReg(_L8("Lunge"), n);
182 test.Next(_L("Set to little registry"));
183 r=User::SetMachineConfiguration(little);
185 test.Next(_L("Test it"));
186 i=testReg(_L8("Groat"), m);
189 test.Next(_L("Set to big registry again"));
191 r=User::SetMachineConfiguration(big);
193 test.Next(_L("Test it"));
194 i=testReg(_L8("Lunge"), n);
202 void fillRamDrive(TBusLocalDrive &aRamDrive)
204 // Fill the ram drive with data
208 TLocalDriveCapsV2 info;
209 TPckg<TLocalDriveCapsV2> infoPckg(info);
210 test(aRamDrive.Caps(infoPckg)==KErrNone);
211 TInt size=info.iSize.Low();
213 TPckgBuf<TInt> dataBuf;
214 TInt &data=dataBuf();
215 for (i=0; i<size; i+=4)
218 aRamDrive.Write(i, dataBuf);
222 void testRamDrive(TBusLocalDrive &aRamDrive)
224 // Test the data is still OK
228 TLocalDriveCapsV2 info;
229 TPckg<TLocalDriveCapsV2> infoPckg(info);
230 test(aRamDrive.Caps(infoPckg)==KErrNone);
231 TInt size=info.iSize.Low();
233 TPckgBuf<TInt> dataBuf;
234 TInt &data=dataBuf();
235 for (i=0; i<size; i+=4)
237 aRamDrive.Read(i, sizeof(TInt), dataBuf);
239 test.Printf(_L("."));
240 // test.Printf(_L("%08x "), data);
243 test.Printf(_L("\n"));
249 test.Start(_L("Grow the registry a bit"));
250 TInt n=fillReg(_L8("Run Away"),20);
252 test.Next(_L("Test the content of the registry"));
253 testReg(_L8("Run Away"),n);
258 void setRamDriveSize(TBusLocalDrive aRamDrive, TInt aSize)
261 TLocalDriveCapsV2 info;
262 TPckg<TLocalDriveCapsV2> infoPckg(info);
263 test(aRamDrive.Caps(infoPckg)==KErrNone);
264 TInt oldsize=info.iSize.Low();
266 test(aRamDrive.Enlarge(aSize-oldsize)==KErrNone);
268 test(aRamDrive.ReduceSize(0,oldsize-aSize)==KErrNone);
271 GLDEF_C TInt E32Main(void)
273 // Test the Ram Drive and the Registry
279 test.Start(_L("Connect to the Local Drive"));
281 TBusLocalDrive ramDrive;
282 TInt r=ramDrive.Connect(0,changedFlag);
285 test.Next(_L("Test testing the ram drive"));
286 fillRamDrive(ramDrive);
287 testRamDrive(ramDrive);
289 test.Next(_L("Simple grow test"));
290 fillRamDrive(ramDrive);
292 testRamDrive(ramDrive);
293 test.Next(_L("Shrink"));
295 testRamDrive(ramDrive);
299 test.Next(_L("Grow the registry a bit"));
300 TInt n=fillReg(_L8("Run Away"),40);
301 test.Next(_L("Test the content of the registry"));
302 TInt m=testReg(_L8("Run Away"),n);
304 test.Next(_L("Shrink it a bit"));
305 m=shrinkReg(_L8("Run Away"),n);
307 test.Next(_L("test ram drive"));
308 testRamDrive(ramDrive);
311 /* test.Next(_L("Run the tests with the current ram drive size"));
312 fillRamDrive(ramDrive);
314 testRamDrive(ramDrive);*/
316 test.Next(_L("Run the tests with no Ram Drive"));
317 setRamDriveSize(ramDrive, 0);
320 test.Next(_L("Run the tests with small ram drive"));
321 setRamDriveSize(ramDrive, 0x3000);
322 fillRamDrive(ramDrive);
324 testRamDrive(ramDrive);
326 test.Next(_L("Clear the registry"));
329 /* test.Next(_L("Run the tests with a big ram drive"));
332 r=ramDrive.Enlarge(0x1000);
333 test.Printf(_L("%d"), r);
334 // test(r==KErrDiskFull);
335 r=ramDrive.ReduceSize(0, 0x2000);
337 fillRamDrive(ramDrive);
339 testRamDrive(ramDrive);*/
341 ramDrive.Disconnect();