os/kernelhwsrv/kerneltest/e32test/system/t_regram.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/system/t_regram.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,346 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\system\t_regram.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32test.h>
    1.22 +#include <e32svr.h>
    1.23 +
    1.24 +//
    1.25 +// This test takes forever to run and destroys the internal Ram drive.
    1.26 +//
    1.27 +
    1.28 +LOCAL_D RTest test(_L("T_REGRAM"));
    1.29 +
    1.30 +void deleteReg()
    1.31 +//
    1.32 +// Delete everything from the registry
    1.33 +//
    1.34 +	{
    1.35 +	TUid uid;
    1.36 +	TRegistryIter riter;
    1.37 +	riter.Reset();
    1.38 +	while (riter.Next(uid)==KErrNone)
    1.39 +		{
    1.40 +		TRegistryCategory cat(uid);
    1.41 +		cat.DeleteAllItems();
    1.42 +		}
    1.43 +	}
    1.44 +
    1.45 +TInt fillReg(const TDesC8 &aDes, TInt aEntries)
    1.46 +//
    1.47 +// Fill the registry with big nasty monsters
    1.48 +// returns the number of entries made.
    1.49 +//
    1.50 +	{
    1.51 +	TBuf8<0x100> buf=_L8("");
    1.52 +	TInt i;
    1.53 +	for (i=0; i<8; i++)
    1.54 +		buf.Append(_L8("Big_ nasty_ monster_ chasing_ me"));
    1.55 +	
    1.56 +	TUid uid;
    1.57 +	uid=TUid::Uid(0x12345678);
    1.58 +	TRegistryCategory cat(uid);
    1.59 +	i=0;
    1.60 +	TBuf8<0x20> item;
    1.61 +	while (i<aEntries)
    1.62 +		{
    1.63 +		item.Format(_L8("%S %08x"),&aDes,i);
    1.64 +		TInt r=cat.SetItem(item, buf);
    1.65 +		if (r!=KErrNone)
    1.66 +			break;
    1.67 +		i++;
    1.68 +		}
    1.69 +	return i;
    1.70 +	}
    1.71 +
    1.72 +TInt shrinkReg(const TDesC8 &aDes, TInt aEntries)
    1.73 +//
    1.74 +// Delete aEntries entries from the registry
    1.75 +// returns number of entries deleted.
    1.76 +//
    1.77 +	{
    1.78 +
    1.79 +
    1.80 +	TUid uid;
    1.81 +	uid=TUid::Uid(0x12345678);
    1.82 +	TRegistryCategory cat(uid);
    1.83 +	TBuf8<0x20> item;
    1.84 +	TInt i=aEntries-1;
    1.85 +	while (i>=0)
    1.86 +		{
    1.87 +		item.Format(_L8("%S %08x"),&aDes,i);
    1.88 +		TInt r=cat.DeleteItem(item);
    1.89 +		if (r!=KErrNone)
    1.90 +			break;
    1.91 +		i--;
    1.92 +		}
    1.93 +	return aEntries-i-1;
    1.94 +	}
    1.95 +
    1.96 +TInt testReg(const TDesC8 &aDes, TInt aEntries)
    1.97 +//
    1.98 +// Test the first aEntries entries are set correctly
    1.99 +//
   1.100 +	{
   1.101 +	TBuf8<0x100> buf=_L8("");
   1.102 +	TInt i;
   1.103 +	for (i=0; i<8; i++)
   1.104 +		buf.Append(_L8("Big_ nasty_ monster_ chasing_ me"));
   1.105 +	
   1.106 +	TUid uid;
   1.107 +	uid=TUid::Uid(0x12345678);
   1.108 +	TRegistryCategory cat(uid);
   1.109 +
   1.110 +	TBuf8<0x20> item;
   1.111 +	TBuf8<0x100> res;
   1.112 +	i=0;
   1.113 +	while (i<aEntries)
   1.114 +		{
   1.115 +		item.Format(_L8("%S %08x"),&aDes,i);
   1.116 +		if ((i&0x1f)==0)
   1.117 +			test.Printf(_L("."));
   1.118 +		res=cat.Item(item, _L8("Gone gone gone"));
   1.119 +		test(buf==res);
   1.120 +		i++;
   1.121 +		}
   1.122 +	test.Printf(_L("\n"));
   1.123 +	return i;
   1.124 +	}
   1.125 +
   1.126 +void test1()
   1.127 +//
   1.128 +// Test growing and shrinking the registry
   1.129 +//
   1.130 +	{
   1.131 +
   1.132 +	test.Start(_L("Cleanout the registry"));
   1.133 +	deleteReg();
   1.134 +
   1.135 +	test.Next(_L("Grow the registry a bit"));
   1.136 +	TInt n=fillReg(_L8("Run Away"),40);
   1.137 +	test.Printf(_L("Made %d entries\n"), n);
   1.138 +	test.Next(_L("Test the content of the registry"));
   1.139 +	TInt m=testReg(_L8("Run Away"),n);
   1.140 +	test(n==m);
   1.141 +	test.Next(_L("Shrink it a bit"));
   1.142 +	m=shrinkReg(_L8("Run Away"),n);
   1.143 +	test.Printf(_L("Deleted %d entries\n"), m);
   1.144 +	test(n==m);
   1.145 +
   1.146 +	test.Next(_L("Fill the registry with guff"));
   1.147 +	test.Printf(_L("\tTHIS TEST TAKES AGES\n"));
   1.148 +	n=fillReg(_L8("Run Away"),0x7fffffff);
   1.149 +	test.Printf(_L("Made %d entries\n"), n);
   1.150 +	test.Next(_L("Test the content of the registry"));
   1.151 +	m=testReg(_L8("Run Away"),n);
   1.152 +	test.Next(_L("Shrink the registry"));
   1.153 +	m=shrinkReg(_L8("Run Away"),n);
   1.154 +	test.Printf(_L("Deleted %d entries\n"), m);
   1.155 +	test(n==m);
   1.156 +
   1.157 +	test.Next(_L("Grow a bigish registry"));
   1.158 +	n=fillReg(_L8("Lunge"),40);
   1.159 +	test.Next(_L("Save the registry"));
   1.160 +    TUint8* bigPtr=new TUint8[0x8000];
   1.161 +	TPtr8 big(bigPtr, 0x8000);
   1.162 +	TInt bigsize;
   1.163 +	TInt r=User::MachineConfiguration(big,bigsize);
   1.164 +	test(r==KErrNone);
   1.165 +
   1.166 +	test.Next(_L("Clear it"));
   1.167 +	deleteReg();
   1.168 +
   1.169 +	test.Next(_L("Grow a little registry"));
   1.170 +	m=fillReg(_L8("Groat"), 10);
   1.171 +	test.Next(_L("Save it"));
   1.172 +    TUint8* littlePtr=new TUint8[0x8000];
   1.173 +	TPtr8 little(littlePtr, 0x8000);
   1.174 +	TInt littlesize;
   1.175 +	r=User::MachineConfiguration(little,littlesize);
   1.176 +	test(r==KErrNone);
   1.177 +
   1.178 +	test.Next(_L("Set to big registry"));
   1.179 +	r=User::SetMachineConfiguration(big);
   1.180 +	test(r==KErrNone);
   1.181 +	test.Next(_L("Test it"));
   1.182 +	TInt i=testReg(_L8("Lunge"), n);
   1.183 +	test(n==i);
   1.184 +
   1.185 +	test.Next(_L("Set to little registry"));
   1.186 +	r=User::SetMachineConfiguration(little);
   1.187 +	test(r==KErrNone);
   1.188 +	test.Next(_L("Test it"));
   1.189 +	i=testReg(_L8("Groat"), m);
   1.190 +	test(i==m);
   1.191 +	
   1.192 +	test.Next(_L("Set to big registry again"));
   1.193 +	deleteReg();
   1.194 +	r=User::SetMachineConfiguration(big);
   1.195 +	test(r==KErrNone);
   1.196 +	test.Next(_L("Test it"));
   1.197 +	i=testReg(_L8("Lunge"), n);
   1.198 +	test(n==i);
   1.199 +
   1.200 +	delete bigPtr;
   1.201 +	delete littlePtr;
   1.202 +	test.End();
   1.203 +	}
   1.204 +
   1.205 +void fillRamDrive(TBusLocalDrive &aRamDrive)
   1.206 +//
   1.207 +// Fill the ram drive with data
   1.208 +//
   1.209 +	{
   1.210 +
   1.211 +	TLocalDriveCapsV2 info;
   1.212 +	TPckg<TLocalDriveCapsV2> infoPckg(info);
   1.213 +	test(aRamDrive.Caps(infoPckg)==KErrNone);
   1.214 +	TInt size=info.iSize.Low();
   1.215 +	TInt i;
   1.216 +	TPckgBuf<TInt> dataBuf;
   1.217 +	TInt &data=dataBuf();
   1.218 +	for (i=0; i<size; i+=4)
   1.219 +		{
   1.220 +		data=i;
   1.221 +		aRamDrive.Write(i, dataBuf);
   1.222 +		}
   1.223 +	}
   1.224 +
   1.225 +void testRamDrive(TBusLocalDrive &aRamDrive)
   1.226 +//
   1.227 +// Test the data is still OK
   1.228 +//
   1.229 +	{
   1.230 +
   1.231 +	TLocalDriveCapsV2 info;
   1.232 +	TPckg<TLocalDriveCapsV2> infoPckg(info);
   1.233 +	test(aRamDrive.Caps(infoPckg)==KErrNone);
   1.234 +	TInt size=info.iSize.Low();
   1.235 +	TInt i;
   1.236 +	TPckgBuf<TInt> dataBuf;
   1.237 +	TInt &data=dataBuf();
   1.238 +	for (i=0; i<size; i+=4)
   1.239 +		{
   1.240 +		aRamDrive.Read(i, sizeof(TInt), dataBuf);
   1.241 +		if (i&0x3ff==0)
   1.242 +			test.Printf(_L("."));
   1.243 +	//	test.Printf(_L("%08x "), data);
   1.244 +		test(data==i);
   1.245 +		}
   1.246 +	test.Printf(_L("\n"));
   1.247 +	}
   1.248 +
   1.249 +void testGrow()
   1.250 +	{
   1.251 +
   1.252 +	test.Start(_L("Grow the registry a bit"));
   1.253 +	TInt n=fillReg(_L8("Run Away"),20);
   1.254 +	test(n==20);
   1.255 +	test.Next(_L("Test the content of the registry"));
   1.256 +	testReg(_L8("Run Away"),n);
   1.257 +	test(n==20);
   1.258 +	test.End();
   1.259 +	}
   1.260 +
   1.261 +void setRamDriveSize(TBusLocalDrive aRamDrive, TInt aSize)
   1.262 +	{
   1.263 +
   1.264 +	TLocalDriveCapsV2 info;
   1.265 +	TPckg<TLocalDriveCapsV2> infoPckg(info);
   1.266 +	test(aRamDrive.Caps(infoPckg)==KErrNone);
   1.267 +	TInt oldsize=info.iSize.Low();
   1.268 +	if (aSize>oldsize)
   1.269 +		test(aRamDrive.Enlarge(aSize-oldsize)==KErrNone);
   1.270 +	else
   1.271 +		test(aRamDrive.ReduceSize(0,oldsize-aSize)==KErrNone);
   1.272 +	}
   1.273 +
   1.274 +GLDEF_C TInt E32Main(void)
   1.275 +//
   1.276 +// Test the Ram Drive and the Registry
   1.277 +//
   1.278 +	{
   1.279 +
   1.280 +	test.Title();
   1.281 +
   1.282 +	test.Start(_L("Connect to the Local Drive"));
   1.283 +	TBool changedFlag;
   1.284 +	TBusLocalDrive ramDrive;
   1.285 +	TInt r=ramDrive.Connect(0,changedFlag);
   1.286 +	test(r==KErrNone);
   1.287 +
   1.288 +	test.Next(_L("Test testing the ram drive"));
   1.289 +	fillRamDrive(ramDrive);
   1.290 +	testRamDrive(ramDrive);
   1.291 +
   1.292 +	test.Next(_L("Simple grow test"));
   1.293 +	fillRamDrive(ramDrive);
   1.294 +	testGrow();
   1.295 +	testRamDrive(ramDrive);	
   1.296 +	test.Next(_L("Shrink"));
   1.297 +	deleteReg();
   1.298 +	testRamDrive(ramDrive);
   1.299 +
   1.300 +	{
   1.301 +	deleteReg();
   1.302 +	test.Next(_L("Grow the registry a bit"));
   1.303 +	TInt n=fillReg(_L8("Run Away"),40);
   1.304 +	test.Next(_L("Test the content of the registry"));
   1.305 +	TInt m=testReg(_L8("Run Away"),n);
   1.306 +	test(n==m);
   1.307 +	test.Next(_L("Shrink it a bit"));
   1.308 +	m=shrinkReg(_L8("Run Away"),n);
   1.309 +	test(n==m);
   1.310 +	test.Next(_L("test ram drive"));
   1.311 +	testRamDrive(ramDrive);
   1.312 +	}
   1.313 +
   1.314 +/*	test.Next(_L("Run the tests with the current ram drive size"));
   1.315 +	fillRamDrive(ramDrive);
   1.316 +	test1();
   1.317 +	testRamDrive(ramDrive);*/
   1.318 +
   1.319 +	test.Next(_L("Run the tests with no Ram Drive"));
   1.320 +	setRamDriveSize(ramDrive, 0);
   1.321 +	test1();
   1.322 +
   1.323 +	test.Next(_L("Run the tests with small ram drive"));
   1.324 +	setRamDriveSize(ramDrive, 0x3000);
   1.325 +	fillRamDrive(ramDrive);
   1.326 +	test1();
   1.327 +	testRamDrive(ramDrive);
   1.328 +
   1.329 +	test.Next(_L("Clear the registry"));
   1.330 +	deleteReg();
   1.331 +
   1.332 +/*	test.Next(_L("Run the tests with a big ram drive"));
   1.333 +	r=KErrGeneral;
   1.334 +	while (r==KErrNone)
   1.335 +		r=ramDrive.Enlarge(0x1000);
   1.336 +	test.Printf(_L("%d"), r);
   1.337 +//	test(r==KErrDiskFull);
   1.338 +	r=ramDrive.ReduceSize(0, 0x2000);
   1.339 +	test(r==KErrNone);
   1.340 +	fillRamDrive(ramDrive);
   1.341 +	test1();
   1.342 +	testRamDrive(ramDrive);*/
   1.343 +
   1.344 +	ramDrive.Disconnect();
   1.345 +
   1.346 +	test.End();
   1.347 +	return(KErrNone);
   1.348 +	}
   1.349 +