os/ossrv/lowlevellibsandfws/apputils/tsrc/T_RESOURCE_COMPRESSION.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2001-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
//
sl@0
    15
sl@0
    16
#include <e32std.h>
sl@0
    17
#include <e32base.h>
sl@0
    18
#include <e32test.h>
sl@0
    19
#include <f32file.h>
sl@0
    20
#include <bautils.h>
sl@0
    21
#include <barsc.h>
sl@0
    22
#include <barsread.h>
sl@0
    23
#include <t_compressed_unicode_1.rsg>
sl@0
    24
#include <t_compressed_unicode_2.rsg>
sl@0
    25
sl@0
    26
RTest test=_L("T_RESOURCE_COMPRESSION");
sl@0
    27
RFs fileServerSession;
sl@0
    28
_LIT8(KRscFileHeaderData, "0123456789ABCDEF");
sl@0
    29
_LIT(KRomResourceFileHeader, "z:\\system\\data\\RscHeader.bin");
sl@0
    30
sl@0
    31
LOCAL_D const TPtrC rsc_files[] =
sl@0
    32
	{
sl@0
    33
	  _L("T_COMPRESSED_UNICODE_1.RSC")
sl@0
    34
	, _L("T_COMPRESSED_UNICODE_2.RSC")
sl@0
    35
	, _L("T_DICTIONARY_COMPRESSED_VERSIO_OF_2.RSC")
sl@0
    36
	, _L("T_CALYPSO_TEST_RESOURCE_FILE_1.RSC")
sl@0
    37
	, _L("T_NotRscFile.RSC")
sl@0
    38
	, _L("TRscROMCalypsoComprNewFmt.rsc")
sl@0
    39
	};
sl@0
    40
_LIT(KZDir, "z:\\system\\data\\");
sl@0
    41
_LIT(KCDir, "c:\\");
sl@0
    42
sl@0
    43
LOCAL_C void DeleteDataFile(const TDesC& aFullName)
sl@0
    44
	{
sl@0
    45
	// make sure the file is read/write
sl@0
    46
	TInt err = fileServerSession.SetAtt(aFullName,0, KEntryAttReadOnly);
sl@0
    47
	if(err != KErrNone)
sl@0
    48
		{
sl@0
    49
		RDebug::Print(_L("error changing attributes file = %d"),err);
sl@0
    50
		}
sl@0
    51
	// delete the file
sl@0
    52
	err = BaflUtils::DeleteFile(fileServerSession, aFullName);
sl@0
    53
	if(err != KErrNone)
sl@0
    54
		{
sl@0
    55
		RDebug::Print(_L("error deleting file = %d"),err);
sl@0
    56
		}
sl@0
    57
	}
sl@0
    58
sl@0
    59
LOCAL_C TInt FileSizeL(const TDesC& aFileName)
sl@0
    60
	{
sl@0
    61
	RFile file;
sl@0
    62
	User::LeaveIfError(file.Open(fileServerSession, aFileName, EFileRead));
sl@0
    63
	CleanupClosePushL(file);
sl@0
    64
	TInt size = 0;
sl@0
    65
	User::LeaveIfError(file.Size(size));
sl@0
    66
	CleanupStack::PopAndDestroy(&file);
sl@0
    67
	return size;
sl@0
    68
	}
sl@0
    69
sl@0
    70
LOCAL_C void CreateFileFromL(const TDesC& aDestFileName, const TDesC& aSrcFileName)
sl@0
    71
	{
sl@0
    72
	RFile destFile;
sl@0
    73
	RFile srcFile;
sl@0
    74
sl@0
    75
	CleanupClosePushL(destFile);
sl@0
    76
	CleanupClosePushL(srcFile);
sl@0
    77
sl@0
    78
	BaflUtils::DeleteFile(fileServerSession, aDestFileName);
sl@0
    79
	User::LeaveIfError(destFile.Create(fileServerSession, aDestFileName, EFileRead | EFileWrite));
sl@0
    80
sl@0
    81
	User::LeaveIfError(srcFile.Open(fileServerSession, aSrcFileName, EFileRead));
sl@0
    82
	TInt size = 0;
sl@0
    83
	User::LeaveIfError(srcFile.Size(size));
sl@0
    84
	HBufC8* buf = HBufC8::NewMaxLC(size);
sl@0
    85
	TPtr8 ptr = buf->Des();
sl@0
    86
	srcFile.Read(ptr);
sl@0
    87
sl@0
    88
	destFile.Write(KRscFileHeaderData);
sl@0
    89
	destFile.Write(ptr);
sl@0
    90
sl@0
    91
	CleanupStack::PopAndDestroy(buf);
sl@0
    92
	CleanupStack::PopAndDestroy(&srcFile);
sl@0
    93
	CleanupStack::PopAndDestroy(&destFile);
sl@0
    94
	}
sl@0
    95
sl@0
    96
LOCAL_C void CreateFileFromL(TDes& aDestFilePath, const TDesC& aDestFileName, const TDesC& aSrcFilePath)
sl@0
    97
	{
sl@0
    98
	aDestFilePath.Copy(KCDir);
sl@0
    99
	aDestFilePath += _L("N_");
sl@0
   100
	aDestFilePath += aDestFileName;
sl@0
   101
	CreateFileFromL(aDestFilePath, aSrcFilePath);
sl@0
   102
	}
