os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/TestCaseFactory.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/TestCaseFactory.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,84 @@
     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 +// @file testcasefactory.cpp
    1.18 +// @internalComponent
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include "TestCaseFactory.h"
    1.23 +#include "testdevicebase.h"
    1.24 +#include <e32debug.h>
    1.25 +
    1.26 +namespace NUnitTesting_USBDI
    1.27 +	{
    1.28 +	
    1.29 +RTestFactory& RTestFactory::Instance()
    1.30 +	{
    1.31 +	static RTestFactory singleton;
    1.32 +	return singleton;
    1.33 +	}
    1.34 +	
    1.35 +RTestFactory::~RTestFactory()
    1.36 +	{
    1.37 +	}
    1.38 +	
    1.39 +	
    1.40 +RTestFactory::RTestFactory()
    1.41 +:	iTestCases(TStringIdentity::Hash,TStringIdentity::Id)
    1.42 +	{
    1.43 +	}
    1.44 +	
    1.45 +void RTestFactory::RegisterTestCase(const TDesC& aTestCaseId,TBaseTestCaseFunctor const* aFunctor)
    1.46 +	{
    1.47 +	LOG_CFUNC
    1.48 +
    1.49 +	LOG_INFO((_L("Registering test case '%S'"),&aTestCaseId))
    1.50 +	
    1.51 +	TStringIdentity key(aTestCaseId);
    1.52 +	TInt err(Instance().iTestCases.Insert(key,aFunctor));
    1.53 +	if(err != KErrNone)
    1.54 +		{
    1.55 +		// Log that a test case could not be registered due to err
    1.56 +		RDebug::Printf("Test case '%S' could not be registered with test case factory",&aTestCaseId);
    1.57 +		}
    1.58 +	}
    1.59 +
    1.60 +
    1.61 +CBaseTestCase* RTestFactory::CreateTestCaseL(const TDesC& aTestCaseId,TBool aHostRole)
    1.62 +	{
    1.63 +	LOG_CFUNC
    1.64 +	
    1.65 +	TStringIdentity key(aTestCaseId);
    1.66 +	const TBaseTestCaseFunctor& functor = *(*Instance().iTestCases.Find(key));
    1.67 +	return functor(aHostRole);
    1.68 +	}
    1.69 +	
    1.70 +
    1.71 +void RTestFactory::ListRegisteredTestCases()
    1.72 +	{
    1.73 +	LOG_CFUNC
    1.74 +	RFactoryMap::TIter it(Instance().iTestCases);
    1.75 +	
    1.76 +	RDebug::Printf("-------- F A C T O R Y ---------");
    1.77 +	
    1.78 +	TInt count(0);
    1.79 +	for(count=0; count<Instance().iTestCases.Count(); count++)
    1.80 +		{
    1.81 +		RDebug::Printf("%d: %S",count,it.NextKey());
    1.82 +		}
    1.83 +	
    1.84 +	RDebug::Printf("--------------------------------");
    1.85 +	}
    1.86 +
    1.87 +	}