os/ossrv/lowlevellibsandfws/apputils/tsrc/T_SPI.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-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 <e32test.h>
sl@0
    17
#include <bautils.h>
sl@0
    18
#include <barsread2.h>
sl@0
    19
#include <barsc2.h>
sl@0
    20
#include <baspi.h>
sl@0
    21
sl@0
    22
LOCAL_D RTest TheTest(_L("T_SPI"));
sl@0
    23
LOCAL_D RFs TheFs;
sl@0
    24
sl@0
    25
//Test files
sl@0
    26
_LIT(KTestDirectoryPath,"z:\\system\\data\\");
sl@0
    27
_LIT(KRscExtension,".rsc");
sl@0
    28
_LIT(KXipSpiFile,"z:\\system\\data\\Spi_ECom.SPI");
sl@0
    29
_LIT(KNonXipSpiFile, "c:\\system\\data\\Spi_ECom.SPI");
sl@0
    30
_LIT(KXipSpi_EcomRsc1,"z:\\system\\data\\Spi_EcomRsc1.rsc");
sl@0
    31
_LIT(KXipSpi_EcomRsc2,"z:\\system\\data\\Spi_EcomRsc2.rsc");
sl@0
    32
_LIT(KXipSpi_EcomRsc3,"z:\\system\\data\\Spi_EcomRsc3.rsc");
sl@0
    33
_LIT(KNonXipSpi_EcomRsc1,"c:\\system\\data\\Spi_EcomRsc1.rsc");
sl@0
    34
_LIT(KNonXipSpi_EcomRsc2,"c:\\system\\data\\Spi_EcomRsc2.rsc");
sl@0
    35
_LIT(KNonXipSpi_EcomRsc3,"c:\\system\\data\\Spi_EcomRsc3.rsc");
sl@0
    36
sl@0
    37
//----------------------UTILITY FUNCTIONS----------------------------------
sl@0
    38
LOCAL_C void CopyFileL(const TDesC& aFrom,const TDesC& aTo)
sl@0
    39
	{
sl@0
    40
	TheFs.Delete(aTo);
sl@0
    41
	CFileMan* man=CFileMan::NewL(TheFs);
sl@0
    42
	TInt r=man->Copy(aFrom,aTo, CFileMan::ERecurse);
sl@0
    43
	delete man;
sl@0
    44
	User::LeaveIfError(r);
sl@0
    45
	User::LeaveIfError(TheFs.SetAtt(aTo,0,KEntryAttReadOnly)); // clear RO
sl@0
    46
	}
sl@0
    47
sl@0
    48
LOCAL_C void DeleteFile(const TDesC& aFileName)
sl@0
    49
	{
sl@0
    50
	// make sure the file is read/write
sl@0
    51
	TInt err = TheFs.SetAtt(aFileName, 0, KEntryAttReadOnly);
sl@0
    52
	if(err != KErrNone)
sl@0
    53
		{
sl@0
    54
		RDebug::Print(_L("error changing attributes file = %d"),err);
sl@0
    55
		}
sl@0
    56
	// delete the file
sl@0
    57
	err = BaflUtils::DeleteFile(TheFs, aFileName);
sl@0
    58
	if(err != KErrNone)
sl@0
    59
		{
sl@0
    60
		RDebug::Print(_L("error deleting file = %d"),err);
sl@0
    61
		}
sl@0
    62
	}
sl@0
    63
sl@0
    64
LOCAL_C TInt FileSizeL(const TDesC& aFileName)
sl@0
    65
	{
sl@0
    66
	RFile file;
sl@0
    67
	CleanupClosePushL(file);
sl@0
    68
	User::LeaveIfError(file.Open(TheFs, aFileName, EFileRead));
sl@0
    69
	TInt size = 0;
sl@0
    70
	User::LeaveIfError(file.Size(size));
sl@0
    71
	CleanupStack::PopAndDestroy(&file);
sl@0
    72
	return size;
sl@0
    73
	}
sl@0
    74
sl@0
    75
LOCAL_C void DeleteTestFile()
sl@0
    76
	{
sl@0
    77
	DeleteFile(KNonXipSpiFile);
sl@0
    78
	DeleteFile(KNonXipSpi_EcomRsc1);
sl@0
    79
	DeleteFile(KNonXipSpi_EcomRsc2);
sl@0
    80
	DeleteFile(KNonXipSpi_EcomRsc3);
sl@0
    81
	}
sl@0
    82
