os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_010_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 010.xx
19 // Test system includes
20 #include <comms-infras/commsdebugutility.h>
21 #include "TestMessage.h"
26 #include "teststepcomsdbg.h"
27 #include "step_010_xx.h"
32 CFloggerTest010_01::CFloggerTest010_01()
34 // store the name of this test case
35 SetTestStepName(_L("step_010_01"));
41 CFloggerTest010_01::~CFloggerTest010_01()
48 TVerdict CFloggerTest010_01::doTestStepL( )
50 INFO_PRINTF1(_L("Step 010.01 called "));
52 if ( executeStepL(EFalse) == KErrNone )
53 SetTestStepResult(EPass);
56 SetTestStepResult(EFail);
59 User::After(KTimeForDisplay);
60 return TestStepResult();
65 TInt CFloggerTest010_01::executeStepL(TBool heapTest)
67 User::After(100*1000); //Need this or connect could return KErrServerTerminated
68 TInt ret = KErrGeneral;
70 ret = DoTestConnect();
76 TRAPD(r, ret = DoTestCheckWriteL());
77 if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
81 else if (r != KErrNone)
91 TInt CFloggerTest010_01::executeStepL()
97 TInt CFloggerTest010_01::DoTestWrite()
99 _LIT8(KDescTxt,"TC 10_1:Test Msg----"); //8 bit test descriptor
101 iFlogger.HexDump(KDescTxt,KHexTestHeader);
103 ForceLogFlush(iFlogger);
105 iFlogger.__DbgShutDownServer();
113 TInt CFloggerTest010_01::DoTestCheckWriteL()
115 User::After(KTimeToLog);
121 RFs fileSystem; //For file operation create a file system
122 TBuf8<256> testData; //To hold the test descriptor
123 _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
125 _LIT(KHeaderTxt,"Test Header");// Test header
126 _LIT8(KBodyTxt1,"TC 10_1:Test Msg"); // first 16 chars
128 _LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message
130 User::LeaveIfError(fileSystem.Connect());
132 //Open the file in the read mode
133 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
134 CleanupClosePushL(theFile);
136 User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
137 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
138 CleanupStack::PushL(hBuffer);
139 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
141 // Read from position 0: start of file
142 returnCode = theFile.Read(ptrString);
144 testData.Copy(KHeaderTxt); //Copy the test header descriptor
145 returnCode = ptrString.Find(testData); //find the test header descriptor in the buffer read
149 testData.Copy(KHexTestMargin); //Copy the test margin descriptor
150 returnCode = ptrString.Find(testData); //find the test margin descriptor in the buffer read
156 testData.Copy(KBodyTxt1); //Copy the test descriptor
157 returnCode=ptrString.Find(testData); //find the test descriptor in the buffer read
161 if (returnCode == KErrNotFound) //Find the error message
163 returnCode = ptrString.Find(KOOMError);
165 User::Leave(KErrNoMemory);
168 CleanupStack::PopAndDestroy(hBuffer);
169 CleanupStack::PopAndDestroy(); //theFile object
179 TInt CFloggerTest010_01::DoTestConnect()
185 ptrSubSystem.Set(_L8("SubSystem"));
186 ptrComponent.Set(_L8("Component"));
188 ret = iFlogger.Connect(); //Call connect() of Flogger
191 ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
194 ret = iFlogger.ClearLog(); //clear the contents from the log
207 CFloggerTest010_02::CFloggerTest010_02()
209 // store the name of this test case
210 SetTestStepName(_L("step_010_02"));
216 CFloggerTest010_02::~CFloggerTest010_02()
222 TVerdict CFloggerTest010_02::doTestStepL( )
224 INFO_PRINTF1(_L("Step 010.02 called "));
226 if ( executeStepL() == KErrNone )
227 SetTestStepResult(EPass);
230 SetTestStepResult(EFail);
233 User::After(KTimeForDisplay);
234 return TestStepResult();
239 TInt CFloggerTest010_02::executeStepL( )
241 TInt ret = KErrGeneral;
242 ret = DoTestConnect();
249 TRAPD(r, ret = DoTestCheckWriteL());
261 TInt CFloggerTest010_02::executeStepL(TBool)
267 TInt CFloggerTest010_02::DoTestWrite()
269 _LIT8(KDescText,"TC 10_2:Test Msg");
271 iFlogger.HexDump(KDescText, KEightSpaces8);
272 ForceLogFlush(iFlogger);
274 iFlogger.__DbgShutDownServer();
282 TInt CFloggerTest010_02::DoTestCheckWriteL()
284 User::After(KTimeToLog);
289 RFs fileSystem; //For file operation create a file system
290 TBuf8<256> testData; //To hold the test descriptor
291 _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
293 _LIT8(KOOMError, "#Logs may be lost out of memory!!"); // Error message
295 User::LeaveIfError(fileSystem.Connect());
297 //Open the file in the read mode
298 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
300 CleanupClosePushL(theFile);
302 User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
303 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
304 CleanupStack::PushL(hBuffer);
305 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
307 // Read from position 0: start of file
308 returnCode = theFile.Read(ptrString);
311 testData.Copy(KEightSpaces8); //Copy the test descriptor
312 returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
315 if (returnCode == KErrNotFound) // Check for the error message in the log
317 returnCode = ptrString.Find(KOOMError);
319 User::Leave(KErrNoMemory);
322 CleanupStack::PopAndDestroy(hBuffer);
323 CleanupStack::PopAndDestroy(); //theFile
332 TInt CFloggerTest010_02::DoTestConnect()
334 TInt ret = KErrGeneral;
335 TPtrC8 ptrSubSystem, ptrComponent;
336 ptrSubSystem.Set(_L8("SubSystem"));
337 ptrComponent.Set(_L8("Component"));
339 ret = iFlogger.Connect(); //Call connect() of Flogger
341 ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
344 ret = iFlogger.ClearLog(); //clear the contents from the log
356 CFloggerTest010_03::CFloggerTest010_03()
358 // store the name of this test case
359 SetTestStepName(_L("step_010_03"));
365 CFloggerTest010_03::~CFloggerTest010_03()
367 //iFlogger.Close(); //Close the flogger
373 TVerdict CFloggerTest010_03::doTestStepL( )
375 INFO_PRINTF1(_L("Step 010.03 called "));
377 if ( executeStepL() == KErrNone )
378 SetTestStepResult(EPass);
381 SetTestStepResult(EFail);
384 User::After(KTimeForDisplay);
385 return TestStepResult();
389 TInt CFloggerTest010_03::executeStepL(TBool)
394 TInt CFloggerTest010_03::executeStepL( )
396 TInt ret = KErrGeneral;
397 ret = DoTestConnect();
404 TRAPD(r, ret = DoTestCheckWriteL());
417 TInt CFloggerTest010_03::DoTestWrite()
419 _LIT8(KDescTxt,"TC 10_3:Test Msg"); //8 bit test descriptor
422 iFlogger.HexDump(KDescTxt);
423 ForceLogFlush(iFlogger);
425 iFlogger.__DbgShutDownServer();
434 TInt CFloggerTest010_03::DoTestCheckWriteL()
436 User::After(KTimeToLog);
441 RFs fileSystem; //For file operation create a file system
442 TBuf8<256> testData; //To hold the test descriptor
443 _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
445 _LIT8(KBodyTxt,"TC 10_3:Test Msg");// Test body descriptor
446 _LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message
448 User::LeaveIfError(fileSystem.Connect());
450 //Open the file in the read mode
451 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
452 CleanupClosePushL(theFile);
454 User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
455 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
456 CleanupStack::PushL(hBuffer);
457 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
459 // Read from position 0: start of file
460 returnCode=theFile.Read(ptrString);
462 testData.Copy(KBodyTxt); //Copy the test descriptor
463 returnCode=ptrString.Find(testData); //find the test descriptor in the buffer read
466 if (returnCode == KErrNotFound) //Find the error message
468 returnCode = ptrString.Find(KOOMError);
470 User::Leave(KErrNoMemory);
473 CleanupStack::PopAndDestroy(hBuffer);
474 CleanupStack::PopAndDestroy(); //theFile object
484 TInt CFloggerTest010_03::DoTestConnect()
489 ptrSubSystem.Set(_L8("SubSystem"));
490 ptrComponent.Set(_L8("Component"));
492 result = iFlogger.Connect(); //Call connect() of Flogger
493 if (result == KErrNone)
495 result = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
497 result = iFlogger.ClearLog(); //clear the contents in the log
511 CFloggerTest010_04::CFloggerTest010_04()
513 // store the name of this test case
514 SetTestStepName(_L("step_010_04"));
520 CFloggerTest010_04::~CFloggerTest010_04()
526 TVerdict CFloggerTest010_04::doTestStepL( )
529 INFO_PRINTF1(_L("Step 010.04 called "));
531 if ( executeStepL() == KErrNone )
532 SetTestStepResult(EPass);
535 SetTestStepResult(EFail);
538 User::After(KTimeForDisplay);
539 return TestStepResult();
542 TInt CFloggerTest010_04::executeStepL(TBool)
547 TInt CFloggerTest010_04::executeStepL( )
549 TInt ret = KErrGeneral;
550 ret = DoTestConnect();
557 TRAPD(r, ret = DoTestCheckWriteL());
570 TInt CFloggerTest010_04::DoTestWrite()
572 _LIT8(KTestDesc,"TC 10_4:Test Msg");
574 iFlogger.HexDump(KTestDesc, KNullDesC8);
575 ForceLogFlush(iFlogger);
576 iFlogger.__DbgShutDownServer();
584 TInt CFloggerTest010_04::DoTestCheckWriteL()
586 User::After(KTimeToLog);
591 RFs fileSystem; //For file operation create a file system
592 TBuf8<256> testData; //To hold the test descriptor
593 _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
595 _LIT8(KBodyTxt,"TC 10_4:Test Msg");// Test body descriptor
596 _LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message
597 TInt numSuccessful= 0;
599 User::LeaveIfError(fileSystem.Connect());
601 //Open the file in the read mode
602 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
603 CleanupClosePushL(theFile);
605 User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
606 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
607 CleanupStack::PushL(hBuffer);
608 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
610 // Read from position 0: start of file
611 returnCode = theFile.Read(ptrString);
614 testData.Copy(KBodyTxt); //Copy the test descriptor
615 returnCode=ptrString.Find(testData); //find the test descriptor in the buffer read
621 returnCode=ptrString.Find(KHexTestHeader); //find the test descriptor in the buffer read
623 if (returnCode == KErrNotFound)
627 if (returnCode == KErrNotFound) //Find the error message
629 returnCode = ptrString.Find(KOOMError);
631 User::Leave(KErrNoMemory);
634 CleanupStack::PopAndDestroy(hBuffer);
635 CleanupStack::PopAndDestroy(); //theFile object
637 if (numSuccessful == 2)
646 TInt CFloggerTest010_04::DoTestConnect()
648 TInt ret = KErrGeneral;
651 ptrSubSystem.Set(_L8("SubSystem"));
652 ptrComponent.Set(_L8("Component"));
654 ret = iFlogger.Connect(); //Call connect() of Flogger
656 ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
659 ret = iFlogger.ClearLog(); //clear the contents from the log
672 CFloggerTest010_05::CFloggerTest010_05()
674 // store the name of this test case
675 SetTestStepName(_L("step_010_05"));
680 CFloggerTest010_05::~CFloggerTest010_05()
687 TVerdict CFloggerTest010_05::doTestStepL( )
689 INFO_PRINTF1(_L("Step 010.05 called "));
691 if ( executeStepL() == KErrNone )
692 SetTestStepResult(EPass);
695 SetTestStepResult(EFail);
698 User::After(KTimeForDisplay);
699 return TestStepResult();
704 TInt CFloggerTest010_05::executeStepL(TBool)
709 TInt CFloggerTest010_05::executeStepL( )
711 User::After(100*1000); //Need this or connect will return KErrServerTerminated
712 TInt ret = KErrGeneral;
713 ret = DoTestConnect();
720 TRAPD(r, ret = DoTestCheckWriteL());
727 iFlogger.__DbgShutDownServer();
734 TInt CFloggerTest010_05::DoTestWrite()
736 ForceLogFlush(iFlogger);
738 iFlogger.HexDump(KNullDesC8);
744 TInt CFloggerTest010_05::DoTestCheckWriteL()
746 User::After(KTimeToLog);
751 RFs fileSystem; //For file operation create a file system
752 _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
753 _LIT8(KExpectedString,"0000 :");
755 _LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message
757 User::LeaveIfError(fileSystem.Connect());
759 //Open the file in the read mode
760 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
761 CleanupClosePushL(theFile);
764 User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
765 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
766 CleanupStack::PushL(hBuffer);
767 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
769 // Read from position 0: start of file
770 returnCode = theFile.Read(ptrString);
772 //check for no OOM msg
773 returnCode = ptrString.Find(KOOMError);
776 User::Leave(KErrNoMemory);
780 // we expect the output to be pretty blank, so not much to search for
781 // except make sure the standard "0000: " ins't even there
782 returnCode = ptrString.Find(KExpectedString); //find the test descriptor in the buffer read
785 CleanupStack::PopAndDestroy(hBuffer);
786 CleanupStack::PopAndDestroy(); //theFile object
787 if (returnCode == KErrNotFound)
797 TInt CFloggerTest010_05::DoTestConnect()
799 TInt ret = KErrGeneral;
800 TPtrC8 ptrSubSystem, ptrComponent;
801 ptrSubSystem.Set(_L8("SubSystem"));
802 ptrComponent.Set(_L8("Component"));
804 ret = iFlogger.Connect(); //Call connect() of Flogger
806 ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
809 ret = iFlogger.ClearLog(); //clear the contents from the log
820 CFloggerTest010_06::CFloggerTest010_06()
822 // store the name of this test case
823 SetTestStepName(_L("step_010_06"));
829 CFloggerTest010_06::~CFloggerTest010_06()
835 TVerdict CFloggerTest010_06::doTestStepL( )
837 User::After(100*1000); //Need this or connect will return KErrServerTerminated
839 INFO_PRINTF1(_L("Step 010.06 called "));
841 CFloggerTest010_01* step010_01 = new CFloggerTest010_01;
842 CleanupStack::PushL(step010_01);
843 doTestStepWithHeapFailureL( *step010_01, 1, 20, KErrNone, ETrue);
845 CleanupStack::PopAndDestroy(step010_01);
847 User::After(KTimeForDisplay);
848 return TestStepResult();