sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // This contains Flogger Unit Test Case 017.xx sl@0: sl@0: // EPOC includes sl@0: #include sl@0: sl@0: // Test system includes sl@0: #include sl@0: #include "TestMessage.h" sl@0: #include sl@0: sl@0: sl@0: //User includes sl@0: #include "teststepcomsdbg.h" sl@0: #include "step_017_xx.h" sl@0: sl@0: sl@0: /** sl@0: * Function Name : CFloggerTest017_01 sl@0: * Input parameters : None sl@0: * Output parameters : None sl@0: * Description : This is the constructor sl@0: */ sl@0: sl@0: sl@0: CFloggerTest017_01::CFloggerTest017_01() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_017_01")); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest017_01 sl@0: * Input parameters : None sl@0: * Output parameters : None sl@0: * Description : This is the Destructor sl@0: */ sl@0: sl@0: sl@0: CFloggerTest017_01::~CFloggerTest017_01() sl@0: { sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : doTestStepL sl@0: * Input parameters : None sl@0: * Output parameters : TVerdict sl@0: * Description : This function returns weather the test case 017_01 has sl@0: * passed or failed sl@0: sl@0: */ sl@0: sl@0: sl@0: TVerdict CFloggerTest017_01::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 017.01 called ")); sl@0: sl@0: if ( executeStepL(EFalse) == KErrNone ) sl@0: SetTestStepResult(EPass); sl@0: sl@0: else sl@0: SetTestStepResult(EFail); sl@0: sl@0: sl@0: User::After(KTimeForDisplay1); sl@0: return TestStepResult(); sl@0: } sl@0: /** sl@0: * Function Name : executeStepL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the test data in to the log file sl@0: * This function check the test message is present in the sl@0: * log file sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_01::executeStepL() sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: /** sl@0: * Function Name : executeStepL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the test data in to the log file sl@0: * This function check the test message is present in the sl@0: * log file sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_01::executeStepL(TBool heapTest) sl@0: { sl@0: TInt ret = KErrGeneral; sl@0: sl@0: ret = DoTestWrite(); sl@0: if (ret == KErrNone) sl@0: { sl@0: User::After(KTimeToLog); sl@0: TRAPD(r, ret = DoTestCheckWriteL() ); sl@0: if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone))) sl@0: { sl@0: ret = KErrNoMemory; sl@0: } sl@0: else if (r != KErrNone) sl@0: { sl@0: ret = r; sl@0: } sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : DoTestWrite sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the data to the file logger in hexa format sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_01::DoTestWrite() sl@0: { sl@0: _LIT8(KDescText, "TC 17_1:Test Msg----"); //Test body descriptor sl@0: sl@0: //Write the test datas in the hexa format sl@0: RFileLogger::HexDump(KStdSubsysTag8,KStdCompTag8, KDescText, KHexTestHeader); sl@0: sl@0: // connect so we can flush file buffer for heap check since timer is killed in heap checks sl@0: RFileLogger theFlogger; sl@0: theFlogger.Connect(); sl@0: theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8); sl@0: ForceLogFlush(theFlogger); sl@0: theFlogger.Close(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : DoTestCheckWriteL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function checks the weather test data was written sl@0: * in to the log file by DoTestWrite() or not. sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_01::DoTestCheckWriteL() sl@0: { sl@0: User::After(KTimeToLog); sl@0: sl@0: RFile theFile; sl@0: HBufC8 * hBuffer; sl@0: TInt listfilesize; sl@0: TInt returnCode; sl@0: RFs fileSystem; //For file operation create a file system sl@0: _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path sl@0: sl@0: _LIT8(KBodyTxt,"TC 17_1:Test Msg");// First 16 chars of Test body descriptor sl@0: sl@0: User::LeaveIfError(fileSystem.Connect()); sl@0: sl@0: //Open the file in the read mode sl@0: User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)) ; sl@0: sl@0: sl@0: User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file sl@0: hBuffer = HBufC8::New(listfilesize); //Allocate the buffer sl@0: CleanupStack::PushL(hBuffer); sl@0: sl@0: TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer sl@0: sl@0: // Read from position 0, i.e starting of file sl@0: returnCode = theFile.Read(ptrString); sl@0: sl@0: returnCode = ptrString.Find(KHexTestHeader); //find the test header descriptor in sl@0: //the buffer read from the file sl@0: sl@0: if (returnCode > 0) //The header is present sl@0: { sl@0: returnCode = ptrString.Find(KHexTestMargin); //find the test margin descriptor in sl@0: //the buffer read from the file sl@0: } sl@0: sl@0: if (returnCode > 0) //The margin is present sl@0: { sl@0: returnCode = ptrString.Find(KBodyTxt); //find the test descriptor in the sl@0: //buffer read from the file sl@0: } sl@0: sl@0: theFile.Close(); sl@0: fileSystem.Close(); //Close the file server sl@0: CleanupStack::PopAndDestroy(hBuffer); sl@0: sl@0: if (returnCode > 0) //The test body descriptor is present sl@0: return KErrNone; sl@0: else sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: * Function Name : CFloggerTest017_02 sl@0: * Input parameters : None sl@0: * Output parameters : None sl@0: * Description : This is the constructor sl@0: */ sl@0: sl@0: sl@0: CFloggerTest017_02::CFloggerTest017_02() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_017_02")); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest017_02 sl@0: * Input parameters : None sl@0: * Output parameters : None sl@0: * Description : This is the Destructor sl@0: */ sl@0: sl@0: sl@0: CFloggerTest017_02::~CFloggerTest017_02() sl@0: { sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : doTestStepL sl@0: * Input parameters : None sl@0: * Output parameters : TVerdict sl@0: * Description : This function returns weather the test case 017_02 has sl@0: * passed or failed sl@0: sl@0: */ sl@0: sl@0: sl@0: TVerdict CFloggerTest017_02::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 017.02 called ")); sl@0: sl@0: if ( executeStepL() == KErrNone ) sl@0: SetTestStepResult(EPass); sl@0: sl@0: else sl@0: SetTestStepResult(EFail); sl@0: sl@0: sl@0: User::After(KTimeForDisplay1); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: * Function Name : executeStepL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the test data in to the log file sl@0: * This function check the test message is present in the sl@0: * log file sl@0: sl@0: */ sl@0: sl@0: sl@0: sl@0: TInt CFloggerTest017_02::executeStepL(TBool) sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: /** sl@0: * Function Name : executeStepL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the test data in to the log file sl@0: * This function check the test message is present in the sl@0: * log file sl@0: sl@0: */ sl@0: sl@0: sl@0: sl@0: TInt CFloggerTest017_02::executeStepL( ) sl@0: { sl@0: User::After(1000*1000); //Need this or connect will return KErrServerTerminated sl@0: TInt ret = KErrGeneral; sl@0: sl@0: ret = DoTestWrite(); sl@0: if (ret == KErrNone ) sl@0: { sl@0: TRAPD(r, ret = DoTestCheckWriteL()); sl@0: if (r != KErrNone) sl@0: ret = r; sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : DoTestWrite sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the data to the file logger sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_02::DoTestWrite() sl@0: { sl@0: sl@0: RFileLogger theFlogger; sl@0: TInt ret = KErrNone; sl@0: sl@0: ret = theFlogger.Connect(); //Just to clear the old log message sl@0: if (ret == KErrNone) sl@0: ret = theFlogger.SetLogTags(KStdSubsysTag8,KStdCompTag8); sl@0: if (ret == KErrNone) sl@0: ret = theFlogger.ClearLog(); sl@0: if (ret == KErrNone) sl@0: theFlogger.Close(); sl@0: sl@0: if (ret == KErrNone) sl@0: { sl@0: _LIT8(KDescText,"TC 17_2:Test Msg"); sl@0: sl@0: //Write the test datas in the hexa format sl@0: RFileLogger::HexDump(KStdSubsysTag8,KStdCompTag8, KDescText, KEightSpaces8); sl@0: sl@0: return KErrNone; sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : DoTestCheckWriteL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function checks the weather test data was written sl@0: * in to the log file by DoTestWrite() or not. sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_02::DoTestCheckWriteL() sl@0: { sl@0: User::After(KTimeToLog); sl@0: RFile theFile; sl@0: HBufC8 * hBuffer; sl@0: TInt listfilesize; sl@0: TInt returnCode; sl@0: RFs fileSystem; //For file operation create a file system sl@0: TBuf8<256> testData; //To hold the test descriptor sl@0: _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path sl@0: sl@0: _LIT8(KOOMError, "#Logs may be lost out of memory!!"); // Error message sl@0: sl@0: User::LeaveIfError(fileSystem.Connect()); sl@0: sl@0: //Open the file in the read mode sl@0: User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); sl@0: sl@0: CleanupClosePushL(theFile); sl@0: sl@0: User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file sl@0: hBuffer = HBufC8::New(listfilesize); //Allocate the buffer sl@0: CleanupStack::PushL(hBuffer); sl@0: TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer sl@0: sl@0: // Read from position 0: start of file sl@0: returnCode = theFile.Read(ptrString); sl@0: sl@0: testData.FillZ(); sl@0: testData.Copy(KEightSpaces8); //Copy the test descriptor sl@0: returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read sl@0: //from the file sl@0: sl@0: if (returnCode == KErrNotFound) // Check for the error message in the log sl@0: { sl@0: returnCode = ptrString.Find(KOOMError); sl@0: if (returnCode > 0) sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(hBuffer); sl@0: CleanupStack::PopAndDestroy(); //theFile sl@0: if (returnCode > 0) sl@0: return KErrNone; sl@0: else sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: * Function Name : CFloggerTest017_03 sl@0: * Input parameters : None sl@0: * Output parameters : None sl@0: * Description : This is the constructor sl@0: * Description : This is the constructor sl@0: */ sl@0: sl@0: sl@0: CFloggerTest017_03::CFloggerTest017_03() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_017_03")); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest017_03 sl@0: * Input parameters : None sl@0: * Output parameters : None sl@0: * Description : This is the Destructor sl@0: */ sl@0: sl@0: sl@0: CFloggerTest017_03::~CFloggerTest017_03() sl@0: { sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : doTestStepL sl@0: * Input parameters : None sl@0: * Output parameters : TVerdict sl@0: * Description : This function returns weather the test case 017_03 has sl@0: * passed or failed sl@0: sl@0: */ sl@0: sl@0: sl@0: TVerdict CFloggerTest017_03::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 017.03 called ")); sl@0: sl@0: if ( executeStepL() == KErrNone ) sl@0: SetTestStepResult(EPass); sl@0: sl@0: else sl@0: SetTestStepResult(EFail); sl@0: sl@0: sl@0: User::After(KTimeForDisplay1); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : executeStepL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the test data in to the log file sl@0: * This function check the test message is present in the sl@0: * log file sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_03::executeStepL( ) sl@0: { sl@0: User::After(1000*1000); //Need this or connect will return KErrServerTerminated sl@0: TInt ret = KErrGeneral; sl@0: sl@0: ret = DoTestWrite(); sl@0: if (ret == KErrNone ) sl@0: { sl@0: TRAPD(r, ret = DoTestCheckWriteL()); sl@0: if (ret != KErrNone) sl@0: ret = r; sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: * Function Name : executeStepL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the test data in to the log file sl@0: * This function check the test message is present in the sl@0: * log file sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_03::executeStepL(TBool) sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: //** sl@0: /* Function Name : DoTestWrite sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the data to the file logger sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_03::DoTestWrite() sl@0: { sl@0: sl@0: RFileLogger theFlogger; sl@0: TInt ret = KErrNone; sl@0: sl@0: ret = theFlogger.Connect(); //Just to clear the old log message sl@0: if (ret == KErrNone) sl@0: ret = theFlogger.SetLogTags(KStdSubsysTag8,KStdCompTag8); sl@0: if (ret == KErrNone) sl@0: ret = theFlogger.ClearLog(); sl@0: if (ret == KErrNone) sl@0: theFlogger.Close(); sl@0: sl@0: if (ret == KErrNone) sl@0: { sl@0: _LIT8(KDescText,"TC 17_3:Test Msg"); //8 bit test descriptor sl@0: sl@0: //Write the test datas in the hexa format sl@0: RFileLogger::HexDump(KStdSubsysTag8,KStdCompTag8, KDescText); sl@0: sl@0: sl@0: return KErrNone; sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : DoTestCheckWriteL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function checks the weather test data was written sl@0: * in to the log file by DoTestWrite() or not. sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_03::DoTestCheckWriteL() sl@0: { sl@0: sl@0: User::After(KTimeToLog); sl@0: RFile theFile; sl@0: HBufC8 * hBuffer; sl@0: TInt listfilesize; sl@0: TInt returnCode; sl@0: RFs fileSystem; //For file operation create a file system sl@0: TBuf8<256> testData; //To hold the test descriptor sl@0: _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path sl@0: sl@0: _LIT8(KBodyTxt,"TC 17_3:Test Msg");// Test body descriptor sl@0: sl@0: User::LeaveIfError(fileSystem.Connect()); sl@0: sl@0: //Open the file in the read mode sl@0: User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); sl@0: CleanupClosePushL(theFile); sl@0: sl@0: User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file sl@0: hBuffer = HBufC8::New(listfilesize); //Allocate the buffer sl@0: CleanupStack::PushL(hBuffer); sl@0: TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer sl@0: sl@0: // Read from position 0: start of file sl@0: returnCode=theFile.Read(ptrString); sl@0: sl@0: testData.Copy(KBodyTxt); //Copy the test descriptor sl@0: returnCode=ptrString.Find(testData); //find the test descriptor in the buffer read sl@0: //from the file sl@0: sl@0: if (returnCode == KErrNotFound) //Find the error message sl@0: { sl@0: returnCode = ptrString.Find(KErrOOM); sl@0: if (returnCode > 0) sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(hBuffer); sl@0: CleanupStack::PopAndDestroy(); //theFile object sl@0: if (returnCode > 0) sl@0: return KErrNone; sl@0: else sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: * Function Name : CFloggerTest017_04 sl@0: * Input parameters : None sl@0: * Output parameters : None sl@0: * Description : This is the constructor sl@0: */ sl@0: sl@0: sl@0: CFloggerTest017_04::CFloggerTest017_04() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_017_04")); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest017_04 sl@0: * Input parameters : None sl@0: * Output parameters : None sl@0: * Description : This is the Destructor sl@0: */ sl@0: sl@0: sl@0: CFloggerTest017_04::~CFloggerTest017_04() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Function Name : doTestStepL sl@0: * Input parameters : None sl@0: * Output parameters : TVerdict sl@0: * Description : This function returns weather the test case 017_04 has sl@0: * passed or failed sl@0: sl@0: */ sl@0: sl@0: sl@0: TVerdict CFloggerTest017_04::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 017.04 called ")); sl@0: sl@0: if ( executeStepL() == KErrNone ) sl@0: SetTestStepResult(EPass); sl@0: sl@0: else sl@0: SetTestStepResult(EFail); sl@0: sl@0: sl@0: User::After(KTimeForDisplay1); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : executeStepL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the test data in to the log file sl@0: * This function check the test message is present in the sl@0: * log file sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_04::executeStepL( ) sl@0: { sl@0: User::After(1000*1000); //Need this or connect will return KErrServerTerminated sl@0: TInt ret = KErrGeneral; sl@0: sl@0: ret = DoTestWrite(); sl@0: if (ret == KErrNone ) sl@0: { sl@0: TRAPD(r, ret = DoTestCheckWriteL()); sl@0: if (ret != KErrNone) sl@0: ret = r; sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: /** sl@0: * Function Name : executeStepL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the test data in to the log file sl@0: * This function check the test message is present in the sl@0: * log file sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_04::executeStepL(TBool) sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: /** sl@0: * Function Name : DoTestWrite sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the data to the file logger sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_04::DoTestWrite() sl@0: { sl@0: _LIT8(KDescText,"TC 17_4:Test Msg"); sl@0: sl@0: RFileLogger theFlogger; sl@0: TInt ret = KErrNone; sl@0: ret = theFlogger.Connect(); //Just to clear the old log message sl@0: if (ret == KErrNone) sl@0: ret = theFlogger.SetLogTags(KStdSubsysTag8,KStdCompTag8); sl@0: if (ret == KErrNone) sl@0: ret = theFlogger.ClearLog(); sl@0: if (ret == KErrNone) sl@0: theFlogger.Close(); sl@0: if (ret == KErrNone) sl@0: { sl@0: //Write the test datas in the hexa format sl@0: RFileLogger::HexDump(KStdSubsysTag8,KStdCompTag8, KDescText, KNullDesC8); sl@0: sl@0: return KErrNone; sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : DoTestCheckWriteL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function checks the weather test data was written sl@0: * in to the log file by DoTestWrite() or not. sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_04::DoTestCheckWriteL() sl@0: { sl@0: User::After(KTimeToLog); sl@0: RFile theFile; sl@0: HBufC8 * hBuffer; sl@0: TInt listfilesize; sl@0: TInt returnCode; sl@0: RFs fileSystem; //For file operation create a file system sl@0: TBuf8<256> testData; //To hold the test descriptor sl@0: _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path sl@0: sl@0: _LIT(KBodyTxt,"TC 17_4:Test Msg");// Test body descriptor sl@0: TUint numSuccessful = 0; sl@0: sl@0: User::LeaveIfError(fileSystem.Connect()); sl@0: sl@0: //Open the file in the read mode sl@0: User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); sl@0: CleanupClosePushL(theFile); sl@0: sl@0: User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file sl@0: hBuffer = HBufC8::New(listfilesize); //Allocate the buffer sl@0: CleanupStack::PushL(hBuffer); sl@0: TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer sl@0: sl@0: // Read from position 0: start of file sl@0: returnCode = theFile.Read(ptrString); sl@0: sl@0: sl@0: testData.Copy(KBodyTxt); //Copy the test descriptor sl@0: returnCode=ptrString.Find(testData); //find the test descriptor in the buffer read sl@0: //from the file sl@0: sl@0: if (returnCode > 0) sl@0: numSuccessful++; sl@0: sl@0: returnCode=ptrString.Find(KHexTestHeader); //find the test descriptor in the buffer read sl@0: sl@0: if (returnCode == KErrNotFound) sl@0: numSuccessful++; sl@0: sl@0: sl@0: if (returnCode == KErrNotFound) //Find the error message sl@0: { sl@0: returnCode = ptrString.Find(KErrOOM); sl@0: if (returnCode > 0) sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(hBuffer); sl@0: CleanupStack::PopAndDestroy(); //theFile object sl@0: sl@0: if (numSuccessful == 2) sl@0: return KErrNone; sl@0: else sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: * Function Name : CFloggerTest017_05 sl@0: * Input parameters : None sl@0: * Output parameters : None sl@0: * Description : This is the constructor sl@0: */ sl@0: sl@0: sl@0: CFloggerTest017_05::CFloggerTest017_05() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_017_05")); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest017_05 sl@0: * Input parameters : None sl@0: * Output parameters : None sl@0: * Description : This is the Destructor sl@0: */ sl@0: sl@0: sl@0: CFloggerTest017_05::~CFloggerTest017_05() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Function Name : doTestStepL sl@0: * Input parameters : None sl@0: * Output parameters : TVerdict sl@0: * Description : This function returns weather the test case 017_05 has sl@0: * passed or failed sl@0: sl@0: */ sl@0: sl@0: sl@0: TVerdict CFloggerTest017_05::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 017.05 called ")); sl@0: sl@0: if ( executeStepL() == KErrNone ) sl@0: SetTestStepResult(EPass); sl@0: sl@0: else sl@0: SetTestStepResult(EFail); sl@0: sl@0: sl@0: User::After(KTimeForDisplay1); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: * Function Name : executeStepL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the test data in to the log file sl@0: * This function check the test message is present in the sl@0: * log file sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_05::executeStepL(TBool) sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: /** sl@0: * Function Name : executeStepL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the test data in to the log file sl@0: * This function check the test message is present in the sl@0: * log file sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_05::executeStepL( ) sl@0: { sl@0: User::After(KTimeToLog); //Need this or connect will return KErrServerTerminated sl@0: TInt ret = KErrGeneral; sl@0: sl@0: ret = DoTestWrite(); sl@0: if (ret == KErrNone ) sl@0: { sl@0: TRAPD(r, ret = DoTestCheckWriteL()); sl@0: if (ret != KErrNone) sl@0: ret = r; sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : DoTestWrite sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function writes the data to the file logger sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_05::DoTestWrite() sl@0: { sl@0: RFileLogger theFlogger; sl@0: TInt ret = KErrNone; sl@0: sl@0: ret = theFlogger.Connect(); //Just to clear the old log message sl@0: if (ret == KErrNone) sl@0: ret = theFlogger.SetLogTags(KStdSubsysTag8,KStdCompTag8); sl@0: if (ret == KErrNone) sl@0: ret = theFlogger.ClearLog(); sl@0: if (ret == KErrNone) sl@0: theFlogger.Close(); sl@0: sl@0: if (ret == KErrNone) sl@0: { sl@0: //Write the test datas in the hexa format sl@0: RFileLogger::HexDump(KStdSubsysTag8,KStdCompTag8, KNullDesC8); sl@0: return KErrNone; sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : DoTestCheckWriteL sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function checks the weather test data was written sl@0: * in to the log file by DoTestWrite() or not. sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest017_05::DoTestCheckWriteL() sl@0: { sl@0: User::After(KTimeToLog); sl@0: RFile theFile; sl@0: HBufC8 * hBuffer; sl@0: TInt listfilesize; sl@0: TInt returnCode; sl@0: RFs fileSystem; //For file operation create a file system sl@0: _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path sl@0: _LIT8(KExpectedString,"0000 :"); sl@0: sl@0: _LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message sl@0: sl@0: User::LeaveIfError(fileSystem.Connect()); sl@0: sl@0: //Open the file in the read mode sl@0: User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); sl@0: CleanupClosePushL(theFile); sl@0: sl@0: sl@0: User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file sl@0: hBuffer = HBufC8::New(listfilesize); //Allocate the buffer sl@0: CleanupStack::PushL(hBuffer); sl@0: TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer sl@0: sl@0: // Read from position 0: start of file sl@0: returnCode = theFile.Read(ptrString); sl@0: sl@0: //check for no OOM msg sl@0: returnCode = ptrString.Find(KOOMError); sl@0: if (returnCode > 0) sl@0: { sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: sl@0: sl@0: // we expect the output to be pretty blank, so not much to search for sl@0: // except make sure the standard "0000: " ins't even there sl@0: returnCode = ptrString.Find(KExpectedString); //find the test descriptor in the buffer read sl@0: //from the file sl@0: sl@0: CleanupStack::PopAndDestroy(hBuffer); sl@0: CleanupStack::PopAndDestroy(); //theFile object sl@0: if (returnCode == KErrNotFound) sl@0: return KErrNone; sl@0: else sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: sl@0: sl@0: /* sl@0: * Function Name : CFloggerTest017_06 sl@0: * Input parameters : None sl@0: * Output parameters : None sl@0: * Description : This is the constructor sl@0: */ sl@0: sl@0: sl@0: CFloggerTest017_06::CFloggerTest017_06() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_017_06")); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest017_06 sl@0: * Input parameters : None sl@0: * Output parameters : None sl@0: * Description : This is the Destructor sl@0: */ sl@0: sl@0: sl@0: CFloggerTest017_06::~CFloggerTest017_06() sl@0: { sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : doTestStepL sl@0: * Input parameters : None sl@0: * Output parameters : TVerdict sl@0: * Description : This function is responsible for doing the heap test analysis sl@0: sl@0: */ sl@0: sl@0: sl@0: sl@0: TVerdict CFloggerTest017_06::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 017.06 called ")); sl@0: sl@0: CFloggerTest017_01* step017_01 = new CFloggerTest017_01; sl@0: CleanupStack::PushL(step017_01); sl@0: doTestStepWithHeapFailureL( *step017_01, 1, 20, KErrNone, ETrue); sl@0: sl@0: CleanupStack::PopAndDestroy(step017_01); sl@0: User::After(KTimeForDisplay); sl@0: return TestStepResult(); sl@0: } sl@0: