author | Johnson Ma <johnson.ma@nokia.com> |
Mon, 29 Mar 2010 14:46:27 +0800 | |
changeset 1 | bbd31066657e |
parent 0 | 3e07fef1e154 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (c) 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 |
#include "symbianunittestresult.h" |
|
19 |
#include "symbianunittestfailure.h" |
|
20 |
#include "symbianunittestfileoutputwriter.h" |
|
21 |
#include "symbianunittestoutputashtml.h" |
|
1
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
22 |
#include <utf.h> |
0 | 23 |
|
24 |
// CONSTANTS |
|
25 |
_LIT8( KHtmlHeader, "<html><head><title>Unit test results</title></head>\n" ); |
|
26 |
_LIT8( KHtmlFooter, "</html>\n" ); |
|
27 |
_LIT8( KHtmlBodyStartTag, "<body bgcolor=\"#DDDDDD\" text=\"black\">\n" ); |
|
28 |
_LIT8( KHtmlBodyEndTag, "</body>\n"); |
|
29 |
_LIT8( KHtmlMainHeaderStartTag, "<h2> %d unit tests executed " ); |
|
30 |
_LIT8( KHtmlMainHeaderEndTag, "</h2>\n" ); |
|
31 |
_LIT8( KHtmlPassedTests, |
|
32 |
"<h3><font color=\"green\">Passed tests: %d</b></font></h3>\n" ); |
|
33 |
_LIT8( KHtmlFailedTests, |
|
34 |
"<h3><font color=\"red\">Failed tests: %d</font></h3>\n" ); |
|
35 |
_LIT8( KHtmlParagraphBreak, "<p></p>\n" ); |
|
36 |
_LIT8( KHtmlTableStartTag, "<table border=\"0\">\n" ); |
|
37 |
_LIT8( KHtmlTableEndTag, "</table>\n" ); |
|
38 |
_LIT8( KHtmlTRStartTag, "<tr>\n" ); |
|
39 |
_LIT8( KHtmlTREndTag, "</tr>\n" ); |
|
40 |
_LIT8( KHtmlTitleColumnStart, "<td width=\"100\" bgcolor=\"#888888\"><b>" ); |
|
41 |
_LIT8( KHtmlTitleColumnEnd, "</b></td>\n" ); |
|
42 |
_LIT8( KHtmlTestNameTitle, "Test name" ); |
|
43 |
_LIT8( KHtmlFileNameTitle, "File name" ); |
|
44 |
_LIT8( KHtmlLineNumberTitle, "Line number" ); |
|
45 |
_LIT8( KHtmlReasonTitle, "Reason" ); |
|
46 |
_LIT8( KHtmlValueColumnStart, "<td bgcolor=\"#BBBBBB\">" ); |
|
47 |
_LIT8( KHtmlValueColumnEnd, "</td>\n" ); |
|
48 |
||
49 |
||
50 |
// ----------------------------------------------------------------------------- |
|
51 |
// |
|
52 |
// ----------------------------------------------------------------------------- |
|
53 |
// |
|
54 |
CSymbianUnitTestOutputAsHtml* CSymbianUnitTestOutputAsHtml::NewL( |
|
55 |
const TDesC& aFileName ) |
|
56 |
{ |
|
57 |
CSymbianUnitTestOutputAsHtml* self = |
|
58 |
new( ELeave )CSymbianUnitTestOutputAsHtml; |
|
59 |
CleanupStack::PushL( self ); |
|
60 |
self->ConstructL( aFileName ); |
|
61 |
CleanupStack::Pop( self ); |
|
62 |
return self; |
|
63 |
} |
|
64 |
||
65 |
// ----------------------------------------------------------------------------- |
|
66 |
// |
|
67 |
// ----------------------------------------------------------------------------- |
|
68 |
// |
|
69 |
CSymbianUnitTestOutputAsHtml::CSymbianUnitTestOutputAsHtml() |
|
70 |
{ |
|
71 |
} |
|
72 |
||
73 |
// ----------------------------------------------------------------------------- |
|
74 |
// |
|
75 |
// ----------------------------------------------------------------------------- |
|
76 |
// |
|
77 |
CSymbianUnitTestOutputAsHtml::~CSymbianUnitTestOutputAsHtml() |
|
78 |
{ |
|
79 |
} |
|
80 |
||
81 |
// ----------------------------------------------------------------------------- |
|
82 |
// From CSymbianUnitTestOutputFormatter |
|
83 |
// ----------------------------------------------------------------------------- |
|
84 |
// |
|
85 |
const TDesC& CSymbianUnitTestOutputAsHtml::FileExtension() const |
|
86 |
{ |
|
87 |
return KHtmlOutput; |
|
88 |
} |
|
89 |
||
90 |
// ----------------------------------------------------------------------------- |
|
91 |
// From CSymbianUnitTestOutputFormatter |
|
92 |
// ----------------------------------------------------------------------------- |
|
93 |
// |
|
94 |
void CSymbianUnitTestOutputAsHtml::PrintHeaderL( |
|
95 |
CSymbianUnitTestResult& aResult ) |
|
96 |
{ |
|
97 |
iOutputWriter->WriteL( KHtmlHeader ); |
|
98 |
iOutputWriter->WriteL( KHtmlBodyStartTag ); |
|
99 |
iOutputWriter->WriteL( KHtmlMainHeaderStartTag, aResult.TestCount() ); |
|
100 |
iOutputWriter->WriteDateAndTimeL(); |
|
101 |
iOutputWriter->WriteL( KHtmlMainHeaderEndTag ); |
|
102 |
} |
|
103 |
||
104 |
// ----------------------------------------------------------------------------- |
|
105 |
// From CSymbianUnitTestOutputFormatter |
|
106 |
// ----------------------------------------------------------------------------- |
|
107 |
// |
|
108 |
void CSymbianUnitTestOutputAsHtml::PrintPassedTestsL( |
|
109 |
CSymbianUnitTestResult& aResult ) |
|
110 |
{ |
|
111 |
iOutputWriter->WriteL( KHtmlPassedTests, aResult.PassedTestCount() ); |
|
1
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
112 |
iOutputWriter->WriteL( KHtmlTableStartTag ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
113 |
const CDesCArray& testCaseNames = aResult.TestCaseNames(); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
114 |
for ( TInt i=0; i < testCaseNames.Count(); i++ ) |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
115 |
{ |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
116 |
HBufC8* testName = CnvUtfConverter::ConvertFromUnicodeToUtf8L( testCaseNames[i] ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
117 |
PrintTableRowL( KHtmlTestNameTitle, *testName ); |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
118 |
delete testName; |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
119 |
} |
bbd31066657e
publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents:
0
diff
changeset
|
120 |
iOutputWriter->WriteL( KHtmlTableEndTag ); |
0 | 121 |
} |
122 |
||
123 |
// ----------------------------------------------------------------------------- |
|
124 |
// From CSymbianUnitTestOutputFormatter |
|
125 |
// ----------------------------------------------------------------------------- |
|
126 |
// |
|
127 |
void CSymbianUnitTestOutputAsHtml::PrintFailedTestsL( |
|
128 |
CSymbianUnitTestResult& aResult ) |
|
129 |
{ |
|
130 |
iOutputWriter->WriteL( KHtmlFailedTests, aResult.Failures().Count() ); |
|
131 |
for ( TInt i=0; i < aResult.Failures().Count(); i++ ) |
|
132 |
{ |
|
133 |
CSymbianUnitTestFailure* failure = aResult.Failures()[ i ]; |
|
134 |
iOutputWriter->WriteL( KHtmlTableStartTag ); |
|
135 |
PrintTableRowL( KHtmlTestNameTitle, failure->TestName() ); |
|
136 |
PrintTableRowL( KHtmlReasonTitle, failure->FailureMessage() ); |
|
137 |
if ( failure->LineNumber() >= 0 ) |
|
138 |
{ |
|
139 |
TBuf8< 20 > value; |
|
140 |
value.AppendNum( failure->LineNumber() ); |
|
141 |
PrintTableRowL( KHtmlLineNumberTitle, value ); |
|
142 |
} |
|
143 |
if ( failure->FileName().Length() > 0 ) |
|
144 |
{ |
|
145 |
PrintTableRowL( KHtmlFileNameTitle, failure->FileName() ); |
|
146 |
} |
|
147 |
iOutputWriter->WriteL( KHtmlTableEndTag ); |
|
148 |
iOutputWriter->WriteL( KHtmlParagraphBreak ); |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
// ----------------------------------------------------------------------------- |
|
153 |
// From CSymbianUnitTestOutputFormatter |
|
154 |
// ----------------------------------------------------------------------------- |
|
155 |
// |
|
156 |
void CSymbianUnitTestOutputAsHtml::PrintFooterL() |
|
157 |
{ |
|
158 |
iOutputWriter->WriteL( KHtmlBodyEndTag ); |
|
159 |
iOutputWriter->WriteL( KHtmlFooter ); |
|
160 |
} |
|
161 |
||
162 |
// ----------------------------------------------------------------------------- |
|
163 |
// |
|
164 |
// ----------------------------------------------------------------------------- |
|
165 |
// |
|
166 |
void CSymbianUnitTestOutputAsHtml::PrintTableRowL( |
|
167 |
const TDesC8& aTitle, |
|
168 |
const TDesC8& aValue ) |
|
169 |
{ |
|
170 |
iOutputWriter->WriteL( KHtmlTRStartTag ); |
|
171 |
iOutputWriter->WriteL( KHtmlTitleColumnStart ); |
|
172 |
iOutputWriter->WriteL( aTitle ); |
|
173 |
iOutputWriter->WriteL( KHtmlTitleColumnEnd ); |
|
174 |
iOutputWriter->WriteL( KHtmlValueColumnStart ); |
|
175 |
iOutputWriter->WriteL( aValue ); |
|
176 |
iOutputWriter->WriteL( KHtmlValueColumnEnd ); |
|
177 |
iOutputWriter->WriteL( KHtmlTREndTag ); |
|
178 |
} |