sl@0
   103
sl@0
   104
/**
sl@0
   105
@SYMTestCaseID          SYSLIB-BAFL-CT-0451
sl@0
   106
@SYMTestCaseDesc        RResourceReader class functionality test
sl@0
   107
@SYMTestPriority        High
sl@0
   108
@SYMTestActions         Tests for reading descriptors,integers
sl@0
   109
@SYMTestExpectedResults Tests must not fail
sl@0
   110
@SYMREQ                 REQ0000
sl@0
   111
*/
sl@0
   112
LOCAL_C void Test1(const TDesC& aResourceFileName, TUint aFileOffset = 0, TInt aFileSize = 0)
sl@0
   113
	{
sl@0
   114
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0451 "));
sl@0
   115
	RResourceFile resourceFile;
sl@0
   116
	CleanupClosePushL(resourceFile);
sl@0
   117
	resourceFile.OpenL(fileServerSession, aResourceFileName, aFileOffset, aFileSize);
sl@0
   118
	test(resourceFile.UidType()==TUidType(TUid::Uid(0x101f4a6b), TUid::Uid(0x000eb205), TUid::Uid(TUint(T_COMPRESSED_UNICODE_1_RESOURCE_1)>>12)));
sl@0
   119
	HBufC8* resource;
sl@0
   120
	TResourceReader resourceReader;
sl@0
   121
sl@0
   122
	resource=resourceFile.AllocReadLC(1);
sl@0
   123
	test(resource->Length()%sizeof(TText)==0);
sl@0
   124
	test(TPtrC((TText*)resource->Ptr(), resource->Length()/sizeof(TText))==_L("Gruezi miteinander"));
sl@0
   125
	CleanupStack::PopAndDestroy(resource);
sl@0
   126
sl@0
   127
	resource=resourceFile.AllocReadLC(2);
sl@0
   128
	resourceReader.SetBuffer(resource);
sl@0
   129
	test(resourceReader.ReadUint16()==4);
sl@0
   130
	test(resourceReader.ReadTPtrC()==_L("Bonjour"));
sl@0
   131
	test(resourceReader.ReadTPtrC()==_L("Ni3 hao3"));
sl@0
   132
	test(resourceReader.ReadTPtrC()==_L("Konnichiwa"));
sl@0
   133
	test(resourceReader.ReadTPtrC()==_L("Zdravstvuit'e"));
sl@0
   134
	CleanupStack::PopAndDestroy(resource);
sl@0
   135
sl@0
   136
	resource=resourceFile.AllocReadLC(3);
sl@0
   137
	resourceReader.SetBuffer(resource);
sl@0
   138
	test(resourceReader.ReadUint16()==3);
sl@0
   139
	test(resourceReader.ReadTPtrC()==_L("Gamarjoba"));
sl@0
   140
	test(resourceReader.ReadTPtrC()==_L("Gasou"));
sl@0
   141
	test(resourceReader.ReadTPtrC()==_L("Ola"));
sl@0
   142
	CleanupStack::PopAndDestroy(resource);
sl@0
   143
sl@0
   144
	resource=resourceFile.AllocReadLC(4);
sl@0
   145
	resourceReader.SetBuffer(resource);
sl@0
   146
	test(resourceReader.ReadUint16()==3);
sl@0
   147
	test(resourceReader.ReadUint8()==0xbd);
sl@0
   148
	test(resourceReader.ReadUint8()==0x5e);
sl@0
   149
	test(resourceReader.ReadUint8()==0xf1);
sl@0
   150
	CleanupStack::PopAndDestroy(resource);
sl@0
   151
sl@0
   152
	resource=resourceFile.AllocReadLC(5);
sl@0
   153
	resourceReader.SetBuffer(resource);
sl@0
   154
	test(resourceReader.ReadUint32()==4);
sl@0
   155
	test(resourceReader.ReadUint32()==T_COMPRESSED_UNICODE_1_RESOURCE_5);
sl@0
   156
	CleanupStack::PopAndDestroy(resource);
sl@0
   157
sl@0
   158
	resource=resourceFile.AllocReadLC(6);
sl@0
   159
	test(resource->Length()%sizeof(TText)==0);
sl@0
   160
	test(TPtrC((TText*)resource->Ptr(), resource->Length()/sizeof(TText))==_L("_"));
sl@0
   161
	CleanupStack::PopAndDestroy(resource);
sl@0
   162
sl@0
   163
	resource=resourceFile.AllocReadLC(7);
sl@0
   164
	resourceReader.SetBuffer(resource);
sl@0
   165
	test(resourceReader.ReadUint8()==9);
sl@0
   166
	test(resourceReader.ReadTPtrC()==_L("To"));
sl@0
   167
	test(resourceReader.ReadUint8()==97);
sl@0
   168
	CleanupStack::PopAndDestroy(resource);
sl@0
   169
sl@0
   170
	resource=resourceFile.AllocReadLC(8);
sl@0
   171
	resourceReader.SetBuffer(resource);
sl@0
   172
	test(resourceReader.ReadUint16()==999);
sl@0
   173
	test(resourceReader.ReadTPtrC()==_L("To"));
sl@0
   174
	test(resourceReader.ReadUint8()==79);
sl@0
   175
	CleanupStack::PopAndDestroy(resource);
sl@0
   176
sl@0
   177
	resource=resourceFile.AllocReadLC(9);
sl@0
   178
	resourceReader.SetBuffer(resource);
sl@0
   179
	test(resourceReader.ReadUint16()==53132);
sl@0
   180
	test(resourceReader.ReadTPtrC()==_L("T"));
sl@0
   181
	test(resourceReader.ReadUint8()==62);
sl@0
   182
	CleanupStack::PopAndDestroy(resource);
sl@0
   183
sl@0
   184
	resource=resourceFile.AllocReadLC(10);
sl@0
   185
	resourceReader.SetBuffer(resource);
sl@0
   186
	test(resourceReader.ReadInt32()==1253869);
sl@0
   187
	test(resourceReader.ReadInt32()==-986324);
sl@0
   188
	test(resourceReader.ReadUint32()==0x600ddea1u);
sl@0
   189
	CleanupStack::PopAndDestroy(resource);
sl@0
   190
sl@0
   191
	CleanupStack::PopAndDestroy(&resourceFile);
sl@0
   192
	}
