os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_026_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_026_xx.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,499 @@
     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 026.xx
    1.18 +
    1.19 +// EPOC includes
    1.20 +#include <e32base.h>
    1.21 +
    1.22 +
    1.23 +// Test system includes
    1.24 +#include "teststepcomsdbg.h"
    1.25 +#include "step_026_xx.h"
    1.26 +
    1.27 +#include <comms-infras/commsdebugutility.h>
    1.28 +
    1.29 +
    1.30 +/**
    1.31 +* Function  Name : CFloggerTest026_01
    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 +CFloggerTest026_01::CFloggerTest026_01()
    1.39 +	{
    1.40 +	// Store the name of this test case
    1.41 +	SetTestStepName(_L("step_026_01"));
    1.42 +	}
    1.43 +
    1.44 +
    1.45 +/**
    1.46 +* Function  Name :~ CFloggerTest026_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 +CFloggerTest026_01::~CFloggerTest026_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 026_01 has 
    1.63 +* 					  passed or failed
    1.64 +
    1.65 +*/
    1.66 +
    1.67 +
    1.68 +TVerdict CFloggerTest026_01::doTestStepL( )
    1.69 +	{
    1.70 +	INFO_PRINTF1(_L("Step 026.01 called "));
    1.71 +	User::After(KTimeForDisplay);
    1.72 +
    1.73 +
    1.74 +	if ( executeStepL(EFalse) == KErrNone  )
    1.75 +		SetTestStepResult(EPass);
    1.76 +
    1.77 +	else
    1.78 +		SetTestStepResult(EFail);
    1.79 +
    1.80 +	INFO_PRINTF1(_L("leaving Step 026.01 "));
    1.81 +	User::After(KTimeForDisplay);
    1.82 +
    1.83 +	
    1.84 +	return TestStepResult();
    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 sets the subsystem and component name
    1.92 +* 						  checks weather they are set in the log file correctly
    1.93 +
    1.94 +*/
    1.95 +
    1.96 +
    1.97 +TInt CFloggerTest026_01::executeStepL()
    1.98 +	{
    1.99 +	return KErrGeneral;
   1.100 +	}
   1.101 +/**
   1.102 +* Function  Name		: executeStepL
   1.103 +* Input parameters		: None
   1.104 +* Output parameters		: TInt 
   1.105 +* Description 			: This function sets the subsystem and component name
   1.106 +* 						  checks weather they are set in the log file correctly
   1.107 +
   1.108 +*/
   1.109 +
   1.110 +
   1.111 +TInt CFloggerTest026_01::executeStepL(TBool heapTest)
   1.112 +	{
   1.113 +	return DoTestWrite(heapTest);
   1.114 +	}
   1.115 +
   1.116 +
   1.117 +/**
   1.118 +* Function  Name		: DoTestWriteL
   1.119 +* Input parameters		: None
   1.120 +* Output parameters		: TInt 
   1.121 +* Description 			: This function writes the data to the file logger
   1.122 +					  
   1.123 +*/
   1.124 +
   1.125 +
   1.126 +TInt CFloggerTest026_01::DoTestWrite(TBool heapTest)
   1.127 +	{
   1.128 +
   1.129 +	_LIT8(KTestMessage ,"TC no 26: This is test message");
   1.130 +	TPtrC8 ptrSubSystem;
   1.131 +	TPtrC8 ptrComponent;
   1.132 +	ptrSubSystem.Set(_L8("SubSystem"));
   1.133 +	ptrComponent.Set(_L8("Component"));
   1.134 +	
   1.135 +	TInt ret = KErrNone;
   1.136 +	RFileLogger theFlogger;
   1.137 +
   1.138 +	ret = theFlogger.Connect();
   1.139 +	
   1.140 +	if (ret == KErrNone)
   1.141 +		{
   1.142 +		ret = theFlogger.SetLogTags(ptrSubSystem, ptrComponent);
   1.143 +		if (ret == KErrNone)
   1.144 +			{
   1.145 +			ret = theFlogger.ClearLog();
   1.146 +			if (ret == KErrNone)
   1.147 +				{
   1.148 +				theFlogger.WriteBinary(KTestMessage);
   1.149 +				ForceLogFlush(theFlogger);
   1.150 +				TRAPD(r, ret = DoTestCheckWriteL());
   1.151 +				if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
   1.152 +					{
   1.153 +					ret = KErrNoMemory;
   1.154 +					}
   1.155 +				else if (r != KErrNone)
   1.156 +					{
   1.157 +					ret = r;
   1.158 +					}
   1.159 +				}
   1.160 +			}
   1.161 +		}
   1.162 +		
   1.163 +	theFlogger.Close();
   1.164 +	return ret;
   1.165 +
   1.166 +	}
   1.167 +
   1.168 +
   1.169 +/**
   1.170 +* Function  Name		: DoTestCheckWriteL
   1.171 +* Input parameters		: None
   1.172 +* Output parameters		: TInt 
   1.173 +* Description 			: This function checks the weather test data was written
   1.174 +* 						  in to the log file by DoTestWriteL() or not.
   1.175 +					  
   1.176 +*/
   1.177 +
   1.178 +
   1.179 +TInt CFloggerTest026_01::DoTestCheckWriteL()
   1.180 +	{
   1.181 +	User::After(1000*1000);
   1.182 +	RFile theFile;
   1.183 +	HBufC8 * hBuffer;
   1.184 +	TInt listfilesize,returnCode;
   1.185 +	RFs iFileSystem; //For file operation create a file system
   1.186 +	TBuf8<256> testData; //To hold the test descriptor
   1.187 +	_LIT(KLogFile,"c:\\logs\\log.txt"); 
   1.188 +
   1.189 +	_LIT(KTestSystem, "SubSystem"); //Test sytem name
   1.190 +	_LIT(KTestComponent, "Component"); //Test component name
   1.191 +	_LIT8(KTestMessage ,"TC no 26: This is test message"); // Test descriptor
   1.192 +
   1.193 +	_LIT8(KOOMError, "#Logs may be lost out of memory!!"); // Error message which has to be tested in log
   1.194 +
   1.195 +	User::LeaveIfError(iFileSystem.Connect());
   1.196 +	
   1.197 +	//Open the file in the read mode
   1.198 +	User::LeaveIfError(theFile.Open(iFileSystem, KLogFile, EFileWrite|EFileShareAny)); 
   1.199 +	CleanupClosePushL(theFile);
   1.200 +	
   1.201 +	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   1.202 +	
   1.203 +	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   1.204 +	CleanupStack::PushL(hBuffer);
   1.205 +	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   1.206 +
   1.207 +	// Read from position 0: start of file
   1.208 +	returnCode = theFile.Read(ptrString);
   1.209 +	
   1.210 +	testData.Copy(KTestMessage); //Copy the test message 
   1.211 +	returnCode = ptrString.Find(KTestMessage);	//find the test message  in the 
   1.212 +											//buffer read from the file
   1.213 +	if (returnCode == KErrNotFound)
   1.214 +		{
   1.215 +		returnCode = ptrString.Find(KOOMError);
   1.216 +		if (returnCode > 0)
   1.217 +			User::Leave(KErrNoMemory);
   1.218 +		}
   1.219 +
   1.220 +	if (returnCode > 0) // Test message present
   1.221 +		{
   1.222 +		testData.Copy(KTestSystem); //Copy the test tag
   1.223 +		returnCode = ptrString.Find(testData);	//Find the test tag in the 
   1.224 +												//buffer read from the file
   1.225 +		}
   1.226 +	if (returnCode > 0) // Test tag present
   1.227 +		{
   1.228 +		testData.Copy(KTestComponent); //Copy the test tag
   1.229 +		returnCode = ptrString.Find(testData);	//Find the test tag in the 
   1.230 +												//buffer read from the file
   1.231 +		}
   1.232 +	CleanupStack::PopAndDestroy(hBuffer);
   1.233 +	CleanupStack::PopAndDestroy();	//theFile
   1.234 +
   1.235 +	if (returnCode > 0) // Test tag present
   1.236 +		return KErrNone;
   1.237 +	else 
   1.238 +		return KErrNotFound;
   1.239 +	}
   1.240 +
   1.241 +
   1.242 +
   1.243 +
   1.244 +
   1.245 +/**
   1.246 +* Function  Name : CFloggerTest026_02
   1.247 +* Input parameters : None
   1.248 +* Output parameters : None
   1.249 +* Description : This is the constructor
   1.250 +*/
   1.251 +
   1.252 +
   1.253 +CFloggerTest026_02::CFloggerTest026_02()
   1.254 +	{
   1.255 +	// store the name of this test case
   1.256 +	SetTestStepName(_L("step_026_02"));
   1.257 +	}
   1.258 +
   1.259 +
   1.260 +/**
   1.261 +* Function  Name :~ CFloggerTest026_02
   1.262 +* Input parameters : None
   1.263 +* Output parameters : None
   1.264 +*Description : This is the Destructor
   1.265 +*/
   1.266 +
   1.267 +
   1.268 +CFloggerTest026_02::~CFloggerTest026_02()
   1.269 +	{
   1.270 +	}
   1.271 +
   1.272 +
   1.273 +/**
   1.274 +* Function  Name : doTestStepL
   1.275 +* Input parameters : None
   1.276 +* Output parameters : TVerdict 
   1.277 +* Description : This function is responsible for doing the heap test analysis 
   1.278 +
   1.279 +*/
   1.280 +
   1.281 +TVerdict CFloggerTest026_02::doTestStepL( )
   1.282 +	{
   1.283 +	INFO_PRINTF1(_L("Step 026.02 called "));
   1.284 +	User::After(KTimeForDisplay);
   1.285 +
   1.286 +	CFloggerTest026_01* step026_01 = new CFloggerTest026_01;
   1.287 +	CleanupStack::PushL(step026_01);
   1.288 +	doTestStepWithHeapFailureL( *step026_01, 1, 20, KErrNone, ETrue);
   1.289 +	
   1.290 +	CleanupStack::PopAndDestroy(step026_01);
   1.291 +
   1.292 +	return TestStepResult();
   1.293 +	}
   1.294 +
   1.295 +
   1.296 +/**
   1.297 +* Function  Name : CFloggerTest026_03
   1.298 +* Input parameters : None
   1.299 +* Output parameters : None
   1.300 +* Description : This is the constructor
   1.301 +*/
   1.302 +
   1.303 +
   1.304 +CFloggerTest026_03::CFloggerTest026_03()
   1.305 +	{
   1.306 +	// Store the name of this test case
   1.307 +	SetTestStepName(_L("step_026_03"));
   1.308 +	}
   1.309 +
   1.310 +
   1.311 +/**
   1.312 +* Function  Name :~ CFloggerTest026_03
   1.313 +* Input parameters : None
   1.314 +* Output parameters : None
   1.315 +* Description : This is the Destructor
   1.316 +*/ 
   1.317 +
   1.318 +
   1.319 +CFloggerTest026_03::~CFloggerTest026_03()
   1.320 +	{
   1.321 +	}
   1.322 +
   1.323 +
   1.324 +/**
   1.325 +* Function  Name	: doTestStepL
   1.326 +* Input parameters	: None
   1.327 +* Output parameters : TVerdict 
   1.328 +* Description		: This function returns weather the test case 026_01 has 
   1.329 +* 					  passed or failed
   1.330 +
   1.331 +*/
   1.332 +
   1.333 +
   1.334 +TVerdict CFloggerTest026_03::doTestStepL( )
   1.335 +	{
   1.336 +	INFO_PRINTF1(_L("Step 026.03 called "));
   1.337 +	User::After(KTimeForDisplay);
   1.338 +
   1.339 +
   1.340 +	if ( executeStepL() == KErrNone  )
   1.341 +		SetTestStepResult(EPass);
   1.342 +
   1.343 +	else
   1.344 +		SetTestStepResult(EFail);
   1.345 +
   1.346 +	INFO_PRINTF1(_L("leaving Step 026.03 "));
   1.347 +	User::After(KTimeForDisplay);
   1.348 +
   1.349 +	
   1.350 +	return TestStepResult();
   1.351 +	}
   1.352 +
   1.353 +
   1.354 +/**
   1.355 +* Function  Name		: executeStepL
   1.356 +* Input parameters		: None
   1.357 +* Output parameters		: TInt 
   1.358 +* Description 			: This function sets the subsystem and component name
   1.359 +* 						  checks weather they are set in the log file correctly
   1.360 +
   1.361 +*/
   1.362 +
   1.363 +
   1.364 +TInt CFloggerTest026_03::executeStepL()
   1.365 +	{
   1.366 +	return DoTestWrite();
   1.367 +	}
   1.368 +
   1.369 +/**
   1.370 +* Function  Name		: executeStepL
   1.371 +* Input parameters		: None
   1.372 +* Output parameters		: TInt 
   1.373 +* Description 			: This function sets the subsystem and component name
   1.374 +* 						  checks weather they are set in the log file correctly
   1.375 +
   1.376 +*/
   1.377 +
   1.378 +
   1.379 +TInt CFloggerTest026_03::executeStepL(TBool)
   1.380 +	{
   1.381 +	return KErrGeneral;
   1.382 +	}
   1.383 +
   1.384 +/**
   1.385 +* Function  Name		: DoTestWriteL
   1.386 +* Input parameters		: None
   1.387 +* Output parameters		: TInt 
   1.388 +* Description 			: This function writes the data to the file logger
   1.389 +					  
   1.390 +*/
   1.391 +
   1.392 +
   1.393 +TInt CFloggerTest026_03::DoTestWrite()
   1.394 +	{
   1.395 +
   1.396 +	_LIT8(KTestLongMessage,"TEST 26.3:#À!}!}!} }4}%}&´zß}}&} } } } }'}}(}!æ~.=¢ÛR.... .~ÿ}#À!}!}!} }4}%}&„¥T}9}}&}}'}}(}U­~... .~. -ÿ}#À!}}!} }4}%}&„¥T}9}}&} } } } }'}}(}¾Ä~)... .~. .ÿ}#À!}!}} }$µZ}'}}(}U­~... .~. -ÿ}#À!}}!} }4}%}&„¥T}9}}&} } } } }'}}(}¾Ä~... .~. .ÿ}#À!}!}$µZ"); //8 bit test decriptor
   1.397 +	TPtrC8 ptrSubSystem;
   1.398 +	TPtrC8 ptrComponent;
   1.399 +	ptrSubSystem.Set(_L8("SubSystem"));
   1.400 +	ptrComponent.Set(_L8("Component"));
   1.401 +	
   1.402 +	TInt ret = KErrNone;
   1.403 +	RFileLogger theFlogger;
   1.404 +
   1.405 +	ret = theFlogger.Connect();
   1.406 +
   1.407 +	if (ret == KErrNone)
   1.408 +		{
   1.409 +		ret = theFlogger.SetLogTags(ptrSubSystem, ptrComponent);
   1.410 +		if (ret == KErrNone)
   1.411 +			{
   1.412 +			ret = theFlogger.ClearLog();
   1.413 +			if (ret == KErrNone)
   1.414 +				{
   1.415 +				theFlogger.WriteBinary(KTestLongMessage);
   1.416 +//				ForceLogFlush(theFlogger);
   1.417 +				TRAPD(r, ret = DoTestCheckWriteL());
   1.418 +				if (r != KErrNone)
   1.419 +					ret = r;
   1.420 +				}
   1.421 +			}
   1.422 +		}
   1.423 +		
   1.424 +	theFlogger.Close();
   1.425 +
   1.426 +	return ret;
   1.427 +
   1.428 +	}
   1.429 +
   1.430 +
   1.431 +/**
   1.432 +* Function  Name		: DoTestCheckWriteL
   1.433 +* Input parameters		: None
   1.434 +* Output parameters		: TInt 
   1.435 +* Description 			: This function checks the weather test data was written
   1.436 +* 						  in to the log file by DoTestWriteL() or not.
   1.437 +					  
   1.438 +*/
   1.439 +
   1.440 +
   1.441 +TInt CFloggerTest026_03::DoTestCheckWriteL()
   1.442 +	{
   1.443 +	_LIT8(KTestLongMessage,"TEST 26.3:#À!}!}!} }4}%}&´zß}}&} } } } }'}}(}!æ~.=¢ÛR.... .~ÿ}#À!}!}!} }4}%}&„¥T}9}}&}}'}}(}U­~... .~. -ÿ}#À!}}!} }4}%}&„¥T}9}}&} } } } }'}}(}¾Ä~)... .~. .ÿ}#À!}!}} }$µZ}'}}(}U­~... .~. -ÿ}#À!}}!} }4}%}&„¥T}9}}&} } } } }'}}(}¾Ä~... .~. .ÿ}#À!}!}$µZ"); //8 bit test decriptor
   1.444 +	User::After(KTimeToLogLargeData);	// occasionally, KTimeToLog isn't quite long enough, so use longer time.
   1.445 +	RFile theFile;
   1.446 +	HBufC8 * hBuffer;
   1.447 +	TInt listfilesize,returnCode;
   1.448 +	RFs iFileSystem; //For file operation create a file system
   1.449 +	_LIT(KLogFile,"c:\\logs\\log.txt"); 
   1.450 +	TBuf8<256> testData; //To hold the test descriptor
   1.451 +
   1.452 +	_LIT(KTestSystem, "SubSystem"); //Test sytem name
   1.453 +	_LIT(KTestComponent, "Component"); //Test component name
   1.454 +	//_LIT8(KTestLongMessage,"TEST 26.3: 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.455 +	
   1.456 +	
   1.457 +	User::LeaveIfError(iFileSystem.Connect());
   1.458 +	
   1.459 +	//Open the file in the read mode
   1.460 +	User::LeaveIfError(theFile.Open(iFileSystem, KLogFile, EFileWrite|EFileShareAny)); 
   1.461 +	CleanupClosePushL(theFile);
   1.462 +	
   1.463 +	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   1.464 +	
   1.465 +	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   1.466 +	CleanupStack::PushL(hBuffer);
   1.467 +	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   1.468 +
   1.469 +	// Read from position 0: start of file
   1.470 +	returnCode = theFile.Read(ptrString);
   1.471 +	
   1.472 +	//testData.Copy(KTestLongMessage); //Copy the test message 
   1.473 +	returnCode = ptrString.Find(KTestLongMessage);	//find the test message in the 
   1.474 +											//buffer read from the file
   1.475 +
   1.476 +	if (returnCode > 0) // Test message present
   1.477 +		{
   1.478 +		testData.FillZ();
   1.479 +		testData.Copy(KTestSystem); //Copy the test tag
   1.480 +		returnCode = ptrString.Find(testData);	//Find the test tag in the 
   1.481 +												//buffer read from the file
   1.482 +		}
   1.483 +	if (returnCode > 0) // Test tag present
   1.484 +		{
   1.485 +		testData.FillZ();
   1.486 +		testData.Copy(KTestComponent); //Copy the component name
   1.487 +		returnCode = ptrString.Find(testData);	//Find the component name in the 
   1.488 +												//buffer read from the file
   1.489 +		}
   1.490 +	
   1.491 +	CleanupStack::PopAndDestroy(hBuffer);
   1.492 +	CleanupStack::PopAndDestroy();	//theFile
   1.493 +
   1.494 +	if (returnCode > 0) // Test tag present
   1.495 +		return KErrNone;
   1.496 +	else 
   1.497 +		return KErrGeneral;
   1.498 +	}
   1.499 +
   1.500 +
   1.501 +
   1.502 +