os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/inc/testcasefactory.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/inc/testcasefactory.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,199 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// @internalComponent
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#ifndef TESTFACTORY_H
    1.22 +#define TESTFACTORY_H
    1.23 +
    1.24 +#include <e32base.h>
    1.25 +#include <e32hashtab.h>
    1.26 +#include <e32test.h>     // RTest headder
    1.27 +#include "testengine.h"
    1.28 +
    1.29 +// Test object
    1.30 +extern RTest test;
    1.31 +
    1.32 +
    1.33 +
    1.34 +const TInt KTestCaseIdLength(35); // current longest is 30
    1.35 +
    1.36 +// Forward declarations
    1.37 +class CTestCaseRoot;
    1.38 +
    1.39 +/**
    1.40 +This class describes an identity that consists of a string and will
    1.41 +be used for the key for the association map in the test factory
    1.42 +*/
    1.43 +class TStringIdentity
    1.44 +	{
    1.45 +public:
    1.46 +
    1.47 +	/**
    1.48 +	Constructor, build the identity from a string
    1.49 +	@param anIdentity the string that is used for a unique identity
    1.50 +	*/
    1.51 +	explicit TStringIdentity(const TDesC& anIdentity)
    1.52 +		{
    1.53 +		iIdentity.Copy(anIdentity);
    1.54 +		iIdentity.UpperCase();
    1.55 +		}
    1.56 +
    1.57 +	/**
    1.58 +	Generate a unique hash value from the key
    1.59 +	@param aKey the key i.e. string identity
    1.60 +	@return the 32bit unique hash value
    1.61 +	*/
    1.62 +	static TUint32 Hash(const TStringIdentity& aKey)
    1.63 +		{
    1.64 +		return DefaultHash::Des16(aKey.iIdentity);
    1.65 +		}
    1.66 +
    1.67 +	/**
    1.68 +	Compare the string identity of a target key with the element key
    1.69 +	@param aKeyTarget the target string identity 
    1.70 +	@param aKeyElement the current element key from the association map
    1.71 +	@return the boolean result
    1.72 +	*/
    1.73 +	static TBool Id(const TStringIdentity& aKeyTarget,const TStringIdentity& aKeyElement)
    1.74 +		{
    1.75 +		return aKeyElement.iIdentity == aKeyTarget.iIdentity;
    1.76 +		}
    1.77 +	
    1.78 +private:
    1.79 +
    1.80 +	// The identity as a string symbian descriptor
    1.81 +	TBuf<64> iIdentity;
    1.82 +	
    1.83 +	};
    1.84 +
    1.85 +/**
    1.86 +This class represents the test case factory
    1.87 +Design pattern used: Singleton,Factory
    1.88 +*/
    1.89 +class RTestFactory
    1.90 +	{
    1.91 +public:
    1.92 +
    1.93 +	/**
    1.94 +	The signature of the method to create the test case.  All test cases that have a receipt will have a method of being 
    1.95 +	created by this factory.
    1.96 +	*/
    1.97 +	typedef CTestCaseRoot* (*TCreationMethod)(TBool);
    1.98 +	typedef RHashMap<TStringIdentity,TCreationMethod> RFactoryMap;
    1.99 +
   1.100 +
   1.101 +	/**
   1.102 +	Destructor, Destroy the test factory
   1.103 +	*/
   1.104 +	~RTestFactory();
   1.105 +
   1.106 +	/**
   1.107 +	Register a test case with this factory.  If the test case could not be registered, the resultant
   1.108 +	error will be logged and when requested to be created the factory should state that the test case could
   1.109 +	not be supported.
   1.110 +	@param aTestCaseId the identity of the test case
   1.111 +	@param aCreationMethod the method used to create the test case
   1.112 +	*/
   1.113 +	static void RegisterTestCase(const TDesC& aTestCaseId,
   1.114 +	  TCreationMethod aTestCreationMethod);	
   1.115 +	
   1.116 +	/**
   1.117 +	Obtain a test case object that is for the given test case identity
   1.118 +	@param aTestCaseId the identity of the test case
   1.119 +	@return the test case object for the given identity
   1.120 +	@leave KErrNotSupported if the test case object was not found
   1.121 +	*/
   1.122 +	static CTestCaseRoot* CreateTestCaseL(const TDesC& aTestCaseId);
   1.123 +	
   1.124 +	/**
   1.125 +	Display through the use of the debug port, a list of all the test cases that 
   1.126 +	have registered themselves with the factory
   1.127 +	*/
   1.128 +	static void ListRegisteredTestCases(RPointerArray<HBufC> & testCaseNames);
   1.129 +	static void ListRegisteredTestCases() { RPointerArray<HBufC> test;ListRegisteredTestCases(test);test.ResetAndDestroy();};
   1.130 +	
   1.131 +	static TInt TestCaseCount() {	return(Instance().iTestCases.Count());	}
   1.132 +	
   1.133 +	static void GetTestID(TInt aIndex, TBuf<KTestCaseIdLength> &aTestID);
   1.134 +	
   1.135 +	static TBool TestCaseExists(const TDesC& aTestCaseId);
   1.136 +
   1.137 +private:
   1.138 +
   1.139 +	/**
   1.140 +	Constructor
   1.141 +	*/
   1.142 +	RTestFactory();
   1.143 +	
   1.144 +	/**
   1.145 +	Disable copy constructor
   1.146 +	*/
   1.147 +	RTestFactory(const RTestFactory& aRef);
   1.148 +		
   1.149 +	/**
   1.150 +	Disable assignment operator
   1.151 +	*/
   1.152 +	RTestFactory& operator=(const RTestFactory& aRhs);
   1.153 +		
   1.154 +	/**
   1.155 +	Retrieve the factory singleton instance
   1.156 +	@return the only instance of this class
   1.157 +	*/
   1.158 +	static RTestFactory& Instance();	
   1.159 +	
   1.160 +private:
   1.161 +
   1.162 +	/**
   1.163 +	The association between the test cases identities and the test case objects
   1.164 +	that have registered themselves with the factory (i.e. that are available)	
   1.165 +	*/
   1.166 +	RFactoryMap iTestCases;
   1.167 +	
   1.168 +	};
   1.169 +	
   1.170 +/**
   1.171 +This class represents the receipt object that when instantiated registers a test case class
   1.172 +in the Test case factory under its test case identity.
   1.173 +*/
   1.174 +template<typename T> // T: The test case class	
   1.175 +class TTestCaseFactoryReceipt
   1.176 +	{
   1.177 +public:
   1.178 +	/**
   1.179 +	Called by the factory when the _TestCaseClass needs to be instantiated
   1.180 +	@param aAutomation whether to bypass manual actions
   1.181 +	@return a pointer to the required test case object
   1.182 +	*/
   1.183 +	static CTestCaseRoot* CreateTestCaseL(TBool aAutomation)
   1.184 +		{
   1.185 +		// Use the symbian factory two phase constructor
   1.186 +		return T::NewL(aAutomation);
   1.187 +		}
   1.188 +	
   1.189 +	/**
   1.190 +	Constructor, builds on instantiation a factory receipt object for a test case
   1.191 +	@param aTestCaseId the identity of the test case for which this is a receipt for
   1.192 +	*/
   1.193 +	explicit TTestCaseFactoryReceipt(const TDesC& aTestCaseId)
   1.194 +		{
   1.195 +		RTestFactory::RegisterTestCase(aTestCaseId, CreateTestCaseL);		
   1.196 +		}
   1.197 +	};
   1.198 +
   1.199 +
   1.200 +
   1.201 +#endif // TESTFACTORY_H
   1.202 +