First public contribution.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // @file testcasefactory.cpp
19 #include "TestCaseFactory.h"
20 #include "testdevicebase.h"
23 namespace NUnitTesting_USBDI
26 RTestFactory& RTestFactory::Instance()
28 static RTestFactory singleton;
32 RTestFactory::~RTestFactory()
37 RTestFactory::RTestFactory()
38 : iTestCases(TStringIdentity::Hash,TStringIdentity::Id)
42 void RTestFactory::RegisterTestCase(const TDesC& aTestCaseId,TBaseTestCaseFunctor const* aFunctor)
46 LOG_INFO((_L("Registering test case '%S'"),&aTestCaseId))
48 TStringIdentity key(aTestCaseId);
49 TInt err(Instance().iTestCases.Insert(key,aFunctor));
52 // Log that a test case could not be registered due to err
53 RDebug::Printf("Test case '%S' could not be registered with test case factory",&aTestCaseId);
58 CBaseTestCase* RTestFactory::CreateTestCaseL(const TDesC& aTestCaseId,TBool aHostRole)
62 TStringIdentity key(aTestCaseId);
63 const TBaseTestCaseFunctor& functor = *(*Instance().iTestCases.Find(key));
64 return functor(aHostRole);
68 void RTestFactory::ListRegisteredTestCases()
71 RFactoryMap::TIter it(Instance().iTestCases);
73 RDebug::Printf("-------- F A C T O R Y ---------");
76 for(count=0; count<Instance().iTestCases.Count(); count++)
78 RDebug::Printf("%d: %S",count,it.NextKey());
81 RDebug::Printf("--------------------------------");