|
1 /* |
|
2 * Copyright (c) 1998-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 the License "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 |
|
19 #ifndef __T_TESTHANDLER_H__ |
|
20 #define __T_TESTHANDLER_H__ |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <f32file.h> |
|
24 |
|
25 class MTestSpec; |
|
26 class Output; |
|
27 class CTestHandlerSettings; |
|
28 class CTestSetup; |
|
29 class CTestAction; |
|
30 class CTestRunner; |
|
31 |
|
32 class TTestSummary |
|
33 { |
|
34 public: |
|
35 TTestSummary(); |
|
36 TBool AllTestsPassed(); |
|
37 void PrintL(Output& aOut); |
|
38 |
|
39 public: |
|
40 TInt iTestsRun; |
|
41 TInt iTestsFailed; |
|
42 }; |
|
43 |
|
44 /** |
|
45 * CTestHandler is the class which runs the tests, and outputs results |
|
46 */ |
|
47 class CTestHandler : public CBase |
|
48 { |
|
49 public: |
|
50 /* |
|
51 * MTestSpec is the interface class, providing GetNextTest |
|
52 * TTestHandlerSettings provides the command line switches |
|
53 * |
|
54 * |
|
55 */ |
|
56 |
|
57 IMPORT_C static CTestHandler* NewLC(RFs& aFs, MTestSpec& aTestSpec, |
|
58 CTestHandlerSettings& aSettings, |
|
59 CConsoleBase* aConsole, |
|
60 Output* aOut); |
|
61 ~CTestHandler(); |
|
62 |
|
63 private: |
|
64 CTestHandler(RFs& aFs, MTestSpec& aTestSpec, CConsoleBase* aConsole, |
|
65 Output* aOut); |
|
66 void ConstructL(CTestHandlerSettings& aSettings); |
|
67 |
|
68 public: |
|
69 // API for test programs |
|
70 |
|
71 /// Run the test sequence |
|
72 IMPORT_C void RunTestsL(); |
|
73 |
|
74 /** |
|
75 * Set the test runner to use. This object takes ownership. Passing NULL |
|
76 * means use the default test runner. |
|
77 */ |
|
78 IMPORT_C void SetTestRunnerL(CTestRunner *aTestRunner); |
|
79 |
|
80 public: |
|
81 // API for test actions |
|
82 |
|
83 /// Access to shared data |
|
84 CBase* SharedData() const; |
|
85 void SetSharedData(CBase* aData); |
|
86 |
|
87 /// Set the heap mark |
|
88 void SetHeapMark(TInt aAllocCount); |
|
89 |
|
90 /// Get the heap mark |
|
91 TInt HeapMark(); |
|
92 |
|
93 /// Get the count of tests run/failed |
|
94 TTestSummary Summary(); |
|
95 |
|
96 private: |
|
97 /// The different possible locations a test can fail in. |
|
98 enum TTestFailLocation |
|
99 { |
|
100 EFailInTestHandler, |
|
101 EFailInPrerequisite, |
|
102 EFailInAction |
|
103 }; |
|
104 |
|
105 /// Get the human readable name for a fail location |
|
106 const TDesC& GetFailLocationName(TTestFailLocation aLoc); |
|
107 |
|
108 private: |
|
109 /** |
|
110 * Run one test. Called repeatedly by RunTestsL(). |
|
111 */ |
|
112 void RunTestL(CTestAction* aAction); |
|
113 /** |
|
114 * Record a test failure. |
|
115 */ |
|
116 void FailTestL(CTestAction* aAction, TTestFailLocation aLoc, TInt aErr); |
|
117 /** |
|
118 * Add a test to the list of failed tests. |
|
119 */ |
|
120 void AppendFailedTestL(TInt aIndex, const TDesC8& aName); |
|
121 |
|
122 private: |
|
123 /** |
|
124 * This function prints the number of tests passed, failed, etc at the end of |
|
125 * the test series. |
|
126 */ |
|
127 void DisplaySummary(); |
|
128 |
|
129 private: |
|
130 /** |
|
131 * Used by the test handler itself and the iManager |
|
132 */ |
|
133 RFs& iFs; |
|
134 |
|
135 /** |
|
136 * The settings that define the behaviour of the handler. |
|
137 */ |
|
138 CTestHandlerSettings *iSettings; |
|
139 |
|
140 CConsoleBase* iConsole; |
|
141 Output* iOut; |
|
142 |
|
143 CTestSetup* iTestSetup; |
|
144 CActiveScheduler* iScheduler; |
|
145 |
|
146 MTestSpec& iTestSpec; |
|
147 |
|
148 TInt iActionNumber; |
|
149 TInt iActionCount; |
|
150 |
|
151 /** |
|
152 * After completion of the series of tests, this array contains the numbers of |
|
153 * the failed tests. |
|
154 */ |
|
155 RArray<TInt> iFailedTests; |
|
156 /** |
|
157 * After completion of the series of tests, this array contains the names of |
|
158 * the failed tests. |
|
159 */ |
|
160 RPointerArray<HBufC> iFailedTestNames; |
|
161 /** |
|
162 * After completion of the series of tests, this array contains the names |
|
163 * of tests that failed because of known defects */ |
|
164 |
|
165 RPointerArray<HBufC> iKnownDefects; |
|
166 |
|
167 /** |
|
168 * Pointer to shared data. This is initially NULL. It can be accessed by |
|
169 * any of the test actions. If it is not NULL when this class is destroyed, |
|
170 * it is deleted. |
|
171 */ |
|
172 CBase* iSharedData; |
|
173 |
|
174 /// Pointer to the current test runner. We own this. |
|
175 CTestRunner* iTestRunner; |
|
176 |
|
177 /// Pointer to the test runner to install when we've finished the current |
|
178 /// test. We own this. |
|
179 CTestRunner* iNextTestRunner; |
|
180 |
|
181 /// The heap mark, used by heap mark actions |
|
182 TInt iHeapMark; |
|
183 }; |
|
184 |
|
185 #endif |