os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/TestCaseFactory.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // @file testcasefactory.cpp
    15 // @internalComponent
    16 // 
    17 //
    18 
    19 #include "TestCaseFactory.h"
    20 #include "testdevicebase.h"
    21 #include <e32debug.h>
    22 
    23 namespace NUnitTesting_USBDI
    24 	{
    25 	
    26 RTestFactory& RTestFactory::Instance()
    27 	{
    28 	static RTestFactory singleton;
    29 	return singleton;
    30 	}
    31 	
    32 RTestFactory::~RTestFactory()
    33 	{
    34 	}
    35 	
    36 	
    37 RTestFactory::RTestFactory()
    38 :	iTestCases(TStringIdentity::Hash,TStringIdentity::Id)
    39 	{
    40 	}
    41 	
    42 void RTestFactory::RegisterTestCase(const TDesC& aTestCaseId,TBaseTestCaseFunctor const* aFunctor)
    43 	{
    44 	LOG_CFUNC
    45 
    46 	LOG_INFO((_L("Registering test case '%S'"),&aTestCaseId))
    47 	
    48 	TStringIdentity key(aTestCaseId);
    49 	TInt err(Instance().iTestCases.Insert(key,aFunctor));
    50 	if(err != KErrNone)
    51 		{
    52 		// 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);
    54 		}
    55 	}
    56 
    57 
    58 CBaseTestCase* RTestFactory::CreateTestCaseL(const TDesC& aTestCaseId,TBool aHostRole)
    59 	{
    60 	LOG_CFUNC
    61 	
    62 	TStringIdentity key(aTestCaseId);
    63 	const TBaseTestCaseFunctor& functor = *(*Instance().iTestCases.Find(key));
    64 	return functor(aHostRole);
    65 	}
    66 	
    67 
    68 void RTestFactory::ListRegisteredTestCases()
    69 	{
    70 	LOG_CFUNC
    71 	RFactoryMap::TIter it(Instance().iTestCases);
    72 	
    73 	RDebug::Printf("-------- F A C T O R Y ---------");
    74 	
    75 	TInt count(0);
    76 	for(count=0; count<Instance().iTestCases.Count(); count++)
    77 		{
    78 		RDebug::Printf("%d: %S",count,it.NextKey());
    79 		}
    80 	
    81 	RDebug::Printf("--------------------------------");
    82 	}
    83 
    84 	}