1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/t_integ/src/t_wservintegstepbase.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,338 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent
1.23 +*/
1.24 +
1.25 +#include <s32file.h>
1.26 +#include "t_wservintegstepbase.h"
1.27 +#include "t_wservconsts.h"
1.28 +
1.29 +/**
1.30 + CT_WServIntegStep constructor.
1.31 + @return N/A
1.32 + @pre None
1.33 + @post CT_WServIntegStep 1st stage constructor
1.34 +*/
1.35 +CT_WServIntegStep::CT_WServIntegStep()
1.36 + {
1.37 + SetTestStepName(KT_WServIntegStep);
1.38 + }
1.39 +
1.40 +CT_WServIntegStep::~CT_WServIntegStep()
1.41 + {
1.42 + iFs.Close();
1.43 + }
1.44 +
1.45 +/**
1.46 +Starts test step
1.47 +@internalComponent
1.48 +@return TVerdict pass / fail
1.49 +@pre N/A
1.50 +@post N/A
1.51 +*/
1.52 +enum TVerdict CT_WServIntegStep::doTestStepL()
1.53 + {
1.54 + __UHEAP_MARK;
1.55 +
1.56 + ERR_PRINTF1(_L("Executing Base class"));
1.57 +
1.58 + __UHEAP_MARKEND;
1.59 +
1.60 + return TestStepResult();
1.61 + }
1.62 +
1.63 +void CT_WServIntegStep::WaitForTestL(const TDesC& aFileName, const TInt& aMaxTimeSeconds)
1.64 + {
1.65 + RFile myFile;
1.66 + TInt err = KErrNotFound;
1.67 +
1.68 + TInt endTimer = aMaxTimeSeconds*1000000; // convert to milli secs
1.69 + TInt myTimer = 0;
1.70 +
1.71 + err = myFile.Open(iFs,aFileName,EFileRead);
1.72 +
1.73 + while (err != KErrNone && myTimer < endTimer)
1.74 + {
1.75 + myTimer += 500000;
1.76 + User::After(500000);
1.77 + err = myFile.Open(iFs,aFileName,EFileRead);
1.78 + }
1.79 +
1.80 +
1.81 + if (err != KErrNotFound)
1.82 + {
1.83 + myFile.Close();
1.84 + iFileList.AppendL(&aFileName);
1.85 + }
1.86 + }
1.87 +
1.88 +void CT_WServIntegStep::GetConfigDataL(const TDesC& aData, const TDesC& aName)
1.89 + {
1.90 + TBool moreData=ETrue;
1.91 + TInt index=0;
1.92 + TBuf<KMaxTestExecuteCommandLength> tempStore;
1.93 + TPtrC data;
1.94 + TPtrC name;
1.95 +
1.96 + // populate config data with that contained in [default] section
1.97 + while ( moreData )
1.98 + {
1.99 + tempStore.Format(aData, ++index);
1.100 + moreData=GetStringFromConfig(KDefaultSectionName(), tempStore, data);
1.101 + if ( moreData )
1.102 + {
1.103 + tempStore.Format(aName, index);
1.104 + moreData=GetStringFromConfig(KDefaultSectionName(), tempStore, name);
1.105 +
1.106 + if ( moreData )
1.107 + {
1.108 + iWServConfigData.AddDataL(name, data);
1.109 + }
1.110 + else
1.111 + {
1.112 + ERR_PRINTF2(_L("data %S has no name"), &data);
1.113 + SetTestStepResult(EFail);
1.114 + }
1.115 + }
1.116 + }
1.117 +
1.118 + // update config data with that contained in the config section
1.119 + // appropriate to the test case being executed
1.120 + moreData=ETrue;
1.121 + index = 0;
1.122 + while ( moreData )
1.123 + {
1.124 + tempStore.Format(aData, ++index);
1.125 + moreData=GetStringFromConfig(ConfigSection(), tempStore, data);
1.126 + if ( moreData )
1.127 + {
1.128 + tempStore.Format(aName, index);
1.129 + moreData=GetStringFromConfig(ConfigSection(), tempStore, name);
1.130 +
1.131 + if ( moreData )
1.132 + {
1.133 + TRAPD(err,iWServConfigData.AddDataL(name, data));
1.134 + if (err==KErrAlreadyExists)
1.135 + {
1.136 + iWServConfigData.ReplaceData(name, data);
1.137 + }
1.138 + else
1.139 + {
1.140 + if (err != KErrNone)
1.141 + {
1.142 + User::Leave(err);
1.143 + }
1.144 + }
1.145 + }
1.146 + else
1.147 + {
1.148 + ERR_PRINTF2(_L("data %S has no name"), &data);
1.149 + SetTestStepResult(EFail);
1.150 + }
1.151 + }
1.152 + }
1.153 + }
1.154 +
1.155 +void CT_WServIntegStep::PrintConfigDataL(const TDesC& aFileName)
1.156 + {
1.157 + RFileWriteStream writer;
1.158 + writer.PushL(); // writer on cleanup stack
1.159 + TInt err = iFs.MkDirAll(aFileName);
1.160 + TEST(err==KErrNone||err==KErrAlreadyExists);
1.161 + INFO_PRINTF2(_L("Create Config File: %S"), &aFileName);
1.162 + User::LeaveIfError(writer.Replace(iFs, aFileName, EFileStreamText|EFileWrite));
1.163 + writer.CommitL();
1.164 + CleanupStack::PopAndDestroy(&writer); // writer
1.165 +
1.166 + CIniData* myData=CIniData::NewL(aFileName);
1.167 + CleanupStack::PushL(myData);
1.168 +
1.169 + for (TInt index=0;index<iWServConfigData.NoOfEntriesL();index++)
1.170 + {
1.171 + TPtrC name = iWServConfigData.GetName(index);
1.172 + TPtrC data = iWServConfigData.GetData(index);
1.173 + INFO_PRINTF3(_L("Config Name: %S, \t\tConfig Data: %S"), &name, &data);
1.174 +
1.175 + TInt err = myData->AddValue(KDefaultSectionName, name, data);
1.176 + INFO_PRINTF3(_L("AddValue - Expected: %d, Actual: %d"), KErrNone, err);
1.177 + TEST(err==KErrNone);
1.178 + }
1.179 +
1.180 + myData->WriteToFileL();
1.181 + iFileList.AppendL(&aFileName);
1.182 + CleanupStack::PopAndDestroy(myData);
1.183 + }
1.184 +
1.185 +void CT_WServIntegStep::CheckResultsL(const TDesC& aData, const TDesC& aName,const TDesC& aFileName)
1.186 + {
1.187 + GetConfigDataL(aData,aName);
1.188 +
1.189 + CIniData* myData=CIniData::NewL(aFileName);
1.190 + iFileList.AppendL(&aFileName);
1.191 + CleanupStack::PushL(myData);
1.192 +
1.193 + for (TInt index=0;index<iWServConfigData.NoOfEntriesL();index++)
1.194 + {
1.195 + TPtrC name = iWServConfigData.GetName(index);
1.196 + TPtrC data = iWServConfigData.GetData(index);
1.197 +
1.198 + TPtrC actData;
1.199 + TBool found = myData->FindVar(KDefaultSectionName, name, actData);
1.200 + if (found)
1.201 + {
1.202 + INFO_PRINTF4(_L("Result: %S, Expected: %S, Actual: %S"), &name, &data, &actData);
1.203 + TEST(actData==data);
1.204 + }
1.205 + else
1.206 + {
1.207 + #ifdef __WINS__
1.208 + ERR_PRINTF3(_L("NOT FOUND: Result: %S, \t\tExpected Value: %S"), &name, &data);
1.209 + #else
1.210 + // in the case of a non-debug build then KDsaRotationAbortTimeoutCount cannot
1.211 + // be measured, and hence is ignored.
1.212 + if (name.Compare(_L("KDsaRotationAbortTimeoutCount"))!=KErrNone)
1.213 + {
1.214 + ERR_PRINTF3(_L("NOT FOUND: Result: %S, \t\tExpected Value: %S"), &name, &data);
1.215 + }
1.216 + #endif
1.217 + }
1.218 + }
1.219 +
1.220 + CleanupStack::PopAndDestroy(myData);
1.221 +
1.222 + ClearConfigData();
1.223 + }
1.224 +
1.225 +void CT_WServIntegStep::PrintResultsL(const TDesC& aFileName)
1.226 + {
1.227 + RFile resultFile;
1.228 + CleanupClosePushL(resultFile);
1.229 + User::LeaveIfError(resultFile.Open(iFs,aFileName,EFileRead));
1.230 +
1.231 + TInt size = 0;
1.232 + User::LeaveIfError(resultFile.Size(size));
1.233 + TText* data=(TText*)User::AllocL(size);
1.234 + CleanupStack::PushL(data);
1.235 + TPtr8 resultData((TUint8*)data, 0, size);;
1.236 + resultFile.Read(resultData);
1.237 + TUint8* ptr = (TUint8*)data;
1.238 +
1.239 + // NON-UNICODE so convert to UNICODE
1.240 + TText* newdata = (TText*)User::AllocL(size*sizeof(TText));
1.241 + CleanupStack::PushL(newdata);
1.242 + TPtr printData(newdata, size, size);
1.243 + for(TInt i=0 ; i<size ; ++i)
1.244 + {
1.245 + printData[i]=ptr[i];
1.246 + }
1.247 +
1.248 + INFO_PRINTF2(_L("Printing result file: %S"), &aFileName);
1.249 + INFO_PRINTF2(_L("%S"), &printData);
1.250 +
1.251 + CleanupStack::PopAndDestroy(3);
1.252 +
1.253 + //resultFile.Close();
1.254 + }
1.255 +
1.256 +TInt CT_WServIntegStep::CreateTestProcessL(const TDesC& aApp, const TProcessPriority& aPriority)
1.257 + {
1.258 + INFO_PRINTF2(_L("Starting App: %S"), &aApp);
1.259 +
1.260 + RProcess process;
1.261 + TInt createErr = process.Create(aApp, KNullDesC);
1.262 +
1.263 + if (createErr == KErrNone)
1.264 + {
1.265 + process.SetPriority(aPriority);
1.266 + TEST(process.Priority()==aPriority);
1.267 + INFO_PRINTF3(_L("Process Priority: Actual: %d, Expected: %d"), process.Priority(), aPriority);
1.268 + process.Resume();
1.269 + iProcessList.AppendL(process);
1.270 + }
1.271 +
1.272 + return createErr;
1.273 + }
1.274 +
1.275 +void CT_WServIntegStep::ClearConfigData()
1.276 + {
1.277 + iWServConfigData.Empty();
1.278 + }
1.279 +
1.280 +void CT_WServIntegStep::CleanUp()
1.281 + {
1.282 + INFO_PRINTF1(_L("Test clean up"));
1.283 +
1.284 + TInt count = iProcessList.Count();
1.285 +
1.286 + TInt index;
1.287 + for (index = 0; index < count; index++)
1.288 + {
1.289 + // check process
1.290 + INFO_PRINTF3(_L("Process Check: Actual: %d, Expected: %d"), iProcessList[index].ExitReason(), KErrNone);
1.291 + TEST(iProcessList[index].ExitReason()==KErrNone);
1.292 + // kill process
1.293 + iProcessList[index].Kill(KErrGeneral);
1.294 + INFO_PRINTF3(_L("Process Exit Reason: Actual: %d, Expected: %d"), iProcessList[index].ExitReason(), KErrGeneral);
1.295 + TEST(iProcessList[index].ExitReason()==KErrGeneral);
1.296 + }
1.297 +
1.298 + iProcessList.Reset();
1.299 +
1.300 + count = iFileList.Count();
1.301 + for (index = 0; index < count; index++)
1.302 + {
1.303 + INFO_PRINTF2(_L("Deleting Config File Name: %S"), iFileList[index]);
1.304 + TInt err = iFs.Delete(*iFileList[index]);
1.305 + TEST(err==KErrNone);
1.306 + }
1.307 +
1.308 + iFileList.Reset();
1.309 +
1.310 + ClearConfigData();
1.311 + }
1.312 +
1.313 +void CT_WServIntegStep::PrintTestStepName()
1.314 + {
1.315 + //Print out the test step name in epocwind.out
1.316 + RDebug::Print(_L("************************************************************"));
1.317 + RDebug::Print(_L("*** Starting Test Step %S"), &(ConfigSection()));
1.318 + // debug statement to indicate progress of test suite by
1.319 + // printing the sub-test that is currently active
1.320 + TTime timeStamp;
1.321 + timeStamp.HomeTime();
1.322 + TBuf<50> dateStr;
1.323 + _LIT(KDateString3,"%-B%:0%J%:1%T%:2%S%:3 %Cms");
1.324 + timeStamp.FormatL(dateStr, KDateString3);
1.325 + RDebug::Print(_L("*** Time Stamp - %S"), &dateStr);
1.326 + RDebug::Print(_L("************************************************************"));
1.327 + }
1.328 +
1.329 +enum TVerdict CT_WServIntegStep::doTestStepPreambleL()
1.330 + {
1.331 + TVerdict ret=CTestStep::doTestStepPreambleL();
1.332 +
1.333 + User::LeaveIfError(iFs.Connect());
1.334 +
1.335 + return ret;
1.336 + }
1.337 +
1.338 +enum TVerdict CT_WServIntegStep::doTestStepPostambleL()
1.339 + {
1.340 + return TestStepResult();
1.341 + }