testexecmdw/tef/tef/tefunit/src/crunner.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 CRunner.cpp
       
    22 */
       
    23 
       
    24 
       
    25 #include "cteflogger.h"
       
    26 #include "crunner.h"
       
    27 
       
    28 _LIT( KWildCard, "*"); 
       
    29 
       
    30 CRunner::CRunner( const CTestConfig& aConfig, const CTestExecuteLogger& aLogger)
       
    31 /**
       
    32  * Constructor
       
    33  *
       
    34  * @param aConfig - Instance of the test config
       
    35  * @param aLogger - Instance of the logger
       
    36  */
       
    37 	: iConfig(aConfig), iLogger(aLogger)
       
    38 	{
       
    39 	}
       
    40 
       
    41 CRunner::~CRunner()
       
    42 /**
       
    43  *	Destructor
       
    44  */
       
    45 	{
       
    46 	}
       
    47 
       
    48 void CRunner::ConstructL( const TTestPath& aPath )
       
    49 /**
       
    50  * ConstructL
       
    51  *
       
    52  * @param aPath - The path of the test case to be executed
       
    53  */
       
    54 	{
       
    55 	iPath.ConstructL( aPath );
       
    56 	}
       
    57 
       
    58 /*
       
    59  *	NewL
       
    60  *    Return an instance of CRunner
       
    61  */
       
    62 CRunner* CRunner::NewL( const TTestPath &aPath, const CTestConfig& aConfig, const CTestExecuteLogger& aLogger )
       
    63 /**
       
    64  * NewL
       
    65  *
       
    66  * @param aPath - The path of the test case to be executed
       
    67  * @param aConfig - Instance of the test config
       
    68  * @param aLogger - Instance of the logger
       
    69  * @return - Instance of CRunner
       
    70  */
       
    71 	{
       
    72 	CRunner* lRunner = new (ELeave) CRunner(aConfig, aLogger); 
       
    73 	CleanupStack::PushL(lRunner); 
       
    74 	lRunner->ConstructL(aPath);
       
    75 	CleanupStack::Pop(); 
       
    76 	return lRunner; 
       
    77 	}
       
    78 
       
    79 void CRunner::VisitL(CTestCase* aTestCase)
       
    80 /**
       
    81  * VisitL
       
    82  *
       
    83  * @param aTestCase - The test case to visit
       
    84  */
       
    85 	{
       
    86 	aTestCase->RunL(iConfig, iLogger);
       
    87 	}
       
    88 
       
    89 void CRunner::VisitL(CTestSuite* aTestSuite)
       
    90 /**
       
    91  * VisitL
       
    92  *
       
    93  * @param aTestSuite - The test suite to visit
       
    94  */
       
    95 	{
       
    96 	// Get the next field from the path and search for it
       
    97 	if( iPath.Remaining() )
       
    98 		{
       
    99 		TTestName testSuite = iPath.NextL();
       
   100 		if( testSuite == KWildCard )
       
   101 			{
       
   102 			// Run all the tests in the suite and sub suites
       
   103 			aTestSuite->RunL( iConfig, iLogger );
       
   104 			}
       
   105 		else
       
   106 			{
       
   107 			TInt lIndex = 0;
       
   108 			while( (lIndex < aTestSuite->Count()) &&
       
   109 					(aTestSuite->NameL(lIndex)!=iPath.Current()) )
       
   110 				{
       
   111 				lIndex++;
       
   112 				}
       
   113 			if( (lIndex < aTestSuite->Count()) &&
       
   114 					(aTestSuite->NameL(lIndex)==iPath.Current()) )
       
   115 				{
       
   116 				// Log that the runner is currently in this suite
       
   117 				CTEFLogger::LogTraverse( aTestSuite->Name(), iLogger );
       
   118 				aTestSuite->TestL( lIndex )->AcceptL( *this );
       
   119 				}
       
   120 			else
       
   121 				{
       
   122 				User::Leave(KErrTEFUnitTestSuiteError);
       
   123 				}
       
   124 			}
       
   125 		}
       
   126 	else
       
   127 		{
       
   128 		// Run all the tests in the suite and sub suites
       
   129 		aTestSuite->RunL( iConfig, iLogger );
       
   130 		}
       
   131 	}
       
   132 
       
   133 CPath::CPath()
       
   134 /**
       
   135  * Constructor
       
   136  */
       
   137 	: iCurrent(0)
       
   138 	{
       
   139 	}
       
   140 
       
   141 void CPath::ConstructL( const TDes& aPath )
       
   142 /**
       
   143  * ConstructL
       
   144  *
       
   145  * @param aPath - The path to be parsed
       
   146  */
       
   147 	{
       
   148 	// Prepend a NULL field for the top level suite
       
   149 	User::LeaveIfError(	iFields.Append(_L("NULL")) );
       
   150 	HBufC* ptrPath = HBufC::NewLC(KMaxPathSize);
       
   151 	TPtr ptr(ptrPath->Des());
       
   152 	ptr.Copy(aPath);
       
   153 	// Populate the path fields array
       
   154 	TInt offset = ptr.Locate( '.' );
       
   155 	while( offset != KErrNotFound )
       
   156 		{
       
   157 		TTestName field;
       
   158 		field.Append( ptr.Ptr(), offset );
       
   159 		User::LeaveIfError(	iFields.Append(field) );
       
   160 		ptr.Delete( 0, offset+1 );
       
   161 		offset = ptr.Locate( '.' );
       
   162 		}
       
   163 	// There will be one more field
       
   164 	TTestName field;
       
   165 	field.Append( ptrPath->Ptr(), ptrPath->Size()/2 );
       
   166 	CleanupStack::PopAndDestroy(ptrPath);
       
   167 	User::LeaveIfError(	iFields.Append(field) );
       
   168 	}
       
   169 
       
   170 /*
       
   171  *	NewL
       
   172  *    Return an instance of CPath
       
   173  */
       
   174 CPath* CPath::NewL( TDes& aPath )
       
   175 /**
       
   176  * NewL
       
   177  *
       
   178  * @param aPath - The path to be parsed
       
   179  * @return - Instance of CPath
       
   180  */
       
   181 	{
       
   182 	CPath* lPath = new (ELeave) CPath();
       
   183 	CleanupStack::PushL(lPath);
       
   184 	lPath->ConstructL(aPath);
       
   185 	CleanupStack::Pop();
       
   186 	return lPath;
       
   187 	}
       
   188 
       
   189 CPath::~CPath()
       
   190 /**
       
   191  * Destructor
       
   192  */
       
   193 	{
       
   194 	iFields.Close();
       
   195 	}
       
   196 
       
   197 TTestName CPath::Current() const
       
   198 /**
       
   199  * Current
       
   200  *
       
   201  * @return - The current field within the path
       
   202  */
       
   203 	{
       
   204 	return iFields[iCurrent];
       
   205 	}
       
   206 
       
   207 TTestName CPath::NextL()
       
   208 /**
       
   209  * NextL
       
   210  *
       
   211  * @return - The next field in the path
       
   212  */
       
   213 	{
       
   214 	if( iCurrent>(iFields.Count()-2) )
       
   215 		{
       
   216 		User::Leave(KErrTEFUnitFail);
       
   217 		}
       
   218 
       
   219 	return iFields[++iCurrent];
       
   220 	}
       
   221 
       
   222 TInt CPath::Count() const
       
   223 /**
       
   224  * Count
       
   225  *
       
   226  * @return - The number of fields in the path
       
   227  */
       
   228 	{
       
   229 	return iFields.Count();	
       
   230 	}
       
   231 
       
   232 TInt CPath::Remaining() const
       
   233 /**
       
   234  * Remaining
       
   235  *
       
   236  * @return - The number of remaining fields from the current location in the path
       
   237  */
       
   238 	{
       
   239 	return (iFields.Count()-1)-iCurrent;	
       
   240 	}