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