os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_004_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 004.xx
20 // Test system includes
21 #include "teststepcomsdbg.h"
22 #include "step_004_xx.h"
23 #include "TestMessage.h"
25 #include <comms-infras/commsdebugutility.h>
29 * Function Name : CFloggerTest004_01
30 * Input parameters : None
31 * Output parameters : None
32 * Description : This is the constructor
36 CFloggerTest004_01::CFloggerTest004_01()
38 SetTestStepName(_L("step_004_01"));
43 * Function Name :~ CFloggerTest004_01
44 * Input parameters : None
45 * Output parameters : None
46 * Description : This is the Destructor
50 CFloggerTest004_01::~CFloggerTest004_01()
56 * Function Name : doTestStepL
57 * Input parameters : None
58 * Output parameters : TVerdict
59 * Description : This function returns weather the test case 004_01 has
65 TVerdict CFloggerTest004_01::doTestStepL( )
67 INFO_PRINTF1(_L("Step 004.01 called "));
69 if ( executeStepL(EFalse) == KErrNone )
70 SetTestStepResult(EPass);
72 SetTestStepResult(EFail);
74 User::After(KTimeForDisplay);
75 return TestStepResult();
80 * Function Name : executeStepL
81 * Input parameters : None
82 * Output parameters : TInt
83 * Description : This function writes the test data in to the log file
84 * This function check the test message is present in the
90 TInt CFloggerTest004_01::executeStepL(TBool heapTest)
94 ret = iFlogger.Connect(); //Call connect() of Flogger
95 if (ret == KErrNone) if (ret == KErrNone)
97 CleanupClosePushL(iFlogger);
98 ret = iFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8); //SetLogTags() of Flogger called
101 ret = iFlogger.ClearLog();
107 User::After(KTimeToLog);
109 if ( ret == KErrNone)
111 TRAPD(r, ret = DoTestCheckWriteL() );
112 if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
116 else if (r != KErrNone)
124 CleanupStack::PopAndDestroy(); //logger
130 * Function Name : executeStepL
131 * Input parameters : None
132 * Output parameters : TInt
133 * Description : This function writes the test data in to the log file
134 * This function check the test message is present in the
140 TInt CFloggerTest004_01::executeStepL()
147 * Function Name : DoTestWrite
148 * Input parameters : None
149 * Output parameters : TInt
150 * Description : This function writes the test data in to the log file
155 TInt CFloggerTest004_01::DoTestWrite()
157 _LIT(KTestMessage,"TC 4.01 :This is test msg"); //unicode test decriptor
158 iFlogger.Write(KTestMessage);
159 ForceLogFlush(iFlogger);
166 * Function Name : DoTestCheckWriteL
167 * Input parameters : None
168 * Output parameters : TInt
169 * Description : This function checks the weather test data was written
170 * in to the log file by DoTestWriteL() or not.
175 TInt CFloggerTest004_01::DoTestCheckWriteL()
179 TInt listfilesize,returnCode;
180 RFs fileSystem; //For file operation create a file system
181 TBuf8<256> testData; //To hold the test descriptor
182 _LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
183 TInt numSuccessful = 0;
185 _LIT(KTestMessage,"TC 4.01 :This is test msg"); //unicode test decriptor
187 User::LeaveIfError(fileSystem.Connect());
189 //Open the file in the read mode
190 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
192 CleanupClosePushL(theFile);
194 User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
196 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
197 CleanupStack::PushL(hBuffer);
199 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
201 // Read from position 0: start of file
202 User::LeaveIfError(returnCode = theFile.Read(ptrString));
204 testData.Copy(KTestMessage); //Copy the test descriptor
205 returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
208 if (returnCode != KErrNotFound)
213 returnCode = ptrString.Find(KErrOOM);
216 User::Leave(KErrNoMemory);
221 CleanupStack::PopAndDestroy(hBuffer);
222 CleanupStack::PopAndDestroy(); //theFile
223 if (numSuccessful == 1)
244 * Function Name : CFloggerTest004_02
245 * Input parameters : None
246 * Output parameters : None
247 * Description : This is the constructor
251 CFloggerTest004_02::CFloggerTest004_02()
253 // store the name of this test case
254 SetTestStepName(_L("step_004_02"));
260 * Function Name :~ CFloggerTest004_01
261 * Input parameters : None
262 * Output parameters : None
263 * Description : This is the Destructor
267 CFloggerTest004_02::~CFloggerTest004_02()
273 * Function Name : doTestStepL
274 * Input parameters : None
275 * Output parameters : TVerdict
276 * Description : This function returns weather the test case 004_02 is
282 TVerdict CFloggerTest004_02::doTestStepL( )
284 INFO_PRINTF1(_L("Step 004.02 called "));
286 if ( executeStepL() == KErrNone )
287 SetTestStepResult(EPass);
289 SetTestStepResult(EFail);
291 User::After(KTimeForDisplay);
292 return TestStepResult();
297 * Function Name : executeStepL
298 * Input parameters : None
299 * Output parameters : TInt
300 * Description : This function writes the test data in to the log file
301 * This function check the test message is present in the
307 TInt CFloggerTest004_02::executeStepL()
309 TInt ret = KErrGeneral;
311 ret = DoTestConnect();
312 CleanupClosePushL(iFlogger);
316 // wait to give flogger time to log
317 User::After(KTimeToLog);
318 // catch any memory leaks
319 iFlogger.__DbgShutDownServer();
323 ret = DoTestCheckWriteL();
327 CleanupStack::PopAndDestroy(); //logger
333 * Function Name : executeStepL
334 * Input parameters : None
335 * Output parameters : TInt
336 * Description : This function writes the test data in to the log file
337 * This function check the test message is present in the
343 TInt CFloggerTest004_02::executeStepL(TBool)
349 * Function Name : DoTestConnect
350 * Input parameters : None
351 * Output parameters : TInt
352 * Description : This function establishes a connection to file logger
353 * and sets the system and component name in file logger.
358 TInt CFloggerTest004_02::DoTestConnect()
363 ptrSubSystem.Set(_L8("SubSystem"));
364 ptrComponent.Set(_L8("Component"));
366 ret = iFlogger.Connect(); //Call connect() of Flogger
369 ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
374 ret = iFlogger.ClearLog(); //clear the contents from the log
382 * Function Name : DoTestWrite
383 * Input parameters : None
384 * Output parameters : TInt
385 * Description : This function writees the data to the file logger
390 TInt CFloggerTest004_02::DoTestWrite()
392 //KTestLongMessage contains a very lengthy message
393 _LIT(KTestLongMessage,"TC 4_02: This is the long message This is the long message This is the long message This is the long messageThis is the long messageThis is the long messageThis is the long messageThis is the long messageThis is the long messageThis is the long messageThis is the long messageThis is ");
395 iFlogger.Write(KTestLongMessage);
401 * Function Name : DoTestCheckWriteL
402 * Input parameters : None
403 * Output parameters : TInt
404 * Description : This function checks the weather test data was written
405 * in to the log file by DoTestWriteL() or not.
410 TInt CFloggerTest004_02::DoTestCheckWriteL()
414 TInt listfilesize,returnCode;
415 RFs fileSystem; //For file operation create a file system
416 TBuf8<256> testData; //To hold the test descriptor
417 _LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
419 //The following contains the string of length 200(max)
420 //which is written to the log file
421 //_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");
422 _LIT(KTestLongMessage, "TC 4_02: This is the long message This is the long message This is the long message This is the long messageThis is the long messageThis is the long messageThis is the long messageThis is the long me");
424 //_LIT8(KOOMError, "#Logs may be lost out of memory!!");
426 User::LeaveIfError(fileSystem.Connect());
428 //Open the file in the read mode
429 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
431 CleanupClosePushL(theFile);
433 User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
435 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
436 CleanupStack::PushL(hBuffer);
438 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
440 // Read from position 0: start of file
441 User::LeaveIfError(returnCode = theFile.Read(ptrString));
443 testData.Copy(KTestLongMessage); //Copy the test descriptor
444 returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
448 CleanupStack::PopAndDestroy(hBuffer);
449 CleanupStack::PopAndDestroy(); //theFile
463 * Function Name : CFloggerTest004_03
464 * Input parameters : None
465 * Output parameters : None
466 * Description : This is the constructor
470 CFloggerTest004_03::CFloggerTest004_03()
472 // store the name of this test case
473 SetTestStepName(_L("step_004_03"));
478 * Function Name :~ CFloggerTest004_01
479 * Input parameters : None
480 * Output parameters : None
481 * Description : This is the Destructor
485 CFloggerTest004_03::~CFloggerTest004_03()
491 * Function Name : doTestStepL
492 * Input parameters : None
493 * Output parameters : TVerdict
494 * Description : This function is responsible for doing the heap test analysis
499 TVerdict CFloggerTest004_03::doTestStepL( )
501 INFO_PRINTF1(_L("Step 004.03 called "));
503 CFloggerTest004_01* step004_01 = new CFloggerTest004_01;
504 CleanupStack::PushL(step004_01);
505 doTestStepWithHeapFailureL( *step004_01, 450, 470, KErrNone, ETrue);
507 CleanupStack::PopAndDestroy(step004_01);
508 User::After(KTimeForDisplay);
509 return TestStepResult();