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