kerneltest/e32test/usbho/t_usbdi/src/TestCaseFactory.cpp
changeset 253 d37db4dcc88d
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
252:0a40b8675b23 253:d37db4dcc88d
     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".
    16 // 
    16 // 
    17 //
    17 //
    18 
    18 
    19 #include "TestCaseFactory.h"
    19 #include "TestCaseFactory.h"
    20 #include "testdevicebase.h"
    20 #include "testdevicebase.h"
       
    21 #include "OstTraceDefinitions.h"
       
    22 #ifdef OST_TRACE_COMPILER_IN_USE
       
    23 #include "TestCaseFactoryTraces.h"
       
    24 #endif
    21 #include <e32debug.h>
    25 #include <e32debug.h>
    22 
    26 
    23 namespace NUnitTesting_USBDI
    27 namespace NUnitTesting_USBDI
    24 	{
    28 	{
    25 	
    29 	
    26 RTestFactory& RTestFactory::Instance()
    30 RTestFactory& RTestFactory::Instance()
    27 	{
    31 	{
       
    32 	OstTraceFunctionEntry1( RTESTFACTORY_INSTANCE_ENTRY, 0 );
    28 	static RTestFactory singleton;
    33 	static RTestFactory singleton;
       
    34 	OstTraceFunctionExitExt( RTESTFACTORY_INSTANCE_EXIT, 0, ( TUint )&( singleton ) );
    29 	return singleton;
    35 	return singleton;
    30 	}
    36 	}
    31 	
    37 	
    32 RTestFactory::~RTestFactory()
    38 RTestFactory::~RTestFactory()
    33 	{
    39 	{
       
    40 	OstTraceFunctionEntry1( RTESTFACTORY_RTESTFACTORY_ENTRY, this );
       
    41 	OstTraceFunctionExit1( RTESTFACTORY_RTESTFACTORY_EXIT, this );
    34 	}
    42 	}
    35 	
    43 	
    36 	
    44 	
    37 RTestFactory::RTestFactory()
    45 RTestFactory::RTestFactory()
    38 :	iTestCases(TStringIdentity::Hash,TStringIdentity::Id)
    46 :	iTestCases(TStringIdentity::Hash,TStringIdentity::Id)
    39 	{
    47 	{
       
    48 	OstTraceFunctionEntry1( RTESTFACTORY_RTESTFACTORY_ENTRY_DUP01, this );
       
    49 	OstTraceFunctionExit1( RTESTFACTORY_RTESTFACTORY_EXIT_DUP01, this );
    40 	}
    50 	}
    41 	
    51 	
    42 void RTestFactory::RegisterTestCase(const TDesC& aTestCaseId,TBaseTestCaseFunctor const* aFunctor)
    52 void RTestFactory::RegisterTestCase(const TDesC& aTestCaseId,TBaseTestCaseFunctor const* aFunctor)
    43 	{
    53 	{
    44 	LOG_CFUNC
    54     OstTraceFunctionEntryExt( RTESTFACTORY_REGISTERTESTCASE_ENTRY, 0 );
    45 
    55 
    46 	LOG_INFO((_L("Registering test case '%S'"),&aTestCaseId))
    56 	LOG_INFO((_L("Registering test case '%S'"),&aTestCaseId))
    47 	
    57 	
    48 	TStringIdentity key(aTestCaseId);
    58 	TStringIdentity key(aTestCaseId);
    49 	TInt err(Instance().iTestCases.Insert(key,aFunctor));
    59 	TInt err(Instance().iTestCases.Insert(key,aFunctor));
    50 	if(err != KErrNone)
    60 	if(err != KErrNone)
    51 		{
    61 		{
    52 		// Log that a test case could not be registered due to err
    62 		// 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);
    63 		OstTraceExt1(TRACE_NORMAL, RTESTFACTORY_REGISTERTESTCASE, "Test case '%S' could not be registered with test case factory",aTestCaseId);
    54 		}
    64 		}
       
    65 	OstTraceFunctionExit1( RTESTFACTORY_REGISTERTESTCASE_EXIT, 0 );
    55 	}
    66 	}
    56 
    67 
    57 
    68 
    58 CBaseTestCase* RTestFactory::CreateTestCaseL(const TDesC& aTestCaseId,TBool aHostRole)
    69 CBaseTestCase* RTestFactory::CreateTestCaseL(const TDesC& aTestCaseId,TBool aHostRole)
    59 	{
    70 	{
    60 	LOG_CFUNC
    71 	OstTraceFunctionEntryExt( RTESTFACTORY_CREATETESTCASEL_ENTRY, 0 );
    61 	
    72 	
    62 	TStringIdentity key(aTestCaseId);
    73 	TStringIdentity key(aTestCaseId);
    63 	const TBaseTestCaseFunctor& functor = *(*Instance().iTestCases.Find(key));
    74 	const TBaseTestCaseFunctor& functor = *(*Instance().iTestCases.Find(key));
    64 	return functor(aHostRole);
    75 	return functor(aHostRole);
    65 	}
    76 	}
    66 	
    77 	
    67 
    78 
    68 void RTestFactory::ListRegisteredTestCases()
    79 void RTestFactory::ListRegisteredTestCases()
    69 	{
    80 	{
    70 	LOG_CFUNC
    81 	OstTraceFunctionEntry1( RTESTFACTORY_LISTREGISTEREDTESTCASES_ENTRY, 0 );
    71 	RFactoryMap::TIter it(Instance().iTestCases);
    82 	RFactoryMap::TIter it(Instance().iTestCases);
    72 	
    83 	
    73 	RDebug::Printf("-------- F A C T O R Y ---------");
    84 	OstTrace0(TRACE_NORMAL, RTESTFACTORY_LISTREGISTEREDTESTCASES, "-------- F A C T O R Y ---------");
    74 	
    85 	
    75 	TInt count(0);
    86 	TInt count(0);
    76 	for(count=0; count<Instance().iTestCases.Count(); count++)
    87 	for(count=0; count<Instance().iTestCases.Count(); count++)
    77 		{
    88 		{
    78 		RDebug::Printf("%d: %S",count,it.NextKey());
    89 		OstTrace1(TRACE_NORMAL, RTESTFACTORY_LISTREGISTEREDTESTCASES_DUP01, "%d",count);
    79 		}
    90 		}
    80 	
    91 	
    81 	RDebug::Printf("--------------------------------");
    92 	OstTrace0(TRACE_NORMAL, RTESTFACTORY_LISTREGISTEREDTESTCASES_DUP02, "--------------------------------");
       
    93 	OstTraceFunctionExit1( RTESTFACTORY_LISTREGISTEREDTESTCASES_EXIT, 0 );
    82 	}
    94 	}
    83 
    95 
    84 	}
    96 	}