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