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 009.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_009_xx.h" sl@0: sl@0: sl@0: /** sl@0: * Function Name : CFloggerTest009_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: CFloggerTest009_01::CFloggerTest009_01() sl@0: { sl@0: SetTestStepName(_L("step_009_01")); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest009_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: CFloggerTest009_01::~CFloggerTest009_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 009_01 has sl@0: * passed or failed sl@0: sl@0: */ sl@0: sl@0: sl@0: TVerdict CFloggerTest009_01::doTestStepL( ) sl@0: { sl@0: RFileLogger logger; sl@0: INFO_PRINTF1(_L("Step 009.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 CFloggerTest009_01::executeStepL(TBool heapTest) sl@0: { sl@0: TInt ret = KErrNone; sl@0: sl@0: ret = DoTestConnect(); sl@0: CleanupClosePushL(iFlogger); 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: sl@0: // if (ret == KErrNone) sl@0: CleanupStack::PopAndDestroy(); //logger 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 CFloggerTest009_01::executeStepL() 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 CFloggerTest009_01::DoTestWrite() sl@0: { sl@0: _LIT8(KTestMessageOne,"TC 9_01: The value of test integer variable :%d");// The value of second test integer variable : %d"); sl@0: return DoTestWriteFormat(KTestMessageOne, 100); //Write unicode formatted test descriptor sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : DoTestWriteFormat sl@0: * Input parameters : TRefByValue sl@0: * Output parameters : TInt sl@0: * Description : This function writes formatted data to the file logger sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest009_01::DoTestWriteFormat(TRefByValue aFmt,...) sl@0: { sl@0: VA_LIST list; sl@0: VA_START(list,aFmt); sl@0: iFlogger.WriteFormat(aFmt,list); 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 CFloggerTest009_01::DoTestCheckWriteL() sl@0: { sl@0: User::After(1000*1000); 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: sl@0: _LIT8(KTestMessageOne,"TC 9_01: The value of test integer variable :%d"); sl@0: testData.Format(KTestMessageOne,100); sl@0: sl@0: _LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message sl@0: sl@0: _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path 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: 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: 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 KErrNotFound; 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 CFloggerTest009_01::DoTestConnect() sl@0: { sl@0: TInt ret = EFail; 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 : CFloggerTest009_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: CFloggerTest009_02::CFloggerTest009_02() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_009_02")); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest009_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: CFloggerTest009_02::~CFloggerTest009_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 009_02 has sl@0: * passed or failed sl@0: sl@0: */ sl@0: sl@0: sl@0: TVerdict CFloggerTest009_02::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 009.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: * 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: TInt CFloggerTest009_02::executeStepL() sl@0: { sl@0: TInt ret = KErrGeneral; sl@0: ret = DoTestConnect(); sl@0: 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: 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: TInt CFloggerTest009_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 CFloggerTest009_02::DoTestConnect() sl@0: { sl@0: TInt ret = KErrGeneral; 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 CFloggerTest009_02::DoTestWrite() sl@0: { sl@0: //KTestLongMessage contains a very long test message sl@0: _LIT8(KTestLongMessage,"TC 9_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 %d"); sl@0: DoTestWriteFormat(KTestLongMessage, 100); sl@0: ForceLogFlush(iFlogger); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name : DoTestWriteFormat sl@0: * Input parameters : TRefByValue sl@0: * Output parameters : TInt sl@0: * Description : This function writes formatted data to the file logger sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest009_02::DoTestWriteFormat(TRefByValue aFmt,...) sl@0: { sl@0: VA_LIST list; sl@0: VA_START(list,aFmt); sl@0: TRAPD(res, iFlogger.WriteFormat(aFmt,list)); sl@0: return res; 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: sl@0: TInt CFloggerTest009_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 9_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: * Function Name : CFloggerTest009_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: CFloggerTest009_03::CFloggerTest009_03() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_009_03")); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest009_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: CFloggerTest009_03::~CFloggerTest009_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 is responsible for doing the heap test analysis sl@0: sl@0: */ sl@0: sl@0: sl@0: TVerdict CFloggerTest009_03::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 009.03 called ")); sl@0: sl@0: CFloggerTest009_01* step009_01 = new CFloggerTest009_01; sl@0: CleanupStack::PushL(step009_01); sl@0: doTestStepWithHeapFailureL( *step009_01, 1, 20, KErrNone, ETrue); sl@0: sl@0: CleanupStack::PopAndDestroy(step009_01); sl@0: User::After(KTimeForDisplay); sl@0: return TestStepResult(); sl@0: } sl@0: