|
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 "symbianunittestoutputastext.h" |
|
22 |
|
23 _LIT8( KTxtExecutedTests, "\r\n %d unit tests executed " ); |
|
24 _LIT8( KTxtPassedTests, " Passed tests: %d\r\n\r\n" ); |
|
25 _LIT8( KTxtFailedTests, " Failed tests: %d\r\n\r\n" ); |
|
26 _LIT8( KTxtFailureTest, " Test: " ); |
|
27 _LIT8( KTxtFailureFile, " File: " ); |
|
28 _LIT8( KTxtFailureLine, " Line: %d\r\n" ); |
|
29 _LIT8( KTxtFailureReason, " Reason: " ); |
|
30 _LIT8( KLineEnd, "\r\n" ); |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CSymbianUnitTestOutputAsText* CSymbianUnitTestOutputAsText::NewL( |
|
37 const TDesC& aFileName ) |
|
38 { |
|
39 CSymbianUnitTestOutputAsText* self = |
|
40 new( ELeave )CSymbianUnitTestOutputAsText; |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL( aFileName ); |
|
43 CleanupStack::Pop( self ); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CSymbianUnitTestOutputAsText::CSymbianUnitTestOutputAsText() |
|
52 { |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CSymbianUnitTestOutputAsText::~CSymbianUnitTestOutputAsText() |
|
60 { |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // From CSymbianUnitTestOutputFormatter |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 const TDesC& CSymbianUnitTestOutputAsText::FileExtension() const |
|
68 { |
|
69 return KTextOutput; |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // From CSymbianUnitTestOutputFormatter |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CSymbianUnitTestOutputAsText::PrintHeaderL( |
|
77 CSymbianUnitTestResult& aResult ) |
|
78 { |
|
79 iOutputWriter->WriteL( KTxtExecutedTests, aResult.TestCount() ); |
|
80 iOutputWriter->WriteDateAndTimeL(); |
|
81 iOutputWriter->WriteL( KLineEnd ); |
|
82 iOutputWriter->WriteL( KLineEnd ); |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // From CSymbianUnitTestOutputFormatter |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 void CSymbianUnitTestOutputAsText::PrintPassedTestsL( |
|
90 CSymbianUnitTestResult& aResult ) |
|
91 { |
|
92 iOutputWriter->WriteL( KTxtPassedTests, aResult.PassedTestCount() ); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // From CSymbianUnitTestOutputFormatter |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CSymbianUnitTestOutputAsText::PrintFailedTestsL( |
|
100 CSymbianUnitTestResult& aResult ) |
|
101 { |
|
102 iOutputWriter->WriteL( KTxtFailedTests, aResult.Failures().Count() ); |
|
103 for ( TInt i=0; i < aResult.Failures().Count(); i++ ) |
|
104 { |
|
105 PrintFailureDetailsL( *( aResult.Failures()[ i ] ) ); |
|
106 } |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // From CSymbianUnitTestOutputFormatter |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CSymbianUnitTestOutputAsText::PrintFooterL() |
|
114 { |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 void CSymbianUnitTestOutputAsText::PrintFailureDetailsL( |
|
122 CSymbianUnitTestFailure& aTestFailure ) |
|
123 { |
|
124 iOutputWriter->WriteL( KTxtFailureTest ); |
|
125 iOutputWriter->WriteL( aTestFailure.TestName() ); |
|
126 iOutputWriter->WriteL( KLineEnd ); |
|
127 if ( aTestFailure.FileName().Length() > 0 ) |
|
128 { |
|
129 iOutputWriter->WriteL( KTxtFailureFile ); |
|
130 iOutputWriter->WriteL( aTestFailure.FileName() ); |
|
131 iOutputWriter->WriteL( KLineEnd ); |
|
132 } |
|
133 if ( aTestFailure.LineNumber() >= 0 ) |
|
134 { |
|
135 iOutputWriter->WriteL( KTxtFailureLine, aTestFailure.LineNumber() ); |
|
136 } |
|
137 iOutputWriter->WriteL( KTxtFailureReason ); |
|
138 iOutputWriter->WriteL( aTestFailure.FailureMessage() ); |
|
139 iOutputWriter->WriteL( KLineEnd ); |
|
140 iOutputWriter->WriteL( KLineEnd ); |
|
141 } |