sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Tests resource reader sl@0: // NB, prior to version 050 of BAFL, the resource compiler did not generate sl@0: // unicode text and so this code used to make a special 8/16 bit text sl@0: // comparison where appropriate and the resource binary file could be common sl@0: // between the 8 and 16-bit builds. This is now no-longer the case, which means sl@0: // that the resource binary used for this text MUST be compiled as Unicode sl@0: // text for the unicode build and 8-bit text for the 8-bit build. sl@0: // - PNJ, January 1997. sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "T_RSC.H" sl@0: sl@0: RTest test(_L("T_RSREAD")); sl@0: RFs TheFs; sl@0: RResourceFile TheResourceFile; sl@0: sl@0: _LIT(KPanicThread1,"panicThread1"); sl@0: _LIT(KPanicThread2,"panicThread2"); sl@0: _LIT(KPanicThread3,"panicThread3"); sl@0: _LIT(KPanicThread4,"panicThread4"); sl@0: sl@0: class TRsReadTester sl@0: { sl@0: public: sl@0: void TestButtonL(); sl@0: void TestArrayL(); sl@0: void TestFlPtEdL(); sl@0: void TestMenuBarL(); sl@0: void TestAlignment1L(); sl@0: void TestAlignment2L(); sl@0: void TimingTestsL(); sl@0: TInt PanicTests(); sl@0: private: sl@0: void DumpBytes(const TAny* aPtr,TInt aLen); sl@0: TUint8 DumpByte(TUint aVal); sl@0: void CreateResourceReaderLC(TResourceReader& aReader,TInt aResourceId) const; sl@0: void PanicTResImp1(); sl@0: void PanicTResImp2(); sl@0: void PanicTResImp3(); sl@0: void PanicTResImp4(); sl@0: }; sl@0: sl@0: void TRsReadTester::CreateResourceReaderLC(TResourceReader& aReader,TInt aResourceId) const sl@0: { sl@0: HBufC8* resource=TheResourceFile.AllocReadLC(aResourceId); sl@0: aReader.SetBuffer(resource); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0433 sl@0: @SYMTestCaseDesc Tests for TResourceReader::ReadInt16(),TResourceReader::ReadUint16() functions sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Attempt to read a BUTTON resource sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void TRsReadTester::TestButtonL() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0433 Test reading BUTTON resource ")); sl@0: TResourceReader reader; sl@0: CreateResourceReaderLC(reader,SYS_BUTTON_ONE); sl@0: test(reader.ReadInt16()==3); sl@0: test(reader.ReadUint16()==5); sl@0: TPtrC ptr=reader.ReadTPtrC(); sl@0: test(ptr==_L("Text")); sl@0: ptr.Set(reader.ReadTPtrC()); sl@0: test(ptr.Length()==0); sl@0: HBufC* hBuf=reader.ReadHBufCL(); sl@0: test(*hBuf==_L("Bitmap placeholder")); sl@0: delete(hBuf); sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0434 sl@0: @SYMTestCaseDesc Tests for TResourceReader::ReadDesCArrayL() function sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Attempt to read an array resource sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void TRsReadTester::TestArrayL() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0434 Test reading ARRAY resource ")); sl@0: TResourceReader reader; sl@0: CreateResourceReaderLC(reader,SYS_ARRAY_ONE); sl@0: CDesCArray* desArray=reader.ReadDesCArrayL(); sl@0: CleanupStack::PopAndDestroy(); sl@0: test(desArray->Count()==5); sl@0: sl@0: test((*desArray)[0]==_L("Esc")); sl@0: test((*desArray)[1]==_L("Enter")); sl@0: test((*desArray)[2]==_L("Tab")); sl@0: test((*desArray)[3]==_L("Del")); sl@0: test((*desArray)[4]==_L("Space")); sl@0: sl@0: delete(desArray); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0435 sl@0: @SYMTestCaseDesc Tests for TResourceReader::ReadInt16(),TResourceReader::ReadInt64() function sl@0: @SYMTestPriority High sl@0: @SYMTestActions Attempt for reading FLPTED resource sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void TRsReadTester::TestFlPtEdL() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0435 Test reading FLPTED resource ")); sl@0: TResourceReader reader; sl@0: CreateResourceReaderLC(reader,SYS_FLPTED_ONE); sl@0: test(reader.ReadInt16()==18); sl@0: TReal little=reader.ReadReal64(); sl@0: test(little==0.0); sl@0: TReal big=reader.ReadReal64(); sl@0: test(big>9.89e99); sl@0: test(big<9.91e99); sl@0: CleanupStack::PopAndDestroy(1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0436 sl@0: @SYMTestCaseDesc TResourceReader class functionality test sl@0: Test for TResourceReader::ReadInt32 (),TResourceReader::ReadTPtrC() functions sl@0: @SYMTestPriority High sl@0: @SYMTestActions Attempt for reading MENU_BAR resource sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void TRsReadTester::TestMenuBarL() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0436 Test reading MENU_BAR resource ")); sl@0: TResourceReader reader; sl@0: CreateResourceReaderLC(reader,SYS_MENUBAR_ONE); sl@0: test(reader.ReadInt16()==8); // how many items following sl@0: TPtrC ref=_L("abcdefgh"); sl@0: for (TInt ii=1; ii<=8; ii++) sl@0: { sl@0: test(reader.ReadInt32()==ii); sl@0: test(reader.ReadTPtrC()==ref.Left(ii)); sl@0: } sl@0: CleanupStack::PopAndDestroy(1); sl@0: } sl@0: sl@0: TInt horrors[] = { sl@0: SYS_ALIGNMENT_HORROR0, SYS_ALIGNMENT_HORROR1, sl@0: SYS_ALIGNMENT_HORROR2, SYS_ALIGNMENT_HORROR3, sl@0: 0 sl@0: }; sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0437 sl@0: @SYMTestCaseDesc Reading ALIGNMENT_HORROR resources test sl@0: Test for TResourceReader::ReadTPtrC8(),TResourceReader::ReadTPtrC16() function sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for reading descriptors and checks for alignment sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void TRsReadTester::TestAlignment1L() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0437 Test reading ALIGNMENT_HORROR resources ")); sl@0: TPtrC8 ref8 =_L8("xyz"); sl@0: TPtrC16 ref16=_L16("xyz"); sl@0: TResourceReader reader; sl@0: for (TInt rr=0; horrors[rr]!=0; rr++) sl@0: { sl@0: CreateResourceReaderLC(reader,horrors[rr]); sl@0: test(reader.ReadTPtrC8() ==ref8.Left(rr)); sl@0: test(reader.ReadTPtrC16()==ref16.Left(rr)); sl@0: CleanupStack::PopAndDestroy(1); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0438 sl@0: @SYMTestCaseDesc Reading ALIGNMENT_HORROR_ARRAY resource test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for reading descriptors and checks for alignment sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void TRsReadTester::TestAlignment2L() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0438 Test reading ALIGNMENT_HORROR_ARRAY resource ")); sl@0: TResourceReader reader; sl@0: CreateResourceReaderLC(reader,SYS_ALIGNMENT_HORROR_ARRAY); sl@0: test(reader.ReadInt16()==7); // how many items following sl@0: TPtrC8 ref8 =_L8("abcdef"); sl@0: TPtrC16 ref16=_L16("abcdef"); sl@0: for (TInt ii=0; ii<=6; ii++) sl@0: { sl@0: test(reader.ReadTPtrC8() ==ref8.Left(ii)); sl@0: test(reader.ReadTPtrC16()==ref16.Mid(ii)); sl@0: } sl@0: CleanupStack::PopAndDestroy(1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0439 sl@0: @SYMTestCaseDesc Timing Tests sl@0: @SYMTestPriority High sl@0: @SYMTestActions Check for the time loads needed to repeatedly load a resource sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void TRsReadTester::TimingTestsL() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0439 Timing tests ")); sl@0: test.Next(_L("BUTTON and FLPTED")); sl@0: TUint time = User::TickCount(); sl@0: for (TInt ii=0; ii<100; ii++) sl@0: { sl@0: TResourceReader reader; sl@0: CreateResourceReaderLC(reader,SYS_BUTTON_ONE); sl@0: CleanupStack::PopAndDestroy(); sl@0: CreateResourceReaderLC(reader,SYS_FLPTED_ONE); sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: time = User::TickCount() - time; sl@0: test.Printf(_L("Time to load 100 times: %d\n"),time); sl@0: sl@0: test.Next(_L("BUTTON and ARRAY")); sl@0: time = User::TickCount(); sl@0: for (TInt jj=0; jj<100; jj++) sl@0: { sl@0: TResourceReader reader; sl@0: CreateResourceReaderLC(reader,SYS_BUTTON_ONE); sl@0: CleanupStack::PopAndDestroy(); sl@0: CreateResourceReaderLC(reader,SYS_ARRAY_ONE); sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: time = User::TickCount() - time; sl@0: test.Printf(_L("Time to load 100 times: %d\n"),time); sl@0: } sl@0: sl@0: sl@0: TUint8 TRsReadTester::DumpByte(TUint aVal) sl@0: { sl@0: return(aVal>9? TUint8(aVal-10+'a'): TUint8(aVal+'0')); sl@0: } sl@0: sl@0: void TRsReadTester::DumpBytes(const TAny* aPtr,TInt aLen) sl@0: { sl@0: TUint8* src=(TUint8*)aPtr; sl@0: TBuf<100> whole; sl@0: TUint8* tar=(TUint8*)whole.Ptr(); sl@0: TInt len=0; sl@0: while (aLen--) sl@0: { sl@0: TUint val=(*src++); sl@0: TUint top=val/16; sl@0: TUint bottom=val%16; sl@0: *tar++=DumpByte(top); sl@0: *tar++=DumpByte(bottom); sl@0: *tar++=' '; sl@0: len+=3; sl@0: } sl@0: whole.SetLength(len); sl@0: test.Printf(whole); sl@0: test.Printf(_L("\r\n")); sl@0: } sl@0: sl@0: TInt ThreadFunc1(TAny*) sl@0: { sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); sl@0: RResourceReader reader; sl@0: reader.Close();// iCurrentPtr=NULL sl@0: TRAPD(err,reader.AdvanceL(0));//calls TResourceReaderImpl::AdvanceL() sl@0: delete cleanup; sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-UT-1791 sl@0: @SYMTestCaseDesc Testing a panic on TResourceReaderImpl class(JustInTimeDebug is disabled) sl@0: @SYMTestPriority Low sl@0: @SYMTestActions Test that panics, when the condition inside __ASSERT is made false, by calling AdvanceL, after iCurrentPtr is made NULL using RResourceReader::close() sl@0: @SYMTestExpectedResults Test must panic sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void TRsReadTester::PanicTResImp1() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-UT-1791 ")); sl@0: TRequestStatus threadStatus; sl@0: RThread thread1; sl@0: TInt rc; sl@0: rc = thread1.Create(KPanicThread1, ThreadFunc1, sl@0: KDefaultStackSize, KMinHeapSize, KMinHeapSize*4,NULL); sl@0: test(KErrNone == rc); sl@0: thread1.Logon(threadStatus); sl@0: thread1.Resume(); sl@0: User::WaitForRequest(threadStatus); sl@0: sl@0: test(thread1.ExitType() == EExitPanic); sl@0: thread1.Close(); sl@0: } sl@0: sl@0: TInt ThreadFunc2(TAny*) sl@0: { sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); sl@0: RResourceReader reader; sl@0: reader.Close();// iCurrentPtr=NULL sl@0: TRAPD(err,reader.ReadInt8L());//calls TResourceReaderImpl::ReadInt8L() sl@0: delete cleanup; sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-UT-1792 sl@0: @SYMTestCaseDesc Testing a panic on TResourceReaderImpl class(JustInTimeDebug is disabled) sl@0: @SYMTestPriority Low sl@0: @SYMTestActions Test that panics, when the condition inside __ASSERT is made false, by calling ReadInt8L, after iCurrentPtr is made NULL using RResourceReader::close() sl@0: @SYMTestExpectedResults Test must panic sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void TRsReadTester::PanicTResImp2() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-UT-1792 ")); sl@0: TRequestStatus threadStatus; sl@0: RThread thread2; sl@0: TInt rc; sl@0: rc = thread2.Create(KPanicThread2, ThreadFunc2, sl@0: KDefaultStackSize, KMinHeapSize, KMinHeapSize*4,NULL); sl@0: test(KErrNone == rc); sl@0: thread2.Logon(threadStatus); sl@0: thread2.Resume(); sl@0: User::WaitForRequest(threadStatus); sl@0: sl@0: test(thread2.ExitType() == EExitPanic); sl@0: thread2.Close(); sl@0: } sl@0: sl@0: TInt ThreadFunc3(TAny*) sl@0: { sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); sl@0: RResourceReader reader; sl@0: reader.Close(); sl@0: TRAPD(err,reader.ReadTPtrC8L());//calls TResourceReaderImpl::ReadTPtrC8L() sl@0: delete cleanup; sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-UT-1793 sl@0: @SYMTestCaseDesc Testing a panic on TResourceReaderImpl class(JustInTimeDebug is disabled) sl@0: @SYMTestPriority Low sl@0: @SYMTestActions Test that panics, when the condition inside __ASSERT is made false, by calling ReadTPtrC8L, after iCurrentPtr is made NULL using RResourceReader::close() sl@0: @SYMTestExpectedResults Test must panic sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void TRsReadTester::PanicTResImp3() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-UT-1793 ")); sl@0: TRequestStatus threadStatus; sl@0: RThread thread3; sl@0: TInt rc; sl@0: rc = thread3.Create(KPanicThread3, ThreadFunc3, sl@0: KDefaultStackSize, KMinHeapSize, KMinHeapSize*4,NULL); sl@0: test(KErrNone == rc); sl@0: thread3.Logon(threadStatus); sl@0: thread3.Resume(); sl@0: User::WaitForRequest(threadStatus); sl@0: sl@0: test(thread3.ExitType() == EExitPanic); sl@0: thread3.Close(); sl@0: } sl@0: sl@0: TInt ThreadFunc4(TAny*) sl@0: { sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); sl@0: RResourceReader reader; sl@0: reader.Close(); sl@0: TRAPD(err,reader.ReadUint8L());//calls TResourceReaderImpl::ReadUint8L() sl@0: delete cleanup; sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-UT-1794 sl@0: @SYMTestCaseDesc Testing a panic on TResourceReaderImpl class(JustInTimeDebug is disabled) sl@0: @SYMTestPriority Low sl@0: @SYMTestActions Test that panics, when the condition inside __ASSERT is made false, by calling ReadUint8L, after iCurrentPtr is made NULL using RResourceReader::close() sl@0: @SYMTestExpectedResults Test must panic sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void TRsReadTester::PanicTResImp4() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-UT-1794 ")); sl@0: TRequestStatus threadStatus; sl@0: RThread thread4; sl@0: TInt rc; sl@0: rc = thread4.Create(KPanicThread4, ThreadFunc4, sl@0: KDefaultStackSize, KMinHeapSize, KMinHeapSize*4,NULL); sl@0: test(KErrNone == rc); sl@0: thread4.Logon(threadStatus); sl@0: thread4.Resume(); sl@0: User::WaitForRequest(threadStatus); sl@0: sl@0: test(thread4.ExitType() == EExitPanic); sl@0: thread4.Close(); sl@0: } sl@0: sl@0: TInt TRsReadTester::PanicTests() sl@0: { sl@0: TBool jit; sl@0: jit = User::JustInTime(); sl@0: User::SetJustInTime(EFalse); sl@0: sl@0: //Tests for panics in TResourceReaderImpl class, through RResourceReader class sl@0: PanicTResImp1(); sl@0: PanicTResImp2(); sl@0: PanicTResImp3(); sl@0: PanicTResImp4(); sl@0: sl@0: User::SetJustInTime(jit); sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0440 sl@0: @SYMTestCaseDesc Resource reader test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Executes all the tests related to resource read sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void RunTests() sl@0: { sl@0: test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0440 Resource reader ")); sl@0: TheFs.Connect(); sl@0: TheResourceFile.OpenL(TheFs,KRomResourceFile); sl@0: TRsReadTester lt; sl@0: TRAPD(errCode, lt.TestButtonL()); sl@0: test(errCode==KErrNone); sl@0: TRAP(errCode, lt.TestArrayL()); sl@0: test(errCode==KErrNone); sl@0: TRAP(errCode, lt.TestFlPtEdL()); sl@0: test(errCode==KErrNone); sl@0: TRAP(errCode, lt.TestMenuBarL()); sl@0: test(errCode==KErrNone); sl@0: TRAP(errCode, lt.TestAlignment1L()); sl@0: test(errCode==KErrNone); sl@0: TRAP(errCode, lt.TestAlignment2L()); sl@0: test(errCode==KErrNone); sl@0: TRAP(errCode, lt.TimingTestsL()); sl@0: test(errCode==KErrNone); sl@0: TheResourceFile.Close(); sl@0: //Test that raises panics sl@0: test(KErrNone==lt.PanicTests()); sl@0: sl@0: TheFs.Close(); sl@0: test.End(); sl@0: test.Close(); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: CTrapCleanup *cleanup=CTrapCleanup::New(); sl@0: test.Title(); sl@0: TRAPD(err,RunTests()); sl@0: test(!err); sl@0: test.Close(); sl@0: delete(cleanup); sl@0: __UHEAP_MARKEND; sl@0: return(0); sl@0: }