os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_007_xx.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // This contains Flogger Unit Test Case 007.xx
    15 
    16 // EPOC includes
    17 #include <e32base.h>
    18 
    19 // Test system includes
    20 #include <comms-infras/commsdebugutility.h>
    21 #include <f32file.h>
    22 
    23 
    24 //User includes
    25 #include "teststepcomsdbg.h"
    26 #include "step_007_xx.h"
    27 
    28 
    29 /**
    30 * Function  Name	: CFloggerTest007_01
    31 * Input parameters	: None
    32 * Output parameters : None
    33 * Description		: This is the constructor
    34 */
    35 
    36 CFloggerTest007_01::CFloggerTest007_01()
    37 	{
    38 	// store the name of this test case
    39 	SetTestStepName(_L("step_007_01"));
    40 	
    41 	}
    42 	
    43 
    44 /**
    45 * Function  Name	:~ CFloggerTest007_01
    46 * Input parameters	: None
    47 * Output parameters : None
    48 * Description		: This is the Destructor
    49 */
    50 
    51 
    52 CFloggerTest007_01::~CFloggerTest007_01()
    53 	{
    54 
    55 	}
    56 
    57 
    58 /**
    59 * Function  Name	: doTestStepL
    60 * Input parameters	: None
    61 * Output parameters : TVerdict 
    62 * Description		: This function returns weather the test case 007_01 has 
    63 *					  passed or failed
    64 */
    65 
    66 
    67 TVerdict CFloggerTest007_01::doTestStepL( )
    68 	{
    69 
    70 	INFO_PRINTF1(_L("Step 007.01 called "));
    71 	
    72 	if ( executeStepL(EFalse) == KErrNone )
    73 		SetTestStepResult(EPass);
    74 
    75 	else
    76 		SetTestStepResult(EFail);
    77 
    78 	
    79 	User::After(KTimeForDisplay);
    80 	return TestStepResult();
    81 	
    82 	}
    83 
    84 /**
    85 * Function  Name		: executeStepL
    86 * Input parameters		: None
    87 * Output parameters		: TInt 
    88 * Description 			: This function writes the test data in to the log file 
    89 *						  This function check the test message is present in the 
    90 						  log file  or not.
    91 
    92 */
    93 
    94 
    95 TInt CFloggerTest007_01::executeStepL(TBool heapTest)
    96 	{
    97 	User::After(KTimeToLog);
    98 	TInt ret = KErrGeneral;
    99 	ret = DoTestConnect();
   100 	if (ret == KErrNone)
   101 		{
   102 		ret = DoTestWrite() ;
   103 		if ( ret == KErrNone)
   104 			{
   105 			TRAPD(r, ret = DoTestCheckWriteL() );
   106 			if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
   107 				{
   108 				ret = KErrNoMemory;
   109 				}
   110 			else if (r != KErrNone)
   111 				{
   112 				ret = r;
   113 				}
   114 			}
   115 		}
   116 	iFlogger.Close();
   117 
   118 //	if (ret == KErrNone)
   119 	return ret;
   120 	}
   121 
   122 /**
   123 * Function  Name		: executeStepL
   124 * Input parameters		: None
   125 * Output parameters		: TInt 
   126 * Description 			: This function writes the test data in to the log file 
   127 *						  This function check the test message is present in the 
   128 						  log file  or not.
   129 
   130 */
   131 
   132 
   133 TInt CFloggerTest007_01::executeStepL()
   134 	{
   135 	return KErrGeneral;
   136 	}
   137 
   138 
   139 /******************************************************************
   140 * Function  Name		: DoTestWrite
   141 * Input parameters		: None
   142 * Output parameters		: TInt 
   143 * Description 			: This function writes the data to the file logger
   144 *
   145 */
   146 
   147 
   148 TInt CFloggerTest007_01::DoTestWrite()
   149 	{	
   150 	_LIT8(KTestMessage,"TC 7_01: Just for compalation"); //8 bit test decriptor
   151 	iFlogger.Write(KTestMessage); //Writes a 8 bit test descriptor
   152 	
   153 	ForceLogFlush(iFlogger);
   154 	return KErrNone; 
   155 	}
   156 
   157 
   158 
   159 /******************************************************************
   160 * Function  Name		: DoTestCheckWriteL
   161 * Input parameters		: None
   162 * Output parameters		: TInt 
   163 * Description 			: This function checks the weather test data was written
   164 *						  in to the log file by DoTestWriteL() or not.
   165 					  
   166 */
   167 
   168 
   169 TInt CFloggerTest007_01::DoTestCheckWriteL()
   170 	{
   171 	User::After(KTimeToLog);
   172 	RFile theFile;
   173 	HBufC8 * hBuffer;
   174 	TInt listfilesize;
   175 	TInt returnCode;
   176 	RFs fileSystem; //For file operation create a file system	
   177 	TBuf8<256> testData; //To hold the test descriptor
   178 	_LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
   179 
   180 	_LIT8(KTestMessage,"TC 7_01: Just for compalation"); //8 bit test decriptor
   181 
   182 	_LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message
   183 
   184 	User::LeaveIfError(fileSystem.Connect()); //connect to file server
   185 	
   186 	//Open the file in the read mode
   187 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
   188 
   189 	CleanupClosePushL(theFile);
   190 
   191 	returnCode = theFile.Size(listfilesize); //Size of the file
   192 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   193 	CleanupStack::PushL(hBuffer);
   194 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   195 
   196 	// Read from position 0: start of file
   197 	returnCode = theFile.Read(ptrString);
   198 	
   199 	testData.Copy(KTestMessage); //Copy the test descriptor
   200 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   201 									//from the file
   202 
   203 	if (returnCode == KErrNotFound)  //Find the error message
   204 		{
   205 		returnCode = ptrString.Find(KOOMError);
   206 		if (returnCode > 0)
   207 			User::Leave(KErrNoMemory);
   208 		}
   209 
   210 	
   211 	CleanupStack::PopAndDestroy(hBuffer);
   212 	CleanupStack::PopAndDestroy(); // For theFile object
   213 	if (returnCode > 0)
   214 		return KErrNone;
   215 	else 
   216 		return KErrNoMemory;
   217 	}
   218 
   219 
   220 
   221 /**
   222 * Function  Name		: DoTestConnect
   223 * Input parameters		: None
   224 * Output parameters		: TInt 
   225 * Description 			: This function establishes a connection to file logger
   226 * 						  and sets the system and component name in file logger.
   227 					  
   228 */
   229 
   230 
   231 TInt CFloggerTest007_01::DoTestConnect()
   232 	{
   233 	TInt ret;
   234 	TPtrC8 ptrSubSystem;
   235 	TPtrC8 ptrComponent;
   236 	ptrSubSystem.Set(_L8("SubSystem"));
   237 	ptrComponent.Set(_L8("Component"));
   238 
   239 	ret = iFlogger.Connect(); //Call connect() of Flogger
   240 	if (ret == KErrNone)
   241 		ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
   242 
   243 //	if (ret == KErrNone)
   244 //		ret = iFlogger.ClearLog(); //clear the contents from the log
   245 	return ret;
   246 	}
   247 
   248 
   249 
   250 
   251 
   252 /**
   253 * Function  Name	: CFloggerTest007_02
   254 * Input parameters	: None
   255 * Output parameters : None
   256 * Description		: This is the constructor
   257 */
   258 
   259 
   260 CFloggerTest007_02::CFloggerTest007_02()
   261 	{
   262 	// store the name of this test case
   263 	SetTestStepName(_L("step_007_02"));
   264 	}
   265 
   266 
   267 /**
   268 * Function  Name	:~ CFloggerTest007_02
   269 * Input parameters	: None
   270 * Output parameters : None
   271 * Description		: This is the Destructor
   272 */
   273 
   274 
   275 CFloggerTest007_02::~CFloggerTest007_02()
   276 	{
   277 	}
   278 
   279 
   280 /**
   281 * Function  Name	: doTestStepL
   282 * Input parameters	: None
   283 * Output parameters : TVerdict 
   284 * Description		: This function returns weather the test case 007_02 has 
   285 * 					  passed or failed
   286 
   287 */
   288 
   289 
   290 TVerdict CFloggerTest007_02::doTestStepL( )
   291 	{
   292 	INFO_PRINTF1(_L("Step 007.02 called "));
   293 		
   294 	if ( executeStepL() == KErrNone )
   295 		SetTestStepResult(EPass);
   296 
   297 	else
   298 		SetTestStepResult(EFail);
   299 
   300 	
   301 	User::After(KTimeForDisplay);
   302 	return TestStepResult();
   303 	}
   304 
   305 
   306 
   307 /**
   308 * Function  Name		: executeStepL
   309 * Input parameters		: None
   310 * Output parameters		: TInt 
   311 * Description 			: This function writes the test data in to the log file 
   312 * 						  This function check the test message is present in the 
   313 * 						  log file 
   314 
   315 */
   316 
   317 
   318 TInt CFloggerTest007_02::executeStepL()
   319 	{
   320 	TInt ret = KErrGeneral;
   321 	
   322 	ret = DoTestConnect();
   323 	CleanupClosePushL(iFlogger);
   324 	if (ret == KErrNone)
   325 		ret = DoTestWrite();
   326 		if (ret == KErrNone)
   327 			ret = DoTestCheckWriteL();
   328 	
   329 	CleanupStack::PopAndDestroy();	//logger
   330 	User::After(1000000);
   331 	return ret;
   332 	}
   333 
   334 /**
   335 * Function  Name		: executeStepL
   336 * Input parameters		: None
   337 * Output parameters		: TInt 
   338 * Description 			: This function writes the test data in to the log file 
   339 * 						  This function check the test message is present in the 
   340 * 						  log file 
   341 
   342 */
   343 
   344 
   345 TInt CFloggerTest007_02::executeStepL(TBool)
   346 	{
   347 	return KErrGeneral;
   348 	}
   349 
   350 /**
   351 * Function  Name		: DoTestConnect
   352 * Input parameters		: None
   353 * Output parameters		: TInt 
   354 * Description 			: This function establishes a connection to file logger
   355 * 						  and sets the system and component name in file logger.
   356 					  
   357 */
   358 
   359 
   360 TInt CFloggerTest007_02::DoTestConnect()
   361 	{
   362 	TInt ret;
   363 	TPtrC8 ptrSubSystem;
   364 	TPtrC8 ptrComponent;
   365 	ptrSubSystem.Set(_L8("SubSystem"));
   366 	ptrComponent.Set(_L8("Component"));
   367 
   368 	ret = iFlogger.Connect(); //Call connect() of Flogger
   369 	if (ret == KErrNone)
   370 		ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
   371 
   372 	if (ret == KErrNone)
   373 		ret = iFlogger.ClearLog(); //clear the contents from the log
   374 
   375 	return ret;
   376 	}
   377 
   378 
   379 /**
   380 * Function  Name		: DoTestWrite
   381 * Input parameters		: None
   382 * Output parameters		: TInt 
   383 * Description 			: This function writes the data to the file logger
   384  
   385 */
   386 
   387 
   388 TInt CFloggerTest007_02::DoTestWrite()
   389 	{
   390 	//KTestLongMessage contains a very long test message 
   391 	_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");
   392 	iFlogger.Write(KTestLongMessage); 		
   393 	ForceLogFlush(iFlogger);	
   394 	return KErrNone; 
   395 	}
   396 
   397 
   398 /**
   399 * Function  Name		: DoTestCheckWriteL
   400 * Input parameters		: None
   401 * Output parameters		: TInt 
   402 * Description 			: This function checks the weather test data was written
   403 *						  in to the log file by DoTestWriteL() or not.
   404 					  
   405 */
   406 
   407 
   408 TInt CFloggerTest007_02::DoTestCheckWriteL()
   409 	{
   410 	User::After(KTimeToLog);
   411 	RFile theFile;
   412 	HBufC8 * hBuffer;
   413 	TInt listfilesize,returnCode;
   414 	RFs fileSystem; //For file operation create a file system
   415 	TBuf8<256> testData; //To hold the test descriptor
   416 	_LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
   417 
   418 	//The following contains the string of length 200(max) 
   419 	//which is  written to the log file
   420 	//_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");
   421 	_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");
   422 	
   423 	//_LIT8(KOOMError, "#Logs may be lost out of memory!!");
   424 	
   425 	User::LeaveIfError(fileSystem.Connect());
   426 	
   427 	//Open the file in the read mode
   428 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   429 
   430 	CleanupClosePushL(theFile);
   431 
   432 	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   433 	
   434 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   435 	CleanupStack::PushL(hBuffer);
   436 
   437 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   438 
   439 	// Read from position 0: start of file
   440 	User::LeaveIfError(returnCode = theFile.Read(ptrString));
   441 	
   442 	testData.Copy(KTestLongMessage); //Copy the test descriptor
   443 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   444 											//from the file
   445 
   446 	
   447 	CleanupStack::PopAndDestroy(hBuffer);
   448 	CleanupStack::PopAndDestroy();	//theFile
   449 	if (returnCode > 0)
   450 		return KErrNone;
   451 	else 
   452 		return KErrGeneral;
   453 	
   454 
   455 }
   456 
   457 
   458 
   459 
   460 
   461 
   462 /**
   463 * Function  Name	: CFloggerTest007_03
   464 * Input parameters	: None
   465 * Output parameters : None
   466 * Description		: This is the constructor
   467 */
   468 
   469 
   470 CFloggerTest007_03::CFloggerTest007_03()
   471 	{
   472 	// store the name of this test case
   473 	SetTestStepName(_L("step_007_03"));
   474 	}
   475 
   476 
   477 
   478 /**
   479 * Function  Name	:~ CFloggerTest007_03
   480 * Input parameters	: None
   481 * Output parameters : None
   482 * Description		: This is the Destructor
   483 */
   484 
   485 
   486 
   487 CFloggerTest007_03::~CFloggerTest007_03()
   488 	{
   489 	}
   490 
   491 
   492 
   493 /**
   494 * Function  Name : doTestStepL
   495 * Input parameters : None
   496 * Output parameters : TVerdict 
   497 * Description : This function is responsible for doing the heap test analysis 
   498 
   499 */
   500 
   501 
   502 TVerdict CFloggerTest007_03::doTestStepL( )
   503 	{
   504 	INFO_PRINTF1(_L("Step 007.03 called "));
   505 
   506 	CFloggerTest007_01* step007_01 = new CFloggerTest007_01;
   507 	CleanupStack::PushL(step007_01);
   508 	doTestStepWithHeapFailureL( *step007_01, 1, 20, KErrNone, ETrue);
   509 
   510 	CleanupStack::PopAndDestroy(step007_01);
   511 	User::After(KTimeForDisplay);
   512 	return TestStepResult();
   513 	}
   514