os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_026_xx.cpp
Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // This contains Flogger Unit Test Case 026.xx
20 // Test system includes
21 #include "teststepcomsdbg.h"
22 #include "step_026_xx.h"
24 #include <comms-infras/commsdebugutility.h>
28 * Function Name : CFloggerTest026_01
29 * Input parameters : None
30 * Output parameters : None
31 * Description : This is the constructor
35 CFloggerTest026_01::CFloggerTest026_01()
37 // Store the name of this test case
38 SetTestStepName(_L("step_026_01"));
43 * Function Name :~ CFloggerTest026_01
44 * Input parameters : None
45 * Output parameters : None
46 * Description : This is the Destructor
50 CFloggerTest026_01::~CFloggerTest026_01()
56 * Function Name : doTestStepL
57 * Input parameters : None
58 * Output parameters : TVerdict
59 * Description : This function returns weather the test case 026_01 has
65 TVerdict CFloggerTest026_01::doTestStepL( )
67 INFO_PRINTF1(_L("Step 026.01 called "));
68 User::After(KTimeForDisplay);
71 if ( executeStepL(EFalse) == KErrNone )
72 SetTestStepResult(EPass);
75 SetTestStepResult(EFail);
77 INFO_PRINTF1(_L("leaving Step 026.01 "));
78 User::After(KTimeForDisplay);
81 return TestStepResult();
85 * Function Name : executeStepL
86 * Input parameters : None
87 * Output parameters : TInt
88 * Description : This function sets the subsystem and component name
89 * checks weather they are set in the log file correctly
94 TInt CFloggerTest026_01::executeStepL()
99 * Function Name : executeStepL
100 * Input parameters : None
101 * Output parameters : TInt
102 * Description : This function sets the subsystem and component name
103 * checks weather they are set in the log file correctly
108 TInt CFloggerTest026_01::executeStepL(TBool heapTest)
110 return DoTestWrite(heapTest);
115 * Function Name : DoTestWriteL
116 * Input parameters : None
117 * Output parameters : TInt
118 * Description : This function writes the data to the file logger
123 TInt CFloggerTest026_01::DoTestWrite(TBool heapTest)
126 _LIT8(KTestMessage ,"TC no 26: This is test message");
129 ptrSubSystem.Set(_L8("SubSystem"));
130 ptrComponent.Set(_L8("Component"));
133 RFileLogger theFlogger;
135 ret = theFlogger.Connect();
139 ret = theFlogger.SetLogTags(ptrSubSystem, ptrComponent);
142 ret = theFlogger.ClearLog();
145 theFlogger.WriteBinary(KTestMessage);
146 ForceLogFlush(theFlogger);
147 TRAPD(r, ret = DoTestCheckWriteL());
148 if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
152 else if (r != KErrNone)
167 * Function Name : DoTestCheckWriteL
168 * Input parameters : None
169 * Output parameters : TInt
170 * Description : This function checks the weather test data was written
171 * in to the log file by DoTestWriteL() or not.
176 TInt CFloggerTest026_01::DoTestCheckWriteL()
178 User::After(1000*1000);
181 TInt listfilesize,returnCode;
182 RFs iFileSystem; //For file operation create a file system
183 TBuf8<256> testData; //To hold the test descriptor
184 _LIT(KLogFile,"c:\\logs\\log.txt");
186 _LIT(KTestSystem, "SubSystem"); //Test sytem name
187 _LIT(KTestComponent, "Component"); //Test component name
188 _LIT8(KTestMessage ,"TC no 26: This is test message"); // Test descriptor
190 _LIT8(KOOMError, "#Logs may be lost out of memory!!"); // Error message which has to be tested in log
192 User::LeaveIfError(iFileSystem.Connect());
194 //Open the file in the read mode
195 User::LeaveIfError(theFile.Open(iFileSystem, KLogFile, EFileWrite|EFileShareAny));
196 CleanupClosePushL(theFile);
198 User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
200 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
201 CleanupStack::PushL(hBuffer);
202 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
204 // Read from position 0: start of file
205 returnCode = theFile.Read(ptrString);
207 testData.Copy(KTestMessage); //Copy the test message
208 returnCode = ptrString.Find(KTestMessage); //find the test message in the
209 //buffer read from the file
210 if (returnCode == KErrNotFound)
212 returnCode = ptrString.Find(KOOMError);
214 User::Leave(KErrNoMemory);
217 if (returnCode > 0) // Test message present
219 testData.Copy(KTestSystem); //Copy the test tag
220 returnCode = ptrString.Find(testData); //Find the test tag in the
221 //buffer read from the file
223 if (returnCode > 0) // Test tag present
225 testData.Copy(KTestComponent); //Copy the test tag
226 returnCode = ptrString.Find(testData); //Find the test tag in the
227 //buffer read from the file
229 CleanupStack::PopAndDestroy(hBuffer);
230 CleanupStack::PopAndDestroy(); //theFile
232 if (returnCode > 0) // Test tag present
243 * Function Name : CFloggerTest026_02
244 * Input parameters : None
245 * Output parameters : None
246 * Description : This is the constructor
250 CFloggerTest026_02::CFloggerTest026_02()
252 // store the name of this test case
253 SetTestStepName(_L("step_026_02"));
258 * Function Name :~ CFloggerTest026_02
259 * Input parameters : None
260 * Output parameters : None
261 *Description : This is the Destructor
265 CFloggerTest026_02::~CFloggerTest026_02()
271 * Function Name : doTestStepL
272 * Input parameters : None
273 * Output parameters : TVerdict
274 * Description : This function is responsible for doing the heap test analysis
278 TVerdict CFloggerTest026_02::doTestStepL( )
280 INFO_PRINTF1(_L("Step 026.02 called "));
281 User::After(KTimeForDisplay);
283 CFloggerTest026_01* step026_01 = new CFloggerTest026_01;
284 CleanupStack::PushL(step026_01);
285 doTestStepWithHeapFailureL( *step026_01, 1, 20, KErrNone, ETrue);
287 CleanupStack::PopAndDestroy(step026_01);
289 return TestStepResult();
294 * Function Name : CFloggerTest026_03
295 * Input parameters : None
296 * Output parameters : None
297 * Description : This is the constructor
301 CFloggerTest026_03::CFloggerTest026_03()
303 // Store the name of this test case
304 SetTestStepName(_L("step_026_03"));
309 * Function Name :~ CFloggerTest026_03
310 * Input parameters : None
311 * Output parameters : None
312 * Description : This is the Destructor
316 CFloggerTest026_03::~CFloggerTest026_03()
322 * Function Name : doTestStepL
323 * Input parameters : None
324 * Output parameters : TVerdict
325 * Description : This function returns weather the test case 026_01 has
331 TVerdict CFloggerTest026_03::doTestStepL( )
333 INFO_PRINTF1(_L("Step 026.03 called "));
334 User::After(KTimeForDisplay);
337 if ( executeStepL() == KErrNone )
338 SetTestStepResult(EPass);
341 SetTestStepResult(EFail);
343 INFO_PRINTF1(_L("leaving Step 026.03 "));
344 User::After(KTimeForDisplay);
347 return TestStepResult();
352 * Function Name : executeStepL
353 * Input parameters : None
354 * Output parameters : TInt
355 * Description : This function sets the subsystem and component name
356 * checks weather they are set in the log file correctly
361 TInt CFloggerTest026_03::executeStepL()
363 return DoTestWrite();
367 * Function Name : executeStepL
368 * Input parameters : None
369 * Output parameters : TInt
370 * Description : This function sets the subsystem and component name
371 * checks weather they are set in the log file correctly
376 TInt CFloggerTest026_03::executeStepL(TBool)
382 * Function Name : DoTestWriteL
383 * Input parameters : None
384 * Output parameters : TInt
385 * Description : This function writes the data to the file logger
390 TInt CFloggerTest026_03::DoTestWrite()
393 _LIT8(KTestLongMessage,"TEST 26.3:#À!}!}!} }4}%}&´zß}}&} } } } }'}}(}!æ~.=¢ÛR.... .~ÿ}#À!}!}!} }4}%}&„¥T}9}}&}}'}}(}U~... .~. -ÿ}#À!}}!} }4}%}&„¥T}9}}&} } } } }'}}(}¾Ä~)... .~. .ÿ}#À!}!}} }$µZ}'}}(}U~... .~. -ÿ}#À!}}!} }4}%}&„¥T}9}}&} } } } }'}}(}¾Ä~... .~. .ÿ}#À!}!}$µZ"); //8 bit test decriptor
396 ptrSubSystem.Set(_L8("SubSystem"));
397 ptrComponent.Set(_L8("Component"));
400 RFileLogger theFlogger;
402 ret = theFlogger.Connect();
406 ret = theFlogger.SetLogTags(ptrSubSystem, ptrComponent);
409 ret = theFlogger.ClearLog();
412 theFlogger.WriteBinary(KTestLongMessage);
413 // ForceLogFlush(theFlogger);
414 TRAPD(r, ret = DoTestCheckWriteL());
429 * Function Name : DoTestCheckWriteL
430 * Input parameters : None
431 * Output parameters : TInt
432 * Description : This function checks the weather test data was written
433 * in to the log file by DoTestWriteL() or not.
438 TInt CFloggerTest026_03::DoTestCheckWriteL()
440 _LIT8(KTestLongMessage,"TEST 26.3:#À!}!}!} }4}%}&´zß}}&} } } } }'}}(}!æ~.=¢ÛR.... .~ÿ}#À!}!}!} }4}%}&„¥T}9}}&}}'}}(}U~... .~. -ÿ}#À!}}!} }4}%}&„¥T}9}}&} } } } }'}}(}¾Ä~)... .~. .ÿ}#À!}!}} }$µZ}'}}(}U~... .~. -ÿ}#À!}}!} }4}%}&„¥T}9}}&} } } } }'}}(}¾Ä~... .~. .ÿ}#À!}!}$µZ"); //8 bit test decriptor
441 User::After(KTimeToLogLargeData); // occasionally, KTimeToLog isn't quite long enough, so use longer time.
444 TInt listfilesize,returnCode;
445 RFs iFileSystem; //For file operation create a file system
446 _LIT(KLogFile,"c:\\logs\\log.txt");
447 TBuf8<256> testData; //To hold the test descriptor
449 _LIT(KTestSystem, "SubSystem"); //Test sytem name
450 _LIT(KTestComponent, "Component"); //Test component name
451 //_LIT8(KTestLongMessage,"TEST 26.3: 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"); //8 bit test decriptor
454 User::LeaveIfError(iFileSystem.Connect());
456 //Open the file in the read mode
457 User::LeaveIfError(theFile.Open(iFileSystem, KLogFile, EFileWrite|EFileShareAny));
458 CleanupClosePushL(theFile);
460 User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
462 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
463 CleanupStack::PushL(hBuffer);
464 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
466 // Read from position 0: start of file
467 returnCode = theFile.Read(ptrString);
469 //testData.Copy(KTestLongMessage); //Copy the test message
470 returnCode = ptrString.Find(KTestLongMessage); //find the test message in the
471 //buffer read from the file
473 if (returnCode > 0) // Test message present
476 testData.Copy(KTestSystem); //Copy the test tag
477 returnCode = ptrString.Find(testData); //Find the test tag in the
478 //buffer read from the file
480 if (returnCode > 0) // Test tag present
483 testData.Copy(KTestComponent); //Copy the component name
484 returnCode = ptrString.Find(testData); //Find the component name in the
485 //buffer read from the file
488 CleanupStack::PopAndDestroy(hBuffer);
489 CleanupStack::PopAndDestroy(); //theFile
491 if (returnCode > 0) // Test tag present