os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_007_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_007_xx.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,514 @@
     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 007.xx
    1.18 +
    1.19 +// EPOC includes
    1.20 +#include <e32base.h>
    1.21 +
    1.22 +// Test system includes
    1.23 +#include <comms-infras/commsdebugutility.h>
    1.24 +#include <f32file.h>
    1.25 +
    1.26 +
    1.27 +//User includes
    1.28 +#include "teststepcomsdbg.h"
    1.29 +#include "step_007_xx.h"
    1.30 +
    1.31 +
    1.32 +/**
    1.33 +* Function  Name	: CFloggerTest007_01
    1.34 +* Input parameters	: None
    1.35 +* Output parameters : None
    1.36 +* Description		: This is the constructor
    1.37 +*/
    1.38 +
    1.39 +CFloggerTest007_01::CFloggerTest007_01()
    1.40 +	{
    1.41 +	// store the name of this test case
    1.42 +	SetTestStepName(_L("step_007_01"));
    1.43 +	
    1.44 +	}
    1.45 +	
    1.46 +
    1.47 +/**
    1.48 +* Function  Name	:~ CFloggerTest007_01
    1.49 +* Input parameters	: None
    1.50 +* Output parameters : None
    1.51 +* Description		: This is the Destructor
    1.52 +*/
    1.53 +
    1.54 +
    1.55 +CFloggerTest007_01::~CFloggerTest007_01()
    1.56 +	{
    1.57 +
    1.58 +	}
    1.59 +
    1.60 +
    1.61 +/**
    1.62 +* Function  Name	: doTestStepL
    1.63 +* Input parameters	: None
    1.64 +* Output parameters : TVerdict 
    1.65 +* Description		: This function returns weather the test case 007_01 has 
    1.66 +*					  passed or failed
    1.67 +*/
    1.68 +
    1.69 +
    1.70 +TVerdict CFloggerTest007_01::doTestStepL( )
    1.71 +	{
    1.72 +
    1.73 +	INFO_PRINTF1(_L("Step 007.01 called "));
    1.74 +	
    1.75 +	if ( executeStepL(EFalse) == KErrNone )
    1.76 +		SetTestStepResult(EPass);
    1.77 +
    1.78 +	else
    1.79 +		SetTestStepResult(EFail);
    1.80 +
    1.81 +	
    1.82 +	User::After(KTimeForDisplay);
    1.83 +	return TestStepResult();
    1.84 +	
    1.85 +	}
    1.86 +
    1.87 +/**
    1.88 +* Function  Name		: executeStepL
    1.89 +* Input parameters		: None
    1.90 +* Output parameters		: TInt 
    1.91 +* Description 			: This function writes the test data in to the log file 
    1.92 +*						  This function check the test message is present in the 
    1.93 +						  log file  or not.
    1.94 +
    1.95 +*/
    1.96 +
    1.97 +
    1.98 +TInt CFloggerTest007_01::executeStepL(TBool heapTest)
    1.99 +	{
   1.100 +	User::After(KTimeToLog);
   1.101 +	TInt ret = KErrGeneral;
   1.102 +	ret = DoTestConnect();
   1.103 +	if (ret == KErrNone)
   1.104 +		{
   1.105 +		ret = DoTestWrite() ;
   1.106 +		if ( ret == KErrNone)
   1.107 +			{
   1.108 +			TRAPD(r, ret = DoTestCheckWriteL() );
   1.109 +			if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
   1.110 +				{
   1.111 +				ret = KErrNoMemory;
   1.112 +				}
   1.113 +			else if (r != KErrNone)
   1.114 +				{
   1.115 +				ret = r;
   1.116 +				}
   1.117 +			}
   1.118 +		}
   1.119 +	iFlogger.Close();
   1.120 +
   1.121 +//	if (ret == KErrNone)
   1.122 +	return ret;
   1.123 +	}
   1.124 +
   1.125 +/**
   1.126 +* Function  Name		: executeStepL
   1.127 +* Input parameters		: None
   1.128 +* Output parameters		: TInt 
   1.129 +* Description 			: This function writes the test data in to the log file 
   1.130 +*						  This function check the test message is present in the 
   1.131 +						  log file  or not.
   1.132 +
   1.133 +*/
   1.134 +
   1.135 +
   1.136 +TInt CFloggerTest007_01::executeStepL()
   1.137 +	{
   1.138 +	return KErrGeneral;
   1.139 +	}
   1.140 +
   1.141 +
   1.142 +/******************************************************************
   1.143 +* Function  Name		: DoTestWrite
   1.144 +* Input parameters		: None
   1.145 +* Output parameters		: TInt 
   1.146 +* Description 			: This function writes the data to the file logger
   1.147 +*
   1.148 +*/
   1.149 +
   1.150 +
   1.151 +TInt CFloggerTest007_01::DoTestWrite()
   1.152 +	{	
   1.153 +	_LIT8(KTestMessage,"TC 7_01: Just for compalation"); //8 bit test decriptor
   1.154 +	iFlogger.Write(KTestMessage); //Writes a 8 bit test descriptor
   1.155 +	
   1.156 +	ForceLogFlush(iFlogger);
   1.157 +	return KErrNone; 
   1.158 +	}
   1.159 +
   1.160 +
   1.161 +
   1.162 +/******************************************************************
   1.163 +* Function  Name		: DoTestCheckWriteL
   1.164 +* Input parameters		: None
   1.165 +* Output parameters		: TInt 
   1.166 +* Description 			: This function checks the weather test data was written
   1.167 +*						  in to the log file by DoTestWriteL() or not.
   1.168 +					  
   1.169 +*/
   1.170 +
   1.171 +
   1.172 +TInt CFloggerTest007_01::DoTestCheckWriteL()
   1.173 +	{
   1.174 +	User::After(KTimeToLog);
   1.175 +	RFile theFile;
   1.176 +	HBufC8 * hBuffer;
   1.177 +	TInt listfilesize;
   1.178 +	TInt returnCode;
   1.179 +	RFs fileSystem; //For file operation create a file system	
   1.180 +	TBuf8<256> testData; //To hold the test descriptor
   1.181 +	_LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
   1.182 +
   1.183 +	_LIT8(KTestMessage,"TC 7_01: Just for compalation"); //8 bit test decriptor
   1.184 +
   1.185 +	_LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message
   1.186 +
   1.187 +	User::LeaveIfError(fileSystem.Connect()); //connect to file server
   1.188 +	
   1.189 +	//Open the file in the read mode
   1.190 +	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
   1.191 +
   1.192 +	CleanupClosePushL(theFile);
   1.193 +
   1.194 +	returnCode = theFile.Size(listfilesize); //Size of the file
   1.195 +	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   1.196 +	CleanupStack::PushL(hBuffer);
   1.197 +	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   1.198 +
   1.199 +	// Read from position 0: start of file
   1.200 +	returnCode = theFile.Read(ptrString);
   1.201 +	
   1.202 +	testData.Copy(KTestMessage); //Copy the test descriptor
   1.203 +	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   1.204 +									//from the file
   1.205 +
   1.206 +	if (returnCode == KErrNotFound)  //Find the error message
   1.207 +		{
   1.208 +		returnCode = ptrString.Find(KOOMError);
   1.209 +		if (returnCode > 0)
   1.210 +			User::Leave(KErrNoMemory);
   1.211 +		}
   1.212 +
   1.213 +	
   1.214 +	CleanupStack::PopAndDestroy(hBuffer);
   1.215 +	CleanupStack::PopAndDestroy(); // For theFile object
   1.216 +	if (returnCode > 0)
   1.217 +		return KErrNone;
   1.218 +	else 
   1.219 +		return KErrNoMemory;
   1.220 +	}
   1.221 +
   1.222 +
   1.223 +
   1.224 +/**
   1.225 +* Function  Name		: DoTestConnect
   1.226 +* Input parameters		: None
   1.227 +* Output parameters		: TInt 
   1.228 +* Description 			: This function establishes a connection to file logger
   1.229 +* 						  and sets the system and component name in file logger.
   1.230 +					  
   1.231 +*/
   1.232 +
   1.233 +
   1.234 +TInt CFloggerTest007_01::DoTestConnect()
   1.235 +	{
   1.236 +	TInt ret;
   1.237 +	TPtrC8 ptrSubSystem;
   1.238 +	TPtrC8 ptrComponent;
   1.239 +	ptrSubSystem.Set(_L8("SubSystem"));
   1.240 +	ptrComponent.Set(_L8("Component"));
   1.241 +
   1.242 +	ret = iFlogger.Connect(); //Call connect() of Flogger
   1.243 +	if (ret == KErrNone)
   1.244 +		ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
   1.245 +
   1.246 +//	if (ret == KErrNone)
   1.247 +//		ret = iFlogger.ClearLog(); //clear the contents from the log
   1.248 +	return ret;
   1.249 +	}
   1.250 +
   1.251 +
   1.252 +
   1.253 +
   1.254 +
   1.255 +/**
   1.256 +* Function  Name	: CFloggerTest007_02
   1.257 +* Input parameters	: None
   1.258 +* Output parameters : None
   1.259 +* Description		: This is the constructor
   1.260 +*/
   1.261 +
   1.262 +
   1.263 +CFloggerTest007_02::CFloggerTest007_02()
   1.264 +	{
   1.265 +	// store the name of this test case
   1.266 +	SetTestStepName(_L("step_007_02"));
   1.267 +	}
   1.268 +
   1.269 +
   1.270 +/**
   1.271 +* Function  Name	:~ CFloggerTest007_02
   1.272 +* Input parameters	: None
   1.273 +* Output parameters : None
   1.274 +* Description		: This is the Destructor
   1.275 +*/
   1.276 +
   1.277 +
   1.278 +CFloggerTest007_02::~CFloggerTest007_02()
   1.279 +	{
   1.280 +	}
   1.281 +
   1.282 +
   1.283 +/**
   1.284 +* Function  Name	: doTestStepL
   1.285 +* Input parameters	: None
   1.286 +* Output parameters : TVerdict 
   1.287 +* Description		: This function returns weather the test case 007_02 has 
   1.288 +* 					  passed or failed
   1.289 +
   1.290 +*/
   1.291 +
   1.292 +
   1.293 +TVerdict CFloggerTest007_02::doTestStepL( )
   1.294 +	{
   1.295 +	INFO_PRINTF1(_L("Step 007.02 called "));
   1.296 +		
   1.297 +	if ( executeStepL() == KErrNone )
   1.298 +		SetTestStepResult(EPass);
   1.299 +
   1.300 +	else
   1.301 +		SetTestStepResult(EFail);
   1.302 +
   1.303 +	
   1.304 +	User::After(KTimeForDisplay);
   1.305 +	return TestStepResult();
   1.306 +	}
   1.307 +
   1.308 +
   1.309 +
   1.310 +/**
   1.311 +* Function  Name		: executeStepL
   1.312 +* Input parameters		: None
   1.313 +* Output parameters		: TInt 
   1.314 +* Description 			: This function writes the test data in to the log file 
   1.315 +* 						  This function check the test message is present in the 
   1.316 +* 						  log file 
   1.317 +
   1.318 +*/
   1.319 +
   1.320 +
   1.321 +TInt CFloggerTest007_02::executeStepL()
   1.322 +	{
   1.323 +	TInt ret = KErrGeneral;
   1.324 +	
   1.325 +	ret = DoTestConnect();
   1.326 +	CleanupClosePushL(iFlogger);
   1.327 +	if (ret == KErrNone)
   1.328 +		ret = DoTestWrite();
   1.329 +		if (ret == KErrNone)
   1.330 +			ret = DoTestCheckWriteL();
   1.331 +	
   1.332 +	CleanupStack::PopAndDestroy();	//logger
   1.333 +	User::After(1000000);
   1.334 +	return ret;
   1.335 +	}
   1.336 +
   1.337 +/**
   1.338 +* Function  Name		: executeStepL
   1.339 +* Input parameters		: None
   1.340 +* Output parameters		: TInt 
   1.341 +* Description 			: This function writes the test data in to the log file 
   1.342 +* 						  This function check the test message is present in the 
   1.343 +* 						  log file 
   1.344 +
   1.345 +*/
   1.346 +
   1.347 +
   1.348 +TInt CFloggerTest007_02::executeStepL(TBool)
   1.349 +	{
   1.350 +	return KErrGeneral;
   1.351 +	}
   1.352 +
   1.353 +/**
   1.354 +* Function  Name		: DoTestConnect
   1.355 +* Input parameters		: None
   1.356 +* Output parameters		: TInt 
   1.357 +* Description 			: This function establishes a connection to file logger
   1.358 +* 						  and sets the system and component name in file logger.
   1.359 +					  
   1.360 +*/
   1.361 +
   1.362 +
   1.363 +TInt CFloggerTest007_02::DoTestConnect()
   1.364 +	{
   1.365 +	TInt ret;
   1.366 +	TPtrC8 ptrSubSystem;
   1.367 +	TPtrC8 ptrComponent;
   1.368 +	ptrSubSystem.Set(_L8("SubSystem"));
   1.369 +	ptrComponent.Set(_L8("Component"));
   1.370 +
   1.371 +	ret = iFlogger.Connect(); //Call connect() of Flogger
   1.372 +	if (ret == KErrNone)
   1.373 +		ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
   1.374 +
   1.375 +	if (ret == KErrNone)
   1.376 +		ret = iFlogger.ClearLog(); //clear the contents from the log
   1.377 +
   1.378 +	return ret;
   1.379 +	}
   1.380 +
   1.381 +
   1.382 +/**
   1.383 +* Function  Name		: DoTestWrite
   1.384 +* Input parameters		: None
   1.385 +* Output parameters		: TInt 
   1.386 +* Description 			: This function writes the data to the file logger
   1.387 + 
   1.388 +*/
   1.389 +
   1.390 +
   1.391 +TInt CFloggerTest007_02::DoTestWrite()
   1.392 +	{
   1.393 +	//KTestLongMessage contains a very long test message 
   1.394 +	_LIT(KTestLongMessage,"TC 7_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");
   1.395 +	iFlogger.Write(KTestLongMessage); 		
   1.396 +	ForceLogFlush(iFlogger);	
   1.397 +	return KErrNone; 
   1.398 +	}
   1.399 +
   1.400 +
   1.401 +/**
   1.402 +* Function  Name		: DoTestCheckWriteL
   1.403 +* Input parameters		: None
   1.404 +* Output parameters		: TInt 
   1.405 +* Description 			: This function checks the weather test data was written
   1.406 +*						  in to the log file by DoTestWriteL() or not.
   1.407 +					  
   1.408 +*/
   1.409 +
   1.410 +
   1.411 +TInt CFloggerTest007_02::DoTestCheckWriteL()
   1.412 +	{
   1.413 +	User::After(KTimeToLog);
   1.414 +	RFile theFile;
   1.415 +	HBufC8 * hBuffer;
   1.416 +	TInt listfilesize,returnCode;
   1.417 +	RFs fileSystem; //For file operation create a file system
   1.418 +	TBuf8<256> testData; //To hold the test descriptor
   1.419 +	_LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
   1.420 +
   1.421 +	//The following contains the string of length 200(max) 
   1.422 +	//which is  written to the log file
   1.423 +	//_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.424 +	_LIT(KTestLongMessage, "TC 7_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");
   1.425 +	
   1.426 +	//_LIT8(KOOMError, "#Logs may be lost out of memory!!");
   1.427 +	
   1.428 +	User::LeaveIfError(fileSystem.Connect());
   1.429 +	
   1.430 +	//Open the file in the read mode
   1.431 +	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   1.432 +
   1.433 +	CleanupClosePushL(theFile);
   1.434 +
   1.435 +	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   1.436 +	
   1.437 +	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   1.438 +	CleanupStack::PushL(hBuffer);
   1.439 +
   1.440 +	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   1.441 +
   1.442 +	// Read from position 0: start of file
   1.443 +	User::LeaveIfError(returnCode = theFile.Read(ptrString));
   1.444 +	
   1.445 +	testData.Copy(KTestLongMessage); //Copy the test descriptor
   1.446 +	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   1.447 +											//from the file
   1.448 +
   1.449 +	
   1.450 +	CleanupStack::PopAndDestroy(hBuffer);
   1.451 +	CleanupStack::PopAndDestroy();	//theFile
   1.452 +	if (returnCode > 0)
   1.453 +		return KErrNone;
   1.454 +	else 
   1.455 +		return KErrGeneral;
   1.456 +	
   1.457 +
   1.458 +}
   1.459 +
   1.460 +
   1.461 +
   1.462 +
   1.463 +
   1.464 +
   1.465 +/**
   1.466 +* Function  Name	: CFloggerTest007_03
   1.467 +* Input parameters	: None
   1.468 +* Output parameters : None
   1.469 +* Description		: This is the constructor
   1.470 +*/
   1.471 +
   1.472 +
   1.473 +CFloggerTest007_03::CFloggerTest007_03()
   1.474 +	{
   1.475 +	// store the name of this test case
   1.476 +	SetTestStepName(_L("step_007_03"));
   1.477 +	}
   1.478 +
   1.479 +
   1.480 +
   1.481 +/**
   1.482 +* Function  Name	:~ CFloggerTest007_03
   1.483 +* Input parameters	: None
   1.484 +* Output parameters : None
   1.485 +* Description		: This is the Destructor
   1.486 +*/
   1.487 +
   1.488 +
   1.489 +
   1.490 +CFloggerTest007_03::~CFloggerTest007_03()
   1.491 +	{
   1.492 +	}
   1.493 +
   1.494 +
   1.495 +
   1.496 +/**
   1.497 +* Function  Name : doTestStepL
   1.498 +* Input parameters : None
   1.499 +* Output parameters : TVerdict 
   1.500 +* Description : This function is responsible for doing the heap test analysis 
   1.501 +
   1.502 +*/
   1.503 +
   1.504 +
   1.505 +TVerdict CFloggerTest007_03::doTestStepL( )
   1.506 +	{
   1.507 +	INFO_PRINTF1(_L("Step 007.03 called "));
   1.508 +
   1.509 +	CFloggerTest007_01* step007_01 = new CFloggerTest007_01;
   1.510 +	CleanupStack::PushL(step007_01);
   1.511 +	doTestStepWithHeapFailureL( *step007_01, 1, 20, KErrNone, ETrue);
   1.512 +
   1.513 +	CleanupStack::PopAndDestroy(step007_01);
   1.514 +	User::After(KTimeForDisplay);
   1.515 +	return TestStepResult();
   1.516 +	}
   1.517 +