sl@0: /* sl@0: * Copyright (c) 2001-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 the License "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: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "MTestInterface.h" sl@0: #include sl@0: sl@0: RTest test(_L("CT Framework Tests")); sl@0: sl@0: sl@0: sl@0: TBool gLogging=ETrue; sl@0: TBool gSilent=EFalse; sl@0: sl@0: const TInt gInterfaceA = 0x101f4e50; sl@0: const TInt gInterfaceB = 0x101f4e51; sl@0: const TInt gInterfaceC = 0x101f4e52; sl@0: sl@0: const TInt gAttribute1 = 0x101f4e4a; sl@0: const TInt gAttribute2 = 0x101f4e4b; sl@0: sl@0: const TInt gImplementation6 = 0x101f4e4c; sl@0: const TInt gImplementation5 = 0x101f4e4d; sl@0: sl@0: class CTestConsole:public CConsoleBase sl@0: sl@0: { sl@0: public: sl@0: static CTestConsole* NewL(CConsoleBase* aCon); sl@0: TInt Create(const TDesC16& aTitle,TSize aSize) {return iCon->Create(aTitle,aSize);}; sl@0: void Read(TRequestStatus& aStatus) {iCon->Read(aStatus);}; sl@0: void ReadCancel(void) {iCon->ReadCancel();}; sl@0: void Write(const TDesC16& aString); sl@0: TPoint CursorPos(void) const {return iCon->CursorPos();}; sl@0: void SetCursorPosAbs(const TPoint& aPos) {iCon->SetCursorPosAbs(aPos);}; sl@0: void SetCursorPosRel(const TPoint& aPos) {iCon->SetCursorPosRel(aPos);}; sl@0: void SetCursorHeight(TInt aHeight) {iCon->SetCursorHeight(aHeight);}; sl@0: void SetTitle(const TDesC16& aTitle) {iCon->SetTitle(aTitle);}; sl@0: void ClearScreen(void) {iCon->ClearScreen();}; sl@0: void ClearToEndOfLine(void) {iCon->ClearToEndOfLine();}; sl@0: TSize ScreenSize(void) const {return iCon->ScreenSize();}; sl@0: TKeyCode KeyCode(void) const {return iCon->KeyCode();}; sl@0: TUint KeyModifiers(void) const {return iCon->KeyModifiers();}; sl@0: ~CTestConsole(void); sl@0: void SetLogFile(RFile* aFile); sl@0: private: sl@0: CTestConsole(void); sl@0: CConsoleBase* iCon; sl@0: RFile* iFile; sl@0: }; sl@0: sl@0: CTestConsole* CTestConsole::NewL(CConsoleBase* aCon) sl@0: sl@0: { sl@0: CTestConsole* self; sl@0: self=new (ELeave) CTestConsole; sl@0: self->iCon=aCon; sl@0: self->iFile=NULL; sl@0: return self; sl@0: } sl@0: sl@0: CTestConsole::CTestConsole(void):CConsoleBase() sl@0: sl@0: { sl@0: } sl@0: sl@0: CTestConsole::~CTestConsole(void) sl@0: sl@0: { sl@0: delete iCon; sl@0: if (iFile) sl@0: { sl@0: iFile->Close(); sl@0: } sl@0: } sl@0: sl@0: void CTestConsole::Write(const TDesC16& aString) sl@0: sl@0: { sl@0: if (gSilent) sl@0: return; sl@0: iCon->Write(aString); sl@0: if ((iFile)&&(gLogging)) sl@0: { sl@0: TUint8 space[200]; sl@0: TPtr8 ptr(space,200); sl@0: ptr.Copy(aString); sl@0: iFile->Write(ptr); sl@0: } sl@0: } sl@0: sl@0: void CTestConsole::SetLogFile(RFile* aFile) sl@0: sl@0: { sl@0: iFile=aFile; sl@0: } sl@0: sl@0: template class TTestArray sl@0: { sl@0: public: sl@0: TTestArray(T* aArray, TInt aCount); sl@0: TArray Array(); sl@0: private: sl@0: static TInt Count(const CBase* aThat); sl@0: static const TAny* Get(const CBase* aThat, TInt aIndex); sl@0: sl@0: T* iArray; sl@0: TInt iCount; sl@0: }; sl@0: sl@0: template TTestArray::TTestArray(T* aArray, TInt aCount) sl@0: : iArray(aArray), iCount(aCount) sl@0: { sl@0: } sl@0: sl@0: template TInt TTestArray::Count(const CBase* aThat) sl@0: { sl@0: return reinterpret_cast(aThat)->iCount; sl@0: } sl@0: sl@0: template const TAny* TTestArray::Get(const CBase* aThat, TInt aIndex) sl@0: { sl@0: return &reinterpret_cast(aThat)->iArray[aIndex]; sl@0: } sl@0: sl@0: template TArray TTestArray::Array() sl@0: { sl@0: return TArray(Count, Get, reinterpret_cast(this)); sl@0: } sl@0: sl@0: /** A filter that includes nothing (as a random easy-to-write test filter */ sl@0: class TNoTokenTypes : public MCTTokenTypeFilter sl@0: { sl@0: public: sl@0: /** Always returns EFalse. */ sl@0: virtual TBool Accept(const CCTTokenTypeInfo& aTokenType) const; sl@0: }; sl@0: sl@0: // Accept everything sl@0: TBool TNoTokenTypes::Accept(const CCTTokenTypeInfo&) const sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: class CStopScheduler : public CActive sl@0: { sl@0: public: sl@0: void DoCancel() {}; sl@0: void RunL(); sl@0: CStopScheduler(); sl@0: }; sl@0: sl@0: void CStopScheduler::RunL() sl@0: { sl@0: CActiveScheduler::Stop(); sl@0: }; sl@0: sl@0: CStopScheduler::CStopScheduler() sl@0: : CActive(EPriorityIdle) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: SetActive(); sl@0: TRequestStatus* r = &iStatus; sl@0: User::RequestComplete(r, KErrNone); sl@0: } sl@0: sl@0: TInt TokenTypeInfoListTestsL() sl@0: { sl@0: test.Printf(_L("1.1,Testing getting all token types,")); sl@0: RCPointerArray myTokenTypes; sl@0: CleanupClosePushL(myTokenTypes); sl@0: sl@0: CCTTokenTypeInfo::ListL(myTokenTypes); sl@0: sl@0: if (myTokenTypes.Count() < 6) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (1); sl@0: } sl@0: sl@0: myTokenTypes.ResetAndDestroy(); sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("1.2,Testing user-supplied filter,")); sl@0: TNoTokenTypes filter; sl@0: CCTTokenTypeInfo::ListL(myTokenTypes, filter); sl@0: sl@0: if (myTokenTypes.Count() > 0) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (2); sl@0: } sl@0: sl@0: myTokenTypes.ResetAndDestroy(); sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("1.3,Testing finding filters matching 1 interface,")); sl@0: RArray a; sl@0: TUid aa = {gInterfaceA}; sl@0: User::LeaveIfError(a.Append(aa)); sl@0: CleanupClosePushL(a); sl@0: TCTFindTokenTypesByInterface findA(a.Array()); sl@0: CCTTokenTypeInfo::ListL(myTokenTypes, findA); sl@0: if (myTokenTypes.Count() != 4) sl@0: { sl@0: CleanupStack::PopAndDestroy(2); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (3); sl@0: } sl@0: TInt findAResults[] = {1,4,5,6}; sl@0: TInt flag[] = {1,1,1,1}; sl@0: for (TInt ii = 0; ii < 4; ii++) sl@0: { sl@0: TInt count = 0; sl@0: TInt iii=0; sl@0: TBuf<20> matchString; sl@0: _LIT(format, "Test Token Type %d"); sl@0: matchString.Format(format, findAResults[iii]); sl@0: TBuf<20> idisplay_name= myTokenTypes[ii]->Label(); sl@0: sl@0: if (matchString.Compare(idisplay_name)) sl@0: count++; sl@0: else sl@0: { sl@0: if(flag[0]==1) sl@0: flag[0]=0; sl@0: else sl@0: count++; sl@0: } sl@0: matchString.Format(format, findAResults[iii+1]); sl@0: if (matchString.Compare(idisplay_name)) sl@0: count++; sl@0: else sl@0: { sl@0: if(flag[1]==1) sl@0: flag[1]=0; sl@0: else sl@0: count++; sl@0: } sl@0: matchString.Format(format, findAResults[iii+2]); sl@0: if (matchString.Compare(idisplay_name)) sl@0: count++; sl@0: else sl@0: { sl@0: if(flag[2]==1) sl@0: flag[2]=0; sl@0: else sl@0: count++; sl@0: } sl@0: matchString.Format(format, findAResults[iii+3]); sl@0: if (matchString.Compare(idisplay_name)) sl@0: count++; sl@0: else sl@0: { sl@0: if(flag[3]==1) sl@0: flag[3]=0; sl@0: else sl@0: count++; sl@0: } sl@0: if(count==4) sl@0: { sl@0: CleanupStack::PopAndDestroy(2); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (4); sl@0: } sl@0: } sl@0: sl@0: myTokenTypes.ResetAndDestroy(); sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("1.5,Testing finding filters matching 2 interfaces,")); sl@0: TUid aAndB[] = {{gInterfaceA}, {gInterfaceB}}; sl@0: TTestArray aAndBArray(aAndB, 2); sl@0: TCTFindTokenTypesByInterface findAAndB(aAndBArray.Array()); sl@0: CCTTokenTypeInfo::ListL(myTokenTypes, findAAndB); sl@0: if (myTokenTypes.Count() != 2) sl@0: { sl@0: CleanupStack::PopAndDestroy(2); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (5); sl@0: } sl@0: TInt findAAndBResults[] = {4,6}; sl@0: TInt flag1[] = {1,1}; sl@0: for (TInt jj = 0; jj < 2; jj++) sl@0: { sl@0: TInt count = 0; sl@0: TInt jjj=0; sl@0: TBuf<20> matchString; sl@0: _LIT(format, "Test Token Type %d"); sl@0: matchString.Format(format, findAAndBResults[jjj]); sl@0: TBuf<20> idisplay_name = myTokenTypes[jj]->Label(); sl@0: if (matchString.Compare(idisplay_name)) sl@0: count++; sl@0: else sl@0: { sl@0: if(flag1[0]==1) sl@0: flag1[0]=0; sl@0: else sl@0: count++; sl@0: } sl@0: matchString.Format(format, findAAndBResults[jjj+1]); sl@0: if (matchString.Compare(idisplay_name)) sl@0: count++; sl@0: else sl@0: { sl@0: if(flag1[1]==1) sl@0: flag1[1]=0; sl@0: else sl@0: count++; sl@0: } sl@0: if(count==2) sl@0: { sl@0: CleanupStack::PopAndDestroy(2); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (6); sl@0: } sl@0: } sl@0: sl@0: // NOTE No ResetAndDestroy sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("1.6,Testing appending interface infos,")); sl@0: CCTTokenTypeInfo::ListL(myTokenTypes, findA); sl@0: if (myTokenTypes.Count() != 6) sl@0: { sl@0: CleanupStack::PopAndDestroy(2); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (7); sl@0: } sl@0: TInt flag2[] = {1,1,1,1}; sl@0: for (TInt kk = 0; kk < 4; kk++) sl@0: { sl@0: TInt count = 0; sl@0: TInt kkk=0; sl@0: TBuf<20> matchString; sl@0: _LIT(format, "Test Token Type %d"); sl@0: matchString.Format(format, findAResults[kkk]); sl@0: TBuf<20> idisplay_name = myTokenTypes[kk+2]->Label(); sl@0: if (matchString.Compare(idisplay_name)) sl@0: count++; sl@0: else sl@0: { sl@0: if(flag2[0]==1) sl@0: flag2[0]=0; sl@0: else sl@0: count++; sl@0: } sl@0: matchString.Format(format, findAResults[kkk+1]); sl@0: if (matchString.Compare(idisplay_name)) sl@0: count++; sl@0: else sl@0: { sl@0: if(flag2[1]==1) sl@0: flag2[1]=0; sl@0: else sl@0: count++; sl@0: } sl@0: matchString.Format(format, findAResults[kkk+2]); sl@0: if (matchString.Compare(idisplay_name)) sl@0: count++; sl@0: else sl@0: { sl@0: if(flag2[2]==1) sl@0: flag2[2]=0; sl@0: else sl@0: count++; sl@0: } sl@0: matchString.Format(format, findAResults[kkk+3]); sl@0: if (matchString.Compare(idisplay_name)) sl@0: count++; sl@0: else sl@0: { sl@0: if(flag2[3]==1) sl@0: flag2[3]=0; sl@0: else sl@0: count++; sl@0: } sl@0: if(count==4) sl@0: { sl@0: CleanupStack::PopAndDestroy(2); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (8); sl@0: } sl@0: } sl@0: sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: myTokenTypes.ResetAndDestroy(); sl@0: test.Printf(_L("1.7,Testing filtering by interface and attribute,")); sl@0: TCTTokenTypeAttribute att = {{gAttribute1}, 1}; sl@0: RArray attArray(sizeof(TCTTokenTypeAttribute), &att, sl@0: 1); sl@0: TCTFindTokenTypesByInterfaceAndAttribute findAWithAtt1(a.Array(), sl@0: attArray.Array()); sl@0: CCTTokenTypeInfo::ListL(myTokenTypes, findAWithAtt1); sl@0: if (myTokenTypes.Count() != 1) sl@0: { sl@0: CleanupStack::PopAndDestroy(2); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (9); sl@0: } sl@0: _LIT(KMatch, "Test Token Type 6"); sl@0: if (myTokenTypes[0]->Label() != KMatch) sl@0: { sl@0: CleanupStack::PopAndDestroy(2); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (10); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: CleanupStack::PopAndDestroy(2); sl@0: return KErrNone; sl@0: }; sl@0: sl@0: TInt TokenTypeInfoTestsL() sl@0: { sl@0: test.Printf(_L("2.1,Testing token type for tests,")); sl@0: RCPointerArray myTokenTypes; sl@0: CleanupClosePushL(myTokenTypes); sl@0: TUid aABndC[] = {{gInterfaceA}, {gInterfaceB}, {gInterfaceC}}; sl@0: TTestArray aABndCArray(aABndC, 3); sl@0: TCTFindTokenTypesByInterface findABAndC(aABndCArray.Array()); sl@0: CCTTokenTypeInfo::ListL(myTokenTypes, findABAndC); sl@0: if (myTokenTypes.Count() != 1) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (1); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("2.2,Test UID function,")); sl@0: CCTTokenTypeInfo* info = myTokenTypes[0]; sl@0: if (info->Type().iUid != gImplementation6) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (1); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("2.3,Test getting an array of interfaces,")); sl@0: RArray interfaces = info->Interfaces(); sl@0: if (interfaces.Count() != 3) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (4); sl@0: } sl@0: TUid refInterfaces[] = {{gInterfaceA}, {gInterfaceB}, {gInterfaceC}}; sl@0: for (TInt ii = 0; ii < 3; ii++) sl@0: { sl@0: if (interfaces[ii] != refInterfaces[ii]) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (5); sl@0: } sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("2.4,Test getting an array of attributes,")); sl@0: RArray attributes = info->Attributes(); sl@0: if (attributes.Count() != 2) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (8); sl@0: } sl@0: TCTTokenTypeAttribute refAttributes[] = sl@0: {{{gAttribute2}, 2}, {{gAttribute1}, 1}}; sl@0: for (TInt jj = 0; jj < 2; jj++) sl@0: { sl@0: if (attributes[jj].iUID != refAttributes[jj].iUID || sl@0: attributes[jj].iVal != refAttributes[jj].iVal) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (9); sl@0: } sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("2.5,Test getting the label,")); sl@0: _LIT(KLabel, "Test Token Type 6"); sl@0: if (info->Label() != KLabel) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (10); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("2.6,Test getting the type of the token type,")); sl@0: TUid impl6 = {gImplementation6}; sl@0: if (info->Type() != impl6) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (11); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: CleanupStack::PopAndDestroy(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: TInt TestTokenTypeL(MCTTokenType* aTokenType, TInt aNum) sl@0: { sl@0: test.Printf(_L("3.4.1,Getting token info,")); sl@0: RCPointerArray tokenInfo; sl@0: CleanupClosePushL(tokenInfo); sl@0: TRequestStatus status = KRequestPending; sl@0: aTokenType->List(tokenInfo, status); sl@0: // Cancel call is pointelss as it does nothing in the test sl@0: // plugin. But it won't do any harm to check it doesn't explode. sl@0: aTokenType->CancelList(); sl@0: User::WaitForRequest(status); sl@0: if (status.Int() != KErrNone || tokenInfo.Count() != 1) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (100); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("3.4.1,Checking token type name,")); sl@0: TBuf<20> buf; sl@0: _LIT(KLabelFormat, "Test Token Type %d"); sl@0: buf.Format(KLabelFormat, aNum); sl@0: if (aTokenType->Label().Compare(buf)) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (105); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("3.4.2,Checking token type Type UID,")); sl@0: TUid uid = {gImplementation5 + 5 - aNum}; sl@0: if (aTokenType->Type() != uid) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (105); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("3.4.3,Checking token name,")); sl@0: _LIT(KFormat, "Test Token %d"); sl@0: buf.Format(KFormat, aNum); sl@0: if (buf.Compare(*tokenInfo[0])) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (101); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("3.4.4,Opening token,")); sl@0: status = KRequestPending; sl@0: MCTToken* token; sl@0: aTokenType->OpenToken(*tokenInfo[0], token, status); sl@0: // Cancel call will fail as token isn't opened asynchronous. Check sl@0: // that the reference counting still works. sl@0: aTokenType->CancelOpenToken(); sl@0: User::WaitForRequest(status); sl@0: if (status.Int() != KErrNone) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (102); sl@0: } sl@0: token->Release(); sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("3.4.5,Opening token by handle,")); sl@0: status = KRequestPending; sl@0: TCTTokenHandle handle(aTokenType->Type(), 1); sl@0: aTokenType->OpenToken(handle, token, status); sl@0: User::WaitForRequest(status); sl@0: if (status.Int() != KErrNone) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (102); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("3.4.6,Checking token's TokenType() function,")); sl@0: if (&token->TokenType() != aTokenType) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (102); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: _LIT(KVersion, "The Ultimate Version"); sl@0: _LIT(KSerial, "Serial No. 1"); sl@0: _LIT(KManufacturer, "ACME Corporation"); sl@0: sl@0: test.Printf(_L("3.4.6.1,Checking token's Information() function,")); sl@0: if (token->Information(MCTToken::EVersion) != KVersion || sl@0: token->Information(MCTToken::ESerialNo) != KSerial || sl@0: token->Information(MCTToken::EManufacturer) != KManufacturer) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (102); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("3.4.7,Registering for removal notification,")); sl@0: // This is another test to check that an API doesn't crash. We sl@0: // call the base NotifyOnRemoval/CancelNotify functions and check sl@0: // they do nothing! There's no point in creating derived versions sl@0: // that do something as that would be testing the test plugin, not sl@0: // the framework. sl@0: TRequestStatus removalStatus; sl@0: token->NotifyOnRemoval(removalStatus); sl@0: token->CancelNotify(); sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("3.4.9,Testing cancellation of async interface opening,")); sl@0: MTestInterface* interface; sl@0: MCTTokenInterface* temp; sl@0: TUid intB = {gInterfaceB}; sl@0: token->GetInterface(intB, temp, status); sl@0: token->CancelGetInterface(); sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("3.4.10,Opening an interface,")); sl@0: status = KRequestPending; sl@0: TUid intC = {gInterfaceC}; sl@0: token->GetInterface(intC, temp, status); sl@0: interface = static_cast(temp); sl@0: // Cancel call is pointelss as it does nothing in the test sl@0: // plugin. But it won't do any harm to check it doesn't explode. sl@0: token->CancelGetInterface(); sl@0: CleanupReleasePushL(*interface); sl@0: token->Release(); sl@0: User::WaitForRequest(status); sl@0: if (status.Int() != KErrNone) sl@0: { sl@0: CleanupStack::PopAndDestroy(2); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (103); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("3.4.11,Checking interface name,")); sl@0: if (buf.Compare(interface->Label())) sl@0: { sl@0: CleanupStack::PopAndDestroy(2); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (104); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("3.4.12,Getting an object,")); sl@0: MTestObject* object = interface->ObjectL(); sl@0: object->Release(); sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: CleanupStack::PopAndDestroy(2); sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt TokenTypeTestsL() sl@0: { sl@0: test.Printf(_L("3.1,Getting token types for tests,")); sl@0: RFs fs; sl@0: RCPointerArray myTokenTypes; sl@0: CleanupClosePushL(myTokenTypes); sl@0: TUid aABndC[] = {{gInterfaceA}, {gInterfaceB}, {gInterfaceC}}; sl@0: TTestArray aABandCArray(aABndC, 3); sl@0: TCTFindTokenTypesByInterface findABAndC(aABandCArray.Array()); sl@0: CCTTokenTypeInfo::ListL(myTokenTypes, findABAndC); sl@0: if (myTokenTypes.Count() != 1) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (1); sl@0: } sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: test.Printf(_L("3.2,Loading token type 6,")); sl@0: MCTTokenType* token6 = MCTTokenType::NewL(*myTokenTypes[0], fs); sl@0: if (!token6) sl@0: { sl@0: CleanupStack::PopAndDestroy(); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (1); sl@0: } sl@0: CleanupReleasePushL(*token6); sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: TInt ret = TestTokenTypeL(token6, 6); sl@0: if (ret) sl@0: { sl@0: CleanupStack::PopAndDestroy(2); sl@0: return ret; sl@0: } sl@0: sl@0: test.Printf(_L("3.3,Loading token type 5,")); sl@0: TUid UID5 = {gImplementation5}; sl@0: MCTTokenType* token5 = MCTTokenType::NewL(UID5, fs); sl@0: if (!token5) sl@0: { sl@0: CleanupStack::PopAndDestroy(2); sl@0: test.Printf(_L("FAILED\r\n")); sl@0: return (2); sl@0: } sl@0: CleanupReleasePushL(*token5); sl@0: test.Printf(_L("PASSED\r\n")); sl@0: sl@0: ret = TestTokenTypeL(token5, 5); sl@0: CleanupStack::PopAndDestroy(3); sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: TInt MemoryTestL(TInt (*aFnToTest)()) sl@0: { sl@0: gLogging = EFalse; sl@0: for (TInt ii = 1; ; ii++) sl@0: { sl@0: if (ii % 10) sl@0: test.Printf(_L(".")); sl@0: else sl@0: test.Printf(_L("*")); sl@0: if (!(ii % 50)) sl@0: test.Printf(_L("\r\n")); sl@0: gSilent = ETrue; sl@0: __UHEAP_MARK; sl@0: __UHEAP_FAILNEXT(ii); sl@0: TRAPD(err,aFnToTest()); sl@0: __UHEAP_RESET; sl@0: REComSession::FinalClose(); sl@0: __UHEAP_MARKEND; sl@0: User::Heap().Check(); sl@0: gSilent = EFalse; sl@0: if (err != KErrNoMemory) sl@0: { sl@0: test.Printf(_L("\r\n")); sl@0: gLogging = ETrue; sl@0: return err; sl@0: } sl@0: } sl@0: } sl@0: sl@0: void TestsL(void) sl@0: { sl@0: CActiveScheduler* as = new(ELeave) CActiveScheduler; sl@0: CActiveScheduler::Install(as); sl@0: sl@0: TInt errors = 0; sl@0: TInt ret; sl@0: __UHEAP_MARK; sl@0: ret = TokenTypeInfoListTestsL(); sl@0: REComSession::FinalClose(); sl@0: __UHEAP_MARKEND; sl@0: if (ret) sl@0: { sl@0: test.Printf(_L("1.9,ERROR %d in Info List test,FAILED\r\n"),ret); sl@0: errors++; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("1.9,Info List test,PASSED\r\n"),ret); sl@0: } sl@0: __UHEAP_MARK; sl@0: ret = TokenTypeInfoTestsL(); sl@0: REComSession::FinalClose(); sl@0: __UHEAP_MARKEND; sl@0: if (ret) sl@0: { sl@0: test.Printf(_L("2.9,ERROR %d in Info test,FAILED\r\n"),ret); sl@0: errors++; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("2.9,Info test,PASSED\r\n"),ret); sl@0: } sl@0: sl@0: __UHEAP_MARK; sl@0: ret = TokenTypeTestsL(); sl@0: REComSession::FinalClose(); sl@0: __UHEAP_MARKEND; sl@0: if (ret) sl@0: { sl@0: test.Printf(_L("3.9,ERROR %d in token test,FAILED\r\n"),ret); sl@0: errors++; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("3.9,token test,PASSED\r\n"),ret); sl@0: } sl@0: sl@0: ret = MemoryTestL(TokenTypeInfoListTestsL); sl@0: if (ret) sl@0: { sl@0: test.Printf(_L("4.9,ERROR %d in Info List memory test,FAILED\r\n"),ret); sl@0: errors++; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("4.9,Info List memory test,PASSED\r\n"),ret); sl@0: } sl@0: ret = MemoryTestL(TokenTypeTestsL); sl@0: if (ret) sl@0: { sl@0: test.Printf(_L("5.9,ERROR %d in Token Type memory test,FAILED\r\n"),ret); sl@0: errors++; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("5.9,Token Type memory test,PASSED\r\n"),ret); sl@0: } sl@0: sl@0: test.Printf(_L("%d tests failed out of 44 hardcoded\r\n"), errors); sl@0: sl@0: sl@0: if (errors) sl@0: { sl@0: test.Printf(_L("%d TESTS FAILED\r\n"),errors); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("ALL TESTS PASSED\r\n")); sl@0: } sl@0: sl@0: delete as; sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main(void) sl@0: sl@0: { sl@0: CTrapCleanup* cleanup; sl@0: cleanup=CTrapCleanup::New(); sl@0: test.Start(_L(" @SYMTestCaseID:SEC-CRYPTOTOKENS-CTFRAMEWORK-0001 Starting token framework tests\r\n")); sl@0: CTestConsole* con=NULL; sl@0: TRAPD(ret,con=CTestConsole::NewL(test.Console())); sl@0: RFs fs; sl@0: if (gLogging) sl@0: { sl@0: User::LeaveIfError(fs.Connect()); sl@0: RFile* file; sl@0: file=new (ELeave) RFile; sl@0: TDriveUnit sysDrive (fs.GetSystemDrive()); sl@0: TDriveName driveName(sysDrive.Name()); sl@0: TBuf<64> logFile (driveName); sl@0: logFile.Append(_L("\\T_CTFrameworkLog.txt")); sl@0: User::LeaveIfError(file->Replace(fs, logFile, EFileShareAny|EFileWrite)); sl@0: con->SetLogFile(file); sl@0: } sl@0: test.SetConsole(con); sl@0: TRAP(ret,TestsL()); sl@0: if (ret) sl@0: { sl@0: test.Printf(_L("Unexpected leave\r\n")); sl@0: } sl@0: gLogging=EFalse; sl@0: test.Close(); sl@0: delete cleanup; sl@0: return(KErrNone); sl@0: }