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 011.01 sl@0: sl@0: // EPOC includes sl@0: #include sl@0: sl@0: // Test system includes sl@0: #include "teststepcomsdbg.h" sl@0: #include "TestMessage.h" sl@0: #include "step_011_xx.h" sl@0: sl@0: #include sl@0: sl@0: sl@0: //***************************************************************** sl@0: //Function Name : CFloggerTest011_01 sl@0: //Input parameters : None sl@0: //Output parameters : None sl@0: //Description : This is the constructor sl@0: //***************************************************************** sl@0: sl@0: CFloggerTest011_01::CFloggerTest011_01() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_011_01")); sl@0: } sl@0: sl@0: sl@0: sl@0: //***************************************************************** sl@0: //Function Name :~ CFloggerTest011_01 sl@0: //Input parameters : None sl@0: //Output parameters : None sl@0: //Description : This is the Destructor sl@0: //***************************************************************** sl@0: sl@0: CFloggerTest011_01::~CFloggerTest011_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 011_01 has sl@0: // passed or failed sl@0: sl@0: //***************************************************************** sl@0: sl@0: TVerdict CFloggerTest011_01::doTestStepL( ) sl@0: { sl@0: sl@0: INFO_PRINTF1(_L("Step 011.01 called ")); sl@0: sl@0: if ( executeStepL(EFalse) == KErrNone ) sl@0: SetTestStepResult(EPass); sl@0: else sl@0: SetTestStepResult(EFail); sl@0: User::After(KTimeForDisplay); 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 CFloggerTest011_01::executeStepL() sl@0: { sl@0: return KErrGeneral; 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 CFloggerTest011_01::executeStepL(TBool heapTest) sl@0: { 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: //***************************************************************** 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: TInt CFloggerTest011_01::DoTestWrite() sl@0: { sl@0: TInt ret = KErrNone; sl@0: _LIT(KTestMessage,"TC 11_01: This is test messsage"); //unicode test decriptor sl@0: sl@0: RFileLogger theFlogger; sl@0: sl@0: //Just to clear the old log message sl@0: ret = theFlogger.Connect(); sl@0: if ( ret == KErrNone) sl@0: { sl@0: ret = theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8); sl@0: if ( ret == KErrNone) sl@0: { sl@0: ret = theFlogger.ClearLog(); sl@0: } sl@0: if ( ret == KErrNone) sl@0: { sl@0: theFlogger.Close(); sl@0: } sl@0: } sl@0: sl@0: sl@0: if ( ret == KErrNone) sl@0: { sl@0: // Test case sl@0: RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestMessage); sl@0: sl@0: // reconnect so we can flush file buffer for heap check sl@0: ret = theFlogger.Connect(); sl@0: if (ret == KErrNone) sl@0: { sl@0: theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8); sl@0: ForceLogFlush(theFlogger); sl@0: theFlogger.Close(); sl@0: } sl@0: } sl@0: return ret; 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: TInt CFloggerTest011_01::DoTestCheckWriteL() sl@0: { sl@0: 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: 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: _LIT(KTestMessage,"TC 11_01: This is test messsage"); //unicode test decriptor 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(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: 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 KErrNotFound; sl@0: } sl@0: sl@0: sl@0: sl@0: TInt CFloggerTest011_01::DoHeapTestWrite() sl@0: { sl@0: sl@0: sl@0: _LIT(KTestMessage,"TC 11_03: This is heap test messsage"); //unicode test decriptor sl@0: sl@0: RFileLogger ::Write(KStdSubsysTag8, KStdCompTag8, KTestMessage); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: ///////////////////////////////////////////////////////////////////// sl@0: sl@0: //***************************************************************** sl@0: //Function Name : CFloggerTest011_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: sl@0: CFloggerTest011_02::CFloggerTest011_02() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_011_02")); sl@0: sl@0: } sl@0: sl@0: sl@0: //***************************************************************** sl@0: //Function Name :~ CFloggerTest011_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: CFloggerTest011_02::~CFloggerTest011_02() sl@0: { sl@0: iFlogger.Close(); 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: TVerdict CFloggerTest011_02::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 011.02 called ")); sl@0: sl@0: if ( executeStepL() == KErrNone ) sl@0: SetTestStepResult(EPass); 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: //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 CFloggerTest011_02::executeStepL(TBool) 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: TInt CFloggerTest011_02::executeStepL() sl@0: { 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: 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: TInt CFloggerTest011_02::DoTestWrite() sl@0: { sl@0: sl@0: TInt ret = KErrNone; sl@0: sl@0: sl@0: _LIT(KTestLongMessage,"TC 11_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"); //unicode test decriptor sl@0: sl@0: RFileLogger theFlogger; 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: RFileLogger ::Write(KStdSubsysTag8, KStdCompTag8, KTestLongMessage); sl@0: User::After(100000); sl@0: sl@0: return KErrNone; sl@0: sl@0: } sl@0: sl@0: sl@0: TInt CFloggerTest011_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 11_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 lon"); 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 : CFloggerTest011_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: CFloggerTest011_03::CFloggerTest011_03() sl@0: { sl@0: // store the name of this test case sl@0: SetTestStepName(_L("step_011_03")); sl@0: } sl@0: sl@0: sl@0: sl@0: //***************************************************************** sl@0: //Function Name :~ CFloggerTest011_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: CFloggerTest011_03::~CFloggerTest011_03() sl@0: { 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: sl@0: TVerdict CFloggerTest011_03::doTestStepL( ) sl@0: { sl@0: INFO_PRINTF1(_L("Step 011.03 called ")); sl@0: sl@0: CFloggerTest011_01* step011_01 = new CFloggerTest011_01; sl@0: CleanupStack::PushL(step011_01); sl@0: doTestStepWithHeapFailureL( *step011_01, 1, 20, KErrNone, ETrue); sl@0: sl@0: CleanupStack::PopAndDestroy(step011_01); sl@0: User::After(KTimeForDisplay); sl@0: return TestStepResult(); sl@0: sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: ///////////////////////////////////////////////////////////////////////