os/graphics/windowing/windowserver/test/t_integ/src/t_wservintegstepbase.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) 2007-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 /**
    17  @file
    18  @test
    19  @internalComponent
    20 */
    21 
    22 #include <s32file.h>
    23 #include "t_wservintegstepbase.h"
    24 #include "t_wservconsts.h"
    25 
    26 /**
    27  CT_WServIntegStep constructor.
    28  @return N/A
    29  @pre None
    30  @post CT_WServIntegStep 1st stage constructor
    31 */
    32 CT_WServIntegStep::CT_WServIntegStep()
    33 	{
    34 	SetTestStepName(KT_WServIntegStep);
    35 	}
    36 
    37 CT_WServIntegStep::~CT_WServIntegStep()
    38 	{
    39 	iFs.Close();
    40 	}
    41 
    42 /**
    43 Starts test step
    44 @internalComponent
    45 @return TVerdict pass / fail
    46 @pre N/A
    47 @post N/A
    48 */
    49 enum TVerdict CT_WServIntegStep::doTestStepL()
    50 	{
    51 	__UHEAP_MARK;
    52 
    53 	ERR_PRINTF1(_L("Executing Base class"));
    54 
    55 	__UHEAP_MARKEND;
    56 
    57 	return TestStepResult();
    58 	}
    59 
    60 void CT_WServIntegStep::WaitForTestL(const TDesC& aFileName, const TInt& aMaxTimeSeconds)
    61 	{
    62 	RFile myFile;
    63 	TInt err = KErrNotFound;
    64 
    65 	TInt endTimer = aMaxTimeSeconds*1000000; // convert to milli secs
    66 	TInt myTimer = 0;
    67 
    68 	err = myFile.Open(iFs,aFileName,EFileRead);
    69 
    70 	while (err != KErrNone && myTimer < endTimer)
    71 		{
    72 		myTimer += 500000;
    73 		User::After(500000);
    74 		err = myFile.Open(iFs,aFileName,EFileRead);
    75 		}
    76 
    77 
    78 	if (err != KErrNotFound)
    79 		{
    80 		myFile.Close();
    81 		iFileList.AppendL(&aFileName);
    82 		}
    83 	}
    84 
    85 void CT_WServIntegStep::GetConfigDataL(const TDesC& aData, const TDesC& aName)
    86 	{
    87 	TBool								moreData=ETrue;
    88 	TInt								index=0;
    89 	TBuf<KMaxTestExecuteCommandLength>	tempStore;
    90 	TPtrC								data;
    91 	TPtrC								name;
    92 
    93 	// populate config data with that contained in [default] section
    94 	while ( moreData )
    95 		{
    96 		tempStore.Format(aData, ++index);
    97 		moreData=GetStringFromConfig(KDefaultSectionName(), tempStore, data);
    98 		if ( moreData )
    99 			{
   100 			tempStore.Format(aName, index);
   101 			moreData=GetStringFromConfig(KDefaultSectionName(), tempStore, name);
   102 
   103 			if ( moreData )
   104 				{
   105 				iWServConfigData.AddDataL(name, data);
   106 				}
   107 			else
   108 				{
   109 				ERR_PRINTF2(_L("data %S has no name"), &data);
   110 				SetTestStepResult(EFail);
   111 				}
   112 			}
   113 		}
   114 
   115 	// update config data with that contained in the config section
   116 	// appropriate to the test case being executed
   117 	moreData=ETrue;
   118 	index = 0;
   119 	while ( moreData )
   120 		{
   121 		tempStore.Format(aData, ++index);
   122 		moreData=GetStringFromConfig(ConfigSection(), tempStore, data);
   123 		if ( moreData )
   124 			{
   125 			tempStore.Format(aName, index);
   126 			moreData=GetStringFromConfig(ConfigSection(), tempStore, name);
   127 
   128 			if ( moreData )
   129 				{
   130 				TRAPD(err,iWServConfigData.AddDataL(name, data));
   131 				if (err==KErrAlreadyExists)
   132 					{
   133 					iWServConfigData.ReplaceData(name, data);
   134 					}
   135 				else
   136 					{
   137 					if (err != KErrNone)
   138 						{
   139 						User::Leave(err);
   140 						}
   141 					}
   142 				}
   143 			else
   144 				{
   145 				ERR_PRINTF2(_L("data %S has no name"), &data);
   146 				SetTestStepResult(EFail);
   147 				}
   148 			}
   149 		}
   150 	}
   151 
   152 void CT_WServIntegStep::PrintConfigDataL(const TDesC& aFileName)
   153 	{
   154 	RFileWriteStream writer;
   155 	writer.PushL(); // writer on cleanup stack
   156 	TInt err = iFs.MkDirAll(aFileName);
   157 	TEST(err==KErrNone||err==KErrAlreadyExists);
   158 	INFO_PRINTF2(_L("Create Config File: %S"), &aFileName);
   159 	User::LeaveIfError(writer.Replace(iFs, aFileName, EFileStreamText|EFileWrite));
   160 	writer.CommitL();
   161 	CleanupStack::PopAndDestroy(&writer); // writer
   162 
   163 	CIniData* myData=CIniData::NewL(aFileName);
   164 	CleanupStack::PushL(myData);
   165 
   166 	for (TInt index=0;index<iWServConfigData.NoOfEntriesL();index++)
   167 		{
   168 		TPtrC name = iWServConfigData.GetName(index);
   169 		TPtrC data = iWServConfigData.GetData(index);
   170 		INFO_PRINTF3(_L("Config Name: %S, \t\tConfig Data: %S"), &name, &data);
   171 
   172 		TInt err = myData->AddValue(KDefaultSectionName, name, data);
   173 		INFO_PRINTF3(_L("AddValue - Expected: %d, Actual: %d"), KErrNone, err);
   174 		TEST(err==KErrNone);
   175 		}
   176 
   177 	myData->WriteToFileL();
   178 	iFileList.AppendL(&aFileName);
   179 	CleanupStack::PopAndDestroy(myData);
   180 	}
   181 
   182 void CT_WServIntegStep::CheckResultsL(const TDesC& aData, const TDesC& aName,const TDesC& aFileName)
   183 	{
   184 	GetConfigDataL(aData,aName);
   185 
   186 	CIniData* myData=CIniData::NewL(aFileName);
   187 	iFileList.AppendL(&aFileName);
   188 	CleanupStack::PushL(myData);
   189 
   190 	for (TInt index=0;index<iWServConfigData.NoOfEntriesL();index++)
   191 		{
   192 		TPtrC name = iWServConfigData.GetName(index);
   193 		TPtrC data = iWServConfigData.GetData(index);
   194 
   195 		TPtrC actData;
   196 		TBool found = myData->FindVar(KDefaultSectionName, name, actData);
   197 		if (found)
   198 			{
   199 			INFO_PRINTF4(_L("Result: %S, Expected: %S, Actual: %S"), &name, &data, &actData);
   200 			TEST(actData==data);
   201 			}
   202 		else
   203 			{
   204 			#ifdef __WINS__
   205 			ERR_PRINTF3(_L("NOT FOUND: Result: %S, \t\tExpected Value: %S"), &name, &data);
   206 			#else
   207 			// in the case of a non-debug build then KDsaRotationAbortTimeoutCount cannot
   208 			// be measured, and hence is ignored.
   209 			if (name.Compare(_L("KDsaRotationAbortTimeoutCount"))!=KErrNone)
   210 				{
   211 				ERR_PRINTF3(_L("NOT FOUND: Result: %S, \t\tExpected Value: %S"), &name, &data);
   212 				}
   213 			#endif
   214 			}
   215 		}
   216 
   217 	CleanupStack::PopAndDestroy(myData);
   218 
   219 	ClearConfigData();
   220 	}
   221 
   222 void CT_WServIntegStep::PrintResultsL(const TDesC& aFileName)
   223 	{
   224 	RFile resultFile;
   225 	CleanupClosePushL(resultFile);
   226 	User::LeaveIfError(resultFile.Open(iFs,aFileName,EFileRead));
   227 
   228 	TInt size = 0;
   229 	User::LeaveIfError(resultFile.Size(size));
   230 	TText* data=(TText*)User::AllocL(size);
   231 	CleanupStack::PushL(data);
   232 	TPtr8 resultData((TUint8*)data, 0, size);;
   233 	resultFile.Read(resultData);
   234 	TUint8* ptr = (TUint8*)data;
   235 
   236 	// NON-UNICODE so convert to UNICODE
   237 	TText* newdata = (TText*)User::AllocL(size*sizeof(TText));
   238 	CleanupStack::PushL(newdata);
   239 	TPtr printData(newdata, size, size);
   240 	for(TInt i=0 ; i<size ; ++i)
   241 		{
   242 		printData[i]=ptr[i];
   243 		}
   244 
   245 	INFO_PRINTF2(_L("Printing result file: %S"), &aFileName);
   246 	INFO_PRINTF2(_L("%S"), &printData);
   247 
   248 	CleanupStack::PopAndDestroy(3);
   249 
   250 	//resultFile.Close();
   251 	}
   252 
   253 TInt CT_WServIntegStep::CreateTestProcessL(const TDesC& aApp, const TProcessPriority& aPriority)
   254 	{
   255 	INFO_PRINTF2(_L("Starting App: %S"), &aApp);
   256 
   257 	RProcess process;
   258 	TInt createErr = process.Create(aApp, KNullDesC);
   259 
   260 	if (createErr == KErrNone)
   261 		{
   262 		process.SetPriority(aPriority);
   263 		TEST(process.Priority()==aPriority);
   264 		INFO_PRINTF3(_L("Process Priority: Actual: %d, Expected: %d"), process.Priority(), aPriority);
   265 		process.Resume();
   266 		iProcessList.AppendL(process);
   267 		}
   268 
   269 	return createErr;
   270 	}
   271 
   272 void CT_WServIntegStep::ClearConfigData()
   273 	{
   274 	iWServConfigData.Empty();
   275 	}
   276 
   277 void CT_WServIntegStep::CleanUp()
   278 	{
   279 	INFO_PRINTF1(_L("Test clean up"));
   280 
   281 	TInt count = iProcessList.Count();
   282 
   283 	TInt index;
   284 	for (index = 0; index < count; index++)
   285 		{
   286 		// check process
   287 		INFO_PRINTF3(_L("Process Check: Actual: %d, Expected: %d"), iProcessList[index].ExitReason(), KErrNone);
   288 		TEST(iProcessList[index].ExitReason()==KErrNone);
   289 		// kill process
   290 		iProcessList[index].Kill(KErrGeneral);
   291 		INFO_PRINTF3(_L("Process Exit Reason: Actual: %d, Expected: %d"), iProcessList[index].ExitReason(), KErrGeneral);
   292 		TEST(iProcessList[index].ExitReason()==KErrGeneral);
   293 		}
   294 
   295 	iProcessList.Reset();
   296 
   297 	count = iFileList.Count();
   298 	for (index = 0; index < count; index++)
   299 		{
   300 		INFO_PRINTF2(_L("Deleting Config File Name: %S"), iFileList[index]);
   301 		TInt err = iFs.Delete(*iFileList[index]);
   302 		TEST(err==KErrNone);
   303 		}
   304 
   305 	iFileList.Reset();
   306 
   307 	ClearConfigData();
   308 	}
   309 
   310 void CT_WServIntegStep::PrintTestStepName()
   311 	{
   312 	//Print out the test step name in epocwind.out
   313 	RDebug::Print(_L("************************************************************"));
   314 	RDebug::Print(_L("*** Starting Test Step %S"), &(ConfigSection()));
   315 	// debug statement to indicate progress of test suite by
   316 	// printing the sub-test that is currently active
   317 	TTime timeStamp;
   318 	timeStamp.HomeTime();
   319 	TBuf<50> dateStr;
   320 	_LIT(KDateString3,"%-B%:0%J%:1%T%:2%S%:3 %Cms");
   321 	timeStamp.FormatL(dateStr, KDateString3);
   322 	RDebug::Print(_L("*** Time Stamp - %S"), &dateStr);
   323 	RDebug::Print(_L("************************************************************"));
   324 	}
   325 
   326 enum TVerdict CT_WServIntegStep::doTestStepPreambleL()
   327 	{
   328 	TVerdict	ret=CTestStep::doTestStepPreambleL();
   329 
   330 	User::LeaveIfError(iFs.Connect());
   331 
   332 	return ret;
   333 	}
   334 
   335 enum TVerdict CT_WServIntegStep::doTestStepPostambleL()
   336 	{
   337 	return TestStepResult();
   338 	}