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 008.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_008_xx.h" sl@0: sl@0: sl@0: /** sl@0: * Function Name : CFloggerTest008_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: CFloggerTest008_01::CFloggerTest008_01() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_008_01")); sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest008_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: CFloggerTest008_01::~CFloggerTest008_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 008_01 has sl@0: * passed or failed sl@0: sl@0: */ sl@0: sl@0: sl@0: TVerdict CFloggerTest008_01::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 008.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 sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest008_01::executeStepL(TBool heapTest) sl@0: { sl@0: TInt ret = KErrNone; 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: sl@0: // if (ret == KErrNone) sl@0: iFlogger.Close(); 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 CFloggerTest008_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 CFloggerTest008_01::DoTestWrite() sl@0: { sl@0: _LIT8(KTestMessageOne,"TC 8_01: The value of test integer variable :%d"); sl@0: iFlogger.WriteFormat(KTestMessageOne, 100); //Write 8 bit test descriptor sl@0: sl@0: ForceLogFlush(iFlogger); sl@0: 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 CFloggerTest008_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: _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path sl@0: sl@0: TBuf8<256> testData; //To hold the test descriptor sl@0: sl@0: _LIT8(KTestMessageOne,"TC 8_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: 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: 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: 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: /** 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 CFloggerTest008_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: sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: * Function Name : CFloggerTest008_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: CFloggerTest008_02::CFloggerTest008_02() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_008_02")); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest008_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: CFloggerTest008_02::~CFloggerTest008_02() 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 008_02 has sl@0: * passed or failed sl@0: sl@0: */ sl@0: sl@0: sl@0: TVerdict CFloggerTest008_02::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 008.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: sl@0: TInt CFloggerTest008_02::executeStepL() sl@0: { sl@0: TInt ret = KErrGeneral; 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: iFlogger.Close(); sl@0: TRAPD(r, ret = DoTestCheckWriteL() ); sl@0: if ( r != KErrNone) sl@0: ret = r; sl@0: } sl@0: } 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 sl@0: sl@0: */ sl@0: sl@0: sl@0: TInt CFloggerTest008_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 CFloggerTest008_02::DoTestConnect() sl@0: { sl@0: TInt ret; sl@0: TPtrC8 ptrSubSystem, 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: /** 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 CFloggerTest008_02::DoTestWrite() sl@0: { sl@0: _LIT8(KTestMessageTwo,"TC 8_02: The value of first test integer variable :%d The value of second test integer variable : %d"); sl@0: iFlogger.WriteFormat(KTestMessageTwo, 100, 200); //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: //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 CFloggerTest008_02::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: 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: TBuf8<256> testData; //To hold the test descriptor sl@0: _LIT8(KTestMessageTwo,"TC 8_02: The value of first test integer variable :%d The value of second test integer variable : %d"); sl@0: testData.Format(KTestMessageTwo,100, 200); 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 the 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: 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) // 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: 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: * Function Name : CFloggerTest008_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: CFloggerTest008_03::CFloggerTest008_03() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_008_03")); sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest008_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: CFloggerTest008_03::~CFloggerTest008_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 returns weather the test case 004_01 has sl@0: * passed or failed sl@0: sl@0: */ sl@0: sl@0: sl@0: TVerdict CFloggerTest008_03::doTestStepL( ) sl@0: { sl@0: if ( executeStepL() == KErrNone ) sl@0: SetTestStepResult(EPass); sl@0: sl@0: else sl@0: SetTestStepResult(EFail); 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: sl@0: TInt CFloggerTest008_03::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: 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 CFloggerTest008_03::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 CFloggerTest008_03::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: sl@0: if (ret == KErrNone) sl@0: ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called 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 CFloggerTest008_03::DoTestWrite() sl@0: { sl@0: //KTestLongMessage contains a very long test message sl@0: _LIT(KTestLongMessage,"TC 8_03: 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: sl@0: iFlogger.Write(KTestLongMessage); //this causes a PANIC 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 CFloggerTest008_03::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 8_03: 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: * Function Name : CFloggerTest008_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: CFloggerTest008_04::CFloggerTest008_04() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_008_04")); sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: * Function Name :~ CFloggerTest008_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: CFloggerTest008_04::~CFloggerTest008_04() sl@0: { 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: TVerdict CFloggerTest008_04::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 008.04 called ")); sl@0: sl@0: CFloggerTest008_01* step008_01 = new CFloggerTest008_01; sl@0: CleanupStack::PushL(step008_01); sl@0: doTestStepWithHeapFailureL( *step008_01, 1, 20, KErrNone, ETrue); sl@0: sl@0: CleanupStack::PopAndDestroy(step008_01); sl@0: sl@0: User::After(KTimeForDisplay); sl@0: return TestStepResult(); sl@0: } sl@0: