os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_029_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 // See the test specification for details of what these test cases do.
    15 
    16 #include "teststepcomsdbg.h"
    17 #include "TestMessage.h"
    18 #include "step_029_xx.h"
    19 
    20 
    21 #include <comms-infras/commsdebugutility.h>
    22 
    23 
    24 
    25 /**
    26 * 029_IniFile01: Test that flogger handles ini change to debugport and file
    27 */ 
    28 
    29 CFloggerTest029_IniFile01::CFloggerTest029_IniFile01()
    30 	{
    31 	// Store the name of this test case
    32 	SetTestStepName(_L("step_029_IniFile01"));
    33 	}
    34 
    35 
    36 
    37 
    38 CFloggerTest029_IniFile01::~CFloggerTest029_IniFile01()
    39 	{
    40 	}
    41 
    42 
    43 
    44 
    45 TVerdict CFloggerTest029_IniFile01::doTestStepL( )
    46 	{
    47 	if ( executeStepL() == KErrNone  )
    48 		SetTestStepResult(EPass);
    49 
    50 	else
    51 		SetTestStepResult(EFail);
    52 
    53 	User::After(KTimeForDisplay);
    54 
    55 	
    56 	return TestStepResult();
    57 	}
    58 
    59 TInt CFloggerTest029_IniFile01::executeStepL(TBool)
    60 	{
    61 	return KErrGeneral;
    62 	}
    63 
    64 
    65 TInt CFloggerTest029_IniFile01::executeStepL()
    66 	{
    67 	TInt ret;
    68 	TInt r;
    69 	RFileLogger theFlogger;
    70 	
    71 	ret = theFlogger.Connect();
    72 	
    73 	if ( ret == KErrNone)
    74 		{
    75 		theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
    76 		theFlogger.ClearLog();
    77 		theFlogger.Write(KLogFillerMessage8);
    78 		theFlogger.Write(KLogFillerMessage8);
    79 		theFlogger.Close();
    80 	
    81 		replaceFloggerIniL( KIniConfigWithFileAndDebugPort );
    82 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestMessage8);
    83 	
    84 		User::After(KTimeToLog);
    85 		TRAP(r, ret = DoTestCheckWriteL());
    86 		if (r != KErrNone)
    87 			ret = r;
    88 		}
    89 
    90 	constructFloggerIniL( KDefaultIniFileSettings );
    91 	
    92 	return ret;		
    93 
    94 	}
    95 
    96 
    97 
    98 
    99 TInt CFloggerTest029_IniFile01::DoTestCheckWriteL()
   100 	{
   101 	RFile theFile;
   102 	HBufC8 * hBuffer;
   103 	TInt listfilesize,returnCode;
   104 	RFs fileSystem; //For file operation create a file system
   105 	TUint numSuccessful = 0;
   106 
   107 	
   108 	User::LeaveIfError(fileSystem.Connect());
   109 	CleanupClosePushL(fileSystem);
   110 	
   111 	//Open the file in the read mode
   112 	User::LeaveIfError(theFile.Open(fileSystem,KFloggerOutputFile,EFileRead)); 
   113 
   114 	CleanupClosePushL(theFile);
   115 
   116 	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   117 	
   118 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   119 	CleanupStack::PushL(hBuffer);
   120 
   121 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   122 
   123 	// Read from position 0: start of file
   124 	User::LeaveIfError(returnCode = theFile.Read(ptrString));
   125 	
   126 	returnCode = ptrString.Find(KMessageIniHasChanged); //find the test descriptor in the buffer read
   127 											//from the file
   128 	
   129 	if (returnCode > 0)
   130 		{
   131 		numSuccessful++;
   132 		}
   133 	else if (returnCode == KErrNotFound)
   134 		{
   135 		returnCode = ptrString.Find(KErrOOM);
   136 		if (returnCode > 0)
   137 			User::Leave(KErrNoMemory);
   138 		}
   139 
   140 	returnCode = ptrString.Find(KTestMessage8); //find the test descriptor in the buffer read
   141 											//from the file
   142 	
   143 	if (returnCode > 0)
   144 		{
   145 		numSuccessful++;
   146 		}
   147 
   148 
   149 	// flogger should not have had a problem reading the ini file
   150 	returnCode = ptrString.Find(KErrIniProblemMessage);
   151 	
   152 	if (returnCode == KErrNotFound)
   153 		{
   154 		numSuccessful++;
   155 		}
   156 	
   157 	CleanupStack::PopAndDestroy(hBuffer);
   158 	CleanupStack::PopAndDestroy();	//theFile
   159 	CleanupStack::PopAndDestroy();  //fileSystem
   160 	
   161 	if (numSuccessful == 3)
   162 		return KErrNone;
   163 	else 
   164 		return KErrNotFound;
   165 	}
   166 
   167 
   168 
   169 /**
   170 * 029_IniFile02: Test that flogger handles ini change to debugport and serial
   171 */ 
   172 
   173 CFloggerTest029_IniFile02::CFloggerTest029_IniFile02()
   174 	{
   175 	// Store the name of this test case
   176 	SetTestStepName(_L("step_029_IniFile02"));
   177 	}
   178 
   179 
   180 
   181 
   182 CFloggerTest029_IniFile02::~CFloggerTest029_IniFile02()
   183 	{
   184 	}
   185 
   186 
   187 
   188 
   189 TVerdict CFloggerTest029_IniFile02::doTestStepL( )
   190 	{
   191 	if ( executeStepL() == KErrNone  )
   192 		SetTestStepResult(EPass);
   193 
   194 	else
   195 		SetTestStepResult(EFail);
   196 
   197 	User::After(KTimeForDisplay);
   198 
   199 	
   200 	return TestStepResult();
   201 	}
   202 
   203 
   204 TInt CFloggerTest029_IniFile02::executeStepL(TBool)
   205 	{
   206 	return KErrGeneral;
   207 	}
   208 
   209 TInt CFloggerTest029_IniFile02::executeStepL()
   210 	{
   211 	TInt ret;
   212 	RFileLogger theFlogger;
   213 	
   214 	ret = theFlogger.Connect();
   215 	
   216 	if ( ret == KErrNone)
   217 		{
   218 		theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
   219 		theFlogger.ClearLog();
   220 		theFlogger.Write(KLogFillerMessage8);
   221 		theFlogger.Write(KLogFillerMessage8);
   222 		theFlogger.Close();
   223 	
   224 		replaceFloggerIniL( KIniConfigWithSerialAndDebugPort );
   225 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestMessage8);
   226 	
   227 		// serial logging means there isn't actually anything to check
   228 		// since we can't check the serial output
   229 		User::After(KTimeToLog);
   230 		}
   231 
   232 	constructFloggerIniL( KDefaultIniFileSettings );
   233 	
   234 	return ret;
   235 
   236 	}
   237 
   238 
   239 
   240 
   241 
   242 
   243 
   244 
   245 /**
   246 * 029_IniFile03: Test that flogger handles ini change to debugport and file
   247 */ 
   248 
   249 CFloggerTest029_IniFile03::CFloggerTest029_IniFile03()
   250 	{
   251 	// Store the name of this test case
   252 	SetTestStepName(_L("step_029_IniFile03"));
   253 	}
   254 
   255 
   256 
   257 
   258 CFloggerTest029_IniFile03::~CFloggerTest029_IniFile03()
   259 	{
   260 	}
   261 
   262 
   263 
   264 
   265 TVerdict CFloggerTest029_IniFile03::doTestStepL( )
   266 	{
   267 	if ( executeStepL() == KErrNone  )
   268 		SetTestStepResult(EPass);
   269 
   270 	else
   271 		SetTestStepResult(EFail);
   272 
   273 	User::After(KTimeForDisplay);
   274 
   275 	
   276 	return TestStepResult();
   277 	}
   278 
   279 
   280 TInt CFloggerTest029_IniFile03::executeStepL(TBool)
   281 	{
   282 	return KErrGeneral;
   283 	}
   284 
   285 TInt CFloggerTest029_IniFile03::executeStepL()
   286 	{
   287 	TInt ret;
   288 	TInt r;
   289 	RFileLogger theFlogger;
   290 	
   291 	ret = theFlogger.Connect();
   292 	
   293 	if ( ret == KErrNone)
   294 		{
   295 		theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
   296 		theFlogger.ClearLog();
   297 		theFlogger.Write(KLogFillerMessage8);
   298 		theFlogger.Write(KLogFillerMessage8);
   299 		theFlogger.Close();
   300 	
   301 		TRAP(r,constructFloggerIniL( KSyncTestsIniFileSettings ));
   302 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestMessage8);
   303 	
   304 		User::After(KTimeToLog);  // although we asked for synchronous mode, we cannot switch to it while flogger is running
   305 		TRAP(r, ret = DoTestCheckWriteL());
   306 		if (r != KErrNone)
   307 			{
   308 			ret = r;
   309 			}
   310 		}
   311 
   312 	TRAP(r,constructFloggerIniL( KDefaultIniFileSettings ));
   313 	if (r != KErrNone)
   314 		{
   315 		ret = r;
   316 		}
   317 	
   318 	return ret;		
   319 
   320 	}
   321 
   322 
   323 
   324 
   325 TInt CFloggerTest029_IniFile03::DoTestCheckWriteL()
   326 	{
   327 	RFile theFile;
   328 	HBufC8 * hBuffer;
   329 	TInt listfilesize,returnCode;
   330 	RFs fileSystem; //For file operation create a file system
   331 	TUint numSuccessful = 0;
   332 
   333 	
   334 	User::LeaveIfError(fileSystem.Connect());
   335 	CleanupClosePushL(fileSystem);
   336 	
   337 	//Open the file in the read mode
   338 	User::LeaveIfError(theFile.Open(fileSystem,KFloggerOutputFile,EFileRead)); 
   339 
   340 	CleanupClosePushL(theFile);
   341 
   342 	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   343 	
   344 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   345 	CleanupStack::PushL(hBuffer);
   346 
   347 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   348 
   349 	// Read from position 0: start of file
   350 	User::LeaveIfError(returnCode = theFile.Read(ptrString));
   351 	
   352 	returnCode = ptrString.Find(KMessageIniHasChanged); //find the test descriptor in the buffer read
   353 											//from the file
   354 	
   355 	if (returnCode > 0)
   356 		{
   357 		numSuccessful++;
   358 		}
   359 	else if (returnCode == KErrNotFound)
   360 		{
   361 		returnCode = ptrString.Find(KErrOOM);
   362 		if (returnCode > 0)
   363 			User::Leave(KErrNoMemory);
   364 		}
   365 
   366 	returnCode = ptrString.Find(KTestMessage8); //find the test descriptor in the buffer read
   367 											//from the file
   368 	
   369 	if (returnCode > 0)
   370 		{
   371 		numSuccessful++;
   372 		}
   373 
   374 
   375 	// flogger should not have had a problem reading the ini file
   376 	returnCode = ptrString.Find(KErrIniProblemMessage);
   377 	
   378 	if (returnCode == KErrNotFound)
   379 		{
   380 		numSuccessful++;
   381 		}
   382 	
   383 	CleanupStack::PopAndDestroy(hBuffer);
   384 	CleanupStack::PopAndDestroy();	//theFile
   385 	CleanupStack::PopAndDestroy();  //fileSystem
   386 	
   387 	if (numSuccessful == 3)
   388 		return KErrNone;
   389 	else 
   390 		return KErrNotFound;
   391 	}
   392 
   393 
   394 /**
   395  029_IniFile04 - test changing ini file on the fly and removing a tag from it
   396  doTestStep returns whether test case passed or failed. 
   397  When running heapcheck, doTestStep is not called - only executeStepL is called,
   398   and it must return either KErrNoMemory or KErrNone to pass the heap check.
   399 */ 
   400 
   401 CFloggerTest029_IniFile04::CFloggerTest029_IniFile04()
   402 	{
   403 	// store the name of this test case
   404 	SetTestStepName(_L("step_029_IniFile04"));
   405 	}
   406 
   407 // destructor
   408 CFloggerTest029_IniFile04::~CFloggerTest029_IniFile04()
   409 	{
   410 
   411 	}
   412 
   413 
   414 // do Test step 029.01
   415 TVerdict CFloggerTest029_IniFile04::doTestStepL( )
   416 	{
   417 	if (executeStepL(EFalse) == KErrNone)
   418 		SetTestStepResult(EPass);
   419 
   420 	else
   421 		SetTestStepResult(EFail);
   422 
   423 
   424 	INFO_PRINTF1(_L("leaving Step 029.IniFile04 "));
   425 
   426 	return TestStepResult() ;
   427 	}
   428 
   429 TInt CFloggerTest029_IniFile04::executeStepL()
   430 	{
   431 	return KErrGeneral;
   432 	}
   433 
   434 TInt CFloggerTest029_IniFile04::executeStepL(TBool heapTest)
   435 /**
   436 @param heapTest  supplied as ETrue when heap checking so that
   437   we can catch instances of data not being in the file and let harness know
   438   that perhaps its because no memory yet.
   439  */
   440 	{
   441 	TInt ret = KErrGeneral;
   442 	
   443 	TRAPD(r, ret = DoTestWrite(0))
   444 	
   445 	if (r == KErrNone && ret == KErrNone)
   446 		{
   447 		User::After(KTimeToLog);
   448 		TRAP(r, ret = DoTestCheckWriteL(0));
   449 			{
   450 			if ((heapTest) && (ret == KErrNotFound))
   451 				{
   452 				//
   453 				ret = KErrNoMemory;
   454 				}
   455 			else if (r == KErrNone && ret == KErrNone)
   456 				{
   457 				constructFloggerIniL( KIniFileChangeIniFileSettings );
   458 				TRAP(r, ret = DoTestWrite(1))
   459 				
   460 				User::After(KTimeToLog);
   461 				TRAP(r, ret = DoTestCheckWriteL(1));
   462 				if ((heapTest) && (ret == KErrNotFound))
   463 					{
   464 					ret = KErrNoMemory;
   465 					}
   466 				}
   467 			}
   468 
   469 		}
   470 	// regardless of what happens, we need to ensure we close the connection
   471 	// if it was opened
   472 	TRAP(r, DoTestWrite(2))
   473 	constructFloggerIniL( KDefaultIniFileSettings );
   474 	
   475 	return ret;
   476 	
   477 	}
   478 
   479 
   480 
   481 
   482 //NOTE
   483 // If aStatus is 0 then first modification
   484 // If aStatus is 1 then second modification
   485 
   486 TInt CFloggerTest029_IniFile04::DoTestWrite(TInt aStatus)
   487 	{
   488 	
   489 	TPtrC8 ptrSubSystem;
   490 	TPtrC8 ptrComponent;
   491 	ptrSubSystem.Set(_L8("SubSystem"));
   492 	ptrComponent.Set(_L8("Component"));
   493 	TInt ret = KErrGeneral;
   494 
   495 
   496 	if (aStatus ==0)
   497 		{	
   498 		ret = iFlogger.Connect(); //Connect 
   499 	
   500 		if (ret == KErrNone)
   501 			{
   502 			//Set tags by passing the subsystem and component name as parameters
   503 			ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); 
   504 			if ( ret == KErrNone)
   505 				{
   506 				ret = iFlogger.ClearLog(); //Clear old log messages in the log
   507 				}
   508 			else if (ret == KErrNotFound)
   509 				{
   510 				ret = KErrNoMemory; // keep heap checker happy
   511 				}
   512 			if ( ret == KErrNone)
   513 				{
   514 				iFlogger.Write(KFirstTestMessage); //Write the test descriptor
   515 				ForceLogFlush(iFlogger);
   516 				}
   517 			}
   518 		
   519 		return ret;
   520 		
   521 		}
   522 	if (aStatus == 1)
   523 		{
   524 		//Set tags by passing the subsystem and component name as parameters
   525 		iFlogger.SetLogTags(ptrSubSystem, ptrComponent); 
   526 		iFlogger.Write(KSecondTestMessage); //Write the test descriptor
   527 		iFlogger.SetLogTags(_L8("Esock"),_L8("Esock.txt"));
   528 		iFlogger.Write(KHexTestHeader); //Write the test descriptor
   529 		}
   530 	if (aStatus == 2)
   531 		{
   532 		iFlogger.Close();
   533 		}
   534 	
   535 	return KErrNone;
   536 		
   537 	}
   538 
   539 //NOTE
   540 // If aFileStatus is 0 then status before modification
   541 // If aFileStatus is 1 then status after modification
   542 
   543 TInt CFloggerTest029_IniFile04::DoTestCheckWriteL(TInt aFileStatus)  
   544 	{
   545 	RFile theFile;
   546 	HBufC8 * hBuffer;
   547 	TInt listfilesize = KErrGeneral;
   548 	TInt returnCode = KErrNotFound;
   549 	RFs fileSystem; //For file operation create a file system
   550 	TInt numSuccessful = 0;
   551 
   552 
   553 	User::LeaveIfError(fileSystem.Connect()); //Connect to the file server
   554 	
   555 	//Open the file in the read mode
   556 	User::LeaveIfError(theFile.Open(fileSystem, KFloggerOutputFile, EFileRead)); 
   557 
   558 	User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
   559 
   560 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   561 	CleanupStack::PushL(hBuffer);
   562 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   563 
   564 	// Read from position 0: starting of file
   565 	returnCode = theFile.Read(ptrString);
   566 			
   567 	if (aFileStatus == 0)
   568 		{
   569 		// as a little extra test, the subsystem tag in the "ini" file is "Subsystem"
   570 		// but we wrote the data as "SubSystem" so it should still be in the file,
   571 		// but we need to search non-case sensitive
   572 		returnCode = ptrString.FindF(KStdSubsysTag8);	//find the test system name in 
   573 											//the buffer read from the file
   574 
   575 		
   576 		if (returnCode > 0) //Note test system should be present before/After the ini is modified
   577 			{
   578 
   579 			returnCode = ptrString.Find(KStdCompTag8);	//find the test component name in the buffer read
   580 													//from the file
   581 			}
   582 			if (returnCode > 0) //Note test descriptor should be present before the ini is modified
   583 				{
   584 				returnCode = ptrString.Find(KFirstTestMessage); //find the test descriptor in the buffer read
   585 													//from the file					
   586 				}
   587 
   588 		CleanupStack::PopAndDestroy(hBuffer);
   589 		theFile.Close();
   590 		fileSystem.Close();
   591 
   592 		
   593 		if (returnCode > 0) //Note test descriptor should be present before the ini is modified
   594 			returnCode = KErrNone;
   595 	
   596 		}
   597 
   598 
   599 	else if (aFileStatus == 1)
   600 		{
   601 		returnCode = ptrString.Find(KFirstTestMessage);	//find the first test descriptor in
   602 												//the buffer read from the file
   603 
   604 		if (returnCode > 0)	//Note first test message should be present even after 
   605 							//the ini is modified
   606 			{
   607 			numSuccessful++;
   608 			}
   609 		returnCode = ptrString.Find(KErrIniProblemMessage);
   610 		if (returnCode > 0)	//Note as a bonus the ini we supplied has an error, so a message as such should be there
   611 			{
   612 			numSuccessful++;
   613 			}
   614 		
   615 		returnCode = ptrString.Find(KSecondTestMessage);
   616 		if ( returnCode == KErrNotFound )	// The second test msg should not be there since there is no associated tag in the ini file
   617 			{
   618 			numSuccessful++;
   619 			}
   620 			
   621 		returnCode = ptrString.Find(KMessageIniHasChanged);
   622 		if ( returnCode > 0 )	// Flogger should see that the ini file has changed
   623 			{
   624 			numSuccessful++;
   625 			}
   626 
   627 		CleanupStack::PopAndDestroy(hBuffer);
   628 		theFile.Close();
   629 		fileSystem.Close();
   630 
   631 		if (numSuccessful == 4)
   632 			returnCode = KErrNone;
   633 		}
   634 	
   635 	
   636 	return returnCode;
   637 	}
   638 
   639 
   640 
   641 
   642 CFloggerTest029_IniFile04H::CFloggerTest029_IniFile04H()
   643 	{
   644 	// store the name of this test case
   645 	SetTestStepName(_L("step_029_IniFile04H"));
   646 	}
   647 
   648 
   649 
   650 CFloggerTest029_IniFile04H::~CFloggerTest029_IniFile04H()
   651 	{
   652 	}
   653 
   654 
   655 
   656 TVerdict CFloggerTest029_IniFile04H::doTestStepL( )
   657 	{
   658 	INFO_PRINTF1(_L("Step 029.IniFile04H called "));
   659 	User::After(KTimeForDisplay1);
   660 
   661 	CFloggerTest029_IniFile04* step029_IniFile04 = new CFloggerTest029_IniFile04;
   662 	CleanupStack::PushL(step029_IniFile04);
   663 	doTestStepWithHeapFailureL( *step029_IniFile04, 523, 550, KErrNone, ETrue);
   664 	
   665 	CleanupStack::PopAndDestroy(step029_IniFile04);
   666 	INFO_PRINTF1(_L("leaving Step 029.IniFile04H "));
   667 	
   668 
   669 	return TestStepResult();
   670 	}
   671