sl@0
   193
sl@0
   194
/**
sl@0
   195
@SYMTestCaseID          SYSLIB-BAFL-CT-0452
sl@0
   196
@SYMTestCaseDesc        RResourceReader class test
sl@0
   197
                        Tests for RResourceReader::UidType() function
sl@0
   198
@SYMTestPriority        High
sl@0
   199
@SYMTestActions         Tests for reading compressed unicode
sl@0
   200
@SYMTestExpectedResults Tests must not fail
sl@0
   201
@SYMREQ                 REQ0000
sl@0
   202
*/
sl@0
   203
LOCAL_C void Test2(const TDesC& aResourceFileName, TUid aFirstUid, TUint aFileOffset = 0, TInt aFileSize = 0)
sl@0
   204
	{
sl@0
   205
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0452 "));
sl@0
   206
	RResourceFile resourceFile;
sl@0
   207
	CleanupClosePushL(resourceFile);
sl@0
   208
	resourceFile.OpenL(fileServerSession, aResourceFileName, aFileOffset, aFileSize);
sl@0
   209
	test(resourceFile.UidType()==TUidType(aFirstUid, TUid::Null(), TUid::Uid(TUint(T_COMPRESSED_UNICODE_2_RESOURCE_1)>>12)));
sl@0
   210
	HBufC8* resource;
sl@0
   211
	TResourceReader resourceReader;
sl@0
   212
sl@0
   213
	resource=resourceFile.AllocReadLC(1);
sl@0
   214
	resourceReader.SetBuffer(resource);
sl@0
   215
	test(resourceReader.ReadUint32()==4);
sl@0
   216
	test(resourceReader.ReadUint32()==T_COMPRESSED_UNICODE_2_RESOURCE_1);
sl@0
   217
	CleanupStack::PopAndDestroy(resource);
sl@0
   218
sl@0
   219
	resource=resourceFile.AllocReadLC(2);
sl@0
   220
	test(resource->Length()%sizeof(TText)==0);
sl@0
   221
	test(TPtrC((TText*)resource->Ptr(), resource->Length()/sizeof(TText))==_L("My program is cool"));
sl@0
   222
	CleanupStack::PopAndDestroy(resource);
sl@0
   223
sl@0
   224
	resource=resourceFile.AllocReadLC(3);
sl@0
   225
	test(resource->Length()%sizeof(TText)==0);
sl@0
   226
	test(TPtrC((TText*)resource->Ptr(), resource->Length()/sizeof(TText))==_L("z:\\system\\data\\eikon.mbm"));
sl@0
   227
	CleanupStack::PopAndDestroy(resource);
sl@0
   228
sl@0
   229
	resource=resourceFile.AllocReadLC(4);
sl@0
   230
	resourceReader.SetBuffer(resource);
sl@0
   231
	test(resourceReader.ReadInt32()==9174804);
sl@0
   232
	test(resourceReader.ReadUint8()==6);
sl@0
   233
	test(resourceReader.ReadInt32()==-6208493);
sl@0
   234
	test(resourceReader.ReadUint16()==0x3176);
sl@0
   235
	CleanupStack::PopAndDestroy(resource);
sl@0
   236
sl@0
   237
	resource=resourceFile.AllocReadLC(5);
sl@0
   238
	resourceReader.SetBuffer(resource);
sl@0
   239
	test(resourceReader.ReadInt32()==-120727);
sl@0
   240
	test(resourceReader.ReadInt32()==-82385253);
sl@0
   241
	test(resourceReader.ReadUint16()==0x3176);
sl@0
   242
	CleanupStack::PopAndDestroy(resource);
sl@0
   243
sl@0
   244
	resource=resourceFile.AllocReadLC(6);
sl@0
   245
	resourceReader.SetBuffer(resource);
sl@0
   246
	test(resourceReader.ReadUint8()==2);
sl@0
   247
	test(resourceReader.ReadTPtrC()==_L("z:\\system\\data\\uikon.mbm"));
sl@0
   248
	test(resourceReader.ReadTPtrC()==_L("z:\\system\\apps\\my_program\\my_program.mbm"));
sl@0
   249
	CleanupStack::PopAndDestroy(resource);
sl@0
   250
sl@0
   251
	CleanupStack::PopAndDestroy(&resourceFile);
sl@0
   252
	}