sl@0
    83
//Test macroses and functions
sl@0
    84
LOCAL_C void Check(TInt aValue, TInt aLine)
sl@0
    85
	{
sl@0
    86
	if(!aValue)
sl@0
    87
		{
sl@0
    88
		::DeleteTestFile();
sl@0
    89
		TheTest(EFalse, aLine);
sl@0
    90
		}
sl@0
    91
	}
sl@0
    92
sl@0
    93
#define TEST(arg) ::Check((arg), __LINE__)
sl@0
    94
sl@0
    95
//---------------------TEST CASE for RResoureArchive------------------
sl@0
    96
// Tests for RResourceArchive
sl@0
    97
/*
sl@0
    98
(1) Test Loading SPI file through RResourceArchive and retrieving the first rsc block
sl@0
    99
	from XIP media(e.g NOR flash) in basic and OOM environment.
sl@0
   100
(2) Test Loading SPI file through RResourceArchive and retrieving the first rsc block
sl@0
   101
	from NON-XIP media(e.g NAND flash) in basic and OOM environment.
sl@0
   102
(3) Test the Reset() functionality to ensure proper reset functionality by comparing the
sl@0
   103
	content of the rsc file
sl@0
   104
(4)	Test Loading some test SPI(with 2-3 random rsc file), interpret the content of rsc file
sl@0
   105
	through RResourceReader and compare it with the results when opening each rsc file
sl@0
   106
	separately.
sl@0
   107
(5) Test Loading some non-spi file using RResourceArchive expecting a KErrCorrupt to be
sl@0
   108
	returned
sl@0
   109
*/
sl@0
   110
class RStaticPluginInfoTest
sl@0
   111
	{
sl@0
   112
public:
sl@0
   113
	static void TestCase1L();
sl@0
   114
	static void TestCase2L();
sl@0
   115
	static void TestCase3L();
sl@0
   116
	static void TestCase4L();
sl@0
   117
	static void TestCase5L();
sl@0
   118
private:
sl@0
   119
	static void TestOpenNextL(const TDesC& aFileName);
sl@0
   120
	static void TestComparisonL(const TDesC& aFileName);
sl@0
   121
	};
sl@0
   122
sl@0
   123
void RStaticPluginInfoTest::TestCase1L()
sl@0
   124
	{
sl@0
   125
	TheTest.Next(_L("Test case 1 Loading/Reading SPI file from XIP media\n"));
sl@0
   126
	TestOpenNextL(KXipSpiFile);
sl@0
   127
	}
sl@0
   128
sl@0
   129
void RStaticPluginInfoTest::TestCase2L()
sl@0
   130
	{
sl@0
   131
	TheTest.Next(_L("Test case 2 Loading/Reading SPI file from Non-XIP media\n"));
sl@0
   132
	TestOpenNextL(KNonXipSpiFile);
sl@0
   133
	}
sl@0
   134
sl@0
   135
void RStaticPluginInfoTest::TestCase3L()
sl@0
   136
	{
sl@0
   137
	__UHEAP_MARK;
sl@0
   138
	TheTest.Next(_L("Test case 3 Testing functionality of the Reset() function\n"));
sl@0
   139
	RResourceArchive testArchiveIter;
sl@0
   140
	testArchiveIter.OpenL(TheFs,KXipSpiFile);
sl@0
   141
sl@0
   142
	RResourceReader theReader1;
sl@0
   143
	RResourceReader theReader3;
sl@0
   144
sl@0
   145
	HBufC* rscName1=NULL;
sl@0
   146
	HBufC* rscName2=NULL;
sl@0
   147
	HBufC* rscName3=NULL;
sl@0
   148
sl@0
   149
	CResourceFile* rscArchive1=testArchiveIter.NextL(rscName1);
sl@0
   150
	TEST(rscArchive1!=NULL);
sl@0
   151
sl@0
   152
	CResourceFile* rscArchive2=testArchiveIter.NextL(rscName2);
sl@0
   153
	TEST(rscArchive2!=NULL);
sl@0
   154
sl@0
   155
	testArchiveIter.Reset();
sl@0
   156
sl@0
   157
	CResourceFile* rscArchive3=testArchiveIter.NextL(rscName3);
sl@0
   158
	TEST(rscArchive3!=NULL);
sl@0
   159
sl@0
   160
	//Check to ensure that rscArchive3 content is the same as rscArchive1
sl@0
   161
	theReader1.OpenLC(rscArchive1,1);
sl@0
   162
	theReader3.OpenLC(rscArchive3,1);
sl@0
   163
	TEST(rscArchive1->UidType()==rscArchive3->UidType());
sl@0
   164
	TEST(rscName1->CompareF(rscName3->Des())==0);
sl@0
   165
	TEST(theReader1.ReadInt32L()==theReader3.ReadInt32L());
sl@0
   166
sl@0
   167
	delete rscName1;
sl@0
   168
	delete rscName2;
sl@0
   169
	delete rscName3;
sl@0
   170
	delete rscArchive1;
sl@0
   171
	delete rscArchive2;
sl@0
   172
	delete rscArchive3;
sl@0
   173
sl@0
   174
	testArchiveIter.Close();
sl@0
   175
sl@0
   176
	CleanupStack::PopAndDestroy(&theReader3);
sl@0
   177
	CleanupStack::PopAndDestroy(&theReader1);
sl@0
   178
	__UHEAP_MARKEND;
sl@0
   179
	}
