os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_014_xx.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_014_xx.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,450 @@
     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 014.xx
    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 "TestMessage.h"
    1.25 +#include "step_014_xx.h"
    1.26 +
    1.27 +#include <comms-infras/commsdebugutility.h>
    1.28 +
    1.29 +
    1.30 +/**
    1.31 +* Function  Name	: CFloggerTest005_02
    1.32 +* Input parameters	: None
    1.33 +* Output parameters : None
    1.34 +* Description		: This is the constructor
    1.35 +*/
    1.36 +
    1.37 +
    1.38 +CFloggerTest014_01::CFloggerTest014_01()
    1.39 +	{
    1.40 +	// store the name of this test case
    1.41 +	SetTestStepName(_L("step_014_01"));
    1.42 +	}
    1.43 +
    1.44 +
    1.45 +/**
    1.46 +* Function  Name	:~ CFloggerTest014_01
    1.47 +* Input parameters	: None
    1.48 +* Output parameters : None
    1.49 +* Description		: This is the Destructor
    1.50 +*/
    1.51 +
    1.52 +
    1.53 +CFloggerTest014_01::~CFloggerTest014_01()
    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 014_01 has 
    1.63 +* 					  passed or failed
    1.64 +
    1.65 +*/
    1.66 +
    1.67 +
    1.68 +TVerdict CFloggerTest014_01::doTestStepL( )
    1.69 +	{
    1.70 +	INFO_PRINTF1(_L("Step 011.01 called "));
    1.71 +	
    1.72 +	if ( executeStepL(EFalse) == KErrNone )
    1.73 +		SetTestStepResult(EPass);
    1.74 +
    1.75 +	else
    1.76 +		SetTestStepResult(EFail);
    1.77 +
    1.78 +	
    1.79 +	User::After(KTimeForDisplay1);
    1.80 +	return TestStepResult();
    1.81 +	}
    1.82 +
    1.83 +/**
    1.84 +* Function  Name		: executeStepL
    1.85 +* Input parameters		: None
    1.86 +* Output parameters		: TInt 
    1.87 +* Description 			: This function writes the test data in to the log file 
    1.88 +* 						  This function check the test message is present in the 
    1.89 +* 						  log file 
    1.90 +
    1.91 +*/
    1.92 +
    1.93 +
    1.94 +TInt CFloggerTest014_01::executeStepL()
    1.95 +	{
    1.96 +	return KErrGeneral;
    1.97 +	}
    1.98 +
    1.99 +/**
   1.100 +* Function  Name		: executeStepL
   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 +* 						  This function check the test message is present in the 
   1.105 +* 						  log file 
   1.106 +
   1.107 +*/
   1.108 +
   1.109 +
   1.110 +TInt CFloggerTest014_01::executeStepL(TBool heapTest)
   1.111 +	{
   1.112 +	TInt ret = KErrGeneral;
   1.113 +		
   1.114 +	ret = DoTestWrite();
   1.115 +	if (ret == KErrNone )
   1.116 +		{
   1.117 +		User::After(KTimeToLog);
   1.118 +		TRAPD(r, ret = DoTestCheckWriteL() );
   1.119 +		if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
   1.120 +			{
   1.121 +			ret = KErrNoMemory;
   1.122 +			}
   1.123 +		else if (r != KErrNone)
   1.124 +			{
   1.125 +			ret = r;
   1.126 +			}
   1.127 +		}
   1.128 +	return ret;
   1.129 +	}
   1.130 +
   1.131 +
   1.132 +/**
   1.133 +* Function  Name		: DoTestWrite
   1.134 +* Input parameters		: None
   1.135 +* Output parameters		: TInt 
   1.136 +* Description 			: This function writes the data to the file logger
   1.137 + 
   1.138 +*/
   1.139 +
   1.140 +
   1.141 +TInt CFloggerTest014_01::DoTestWrite()
   1.142 +	{
   1.143 +	_LIT8(KTestMessage,"TC 14.01 :This is test msg"); //8 bit test decriptor
   1.144 +	
   1.145 +	//test step
   1.146 +	RFileLogger ::Write(KStdSubsysTag8, KStdCompTag8, KTestMessage);
   1.147 +
   1.148 +	// connect so we can flush file buffer for heap check since timer is killed in heap checks
   1.149 +	RFileLogger theFlogger;
   1.150 +	theFlogger.Connect();
   1.151 +	theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
   1.152 +	ForceLogFlush(theFlogger);
   1.153 +	theFlogger.Close();
   1.154 +
   1.155 +
   1.156 +	return KErrNone; 
   1.157 +	}
   1.158 +
   1.159 +
   1.160 +/**
   1.161 +* Function  Name		: DoTestCheckWriteL
   1.162 +* Input parameters		: None
   1.163 +* Output parameters		: TInt 
   1.164 +* Description 			: This function checks the weather test data was written
   1.165 +* 						  in to the log file by DoTestWrite() or not.
   1.166 +					  
   1.167 +*/
   1.168 +
   1.169 +
   1.170 +TInt CFloggerTest014_01::DoTestCheckWriteL()
   1.171 +	{
   1.172 +	User::After(KTimeToLog);
   1.173 +
   1.174 +	RFile theFile;
   1.175 +	HBufC8 * hBuffer;
   1.176 +	TInt listfilesize;
   1.177 +	TInt returnCode;
   1.178 +	RFs fileSystem; //For file operation create a file system
   1.179 +	TBuf8<256> testData; //To hold the test descriptor
   1.180 +	_LIT(KLogFile, "c:\\logs\\log.txt"); // log file name and path
   1.181 +	
   1.182 +
   1.183 +	_LIT8(KTestMessage,"TC 14.01 :This is test msg"); //8 bit test decriptor
   1.184 +
   1.185 +	User::LeaveIfError(fileSystem.Connect());
   1.186 +	
   1.187 +	//Open the file in the read mode
   1.188 +	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   1.189 +
   1.190 +	
   1.191 +	returnCode = theFile.Size(listfilesize); //Size of the file
   1.192 +	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   1.193 +	CleanupStack::PushL(hBuffer);
   1.194 +	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   1.195 +
   1.196 +	// Read from position 0: start of file
   1.197 +	returnCode = theFile.Read(ptrString);
   1.198 +	
   1.199 +	testData.Copy(KTestMessage); //Copy the test descriptor
   1.200 +	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   1.201 +									//from the file
   1.202 +
   1.203 +	theFile.Close();
   1.204 +	fileSystem.Close();
   1.205 +	CleanupStack::PopAndDestroy(hBuffer);
   1.206 +	if (returnCode > 0)
   1.207 +		return KErrNone;
   1.208 +	else 
   1.209 +		return KErrNotFound;
   1.210 +	}
   1.211 +
   1.212 +
   1.213 +
   1.214 +
   1.215 +
   1.216 +
   1.217 +/**
   1.218 +* Function  Name	: CFloggerTest014_02
   1.219 +* Input parameters	: None
   1.220 +* Output parameters : None
   1.221 +* Description		: This is the constructor
   1.222 +*/
   1.223 +
   1.224 +
   1.225 +CFloggerTest014_02::CFloggerTest014_02()
   1.226 +	{
   1.227 +	// store the name of this test case
   1.228 +	SetTestStepName(_L("step_014_02"));
   1.229 +	}
   1.230 +
   1.231 +
   1.232 +/**
   1.233 +* Function  Name	:~ CFloggerTest014_02
   1.234 +* Input parameters	: None
   1.235 +* Output parameters : None
   1.236 +* Description		: This is the Destructor
   1.237 +*/
   1.238 +
   1.239 +
   1.240 +CFloggerTest014_02::~CFloggerTest014_02()
   1.241 +	{
   1.242 +	}
   1.243 +
   1.244 +
   1.245 +/**
   1.246 +* Function  Name	: doTestStepL
   1.247 +* Input parameters	: None
   1.248 +* Output parameters : TVerdict 
   1.249 +* Description		: This function returns weather the test case 014_02 has 
   1.250 +* 					  passed or failed
   1.251 +
   1.252 +*/
   1.253 +
   1.254 +
   1.255 +TVerdict CFloggerTest014_02::doTestStepL( )
   1.256 +	{
   1.257 +	INFO_PRINTF1(_L("Step 014.02 called "));
   1.258 +	
   1.259 +	if ( executeStepL() == KErrNone )
   1.260 +		SetTestStepResult(EPass);
   1.261 +
   1.262 +	else
   1.263 +		SetTestStepResult(EFail);
   1.264 +
   1.265 +	
   1.266 +	User::After(KTimeForDisplay1);
   1.267 +	return TestStepResult();
   1.268 +	}
   1.269 +
   1.270 +
   1.271 +/**
   1.272 +* Function  Name		: executeStepL
   1.273 +* Input parameters		: None
   1.274 +* Output parameters		: TInt 
   1.275 +* Description 			: This function writes the test data in to the log file 
   1.276 +* 						  This function check the test message is present in the 
   1.277 +* 						  log file 
   1.278 +
   1.279 +*/
   1.280 +
   1.281 +
   1.282 +TInt CFloggerTest014_02::executeStepL()
   1.283 +	{
   1.284 +	User::After(1000*1000);
   1.285 +	
   1.286 +	TInt ret = KErrGeneral;
   1.287 +		
   1.288 +	ret = DoTestWrite();
   1.289 +	if (ret == KErrNone )
   1.290 +		{
   1.291 +		TRAPD(r, ret = DoTestCheckWriteL());
   1.292 +		if ( r != KErrNone)
   1.293 +			ret = r;
   1.294 +		}
   1.295 +	return ret;
   1.296 +	}
   1.297 +
   1.298 +/**
   1.299 +* Function  Name		: executeStepL
   1.300 +* Input parameters		: None
   1.301 +* Output parameters		: TInt 
   1.302 +* Description 			: This function writes the test data in to the log file 
   1.303 +* 						  This function check the test message is present in the 
   1.304 +* 						  log file 
   1.305 +
   1.306 +*/
   1.307 +
   1.308 +
   1.309 +TInt CFloggerTest014_02::executeStepL(TBool)
   1.310 +	{
   1.311 +	return KErrGeneral;
   1.312 +	}	
   1.313 +
   1.314 +/**
   1.315 +* Function  Name		: DoTestWrite
   1.316 +* Input parameters		: None
   1.317 +* Output parameters		: TInt 
   1.318 +* Description 			: This function writes the data to the file logger
   1.319 + 
   1.320 +*/
   1.321 +
   1.322 +
   1.323 +TInt CFloggerTest014_02::DoTestWrite()
   1.324 +	{
   1.325 +	_LIT8(KTestLongMessage,"TEST 14.2: 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"); //8 bit test decriptor
   1.326 +
   1.327 +	TInt ret;
   1.328 +
   1.329 +	RFileLogger theFlogger;
   1.330 +
   1.331 +	theFlogger.Connect(); //Just to clear the old log message
   1.332 +	ret = theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
   1.333 +	theFlogger.ClearLog();
   1.334 +	theFlogger.Close();
   1.335 +	User::After(100000);
   1.336 +	
   1.337 +	RFileLogger ::Write(KStdSubsysTag8, KStdCompTag8, KTestLongMessage);
   1.338 +	return ret;
   1.339 +	}
   1.340 +
   1.341 +
   1.342 +/**
   1.343 +* Function  Name		: DoTestCheckWriteL
   1.344 +* Input parameters		: None
   1.345 +* Output parameters		: TInt 
   1.346 +* Description 			: This function checks the weather test data was written
   1.347 +* 						  in to the log file by DoTestWrite() or not.
   1.348 +					  
   1.349 +*/
   1.350 +
   1.351 +
   1.352 +TInt CFloggerTest014_02::DoTestCheckWriteL()
   1.353 +	{
   1.354 +	User::After(KTimeToLog);
   1.355 +
   1.356 +	RFile theFile;
   1.357 +	HBufC8 * hBuffer;
   1.358 +	TInt listfilesize,returnCode;
   1.359 +	RFs fileSystem; //For file operation create a file system
   1.360 +	TBuf8<256> testData; //To hold the test descriptor
   1.361 +	_LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
   1.362 +
   1.363 +	//The following contains the string of length 200(max) 
   1.364 +	//which is  written to the log file
   1.365 +	//_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");
   1.366 +	_LIT(KTestLongMessage, "TEST 14.2: 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 lo");
   1.367 +	
   1.368 +	//_LIT8(KOOMError, "#Logs may be lost out of memory!!");
   1.369 +	
   1.370 +	User::LeaveIfError(fileSystem.Connect());
   1.371 +	
   1.372 +	//Open the file in the read mode
   1.373 +	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   1.374 +
   1.375 +	CleanupClosePushL(theFile);
   1.376 +
   1.377 +	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   1.378 +	
   1.379 +	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   1.380 +	CleanupStack::PushL(hBuffer);
   1.381 +
   1.382 +	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   1.383 +
   1.384 +	// Read from position 0: start of file
   1.385 +	User::LeaveIfError(returnCode = theFile.Read(ptrString));
   1.386 +	
   1.387 +	testData.Copy(KTestLongMessage); //Copy the test descriptor
   1.388 +	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   1.389 +											//from the file
   1.390 +
   1.391 +	
   1.392 +	CleanupStack::PopAndDestroy(hBuffer);
   1.393 +	CleanupStack::PopAndDestroy();	//theFile
   1.394 +	if (returnCode > 0)
   1.395 +		return KErrNone;
   1.396 +	else 
   1.397 +		return KErrGeneral;
   1.398 +	}
   1.399 +
   1.400 +
   1.401 +
   1.402 +/**
   1.403 +* Function  Name	: CFloggerTest014_03
   1.404 +* Input parameters	: None
   1.405 +* Output parameters : None
   1.406 +* Description		: This is the constructor
   1.407 +*/ 
   1.408 +
   1.409 +
   1.410 +CFloggerTest014_03::CFloggerTest014_03()
   1.411 +	{
   1.412 +	// store the name of this test case
   1.413 +	SetTestStepName(_L("step_014_03"));
   1.414 +	}
   1.415 +
   1.416 +
   1.417 +/**
   1.418 +* Function  Name	:~ CFloggerTest014_03
   1.419 +* Input parameters	: None
   1.420 +* Output parameters : None
   1.421 +* Description		: This is the Destructor
   1.422 +*/
   1.423 +
   1.424 +
   1.425 +CFloggerTest014_03::~CFloggerTest014_03()
   1.426 +	{
   1.427 +	}
   1.428 +
   1.429 +
   1.430 +/**
   1.431 +* Function  Name : doTestStepL
   1.432 +* Input parameters : None
   1.433 +* Output parameters : TVerdict 
   1.434 +* Description : This function is responsible for doing the heap test analysis 
   1.435 +
   1.436 +*/
   1.437 +
   1.438 +
   1.439 +TVerdict CFloggerTest014_03::doTestStepL( )
   1.440 +	{
   1.441 +	INFO_PRINTF1(_L("Step 014.03 called "));
   1.442 +
   1.443 +	CFloggerTest014_01* step014_01 = new CFloggerTest014_01;
   1.444 +	CleanupStack::PushL(step014_01);
   1.445 +	doTestStepWithHeapFailureL( *step014_01, 1, 20, KErrNone, ETrue);
   1.446 +
   1.447 +	CleanupStack::PopAndDestroy(step014_01);
   1.448 +	User::After(KTimeForDisplay);
   1.449 +	return TestStepResult();
   1.450 +
   1.451 +
   1.452 +	}
   1.453 +