|
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 "symbianunittestconsoleui.h" |
|
19 #include "symbianunittestcommandlineparser.h" |
|
20 #include "symbianunittestrunner.h" |
|
21 #include "symbianunittestversion.h" |
|
22 |
|
23 _LIT( KTitleTxt, "\n==== SymbianUnit v%d.%d.%d ====\n\n" ); |
|
24 _LIT( KAllocOnTxt, " Alloc: ON\n\n" ); |
|
25 _LIT( KAllocOffTxt, " Alloc: OFF\n\n" ); |
|
26 _LIT( KExecutingTestsTxt, " Executing...\n" ); |
|
27 _LIT( KTestRunnerFailedTxt, " Test run failed!\n Reason: %d\n" ); |
|
28 _LIT( KNoTestsFoundTxt, " No tests found!\n" ); |
|
29 _LIT( KTestsExecutedTxt, " Executed: %d / %d\n" ); |
|
30 _LIT( KPassedTestsTxt, " Passed: %d\n" ); |
|
31 _LIT( KFailedTestsTxt, " Failed: %d\n" ); |
|
32 _LIT( KSymbianUnitTestPanic, "SymbianUnit creation" ); |
|
33 _LIT( KWindowName, "SymbianUnit" ); |
|
34 _LIT( KPressAnyKeyTxt, "\n==[ press any key ]==\n " ); |
|
35 |
|
36 _LIT( KHelpTxt, |
|
37 "Allowed arguments:\n\n\ |
|
38 -tests|t=<dll,dll,...>\n\ |
|
39 -cases|c=<case,case,...>\n\ |
|
40 -alloc|a\n\ |
|
41 -help|h\n\ |
|
42 -output|o=<html|xml|txt>\n\ |
|
43 -timeout|to\n\ |
|
44 -noprompt\n" ); |
|
45 |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 GLDEF_C TInt E32Main() |
|
52 { |
|
53 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
54 TRAPD( err, MainL() ); |
|
55 __ASSERT_ALWAYS( |
|
56 err == KErrNone, User::Panic( KSymbianUnitTestPanic, err ) ); |
|
57 delete cleanup; |
|
58 User::Heap().Reset(); |
|
59 return err; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 LOCAL_C void MainL() |
|
67 { |
|
68 RThread().SetPriority( EPriorityAbsoluteForeground ); |
|
69 // install an active scheduler |
|
70 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler; |
|
71 CActiveScheduler::Install( scheduler ); |
|
72 CleanupStack::PushL( scheduler ); |
|
73 |
|
74 TSize size( KConsFullScreen, KConsFullScreen ); |
|
75 CConsoleBase* console = Console::NewL( KWindowName, size ); |
|
76 CleanupStack::Pop( scheduler ); |
|
77 |
|
78 CSymbianUnitTestConsoleUi* main = NULL; |
|
79 TRAPD( err, main = CSymbianUnitTestConsoleUi::NewL( *console ) ); |
|
80 if ( err == KErrNone ) |
|
81 { |
|
82 CActiveScheduler::Start(); |
|
83 } |
|
84 delete main; |
|
85 delete scheduler; |
|
86 // Do not delete console. It will check for memory leaks. |
|
87 // This is not what is wanted if running tests without |
|
88 // memory leak detection. |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CSymbianUnitTestConsoleUi* CSymbianUnitTestConsoleUi::NewLC( |
|
96 CConsoleBase& aConsole ) |
|
97 { |
|
98 CSymbianUnitTestConsoleUi* self = |
|
99 new( ELeave )CSymbianUnitTestConsoleUi( aConsole ); |
|
100 CleanupStack::PushL( self ); |
|
101 self->ConstructL(); |
|
102 return self; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 CSymbianUnitTestConsoleUi* CSymbianUnitTestConsoleUi::NewL( |
|
110 CConsoleBase& aConsole ) |
|
111 { |
|
112 CSymbianUnitTestConsoleUi* self = |
|
113 CSymbianUnitTestConsoleUi::NewLC( aConsole ); |
|
114 CleanupStack::Pop( self ); |
|
115 return self; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 CSymbianUnitTestConsoleUi::CSymbianUnitTestConsoleUi( CConsoleBase& aConsole ) |
|
123 : CActive( EPriorityStandard ), |
|
124 iConsole( aConsole ) |
|
125 { |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void CSymbianUnitTestConsoleUi::ConstructL() |
|
133 { |
|
134 User::SetJustInTime( EFalse ); // Do not stop on test case panics |
|
135 iCommandLineParser = CSymbianUnitTestCommandLineParser::NewL(); |
|
136 iTestRunner = CSymbianUnitTestRunner::NewL( *this ); |
|
137 CActiveScheduler::Add( this ); |
|
138 // Set ready to run immediately |
|
139 TRequestStatus *status = &iStatus; |
|
140 User::RequestComplete( status, KErrNone ); |
|
141 SetActive (); |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 CSymbianUnitTestConsoleUi::~CSymbianUnitTestConsoleUi() |
|
149 { |
|
150 Cancel(); |
|
151 delete iTestRunner; |
|
152 delete iCommandLineParser; |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // From CActive |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 void CSymbianUnitTestConsoleUi::RunL() |
|
160 { |
|
161 iConsole.Printf( KTitleTxt, SUT_MAJOR_VERSION, SUT_MINOR_VERSION, SUT_BUILD_VERSION); |
|
162 if ( iCommandLineParser->ShowHelp() ) |
|
163 { |
|
164 iConsole.Printf( KHelpTxt ); |
|
165 } |
|
166 else |
|
167 { |
|
168 PrintAllocFailureSimulationText(); |
|
169 iConsole.Printf( KExecutingTestsTxt ); |
|
170 TRAPD( err, |
|
171 iTestRunner->ExecuteTestsL( |
|
172 iCommandLineParser->TestDllNames(), |
|
173 iCommandLineParser->MemoryAllocationFailureSimulation(), |
|
174 iCommandLineParser->OutputFileName(), |
|
175 iCommandLineParser->OutputFormat(), |
|
176 iCommandLineParser->TestCaseNames(), |
|
177 iCommandLineParser->Timeout()) ) |
|
178 if ( err != KErrNone ) |
|
179 { |
|
180 iConsole.Printf( KTestRunnerFailedTxt, err ); |
|
181 } |
|
182 else |
|
183 { |
|
184 if ( iExecutedTestCount == 0 ) |
|
185 { |
|
186 iConsole.Printf( KNoTestsFoundTxt ); |
|
187 } |
|
188 } |
|
189 } |
|
190 if ( iCommandLineParser->PromptUser() ) |
|
191 { |
|
192 iConsole.Printf( KPressAnyKeyTxt ); |
|
193 iConsole.Getch(); // get and ignore character |
|
194 } |
|
195 CActiveScheduler::Stop(); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // From CActive |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 void CSymbianUnitTestConsoleUi::DoCancel() |
|
203 { |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // From MSymbianUnitTestUiCallBack |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 void CSymbianUnitTestConsoleUi::InfoMsg( const TDesC& aMessage ) |
|
211 { |
|
212 iConsole.Printf( aMessage ); |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // From MSymbianUnitTestUiCallBack |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 void CSymbianUnitTestConsoleUi::InfoMsg( |
|
220 const TDesC& aFormat, |
|
221 const TDesC& aMessage ) |
|
222 { |
|
223 iConsole.Printf( aFormat, &aMessage ); |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // From MSymbianUnitTestUiCallBack |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 void CSymbianUnitTestConsoleUi::IncrementExecutedTestsCount() |
|
231 { |
|
232 TPoint pos = iConsole.CursorPos(); |
|
233 pos.iY -= 1; |
|
234 if ( iExecutedTestCount > 0 ) |
|
235 { |
|
236 pos.iY -= 2; |
|
237 } |
|
238 iConsole.SetCursorPosAbs( pos ); |
|
239 iExecutedTestCount++; |
|
240 iConsole.Printf( |
|
241 KTestsExecutedTxt, iExecutedTestCount, iTestRunner->TestCount()); |
|
242 TInt passedTestCount = iExecutedTestCount - iTestRunner->FailedTestCount(); |
|
243 iConsole.Printf( KPassedTestsTxt, passedTestCount ); |
|
244 iConsole.Printf( KFailedTestsTxt, iTestRunner->FailedTestCount() ); |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 void CSymbianUnitTestConsoleUi::PrintAllocFailureSimulationText() |
|
252 { |
|
253 if ( iCommandLineParser->MemoryAllocationFailureSimulation() ) |
|
254 { |
|
255 iConsole.Printf( KAllocOnTxt ); |
|
256 } |
|
257 else |
|
258 { |
|
259 iConsole.Printf( KAllocOffTxt ); |
|
260 } |
|
261 } |