sl@0
   180
sl@0
   181
void RStaticPluginInfoTest::TestCase4L()
sl@0
   182
	{
sl@0
   183
	TheTest.Next(_L("Test case 4 Testing comparison of spi and rsc read CResourceFiles\n"));
sl@0
   184
	TestComparisonL(KXipSpiFile);
sl@0
   185
	TestComparisonL(KNonXipSpiFile);
sl@0
   186
	}
sl@0
   187
sl@0
   188
void RStaticPluginInfoTest::TestCase5L()
sl@0
   189
	{
sl@0
   190
	TheTest.Next(_L("Test case 5 Testing opening a non-spi file\n"));
sl@0
   191
	__UHEAP_MARK;
sl@0
   192
	RResourceArchive testArchiveIter;
sl@0
   193
	TRAPD(err,testArchiveIter.OpenL(TheFs,KXipSpi_EcomRsc1));
sl@0
   194
	TEST(err==KErrCorrupt);
sl@0
   195
sl@0
   196
	__UHEAP_MARKEND;
sl@0
   197
	}
sl@0
   198
sl@0
   199
void RStaticPluginInfoTest::TestComparisonL(const TDesC& aFileName)
sl@0
   200
	{
sl@0
   201
	__UHEAP_MARK;
sl@0
   202
	RResourceArchive testArchiveIter;
sl@0
   203
	testArchiveIter.OpenL(TheFs,aFileName);
sl@0
   204
	TUid spiType=testArchiveIter.Type();
sl@0
   205
	TEST(spiType.iUid=0x10205C2C);
sl@0
   206
sl@0
   207
	CResourceFile* spiRscArchive=NULL;
sl@0
   208
	HBufC* rscName=NULL;
sl@0
   209
	spiRscArchive=testArchiveIter.NextL(rscName);
sl@0
   210
	while (spiRscArchive)
sl@0
   211
		{
sl@0
   212
		TFileName fullRscName;
sl@0
   213
		fullRscName.Append(KTestDirectoryPath);
sl@0
   214
		fullRscName.Append(rscName->Des());
sl@0
   215
		fullRscName.Append(KRscExtension);
sl@0
   216
		TInt rscFileSize=FileSizeL(fullRscName);
sl@0
   217
sl@0
   218
		//Creating a CResourceFile by opening the individual rsc file
sl@0
   219
		CResourceFile* existingRscArchive=CResourceFile::NewL(TheFs,fullRscName,0,rscFileSize);
sl@0
   220
		//Now perform general comparison
sl@0
   221
		TEST(spiRscArchive->UidType()==existingRscArchive->UidType());
sl@0
   222
		TEST(spiRscArchive->Offset()==existingRscArchive->Offset());
sl@0
   223
		//Now perform interpreting and comparing the rsc content
sl@0
   224
		RResourceReader rscReader;
sl@0
   225
		RResourceReader spiRscReader;
sl@0
   226
		spiRscReader.OpenLC(spiRscArchive,1);
sl@0
   227
		rscReader.OpenLC(existingRscArchive,1);
sl@0
   228
		//Now perform all the read results and comparison between the two CResourceFile
sl@0
   229
		const TUid KUidEComResourceFormatV2 = {0x101FB0B9};
sl@0
   230
		TInt resourceFormatVersion=0;
sl@0
   231
		resourceFormatVersion+=0;
sl@0
   232
		//Comparison of Rsc uid
sl@0
   233
		TUid rscUid = {rscReader.ReadInt32L()};
sl@0
   234
		TEST(rscUid.iUid==spiRscReader.ReadInt32L());
sl@0
   235
		if(rscUid==KUidEComResourceFormatV2)
sl@0
   236
			{
sl@0
   237
			resourceFormatVersion = 2;
sl@0
   238
			TUid dllUid={rscReader.ReadInt32L()};
sl@0
   239
			TEST(dllUid.iUid==spiRscReader.ReadInt32L());
sl@0
   240
			}
sl@0
   241
		//Comparison of number of interfaces
sl@0
   242
		TInt numberOfInterface=rscReader.ReadInt16L();
sl@0
   243
		TEST(numberOfInterface==spiRscReader.ReadInt16L());
sl@0
   244
		//Comparison of the each interface uid and implementations under this interface
sl@0
   245
		for(TInt iFace = 0; iFace < numberOfInterface; ++iFace)
sl@0
   246
			{
sl@0
   247
			//Comparison of each interface Uid
sl@0
   248
			const TUid interfaceUid = {rscReader.ReadInt32L()};
sl@0
   249
			TEST(interfaceUid.iUid==spiRscReader.ReadInt32L());
sl@0
   250
			//Comparison of number of implementations under this interface
sl@0
   251
			const TInt numImplementations = rscReader.ReadInt16L();
sl@0
   252
			TEST(numImplementations==spiRscReader.ReadInt16L());
sl@0
   253
			for(TInt impl = 0; impl < numImplementations; ++impl)
sl@0
   254
				{
sl@0
   255
				//Comparison of some of the implementation content
sl@0
   256
				const TUid impUid  = {rscReader.ReadInt32L()};
sl@0
   257
				TEST(impUid.iUid==spiRscReader.ReadInt32L());
sl@0
   258
				const TInt version = rscReader.ReadInt8L();
sl@0
   259
				TEST(version==spiRscReader.ReadInt8L());
sl@0
   260
				}
sl@0
   261
			}
sl@0
   262
		delete existingRscArchive;
sl@0
   263
		existingRscArchive=NULL;
sl@0
   264
		delete spiRscArchive;
sl@0
   265
		spiRscArchive=NULL;
sl@0
   266
		delete rscName;
sl@0
   267
		rscName=NULL;
sl@0
   268
		CleanupStack::PopAndDestroy(&rscReader);
sl@0
   269
		CleanupStack::PopAndDestroy(&spiRscReader);
sl@0
   270
		spiRscArchive=testArchiveIter.NextL(rscName);
sl@0
   271
		}
sl@0
   272
	testArchiveIter.Close();
sl@0
   273
sl@0
   274
	__UHEAP_MARKEND;
sl@0
   275
	}
