diff -r 000000000000 -r bde4ae8d615e os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcasefactory.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcasefactory.cpp Fri Jun 15 03:10:57 2012 +0200 @@ -0,0 +1,207 @@ +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// @internalComponent +// +// + +#include +#include +#include // unicode builds +#include +#include +#include +#include // RTest headder +#include +#include +#include "TestCaseFactory.h" +#include "debugmacros.h" + + + +RTestFactory& RTestFactory::Instance() + { + static RTestFactory singleton; + return singleton; + } + + +RTestFactory::~RTestFactory() + { + } + + +RTestFactory::RTestFactory() +: iTestCases(TStringIdentity::Hash,TStringIdentity::Id) + { + } + + +void RTestFactory::RegisterTestCase(const TDesC& aTestCaseId,TCreationMethod aCreationMethod) + { + //LOG_FUNC + TStringIdentity key(aTestCaseId); + TInt err(Instance().iTestCases.Insert(key,aCreationMethod)); + if (err != KErrNone) + { + // Log that a test case could not be registered due to err + RDebug::Print(_L("Test case '%S' could not be registered with test case factory"),&aTestCaseId); + } + else + { + RTestFactory::TCreationMethod* creatorFunction = Instance().iTestCases.Find(key); + if (creatorFunction == NULL) + { + RDebug::Print(_L(" Test case '%S' did not register"),&aTestCaseId); + ListRegisteredTestCases(); + } + else + { + RDebug::Print(_L("Test case '%S' registered in factory"),&aTestCaseId); + } + } + } + + +TBool RTestFactory::TestCaseExists(const TDesC& aTestCaseId) + { + RTestFactory::TCreationMethod creatorFunction; + TStringIdentity key(aTestCaseId); + + creatorFunction = REINTERPRET_CAST(RTestFactory::TCreationMethod, Instance().iTestCases.Find(key)); + return (NULL != creatorFunction); + } + + +/* Returns the test ID (name) of test at offset aIndex in the MAP + */ +void RTestFactory::GetTestID(TInt aIndex, TBuf &aTestID) + { + LOG_FUNC + + RFactoryMap::TIter it(Instance().iTestCases); + + TInt count(0); + for (count=0; count *p = REINTERPRET_CAST(TBuf<64>*, &k); + + aTestID.Copy( *p); + return; + } + } + // Error: Case not found! + User::Leave(-2); + } + + +/* Return the ordinal value of the Test ID (numeric portion) + */ +TInt TestIDValue(const TDesC & aTestID) + { + TUint16 value; + TBuf id; + id = aTestID.Right(4); + TLex lex(id); + if (KErrNone == lex.Val(value, EDecimal)) + return(value); + return(-1); + } + +/* Print the test IDs in numerical order + * Returns a sorted array of strings containing all of the test IDs + */ +void RTestFactory::ListRegisteredTestCases(RPointerArray & aTestCaseNameArr) + { + LOG_FUNC + RFactoryMap::TIter it(Instance().iTestCases); + TInt count(0); + TInt cases(Instance().iTestCases.Count()); + + test.Printf(_L("------ F A C T O R Y -------\n")); + + it.Reset(); + for (count=0; count *p = REINTERPRET_CAST(TBuf*, &k); // pointer to the test ID + TBool placed(EFalse); + TInt pos(0); + TInt val(0); + + // build the sorted list + while (!placed) + { + val = TestIDValue(*p); + if (aTestCaseNameArr.Count()==pos) + { //array empty or reached end + HBufC* testIdentity = HBufC::NewLC(KTestCaseIdLength); + *testIdentity = *p; + aTestCaseNameArr.Append(testIdentity); + CleanupStack::Pop(testIdentity); + placed = ETrue; + } + else + { + if ( val < TestIDValue(*aTestCaseNameArr[pos]) ) + { + HBufC* testIdentity = HBufC::NewLC(KTestCaseIdLength); + *testIdentity = *p; + aTestCaseNameArr.Insert(testIdentity, pos); + placed = ETrue; + CleanupStack::Pop(testIdentity); + } + else + { + pos++; + } + } + } + } + // print it + for (count=0; count Test case '%S' not supported"),err,&aTestCaseId); + ListRegisteredTestCases(); + User::Leave(err); + } + + RDebug::Print(_L("Creating test case '%S'"),&aTestCaseId); + + // Call the creator function to create the test case object + return creatorFunction(gSemiAutomated); + } + +