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