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".
9 // Initial Contributors:
10 // Nokia Corporation - initial contribution.
24 #include <test/ttmsgraphicsstep.h>
28 _LIT8(KLogPass,"PASS");
29 _LIT8(KLogFail,"FAIL");
32 void CTTMSGraphicsStep::CleanUpAndWriteResults()
37 for (TInt iArrayIndex=0; iArrayIndex < iArrayTMSData.Count(); iArrayIndex++)
39 CTMSDataColumn columnData = iArrayTMSData[iArrayIndex];
41 testID.Copy(columnData.iTheID);
42 testResult.Copy(columnData.iTheResult);
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);
50 iArrayTMSData.Close();
53 EXPORT_C CTTMSGraphicsStep::CTTMSGraphicsStep() : iStepPassFail(ETrue), iShowMultipleResults(EFalse)
55 iCurrentTestStepName.Copy(KUnknownSYMTestCaseIDName);
58 EXPORT_C void CTTMSGraphicsStep::CloseTMSGraphicsStep()
60 CTTMSGraphicsStep::CleanUpAndWriteResults();
63 EXPORT_C CTTMSGraphicsStep::~CTTMSGraphicsStep()
65 CTTMSGraphicsStep::CleanUpAndWriteResults();
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.
74 void CTTMSGraphicsStep::DebugLogL(const TDesC8& aTestCaseID, const TDesC8& aResult)
76 TBool foundID = EFalse;
77 if(!iShowMultipleResults)
79 for (TInt iArrayIndex=0; iArrayIndex < iArrayTMSData.Count(); iArrayIndex++)
81 CTMSDataColumn columnData = iArrayTMSData[iArrayIndex];
82 if (columnData.iTheID.Compare(aTestCaseID)== 0)
84 if (columnData.iTheResult.Compare(KLogFail) != 0)
86 iArrayTMSData[iArrayIndex].iTheResult.Copy(aResult);
89 iArrayIndex = iArrayTMSData.Count();
94 if (!foundID || iShowMultipleResults)
96 CTMSDataColumn theData;
97 theData.iTheID.Copy(aTestCaseID);
98 theData.iTheResult.Copy(aResult);
99 iArrayTMSData.Append(theData);
103 EXPORT_C void CTTMSGraphicsStep::RecordTestResultL()
105 TBuf<64> unknownTMSID(KUnknownSYMTestCaseIDName);
106 TBuf8<64> unknownID8;
107 unknownID8.Copy(unknownTMSID);
109 TBuf<64> undefinedTMSID(KUndefinedSYMTestCaseIDName);
110 TBuf8<64> undefinedID8;
111 undefinedID8.Copy(undefinedTMSID);
113 TBuf<64> notaTMSID(KNotATestSYMTestCaseIDName);
115 notaID8.Copy(notaTMSID);
117 TBuf<128> currentTSName;
118 currentTSName.Copy(iCurrentTestStepName);
120 if (iCurrentTestStepName.Compare(unknownID8) == 0) // unknown tests logged to warning file
122 INFO_PRINTF1(_L("ID NOT SET"));
124 else if (iCurrentTestStepName.Compare(undefinedID8) == 0) // undefined tests logged to warning file
126 INFO_PRINTF1(_L("ID UNDEFINED"));
128 else if (iCurrentTestStepName.Compare(notaID8) == 0)
133 if( iStepPassFail == EFalse)
135 INFO_PRINTF2(_L("%S FAILED"), ¤tTSName );
136 DebugLogL(iCurrentTestStepName, KLogFail);
140 DebugLogL(iCurrentTestStepName, KLogPass);
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)
148 if(TestStepName() == KNullDesC)
150 SetTestStepName(aStepName);
153 iCurrentTestStepName.Copy(aStepName);
154 iStepPassFail = ETrue;
157 EXPORT_C void CTTMSGraphicsStep::SetOverallTestStepID(const TDesC& aStepName)
159 iCurrentTestStepName.Copy(aStepName);
160 iStepPassFail = ETrue;
161 if (!TestStepResult() == EPass)
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)
171 iStepPassFail = EFalse;
173 testBooleanTrue( aCondition, aFile, aLine, ETrue);
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)
182 iStepPassFail = EFalse;
184 testBooleanTrueL( aCondition, aFile, aLine, ETrue);
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
190 EXPORT_C void CTTMSGraphicsStep::MQCTestWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine)
194 iStepPassFail = EFalse;
195 SetTestStepResult(EFail);
196 _LIT(KMessage,"Test Failed with error [%d]");
197 Logger().LogExtra(aFile, aLine, ESevrErr, KMessage, aErrorCode);
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)
204 iShowMultipleResults = aShowMultipleResults;