os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/TestCaseFactory.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// @file testcasefactory.cpp
sl@0
    15
// @internalComponent
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include "TestCaseFactory.h"
sl@0
    20
#include "testdevicebase.h"
sl@0
    21
#include <e32debug.h>
sl@0
    22
sl@0
    23
namespace NUnitTesting_USBDI
sl@0
    24
	{
sl@0
    25
	
sl@0
    26
RTestFactory& RTestFactory::Instance()
sl@0
    27
	{
sl@0
    28
	static RTestFactory singleton;
sl@0
    29
	return singleton;
sl@0
    30
	}
sl@0
    31
	
sl@0
    32
RTestFactory::~RTestFactory()
sl@0
    33
	{
sl@0
    34
	}
sl@0
    35
	
sl@0
    36
	
sl@0
    37
RTestFactory::RTestFactory()
sl@0
    38
:	iTestCases(TStringIdentity::Hash,TStringIdentity::Id)
sl@0
    39
	{
sl@0
    40
	}
sl@0
    41
	
sl@0
    42
void RTestFactory::RegisterTestCase(const TDesC& aTestCaseId,TBaseTestCaseFunctor const* aFunctor)
sl@0
    43
	{
sl@0
    44
	LOG_CFUNC
sl@0
    45
sl@0
    46
	LOG_INFO((_L("Registering test case '%S'"),&aTestCaseId))
sl@0
    47
	
sl@0
    48
	TStringIdentity key(aTestCaseId);
sl@0
    49
	TInt err(Instance().iTestCases.Insert(key,aFunctor));
sl@0
    50
	if(err != KErrNone)
sl@0
    51
		{
sl@0
    52
		// Log that a test case could not be registered due to err
sl@0
    53
		RDebug::Printf("Test case '%S' could not be registered with test case factory",&aTestCaseId);
sl@0
    54
		}
sl@0
    55
	}
sl@0
    56
sl@0
    57
sl@0
    58
CBaseTestCase* RTestFactory::CreateTestCaseL(const TDesC& aTestCaseId,TBool aHostRole)
sl@0
    59
	{
sl@0
    60
	LOG_CFUNC
sl@0
    61
	
sl@0
    62
	TStringIdentity key(aTestCaseId);
sl@0
    63
	const TBaseTestCaseFunctor& functor = *(*Instance().iTestCases.Find(key));
sl@0
    64
	return functor(aHostRole);
sl@0
    65
	}
sl@0
    66
	
sl@0
    67
sl@0
    68
void RTestFactory::ListRegisteredTestCases()
sl@0
    69
	{
sl@0
    70
	LOG_CFUNC
sl@0
    71
	RFactoryMap::TIter it(Instance().iTestCases);
sl@0
    72
	
sl@0
    73
	RDebug::Printf("-------- F A C T O R Y ---------");
sl@0
    74
	
sl@0
    75
	TInt count(0);
sl@0
    76
	for(count=0; count<Instance().iTestCases.Count(); count++)
sl@0
    77
		{
sl@0
    78
		RDebug::Printf("%d: %S",count,it.NextKey());
sl@0
    79
		}
sl@0
    80
	
sl@0
    81
	RDebug::Printf("--------------------------------");
sl@0
    82
	}
sl@0
    83
sl@0
    84
	}