sl@0
   253
sl@0
   254
/**
sl@0
   255
@SYMTestCaseID          SYSLIB-BAFL-CT-0453
sl@0
   256
@SYMTestCaseDesc        RResourceReader class test
sl@0
   257
						Tests the calypso resource file format for loading and reading
sl@0
   258
@SYMTestPriority        High
sl@0
   259
@SYMTestActions         Tests for reading calypso resource file format
sl@0
   260
@SYMTestExpectedResults Tests must not fail
sl@0
   261
@SYMREQ                 REQ0000
sl@0
   262
*/
sl@0
   263
LOCAL_C void Test3(const TDesC& aResourceFileName, TUint aFileOffset = 0, TInt aFileSize = 0)
sl@0
   264
	{
sl@0
   265
	/* This function tests the calypso resoruce file format loading/reading
sl@0
   266
	 * and was derived from the Test1 function above. Therefore the resource
sl@0
   267
	 * file it reads is also derived from the file used in test 1.
sl@0
   268
	 */
sl@0
   269
sl@0
   270
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0453 "));
sl@0
   271
	RResourceFile resourceFile;
sl@0
   272
	CleanupClosePushL(resourceFile);
sl@0
   273
	resourceFile.OpenL(fileServerSession, aResourceFileName, aFileOffset, aFileSize);
sl@0
   274
	HBufC8* resource;
sl@0
   275
	TResourceReader resourceReader;
sl@0
   276
sl@0
   277
	resource=resourceFile.AllocReadLC(1);
sl@0
   278
	test(resource->Length()%sizeof(TText)==0);
sl@0
   279
	test(TPtrC((TText*)resource->Ptr(), resource->Length()/sizeof(TText))==_L("Gruezi miteinander"));
sl@0
   280
	CleanupStack::PopAndDestroy(resource);
sl@0
   281
sl@0
   282
	resource=resourceFile.AllocReadLC(2);
sl@0
   283
	resourceReader.SetBuffer(resource);
sl@0
   284
	test(resourceReader.ReadUint16()==4);
sl@0
   285
	test(resourceReader.ReadTPtrC()==_L("Bonjour"));
sl@0
   286
	test(resourceReader.ReadTPtrC()==_L("Ni3 hao3"));
sl@0
   287
	test(resourceReader.ReadTPtrC()==_L("Konnichiwa"));
sl@0
   288
	test(resourceReader.ReadTPtrC()==_L("Zdravstvuit'e"));
sl@0
   289
	CleanupStack::PopAndDestroy(resource);
sl@0
   290
sl@0
   291
	resource=resourceFile.AllocReadLC(3);
sl@0
   292
	resourceReader.SetBuffer(resource);
sl@0
   293
	test(resourceReader.ReadUint16()==3);
sl@0
   294
	test(resourceReader.ReadTPtrC()==_L("Gamarjoba"));
sl@0
   295
	test(resourceReader.ReadTPtrC()==_L("Gasou"));
sl@0
   296
	test(resourceReader.ReadTPtrC()==_L("Ola"));
sl@0
   297
	CleanupStack::PopAndDestroy(resource);
sl@0
   298
sl@0
   299
	resource=resourceFile.AllocReadLC(4);
sl@0
   300
	resourceReader.SetBuffer(resource);
sl@0
   301
	test(resourceReader.ReadUint16()==3);
sl@0
   302
	test(resourceReader.ReadUint8()==0xbd);
sl@0
   303
	test(resourceReader.ReadUint8()==0x5e);
sl@0
   304
	test(resourceReader.ReadUint8()==0xf1);
sl@0
   305
	CleanupStack::PopAndDestroy(resource);
sl@0
   306
sl@0
   307
	resource=resourceFile.AllocReadLC(5);
sl@0
   308
	resourceReader.SetBuffer(resource);
sl@0
   309
	test(resourceReader.ReadUint32()==4);
sl@0
   310
	test(resourceReader.ReadUint32()==T_COMPRESSED_UNICODE_1_RESOURCE_5);
sl@0
   311
	CleanupStack::PopAndDestroy(resource);
sl@0
   312
sl@0
   313
	resource=resourceFile.AllocReadLC(6);
sl@0
   314
	test(resource->Length()%sizeof(TText)==0);
sl@0
   315
	test(TPtrC((TText*)resource->Ptr(), resource->Length()/sizeof(TText))==_L("_"));
sl@0
   316
	CleanupStack::PopAndDestroy(resource);
sl@0
   317
sl@0
   318
	resource=resourceFile.AllocReadLC(7);
sl@0
   319
	resourceReader.SetBuffer(resource);
sl@0
   320
	test(resourceReader.ReadUint8()==9);
sl@0
   321
	test(resourceReader.ReadTPtrC()==_L("To"));
sl@0
   322
	test(resourceReader.ReadUint8()==97);
sl@0
   323
	CleanupStack::PopAndDestroy(resource);
sl@0
   324
sl@0
   325
	resource=resourceFile.AllocReadLC(8);
sl@0
   326
	resourceReader.SetBuffer(resource);
sl@0
   327
	test(resourceReader.ReadUint16()==999);
sl@0
   328
	test(resourceReader.ReadTPtrC()==_L("To"));
sl@0
   329
	test(resourceReader.ReadUint8()==79);
sl@0
   330
	CleanupStack::PopAndDestroy(resource);
sl@0
   331
sl@0
   332
	resource=resourceFile.AllocReadLC(9);
sl@0
   333
	resourceReader.SetBuffer(resource);
sl@0
   334
	test(resourceReader.ReadUint16()==53132);
sl@0
   335
	test(resourceReader.ReadTPtrC()==_L("T"));
sl@0
   336
	test(resourceReader.ReadUint8()==62);
sl@0
   337
	CleanupStack::PopAndDestroy(resource);
sl@0
   338
sl@0
   339
	resource=resourceFile.AllocReadLC(10);
sl@0
   340
	resourceReader.SetBuffer(resource);
sl@0
   341
	test(resourceReader.ReadInt32()==1253869);
sl@0
   342
	test(resourceReader.ReadInt32()==-986324);
sl@0
   343
	test(resourceReader.ReadUint32()==0x600ddea1u);
sl@0
   344
	CleanupStack::PopAndDestroy(resource);
sl@0
   345
sl@0
   346
	CleanupStack::PopAndDestroy(&resourceFile);
sl@0
   347
	}
