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 007.xx sl@0: sl@0: // EPOC includes sl@0: #include sl@0: sl@0: // Test system includes sl@0: #include sl@0: #include sl@0: sl@0: sl@0: //User includes sl@0: #include "teststepcomsdbg.h" sl@0: #include "step_007_xx.h" sl@0: sl@0: sl@0: /** sl@0: * Function Name : CFloggerTest007_01 sl@0: * Input parameters : None sl@0: * Output parameters : None sl@0: * Description : This is the constructor sl@0: */ sl@0: sl@0: CFloggerTest007_01::CFloggerTest007_01() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_007_01")); sl@0: sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest007_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: CFloggerTest007_01::~CFloggerTest007_01() sl@0: { 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 007_01 has sl@0: * passed or failed sl@0: */ sl@0: sl@0: sl@0: TVerdict CFloggerTest007_01::doTestStepL( ) sl@0: { sl@0: sl@0: INFO_PRINTF1(_L("Step 007.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(KTimeForDisplay); 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 or not. sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest007_01::executeStepL(TBool heapTest) sl@0: { sl@0: User::After(KTimeToLog); sl@0: TInt ret = KErrGeneral; sl@0: ret = DoTestConnect(); sl@0: if (ret == KErrNone) sl@0: { sl@0: ret = DoTestWrite() ; sl@0: if ( ret == KErrNone) sl@0: { 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: } sl@0: iFlogger.Close(); sl@0: sl@0: // if (ret == KErrNone) 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 or not. sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest007_01::executeStepL() sl@0: { sl@0: return KErrGeneral; 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 CFloggerTest007_01::DoTestWrite() sl@0: { sl@0: _LIT8(KTestMessage,"TC 7_01: Just for compalation"); //8 bit test decriptor sl@0: iFlogger.Write(KTestMessage); //Writes a 8 bit test descriptor sl@0: sl@0: ForceLogFlush(iFlogger); sl@0: return KErrNone; sl@0: } 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 DoTestWriteL() or not. sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest007_01::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(KTestMessage,"TC 7_01: Just for compalation"); //8 bit test decriptor sl@0: sl@0: _LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message sl@0: sl@0: User::LeaveIfError(fileSystem.Connect()); //connect to file server 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: 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(KTestMessage); //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(KOOMError); sl@0: if (returnCode > 0) sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: sl@0: sl@0: CleanupStack::PopAndDestroy(hBuffer); sl@0: CleanupStack::PopAndDestroy(); // For theFile object sl@0: if (returnCode > 0) sl@0: return KErrNone; sl@0: else sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: * Function Name : DoTestConnect sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function establishes a connection to file logger sl@0: * and sets the system and component name in file logger. sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest007_01::DoTestConnect() sl@0: { sl@0: TInt ret; sl@0: TPtrC8 ptrSubSystem; sl@0: TPtrC8 ptrComponent; sl@0: ptrSubSystem.Set(_L8("SubSystem")); sl@0: ptrComponent.Set(_L8("Component")); sl@0: sl@0: ret = iFlogger.Connect(); //Call connect() of Flogger sl@0: if (ret == KErrNone) sl@0: ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called sl@0: sl@0: // if (ret == KErrNone) sl@0: // ret = iFlogger.ClearLog(); //clear the contents from the log sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: * Function Name : CFloggerTest007_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: CFloggerTest007_02::CFloggerTest007_02() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_007_02")); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest007_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: CFloggerTest007_02::~CFloggerTest007_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 007_02 has sl@0: * passed or failed sl@0: sl@0: */ sl@0: sl@0: sl@0: TVerdict CFloggerTest007_02::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 007.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(KTimeForDisplay); sl@0: return TestStepResult(); sl@0: } 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 CFloggerTest007_02::executeStepL() sl@0: { sl@0: TInt ret = KErrGeneral; sl@0: sl@0: ret = DoTestConnect(); sl@0: CleanupClosePushL(iFlogger); sl@0: if (ret == KErrNone) sl@0: ret = DoTestWrite(); sl@0: if (ret == KErrNone) sl@0: ret = DoTestCheckWriteL(); sl@0: sl@0: CleanupStack::PopAndDestroy(); //logger sl@0: User::After(1000000); 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 CFloggerTest007_02::executeStepL(TBool) sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: /** sl@0: * Function Name : DoTestConnect sl@0: * Input parameters : None sl@0: * Output parameters : TInt sl@0: * Description : This function establishes a connection to file logger sl@0: * and sets the system and component name in file logger. sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest007_02::DoTestConnect() sl@0: { sl@0: TInt ret; sl@0: TPtrC8 ptrSubSystem; sl@0: TPtrC8 ptrComponent; sl@0: ptrSubSystem.Set(_L8("SubSystem")); sl@0: ptrComponent.Set(_L8("Component")); sl@0: sl@0: ret = iFlogger.Connect(); //Call connect() of Flogger sl@0: if (ret == KErrNone) sl@0: ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called sl@0: sl@0: if (ret == KErrNone) sl@0: ret = iFlogger.ClearLog(); //clear the contents from the log 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 CFloggerTest007_02::DoTestWrite() sl@0: { sl@0: //KTestLongMessage contains a very long test message sl@0: _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"); sl@0: iFlogger.Write(KTestLongMessage); sl@0: ForceLogFlush(iFlogger); 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 DoTestWriteL() or not. sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest007_02::DoTestCheckWriteL() sl@0: { sl@0: User::After(KTimeToLog); sl@0: RFile theFile; sl@0: HBufC8 * hBuffer; sl@0: TInt listfilesize,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"); // log file name and path sl@0: sl@0: //The following contains the string of length 200(max) sl@0: //which is written to the log file sl@0: //_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"); sl@0: _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"); sl@0: sl@0: //_LIT8(KOOMError, "#Logs may be lost out of memory!!"); 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(theFile.Size(listfilesize)); //Size of the file sl@0: 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: start of file sl@0: User::LeaveIfError(returnCode = theFile.Read(ptrString)); sl@0: sl@0: testData.Copy(KTestLongMessage); //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: 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: sl@0: sl@0: sl@0: sl@0: /** sl@0: * Function Name : CFloggerTest007_03 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: CFloggerTest007_03::CFloggerTest007_03() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_007_03")); sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest007_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: sl@0: CFloggerTest007_03::~CFloggerTest007_03() sl@0: { 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: TVerdict CFloggerTest007_03::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 007.03 called ")); sl@0: sl@0: CFloggerTest007_01* step007_01 = new CFloggerTest007_01; sl@0: CleanupStack::PushL(step007_01); sl@0: doTestStepWithHeapFailureL( *step007_01, 1, 20, KErrNone, ETrue); sl@0: sl@0: CleanupStack::PopAndDestroy(step007_01); sl@0: User::After(KTimeForDisplay); sl@0: return TestStepResult(); sl@0: } sl@0: