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.
22 #include <e32hashtab.h>
23 #include <e32test.h> // RTest headder
24 #include "testengine.h"
31 const TInt KTestCaseIdLength(35); // current longest is 30
33 // Forward declarations
37 This class describes an identity that consists of a string and will
38 be used for the key for the association map in the test factory
45 Constructor, build the identity from a string
46 @param anIdentity the string that is used for a unique identity
48 explicit TStringIdentity(const TDesC& anIdentity)
50 iIdentity.Copy(anIdentity);
51 iIdentity.UpperCase();
55 Generate a unique hash value from the key
56 @param aKey the key i.e. string identity
57 @return the 32bit unique hash value
59 static TUint32 Hash(const TStringIdentity& aKey)
61 return DefaultHash::Des16(aKey.iIdentity);
65 Compare the string identity of a target key with the element key
66 @param aKeyTarget the target string identity
67 @param aKeyElement the current element key from the association map
68 @return the boolean result
70 static TBool Id(const TStringIdentity& aKeyTarget,const TStringIdentity& aKeyElement)
72 return aKeyElement.iIdentity == aKeyTarget.iIdentity;
77 // The identity as a string symbian descriptor
83 This class represents the test case factory
84 Design pattern used: Singleton,Factory
91 The signature of the method to create the test case. All test cases that have a receipt will have a method of being
92 created by this factory.
94 typedef CTestCaseRoot* (*TCreationMethod)(TBool);
95 typedef RHashMap<TStringIdentity,TCreationMethod> RFactoryMap;
99 Destructor, Destroy the test factory
104 Register a test case with this factory. If the test case could not be registered, the resultant
105 error will be logged and when requested to be created the factory should state that the test case could
107 @param aTestCaseId the identity of the test case
108 @param aCreationMethod the method used to create the test case
110 static void RegisterTestCase(const TDesC& aTestCaseId,
111 TCreationMethod aTestCreationMethod);
114 Obtain a test case object that is for the given test case identity
115 @param aTestCaseId the identity of the test case
116 @return the test case object for the given identity
117 @leave KErrNotSupported if the test case object was not found
119 static CTestCaseRoot* CreateTestCaseL(const TDesC& aTestCaseId);
122 Display through the use of the debug port, a list of all the test cases that
123 have registered themselves with the factory
125 static void ListRegisteredTestCases(RPointerArray<HBufC> & testCaseNames);
126 static void ListRegisteredTestCases() { RPointerArray<HBufC> test;ListRegisteredTestCases(test);test.ResetAndDestroy();};
128 static TInt TestCaseCount() { return(Instance().iTestCases.Count()); }
130 static void GetTestID(TInt aIndex, TBuf<KTestCaseIdLength> &aTestID);
132 static TBool TestCaseExists(const TDesC& aTestCaseId);
142 Disable copy constructor
144 RTestFactory(const RTestFactory& aRef);
147 Disable assignment operator
149 RTestFactory& operator=(const RTestFactory& aRhs);
152 Retrieve the factory singleton instance
153 @return the only instance of this class
155 static RTestFactory& Instance();
160 The association between the test cases identities and the test case objects
161 that have registered themselves with the factory (i.e. that are available)
163 RFactoryMap iTestCases;
168 This class represents the receipt object that when instantiated registers a test case class
169 in the Test case factory under its test case identity.
171 template<typename T> // T: The test case class
172 class TTestCaseFactoryReceipt
176 Called by the factory when the _TestCaseClass needs to be instantiated
177 @param aAutomation whether to bypass manual actions
178 @return a pointer to the required test case object
180 static CTestCaseRoot* CreateTestCaseL(TBool aAutomation)
182 // Use the symbian factory two phase constructor
183 return T::NewL(aAutomation);
187 Constructor, builds on instantiation a factory receipt object for a test case
188 @param aTestCaseId the identity of the test case for which this is a receipt for
190 explicit TTestCaseFactoryReceipt(const TDesC& aTestCaseId)
192 RTestFactory::RegisterTestCase(aTestCaseId, CreateTestCaseL);
198 #endif // TESTFACTORY_H