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