1 /* |
|
2 * Copyright (c) 2002 - 2007 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: hgtestbase class member functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <Stiftestinterface.h> |
|
22 #include "hgtestbase.h" |
|
23 #include <e32math.h> |
|
24 #include <e32math.h> |
|
25 #include <aknappui.h> |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CHgTestBase::CHgTestBase |
|
31 // C++ default constructor can NOT contain any code, that |
|
32 // might leave. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CHgTestBase::CHgTestBase() |
|
36 { |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CHgTestBase::ConstructL |
|
41 // Symbian 2nd phase constructor can leave. |
|
42 // |
|
43 // Note: If OOM test case uses STIF Logger, then STIF Logger must be created |
|
44 // with static buffer size parameter (aStaticBufferSize). Otherwise Logger |
|
45 // allocates memory from heap and therefore causes error situations with OOM |
|
46 // testing. For more information about STIF Logger construction, see STIF Users |
|
47 // Guide. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CHgTestBase::BaseConstructL( const TDesC& aTestPath, |
|
51 const TDesC& aTestFile ) |
|
52 { |
|
53 iLog = CStifLogger::NewL( aTestPath, |
|
54 aTestFile); |
|
55 |
|
56 // Sample how to use logging |
|
57 _LIT( KLogStart, "Logging starts!" ); |
|
58 iLog->Log( KLogStart ); |
|
59 |
|
60 iVersionLogged = EFalse; |
|
61 iNumberOfTestCases = 0; |
|
62 |
|
63 // Construct active scheduler |
|
64 iActiveScheduler = new ( ELeave ) CActiveScheduler; |
|
65 |
|
66 // Install active scheduler |
|
67 // We don't need to check whether an active scheduler is already installed |
|
68 // as this is a new thread, so there won't be one |
|
69 CActiveScheduler::Install ( iActiveScheduler ); |
|
70 } |
|
71 |
|
72 // Destructor |
|
73 CHgTestBase::~CHgTestBase() |
|
74 { |
|
75 |
|
76 delete iTestDllName; |
|
77 delete iLog; |
|
78 //delete ENV_cleanup; |
|
79 delete iActiveScheduler; |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CHgTestBase::InitL |
|
84 // InitL is used to initialize the Test Module. |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 TInt CHgTestBase::InitL( |
|
88 TFileName& /*aIniFile*/, |
|
89 TBool /*aFirstTime*/ ) |
|
90 { |
|
91 return KErrNone; |
|
92 |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CHgTestBase::GetTestCasesL |
|
97 // GetTestCases is used to inquire test cases from the Test Module. Test |
|
98 // cases are stored to array of test cases. The Test Framework will be |
|
99 // the owner of the data in the RPointerArray after GetTestCases return |
|
100 // and it does the memory deallocation. |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 TInt CHgTestBase::GetTestCasesL( |
|
104 const TFileName& /*aConfig*/, |
|
105 RPointerArray<TTestCaseInfo>& aTestCases ) |
|
106 { |
|
107 TTestResult dummyResult; |
|
108 return MainTestL(CHgTestBase::EEnumerateTestCases, -1, aTestCases, dummyResult); |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CHgTestBase::OOMTestQueryL |
|
113 // Used to check if a particular test case should be run in OOM conditions and |
|
114 // which memory allocations should fail. |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 TBool CHgTestBase::OOMTestQueryL( |
|
118 const TFileName& /* aTestCaseFile */, |
|
119 const TInt /*aCaseNumber*/, |
|
120 TOOMFailureType& /* aFailureType */, |
|
121 TInt& /*aFirstMemFailure*/, |
|
122 TInt& /*aLastMemFailure*/ ) |
|
123 { |
|
124 return EFalse; |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CHgTestBase::OOMTestInitializeL |
|
129 // Used to perform the test environment setup for a particular OOM test case. |
|
130 // Test Modules may use the initialization file to read parameters for Test |
|
131 // Module initialization but they can also have their own configure file or |
|
132 // some other routine to initialize themselves. |
|
133 // |
|
134 // NOTE: User may add implementation for OOM test environment initialization. |
|
135 // Usually no implementation is required. |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void CHgTestBase::OOMTestInitializeL( |
|
139 const TFileName& /* aTestCaseFile */, |
|
140 const TInt /* aCaseNumber */ ) |
|
141 { |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CHgTestBase::OOMHandleWarningL |
|
146 // In some cases the heap memory allocation should be skipped, either due to |
|
147 // problems in the OS code or components used by the code being tested, or even |
|
148 // inside the tested components which are implemented this way on purpose (by |
|
149 // design), so it is important to give the tester a way to bypass allocation |
|
150 // failures. |
|
151 // |
|
152 // NOTE: User may add implementation for OOM test warning handling. Usually no |
|
153 // implementation is required. |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void CHgTestBase::OOMHandleWarningL( |
|
157 const TFileName& /* aTestCaseFile */, |
|
158 const TInt /* aCaseNumber */, |
|
159 TInt& /* aFailNextValue */ ) |
|
160 { |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CHgTestBase::OOMTestFinalizeL |
|
165 // Used to perform the test environment cleanup for a particular OOM test case. |
|
166 // |
|
167 // NOTE: User may add implementation for OOM test environment finalization. |
|
168 // Usually no implementation is required. |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 void CHgTestBase::OOMTestFinalizeL( |
|
172 const TFileName& /* aTestCaseFile */, |
|
173 const TInt /* aCaseNumber */ ) |
|
174 { |
|
175 } |
|
176 |
|
177 void CHgTestBase::SendTestModuleVersion( const TDesC& aModuleName ) |
|
178 { |
|
179 TVersion moduleVersion; |
|
180 moduleVersion.iMajor = TEST_MODULE_VERSION_MAJOR; |
|
181 moduleVersion.iMinor = TEST_MODULE_VERSION_MINOR; |
|
182 moduleVersion.iBuild = TEST_MODULE_VERSION_BUILD; |
|
183 |
|
184 TBool newVersionOfMethod = ETrue; |
|
185 TestModuleIf().SendTestModuleVersion(moduleVersion, aModuleName, newVersionOfMethod); |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CHgTestBase::RunTestCaseL |
|
190 // RunTestCaseL is used to run an individual test case specified |
|
191 // by aTestCase. Test cases that can be run may be requested from |
|
192 // Test Module by GetTestCases method before calling RunTestCase. |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 TInt CHgTestBase::RunTestCaseL( |
|
196 const TInt aCaseNumber, |
|
197 const TFileName& /*aConfig*/, |
|
198 TTestResult& aResult ) |
|
199 { |
|
200 if(!iVersionLogged) |
|
201 { |
|
202 CHgTestBase::SendTestModuleVersion( *iTestDllName ); |
|
203 iVersionLogged = ETrue; |
|
204 } |
|
205 |
|
206 RPointerArray<TTestCaseInfo> aTestCases; //temporary |
|
207 |
|
208 /** |
|
209 * SetupL is responsible for inicialization of all fields (etc.) common for all testcases |
|
210 * MainTestL starts required testcase |
|
211 * TeardownL destroys all data that was created by SetupL |
|
212 */ |
|
213 TInt errSetup = KErrNone; |
|
214 TInt errTestcase = KErrNone; |
|
215 |
|
216 if(aCaseNumber > iNumberOfTestCases) |
|
217 return KErrNotFound; |
|
218 |
|
219 __UHEAP_MARK; |
|
220 |
|
221 //TRAP(errSetup, MainTestL(CHgTestBase::ERunTestCase, STIF_RUN_SETUP, aTestCases, aResult); |
|
222 TRAP(errTestcase, MainTestL(CHgTestBase::ERunTestCase, aCaseNumber, aTestCases, aResult)); |
|
223 // MainTestL(CHgTestBase::ERunTestCase, STIF_RUN_TEARDOWN, aTestCases, aResult)); |
|
224 |
|
225 __UHEAP_MARKEND; |
|
226 |
|
227 if(errTestcase != KErrNone) |
|
228 { |
|
229 aResult.SetResult(errTestcase, _L("Testcase failed")); |
|
230 } |
|
231 if(errSetup != KErrNone) |
|
232 { |
|
233 aResult.SetResult(errSetup, _L("Setup or teardown failed")); |
|
234 } |
|
235 |
|
236 return KErrNone; |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CHgTestBase::MainTestL |
|
241 // Method responsible for enumerating and running test cases (and also setup and teardown activities before |
|
242 // and after each test case). |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 TInt CHgTestBase::MainTestL(CHgTestBase::TCallReason aRunReason, |
|
246 TInt aTestToRun, |
|
247 RPointerArray<TTestCaseInfo>& aTestCases, |
|
248 TTestResult& aResult ) |
|
249 { |
|
250 if(aRunReason == CHgTestBase::ERunTestCase) |
|
251 { |
|
252 if(aTestToRun < 0) |
|
253 { |
|
254 iLog->Log(_L("Running setup or teardown")); |
|
255 } |
|
256 else |
|
257 { |
|
258 iLog->Log(_L("Running test case #%d"), aTestToRun); |
|
259 } |
|
260 } |
|
261 else |
|
262 { |
|
263 iLog->Log(_L("Enumerating test cases.")); |
|
264 } |
|
265 |
|
266 TInt result = -1; |
|
267 |
|
268 // this method must be implemented in the test case |
|
269 result = RunTestL( aRunReason, aTestToRun, aTestCases, aResult ); |
|
270 |
|
271 if(aRunReason != CHgTestBase::ERunTestCase) |
|
272 { |
|
273 iNumberOfTestCases = result; |
|
274 iLog->Log(_L("Enumeration completed.")); |
|
275 } |
|
276 |
|
277 // Test case was executed |
|
278 return KErrNone; |
|
279 } |
|
280 |
|
281 // End of File |
|