|
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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <stiftestinterface.h> |
|
21 #include <s32file.h> |
|
22 #include "sysutiltests.h" |
|
23 |
|
24 // EXTERNAL DATA STRUCTURES |
|
25 |
|
26 // EXTERNAL FUNCTION PROTOTYPES |
|
27 |
|
28 // CONSTANTS |
|
29 |
|
30 // MACROS |
|
31 |
|
32 // LOCAL CONSTANTS AND MACROS |
|
33 |
|
34 // MODULE DATA STRUCTURES |
|
35 |
|
36 // LOCAL FUNCTION PROTOTYPES |
|
37 |
|
38 // FORWARD DECLARATIONS |
|
39 |
|
40 |
|
41 // --------------------------------------------------------- |
|
42 // CSysUtiltests::CSysUtiltests |
|
43 // Returns: KErrNone |
|
44 // --------------------------------------------------------- |
|
45 CSysUtiltests::CSysUtiltests() |
|
46 { |
|
47 |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------- |
|
51 // CSysUtiltests::ConstructL |
|
52 // Returns: KErrNone |
|
53 // --------------------------------------------------------- |
|
54 void CSysUtiltests::ConstructL() |
|
55 { |
|
56 User::LeaveIfError( iFs.Connect() ); |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------- |
|
60 // CSysUtiltests::NewL |
|
61 // Returns: KErrNone |
|
62 // --------------------------------------------------------- |
|
63 CSysUtiltests* CSysUtiltests::NewL() |
|
64 { |
|
65 CSysUtiltests* self = new (ELeave) CSysUtiltests; |
|
66 |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL(); |
|
69 CleanupStack::Pop(); |
|
70 |
|
71 return self; |
|
72 |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------- |
|
76 // CSysUtiltests::CSysUtiltests |
|
77 // Returns: KErrNone |
|
78 // --------------------------------------------------------- |
|
79 CSysUtiltests::~CSysUtiltests() |
|
80 { |
|
81 iFs.Close(); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------- |
|
85 // CSysUtiltests::InitL |
|
86 // Returns: KErrNone |
|
87 // --------------------------------------------------------- |
|
88 TInt CSysUtiltests::InitL( TFileName& /*aIniFile*/, TBool /*aFirstTime*/ ) |
|
89 { |
|
90 return KErrNone; |
|
91 |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------- |
|
95 // CSysUtiltests::Case |
|
96 // Returns: KErrNone |
|
97 // --------------------------------------------------------- |
|
98 const TCaseInfo CSysUtiltests::Case ( const TInt aCaseNumber ) const |
|
99 { |
|
100 |
|
101 // To add new test cases, implement new test case function and add new |
|
102 // line to KCases array specify the name of the case and the function |
|
103 // doing the test case |
|
104 // In practice, do following |
|
105 // 1) Make copy of existing function and change it name |
|
106 // 2) Duplicate the last line in cases array |
|
107 // 3) Change case name and function name in case array |
|
108 |
|
109 static TCaseInfoInternal const KCases[] = |
|
110 { |
|
111 |
|
112 // To add new test cases, add new items to this array |
|
113 ENTRY( "[SYSUTIL] GetVersionInfo test", CSysUtiltests::GetVersionInfo ), |
|
114 ENTRY( "[SYSUTIL] GetVersionInfo2 test", CSysUtiltests::GetVersionInfo2 ), |
|
115 ENTRY( "[SYSUTIL] GetOSVersionInfo test", CSysUtiltests::GetOSVersionInfo ), |
|
116 ENTRY( "[SYSUTIL] GetProductVersionInfo test", CSysUtiltests::GetProductVersionInfo ), |
|
117 ENTRY( "[SYSUTIL] GetOSVersionInfo2 test", CSysUtiltests::GetOSVersionInfo2 ), |
|
118 ENTRY( "[SYSUTIL] GetProductVersionInfo2 test", CSysUtiltests::GetProductVersionInfo2 ), |
|
119 ENTRY( "[SYSUTIL] GetProductCode test", CSysUtiltests::GetProductCode ), |
|
120 |
|
121 OOM_ENTRY( "[OOM_SYSUTIL] GetVersionInfo test", CSysUtiltests::GetVersionInfo ,ETrue,1,5 ), |
|
122 OOM_ENTRY( "[OOM_SYSUTIL] GetVersionInfo2 test", CSysUtiltests::GetVersionInfo2,ETrue,1,5 ), |
|
123 OOM_ENTRY( "[OOM_SYSUTIL] GetOSVersionInfo test", CSysUtiltests::GetOSVersionInfo ,ETrue,1,5), |
|
124 OOM_ENTRY( "[OOM_SYSUTIL] GetProductVersionInfo test", CSysUtiltests::GetProductVersionInfo ,ETrue,1,5), |
|
125 OOM_ENTRY( "[OOM_SYSUTIL] GetOSVersionInfo2 test", CSysUtiltests::GetOSVersionInfo2 ,ETrue,1,5), |
|
126 OOM_ENTRY( "[OOM_SYSUTIL] GetProductVersionInfo2 test", CSysUtiltests::GetProductVersionInfo2 ,ETrue,1,5), |
|
127 OOM_ENTRY( "[OOM_SYSUTIL] GetProductCode test", CSysUtiltests::GetProductCode ,ETrue,1,5) |
|
128 |
|
129 }; |
|
130 |
|
131 // Verify that case number is valid |
|
132 if( (TUint) aCaseNumber >= sizeof( KCases ) / |
|
133 sizeof( TCaseInfoInternal ) ) |
|
134 { |
|
135 |
|
136 // Invalid case, construct empty object |
|
137 TCaseInfo null( (const TText*) L"" ); |
|
138 null.iMethod = NULL; |
|
139 return null; |
|
140 |
|
141 } |
|
142 |
|
143 // Construct TCaseInfo object and return it |
|
144 TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName ); |
|
145 tmp.iMethod = KCases[ aCaseNumber ].iMethod; |
|
146 tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest; |
|
147 tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation; |
|
148 tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation; |
|
149 return tmp; |
|
150 |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------- |
|
154 // CSysUtiltests::GetTestCasesL |
|
155 // Returns: KErrNone |
|
156 // --------------------------------------------------------- |
|
157 TInt CSysUtiltests::GetTestCasesL( const TFileName& /*aConfigFile*/, |
|
158 RPointerArray<TTestCaseInfo>& aTestCases ) |
|
159 { |
|
160 |
|
161 // Loop through all test cases and create new |
|
162 // TTestCaseInfo items and append items to aTestCase array |
|
163 for( TInt i = 0; Case(i).iMethod != NULL; i++ ) |
|
164 { |
|
165 |
|
166 // Allocate new TTestCaseInfo from heap for a testcase definition. |
|
167 TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo(); |
|
168 |
|
169 // PushL TTestCaseInfo to CleanupStack. |
|
170 CleanupStack::PushL( newCase ); |
|
171 |
|
172 // Set number for the testcase. |
|
173 // When the testcase is run, this comes as a parameter to RunTestCaseL. |
|
174 newCase->iCaseNumber = i; |
|
175 |
|
176 // Set title for the test case. This is shown in UI to user. |
|
177 newCase->iTitle.Copy( Case(i).iCaseName ); |
|
178 |
|
179 // Append TTestCaseInfo to the testcase array. After appended |
|
180 // successfully the TTestCaseInfo object is owned (and freed) |
|
181 // by the TestServer. |
|
182 User::LeaveIfError(aTestCases.Append ( newCase ) ); |
|
183 |
|
184 // Pop TTestCaseInfo from the CleanupStack. |
|
185 CleanupStack::Pop( newCase ); |
|
186 |
|
187 } |
|
188 |
|
189 return KErrNone; |
|
190 |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------- |
|
194 // CSysUtiltests::RunTestCaseL |
|
195 // Returns: KErrNone |
|
196 // --------------------------------------------------------- |
|
197 TInt CSysUtiltests::RunTestCaseL( const TInt aCaseNumber, |
|
198 const TFileName& /*aConfig*/, |
|
199 TTestResult& aResult ) |
|
200 { |
|
201 |
|
202 // Return value |
|
203 TInt execStatus = KErrNone; |
|
204 |
|
205 // Get the pointer to test case function |
|
206 TCaseInfo tmp = Case ( aCaseNumber ); |
|
207 |
|
208 // Check that case number was valid |
|
209 if ( tmp.iMethod != NULL ) |
|
210 { |
|
211 // Valid case was found, call it via function pointer |
|
212 iMethod = tmp.iMethod; |
|
213 execStatus = ( this->*iMethod )( aResult ); |
|
214 } |
|
215 else |
|
216 { |
|
217 // Valid case was not found, return error. |
|
218 execStatus = KErrNotFound; |
|
219 } |
|
220 |
|
221 // Return case execution status (not the result of the case execution) |
|
222 return execStatus; |
|
223 |
|
224 } |
|
225 |
|
226 TInt CSysUtiltests::CheckIsFileExist( const TDesC& aFilename ) |
|
227 { |
|
228 RFs fs; |
|
229 TInt err; |
|
230 err = fs.Connect(); |
|
231 if (err != KErrNone) |
|
232 return err; |
|
233 |
|
234 RFile file; |
|
235 err = file.Open(fs, aFilename, EFileRead | EFileStreamText | EFileShareReadersOnly); |
|
236 |
|
237 file.Close(); |
|
238 fs.Close(); |
|
239 |
|
240 if ( err == KErrNotFound || err == KErrPathNotFound ) |
|
241 { |
|
242 err = KErrNotSupported; |
|
243 } |
|
244 |
|
245 return err; |
|
246 } |
|
247 |
|
248 |
|
249 // --------------------------------------------------------- |
|
250 // CSysUtiltests::LibEntryL |
|
251 // Returns: Poiter to CSysUtiltests class |
|
252 // --------------------------------------------------------- |
|
253 EXPORT_C CSysUtiltests* LibEntryL() |
|
254 { |
|
255 return CSysUtiltests::NewL(); |
|
256 |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CSysUtiltests::OOMTestQueryL |
|
261 // Used to check if a particular test case should be run in OOM conditions and |
|
262 // which memory allocations should fail. |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 TBool CSysUtiltests::OOMTestQueryL( |
|
266 const TFileName& /* aTestCaseFile */, |
|
267 const TInt aCaseNumber, |
|
268 TOOMFailureType& /* aFailureType */, |
|
269 TInt& aFirstMemFailure, |
|
270 TInt& aLastMemFailure ) |
|
271 { |
|
272 aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation; |
|
273 aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation; |
|
274 |
|
275 return Case( aCaseNumber ).iIsOOMTest; |
|
276 |
|
277 } |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // CSysUtiltests::OOMTestInitializeL |
|
281 // Used to perform the test environment setup for a particular OOM test case. |
|
282 // Test Modules may use the initialization file to read parameters for Test |
|
283 // Module initialization but they can also have their own configure file or |
|
284 // some other routine to initialize themselves. |
|
285 // |
|
286 // NOTE: User may add implementation for OOM test environment initialization. |
|
287 // Usually no implementation is required. |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 void CSysUtiltests::OOMTestInitializeL( |
|
291 const TFileName& /* aTestCaseFile */, |
|
292 const TInt /* aCaseNumber */ ) |
|
293 { |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CSysUtiltests::OOMHandleWarningL |
|
298 // In some cases the heap memory allocation should be skipped, either due to |
|
299 // problems in the OS code or components used by the code being tested, or even |
|
300 // inside the tested components which are implemented this way on purpose (by |
|
301 // design), so it is important to give the tester a way to bypass allocation |
|
302 // failures. |
|
303 // |
|
304 // NOTE: User may add implementation for OOM test warning handling. Usually no |
|
305 // implementation is required. |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 void CSysUtiltests::OOMHandleWarningL( |
|
309 const TFileName& /* aTestCaseFile */, |
|
310 const TInt /* aCaseNumber */, |
|
311 TInt& /* aFailNextValue */ ) |
|
312 { |
|
313 } |
|
314 |
|
315 // ----------------------------------------------------------------------------- |
|
316 // CSysUtiltests::OOMTestFinalizeL |
|
317 // Used to perform the test environment cleanup for a particular OOM test case. |
|
318 // |
|
319 // NOTE: User may add implementation for OOM test environment finalization. |
|
320 // Usually no implementation is required. |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 void CSysUtiltests::OOMTestFinalizeL( |
|
324 const TFileName& /* aTestCaseFile */, |
|
325 const TInt /* aCaseNumber */ ) |
|
326 { |
|
327 } |
|
328 |