os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_009_xx.cpp
First public contribution.
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 009.xx
19 // Test system includes
20 #include <comms-infras/commsdebugutility.h>
25 #include "teststepcomsdbg.h"
26 #include "step_009_xx.h"
30 * Function Name : CFloggerTest009_01
31 * Input parameters : None
32 * Output parameters : None
33 * Description : This is the constructor
37 CFloggerTest009_01::CFloggerTest009_01()
39 SetTestStepName(_L("step_009_01"));
44 * Function Name :~ CFloggerTest009_01
45 * Input parameters : None
46 * Output parameters : None
47 * Description : This is the Destructor
51 CFloggerTest009_01::~CFloggerTest009_01()
57 * Function Name : doTestStepL
58 * Input parameters : None
59 * Output parameters : TVerdict
60 * Description : This function returns weather the test case 009_01 has
66 TVerdict CFloggerTest009_01::doTestStepL( )
69 INFO_PRINTF1(_L("Step 009.01 called "));
71 if ( executeStepL(EFalse) == KErrNone )
72 SetTestStepResult(EPass);
75 SetTestStepResult(EFail);
78 User::After(KTimeForDisplay);
79 return TestStepResult();
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
94 TInt CFloggerTest009_01::executeStepL(TBool heapTest)
98 ret = DoTestConnect();
99 CleanupClosePushL(iFlogger);
103 if ( ret == KErrNone)
105 TRAPD(r, ret = DoTestCheckWriteL());
106 if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
110 else if (r != KErrNone)
117 // if (ret == 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 CFloggerTest009_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 CFloggerTest009_01::DoTestWrite()
149 _LIT8(KTestMessageOne,"TC 9_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 TDesC8>
157 * Output parameters : TInt
158 * Description : This function writes formatted data to the file logger
163 TInt CFloggerTest009_01::DoTestWriteFormat(TRefByValue<const TDesC8> aFmt,...)
167 iFlogger.WriteFormat(aFmt,list);
168 ForceLogFlush(iFlogger);
174 * Function Name : DoTestCheckWriteL
175 * Input parameters : None
176 * Output parameters : TInt
177 * Description : This function checks the weather test data was written
178 * in to the log file by DoTestWriteL() or not.
183 TInt CFloggerTest009_01::DoTestCheckWriteL()
185 User::After(1000*1000);
190 RFs fileSystem; //For file operation create a file system
191 TBuf8<256> testData; //To hold the test descriptor
193 _LIT8(KTestMessageOne,"TC 9_01: The value of test integer variable :%d");
194 testData.Format(KTestMessageOne,100);
196 _LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message
198 _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
200 User::LeaveIfError(fileSystem.Connect());
202 //Open the file in the read mode
203 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
205 CleanupClosePushL(theFile);
208 User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
209 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
210 CleanupStack::PushL(hBuffer);
211 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
213 // Read from position 0: start of file
214 returnCode = theFile.Read(ptrString);
216 returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
219 if (returnCode == KErrNotFound) //Find the error message
221 returnCode = ptrString.Find(KOOMError);
223 User::Leave(KErrNoMemory);
227 CleanupStack::PopAndDestroy(hBuffer);
228 CleanupStack::PopAndDestroy(); // For theFile object
237 * Function Name : DoTestConnect
238 * Input parameters : None
239 * Output parameters : TInt
240 * Description : This function establishes a connection to file logger
241 * and sets the system and component name in file logger.
246 TInt CFloggerTest009_01::DoTestConnect()
251 ptrSubSystem.Set(_L8("SubSystem"));
252 ptrComponent.Set(_L8("Component"));
254 ret = iFlogger.Connect(); //Call connect() of Flogger
256 ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
259 ret = iFlogger.ClearLog(); //clear the contents from the log
268 * Function Name : CFloggerTest009_02
269 * Input parameters : None
270 * Output parameters : None
271 * Description : This is the constructor
275 CFloggerTest009_02::CFloggerTest009_02()
277 // store the name of this test case
278 SetTestStepName(_L("step_009_02"));
283 * Function Name :~ CFloggerTest009_02
284 * Input parameters : None
285 * Output parameters : None
286 * Description : This is the Destructor
290 CFloggerTest009_02::~CFloggerTest009_02()
296 * Function Name : doTestStepL
297 * Input parameters : None
298 * Output parameters : TVerdict
299 * Description : This function returns weather the test case 009_02 has
305 TVerdict CFloggerTest009_02::doTestStepL( )
307 INFO_PRINTF1(_L("Step 009.02 called "));
309 if ( executeStepL() == KErrNone )
310 SetTestStepResult(EPass);
313 SetTestStepResult(EFail);
316 User::After(KTimeForDisplay);
317 return TestStepResult();
322 * Function Name : executeStepL
323 * Input parameters : None
324 * Output parameters : TInt
325 * Description : This function writes the test data in to the log file
326 * This function check the test message is present in the
331 TInt CFloggerTest009_02::executeStepL()
333 TInt ret = KErrGeneral;
334 ret = DoTestConnect();
336 CleanupClosePushL(iFlogger);
340 ret = DoTestCheckWriteL();
342 CleanupStack::PopAndDestroy(); //logger
344 User::After(1000000);
349 * Function Name : executeStepL
350 * Input parameters : None
351 * Output parameters : TInt
352 * Description : This function writes the test data in to the log file
353 * This function check the test message is present in the
358 TInt CFloggerTest009_02::executeStepL(TBool)
364 * Function Name : DoTestConnect
365 * Input parameters : None
366 * Output parameters : TInt
367 * Description : This function establishes a connection to file logger
368 * and sets the system and component name in file logger.
373 TInt CFloggerTest009_02::DoTestConnect()
375 TInt ret = KErrGeneral;
378 ptrSubSystem.Set(_L8("SubSystem"));
379 ptrComponent.Set(_L8("Component"));
381 ret = iFlogger.Connect(); //Call connect() of Flogger
383 ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
386 ret = iFlogger.ClearLog(); //clear the contents from the log
393 * Function Name : DoTestWrite
394 * Input parameters : None
395 * Output parameters : TInt
396 * Description : This function writes the data to the file logger
401 TInt CFloggerTest009_02::DoTestWrite()
403 //KTestLongMessage contains a very long test message
404 _LIT8(KTestLongMessage,"TC 9_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");
405 DoTestWriteFormat(KTestLongMessage, 100);
406 ForceLogFlush(iFlogger);
412 * Function Name : DoTestWriteFormat
413 * Input parameters : TRefByValue<const TDesC8>
414 * Output parameters : TInt
415 * Description : This function writes formatted data to the file logger
420 TInt CFloggerTest009_02::DoTestWriteFormat(TRefByValue<const TDesC8> aFmt,...)
424 TRAPD(res, iFlogger.WriteFormat(aFmt,list));
430 * Function Name : DoTestCheckWriteL
431 * Input parameters : None
432 * Output parameters : TInt
433 * Description : This function checks the weather test data was written
434 * in to the log file by DoTestWriteL() or not.
440 TInt CFloggerTest009_02::DoTestCheckWriteL()
442 User::After(KTimeToLog);
445 TInt listfilesize,returnCode;
446 RFs fileSystem; //For file operation create a file system
447 TBuf8<256> testData; //To hold the test descriptor
448 _LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
450 //The following contains the string of length 200(max)
451 //which is written to the log file
452 //_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");
453 _LIT(KTestLongMessage, "TC 9_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");
455 //_LIT8(KOOMError, "#Logs may be lost out of memory!!");
457 User::LeaveIfError(fileSystem.Connect());
459 //Open the file in the read mode
460 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
462 CleanupClosePushL(theFile);
464 User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
466 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
467 CleanupStack::PushL(hBuffer);
469 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
471 // Read from position 0: start of file
472 User::LeaveIfError(returnCode = theFile.Read(ptrString));
474 testData.Copy(KTestLongMessage); //Copy the test descriptor
475 returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
479 CleanupStack::PopAndDestroy(hBuffer);
480 CleanupStack::PopAndDestroy(); //theFile
494 * Function Name : CFloggerTest009_03
495 * Input parameters : None
496 * Output parameters : None
497 * Description : This is the constructor
501 CFloggerTest009_03::CFloggerTest009_03()
503 // store the name of this test case
504 SetTestStepName(_L("step_009_03"));
509 * Function Name :~ CFloggerTest009_03
510 * Input parameters : None
511 * Output parameters : None
512 * Description : This is the Destructor
516 CFloggerTest009_03::~CFloggerTest009_03()
522 * Function Name : doTestStepL
523 * Input parameters : None
524 * Output parameters : TVerdict
525 * Description : This function is responsible for doing the heap test analysis
530 TVerdict CFloggerTest009_03::doTestStepL( )
532 INFO_PRINTF1(_L("Step 009.03 called "));
534 CFloggerTest009_01* step009_01 = new CFloggerTest009_01;
535 CleanupStack::PushL(step009_01);
536 doTestStepWithHeapFailureL( *step009_01, 1, 20, KErrNone, ETrue);
538 CleanupStack::PopAndDestroy(step009_01);
539 User::After(KTimeForDisplay);
540 return TestStepResult();