os/ossrv/lowlevellibsandfws/apputils/tsrc/T_RESOURCE_COMPRESSION2.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/tsrc/T_RESOURCE_COMPRESSION2.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,670 @@
     1.4 +// Copyright (c) 2003-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 "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 +//
    1.18 +
    1.19 +#include <e32std.h>
    1.20 +#include <e32base.h>
    1.21 +#include <e32test.h>
    1.22 +#include <f32file.h>
    1.23 +#include <bautils.h>
    1.24 +#include <barsc2.h>
    1.25 +#include <barsread2.h>
    1.26 +#include <t_compressed_unicode_1.rsg>
    1.27 +#include <t_compressed_unicode_2.rsg>
    1.28 +
    1.29 +RTest test(_L("T_RESOURCE_COMPRESSION2"));
    1.30 +RFs fileServerSession;
    1.31 +_LIT8(KRscFileHeaderData, "0123456789ABCDEF");
    1.32 +_LIT(KRomResourceFileHeader, "z:\\system\\data\\RscHeader.bin");
    1.33 +
    1.34 +LOCAL_D const TPtrC rsc_files[] =
    1.35 +	{
    1.36 +	  _L("T_COMPRESSED_UNICODE_1.RSC")
    1.37 +	, _L("T_COMPRESSED_UNICODE_2.RSC")
    1.38 +	, _L("T_DICTIONARY_COMPRESSED_VERSIO_OF_2.RSC")
    1.39 +	, _L("T_CALYPSO_TEST_RESOURCE_FILE_1.RSC")
    1.40 +	, _L("T_NotRscFile.RSC")
    1.41 +	, _L("TRscROMCalypsoComprNewFmt.rsc")
    1.42 +	};
    1.43 +_LIT(KZDir, "z:\\system\\data\\");
    1.44 +_LIT(KCDir, "c:\\");
    1.45 +
    1.46 +LOCAL_C void DeleteDataFile(const TDesC& aFullName)
    1.47 +	{
    1.48 +	// make sure the file is read/write
    1.49 +	TInt err = fileServerSession.SetAtt(aFullName,0, KEntryAttReadOnly);
    1.50 +	if(err != KErrNone)
    1.51 +		{
    1.52 +		RDebug::Print(_L("error changing attributes file = %d"),err);
    1.53 +		}
    1.54 +	// delete the file
    1.55 +	err = BaflUtils::DeleteFile(fileServerSession, aFullName);
    1.56 +	if(err != KErrNone)
    1.57 +		{
    1.58 +		RDebug::Print(_L("error deleting file = %d"),err);
    1.59 +		}
    1.60 +	}
    1.61 +
    1.62 +LOCAL_C TInt FileSizeL(const TDesC& aFileName)
    1.63 +	{
    1.64 +	RFile file;
    1.65 +	User::LeaveIfError(file.Open(fileServerSession, aFileName, EFileRead));
    1.66 +	CleanupClosePushL(file);
    1.67 +	TInt size = 0;
    1.68 +	User::LeaveIfError(file.Size(size));
    1.69 +	CleanupStack::PopAndDestroy(&file);
    1.70 +	return size;
    1.71 +	}
    1.72 +
    1.73 +LOCAL_C void CreateFileFromL(const TDesC& aDestFileName, const TDesC& aSrcFileName)
    1.74 +	{
    1.75 +	RFile destFile;
    1.76 +	RFile srcFile;
    1.77 +
    1.78 +	CleanupClosePushL(destFile);
    1.79 +	CleanupClosePushL(srcFile);
    1.80 +
    1.81 +	BaflUtils::DeleteFile(fileServerSession, aDestFileName);
    1.82 +	User::LeaveIfError(destFile.Create(fileServerSession, aDestFileName, EFileRead | EFileWrite));
    1.83 +
    1.84 +	User::LeaveIfError(srcFile.Open(fileServerSession, aSrcFileName, EFileRead));
    1.85 +	TInt size = 0;
    1.86 +	User::LeaveIfError(srcFile.Size(size));
    1.87 +	HBufC8* buf = HBufC8::NewMaxLC(size);
    1.88 +	TPtr8 ptr = buf->Des();
    1.89 +	srcFile.Read(ptr);
    1.90 +
    1.91 +	destFile.Write(KRscFileHeaderData);
    1.92 +	destFile.Write(ptr);
    1.93 +
    1.94 +	CleanupStack::PopAndDestroy(buf);
    1.95 +	CleanupStack::PopAndDestroy(&srcFile);
    1.96 +	CleanupStack::PopAndDestroy(&destFile);
    1.97 +	}
    1.98 +
    1.99 +LOCAL_C void CreateFileFromL(TDes& aDestFilePath, const TDesC& aDestFileName, const TDesC& aSrcFilePath)
   1.100 +	{
   1.101 +	aDestFilePath.Copy(KCDir);
   1.102 +	aDestFilePath += _L("N_");
   1.103 +	aDestFilePath += aDestFileName;
   1.104 +	CreateFileFromL(aDestFilePath, aSrcFilePath);
   1.105 +	}
   1.106 +
   1.107 +LOCAL_C void Test1L(const TDesC& aResourceFileName, TUint aFileOffset = 0, TInt aFileSize = 0)
   1.108 +	{
   1.109 +	CResourceFile* resourceFile = CResourceFile::NewLC(fileServerSession, aResourceFileName, aFileOffset, aFileSize);
   1.110 +	test(resourceFile->UidType()==TUidType(TUid::Uid(0x101f4a6b), TUid::Uid(0x000eb205), TUid::Uid(TUint(T_COMPRESSED_UNICODE_1_RESOURCE_1)>>12)));
   1.111 +	HBufC8* resource = NULL;
   1.112 +	RResourceReader resourceReader;
   1.113 +
   1.114 +	resource=resourceFile->AllocReadLC(1);
   1.115 +	test(resource->Length()%sizeof(TText)==0);
   1.116 +	test(TPtrC((TText*)resource->Ptr(), resource->Length()/sizeof(TText))==_L("Gruezi miteinander"));
   1.117 +	CleanupStack::PopAndDestroy(resource);
   1.118 +	resource = NULL;
   1.119 +
   1.120 +	resourceReader.OpenLC(resourceFile, 2);
   1.121 +	test(resourceReader.ReadUint16L()==4);
   1.122 +	test(resourceReader.ReadTPtrCL()==_L("Bonjour"));
   1.123 +	test(resourceReader.ReadTPtrCL()==_L("Ni3 hao3"));
   1.124 +	test(resourceReader.ReadTPtrCL()==_L("Konnichiwa"));
   1.125 +	test(resourceReader.ReadTPtrCL()==_L("Zdravstvuit'e"));
   1.126 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.127 +	resource = NULL;
   1.128 +
   1.129 +	resourceReader.OpenLC(resourceFile, 3);
   1.130 +	test(resourceReader.ReadUint16L()==3);
   1.131 +	test(resourceReader.ReadTPtrCL()==_L("Gamarjoba"));
   1.132 +	test(resourceReader.ReadTPtrCL()==_L("Gasou"));
   1.133 +	test(resourceReader.ReadTPtrCL()==_L("Ola"));
   1.134 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.135 +	resource = NULL;
   1.136 +
   1.137 +	resourceReader.OpenLC(resourceFile, 4);
   1.138 +	test(resourceReader.ReadUint16L()==3);
   1.139 +	test(resourceReader.ReadUint8L()==0xbd);
   1.140 +	test(resourceReader.ReadUint8L()==0x5e);
   1.141 +	test(resourceReader.ReadUint8L()==0xf1);
   1.142 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.143 +	resource = NULL;
   1.144 +
   1.145 +	resourceReader.OpenLC(resourceFile, 5);
   1.146 +	test(resourceReader.ReadUint32L()==4);
   1.147 +	test(resourceReader.ReadUint32L()==T_COMPRESSED_UNICODE_1_RESOURCE_5);
   1.148 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.149 +	resource = NULL;
   1.150 +
   1.151 +	resource=resourceFile->AllocReadLC(6);
   1.152 +	test(resource->Length()%sizeof(TText)==0);
   1.153 +	test(TPtrC((TText*)resource->Ptr(), resource->Length()/sizeof(TText))==_L("_"));
   1.154 +	CleanupStack::PopAndDestroy(resource);
   1.155 +	resource = NULL;
   1.156 +
   1.157 +	resourceReader.OpenLC(resourceFile, 7);
   1.158 +	test(resourceReader.ReadUint8L()==9);
   1.159 +	test(resourceReader.ReadTPtrCL()==_L("To"));
   1.160 +	test(resourceReader.ReadUint8L()==97);
   1.161 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.162 +	resource = NULL;
   1.163 +
   1.164 +	resourceReader.OpenLC(resourceFile, 8);
   1.165 +	test(resourceReader.ReadUint16L()==999);
   1.166 +	test(resourceReader.ReadTPtrCL()==_L("To"));
   1.167 +	test(resourceReader.ReadUint8L()==79);
   1.168 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.169 +	resource = NULL;
   1.170 +
   1.171 +	resourceReader.OpenLC(resourceFile, 9);
   1.172 +	test(resourceReader.ReadUint16L()==53132);
   1.173 +	test(resourceReader.ReadTPtrCL()==_L("T"));
   1.174 +	test(resourceReader.ReadUint8L()==62);
   1.175 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.176 +	resource = NULL;
   1.177 +
   1.178 +	resourceReader.OpenLC(resourceFile, 10);
   1.179 +	test(resourceReader.ReadInt32L()==1253869);
   1.180 +	test(resourceReader.ReadInt32L()==-986324);
   1.181 +	test(resourceReader.ReadUint32L()==0x600ddea1u);
   1.182 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.183 +	resource = NULL;
   1.184 +
   1.185 +	CleanupStack::PopAndDestroy(resourceFile);
   1.186 +	}
   1.187 +
   1.188 +LOCAL_C void Test2L(const TDesC& aResourceFileName, TUid aFirstUid, TUint aFileOffset = 0, TInt aFileSize = 0)
   1.189 +	{
   1.190 +	CResourceFile* resourceFile = CResourceFile::NewLC(fileServerSession, aResourceFileName, aFileOffset, aFileSize);
   1.191 +	test(resourceFile->UidType()==TUidType(aFirstUid, TUid::Null(), TUid::Uid(TUint(T_COMPRESSED_UNICODE_2_RESOURCE_1)>>12)));
   1.192 +	HBufC8* resource = NULL;
   1.193 +	RResourceReader resourceReader;
   1.194 +
   1.195 +	resourceReader.OpenLC(resourceFile, 1);
   1.196 +	test(resourceReader.ReadUint32L()==4);
   1.197 +	test(resourceReader.ReadUint32L()==T_COMPRESSED_UNICODE_2_RESOURCE_1);
   1.198 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.199 +	resource = NULL;
   1.200 +
   1.201 +	resource=resourceFile->AllocReadLC(2);
   1.202 +	test(resource->Length()%sizeof(TText)==0);
   1.203 +	test(TPtrC((TText*)resource->Ptr(), resource->Length()/sizeof(TText))==_L("My program is cool"));
   1.204 +	CleanupStack::PopAndDestroy(resource);
   1.205 +	resource = NULL;
   1.206 +
   1.207 +	resource=resourceFile->AllocReadLC(3);
   1.208 +	test(resource->Length()%sizeof(TText)==0);
   1.209 +	test(TPtrC((TText*)resource->Ptr(), resource->Length()/sizeof(TText))==_L("z:\\system\\data\\eikon.mbm"));
   1.210 +	CleanupStack::PopAndDestroy(resource);
   1.211 +	resource = NULL;
   1.212 +
   1.213 +	resourceReader.OpenLC(resourceFile, 4);
   1.214 +	test(resourceReader.ReadInt32L()==9174804);
   1.215 +	test(resourceReader.ReadUint8L()==6);
   1.216 +	test(resourceReader.ReadInt32L()==-6208493);
   1.217 +	test(resourceReader.ReadUint16L()==0x3176);
   1.218 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.219 +	resource = NULL;
   1.220 +
   1.221 +	resourceReader.OpenLC(resourceFile, 5);
   1.222 +	test(resourceReader.ReadInt32L()==-120727);
   1.223 +	test(resourceReader.ReadInt32L()==-82385253);
   1.224 +	test(resourceReader.ReadUint16L()==0x3176);
   1.225 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.226 +	resource = NULL;
   1.227 +
   1.228 +	resourceReader.OpenLC(resourceFile, 6);
   1.229 +	test(resourceReader.ReadUint8L()==2);
   1.230 +	test(resourceReader.ReadTPtrCL()==_L("z:\\system\\data\\uikon.mbm"));
   1.231 +	test(resourceReader.ReadTPtrCL()==_L("z:\\system\\apps\\my_program\\my_program.mbm"));
   1.232 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.233 +	resource = NULL;
   1.234 +
   1.235 +	CleanupStack::PopAndDestroy(resourceFile);
   1.236 +	}
   1.237 +
   1.238 +LOCAL_C void Test3L(const TDesC& aResourceFileName, TUint aFileOffset = 0, TInt aFileSize = 0)
   1.239 +	{
   1.240 +	/* This function tests the calypso resoruce file format loading/reading
   1.241 +	 * and was derived from the Test1 function above. Therefore the resource
   1.242 +	 * file it reads is also derived from the file used in test 1.
   1.243 +	 */
   1.244 +
   1.245 +	CResourceFile* resourceFile = CResourceFile::NewLC(fileServerSession, aResourceFileName, aFileOffset, aFileSize);
   1.246 +	HBufC8* resource = NULL;
   1.247 +	RResourceReader resourceReader;
   1.248 +
   1.249 +	resource=resourceFile->AllocReadLC(1);
   1.250 +	test(resource->Length()%sizeof(TText)==0);
   1.251 +	test(TPtrC((TText*)resource->Ptr(), resource->Length()/sizeof(TText))==_L("Gruezi miteinander"));
   1.252 +	CleanupStack::PopAndDestroy(resource);
   1.253 +	resource = NULL;
   1.254 +
   1.255 +	resourceReader.OpenLC(resourceFile, 2);
   1.256 +	test(resourceReader.ReadUint16L()==4);
   1.257 +	test(resourceReader.ReadTPtrCL()==_L("Bonjour"));
   1.258 +	test(resourceReader.ReadTPtrCL()==_L("Ni3 hao3"));
   1.259 +	test(resourceReader.ReadTPtrCL()==_L("Konnichiwa"));
   1.260 +	test(resourceReader.ReadTPtrCL()==_L("Zdravstvuit'e"));
   1.261 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.262 +	resource = NULL;
   1.263 +
   1.264 +	resourceReader.OpenLC(resourceFile, 3);
   1.265 +	test(resourceReader.ReadUint16L()==3);
   1.266 +	test(resourceReader.ReadTPtrCL()==_L("Gamarjoba"));
   1.267 +	test(resourceReader.ReadTPtrCL()==_L("Gasou"));
   1.268 +	test(resourceReader.ReadTPtrCL()==_L("Ola"));
   1.269 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.270 +	resource = NULL;
   1.271 +
   1.272 +	resourceReader.OpenLC(resourceFile, 4);
   1.273 +	test(resourceReader.ReadUint16L()==3);
   1.274 +	test(resourceReader.ReadUint8L()==0xbd);
   1.275 +	test(resourceReader.ReadUint8L()==0x5e);
   1.276 +	test(resourceReader.ReadUint8L()==0xf1);
   1.277 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.278 +	resource = NULL;
   1.279 +
   1.280 +	resourceReader.OpenLC(resourceFile, 5);
   1.281 +	test(resourceReader.ReadUint32L()==4);
   1.282 +	test(resourceReader.ReadUint32L()==T_COMPRESSED_UNICODE_1_RESOURCE_5);
   1.283 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.284 +	resource = NULL;
   1.285 +
   1.286 +	resource=resourceFile->AllocReadLC(6);
   1.287 +	test(resource->Length()%sizeof(TText)==0);
   1.288 +	test(TPtrC((TText*)resource->Ptr(), resource->Length()/sizeof(TText))==_L("_"));
   1.289 +	CleanupStack::PopAndDestroy(resource);
   1.290 +	resource = NULL;
   1.291 +
   1.292 +	resourceReader.OpenLC(resourceFile, 7);
   1.293 +	test(resourceReader.ReadUint8L()==9);
   1.294 +	test(resourceReader.ReadTPtrCL()==_L("To"));
   1.295 +	test(resourceReader.ReadUint8L()==97);
   1.296 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.297 +	resource = NULL;
   1.298 +
   1.299 +	resourceReader.OpenLC(resourceFile, 8);
   1.300 +	test(resourceReader.ReadUint16L()==999);
   1.301 +	test(resourceReader.ReadTPtrCL()==_L("To"));
   1.302 +	test(resourceReader.ReadUint8L()==79);
   1.303 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.304 +	resource = NULL;
   1.305 +
   1.306 +	resourceReader.OpenLC(resourceFile, 9);
   1.307 +	test(resourceReader.ReadUint16L()==53132);
   1.308 +	test(resourceReader.ReadTPtrCL()==_L("T"));
   1.309 +	test(resourceReader.ReadUint8L()==62);
   1.310 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.311 +	resource = NULL;
   1.312 +
   1.313 +	resourceReader.OpenLC(resourceFile, 10);
   1.314 +	test(resourceReader.ReadInt32L()==1253869);
   1.315 +	test(resourceReader.ReadInt32L()==-986324);
   1.316 +	test(resourceReader.ReadUint32L()==0x600ddea1u);
   1.317 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.318 +	resource = NULL;
   1.319 +
   1.320 +	// reading resource 11 takes some time, as it is long
   1.321 +	// and gets compressed.
   1.322 +	// This is useful for the timing measurements in TestDef044572L()
   1.323 +	resourceReader.OpenLC(resourceFile, 11);
   1.324 +	CleanupStack::PopAndDestroy(1, &resourceReader);
   1.325 +	resource = NULL;
   1.326 +
   1.327 +	CleanupStack::PopAndDestroy(resourceFile);
   1.328 +	}
   1.329 +
   1.330 +LOCAL_C void Test4L(const TDesC& aResourceFileName, TUint aFileOffset = 0, TInt aFileSize = 0)
   1.331 +	{
   1.332 +	/* This function tests the behaviour of bafl when reading a calypso resource file
   1.333 +	 * for a signature. Calypso resource files do not have signatures.
   1.334 +	 */
   1.335 +
   1.336 +	CResourceFile* resourceFile = CResourceFile::NewLC(fileServerSession, aResourceFileName, aFileOffset, aFileSize);
   1.337 +
   1.338 +	// Need to pass the TInt as required, but doesn't
   1.339 +	// use it. Legacy for BC sake.
   1.340 +	TInt err = KErrNone;
   1.341 +	TRAP(err, resourceFile->ConfirmSignatureL(1));
   1.342 +	test(err == KErrCorrupt);
   1.343 +
   1.344 +	// New function that has further test to confirm absence of signature
   1.345 +	// Hopefully we can get clients to move over to this in future.
   1.346 +	TRAP(err, resourceFile->ConfirmSignatureL());
   1.347 +	test(err == KErrCorrupt);
   1.348 +
   1.349 +	CleanupStack::PopAndDestroy(resourceFile);
   1.350 +	}
   1.351 +
   1.352 +LOCAL_C void Test5L(const TDesC& aResourceFileName, TUint aFileOffset = 0, TInt aFileSize = 0)
   1.353 +	{
   1.354 +	/* This function tests the behaviour of bafl when reading a resource file
   1.355 +	 * for a signature.
   1.356 +	 * In this case the signature is present and is NOT the first resource.
   1.357 +	 */
   1.358 +
   1.359 +	CResourceFile* resourceFile = CResourceFile::NewLC(fileServerSession, aResourceFileName, aFileOffset, aFileSize);
   1.360 +
   1.361 +	// Need to pass the TInt as required, but doesn't
   1.362 +	// use it. Legacy for BC sake.
   1.363 +	TInt err = KErrNone;
   1.364 +	TRAP(err, resourceFile->ConfirmSignatureL(1));
   1.365 +	test(err == KErrCorrupt);
   1.366 +
   1.367 +	// New function that has further test to confirm absence of signature
   1.368 +	// Hopefully we can get clients to move over to this in future.
   1.369 +	TRAP(err, resourceFile->ConfirmSignatureL());
   1.370 +	test(err == KErrCorrupt);
   1.371 +
   1.372 +	CleanupStack::PopAndDestroy(resourceFile);
   1.373 +	}
   1.374 +
   1.375 +LOCAL_C void Test6L(const TDesC& aResourceFileName, TUint aFileOffset = 0, TInt aFileSize = 0)
   1.376 +	{
   1.377 +	/* This function tests the behaviour of bafl when reading a resource file
   1.378 +	 * for a signature.
   1.379 +	 * In this case the signature is present and is the first resource.
   1.380 +	 */
   1.381 +
   1.382 +	CResourceFile* resourceFile = CResourceFile::NewLC(fileServerSession, aResourceFileName, aFileOffset, aFileSize);
   1.383 +
   1.384 +	// Need to pass the TInt as required, but doesn't
   1.385 +	// use it. Legacy for BC sake.
   1.386 +	TInt err = KErrNone;
   1.387 +	TRAP(err, resourceFile->ConfirmSignatureL(1));
   1.388 +	test(err == KErrNone);
   1.389 +
   1.390 +	// New function that has further test to confirm absence of signature
   1.391 +	// Hopefully we can get clients to move over to this in future.
   1.392 +	TRAP(err, resourceFile->ConfirmSignatureL());
   1.393 +	test(err == KErrNone);
   1.394 +
   1.395 +	CleanupStack::PopAndDestroy(resourceFile);
   1.396 +	}
   1.397 +
   1.398 +LOCAL_C void Test7L(const TDesC& aResourceFileName, TUint aFileOffset = 0, TInt aFileSize = 0)
   1.399 +	{
   1.400 +	/* This function tests the behaviour of bafl when reading a non resource file.
   1.401 +	 */
   1.402 +	TRAPD(err, (void)CResourceFile::NewL(fileServerSession, aResourceFileName, aFileOffset, aFileSize));
   1.403 +	test(err != KErrNotFound && err != KErrNone);
   1.404 +	}
   1.405 +
   1.406 +/**
   1.407 +@SYMTestCaseID          SYSLIB-BAFL-CT-0480
   1.408 +@SYMTestCaseDesc        Testing resource files containing Unicode-compressed text
   1.409 +@SYMTestPriority        High
   1.410 +@SYMTestActions         Wrapper function calling up Test1L() and Test2L() functions
   1.411 +@SYMTestExpectedResults Tests must not fail
   1.412 +@SYMREQ                 REQ0000
   1.413 +*/
   1.414 +LOCAL_C void SubTest1L()
   1.415 +	{
   1.416 +	test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0480 Testing resource files containing Unicode-compressed text "));
   1.417 +	TBuf<128> z_path;
   1.418 +	TBuf<128> c_path;
   1.419 +
   1.420 +	z_path.Copy(KZDir);
   1.421 +	z_path += rsc_files[0];
   1.422 +	Test1L(z_path);
   1.423 +	CreateFileFromL(c_path, rsc_files[0], z_path);
   1.424 +	Test1L(c_path, KRscFileHeaderData().Length(), FileSizeL(z_path));
   1.425 +	DeleteDataFile(c_path);
   1.426 +
   1.427 +	z_path.Copy(KZDir);
   1.428 +	z_path.Append(rsc_files[1]);
   1.429 +	Test2L(z_path, TUid::Uid(0x101f4a6b));
   1.430 +	CreateFileFromL(c_path, rsc_files[1], z_path);
   1.431 +	Test2L(c_path, TUid::Uid(0x101f4a6b), KRscFileHeaderData().Length(), FileSizeL(z_path));
   1.432 +	DeleteDataFile(c_path);
   1.433 +	}
   1.434 +
   1.435 +/**
   1.436 +@SYMTestCaseID          SYSLIB-BAFL-CT-0481
   1.437 +@SYMTestCaseDesc        Testing dictionary-compressed resource files
   1.438 +@SYMTestPriority        High
   1.439 +@SYMTestActions         Wrapper function calling up Test2L() function
   1.440 +@SYMTestExpectedResults Tests must not fail
   1.441 +@SYMREQ                 REQ0000
   1.442 +*/
   1.443 +LOCAL_C void SubTest2L()
   1.444 +	{
   1.445 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0481 Testing dictionary-compressed resource files "));
   1.446 +	TBuf<128> z_path;
   1.447 +	TBuf<128> c_path;
   1.448 +
   1.449 +	z_path.Copy(KZDir);
   1.450 +	z_path.Append(rsc_files[2]);
   1.451 +	Test2L(z_path, TUid::Uid(0x101f5010));
   1.452 +	CreateFileFromL(c_path, rsc_files[2], z_path);
   1.453 +	Test2L(c_path, TUid::Uid(0x101f5010), KRscFileHeaderData().Length(), FileSizeL(z_path));
   1.454 +	DeleteDataFile(c_path);
   1.455 +	}
   1.456 +
   1.457 +/**
   1.458 +@SYMTestCaseID          SYSLIB-BAFL-CT-0482-0001
   1.459 +@SYMTestCaseDesc        Testing Calypso ER5u format dictionary-compressed resource files
   1.460 +@SYMTestPriority        High
   1.461 +@SYMTestActions         Wrapper function calling up Test3L() function
   1.462 +@SYMTestExpectedResults Tests must not fail
   1.463 +@SYMREQ                 REQ0000
   1.464 +*/
   1.465 +LOCAL_C void SubTest3L()
   1.466 +	{
   1.467 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0482-0001 Testing Calypso ER5u format dictionary-compressed resource files "));
   1.468 +	TBuf<128> z_path;
   1.469 +	TBuf<128> c_path;
   1.470 +
   1.471 +	z_path.Copy(KZDir);
   1.472 +	z_path.Append(rsc_files[3]);
   1.473 +	Test3L(z_path);
   1.474 +	CreateFileFromL(c_path, rsc_files[3], z_path);
   1.475 +	Test3L(c_path, KRscFileHeaderData().Length(), FileSizeL(z_path));
   1.476 +	DeleteDataFile(c_path);
   1.477 +
   1.478 +	z_path.Copy(KZDir);
   1.479 +	z_path.Append(rsc_files[5]);
   1.480 +	Test3L(z_path, FileSizeL(KRomResourceFileHeader), FileSizeL(z_path) - FileSizeL(KRomResourceFileHeader));
   1.481 +	}
   1.482 +
   1.483 +/**
   1.484 +@SYMTestCaseID          SYSLIB-BAFL-CT-0483-0001
   1.485 +@SYMTestCaseDesc        Testing resource file missing signature behaviour
   1.486 +@SYMTestPriority        High
   1.487 +@SYMTestActions         Wrapper function calling up Test4L() function
   1.488 +@SYMTestExpectedResults Tests must not fail
   1.489 +@SYMREQ                 REQ0000
   1.490 +*/
   1.491 +LOCAL_C void SubTest4L()
   1.492 +	{
   1.493 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0483-0001 Testing resource file missing signature behaviour "));
   1.494 +	TBuf<128> z_path;
   1.495 +	TBuf<128> c_path;
   1.496 +
   1.497 +	z_path.Copy(KZDir);
   1.498 +	z_path.Append(rsc_files[3]);
   1.499 +	Test4L(z_path);
   1.500 +	CreateFileFromL(c_path, rsc_files[3], z_path);
   1.501 +	Test4L(c_path, KRscFileHeaderData().Length(), FileSizeL(z_path));
   1.502 +	DeleteDataFile(c_path);
   1.503 +	}
   1.504 +
   1.505 +/**
   1.506 +@SYMTestCaseID          SYSLIB-BAFL-CT-0484-0001
   1.507 +@SYMTestCaseDesc        Testing resource file signature present and not in order behaviour
   1.508 +@SYMTestPriority        High
   1.509 +@SYMTestActions         Wrapper function calling up Test5() function
   1.510 +@SYMTestExpectedResults Tests must not fail
   1.511 +@SYMREQ                 REQ0000
   1.512 +*/
   1.513 +LOCAL_C void SubTest5L()
   1.514 +	{
   1.515 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0484-0001 Testing resource file signature present and not in order behaviour "));
   1.516 +	TBuf<128> z_path;
   1.517 +	TBuf<128> c_path;
   1.518 +
   1.519 +	z_path.Copy(KZDir);
   1.520 +	z_path.Append(rsc_files[0]);
   1.521 +	Test5L(z_path);
   1.522 +	CreateFileFromL(c_path, rsc_files[0], z_path);
   1.523 +	Test5L(c_path, KRscFileHeaderData().Length(), FileSizeL(z_path));
   1.524 +	DeleteDataFile(c_path);
   1.525 +	}
   1.526 +
   1.527 +/**
   1.528 +@SYMTestCaseID          SYSLIB-BAFL-CT-0485-0001
   1.529 +@SYMTestCaseDesc        Testing resource file signature present and in order behaviour
   1.530 +@SYMTestPriority        High
   1.531 +@SYMTestActions         Wrapper function calling up Test6L() function
   1.532 +@SYMTestExpectedResults Tests must not fail
   1.533 +@SYMREQ                 REQ0000
   1.534 +*/
   1.535 +LOCAL_C void SubTest6L()
   1.536 +	{
   1.537 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0485-0001 Testing resource file signature present and in order behaviour "));
   1.538 +	TBuf<128> z_path;
   1.539 +	TBuf<128> c_path;
   1.540 +
   1.541 +	z_path.Copy(KZDir);
   1.542 +	z_path.Append(rsc_files[1]);
   1.543 +	Test6L(z_path);
   1.544 +	CreateFileFromL(c_path, rsc_files[1], z_path);
   1.545 +	Test6L(c_path, KRscFileHeaderData().Length(), FileSizeL(z_path));
   1.546 +	DeleteDataFile(c_path);
   1.547 +	}
   1.548 +
   1.549 +/**
   1.550 +@SYMTestCaseID          SYSLIB-BAFL-CT-0486-0001
   1.551 +@SYMTestCaseDesc        Testing invalid resource file
   1.552 +@SYMTestPriority        High
   1.553 +@SYMTestActions         Wrapper function calling up Test7L() function
   1.554 +@SYMTestExpectedResults Tests must not fail
   1.555 +@SYMREQ                 REQ0000
   1.556 +*/
   1.557 +LOCAL_C void SubTest7L()
   1.558 +	{
   1.559 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0486-0001 Testing invalid resource file "));
   1.560 +	TBuf<128> z_path;
   1.561 +	TBuf<128> c_path;
   1.562 +
   1.563 +	z_path.Copy(KZDir);
   1.564 +	z_path.Append(rsc_files[4]);
   1.565 +	Test7L(z_path);
   1.566 +	CreateFileFromL(c_path, rsc_files[4], z_path);
   1.567 +	Test7L(c_path, KRscFileHeaderData().Length(), FileSizeL(z_path));
   1.568 +	DeleteDataFile(c_path);
   1.569 +	}
   1.570 +
   1.571 +/**
   1.572 +This test is for measuring the performance improvements from
   1.573 +compressed resource file dictionary cache (added DEF044572)
   1.574 +
   1.575 +@SYMTestCaseID          SYSLIB-BAFL-CT-0487-0001
   1.576 +@SYMTestCaseDesc        Tests for defect number Def044572L
   1.577 +@SYMTestPriority        High
   1.578 +@SYMTestActions         Attempt for measuring the performance improvements from compressed resource file dictionary cache
   1.579 +@SYMTestExpectedResults Tests must not fail
   1.580 +@SYMREQ                 REQ0000
   1.581 +*/
   1.582 +LOCAL_C void TestDef044572L()
   1.583 +	{
   1.584 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0487-0001 "));
   1.585 +	// measure the time taken to run this test 10 times.
   1.586 +	TTime startTime, stopTime;
   1.587 +	startTime.UniversalTime();
   1.588 +
   1.589 +	// run the test 20 times to make the time easier to measure
   1.590 +	for (TInt repeat=0;repeat<20;repeat++)
   1.591 +		{
   1.592 +		// SubTest3 which uses "Calypso ER5u format dictionary-compressed resource files"
   1.593 +		SubTest3L();
   1.594 +		}
   1.595 +
   1.596 +	// display the time taken
   1.597 +	// for WINSCW this increase from 3.4 to 1.3 seconds when the
   1.598 +	// compressed resource file dictionary cache was added DEF044572
   1.599 +	stopTime.UniversalTime();
   1.600 +	TTimeIntervalMicroSeconds timeTaken = stopTime.MicroSecondsFrom(startTime);
   1.601 +	test.Printf(_L("Time taken for Subtest3:%d microseconds\n"), timeTaken.Int64() );
   1.602 +	}
   1.603 +
   1.604 +/**
   1.605 +This test checks reading resource files for memory leaks,
   1.606 +when running Out Of Memory.(added as part of DEF044572)
   1.607 +
   1.608 +@SYMTestCaseID          SYSLIB-BAFL-CT-0488-0001
   1.609 +@SYMTestCaseDesc        Out of memory tests
   1.610 +@SYMTestPriority        High
   1.611 +@SYMTestActions         Tests for memory leaks while reading resource files.
   1.612 +@SYMTestExpectedResults Tests must not fail
   1.613 +@SYMREQ                 REQ0000
   1.614 +*/
   1.615 +LOCAL_C void MemoryLeakTestL()
   1.616 +	{
   1.617 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0488-0001 "));
   1.618 +	TInt ret = KErrNoMemory;
   1.619 +	TInt pass = 1;
   1.620 +
   1.621 +	__UHEAP_MARK;
   1.622 +	// increasing the value of pass until the test completes with KErrNone
   1.623 +	while  (ret != KErrNone )
   1.624 +		{
   1.625 +		// check that the test is failing with KErrNoMemory
   1.626 +		test(ret==KErrNoMemory);
   1.627 +
   1.628 +		__UHEAP_FAILNEXT(pass);
   1.629 +		TRAP(ret, SubTest3L());
   1.630 +		__UHEAP_CHECK(0);
   1.631 +
   1.632 +		pass++;
   1.633 +		}
   1.634 +
   1.635 +	// disable the heap fail
   1.636 +	__UHEAP_RESET;
   1.637 +	__UHEAP_MARKEND;
   1.638 +
   1.639 +	}
   1.640 +
   1.641 +
   1.642 +LOCAL_C void DoE32MainL()
   1.643 +	{
   1.644 +	CleanupClosePushL(fileServerSession);
   1.645 +	User::LeaveIfError(fileServerSession.Connect());
   1.646 +
   1.647 +	SubTest1L();
   1.648 +	SubTest2L();
   1.649 +	SubTest3L();
   1.650 +	SubTest4L();
   1.651 +	SubTest5L();
   1.652 +	SubTest6L();
   1.653 +	SubTest7L();
   1.654 +	TestDef044572L();
   1.655 +	MemoryLeakTestL();
   1.656 +
   1.657 +	CleanupStack::PopAndDestroy(1, &fileServerSession);
   1.658 +	}
   1.659 +
   1.660 +GLDEF_C TInt E32Main()
   1.661 +	{
   1.662 +	__UHEAP_MARK;
   1.663 +	CTrapCleanup* trapCleanup=CTrapCleanup::New();
   1.664 +	TRAPD(error, DoE32MainL());
   1.665 +	test(error == KErrNone);
   1.666 +	test.Next(_L("/n"));
   1.667 +	test.End();
   1.668 +	test.Close();
   1.669 +	delete trapCleanup;
   1.670 +	__UHEAP_MARKEND;
   1.671 +	return error;
   1.672 +	}
   1.673 +