sl@0
   276
sl@0
   277
void RStaticPluginInfoTest::TestOpenNextL(const TDesC& aFileName)
sl@0
   278
    {
sl@0
   279
    //---------Basic testing-------------------------------
sl@0
   280
	__UHEAP_MARK;
sl@0
   281
sl@0
   282
	RResourceArchive testArchiveIter;
sl@0
   283
	testArchiveIter.OpenL(TheFs,aFileName);
sl@0
   284
	TUid spiType=testArchiveIter.Type();
sl@0
   285
	TEST(spiType.iUid==0x10205C2C);
sl@0
   286
	HBufC* rscName=NULL;
sl@0
   287
	CResourceFile* rscArchive=testArchiveIter.NextL(rscName);
sl@0
   288
sl@0
   289
	delete rscArchive;
sl@0
   290
	rscArchive=NULL;
sl@0
   291
	delete rscName;
sl@0
   292
	rscName=NULL;
sl@0
   293
	testArchiveIter.Close();
sl@0
   294
sl@0
   295
	__UHEAP_MARKEND;
sl@0
   296
sl@0
   297
	//-----------OOM testing--------------------------------
sl@0
   298
	TInt err;
sl@0
   299
	TInt tryCount = 0;
sl@0
   300
	tryCount=tryCount;
sl@0
   301
	RResourceArchive testArchiveIter1;
sl@0
   302
	testArchiveIter1.OpenL(TheFs,aFileName);
sl@0
   303
	do
sl@0
   304
		{
sl@0
   305
		__UHEAP_MARK;
sl@0
   306
  		// find out the number of open handles
sl@0
   307
		TInt startProcessHandleCount;
sl@0
   308
		TInt startThreadHandleCount;
sl@0
   309
		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
sl@0
   310
		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
sl@0
   311
		TRAP(err,rscArchive=testArchiveIter1.NextL(rscName));
sl@0
   312
		__UHEAP_SETFAIL(RHeap::ENone, 0);
sl@0
   313
sl@0
   314
		delete rscArchive;
sl@0
   315
		rscArchive=NULL;
sl@0
   316
sl@0
   317
		delete rscName;
sl@0
   318
		rscName=NULL;
sl@0
   319
sl@0
   320
		// check that no handles have leaked
sl@0
   321
		TInt endProcessHandleCount;
sl@0
   322
		TInt endThreadHandleCount;
sl@0
   323
		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
sl@0
   324
sl@0
   325
		TEST(startProcessHandleCount == endProcessHandleCount);
sl@0
   326
		TEST(startThreadHandleCount  == endThreadHandleCount);
sl@0
   327
sl@0
   328
		__UHEAP_MARKEND;
sl@0
   329
		} while(err == KErrNoMemory);
sl@0
   330
	testArchiveIter1.Close();
sl@0
   331
	}
