testexecmdw/tef/tef/tefunit/src/ctestsuite.cpp
branchRCL_3
changeset 3 9397a16b6eb8
parent 1 6edeef394eb7
equal deleted inserted replaced
1:6edeef394eb7 3:9397a16b6eb8
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 /**
       
    21  @file CTestSuite.cpp
       
    22 */
       
    23 
       
    24 #include "tefunit.h"
       
    25 
       
    26 CTestSuite::CTestSuite(const TTestName& aName)
       
    27 /**
       
    28  * Constructor
       
    29  *
       
    30  * @param aName - Test suite name
       
    31  */
       
    32 	: CTestBase(aName)
       
    33 	{
       
    34 	}
       
    35 
       
    36 CTestSuite::CTestSuite(CTestSuite &rhs)
       
    37 /**
       
    38  * Constructor
       
    39  *
       
    40  * @param rhs - Test suite to copy
       
    41  */
       
    42 	: CTestBase(rhs.iName)
       
    43 	{
       
    44 	iTests=rhs.iTests;
       
    45 	}
       
    46 
       
    47 void CTestSuite::ConstructL()
       
    48 /**
       
    49  * ConstructL
       
    50  */
       
    51 	{
       
    52 	}
       
    53 
       
    54 CTestSuite* CTestSuite::NewL()
       
    55 /**
       
    56  * NewL
       
    57  *
       
    58  * @return - Instance of CTestSuite
       
    59  */
       
    60 	{
       
    61 	return NewL(_L("TEFUnit"));
       
    62 	}
       
    63 
       
    64 CTestSuite* CTestSuite::NewL(const TTestName& aName)
       
    65 /**
       
    66  * NewL
       
    67  *
       
    68  * @param aName - Name of the test suite
       
    69  * @return - Instance of CTestSuite
       
    70  */
       
    71 	{
       
    72 	CTestSuite* lTestSuite = new (ELeave) CTestSuite(aName);
       
    73 	CleanupStack::PushL(lTestSuite);
       
    74 	lTestSuite->ConstructL();
       
    75 	CleanupStack::Pop();
       
    76 	return lTestSuite;
       
    77 	}
       
    78 
       
    79 CTestSuite::~CTestSuite()
       
    80 /**
       
    81  * Destructor
       
    82  */
       
    83 	{
       
    84 	for(TInt lIndex = 0; lIndex < iTests.Count(); lIndex++)
       
    85 		{
       
    86 		delete iTests[lIndex];
       
    87 		iTests[lIndex] = NULL;
       
    88 		}
       
    89 	iTests.Close();
       
    90 	}
       
    91 
       
    92 void CTestSuite::AddL(CTestBase* aTest)
       
    93 /**
       
    94  * AddL
       
    95  *
       
    96  * @param aTest - Test to add to the suite
       
    97  */
       
    98 	{
       
    99 	User::LeaveIfError(	iTests.Append(aTest) );
       
   100 	}
       
   101 
       
   102 void CTestSuite::RunL(CTestConfig& aConfig, CTestExecuteLogger& aLogger)
       
   103 /**
       
   104  * RunL
       
   105  *
       
   106  * @param aConfig - Config to use within the test case
       
   107  * @param aLogger - Logger to use within the test case
       
   108  */
       
   109 	{
       
   110 	// Log that the runner is currently in this suite
       
   111 	CTEFLogger::LogTraverse( iName, aLogger );
       
   112 	for(TInt lIndex = 0; lIndex < iTests.Count(); lIndex++)
       
   113 		{
       
   114 		TRAPD(err,iTests[lIndex]->RunL(aConfig, aLogger));
       
   115 		if(err != KErrTEFUnitPass)
       
   116 			{
       
   117 			iError=err;
       
   118 			}
       
   119 		}
       
   120 	if(iError != KErrTEFUnitPass)
       
   121 		{
       
   122 		User::Leave(iError);
       
   123 		}
       
   124 	}
       
   125 
       
   126 void CTestSuite::AcceptL(MVisitor &aVisitor)
       
   127 /**
       
   128  * AcceptL
       
   129  *
       
   130  * @param aVisitor - Visitor (runner) to accept
       
   131  */
       
   132 	{
       
   133 	aVisitor.VisitL(this);
       
   134 	}
       
   135 
       
   136 TInt CTestSuite::Count()
       
   137 /**
       
   138  * Count
       
   139  *
       
   140  * @return - Number of tests cases/sub-suites
       
   141  */
       
   142 	{
       
   143 	return iTests.Count();
       
   144 	}
       
   145 
       
   146 TTestName CTestSuite::NameL( TInt anIndex )
       
   147 /**
       
   148  * NameL
       
   149  *
       
   150  * @param anIndex - Index of name to retrieve
       
   151  * @return - Test name
       
   152  */
       
   153 	{
       
   154 	return TestL(anIndex)->Name();
       
   155 	}
       
   156 
       
   157 CTestBase*	CTestSuite::TestL( TInt anIndex )
       
   158 /**
       
   159  * TestL
       
   160  *
       
   161  * @param anIndex - Index of test to retrieve
       
   162  * @return - Test case/suite
       
   163  */
       
   164 	{
       
   165 	if( anIndex>=iTests.Count() )
       
   166 		{
       
   167 		User::Leave(KErrTEFUnitFail);
       
   168 		}
       
   169 
       
   170 	return iTests[anIndex];
       
   171 	}