|
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 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32math.h> |
|
22 #include "WebUtilsBCTest.h" |
|
23 |
|
24 // EXTERNAL DATA STRUCTURES |
|
25 //extern ?external_data; |
|
26 |
|
27 // EXTERNAL FUNCTION PROTOTYPES |
|
28 //extern ?external_function( ?arg_type,?arg_type ); |
|
29 |
|
30 // CONSTANTS |
|
31 //const ?type ?constant_var = ?constant; |
|
32 |
|
33 // MACROS |
|
34 //#define ?macro ?macro_def |
|
35 |
|
36 // LOCAL CONSTANTS AND MACROS |
|
37 //const ?type ?constant_var = ?constant; |
|
38 //#define ?macro_name ?macro_def |
|
39 |
|
40 // MODULE DATA STRUCTURES |
|
41 //enum ?declaration |
|
42 //typedef ?declaration |
|
43 |
|
44 // LOCAL FUNCTION PROTOTYPES |
|
45 //?type ?function_name( ?arg_type, ?arg_type ); |
|
46 |
|
47 // FORWARD DECLARATIONS |
|
48 //class ?FORWARD_CLASSNAME; |
|
49 |
|
50 // ============================= LOCAL FUNCTIONS =============================== |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // ?function_name ?description. |
|
54 // ?description |
|
55 // Returns: ?value_1: ?description |
|
56 // ?value_n: ?description_line1 |
|
57 // ?description_line2 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 /* |
|
61 ?type ?function_name( |
|
62 ?arg_type arg, // ?description |
|
63 ?arg_type arg) // ?description |
|
64 { |
|
65 |
|
66 ?code // ?comment |
|
67 |
|
68 // ?comment |
|
69 ?code |
|
70 } |
|
71 */ |
|
72 |
|
73 // ============================ MEMBER FUNCTIONS =============================== |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CWebUtilsBCTest::Case |
|
77 // Returns a test case by number. |
|
78 // |
|
79 // This function contains an array of all available test cases |
|
80 // i.e pair of case name and test function. If case specified by parameter |
|
81 // aCaseNumber is found from array, then that item is returned. |
|
82 // |
|
83 // The reason for this rather complicated function is to specify all the |
|
84 // test cases only in one place. It is not necessary to understand how |
|
85 // function pointers to class member functions works when adding new test |
|
86 // cases. See function body for instructions how to add new test case. |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 const TCaseInfo CWebUtilsBCTest::Case ( |
|
90 const TInt aCaseNumber ) const |
|
91 { |
|
92 |
|
93 /** |
|
94 * To add new test cases, implement new test case function and add new |
|
95 * line to KCases array specify the name of the case and the function |
|
96 * doing the test case |
|
97 * In practice, do following |
|
98 * 1) Make copy of existing test case function and change its name |
|
99 * and functionality. Note that the function must be added to |
|
100 * WebUtilsBCTest.cpp file and to WebUtilsBCTest.h |
|
101 * header file. |
|
102 * |
|
103 * 2) Add entry to following KCases array either by using: |
|
104 * |
|
105 * 2.1: FUNCENTRY or ENTRY macro |
|
106 * ENTRY macro takes two parameters: test case name and test case |
|
107 * function name. |
|
108 * |
|
109 * FUNCENTRY macro takes only test case function name as a parameter and |
|
110 * uses that as a test case name and test case function name. |
|
111 * |
|
112 * Or |
|
113 * |
|
114 * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used |
|
115 * only with OOM (Out-Of-Memory) testing! |
|
116 * |
|
117 * OOM_ENTRY macro takes five parameters: test case name, test case |
|
118 * function name, TBool which specifies is method supposed to be run using |
|
119 * OOM conditions, TInt value for first heap memory allocation failure and |
|
120 * TInt value for last heap memory allocation failure. |
|
121 * |
|
122 * OOM_FUNCENTRY macro takes test case function name as a parameter and uses |
|
123 * that as a test case name, TBool which specifies is method supposed to be |
|
124 * run using OOM conditions, TInt value for first heap memory allocation |
|
125 * failure and TInt value for last heap memory allocation failure. |
|
126 */ |
|
127 |
|
128 static TCaseInfoInternal const KCases[] = |
|
129 { |
|
130 // To add new test cases, add new items to this array |
|
131 |
|
132 // NOTE: When compiled to GCCE, there must be Classname:: |
|
133 // declaration in front of the method name, e.g. |
|
134 // CDemoModule::PrintTest. Otherwise the compiler |
|
135 // gives errors. |
|
136 |
|
137 ENTRY( "Complete constructed user agent string", CWebUtilsBCTest::UserAgentTest ), |
|
138 ENTRY( "Complete constructed MMS user agent string", CWebUtilsBCTest::MMSUserAgentTest ), |
|
139 ENTRY( "Reads the URL to UA profile from cenrep", CWebUtilsBCTest::URLToUserAgentTest ), |
|
140 |
|
141 }; |
|
142 |
|
143 // Verify that case number is valid |
|
144 if( (TUint) aCaseNumber >= sizeof( KCases ) / |
|
145 sizeof( TCaseInfoInternal ) ) |
|
146 { |
|
147 // Invalid case, construct empty object |
|
148 TCaseInfo null( (const TText*) L"" ); |
|
149 null.iMethod = NULL; |
|
150 null.iIsOOMTest = EFalse; |
|
151 null.iFirstMemoryAllocation = 0; |
|
152 null.iLastMemoryAllocation = 0; |
|
153 return null; |
|
154 } |
|
155 |
|
156 // Construct TCaseInfo object and return it |
|
157 TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName ); |
|
158 tmp.iMethod = KCases[ aCaseNumber ].iMethod; |
|
159 tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest; |
|
160 tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation; |
|
161 tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation; |
|
162 return tmp; |
|
163 |
|
164 } |
|
165 |
|
166 /* |
|
167 ------------------------------------------------------------------------------- |
|
168 |
|
169 Class: CWebUtilsBCTest |
|
170 |
|
171 Method: UserAgentTest |
|
172 |
|
173 Description: Test To create UserAgent String. |
|
174 |
|
175 Parameters: TTestResult& aErrorDescription: out: |
|
176 Test result and on error case a short description of error |
|
177 |
|
178 Return Values: HBufC8*: Always vale of UAStringBuf to indicate that test was valid |
|
179 |
|
180 Errors/Exceptions: return Null if error |
|
181 |
|
182 Status: Approved |
|
183 |
|
184 ------------------------------------------------------------------------------- |
|
185 */ |
|
186 TInt CWebUtilsBCTest::UserAgentTest(TTestResult& aResult) |
|
187 { |
|
188 _LIT( KDefinition ,"State"); |
|
189 _LIT( KData ,"Test To create UserAgent String"); |
|
190 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
191 |
|
192 TInt ret = 0; |
|
193 |
|
194 HBufC8* result = iUserAgent->UserAgentL(); |
|
195 |
|
196 |
|
197 _LIT( KData2 ,"Finished"); |
|
198 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
199 |
|
200 if( result != NULL ) |
|
201 { |
|
202 _LIT( KDescription , "Test case passed" ); |
|
203 aResult.SetResult( KErrNone, KDescription ); |
|
204 ret = KErrNone; |
|
205 } |
|
206 else |
|
207 { |
|
208 _LIT( KDescription , "Test case failed" ); |
|
209 aResult.SetResult( KErrGeneral, KDescription ); |
|
210 ret = KErrGeneral; |
|
211 } |
|
212 |
|
213 // Case was executed |
|
214 return ret; |
|
215 } |
|
216 |
|
217 /* |
|
218 ------------------------------------------------------------------------------- |
|
219 |
|
220 Class: CWebUtilsBCTest |
|
221 |
|
222 Method: MMSUserAgentTest |
|
223 |
|
224 Description: Test To create MMS UserAgent String. |
|
225 |
|
226 Parameters: TTestResult& aErrorDescription: out: |
|
227 Test result and on error case a short description of error |
|
228 |
|
229 Return Values: HBufC8*: Always vale of UAStringBuf to indicate that test was valid |
|
230 |
|
231 Errors/Exceptions: return Null if error |
|
232 |
|
233 Status: Approved |
|
234 |
|
235 ------------------------------------------------------------------------------- |
|
236 */ |
|
237 TInt CWebUtilsBCTest::MMSUserAgentTest(TTestResult& aResult) |
|
238 { |
|
239 _LIT( KDefinition ,"State"); |
|
240 _LIT( KData ,"Test To create MMS UserAgent String"); |
|
241 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
242 |
|
243 TInt ret = 0; |
|
244 |
|
245 HBufC8* result = iUserAgent->MMSUserAgentL(); |
|
246 |
|
247 |
|
248 _LIT( KData2 ,"Finished"); |
|
249 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
250 |
|
251 if( result != NULL ) |
|
252 { |
|
253 _LIT( KDescription , "Test case passed" ); |
|
254 aResult.SetResult( KErrNone, KDescription ); |
|
255 ret = KErrNone; |
|
256 } |
|
257 else |
|
258 { |
|
259 _LIT( KDescription , "Test case failed" ); |
|
260 aResult.SetResult( KErrGeneral, KDescription ); |
|
261 ret = KErrGeneral; |
|
262 } |
|
263 |
|
264 // Case was executed |
|
265 return ret; |
|
266 } |
|
267 |
|
268 /* |
|
269 ------------------------------------------------------------------------------- |
|
270 |
|
271 Class: CWebUtilsBCTest |
|
272 |
|
273 Method: URLToUserAgentTest |
|
274 |
|
275 Description: Test To create MMS UserAgent String. |
|
276 |
|
277 Parameters: TTestResult& aErrorDescription: out: |
|
278 Test result and on error case a short description of error |
|
279 |
|
280 Return Values: TInt: Always vale of UAStringBuf to indicate that test was valid |
|
281 |
|
282 Errors/Exceptions: None |
|
283 |
|
284 Status: Approved |
|
285 |
|
286 ------------------------------------------------------------------------------- |
|
287 */ |
|
288 TInt CWebUtilsBCTest::URLToUserAgentTest(TTestResult& aResult) |
|
289 { |
|
290 _LIT( KDefinition ,"State"); |
|
291 _LIT( KData ,"Test for URL to UserAgent"); |
|
292 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
293 |
|
294 TBuf8<128> url = _L8("http://www.google.com"); |
|
295 TBuf8<128> url3G = _L8("http://www.yahoo.com"); |
|
296 |
|
297 TInt result = iUserAgent->URLToUserAgentProfileL(url,url3G); |
|
298 |
|
299 |
|
300 _LIT( KData2 ,"Finished"); |
|
301 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
302 |
|
303 if( result == KErrNone ) |
|
304 { |
|
305 _LIT( KDescription , "Test case passed" ); |
|
306 aResult.SetResult( KErrNone, KDescription ); |
|
307 } |
|
308 else |
|
309 { |
|
310 _LIT( KDescription , "Test case failed" ); |
|
311 aResult.SetResult( KErrGeneral, KDescription ); |
|
312 } |
|
313 |
|
314 // Case was executed |
|
315 return result; |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CWebUtilsBCTest::PrintTest |
|
320 // Simple printing to UI test. |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 TInt CWebUtilsBCTest::PrintTest( |
|
324 TTestResult& aResult ) |
|
325 { |
|
326 /* Simple print test */ |
|
327 _LIT( KPrintTest, "PrintTest" ); |
|
328 _LIT( KEnter, "Enter" ); |
|
329 _LIT( KOnGoing, "On-going" ); |
|
330 _LIT( KExit, "Exit" ); |
|
331 |
|
332 TestModuleIf().Printf( 0, KPrintTest, KEnter ); |
|
333 |
|
334 TestModuleIf().Printf( 1, KPrintTest, KOnGoing ); |
|
335 |
|
336 TestModuleIf().Printf( 0, KPrintTest, KExit ); |
|
337 |
|
338 // Test case passed |
|
339 |
|
340 // Sets test case result and description(Maximum size is KStifMaxResultDes) |
|
341 _LIT( KDescription, "PrintTest passed" ); |
|
342 aResult.SetResult( KErrNone, KDescription ); |
|
343 |
|
344 // Case was executed |
|
345 return KErrNone; |
|
346 |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // CWebUtilsBCTest::LoopTest |
|
351 // Another printing to UI test. |
|
352 // ----------------------------------------------------------------------------- |
|
353 // |
|
354 TInt CWebUtilsBCTest::LoopTest( TTestResult& aResult ) |
|
355 { |
|
356 |
|
357 /* Simple print and wait loop */ |
|
358 _LIT( KState, "State" ); |
|
359 _LIT( KLooping, "Looping" ); |
|
360 |
|
361 TestModuleIf().Printf( 0, KState, KLooping ); |
|
362 |
|
363 _LIT( KRunning, "Running" ); |
|
364 _LIT( KLoop, "%d" ); |
|
365 for( TInt i=0; i<10; i++) |
|
366 { |
|
367 TestModuleIf().Printf( 1, KRunning, KLoop, i); |
|
368 User::After( 1000000 ); |
|
369 } |
|
370 |
|
371 _LIT( KFinished, "Finished" ); |
|
372 TestModuleIf().Printf( 0, KState, KFinished ); |
|
373 |
|
374 // Test case passed |
|
375 |
|
376 // Sets test case result and description(Maximum size is KStifMaxResultDes) |
|
377 _LIT( KDescription, "LoopTest passed" ); |
|
378 aResult.SetResult( KErrNone, KDescription ); |
|
379 |
|
380 // Case was executed |
|
381 return KErrNone; |
|
382 |
|
383 } |
|
384 |
|
385 // ----------------------------------------------------------------------------- |
|
386 // ?classname::?member_function |
|
387 // ?implementation_description |
|
388 // (other items were commented in a header). |
|
389 // ----------------------------------------------------------------------------- |
|
390 // |
|
391 /* |
|
392 ?type ?classname::?member_function( |
|
393 ?arg_type arg, |
|
394 ?arg_type arg ) |
|
395 { |
|
396 |
|
397 ?code |
|
398 |
|
399 } |
|
400 */ |
|
401 |
|
402 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
403 |
|
404 // ----------------------------------------------------------------------------- |
|
405 // ?function_name implements... |
|
406 // ?implementation_description. |
|
407 // Returns: ?value_1: ?description |
|
408 // ?value_n: ?description |
|
409 // ?description |
|
410 // ----------------------------------------------------------------------------- |
|
411 // |
|
412 /* |
|
413 ?type ?function_name( |
|
414 ?arg_type arg, // ?description |
|
415 ?arg_type arg ) // ?description |
|
416 { |
|
417 |
|
418 ?code |
|
419 |
|
420 } |
|
421 */ |
|
422 // End of File |