sl@0
   332
sl@0
   333
/**
sl@0
   334
@SYMTestCaseID SYSLIB-BAFL-CT-0094
sl@0
   335
@SYMTestCaseDesc Testing for the functionality of RResourceArchive
sl@0
   336
@SYMTestPriority High
sl@0
   337
@SYMTestActions  Test loading and reading Spi file through Xip and Non-Xip media
sl@0
   338
				 Test interpreting and comparing rsc content through read from
sl@0
   339
				 spi file and from individual rsc file.
sl@0
   340
				 Test all exported functionality of this class in general and
sl@0
   341
				 OOM conditions.
sl@0
   342
@SYMTestExpectedResults The test must not fail.
sl@0
   343
@SYMPREQ 806 Eliminate scanning for plugins on startup
sl@0
   344
*/
sl@0
   345
LOCAL_C void DoAllTestsL()
sl@0
   346
	{
sl@0
   347
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0094 "));
sl@0
   348
	CleanupClosePushL(TheFs);
sl@0
   349
	User::LeaveIfError(TheFs.Connect());
sl@0
   350
sl@0
   351
	TheTest.Printf(_L("Copying SPI files to RAM\r\n"));
sl@0
   352
	//Copying test spi file and individual rsc files that are included inside spi
sl@0
   353
	CopyFileL(KXipSpiFile,KNonXipSpiFile);
sl@0
   354
	CopyFileL(KXipSpi_EcomRsc1,KNonXipSpi_EcomRsc1);
sl@0
   355
	CopyFileL(KXipSpi_EcomRsc2,KNonXipSpi_EcomRsc2);
sl@0
   356
	CopyFileL(KXipSpi_EcomRsc3,KNonXipSpi_EcomRsc3);
sl@0
   357
sl@0
   358
	//Start running all the TestCase
sl@0
   359
	RStaticPluginInfoTest::TestCase1L();
sl@0
   360
	RStaticPluginInfoTest::TestCase2L();
sl@0
   361
	RStaticPluginInfoTest::TestCase3L();
sl@0
   362
	RStaticPluginInfoTest::TestCase4L();
sl@0
   363
	RStaticPluginInfoTest::TestCase5L();
sl@0
   364
sl@0
   365
	//Clearing all the test files we have copied to C
sl@0
   366
	DeleteTestFile();
sl@0
   367
sl@0
   368
	CleanupStack::PopAndDestroy(1, &TheFs);
sl@0
   369
	}
sl@0
   370
sl@0
   371
GLDEF_C TInt E32Main()
sl@0
   372
	{
sl@0
   373
    __UHEAP_MARK;
sl@0
   374
    CTrapCleanup *cleanup=CTrapCleanup::New();
sl@0
   375
	TheTest.Title();
sl@0
   376
	TheTest.Start(_L("Testing RResourceArchive"));
sl@0
   377
    TRAPD(err,DoAllTestsL());
sl@0
   378
    TheTest.Printf(_L("Error code is %d\n"),err);
sl@0
   379
    TEST(err==KErrNone);
sl@0
   380
    TheTest.End();
sl@0
   381
    TheTest.Close();
sl@0
   382
    delete cleanup;
sl@0
   383
    __UHEAP_MARKEND;
sl@0
   384
	return(0);
sl@0
   385
    }
sl@0
   386