|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This contains Flogger Unit Test Case 013.xx |
|
15 |
|
16 // EPOC includes |
|
17 #include <e32base.h> |
|
18 |
|
19 // Test system includes |
|
20 #include <comms-infras/commsdebugutility.h> |
|
21 #include "TestMessage.h" |
|
22 #include <f32file.h> |
|
23 |
|
24 |
|
25 //User includes |
|
26 #include "teststepcomsdbg.h" |
|
27 #include "step_013_xx.h" |
|
28 |
|
29 |
|
30 /** |
|
31 * Function Name : CFloggerTest013_01 |
|
32 * Input parameters : None |
|
33 * Output parameters : None |
|
34 * Description : This is the constructor |
|
35 */ |
|
36 |
|
37 |
|
38 CFloggerTest013_01::CFloggerTest013_01() |
|
39 { |
|
40 // store the name of this test case |
|
41 SetTestStepName(_L("step_013_01")); |
|
42 } |
|
43 |
|
44 |
|
45 /** |
|
46 * Function Name :~ CFloggerTest013_01 |
|
47 * Input parameters : None |
|
48 * Output parameters : None |
|
49 * Description : This is the Destructor |
|
50 */ |
|
51 |
|
52 |
|
53 CFloggerTest013_01::~CFloggerTest013_01() |
|
54 { |
|
55 } |
|
56 |
|
57 |
|
58 /** |
|
59 * Function Name : doTestStepL |
|
60 * Input parameters : None |
|
61 * Output parameters : TVerdict |
|
62 * Description : This function returns weather the test case 013_01 has |
|
63 * passed or failed |
|
64 |
|
65 */ |
|
66 |
|
67 |
|
68 TVerdict CFloggerTest013_01::doTestStepL( ) |
|
69 { |
|
70 INFO_PRINTF1(_L("Step 013.01 called ")); |
|
71 |
|
72 if ( executeStepL(EFalse) == KErrNone ) |
|
73 SetTestStepResult(EPass); |
|
74 |
|
75 else |
|
76 SetTestStepResult(EFail); |
|
77 |
|
78 |
|
79 User::After(KTimeForDisplay1); |
|
80 return TestStepResult(); |
|
81 } |
|
82 |
|
83 /** |
|
84 * Function Name : executeStepL |
|
85 * Input parameters : None |
|
86 * Output parameters : TInt |
|
87 * Description : This function writes the test data in to the log file |
|
88 * This function check the test message is present in the |
|
89 * log file |
|
90 |
|
91 */ |
|
92 |
|
93 |
|
94 TInt CFloggerTest013_01::executeStepL() |
|
95 { |
|
96 return KErrGeneral; |
|
97 } |
|
98 |
|
99 /** |
|
100 * Function Name : executeStepL |
|
101 * Input parameters : None |
|
102 * Output parameters : TInt |
|
103 * Description : This function writes the test data in to the log file |
|
104 * This function check the test message is present in the |
|
105 * log file |
|
106 |
|
107 */ |
|
108 |
|
109 |
|
110 TInt CFloggerTest013_01::executeStepL(TBool heapTest) |
|
111 { |
|
112 TInt ret = KErrGeneral; |
|
113 ret = DoTestWrite(); |
|
114 if (ret == KErrNone ) |
|
115 { |
|
116 User::After(KTimeToLog); |
|
117 TRAPD(r, ret = DoTestCheckWriteL() ); |
|
118 if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone))) |
|
119 { |
|
120 ret = KErrNoMemory; |
|
121 } |
|
122 else if (r != KErrNone) |
|
123 { |
|
124 ret = r; |
|
125 } |
|
126 } |
|
127 return ret; |
|
128 } |
|
129 |
|
130 |
|
131 /** |
|
132 * Function Name : DoTestWrite |
|
133 * Input parameters : None |
|
134 * Output parameters : TInt |
|
135 * Description : This function writes the data to the file logger |
|
136 |
|
137 */ |
|
138 |
|
139 |
|
140 TInt CFloggerTest013_01::DoTestWrite() |
|
141 { |
|
142 _LIT16(KTestMessageOne,"TC 13_01: The value of test integer variable :%d"); |
|
143 DoTestWriteFormat(KTestMessageOne, 100); //Write unicode formatted test descriptor |
|
144 |
|
145 // connect so we can flush file buffer for heap check since timer is killed in heap checks |
|
146 RFileLogger theFlogger; |
|
147 theFlogger.Connect(); |
|
148 theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8); |
|
149 ForceLogFlush(theFlogger); |
|
150 theFlogger.Close(); |
|
151 |
|
152 return KErrNone; |
|
153 } |
|
154 |
|
155 |
|
156 /** |
|
157 * Function Name : DoTestWriteFormat |
|
158 * Input parameters : TRefByValue<const TDesC16> |
|
159 * Output parameters : TInt |
|
160 * Description : This function writes formatted data to the file logger |
|
161 |
|
162 */ |
|
163 |
|
164 |
|
165 TInt CFloggerTest013_01::DoTestWriteFormat(TRefByValue<const TDesC16> aFmt,...) |
|
166 { |
|
167 VA_LIST list; |
|
168 VA_START(list,aFmt); |
|
169 TRAPD(res, RFileLogger::WriteFormat(KStdSubsysTag8, KStdCompTag8, aFmt, list)); |
|
170 return res; |
|
171 } |
|
172 |
|
173 |
|
174 /** |
|
175 * Function Name : DoTestCheckWriteL |
|
176 * Input parameters : None |
|
177 * Output parameters : TInt |
|
178 * Description : This function checks the weather test data was written |
|
179 * in to the log file by DoTestWrite() or not. |
|
180 |
|
181 */ |
|
182 |
|
183 |
|
184 TInt CFloggerTest013_01::DoTestCheckWriteL() |
|
185 { |
|
186 RFile theFile; |
|
187 HBufC8 * hBuffer; |
|
188 TInt listfilesize; |
|
189 TInt returnCode; |
|
190 RFs fileSystem; //For file operation create a file system |
|
191 TBuf8<256> testData; //To hold the test descriptor |
|
192 |
|
193 _LIT8(KTestMessageOne,"TC 13_01: The value of test integer variable :%d"); |
|
194 testData.Format(KTestMessageOne,100); |
|
195 |
|
196 _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path |
|
197 |
|
198 User::LeaveIfError(fileSystem.Connect()); |
|
199 |
|
200 //Open the file in the read mode |
|
201 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); |
|
202 |
|
203 |
|
204 returnCode = theFile.Size(listfilesize); //Size of the file |
|
205 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer |
|
206 CleanupStack::PushL(hBuffer); |
|
207 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer |
|
208 |
|
209 // Read from position 0: start of file |
|
210 returnCode = theFile.Read(ptrString); |
|
211 |
|
212 |
|
213 returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read |
|
214 //from the file |
|
215 |
|
216 theFile.Close(); |
|
217 fileSystem.Close(); |
|
218 CleanupStack::PopAndDestroy(hBuffer); |
|
219 if (returnCode > 0) |
|
220 return KErrNone; |
|
221 else |
|
222 return KErrNotFound; |
|
223 } |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 /** |
|
230 * Function Name : CFloggerTest013_02 |
|
231 * Input parameters : None |
|
232 * Output parameters : None |
|
233 * Description : This is the constructor |
|
234 */ |
|
235 |
|
236 |
|
237 CFloggerTest013_02::CFloggerTest013_02() |
|
238 { |
|
239 // store the name of this test case |
|
240 SetTestStepName(_L("step_013_02")); |
|
241 } |
|
242 |
|
243 |
|
244 /** |
|
245 * Function Name :~ CFloggerTest013_02 |
|
246 * Input parameters : None |
|
247 * Output parameters : None |
|
248 * Description : This is the Destructor |
|
249 */ |
|
250 |
|
251 |
|
252 CFloggerTest013_02::~CFloggerTest013_02() |
|
253 { |
|
254 } |
|
255 |
|
256 |
|
257 |
|
258 /** |
|
259 * Function Name : doTestStepL |
|
260 * Input parameters : None |
|
261 * Output parameters : TVerdict |
|
262 * Description : This function returns weather the test case 013_02 has |
|
263 * passed or failed |
|
264 |
|
265 */ |
|
266 |
|
267 |
|
268 TVerdict CFloggerTest013_02::doTestStepL( ) |
|
269 { |
|
270 INFO_PRINTF1(_L("Step 013.02 called ")); |
|
271 |
|
272 if ( executeStepL() == KErrNone ) |
|
273 SetTestStepResult(EPass); |
|
274 |
|
275 else |
|
276 SetTestStepResult(EFail); |
|
277 |
|
278 |
|
279 User::After(KTimeForDisplay1); |
|
280 return TestStepResult(); |
|
281 } |
|
282 |
|
283 |
|
284 /** |
|
285 * Function Name : executeStepL |
|
286 * Input parameters : None |
|
287 * Output parameters : TInt |
|
288 * Description : This function writes the test data in to the log file |
|
289 * This function check the test message is present in the |
|
290 * log file |
|
291 |
|
292 */ |
|
293 |
|
294 |
|
295 TInt CFloggerTest013_02::executeStepL() |
|
296 { |
|
297 User::After(1000*1000); //Need this or connect will return KErrServerTerminated |
|
298 |
|
299 TInt ret = KErrGeneral; |
|
300 |
|
301 ret = DoTestWrite(); |
|
302 if (ret == KErrNone ) |
|
303 { |
|
304 TRAPD(r, ret = DoTestCheckWriteL()); |
|
305 if ( r != KErrNone) |
|
306 ret = r; |
|
307 } |
|
308 return ret; |
|
309 |
|
310 } |
|
311 |
|
312 /** |
|
313 * Function Name : executeStepL |
|
314 * Input parameters : None |
|
315 * Output parameters : TInt |
|
316 * Description : This function writes the test data in to the log file |
|
317 * This function check the test message is present in the |
|
318 * log file |
|
319 |
|
320 */ |
|
321 |
|
322 |
|
323 TInt CFloggerTest013_02::executeStepL(TBool) |
|
324 { |
|
325 return KErrGeneral; |
|
326 } |
|
327 |
|
328 |
|
329 /** |
|
330 * Function Name : DoTestWrite |
|
331 * Input parameters : None |
|
332 * Output parameters : TInt |
|
333 * Description : This function writes the data to the file logger |
|
334 |
|
335 */ |
|
336 |
|
337 |
|
338 TInt CFloggerTest013_02::DoTestWrite() |
|
339 { |
|
340 _LIT(KTestLongMessage,"TEST 13: This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message %d"); //Unicode long test decriptor |
|
341 |
|
342 TRAPD(res, DoTestWriteFormat(KTestLongMessage, 100)); //Write unicode formatted test descriptor |
|
343 return res; |
|
344 } |
|
345 |
|
346 |
|
347 /** |
|
348 * Function Name : DoTestWriteFormat |
|
349 * Input parameters : TRefByValue<const TDesC16> |
|
350 * Output parameters : TInt |
|
351 * Description : This function writes formatted data to the file logger |
|
352 |
|
353 */ |
|
354 |
|
355 |
|
356 TInt CFloggerTest013_02::DoTestWriteFormat(TRefByValue<const TDesC16> aFmt,...) |
|
357 { |
|
358 TInt ret = KErrNone; |
|
359 RFileLogger theFlogger; |
|
360 |
|
361 ret = theFlogger.Connect(); //Just to clear the old log message |
|
362 if ( ret == KErrNone) |
|
363 ret = theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8); |
|
364 if ( ret == KErrNone) |
|
365 ret = theFlogger.ClearLog(); |
|
366 if ( ret == KErrNone) |
|
367 theFlogger.Close(); |
|
368 |
|
369 |
|
370 |
|
371 User::After(100000); |
|
372 |
|
373 VA_LIST list; |
|
374 VA_START(list,aFmt); |
|
375 RFileLogger::WriteFormat(KStdSubsysTag8, KStdCompTag8, aFmt, list); |
|
376 |
|
377 return KErrNone ; |
|
378 } |
|
379 |
|
380 |
|
381 |
|
382 TInt CFloggerTest013_02::DoTestCheckWriteL() |
|
383 { |
|
384 User::After(KTimeToLog); |
|
385 |
|
386 RFile theFile; |
|
387 HBufC8 * hBuffer; |
|
388 TInt listfilesize,returnCode; |
|
389 RFs fileSystem; //For file operation create a file system |
|
390 TBuf8<256> testData; //To hold the test descriptor |
|
391 _LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path |
|
392 |
|
393 //The following contains the string of length 200(max) |
|
394 //which is written to the log file |
|
395 //_LIT(KTestLongMessage, "This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message"); |
|
396 _LIT(KTestLongMessage, "TEST 13: This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long"); |
|
397 |
|
398 //_LIT8(KOOMError, "#Logs may be lost out of memory!!"); |
|
399 |
|
400 User::LeaveIfError(fileSystem.Connect()); |
|
401 |
|
402 //Open the file in the read mode |
|
403 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); |
|
404 |
|
405 CleanupClosePushL(theFile); |
|
406 |
|
407 User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file |
|
408 |
|
409 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer |
|
410 CleanupStack::PushL(hBuffer); |
|
411 |
|
412 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer |
|
413 |
|
414 // Read from position 0: start of file |
|
415 User::LeaveIfError(returnCode = theFile.Read(ptrString)); |
|
416 |
|
417 testData.Copy(KTestLongMessage); //Copy the test descriptor |
|
418 returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read |
|
419 //from the file |
|
420 |
|
421 |
|
422 CleanupStack::PopAndDestroy(hBuffer); |
|
423 CleanupStack::PopAndDestroy(); //theFile |
|
424 if (returnCode > 0) |
|
425 return KErrNone; |
|
426 else |
|
427 return KErrGeneral; |
|
428 |
|
429 |
|
430 } |
|
431 |
|
432 |
|
433 /** |
|
434 * Function Name : CFloggerTest013_03 |
|
435 * Input parameters : None |
|
436 * Output parameters : None |
|
437 * Description : This is the constructor |
|
438 */ |
|
439 |
|
440 |
|
441 CFloggerTest013_03::CFloggerTest013_03() |
|
442 { |
|
443 // store the name of this test case |
|
444 SetTestStepName(_L("step_013_03")); |
|
445 } |
|
446 |
|
447 /** |
|
448 * Function Name :~ CFloggerTest013_03 |
|
449 * Input parameters : None |
|
450 * Output parameters : None |
|
451 * Description : This is the Destructor |
|
452 */ |
|
453 |
|
454 |
|
455 CFloggerTest013_03::~CFloggerTest013_03() |
|
456 { |
|
457 } |
|
458 |
|
459 |
|
460 /** |
|
461 * Function Name : doTestStepL |
|
462 * Input parameters : None |
|
463 * Output parameters : TVerdict |
|
464 * Description : This function is responsible for doing the heap test analysis |
|
465 */ |
|
466 |
|
467 |
|
468 TVerdict CFloggerTest013_03::doTestStepL( ) |
|
469 { |
|
470 INFO_PRINTF1(_L("Step 013.03 called ")); |
|
471 |
|
472 CFloggerTest013_01* step013_01 = new CFloggerTest013_01; |
|
473 CleanupStack::PushL(step013_01); |
|
474 doTestStepWithHeapFailureL( *step013_01, 1,20, KErrNone, ETrue); |
|
475 |
|
476 CleanupStack::PopAndDestroy(step013_01); |
|
477 User::After(KTimeForDisplay); |
|
478 return TestStepResult(); |
|
479 } |