sl@0
   348
sl@0
   349
/**
sl@0
   350
@SYMTestCaseID          SYSLIB-BAFL-CT-0454
sl@0
   351
@SYMTestCaseDesc        Tests for reading calypso resource file for signature.
sl@0
   352
						Calypso resource files do not have signatures.
sl@0
   353
@SYMTestPriority        High
sl@0
   354
@SYMTestActions         Tests for RResourceFile::ConfirmSignatureL() function
sl@0
   355
@SYMTestExpectedResults Tests must not fail
sl@0
   356
@SYMREQ                 REQ0000
sl@0
   357
*/
sl@0
   358
LOCAL_C void Test4(const TDesC& aResourceFileName, TUint aFileOffset = 0, TInt aFileSize = 0)
sl@0
   359
	{
sl@0
   360
	/* This function tests the behaviour of bafl when reading a calypso resource file
sl@0
   361
	 * for a signature. Calypso resource files do not have signatures.
sl@0
   362
	 */
sl@0
   363
sl@0
   364
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0454 "));
sl@0
   365
	RResourceFile resourceFile;
sl@0
   366
	CleanupClosePushL(resourceFile);
sl@0
   367
	resourceFile.OpenL(fileServerSession, aResourceFileName, aFileOffset, aFileSize);
sl@0
   368
sl@0
   369
	// Need to pass the TInt as required, but doesn't
sl@0
   370
	// use it. Legacy for BC sake.
sl@0
   371
	TInt err = KErrNone;
sl@0
   372
	TRAP(err, resourceFile.ConfirmSignatureL(1));
sl@0
   373
	test(err == KErrCorrupt);
sl@0
   374
sl@0
   375
	// New function that has further test to confirm absence of signature
sl@0
   376
	// Hopefully we can get clients to move over to this in future.
sl@0
   377
	TRAP(err, resourceFile.ConfirmSignatureL());
sl@0
   378
	test(err == KErrCorrupt);
sl@0
   379
sl@0
   380
	CleanupStack::PopAndDestroy(&resourceFile);
sl@0
   381
	}
sl@0
   382
sl@0
   383
/**
sl@0
   384
@SYMTestCaseID          SYSLIB-BAFL-CT-0456
sl@0
   385
@SYMTestCaseDesc        Tests the behaviour of BAFL when reading a resource file for a signature.
sl@0
   386
@SYMTestPriority        High
sl@0
   387
@SYMTestActions         Tests for reading a resource file for signature.
sl@0
   388
						In this case the signature is present and is NOT the first resource.
sl@0
   389
@SYMTestExpectedResults Tests must not fail
sl@0
   390
@SYMREQ                 REQ0000
sl@0
   391
*/
sl@0
   392
LOCAL_C void Test5(const TDesC& aResourceFileName, TUint aFileOffset = 0, TInt aFileSize = 0)
sl@0
   393
	{
sl@0
   394
	/* This function tests the behaviour of bafl when reading a resource file
sl@0
   395
	 * for a signature.
sl@0
   396
	 * In this case the signature is present and is NOT the first resource.
sl@0
   397
	 */
sl@0
   398
sl@0
   399
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0456 "));
sl@0
   400
	RResourceFile resourceFile;
sl@0
   401
	CleanupClosePushL(resourceFile);
sl@0
   402
	resourceFile.OpenL(fileServerSession, aResourceFileName, aFileOffset, aFileSize);
sl@0
   403
sl@0
   404
	// Need to pass the TInt as required, but doesn't
sl@0
   405
	// use it. Legacy for BC sake.
sl@0
   406
	TInt err = KErrNone;
sl@0
   407
	TRAP(err, resourceFile.ConfirmSignatureL(1));
sl@0
   408
	test(err == KErrCorrupt);
sl@0
   409
sl@0
   410
	// New function that has further test to confirm absence of signature
sl@0
   411
	// Hopefully we can get clients to move over to this in future.
sl@0
   412
	TRAP(err, resourceFile.ConfirmSignatureL());
sl@0
   413
	test(err == KErrCorrupt);
sl@0
   414
sl@0
   415
	CleanupStack::PopAndDestroy(&resourceFile);
sl@0
   416
	}
