os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_023_01.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_023_01.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,287 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// This contains Flogger Unit Test Case 023.01
1.18 +
1.19 +// EPOC includes
1.20 +#include <e32base.h>
1.21 +
1.22 +// Test system includes
1.23 +#include "teststepcomsdbg.h"
1.24 +#include "step_023_01.h"
1.25 +
1.26 +
1.27 +#include <comms-infras/commsdebugutility.h>
1.28 +
1.29 +
1.30 +/**
1.31 +* Function Name : CFloggerTest023_01
1.32 +* Input parameters : None
1.33 +* Output parameters : None
1.34 +* Description : This is the constructor
1.35 +*/
1.36 +
1.37 +CFloggerTest023_01::CFloggerTest023_01()
1.38 + {
1.39 + // store the name of this test case
1.40 + SetTestStepName(_L("step_023_01"));
1.41 + }
1.42 +
1.43 +
1.44 +/**
1.45 +* Function Name :~ CFloggerTest023_01
1.46 +* Input parameters : None
1.47 +* Output parameters : None
1.48 +* Description : This is the Destructor
1.49 +*/
1.50 +
1.51 +
1.52 +CFloggerTest023_01::~CFloggerTest023_01()
1.53 + {
1.54 + }
1.55 +
1.56 +
1.57 +
1.58 +/**
1.59 +* Function Name : doTestStepL
1.60 +* Input parameters : None
1.61 +* Output parameters : TVerdict
1.62 +* Description : This function returns weather the test case 023_01 has
1.63 +* passed or failed
1.64 +
1.65 +*/
1.66 +
1.67 +
1.68 +TVerdict CFloggerTest023_01::doTestStepL( )
1.69 + {
1.70 + if ( executeStepL() == KErrNone )
1.71 + SetTestStepResult(EPass);
1.72 +
1.73 + else
1.74 + SetTestStepResult(EFail);
1.75 +
1.76 +
1.77 + return TestStepResult();
1.78 + }
1.79 +
1.80 +TInt CFloggerTest023_01::executeStepL(TBool)
1.81 + {
1.82 + return KErrGeneral;
1.83 + }
1.84 +
1.85 +TInt CFloggerTest023_01::executeStepL( )
1.86 + {
1.87 + TInt ret = KErrGeneral;
1.88 + ret = DoTestWrite();
1.89 + if ( ret == KErrNone)
1.90 + {
1.91 + TRAPD(r, ret = DoTestCheckWriteL());
1.92 + if ( r != KErrNone)
1.93 + ret = r;
1.94 + }
1.95 + return ret;
1.96 + }
1.97 +
1.98 +
1.99 +/**
1.100 +* Function Name : DoTestWrite
1.101 +* Input parameters : None
1.102 +* Output parameters : TInt
1.103 +* Description : This function writes the test data in to the log file
1.104 +
1.105 +*/
1.106 +
1.107 +
1.108 +TInt CFloggerTest023_01::DoTestWrite()
1.109 + {
1.110 + INFO_PRINTF1(_L("Step 023.01 called "));
1.111 +
1.112 + RFileLogger theFlogger;
1.113 + TPtrC8 ptrSubSystem;
1.114 + TPtrC8 ptrComponent;
1.115 + ptrSubSystem.Set(_L8("SubSystem")); //Test system name
1.116 + ptrComponent.Set(_L8("Component")); //Test component name
1.117 + _LIT8(KTestMessage,"This is the test message"); //Test decriptor
1.118 +
1.119 + TInt ret = KErrGeneral;
1.120 + ret = theFlogger.Connect();
1.121 +
1.122 + if (ret == KErrNone) // To Write the test descriptor the following lines are used.
1.123 + {
1.124 + ret = theFlogger.SetLogTags(ptrSubSystem, ptrComponent); //To set the tags
1.125 + if (ret == KErrNone)
1.126 + {
1.127 + theFlogger.Write(KTestMessage);
1.128 + theFlogger.__DbgShutDownServer();
1.129 + theFlogger.Close();
1.130 + }
1.131 + }
1.132 +
1.133 + User::After(100*1000); //Need this or connect will return KErrServerTerminated
1.134 +
1.135 + if (ret == KErrNone) // To actually test the ClearLog() functionality
1.136 + ret = theFlogger.Connect();
1.137 + if (ret == KErrNone)
1.138 + ret = theFlogger.SetLogTags(ptrSubSystem,ptrComponent);
1.139 + if (ret == KErrNone)
1.140 + {
1.141 + theFlogger.ClearLog(); //ClearLog called to clear the log message
1.142 + theFlogger.__DbgShutDownServer();
1.143 + User::After(100*1000); //need this to give server time to clear the log
1.144 + theFlogger.Close();
1.145 + }
1.146 +
1.147 + theFlogger.Close();
1.148 + return ret;
1.149 + }
1.150 +
1.151 +
1.152 +/**
1.153 +* Function Name : DoTestCheckWriteL
1.154 +* Input parameters : None
1.155 +* Output parameters : TInt
1.156 +* Description : This function writes the data to the file logger
1.157 +
1.158 +*/
1.159 +
1.160 +
1.161 +TInt CFloggerTest023_01::DoTestCheckWriteL()
1.162 + {
1.163 + RFile theFile;
1.164 + HBufC8 * hBuffer;
1.165 + TInt listfilesize;
1.166 + TInt returnCode;
1.167 + RFs fileSystem; //For file operation create a file system
1.168 + TBuf8<256> testData; //To hold the test descriptor
1.169 + _LIT(KLogFile, "c:\\logs\\log.txt"); // log file name and path
1.170 +
1.171 + _LIT8(KTestMessage,"This is the test message"); //Test decriptor
1.172 + _LIT8(KSystemName,"SubSystem"); //Test subsystem name
1.173 + _LIT8(KComponentName,"Component");// Test component name
1.174 +
1.175 + User::LeaveIfError(fileSystem.Connect()); //Connect to the file server
1.176 +
1.177 + //Open the file in the read mode
1.178 + User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
1.179 + CleanupClosePushL(theFile);
1.180 +
1.181 + User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
1.182 + hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
1.183 + CleanupStack::PushL(hBuffer);
1.184 + TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
1.185 +
1.186 + // Read from position 0: start of file
1.187 + returnCode = theFile.Read(ptrString);
1.188 +
1.189 + testData.Copy(KTestMessage); //Copy the test descriptor
1.190 + returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
1.191 + //from the file
1.192 +
1.193 + if (returnCode < 0) //Note test message should not be present
1.194 + {
1.195 + testData.Copy(KSystemName); //Note test system name should not be present
1.196 + returnCode = ptrString.Find(testData); //find the test system in the buffer read
1.197 + //from the file
1.198 + }
1.199 +
1.200 + if (returnCode < 0) //Note test component name should not be present
1.201 + {
1.202 + testData.Copy(KComponentName); //Note test message should not be present
1.203 + returnCode = ptrString.Find(testData); //find the test component in the buffer read
1.204 + //from the file
1.205 + }
1.206 +
1.207 + CleanupStack::PopAndDestroy(hBuffer);
1.208 + CleanupStack::PopAndDestroy(); //theFile
1.209 +
1.210 + if (returnCode < 0)
1.211 + return KErrNone;
1.212 + else
1.213 + return KErrGeneral;
1.214 +
1.215 + }
1.216 +
1.217 +
1.218 +/**
1.219 +* Function Name : CFloggerTest023_02
1.220 +* Input parameters : None
1.221 +* Output parameters : None
1.222 +* Description : This is the Constructor
1.223 +*/
1.224 +
1.225 +
1.226 +CFloggerTest023_02::CFloggerTest023_02()
1.227 + {
1.228 + // store the name of this test case
1.229 + SetTestStepName(_L("step_023_02"));
1.230 + }
1.231 +
1.232 +
1.233 +
1.234 +/**
1.235 +* Function Name :~ CFloggerTest023_02
1.236 +* Input parameters : None
1.237 +* Output parameters : None
1.238 +* Description : This is the Destructor
1.239 +*/
1.240 +
1.241 +
1.242 +CFloggerTest023_02::~CFloggerTest023_02()
1.243 + {
1.244 + }
1.245 +
1.246 +
1.247 +
1.248 +/**
1.249 +* Function Name : doTestStepL
1.250 +* Input parameters : None
1.251 +* Output parameters : TVerdict
1.252 +* Description : This function returns weather the test case 023_02 has
1.253 +* passed or failed
1.254 +
1.255 +*/
1.256 +
1.257 +
1.258 +TVerdict CFloggerTest023_02::doTestStepL( )
1.259 + {
1.260 + // INFO_PRINTF1(_L("Step 023.01 called ")); // This line was panicing in release mode testing
1.261 +
1.262 + if ( executeStepL() == KErrNone )
1.263 + SetTestStepResult(EPass);
1.264 +
1.265 + else
1.266 + SetTestStepResult(EFail);
1.267 +
1.268 +
1.269 + return TestStepResult();
1.270 + }
1.271 +
1.272 +TInt CFloggerTest023_02::executeStepL(TBool)
1.273 + {
1.274 + return KErrGeneral;
1.275 + }
1.276 +
1.277 +TInt CFloggerTest023_02::executeStepL( )
1.278 + {
1.279 + TPtrC8 ptrSubSystemTmp;
1.280 + TPtrC8 ptrComponentTmp;
1.281 + ptrSubSystemTmp.Set(_L8("SubSystem"));
1.282 + ptrComponentTmp.Set(_L8("Component"));
1.283 +
1.284 + RFileLogger theLogger;
1.285 + theLogger.Connect();
1.286 + theLogger.ClearLog(); // This line of code panics since it is called prior to SetLogTags()!!!!
1.287 + theLogger.SetLogTags(ptrSubSystemTmp,ptrComponentTmp);
1.288 + return KErrNone;
1.289 + }
1.290 +