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