sl@0
   417
sl@0
   418
/**
sl@0
   419
@SYMTestCaseID          SYSLIB-BAFL-CT-0457
sl@0
   420
@SYMTestCaseDesc        Tests the behaviour of BAFL when reading a resource file for a signature.
sl@0
   421
						The signature is present and is the first resource.
sl@0
   422
@SYMTestPriority        High
sl@0
   423
@SYMTestActions         Tests for RResourceFile::ConfirmSignatureL() function
sl@0
   424
@SYMTestExpectedResults Tests must not fail
sl@0
   425
@SYMREQ                 REQ0000
sl@0
   426
*/
sl@0
   427
LOCAL_C void Test6(const TDesC& aResourceFileName, TUint aFileOffset = 0, TInt aFileSize = 0)
sl@0
   428
	{
sl@0
   429
	/* This function tests the behaviour of bafl when reading a resource file
sl@0
   430
	 * for a signature.
sl@0
   431
	 * In this case the signature is present and is the first resource.
sl@0
   432
	 */
sl@0
   433
sl@0
   434
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0457 "));
sl@0
   435
	RResourceFile resourceFile;
sl@0
   436
	CleanupClosePushL(resourceFile);
sl@0
   437
	resourceFile.OpenL(fileServerSession, aResourceFileName, aFileOffset, aFileSize);
sl@0
   438
sl@0
   439
	// Need to pass the TInt as required, but doesn't
sl@0
   440
	// use it. Legacy for BC sake.
sl@0
   441
	TInt err = KErrNone;
sl@0
   442
	TRAP(err, resourceFile.ConfirmSignatureL(1));
sl@0
   443
	test(err == KErrNone);
sl@0
   444
sl@0
   445
	// New function that has further test to confirm absence of signature
sl@0
   446
	// Hopefully we can get clients to move over to this in future.
sl@0
   447
	TRAP(err, resourceFile.ConfirmSignatureL());
sl@0
   448
	test(err == KErrNone);
sl@0
   449
sl@0
   450
	CleanupStack::PopAndDestroy(&resourceFile);
sl@0
   451
	}
sl@0
   452
sl@0
   453
/**
sl@0
   454
@SYMTestCaseID          SYSLIB-BAFL-CT-0458
sl@0
   455
@SYMTestCaseDesc        Tests the behaviour of BAFL when reading a non resource file
sl@0
   456
@SYMTestPriority        High
sl@0
   457
@SYMTestActions         Attempt to open a non resource file.
sl@0
   458
@SYMTestExpectedResults Tests must not fail
sl@0
   459
@SYMREQ                 REQ0000
sl@0
   460
*/
sl@0
   461
LOCAL_C void Test7(const TDesC& aResourceFileName, TUint aFileOffset = 0, TInt aFileSize = 0)
sl@0
   462
	{
sl@0
   463
	/* This function tests the behaviour of bafl when reading a non resource file.
sl@0
   464
	 */
sl@0
   465
sl@0
   466
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0458 "));
sl@0
   467
	RResourceFile resourceFile;
sl@0
   468
	CleanupClosePushL(resourceFile);
sl@0
   469
sl@0
   470
	// Need to pass the TInt as required, but doesn't
sl@0
   471
	// use it. Legacy for BC sake.
sl@0
   472
	TInt err = KErrNone;
sl@0
   473
sl@0
   474
	TRAP(err, resourceFile.OpenL(fileServerSession, aResourceFileName, aFileOffset, aFileSize));
sl@0
   475
	test(err != KErrNotFound && err != KErrNone);
sl@0
   476
sl@0
   477
	CleanupStack::PopAndDestroy(&resourceFile);
sl@0
   478
	}
sl@0
   479
sl@0
   480
/**
sl@0
   481
@SYMTestCaseID          SYSLIB-BAFL-CT-0459
sl@0
   482
@SYMTestCaseDesc        Tests resource files containing Unicode-compressed text
sl@0
   483
@SYMTestPriority        High
sl@0
   484
@SYMTestActions         Calls up Test1() and Test2() functions
sl@0
   485
@SYMTestExpectedResults Test must not fail
sl@0
   486
@SYMREQ                 REQ0000
sl@0
   487
*/
sl@0
   488
