os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_007_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 007.xx
19 // Test system includes
20 #include <comms-infras/commsdebugutility.h>
25 #include "teststepcomsdbg.h"
26 #include "step_007_xx.h"
30 * Function Name : CFloggerTest007_01
31 * Input parameters : None
32 * Output parameters : None
33 * Description : This is the constructor
36 CFloggerTest007_01::CFloggerTest007_01()
38 // store the name of this test case
39 SetTestStepName(_L("step_007_01"));
45 * Function Name :~ CFloggerTest007_01
46 * Input parameters : None
47 * Output parameters : None
48 * Description : This is the Destructor
52 CFloggerTest007_01::~CFloggerTest007_01()
59 * Function Name : doTestStepL
60 * Input parameters : None
61 * Output parameters : TVerdict
62 * Description : This function returns weather the test case 007_01 has
67 TVerdict CFloggerTest007_01::doTestStepL( )
70 INFO_PRINTF1(_L("Step 007.01 called "));
72 if ( executeStepL(EFalse) == KErrNone )
73 SetTestStepResult(EPass);
76 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 CFloggerTest007_01::executeStepL(TBool heapTest)
97 User::After(KTimeToLog);
98 TInt ret = KErrGeneral;
99 ret = DoTestConnect();
102 ret = DoTestWrite() ;
103 if ( ret == KErrNone)
105 TRAPD(r, ret = DoTestCheckWriteL() );
106 if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
110 else if (r != KErrNone)
118 // if (ret == KErrNone)
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 CFloggerTest007_01::executeStepL()
139 /******************************************************************
140 * Function Name : DoTestWrite
141 * Input parameters : None
142 * Output parameters : TInt
143 * Description : This function writes the data to the file logger
148 TInt CFloggerTest007_01::DoTestWrite()
150 _LIT8(KTestMessage,"TC 7_01: Just for compalation"); //8 bit test decriptor
151 iFlogger.Write(KTestMessage); //Writes a 8 bit test descriptor
153 ForceLogFlush(iFlogger);
159 /******************************************************************
160 * Function Name : DoTestCheckWriteL
161 * Input parameters : None
162 * Output parameters : TInt
163 * Description : This function checks the weather test data was written
164 * in to the log file by DoTestWriteL() or not.
169 TInt CFloggerTest007_01::DoTestCheckWriteL()
171 User::After(KTimeToLog);
176 RFs fileSystem; //For file operation create a file system
177 TBuf8<256> testData; //To hold the test descriptor
178 _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
180 _LIT8(KTestMessage,"TC 7_01: Just for compalation"); //8 bit test decriptor
182 _LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message
184 User::LeaveIfError(fileSystem.Connect()); //connect to file server
186 //Open the file in the read mode
187 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
189 CleanupClosePushL(theFile);
191 returnCode = theFile.Size(listfilesize); //Size of the file
192 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
193 CleanupStack::PushL(hBuffer);
194 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
196 // Read from position 0: start of file
197 returnCode = theFile.Read(ptrString);
199 testData.Copy(KTestMessage); //Copy the test descriptor
200 returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
203 if (returnCode == KErrNotFound) //Find the error message
205 returnCode = ptrString.Find(KOOMError);
207 User::Leave(KErrNoMemory);
211 CleanupStack::PopAndDestroy(hBuffer);
212 CleanupStack::PopAndDestroy(); // For theFile object
222 * Function Name : DoTestConnect
223 * Input parameters : None
224 * Output parameters : TInt
225 * Description : This function establishes a connection to file logger
226 * and sets the system and component name in file logger.
231 TInt CFloggerTest007_01::DoTestConnect()
236 ptrSubSystem.Set(_L8("SubSystem"));
237 ptrComponent.Set(_L8("Component"));
239 ret = iFlogger.Connect(); //Call connect() of Flogger
241 ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
243 // if (ret == KErrNone)
244 // ret = iFlogger.ClearLog(); //clear the contents from the log
253 * Function Name : CFloggerTest007_02
254 * Input parameters : None
255 * Output parameters : None
256 * Description : This is the constructor
260 CFloggerTest007_02::CFloggerTest007_02()
262 // store the name of this test case
263 SetTestStepName(_L("step_007_02"));
268 * Function Name :~ CFloggerTest007_02
269 * Input parameters : None
270 * Output parameters : None
271 * Description : This is the Destructor
275 CFloggerTest007_02::~CFloggerTest007_02()
281 * Function Name : doTestStepL
282 * Input parameters : None
283 * Output parameters : TVerdict
284 * Description : This function returns weather the test case 007_02 has
290 TVerdict CFloggerTest007_02::doTestStepL( )
292 INFO_PRINTF1(_L("Step 007.02 called "));
294 if ( executeStepL() == KErrNone )
295 SetTestStepResult(EPass);
298 SetTestStepResult(EFail);
301 User::After(KTimeForDisplay);
302 return TestStepResult();
308 * Function Name : executeStepL
309 * Input parameters : None
310 * Output parameters : TInt
311 * Description : This function writes the test data in to the log file
312 * This function check the test message is present in the
318 TInt CFloggerTest007_02::executeStepL()
320 TInt ret = KErrGeneral;
322 ret = DoTestConnect();
323 CleanupClosePushL(iFlogger);
327 ret = DoTestCheckWriteL();
329 CleanupStack::PopAndDestroy(); //logger
330 User::After(1000000);
335 * Function Name : executeStepL
336 * Input parameters : None
337 * Output parameters : TInt
338 * Description : This function writes the test data in to the log file
339 * This function check the test message is present in the
345 TInt CFloggerTest007_02::executeStepL(TBool)
351 * Function Name : DoTestConnect
352 * Input parameters : None
353 * Output parameters : TInt
354 * Description : This function establishes a connection to file logger
355 * and sets the system and component name in file logger.
360 TInt CFloggerTest007_02::DoTestConnect()
365 ptrSubSystem.Set(_L8("SubSystem"));
366 ptrComponent.Set(_L8("Component"));
368 ret = iFlogger.Connect(); //Call connect() of Flogger
370 ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
373 ret = iFlogger.ClearLog(); //clear the contents from the log
380 * Function Name : DoTestWrite
381 * Input parameters : None
382 * Output parameters : TInt
383 * Description : This function writes the data to the file logger
388 TInt CFloggerTest007_02::DoTestWrite()
390 //KTestLongMessage contains a very long test message
391 _LIT(KTestLongMessage,"TC 7_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");
392 iFlogger.Write(KTestLongMessage);
393 ForceLogFlush(iFlogger);
399 * Function Name : DoTestCheckWriteL
400 * Input parameters : None
401 * Output parameters : TInt
402 * Description : This function checks the weather test data was written
403 * in to the log file by DoTestWriteL() or not.
408 TInt CFloggerTest007_02::DoTestCheckWriteL()
410 User::After(KTimeToLog);
413 TInt listfilesize,returnCode;
414 RFs fileSystem; //For file operation create a file system
415 TBuf8<256> testData; //To hold the test descriptor
416 _LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
418 //The following contains the string of length 200(max)
419 //which is written to the log file
420 //_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");
421 _LIT(KTestLongMessage, "TC 7_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");
423 //_LIT8(KOOMError, "#Logs may be lost out of memory!!");
425 User::LeaveIfError(fileSystem.Connect());
427 //Open the file in the read mode
428 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
430 CleanupClosePushL(theFile);
432 User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
434 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
435 CleanupStack::PushL(hBuffer);
437 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
439 // Read from position 0: start of file
440 User::LeaveIfError(returnCode = theFile.Read(ptrString));
442 testData.Copy(KTestLongMessage); //Copy the test descriptor
443 returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
447 CleanupStack::PopAndDestroy(hBuffer);
448 CleanupStack::PopAndDestroy(); //theFile
463 * Function Name : CFloggerTest007_03
464 * Input parameters : None
465 * Output parameters : None
466 * Description : This is the constructor
470 CFloggerTest007_03::CFloggerTest007_03()
472 // store the name of this test case
473 SetTestStepName(_L("step_007_03"));
479 * Function Name :~ CFloggerTest007_03
480 * Input parameters : None
481 * Output parameters : None
482 * Description : This is the Destructor
487 CFloggerTest007_03::~CFloggerTest007_03()
494 * Function Name : doTestStepL
495 * Input parameters : None
496 * Output parameters : TVerdict
497 * Description : This function is responsible for doing the heap test analysis
502 TVerdict CFloggerTest007_03::doTestStepL( )
504 INFO_PRINTF1(_L("Step 007.03 called "));
506 CFloggerTest007_01* step007_01 = new CFloggerTest007_01;
507 CleanupStack::PushL(step007_01);
508 doTestStepWithHeapFailureL( *step007_01, 1, 20, KErrNone, ETrue);
510 CleanupStack::PopAndDestroy(step007_01);
511 User::After(KTimeForDisplay);
512 return TestStepResult();