kerneltest/e32test/usbho/t_otgdi/src/testcasefactory.cpp
changeset 259 57b9594f5772
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    24 #include <e32Test.h>	// RTest headder
    24 #include <e32Test.h>	// RTest headder
    25 #include <e32def.h>
    25 #include <e32def.h>
    26 #include <e32def_private.h>
    26 #include <e32def_private.h>
    27 #include "TestCaseFactory.h"
    27 #include "TestCaseFactory.h"
    28 #include "debugmacros.h"
    28 #include "debugmacros.h"
       
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "testcasefactoryTraces.h"
       
    32 #endif
    29 
    33 
    30 
    34 
    31 	
    35 	
    32 RTestFactory& RTestFactory::Instance()
    36 RTestFactory& RTestFactory::Instance()
    33 	{
    37 	{
    47 	}
    51 	}
    48 	
    52 	
    49 	
    53 	
    50 void RTestFactory::RegisterTestCase(const TDesC& aTestCaseId,TCreationMethod aCreationMethod)
    54 void RTestFactory::RegisterTestCase(const TDesC& aTestCaseId,TCreationMethod aCreationMethod)
    51 	{
    55 	{
    52 	//LOG_FUNC
       
    53 	TStringIdentity key(aTestCaseId);
    56 	TStringIdentity key(aTestCaseId);
    54 	TInt err(Instance().iTestCases.Insert(key,aCreationMethod));
    57 	TInt err(Instance().iTestCases.Insert(key,aCreationMethod));
    55 	if (err != KErrNone)
    58 	if (err != KErrNone)
    56 		{
    59 		{
    57 		// Log that a test case could not be registered due to err
    60 		// Log that a test case could not be registered due to err
    58 		RDebug::Print(_L("Test case '%S' could not be registered with test case factory"),&aTestCaseId);
    61 		OstTraceExt1(TRACE_NORMAL, RTESTFACTORY_REGISTERTESTCASE_DUP01, "Test case '%S' could not be registered with test case factory",aTestCaseId);
    59 		}
    62 		}
    60 	else
    63 	else
    61 		{
    64 		{
    62 		RTestFactory::TCreationMethod* creatorFunction = Instance().iTestCases.Find(key);
    65 		RTestFactory::TCreationMethod* creatorFunction = Instance().iTestCases.Find(key);
    63 		if (creatorFunction == NULL)
    66 		if (creatorFunction == NULL)
    64 			{
    67 			{
    65 			RDebug::Print(_L("<Error> Test case '%S' did not register"),&aTestCaseId);
    68 			OstTraceExt1(TRACE_NORMAL, RTESTFACTORY_REGISTERTESTCASE_DUP02, "<Error> Test case '%S' did not register",aTestCaseId);
    66 			ListRegisteredTestCases();
    69 			ListRegisteredTestCases();
    67 			}
    70 			}
    68 		else
    71 		else
    69 			{
    72 			{
    70 			RDebug::Print(_L("Test case '%S' registered in factory"),&aTestCaseId);
    73 			OstTraceExt1(TRACE_NORMAL, RTESTFACTORY_REGISTERTESTCASE_DUP03, "Test case '%S' registered in factory",aTestCaseId);
    71 			}
    74 			}
    72 		}
    75 		}
    73 	}
    76 	}
    74 
    77 
    75 
    78 
    85 
    88 
    86 /* Returns the test ID (name) of test at offset aIndex in the MAP
    89 /* Returns the test ID (name) of test at offset aIndex in the MAP
    87  */
    90  */
    88 void RTestFactory::GetTestID(TInt aIndex, TBuf<KTestCaseIdLength> &aTestID)
    91 void RTestFactory::GetTestID(TInt aIndex, TBuf<KTestCaseIdLength> &aTestID)
    89 	{
    92 	{
    90 	LOG_FUNC
    93 	if(gVerboseOutput)
       
    94 	    {
       
    95 	    OstTraceFunctionEntry0(RTESTFACTORY_GETTESTID);
       
    96 	    }
    91 
    97 
    92 	RFactoryMap::TIter it(Instance().iTestCases);
    98 	RFactoryMap::TIter it(Instance().iTestCases);
    93 	
    99 	
    94 	TInt count(0);
   100 	TInt count(0);
    95 	for (count=0; count<Instance().iTestCases.Count(); count++)
   101 	for (count=0; count<Instance().iTestCases.Count(); count++)
   125 /* Print the test IDs in numerical order
   131 /* Print the test IDs in numerical order
   126  * Returns a sorted array of strings containing all of the test IDs
   132  * Returns a sorted array of strings containing all of the test IDs
   127  */	
   133  */	
   128 void RTestFactory::ListRegisteredTestCases(RPointerArray<HBufC> & aTestCaseNameArr)
   134 void RTestFactory::ListRegisteredTestCases(RPointerArray<HBufC> & aTestCaseNameArr)
   129 	{
   135 	{
   130 	LOG_FUNC
   136 	if(gVerboseOutput)
       
   137 	    {
       
   138 	    OstTraceFunctionEntry0(RTESTFACTORY_LISTREGISTEREDTESTCASES);
       
   139 	    }
   131 	RFactoryMap::TIter it(Instance().iTestCases);
   140 	RFactoryMap::TIter it(Instance().iTestCases);
   132 	TInt count(0);
   141 	TInt count(0);
   133 	TInt cases(Instance().iTestCases.Count());
   142 	TInt cases(Instance().iTestCases.Count());
   134 	
   143 	
   135 	test.Printf(_L("------ F A C T O R Y -------\n"));
   144 	test.Printf(_L("------ F A C T O R Y -------\n"));
       
   145 	OstTrace0(TRACE_NORMAL, RTESTFACTORY_LISTREGISTEREDTESTCASES_DUP01, "------ F A C T O R Y -------\n");
   136 	
   146 	
   137 	it.Reset();
   147 	it.Reset();
   138 	for (count=0; count<Instance().iTestCases.Count(); count++)
   148 	for (count=0; count<Instance().iTestCases.Count(); count++)
   139 		{
   149 		{
   140 		TStringIdentity k(*it.NextKey());
   150 		TStringIdentity k(*it.NextKey());
   174 		}
   184 		}
   175 	// print it
   185 	// print it
   176 	for (count=0; count<aTestCaseNameArr.Count(); count++)
   186 	for (count=0; count<aTestCaseNameArr.Count(); count++)
   177 		{
   187 		{
   178 		test.Printf(_L("% 2d: %S\n"), count, aTestCaseNameArr[count]);
   188 		test.Printf(_L("% 2d: %S\n"), count, aTestCaseNameArr[count]);
       
   189 		OstTraceExt2(TRACE_NORMAL, RTESTFACTORY_LISTREGISTEREDTESTCASES_DUP02, "% 2d: %S\n", count, *aTestCaseNameArr[count]);
   179 		}
   190 		}
   180 	
   191 	
   181 	test.Printf(_L("----------------------------\n"));
   192 	test.Printf(_L("----------------------------\n"));
       
   193 	OstTrace0(TRACE_NORMAL, RTESTFACTORY_LISTREGISTEREDTESTCASES_DUP03, "----------------------------\n");
   182 	}
   194 	}
   183 
   195 
   184 
   196 
   185 CTestCaseRoot* RTestFactory::CreateTestCaseL(const TDesC& aTestCaseId)
   197 CTestCaseRoot* RTestFactory::CreateTestCaseL(const TDesC& aTestCaseId)
   186 	{
   198 	{
   187 	LOG_FUNC
   199 	if(gVerboseOutput)
       
   200 	    {
       
   201 	    OstTraceFunctionEntry0(RTESTFACTORY_CREATETESTCASEL);
       
   202 	    }
   188 	RTestFactory::TCreationMethod creatorFunction = NULL;
   203 	RTestFactory::TCreationMethod creatorFunction = NULL;
   189 	TInt err(KErrNone);
   204 	TInt err(KErrNone);
   190 	TStringIdentity key(aTestCaseId);
   205 	TStringIdentity key(aTestCaseId);
   191 	
   206 	
   192 	TRAP(err,creatorFunction = Instance().iTestCases.FindL(key));
   207 	TRAP(err,creatorFunction = Instance().iTestCases.FindL(key));
   193 	if (err != KErrNone)
   208 	if (err != KErrNone)
   194 		{
   209 		{
   195 		// Test case is not present in the factory therefore test cannot support specified test case
   210 		// Test case is not present in the factory therefore test cannot support specified test case
   196 		RDebug::Print(_L("<Error %d> Test case '%S' not supported"),err,&aTestCaseId);
   211 		OstTraceExt2(TRACE_NORMAL, RTESTFACTORY_CREATETESTCASEL_DUP01, "<Error %d> Test case '%S' not supported",err,aTestCaseId);
   197 		ListRegisteredTestCases();
   212 		ListRegisteredTestCases();
   198 		User::Leave(err);
   213 		User::Leave(err);
   199 		}
   214 		}
   200 
   215 
   201 	RDebug::Print(_L("Creating test case '%S'"),&aTestCaseId);
   216 	OstTraceExt1(TRACE_NORMAL, RTESTFACTORY_CREATETESTCASEL_DUP02, "Creating test case '%S'",aTestCaseId);
   202 		
   217 		
   203 	// Call the creator function to create the test case object
   218 	// Call the creator function to create the test case object
   204 	return creatorFunction(gSemiAutomated);
   219 	return creatorFunction(gSemiAutomated);
   205 	}
   220 	}
   206 	
   221