sl@0: // Copyright (c) 2006-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 for CBaNamedPlugins class, which contains CParameters class sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: RTest TheTest(_L("T_NamedPlugins")); sl@0: RFs TheFs; sl@0: sl@0: //Test macros and functions sl@0: sl@0: LOCAL_C void Check(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: sl@0: #define TEST(arg) Check((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) Check(aValue, aExpected, __LINE__) sl@0: sl@0: sl@0: TUid KUid1 = {0xE1A01753}; sl@0: TUid KUid2 = {0xE1B01753}; sl@0: sl@0: _LIT(KRscFileName1, "\\resource\\plugins\\E1A01753.RSC"); sl@0: _LIT(KRscFileName2, "\\resource\\plugins\\E1B01753.RSC"); sl@0: _LIT(KIdentifier, "plugin"); sl@0: _LIT(KBadIdentifier, "plugni"); sl@0: _LIT(KMainPath, "\\system\\data\\"); sl@0: _LIT(KLitWildCard, "*.RSC"); sl@0: _LIT(KTextForNone, "NoPlugin"); sl@0: sl@0: class CImplementation: public CBaNamedPlugins::MFallBackName sl@0: { sl@0: public: sl@0: sl@0: HBufC* FallBackNameL(const TDesC& aFullResourceFileName) const; sl@0: }; sl@0: sl@0: HBufC* CImplementation::FallBackNameL(const TDesC& aFullResourceFileName) const sl@0: { sl@0: return aFullResourceFileName.AllocL(); sl@0: } sl@0: sl@0: TBool TestAlgorithmToCompareNames(const TDesC& aName1, const TDesC& aName2) sl@0: { sl@0: return( aName1.CompareC(aName2) == 0); // Function is supposed to return 1, when CompareC returns 0 sl@0: } sl@0: sl@0: /* sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-1756 sl@0: @SYMTestCaseDesc CBaNamedPlugins class test sl@0: Tests for CBaNamedPlugins::IndexOfIdentifier(), CBaNamedPlugins::IndexOfUid(), CBaNamedPlugins::MdcaPoint(), CBaNamedPlugins::IdentifierAtIndex(), CBaNamedPlugins::UidAtIndex(),CBaNamedPlugins::MdcaCount() functions sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions CBaNamedPlugins object is populated with resource file names and checking for identifier and Uid sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void DoTests1() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1756 Testing DoTests1... ")); sl@0: TBuf<64> buf; sl@0: sl@0: CBaNamedPlugins* namedPlugins; sl@0: RArray arrayOfResourceFiles; sl@0: CleanupClosePushL(arrayOfResourceFiles); sl@0: sl@0: buf = KRscFileName1; sl@0: sl@0: CBaNamedPlugins::TResourceFile resourceFile1; sl@0: resourceFile1.iFullFileName = buf.AllocLC(); sl@0: resourceFile1.iIdentifier = NULL; sl@0: resourceFile1.iUid = KUid1; sl@0: resourceFile1.iFormat = CBaNamedPlugins::TResourceFile::EFormatTbuf; sl@0: User::LeaveIfError(arrayOfResourceFiles.Append(resourceFile1)); sl@0: CleanupStack::Pop(resourceFile1.iFullFileName); sl@0: sl@0: buf = KRscFileName2; sl@0: sl@0: CBaNamedPlugins::TResourceFile resourceFile2; sl@0: resourceFile2.iFullFileName = buf.AllocLC(); sl@0: buf = KIdentifier; sl@0: resourceFile2.iIdentifier = buf.AllocLC(); sl@0: resourceFile2.iUid = KUid2; sl@0: resourceFile2.iFormat = CBaNamedPlugins::TResourceFile::EFormatTbuf; sl@0: User::LeaveIfError(arrayOfResourceFiles.Append(resourceFile2)); sl@0: CleanupStack::Pop(resourceFile2.iIdentifier); sl@0: sl@0: CleanupStack::Pop(resourceFile2.iFullFileName); sl@0: sl@0: CBaNamedPlugins::CParameters* const parameters = CBaNamedPlugins::CParameters::NewLC(TheFs, arrayOfResourceFiles.Array()); sl@0: HBufC* textForNone=KTextForNone().AllocL(); sl@0: parameters->SetTextForNone(textForNone,CBaNamedPlugins::EArrayPositionLast); sl@0: sl@0: // This call to SetTextForNoneL will delete textForNone sl@0: parameters->SetTextForNoneL(KTextForNone,CBaNamedPlugins::EArrayPositionLast); sl@0: sl@0: namedPlugins = CBaNamedPlugins::NewL(*parameters); sl@0: sl@0: CBaNamedPlugins::TEquivalentIdentifiers eqIdent = TestAlgorithmToCompareNames; sl@0: TInt i = (*namedPlugins).IndexOfIdentifier(KIdentifier,eqIdent); sl@0: // With the sorting algorithm and resource files benig used KIdentifier is at index 0 sl@0: TEST2(i,0); sl@0: i = (*namedPlugins).IndexOfIdentifier(KBadIdentifier,eqIdent); sl@0: TEST2(i,KErrNotFound); sl@0: sl@0: TInt index = namedPlugins->IndexOfUid(KUid1); sl@0: TEST(index>=0); sl@0: TPtrC name; sl@0: if( index >= 0 ) sl@0: { sl@0: name.Set((*namedPlugins).MdcaPoint(index)); sl@0: } sl@0: index = (namedPlugins)->IndexOfUid(TUid::Uid(0x123)); sl@0: TEST2(index,-1); sl@0: sl@0: TEST((*namedPlugins).IdentifierAtIndex(1)!= &buf); sl@0: TEST((*namedPlugins).UidAtIndex(0)==KUid2); sl@0: TEST((*namedPlugins).UidAtIndex(1)==KUid1); sl@0: sl@0: TInt count = (*namedPlugins).MdcaCount(); sl@0: TEST2(count,3); sl@0: sl@0: count = arrayOfResourceFiles.Count(); sl@0: for(i = 0; i < count; i++ ) sl@0: { sl@0: const CBaNamedPlugins::TResourceFile& resourceFileData=arrayOfResourceFiles[i]; sl@0: delete resourceFileData.iFullFileName; sl@0: delete resourceFileData.iIdentifier; sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, &arrayOfResourceFiles); sl@0: delete namedPlugins; sl@0: sl@0: // Test EFormatArrayOfUidNamePairs format sl@0: buf = KRscFileName1; sl@0: sl@0: CleanupClosePushL(arrayOfResourceFiles); sl@0: sl@0: CBaNamedPlugins::TResourceFile resourceFile; sl@0: resourceFile.iFullFileName = KRscFileName1().AllocLC(); sl@0: resourceFile.iIdentifier = NULL; sl@0: resourceFile.iUid = KNullUid; sl@0: resourceFile.iFormat = CBaNamedPlugins::TResourceFile::EFormatArrayOfUidNamePairs; sl@0: User::LeaveIfError(arrayOfResourceFiles.Append(resourceFile)); sl@0: CleanupStack::Pop(resourceFile.iFullFileName); sl@0: sl@0: CBaNamedPlugins::CParameters* const parameters1 = CBaNamedPlugins::CParameters::NewL(TheFs, arrayOfResourceFiles.Array()); sl@0: textForNone=KTextForNone().AllocL(); sl@0: parameters1->SetTextForNone(textForNone,CBaNamedPlugins::EArrayPositionFirst); sl@0: namedPlugins = CBaNamedPlugins::NewL(*parameters1); sl@0: sl@0: delete resourceFile.iFullFileName; sl@0: sl@0: CleanupStack::PopAndDestroy(&arrayOfResourceFiles); sl@0: delete parameters1; sl@0: delete namedPlugins; sl@0: } sl@0: sl@0: /* sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-1757 sl@0: @SYMTestCaseDesc CBaNamedPlugins::CParameters class test sl@0: Tests for CParameters::SetFallBackName,CParameters::SetCompareNames,getting file names by searching file system sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Setting the algorithm to compare two plugin names sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void DoTests2() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1757 Testing DoTests2... ")); sl@0: TBuf<64> buf; sl@0: buf = KMainPath; sl@0: sl@0: CBaNamedPlugins* namedPlugins; sl@0: RArray arrayOfResourceFiles; sl@0: CleanupClosePushL(arrayOfResourceFiles); sl@0: sl@0: TFindFile* findFile = new(ELeave) TFindFile(TheFs); sl@0: CleanupStack::PushL(findFile); sl@0: sl@0: CDir* directory = NULL; sl@0: sl@0: TInt err = findFile->FindWildByDir(KLitWildCard, buf, directory); sl@0: TInt mdcaCount=0; sl@0: while(err==KErrNone) sl@0: { sl@0: CleanupStack::PushL(directory); sl@0: for (TInt i=directory->Count()-1; i>=0; --i) sl@0: { sl@0: const TEntry& entry = (*directory)[i]; sl@0: CBaNamedPlugins::TResourceFile resourceFile; sl@0: resourceFile.iFullFileName = entry.iName.AllocLC(); sl@0: resourceFile.iIdentifier = NULL; sl@0: resourceFile.iUid = KNullUid; sl@0: resourceFile.iFormat = CBaNamedPlugins::TResourceFile::EFormatTbuf; sl@0: ++mdcaCount; sl@0: User::LeaveIfError(arrayOfResourceFiles.Append(resourceFile)); sl@0: CleanupStack::Pop(resourceFile.iFullFileName); sl@0: } sl@0: CleanupStack::PopAndDestroy(); // directory sl@0: directory = NULL; sl@0: err=findFile->FindWild(directory); sl@0: } sl@0: CleanupStack::PopAndDestroy(); // findfile sl@0: sl@0: CBaNamedPlugins::CParameters* const parameters = CBaNamedPlugins::CParameters::NewL(TheFs, arrayOfResourceFiles.Array()); sl@0: sl@0: CBaNamedPlugins::TCompareNames compName = TestAlgorithmToCompareNames; sl@0: (*parameters).SetCompareNames(compName); sl@0: namedPlugins = CBaNamedPlugins::NewL(*parameters); sl@0: sl@0: // Test CBaNamedPlugins constructor when fall back name is set sl@0: CImplementation obj; sl@0: (*parameters).SetFallBackName(obj); sl@0: delete namedPlugins; sl@0: namedPlugins = CBaNamedPlugins::NewL(*parameters); sl@0: sl@0: TInt count = (*namedPlugins).MdcaCount(); sl@0: TEST2(count,mdcaCount); sl@0: sl@0: count=arrayOfResourceFiles.Count(); sl@0: for( TInt i = 0; i < count; i++ ) sl@0: { sl@0: const CBaNamedPlugins::TResourceFile& resourceFileData=arrayOfResourceFiles[i]; sl@0: delete resourceFileData.iFullFileName; sl@0: } sl@0: CleanupStack::PopAndDestroy(&arrayOfResourceFiles); sl@0: delete parameters; sl@0: delete namedPlugins; sl@0: } sl@0: sl@0: LOCAL_C void StartTestPanicBadArrayPositionL() sl@0: { sl@0: CBaNamedPlugins* namedPlugins; sl@0: RArray arrayOfResourceFiles; sl@0: CleanupClosePushL(arrayOfResourceFiles); sl@0: RFs fs; sl@0: fs.Connect(); sl@0: TBuf<64> buf; sl@0: buf = KRscFileName2; sl@0: sl@0: // Test Panic sl@0: CBaNamedPlugins::TResourceFile resourceFile; sl@0: resourceFile.iFullFileName = buf.AllocLC(); sl@0: resourceFile.iIdentifier = NULL; sl@0: resourceFile.iUid = KNullUid; sl@0: resourceFile.iFormat = CBaNamedPlugins::TResourceFile::EFormatTbuf; sl@0: User::LeaveIfError(arrayOfResourceFiles.Append(resourceFile)); sl@0: CleanupStack::Pop(resourceFile.iFullFileName); sl@0: sl@0: CBaNamedPlugins::CParameters* const parameters = CBaNamedPlugins::CParameters::NewL(fs, arrayOfResourceFiles.Array()); sl@0: sl@0: HBufC* textForNone=KTextForNone().AllocL(); sl@0: parameters->SetTextForNone(textForNone,static_cast(255)); // Pick an illegal position sl@0: sl@0: // This should panic sl@0: namedPlugins = CBaNamedPlugins::NewL(*parameters); sl@0: sl@0: delete resourceFile.iFullFileName; sl@0: sl@0: CleanupStack::PopAndDestroy(&arrayOfResourceFiles); sl@0: delete parameters; sl@0: delete namedPlugins; sl@0: } sl@0: sl@0: LOCAL_C TInt TestPanicBadArrayPosition(TAny* /*aData*/) sl@0: { sl@0: __UHEAP_MARK; sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: if(!cleanup) sl@0: return KErrNoMemory; sl@0: sl@0: TRAPD(err, StartTestPanicBadArrayPositionL()); sl@0: sl@0: // Won't get here but add this line to get rid of ARMV5 warning sl@0: TEST2(err, KErrNone); sl@0: sl@0: delete cleanup; sl@0: __UHEAP_MARKEND; sl@0: sl@0: return (KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void StartTestPanicBadResourceFileFormatL() sl@0: { sl@0: CBaNamedPlugins* namedPlugins; sl@0: RArray arrayOfResourceFiles; sl@0: CleanupClosePushL(arrayOfResourceFiles); sl@0: RFs fs; sl@0: fs.Connect(); sl@0: TBuf<64> buf; sl@0: buf = KRscFileName2; sl@0: sl@0: // Test Panic sl@0: CBaNamedPlugins::TResourceFile resourceFile; sl@0: resourceFile.iFullFileName = buf.AllocLC(); sl@0: resourceFile.iIdentifier = NULL; sl@0: resourceFile.iUid = KNullUid; sl@0: resourceFile.iFormat = static_cast(255); // Pick an illegal format sl@0: User::LeaveIfError(arrayOfResourceFiles.Append(resourceFile)); sl@0: CleanupStack::Pop(resourceFile.iFullFileName); sl@0: sl@0: CBaNamedPlugins::CParameters* const parameters = CBaNamedPlugins::CParameters::NewL(fs, arrayOfResourceFiles.Array()); sl@0: sl@0: // This should panic sl@0: namedPlugins = CBaNamedPlugins::NewL(*parameters); sl@0: sl@0: delete resourceFile.iFullFileName; sl@0: sl@0: CleanupStack::PopAndDestroy(&arrayOfResourceFiles); sl@0: delete parameters; sl@0: delete namedPlugins; sl@0: } sl@0: sl@0: LOCAL_C TInt TestPanicBadResourceFileFormat(TAny* /*aData*/) sl@0: { sl@0: __UHEAP_MARK; sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: if(!cleanup) sl@0: return KErrNoMemory; sl@0: sl@0: TRAPD(err, StartTestPanicBadResourceFileFormatL()); sl@0: sl@0: // Won't get here but add this line to get rid of ARMV5 warning sl@0: TEST2(err, KErrNone); sl@0: sl@0: delete cleanup; sl@0: __UHEAP_MARKEND; sl@0: sl@0: return (KErrNone); sl@0: } sl@0: sl@0: /* sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-3379 sl@0: @SYMTestCaseDesc CBaNamedPlugins::CParameters class test sl@0: Tests the class panic conditions sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Cause the class to panic by setting bad enums. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ DEF101753 sl@0: */ sl@0: LOCAL_C void NamedPluginsPanicConditionsThread() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-3379 Testing CBaNamedPlugins Panics... ")); sl@0: TBool jitEnabled = User::JustInTime(); sl@0: User::SetJustInTime(EFalse); sl@0: sl@0: TRequestStatus status; sl@0: sl@0: _LIT(KName, "NamedPlugins_Panic_Thread"); sl@0: sl@0: RThread thread; sl@0: const TInt KThreadStackSize =0x2000; // 8k sl@0: const TInt KThreadMinHeapSize =0x4000; // 16k sl@0: const TInt KThreadMaxHeapSize =0xf000; // 60k sl@0: sl@0: // Test EBafPanicBadResourceFileFormat sl@0: TInt rc = thread.Create(KName,TestPanicBadResourceFileFormat,KThreadStackSize,KThreadMinHeapSize,KThreadMaxHeapSize,NULL); sl@0: sl@0: TEST(rc==KErrNone); sl@0: sl@0: thread.Logon(status); sl@0: thread.Resume(); sl@0: sl@0: User::WaitForRequest(status); sl@0: sl@0: // Should result in a EExitPanic exit type and an EBafPanicBadResourceFileFormat exit reason sl@0: TEST(thread.ExitType() == EExitPanic); sl@0: TEST(thread.ExitReason() == EBafPanicBadResourceFileFormat); sl@0: sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: // Test EBafPanicBadArrayPosition sl@0: rc = thread.Create(KName,TestPanicBadArrayPosition,KThreadStackSize,KThreadMinHeapSize,KThreadMaxHeapSize,NULL); sl@0: sl@0: TEST(rc==KErrNone); sl@0: sl@0: thread.Logon(status); sl@0: thread.Resume(); sl@0: sl@0: User::WaitForRequest(status); sl@0: sl@0: // Should result in a EExitPanic exit type and an EBafPanicBadArrayPosition exit reason sl@0: TEST(thread.ExitType() == EExitPanic); sl@0: TEST(thread.ExitReason() == EBafPanicBadArrayPosition); sl@0: sl@0: thread.Close(); sl@0: sl@0: User::SetJustInTime(jitEnabled); sl@0: } sl@0: sl@0: sl@0: void DoTestsL() sl@0: { sl@0: TheTest.Next(_L("Calling the tests")); sl@0: TheFs.Connect(); sl@0: CleanupClosePushL(TheFs); sl@0: sl@0: DoTests1();//Getting the resource file names from literals sl@0: DoTests2();//Getting the resource file names by performing a search on the file system sl@0: NamedPluginsPanicConditionsThread(); // Test Panic condition sl@0: sl@0: CleanupStack::PopAndDestroy(); // TheFs sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: TheTest.Title(); sl@0: TheTest.Start(_L("Testing CBaNamedPlugins Class")); sl@0: TRAPD(err,DoTestsL()); sl@0: TEST2(err,KErrNone); sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: delete cleanup; sl@0: sl@0: __UHEAP_MARKEND; sl@0: return(0); sl@0: }