Update contrib.
1 #ifndef __TEST_FACTORY_H
2 #define __TEST_FACTORY_H
5 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
7 * This component and the accompanying materials are made available
8 * under the terms of the License "Eclipse Public License v1.0"
9 * which accompanies this distribution, and is available
10 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
12 * Initial Contributors:
13 * Nokia Corporation - initial contribution.
18 * @file TestCaseFactory.h
27 #include <e32hashtab.h>
29 #include "testdebug.h"
30 #include "basetestcase.h"
32 const TInt KTestCaseIdLength(18);
40 namespace NUnitTesting_USBDI
44 This class describes an identity that consists of a string and will
45 be used for the key for the association map in the test factory
51 Generate a unique has value from the key
52 @param aKey the key i.e. string identity
53 @return the 32bit unique hash value
55 static TUint32 Hash(const TStringIdentity& aKey)
57 return DefaultHash::Des16(aKey.iIdentity);
61 Compare the string identity of a target key with the element key
62 @param aKeyTarget the target string identity
63 @param aKeyElement the current element key from the association map
64 @return the boolean result
66 static TBool Id(const TStringIdentity& aKeyTarget,const TStringIdentity& aKeyElement)
68 return aKeyElement.iIdentity == aKeyTarget.iIdentity;
74 Constructor, build the identity from a string
75 @param anIdentity the string that is used for a unique identity
77 explicit TStringIdentity(const TDesC& anIdentity)
79 iIdentity.Copy(anIdentity);
80 iIdentity.UpperCase();
85 The identity as a string symbian descriptor
93 class TBaseTestCaseFunctor
96 virtual CBaseTestCase* operator()(TBool) const = 0;
101 This class represents the test case factory
102 Design pattern used: Singleton,Factory
107 // The signature for the container of test case associations
109 typedef RHashMap<TStringIdentity,TBaseTestCaseFunctor const*> RFactoryMap;
114 Destructor, Destroy the test factory
121 Register a test case with this factory. If the test case could not be registered, the resultant
122 error will be logged and when requested to be created the factory should state that the test case could
124 @param aTestCaseId the identity of the test case
125 @param aCreationMethod the method used to create the test case
127 static void RegisterTestCase(const TDesC& aTestCaseId,TBaseTestCaseFunctor const* aFunctor);
130 Obtain a test case object that is for the given test case identity
131 @param aTestCaseId the identity of the test case
132 @return the test case object for the given identity
133 @leave KErrNotSupported if the test case object was not found
135 static CBaseTestCase* CreateTestCaseL(const TDesC& aTestCaseId,TBool aHostRole);
138 Display through the use of the debug port, a list of all the test cases that
139 have registered themselves with the factory
141 static void ListRegisteredTestCases();
150 Disable copy constructor
152 RTestFactory(const RTestFactory& aRef);
155 Disable assignment operator
157 RTestFactory& operator=(const RTestFactory& aRhs);
160 Retrieve the factory singleton instance
161 @return the only instance of this class
163 static RTestFactory& Instance();
167 The association between the test cases identities and the test case objects
168 that have registered themselves with the factory (i.e. that are available)
170 RFactoryMap iTestCases;
178 This functor class represents the receipt object that when instantiated registers a test case class
179 in the Test case factory under its test case identity.
181 template<typename TestCase,typename Parameter>
182 class TFunctorTestCase : public TBaseTestCaseFunctor
186 The signature of the method to create the test case. All test cases that have a receipt will have a method of being
187 created by this factory.
189 typedef TestCase* (*TSymbianTwoPhaseCreationMethod)(Parameter);
193 Constructor, builds on instantiation a factory receipt object for a test case
194 @param aTestCaseId the identity of the test case for which this is a receipt for
196 explicit TFunctorTestCase(const TDesC& aTestCaseId)
198 iCreationMethod = TestCase::NewL;
199 RTestFactory::RegisterTestCase(aTestCaseId,this);
203 The invoker function to create a test case
204 @param aHostFlag the flag to indicate at construction time a host or client test case
205 @return the test case
207 CBaseTestCase* operator()(TBool aHostFlag) const
209 return iCreationMethod(aHostFlag);
214 The creation method that will creation the test case when instructed to by the factory
216 TSymbianTwoPhaseCreationMethod iCreationMethod;