os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_006_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 006.xx
19 // Test system includes
20 #include <comms-infras/commsdebugutility.h>
25 #include "teststepcomsdbg.h"
26 #include "step_006_xx.h"
30 * Function Name : CFloggerTest006_01
31 * Input parameters : None
32 * Output parameters : None
33 * Description : This is the constructor
37 CFloggerTest006_01::CFloggerTest006_01()
39 SetTestStepName(_L("step_006_01"));
45 * Function Name :~ CFloggerTest006_01
46 * Input parameters : None
47 * Output parameters : None
48 * Description : This is the Destructor
52 CFloggerTest006_01::~CFloggerTest006_01()
59 * Function Name : doTestStepL
60 * Input parameters : None
61 * Output parameters : TVerdict
62 * Description : This function returns weather the test case 006_01 has
68 TVerdict CFloggerTest006_01::doTestStepL( )
71 INFO_PRINTF1(_L("Step 006.01 called "));
73 if ( executeStepL(EFalse) == KErrNone )
74 SetTestStepResult(EPass);
77 SetTestStepResult(EFail);
79 User::After(KTimeForDisplay);
80 return TestStepResult();
85 * Function Name : executeStepL
86 * Input parameters : None
87 * Output parameters : TInt
88 * Description : This function writes the test data in to the log file
89 * This function check the test message is present in the
95 TInt CFloggerTest006_01::executeStepL(TBool heapTest)
99 ret = DoTestConnect();
100 CleanupClosePushL(iFlogger);
104 if ( ret == KErrNone)
106 TRAPD(r, ret = DoTestCheckWriteL());
107 if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
111 else if (r != KErrNone)
118 CleanupStack::PopAndDestroy(); //logger
123 * Function Name : executeStepL
124 * Input parameters : None
125 * Output parameters : TInt
126 * Description : This function writes the test data in to the log file
127 * This function check the test message is present in the
133 TInt CFloggerTest006_01::executeStepL()
139 * Function Name : DoTestWrite
140 * Input parameters : None
141 * Output parameters : TInt
142 * Description : This function writes the data to the file logger
147 TInt CFloggerTest006_01::DoTestWrite()
149 _LIT16(KTestMessageOne,"TC 006_01: The value of test integer variable :%d");// The value of second test integer variable : %d");
150 return DoTestWriteFormat(KTestMessageOne, 100); //Write unicode formatted test descriptor
155 * Function Name : DoTestWriteFormat
156 * Input parameters : TRefByValue<const TDesC16>
157 * Output parameters : TInt
158 * Description : This function writes formatted data to the file logger
163 TInt CFloggerTest006_01::DoTestWriteFormat(TRefByValue<const TDesC16> aFmt,...)
167 iFlogger.WriteFormat(aFmt,list);
169 ForceLogFlush(iFlogger);
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 DoTestWriteL() or not.
184 TInt CFloggerTest006_01::DoTestCheckWriteL()
186 User::After(KTimeToLog);
192 RFs fileSystem; //For file operation create a file system
193 TBuf8<256> testData; //To hold the test descriptor
195 _LIT8(KTestMessageOne,"TC 006_01: The value of test integer variable :%d");
196 testData.Format(KTestMessageOne,100);
198 _LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message
200 _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
202 User::LeaveIfError(fileSystem.Connect());
204 //Open the file in the read mode
205 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
207 CleanupClosePushL(theFile);
210 User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
211 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
212 CleanupStack::PushL(hBuffer);
213 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
215 // Read from position 0: start of file
216 returnCode = theFile.Read(ptrString);
218 returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
221 if (returnCode == KErrNotFound) //Find the error message
223 returnCode = ptrString.Find(KOOMError);
225 User::Leave(KErrNoMemory);
229 CleanupStack::PopAndDestroy(hBuffer);
230 CleanupStack::PopAndDestroy(); // For theFile object
240 * Function Name : DoTestConnect
241 * Input parameters : None
242 * Output parameters : TInt
243 * Description : This function establishes a connection to file logger
244 * and sets the system and component name in file logger.
249 TInt CFloggerTest006_01::DoTestConnect()
254 ptrSubSystem.Set(_L8("SubSystem"));
255 ptrComponent.Set(_L8("Component"));
257 ret = iFlogger.Connect(); //Call connect() of Flogger
259 ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
262 ret = iFlogger.ClearLog(); //clear the contents from the log
271 * Function Name : CFloggerTest006_02
272 * Input parameters : None
273 * Output parameters : None
274 * Description : This is the constructor
278 CFloggerTest006_02::CFloggerTest006_02()
280 // store the name of this test case
281 SetTestStepName(_L("step_006_02"));
286 * Function Name :~ CFloggerTest006_02
287 * Input parameters : None
288 * Output parameters : None
289 * Description : This is the Destructor
293 CFloggerTest006_02::~CFloggerTest006_02()
299 * Function Name : doTestStepL
300 * Input parameters : None
301 * Output parameters : TVerdict
302 * Description : This function returns weather the test case 006_02 has
308 TVerdict CFloggerTest006_02::doTestStepL( )
310 INFO_PRINTF1(_L("Step 006.02 called "));
312 if ( executeStepL() == KErrNone )
313 SetTestStepResult(EPass);
316 SetTestStepResult(EFail);
319 User::After(KTimeForDisplay);
320 return TestStepResult();
325 * Function Name : executeStepL
326 * Input parameters : None
327 * Output parameters : TInt
328 * Description : This function writes the test data in to the log file
329 * This function check the test message is present in the
335 TInt CFloggerTest006_02::executeStepL()
337 TInt ret = KErrGeneral;
339 ret = DoTestConnect();
340 CleanupClosePushL(iFlogger);
344 ret = DoTestCheckWriteL();
346 CleanupStack::PopAndDestroy(); //logger
348 User::After(1000000);
353 * Function Name : executeStepL
354 * Input parameters : None
355 * Output parameters : TInt
356 * Description : This function writes the test data in to the log file
357 * This function check the test message is present in the
363 TInt CFloggerTest006_02::executeStepL(TBool)
369 * Function Name : DoTestConnect
370 * Input parameters : None
371 * Output parameters : TInt
372 * Description : This function establishes a connection to file logger
373 * and sets the system and component name in file logger.
378 TInt CFloggerTest006_02::DoTestConnect()
380 TInt ret = KErrGeneral;
383 ptrSubSystem.Set(_L8("SubSystem"));
384 ptrComponent.Set(_L8("Component"));
386 ret = iFlogger.Connect(); //Call connect() of Flogger
388 ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
391 ret = iFlogger.ClearLog(); //clear the contents from the log
398 * Function Name : DoTestWrite
399 * Input parameters : None
400 * Output parameters : TInt
401 * Description : This function writes the data to the file logger
406 TInt CFloggerTest006_02::DoTestWrite()
408 //KTestLongMessage contains a very long test message
409 _LIT(KTestLongMessage,"TC 6_02: 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");
410 DoTestWriteFormat(KTestLongMessage, 100); //this causes a PANIC
411 ForceLogFlush(iFlogger);
418 * Function Name : DoTestWriteFormat
419 * Input parameters : TRefByValue<const TDesC16>
420 * Output parameters : TInt
421 * Description : This function writes formatted data to the file logger
426 TInt CFloggerTest006_02::DoTestWriteFormat(TRefByValue<const TDesC16> aFmt,...)
430 TRAPD(res, iFlogger.WriteFormat(aFmt,list));
436 * Function Name : DoTestCheckWriteL
437 * Input parameters : None
438 * Output parameters : TInt
439 * Description : This function checks the weather test data was written
440 * in to the log file by DoTestWriteL() or not.
445 TInt CFloggerTest006_02::DoTestCheckWriteL()
447 User::After(KTimeToLog);
450 TInt listfilesize,returnCode;
451 RFs fileSystem; //For file operation create a file system
452 TBuf8<256> testData; //To hold the test descriptor
453 _LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
455 //The following contains the string of length 200(max)
456 //which is written to the log file
457 //_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");
458 _LIT(KTestLongMessage, "TC 6_02: 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");
460 //_LIT8(KOOMError, "#Logs may be lost out of memory!!");
462 User::LeaveIfError(fileSystem.Connect());
464 //Open the file in the read mode
465 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
467 CleanupClosePushL(theFile);
469 User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
471 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
472 CleanupStack::PushL(hBuffer);
474 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
476 // Read from position 0: start of file
477 User::LeaveIfError(returnCode = theFile.Read(ptrString));
479 testData.Copy(KTestLongMessage); //Copy the test descriptor
480 returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
484 CleanupStack::PopAndDestroy(hBuffer);
485 CleanupStack::PopAndDestroy(); //theFile
498 //Function Name : CFloggerTest006_03
499 //Input parameters : None
500 //Output parameters : None
501 //Description : This is the constructor
505 CFloggerTest006_03::CFloggerTest006_03()
507 // store the name of this test case
508 SetTestStepName(_L("step_006_03"));
513 * Function Name :~ CFloggerTest006_03
514 * Input parameters : None
515 * Output parameters : None
516 * Description : This is the Destructor
520 CFloggerTest006_03::~CFloggerTest006_03()
528 * Function Name : doTestStepL
529 * Input parameters : None
530 * Output parameters : TVerdict
531 * Description : This function is responsible for doing the heap test analysis
536 TVerdict CFloggerTest006_03::doTestStepL( )
538 INFO_PRINTF1(_L("Step 006.03 called "));
540 CFloggerTest006_01* step006_01 = new CFloggerTest006_01;
541 CleanupStack::PushL(step006_01);
542 doTestStepWithHeapFailureL( *step006_01, 1, 20, KErrNone, ETrue);
544 CleanupStack::PopAndDestroy(step006_01);
545 User::After(KTimeForDisplay);
546 return TestStepResult();