LOCAL_C void SubTest1L()
sl@0
   489
	{
sl@0
   490
	test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0459 Testing resource files containing Unicode-compressed text "));
sl@0
   491
	TBuf<128> z_path;
sl@0
   492
	TBuf<128> c_path;
sl@0
   493
sl@0
   494
	z_path.Copy(KZDir);
sl@0
   495
	z_path += rsc_files[0];
sl@0
   496
	Test1(z_path);
sl@0
   497
	CreateFileFromL(c_path, rsc_files[0], z_path);
sl@0
   498
	Test1(c_path, KRscFileHeaderData().Length(), FileSizeL(z_path));
sl@0
   499
	DeleteDataFile(c_path);
sl@0
   500
sl@0
   501
	z_path.Copy(KZDir);
sl@0
   502
	z_path.Append(rsc_files[1]);
sl@0
   503
	Test2(z_path, TUid::Uid(0x101f4a6b));
sl@0
   504
	CreateFileFromL(c_path, rsc_files[1], z_path);
sl@0
   505
	Test2(c_path, TUid::Uid(0x101f4a6b), KRscFileHeaderData().Length(), FileSizeL(z_path));
sl@0
   506
	DeleteDataFile(c_path);
sl@0
   507
	}
sl@0
   508
sl@0
   509
/**
sl@0
   510
@SYMTestCaseID          SYSLIB-BAFL-CT-0460
sl@0
   511
@SYMTestCaseDesc        Tests for dictionary-compressed resource files
sl@0
   512
@SYMTestPriority        High
sl@0
   513
@SYMTestActions         Check by reading the dictionary-compressed resource files
sl@0
   514
@SYMTestExpectedResults Test must not fail
sl@0
   515
@SYMREQ                 REQ0000
sl@0
   516
*/
sl@0
   517
LOCAL_C void SubTest2L()
sl@0
   518
	{
sl@0
   519
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0460 Testing dictionary-compressed resource files "));
sl@0
   520
	TBuf<128> z_path;
sl@0
   521
	TBuf<128> c_path;
sl@0
   522
sl@0
   523
	z_path.Copy(KZDir);
sl@0
   524
	z_path.Append(rsc_files[2]);
sl@0
   525
	Test2(z_path, TUid::Uid(0x101f5010));
sl@0
   526
	CreateFileFromL(c_path, rsc_files[2], z_path);
sl@0
   527
	Test2(c_path, TUid::Uid(0x101f5010), KRscFileHeaderData().Length(), FileSizeL(z_path));
sl@0
   528
	DeleteDataFile(c_path);
sl@0
   529
	}
sl@0
   530
sl@0
   531
/**
sl@0
   532
@SYMTestCaseID          SYSLIB-BAFL-CT-0461
sl@0
   533
@SYMTestCaseDesc        Tests for reading the Calypso ER5u format dictionary-compressed resource files
sl@0
   534
@SYMTestPriority        High
sl@0
   535
@SYMTestActions         Wrapper function calling up Test3() function
sl@0
   536
@SYMTestExpectedResults Test must not fail
sl@0
   537
@SYMREQ                 REQ0000
sl@0
   538
*/
sl@0
   539
LOCAL_C void SubTest3L()
sl@0
   540
	{
sl@0
   541
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0461 Testing Calypso ER5u format dictionary-compressed resource files "));
sl@0
   542
	TBuf<128> z_path;
sl@0
   543
	TBuf<128> c_path;
sl@0
   544
sl@0
   545
	z_path.Copy(KZDir);
sl@0
   546
	z_path.Append(rsc_files[3]);
sl@0
   547
sl@0
   548
	Test3(z_path);
sl@0
   549
	CreateFileFromL(c_path, rsc_files[3], z_path);
sl@0
   550
	Test3(c_path, KRscFileHeaderData().Length(), FileSizeL(z_path));
sl@0
   551
	DeleteDataFile(c_path);
sl@0
   552
sl@0
   553
	z_path.Copy(KZDir);
sl@0
   554
	z_path.Append(rsc_files[5]);
sl@0
   555
	Test3(z_path, FileSizeL(KRomResourceFileHeader), FileSizeL(z_path) - FileSizeL(KRomResourceFileHeader));
sl@0
   556
	}
sl@0
   557
sl@0
   558
/**
sl@0
   559
@SYMTestCaseID          SYSLIB-BAFL-CT-0462
sl@0
   560
@SYMTestCaseDesc        Tests for resource file missing signature behaviour
sl@0
   561
@SYMTestPriority        High
sl@0
   562
@SYMTestActions         Wrapper function calling up Test4() function
sl@0
   563
@SYMTestExpectedResults Test must not fail
sl@0
   564
@SYMREQ                 REQ0000
sl@0
   565
*/
sl@0
   566
LOCAL_C void SubTest4L()
sl@0
   567
	{
sl@0
   568
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0462 Testing resource file missing signature behaviour "));
sl@0
   569
	TBuf<128> z_path;
sl@0
   570
	TBuf<128> c_path;
sl@0
   571
sl@0
   572
	z_path.Copy(KZDir);
sl@0
   573
	z_path.Append(rsc_files[3]);
sl@0
   574
sl@0
   575
	Test4(z_path);
sl@0
   576
	CreateFileFromL(c_path, rsc_files[3], z_path);
sl@0
   577
	Test4(c_path, KRscFileHeaderData().Length(), FileSizeL(z_path));
sl@0
   578
	DeleteDataFile(c_path);
sl@0
   579
	}
sl@0
   580
