applayerprotocols/httptransportfw/Test/T_HttpRegression/t_httpregression.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2004-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 //
       
    15 
       
    16 // Framework includes
       
    17 #if !defined(__HTTPTESTUTILS_H__)
       
    18 #include "httptestutils.h"
       
    19 #endif
       
    20 
       
    21 #if !defined(__HTTPTESTCORE_H__)
       
    22 #include "HttpTestCore.h"
       
    23 #endif
       
    24 
       
    25 #if !defined(__TESTSCRIPTS_H__)
       
    26 #include "TestScripts.h"
       
    27 #endif
       
    28 
       
    29 
       
    30 #include "SingleTrans.h"
       
    31 
       
    32 // Individual test class includes
       
    33 #include "t_CLE-4Y5LC9.h"
       
    34 #include "t_KHN-4Z7DT7.h"
       
    35 #include "t_INC035621.h"
       
    36 #include "T_INC053172.h"
       
    37 
       
    38 
       
    39 
       
    40 // Constants used in this file
       
    41 enum TPanic
       
    42 	{
       
    43 	EFailedToCreateEngine,
       
    44 	EFailedToReadIniFile
       
    45 	};
       
    46 
       
    47 // Name of test harness
       
    48 _LIT(KHttpRegressionTestTitle,		"HTTP Regression Tests");
       
    49 
       
    50 // Location of INI file that defines the test cases to be run
       
    51 _LIT(KHttpRegressionTestCompName,	"regression");
       
    52 _LIT(KHttpregressionTestscriptName, "RegressionTests.ini");
       
    53 
       
    54 _LIT(KSettingsIniCompName,			"settings");
       
    55 _LIT(KSettingsIniName,				"settings.ini");
       
    56 
       
    57 // Labels for resources in the INI file
       
    58 _LIT(KRunTestItemName,				"RunTest");
       
    59 _LIT(KDefaultSection,				"Defaults");
       
    60 _LIT(KSilenceItemName,				"Silent");
       
    61 _LIT(KLeakTestCount,				"LeakTestCount");
       
    62 _LIT(KFirstLeakIteration,			"FirstLeakIteration");
       
    63 _LIT(KSectionSingleTrans,			"SINGLE_TRANS");
       
    64 _LIT(KZero,							"0");
       
    65 
       
    66 // Test names, used as section headings in the .ini file, and any resource 
       
    67 // names associated with the test
       
    68 _LIT(KTestKHN4Z7DT7,				"KHN-4Z7DT7");
       
    69 _LIT(KTestCLE4Y5LC9_1,				"CLE-4Y5LC9_1");
       
    70 _LIT(KTestCLE4Y5LC9_2,				"CLE-4Y5LC9_2");
       
    71 _LIT(KTestINC035621,				"INC035621");
       
    72 _LIT(KTestINC053172, "INC053172");
       
    73 
       
    74 const TInt KMaxHeapSize = 0x100000;
       
    75 const TInt KMaxIntDesLen = 10;				// Des length required for displaying max 32 bit int
       
    76 _LIT(KTestThreadName,						"TestThread");
       
    77 _LIT(KRtestFailureLabel, 					"RTEST: FAILED due to a %S %d Panic ");
       
    78 
       
    79 
       
    80 void DoTestsL()
       
    81 	{	
       
    82 	TBool runTestDefault = EFalse;
       
    83 
       
    84 	CTestScheduler* as = new(ELeave) CTestScheduler;
       
    85 	CleanupStack::PushL(as);
       
    86 	if (!as)
       
    87 		User::Panic(_L("Failed to create active scheduler"),KErrNoMemory);
       
    88 	CActiveScheduler::Install(as); // Install active scheduler
       
    89 	
       
    90 	// Initialise Comms, required in a minimal console environment
       
    91 	CHTTPTestUtils::InitCommsL();
       
    92 
       
    93 	// Force a connection to be held open keep NT RAS connected...
       
    94 	CHTTPTestUtils::HoldOpenConnectionL();
       
    95 	
       
    96 	// Create the test engine
       
    97 	CHttpTestEngine* engine=NULL;
       
    98 	TRAPD(err,engine = CHttpTestEngine::NewL(KHttpRegressionTestTitle(), EFalse));
       
    99 	if (err != KErrNone)
       
   100 		User::Panic(_L("T_HTTPREGRES"),EFailedToCreateEngine);
       
   101 	CleanupStack::PushL(engine);
       
   102 
       
   103 	engine->Utils().LogIt(_L("@SYMTestCaseID IWS-APPPROTOCOLS-HTTP-FRAMEWORK-T_HTTPREGRESSION-0001  "));
       
   104 	
       
   105 	// Open the INI file to initialise the tests we're going to run
       
   106 	CScriptFile* iniFile = NULL;
       
   107 	TRAP(err, iniFile = CScriptFile::NewL(engine->Utils(), KHttpRegressionTestCompName, KHttpregressionTestscriptName()));
       
   108 	if (err != KErrNone)
       
   109 		User::Panic(_L("T_HTTPREGRES"),EFailedToReadIniFile);
       
   110 	CleanupStack::PushL(iniFile);
       
   111 
       
   112 	// Open the settings.ini file which has the server IP/Name that would
       
   113 	// be used by the tests.
       
   114 	CScriptFile* iniSettingsFile = NULL;
       
   115 	TRAP(err, iniSettingsFile = CScriptFile::NewL(engine->Utils(), KSettingsIniCompName, KSettingsIniName()));
       
   116 	if (err != KErrNone)
       
   117 		{
       
   118 		User::Panic(KHttpRegressionTestCompName(),err);
       
   119 		}
       
   120 	CleanupStack::PushL(iniSettingsFile);
       
   121 
       
   122 	// Read the default silent setting for the tests
       
   123 	engine->Utils().SetSilent(iniFile->ItemValue(KDefaultSection, KSilenceItemName, EFalse));
       
   124 
       
   125 	// Create the tests we're going to run.  Ownership is transferred to the test engine
       
   126 	RPointerArray<CHttpTestBase> regressionTests;
       
   127 	CleanupClosePushL(regressionTests);
       
   128 
       
   129 
       
   130 // READ DEFAULTS
       
   131 	CArrayPtrFlat<CScriptSection>& sections=iniFile->Sections();
       
   132 	TInt sectionsCount = sections.Count();
       
   133 	CScriptSection* section = NULL;
       
   134 	
       
   135 	for (TInt ii=0;ii<sectionsCount;++ii)
       
   136 		{
       
   137 		section = sections[ii];
       
   138 	
       
   139 		// DEFAULTS
       
   140 		if (section->SectionName().CompareF(KDefaultSection) == 0)
       
   141 			{
       
   142 			if (iniFile->Section(ii).ItemL(KSilenceItemName).Value().CompareF(KZero) == 0)
       
   143    				engine->SetSilent(EFalse);
       
   144  			else  	
       
   145 				engine->SetSilent(ETrue);
       
   146  			if (iniFile->Section(ii).ItemL(KRunTestItemName).Value().CompareF(KZero) != 0)
       
   147 				runTestDefault = ETrue;
       
   148 			}
       
   149 
       
   150 		// SCRIPTED SINGLE_TRANS TESTS - These are purely done by a single transaction
       
   151 	
       
   152 		if (section->SectionName().CompareF(KSectionSingleTrans) == 0)
       
   153 			{
       
   154 			TBool runTest = runTestDefault;
       
   155 
       
   156    			TPtrC itemPtr(iniFile->Section(ii).Item(0).Item());
       
   157  			if (itemPtr.CompareF(KRunTestItemName)==0)
       
   158  				runTest = !(iniFile->Section(ii).Item(0).Value().CompareF(KZero) == 0);
       
   159  			if (runTest)
       
   160    				{
       
   161    				CHttpTestBase* singleTrans = CHttpTestSingleTrans::NewL(*iniFile,iniSettingsFile,ii);
       
   162 				CleanupStack::PushL(singleTrans);
       
   163    				regressionTests.Append(singleTrans);
       
   164    				}
       
   165 			}
       
   166 		}
       
   167 
       
   168 // NON SCRIPTED TESTS - These are done by separate classes
       
   169 
       
   170 
       
   171 	// Post body rewind tests
       
   172 	if (iniFile->ItemValue(KTestCLE4Y5LC9_1(), KRunTestItemName(), ETrue))
       
   173 		{
       
   174 		CTestFixCLE4Y5LC9_1* CLE4Y5LC9_1 = CTestFixCLE4Y5LC9_1::NewLC(iniSettingsFile);
       
   175 		regressionTests.Append(CLE4Y5LC9_1);
       
   176 		
       
   177 		TInt numLeakTests = iniFile->ItemValue(KTestCLE4Y5LC9_1(), KLeakTestCount(), 0);
       
   178 		TInt firstLeakIter = iniFile->ItemValue(KTestCLE4Y5LC9_1(), KFirstLeakIteration(), 0);
       
   179 		CLE4Y5LC9_1->SetLeakTests(numLeakTests, firstLeakIter);
       
   180 		}
       
   181 
       
   182 	if (iniFile->ItemValue(KTestCLE4Y5LC9_2(), KRunTestItemName(), ETrue))
       
   183 		{
       
   184 		CTestFixCLE4Y5LC9_2* CLE4Y5LC9_2 = CTestFixCLE4Y5LC9_2::NewLC(iniSettingsFile);
       
   185 		regressionTests.Append(CLE4Y5LC9_2);
       
   186 		
       
   187 		TInt numLeakTests = iniFile->ItemValue(KTestCLE4Y5LC9_2(), KLeakTestCount(), 0);
       
   188 		TInt firstLeakIter = iniFile->ItemValue(KTestCLE4Y5LC9_2(), KFirstLeakIteration(), 0);
       
   189 		CLE4Y5LC9_2->SetLeakTests(numLeakTests, firstLeakIter);
       
   190 		}
       
   191 
       
   192 	if (iniFile->ItemValue(KTestKHN4Z7DT7(), KRunTestItemName(), ETrue))
       
   193 		{
       
   194 		CTestFixKHN4Z7DT7* KHN4Z7DT7 = CTestFixKHN4Z7DT7::NewLC(iniSettingsFile);
       
   195 		regressionTests.Append(KHN4Z7DT7);
       
   196 		
       
   197 		TInt numLeakTests = iniFile->ItemValue(KTestKHN4Z7DT7(), KLeakTestCount(), 0);
       
   198 		TInt firstLeakIter = iniFile->ItemValue(KTestKHN4Z7DT7(), KFirstLeakIteration(), 0);
       
   199 		KHN4Z7DT7->SetLeakTests(numLeakTests, firstLeakIter);
       
   200 		}
       
   201 
       
   202 	if (iniFile->ItemValue(KTestINC035621(), KRunTestItemName(), ETrue))
       
   203 		{
       
   204 		CTestFixINC035621* INC035621 = CTestFixINC035621::NewLC(iniSettingsFile);
       
   205 		regressionTests.Append(INC035621);
       
   206 		
       
   207 		TInt numLeakTests = iniFile->ItemValue(KTestINC035621(), KLeakTestCount(), 0);
       
   208 		TInt firstLeakIter = iniFile->ItemValue(KTestINC035621(), KFirstLeakIteration(), 0);
       
   209 		INC035621->SetLeakTests(numLeakTests, firstLeakIter);
       
   210 		}
       
   211 
       
   212 	if (iniFile->ItemValue(KTestINC053172(), KRunTestItemName(), ETrue))
       
   213 		{
       
   214 		CTestFixINC053172* INC053172 = CTestFixINC053172::NewLC();
       
   215 		regressionTests.Append(INC053172);
       
   216 		
       
   217 		TInt numLeakTests = iniFile->ItemValue(KTestINC053172(), KLeakTestCount(), 0);
       
   218 		TInt firstLeakIter = iniFile->ItemValue(KTestINC053172(), KFirstLeakIteration(), 0);
       
   219 		INC053172->SetLeakTests(numLeakTests, firstLeakIter);
       
   220 		}
       
   221 
       
   222 	// Set the test set based on the menu choices
       
   223 	engine->ConfigureTestSet(regressionTests);
       
   224 
       
   225 	// Pop the tests which are now owned by the test engine
       
   226 	TInt numTestsToPop = regressionTests.Count();
       
   227 	CleanupStack::Pop(numTestsToPop); // multiCancelTest
       
   228 	CleanupStack::Pop(); // regressionTests, the array itself
       
   229 
       
   230 	// All the action happens within the main event loop.
       
   231 	CActiveScheduler::Start();
       
   232 
       
   233 	// Returned from start so shutdown. Turn off test engine silence to get a summary report.
       
   234 	engine->Utils().SetSilent(EFalse);
       
   235 	engine->Utils().LogIt(_L("\nEnd of tests"));
       
   236 	TInt pass, fail;
       
   237 	engine->TestSummary(pass, fail);
       
   238 	engine->Utils().LogIt(_L("\nTest Summary: %d passed, %d failed.\n"), pass, fail);
       
   239 	//engine->PressAnyKey();
       
   240 	
       
   241 	// Release the held open connection
       
   242 	CHTTPTestUtils::ReleaseConnectionL();	
       
   243 
       
   244 	CleanupStack::PopAndDestroy(4, as);// inifile, engine, iniSettingsFile
       
   245 	}
       
   246 
       
   247 TInt TestEntryPoint(TAny* /*aParam*/)
       
   248     {
       
   249 __UHEAP_MARK;
       
   250 
       
   251 	// Install exception handler
       
   252 	CTrapCleanup* theCleanup = CTrapCleanup::New(); 
       
   253 	TRAP_IGNORE(DoTestsL());
       
   254 	delete theCleanup;
       
   255 
       
   256 __UHEAP_MARKEND;
       
   257 	User::Heap().Check();
       
   258     return(KErrNone);
       
   259 	}
       
   260 	
       
   261 void LogOnPanicL(RThread& aTestThread)	
       
   262 	{
       
   263 	CActiveScheduler* as = new(ELeave) CActiveScheduler;
       
   264 	CleanupStack::PushL(as);
       
   265 	if (!as)
       
   266 		{
       
   267 		User::Panic(_L("Failed to create active scheduler"),KErrNoMemory);
       
   268 		}
       
   269 	CActiveScheduler::Install(as); // Install active scheduler
       
   270 		
       
   271 	// Initialise Comms, required in a minimal console environment
       
   272 	CHTTPTestUtils::InitCommsL();
       
   273 
       
   274 	// Force a connection to be held open keep NT RAS connected...
       
   275 	CHTTPTestUtils::HoldOpenConnectionL();
       
   276 	
       
   277 	// Create the test engine
       
   278 	CHttpTestEngine* engine=NULL;
       
   279 	TRAPD(err,engine = CHttpTestEngine::NewL(KHttpRegressionTestTitle(), EFalse));
       
   280 	if (err != KErrNone)
       
   281 		{
       
   282 		User::Panic(_L("T_PIPELINING"),err);
       
   283 		}
       
   284 	CleanupStack::PushL(engine);
       
   285 	
       
   286 	// Create log message
       
   287 	TExitCategoryName panicName = aTestThread.ExitCategory();
       
   288 	TInt panicNumber = aTestThread.ExitReason();
       
   289 	HBufC* logMessage = HBufC::NewLC(KRtestFailureLabel().Length() + 
       
   290 								   panicName.Length() +	
       
   291 								   KMaxIntDesLen);
       
   292 	TPtr logMessagePtr = logMessage->Des();
       
   293 	logMessagePtr.Format(KRtestFailureLabel, &panicName, panicNumber);
       
   294 			
       
   295 	engine->Utils().LogIt(logMessagePtr);
       
   296 	
       
   297 	// Panic here so that nothing else is written to the log file
       
   298 	User::Panic(panicName, panicNumber);
       
   299 	
       
   300 	// The code below provided for completenes, but should never be reached
       
   301 	
       
   302 	// Release the held open connection
       
   303 	CHTTPTestUtils::ReleaseConnectionL();	
       
   304 	
       
   305 	CleanupStack::PopAndDestroy(3, as); //as, engine, logMessage
       
   306 	}
       
   307 		
       
   308 // main loop
       
   309 //
       
   310 GLDEF_C TInt E32Main()
       
   311     {  
       
   312 	__UHEAP_MARK;  
       
   313 	CTrapCleanup* theCleanup = CTrapCleanup::New(); // Install exception handler  
       
   314 	
       
   315 	// Create a new thread for running tests in
       
   316 	RThread testThread;
       
   317 	TInt err = testThread.Create(KTestThreadName, TestEntryPoint, KDefaultStackSize,  
       
   318 							 KMinHeapSize, KMaxHeapSize, NULL);
       
   319 	if(err == KErrNone)
       
   320 		{
       
   321 		testThread.Resume();	
       
   322 		}
       
   323 	else
       
   324 		{
       
   325 		return err;
       
   326 		}
       
   327 	
       
   328 	// Kick off test thread and wait for it to exit
       
   329 	TRequestStatus tStat;
       
   330 	testThread.Logon(tStat);
       
   331 	User::WaitForRequest(tStat);
       
   332 	
       
   333 	// Log if paniced
       
   334 	if(testThread.ExitType() == EExitPanic)
       
   335 		{
       
   336 		TRAP_IGNORE(LogOnPanicL(testThread));	
       
   337 		}
       
   338 	
       
   339 	testThread.Close();
       
   340 	delete theCleanup;		
       
   341 	__UHEAP_MARKEND;		
       
   342 	return KErrNone;
       
   343 	}
       
   344