os/graphics/graphicstest/graphicstestharness/src/TTMSGraphicsStep.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 // TTMSGraphicsStep.cpp
     2 // Copyright (c) 2006-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 @file
    19 @test
    20 @internalComponent
    21 */
    22 
    23 #include <bautils.h>
    24 #include <test/ttmsgraphicsstep.h>
    25 #include <f32file.h> 
    26 #include <e32std.h>
    27 
    28 _LIT8(KLogPass,"PASS");
    29 _LIT8(KLogFail,"FAIL");
    30 
    31 
    32 void CTTMSGraphicsStep::CleanUpAndWriteResults()
    33 	{
    34 	TBuf<256> testID;
    35 	TBuf<8> testResult;
    36 	
    37 	for (TInt iArrayIndex=0; iArrayIndex < iArrayTMSData.Count(); iArrayIndex++)
    38 		{
    39 		CTMSDataColumn columnData = iArrayTMSData[iArrayIndex];
    40 		
    41 		testID.Copy(columnData.iTheID);
    42 		testResult.Copy(columnData.iTheResult);
    43 		
    44 		INFO_PRINTF2(_L("START_TESTCASE %S"),&testID);
    45 		INFO_PRINTF2(_L("Line = 1 Command = START_TESTCASE %S"),&testID);
    46 		INFO_PRINTF2(_L("END_TESTCASE %S"),&testID);
    47 		INFO_PRINTF3(_L("Line = 1 Command = END_TESTCASE %S ***TestCaseResult = %S"),&testID,&testResult);
    48 		}
    49 	
    50 	iArrayTMSData.Close();		    
    51 	}
    52 
    53 EXPORT_C CTTMSGraphicsStep::CTTMSGraphicsStep() : iStepPassFail(ETrue), iShowMultipleResults(EFalse)
    54 	{
    55 	iCurrentTestStepName.Copy(KUnknownSYMTestCaseIDName);
    56 	}
    57 
    58 EXPORT_C void CTTMSGraphicsStep::CloseTMSGraphicsStep()
    59 	{
    60 	CTTMSGraphicsStep::CleanUpAndWriteResults();	
    61 	}
    62 
    63 EXPORT_C CTTMSGraphicsStep::~CTTMSGraphicsStep()
    64 	{	
    65 	CTTMSGraphicsStep::CleanUpAndWriteResults();
    66 	}
    67 
    68 // writes out the results of a test that has just been executed to the log file(s)
    69 // the first time a test result is written it is also added to the iTestStepNames array.
    70 // This array is then checked on subsequent tests to see if the test has already been written to log
    71 // if it has and multiple test results are not wanted further logging of this test is omitted.
    72 
    73 
    74 void CTTMSGraphicsStep::DebugLogL(const TDesC8& aTestCaseID, const TDesC8& aResult)
    75 	{		
    76 	TBool foundID = EFalse;
    77 	if(!iShowMultipleResults)
    78 		{
    79 		for (TInt iArrayIndex=0; iArrayIndex < iArrayTMSData.Count(); iArrayIndex++)
    80 			{
    81 			CTMSDataColumn columnData = iArrayTMSData[iArrayIndex];
    82 			if (columnData.iTheID.Compare(aTestCaseID)== 0)
    83 				{
    84 				if (columnData.iTheResult.Compare(KLogFail) != 0)
    85 					{
    86 					iArrayTMSData[iArrayIndex].iTheResult.Copy(aResult);
    87 					}
    88 				foundID = ETrue;
    89 				iArrayIndex = iArrayTMSData.Count();
    90 				}
    91 			}
    92 		}
    93 	
    94 	if (!foundID || iShowMultipleResults)
    95 		{
    96 		CTMSDataColumn theData;
    97 		theData.iTheID.Copy(aTestCaseID);
    98 		theData.iTheResult.Copy(aResult);
    99 		iArrayTMSData.Append(theData);
   100 		}
   101 	}
   102 
   103 EXPORT_C void CTTMSGraphicsStep::RecordTestResultL()
   104 	{	
   105 	TBuf<64> unknownTMSID(KUnknownSYMTestCaseIDName);
   106 	TBuf8<64> unknownID8;
   107 	unknownID8.Copy(unknownTMSID);
   108 	
   109 	TBuf<64> undefinedTMSID(KUndefinedSYMTestCaseIDName);
   110 	TBuf8<64> undefinedID8;
   111 	undefinedID8.Copy(undefinedTMSID);
   112 	
   113 	TBuf<64> notaTMSID(KNotATestSYMTestCaseIDName);
   114 	TBuf8<64> notaID8;
   115 	notaID8.Copy(notaTMSID);
   116 	
   117 	TBuf<128> currentTSName;
   118 	currentTSName.Copy(iCurrentTestStepName);
   119 	
   120 	if (iCurrentTestStepName.Compare(unknownID8) == 0) 	// unknown tests logged to warning file		
   121 		{
   122 		INFO_PRINTF1(_L("ID NOT SET"));
   123 		}
   124 	else if (iCurrentTestStepName.Compare(undefinedID8) == 0)	// undefined tests logged to warning file
   125 		{
   126 		INFO_PRINTF1(_L("ID UNDEFINED"));
   127 		}
   128 	else if (iCurrentTestStepName.Compare(notaID8) == 0)
   129 		{
   130 		}
   131 	else 			
   132 		{
   133 		if( iStepPassFail == EFalse)
   134 			{
   135 			INFO_PRINTF2(_L("%S FAILED"), &currentTSName ); 
   136 			DebugLogL(iCurrentTestStepName, KLogFail);
   137 			}
   138 		else
   139 			{
   140 			DebugLogL(iCurrentTestStepName, KLogPass);
   141 			}	
   142 		}
   143 	}
   144 
   145 // sets the name and pass/fail state of the individual test that is about to be executed 
   146 EXPORT_C void CTTMSGraphicsStep::SetTestStepID(const TDesC& aStepName)
   147 	{
   148 	if(TestStepName() == KNullDesC)
   149 	    {
   150 	    SetTestStepName(aStepName);
   151 	    }
   152 
   153 	iCurrentTestStepName.Copy(aStepName);
   154 	iStepPassFail = ETrue;
   155 	}
   156 
   157 EXPORT_C void CTTMSGraphicsStep::SetOverallTestStepID(const TDesC& aStepName)
   158 	{
   159 	iCurrentTestStepName.Copy(aStepName);
   160 	iStepPassFail = ETrue;
   161 	if (!TestStepResult() == EPass)
   162 				TEST(EFalse);
   163 	}
   164 
   165 // needed for the overide of CTGraphicsBase::testBooleanTrue to allow us to set 
   166 // whether an individual test has passed or failed
   167 EXPORT_C void CTTMSGraphicsStep::MQCTest(TBool aCondition, const TText8* aFile, TInt aLine)
   168 	{
   169 	if(!aCondition)
   170 		{
   171 		iStepPassFail = EFalse;	
   172 		}
   173 	testBooleanTrue( aCondition, aFile, aLine, ETrue);		
   174 	}
   175 
   176 // needed for the overide of CTGraphicsBase::testBooleanTrue to allow us to set 
   177 // whether an individual test has passed or failed
   178 EXPORT_C void CTTMSGraphicsStep::MQCTestL(TBool aCondition, const TText8* aFile, TInt aLine)
   179 	{
   180 	if(!aCondition)
   181 		{
   182 		iStepPassFail = EFalse;	
   183 		}
   184 	testBooleanTrueL( aCondition, aFile, aLine, ETrue);		
   185 	}
   186 
   187 // needed for the overide of CTGraphicsBase::testBooleanTrueWithErrorCode to allow us to set 
   188 // whether an individual test has passed or failed. Also allows line and file of test failure
   189 // to be displayed.
   190 EXPORT_C void CTTMSGraphicsStep::MQCTestWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine)
   191 	{
   192 	if(!aCondition)
   193 		{
   194 		iStepPassFail = EFalse;
   195 		SetTestStepResult(EFail);
   196 		_LIT(KMessage,"Test Failed with error [%d]");
   197 		Logger().LogExtra(aFile, aLine, ESevrErr, KMessage, aErrorCode);
   198 		}
   199 	}
   200 
   201 // sets whether tests with the same @SYMTestCaseID xxxxxx name are printed multiple times in the log files
   202 EXPORT_C void CTTMSGraphicsStep::MultipleResultsForSameID(TBool aShowMultipleResults)
   203 	{
   204 	iShowMultipleResults = aShowMultipleResults;
   205 	}