sl@0
   581
/**
sl@0
   582
@SYMTestCaseID          SYSLIB-BAFL-CT-0463
sl@0
   583
@SYMTestCaseDesc        Testing resource file signature present and not in order behaviour
sl@0
   584
@SYMTestPriority        High
sl@0
   585
@SYMTestActions         Wrapper function calling up Test5() function
sl@0
   586
@SYMTestExpectedResults Test must not fail
sl@0
   587
@SYMREQ                 REQ0000
sl@0
   588
*/
sl@0
   589
LOCAL_C void SubTest5L()
sl@0
   590
	{
sl@0
   591
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0463 Testing resource file signature present and not in order behaviour "));
sl@0
   592
	TBuf<128> z_path;
sl@0
   593
	TBuf<128> c_path;
sl@0
   594
sl@0
   595
	z_path.Copy(KZDir);
sl@0
   596
	z_path.Append(rsc_files[0]);
sl@0
   597
sl@0
   598
	Test5(z_path);
sl@0
   599
	CreateFileFromL(c_path, rsc_files[0], z_path);
sl@0
   600
	Test5(c_path, KRscFileHeaderData().Length(), FileSizeL(z_path));
sl@0
   601
	DeleteDataFile(c_path);
sl@0
   602
	}
sl@0
   603
sl@0
   604
/**
sl@0
   605
@SYMTestCaseID          SYSLIB-BAFL-CT-0464
sl@0
   606
@SYMTestCaseDesc        Tests for resource file signature and in order behaviour
sl@0
   607
@SYMTestPriority        High
sl@0
   608
@SYMTestActions         Wrapper function calling up Test6() function
sl@0
   609
@SYMTestExpectedResults Test must not fail
sl@0
   610
@SYMREQ                 REQ0000
sl@0
   611
*/
sl@0
   612
LOCAL_C void SubTest6L()
sl@0
   613
	{
sl@0
   614
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0464 Testing resource file signature present and in order behaviour "));
sl@0
   615
	TBuf<128> z_path;
sl@0
   616
	TBuf<128> c_path;
sl@0
   617
sl@0
   618
	z_path.Copy(KZDir);
sl@0
   619
	z_path.Append(rsc_files[1]);
sl@0
   620
sl@0
   621
	Test6(z_path);
sl@0
   622
	CreateFileFromL(c_path, rsc_files[1], z_path);
sl@0
   623
	Test6(c_path, KRscFileHeaderData().Length(), FileSizeL(z_path));
sl@0
   624
	DeleteDataFile(c_path);
sl@0
   625
	}
sl@0
   626
sl@0
   627
/**
sl@0
   628
@SYMTestCaseID          SYSLIB-BAFL-CT-0465
sl@0
   629
@SYMTestCaseDesc        Tests for invalid resource file
sl@0
   630
@SYMTestPriority        High
sl@0
   631
@SYMTestActions         Wrapper function calling up Test7() function
sl@0
   632
@SYMTestExpectedResults Test must not fail
sl@0
   633
@SYMREQ                 REQ0000
sl@0
   634
*/
sl@0
   635
LOCAL_C void SubTest7L()
sl@0
   636
	{
sl@0
   637
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0465 Testing invalid resource file "));
sl@0
   638
	TBuf<128> z_path;
sl@0
   639
	TBuf<128> c_path;
sl@0
   640
sl@0
   641
	z_path.Copy(KZDir);
sl@0
   642
	z_path.Append(rsc_files[4]);
sl@0
   643
sl@0
   644
	Test7(z_path);
sl@0
   645
	CreateFileFromL(c_path, rsc_files[4], z_path);
sl@0
   646
	Test7(c_path, KRscFileHeaderData().Length(), FileSizeL(z_path));
sl@0
   647
	DeleteDataFile(c_path);
sl@0
   648
	}
sl@0
   649
sl@0
   650
LOCAL_C void DoE32MainL()
sl@0
   651
	{
sl@0
   652
	CleanupClosePushL(fileServerSession);
sl@0
   653
	User::LeaveIfError(fileServerSession.Connect());
sl@0
   654
sl@0
   655
	SubTest1L();
sl@0
   656
	SubTest2L();
sl@0
   657
	SubTest3L();
sl@0
   658
	SubTest4L();
sl@0
   659
	SubTest5L();
sl@0
   660
	SubTest6L();
sl@0
   661
	SubTest7L();
sl@0
   662
sl@0
   663
	CleanupStack::PopAndDestroy(1, &fileServerSession);
sl@0
   664
	}
sl@0
   665
sl@0
   666
GLDEF_C TInt E32Main()
sl@0
   667
	{
sl@0
   668
	__UHEAP_MARK;
sl@0
   669
	CTrapCleanup* trapCleanup=CTrapCleanup::New();
sl@0
   670
	TRAPD(error, DoE32MainL());
sl@0
   671
	test(error == KErrNone);
sl@0
   672
	test.Next(_L("/n"));
sl@0
   673
	test.End();
sl@0
   674
	test.Close();
sl@0
   675
	delete trapCleanup;
sl@0
   676
	__UHEAP_MARKEND;
sl@0
   677
	return error;
sl@0
   678
	}
sl@0
   679