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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
23 #include "t_wservintegstepbase.h"
24 #include "t_wservconsts.h"
27 CT_WServIntegStep constructor.
30 @post CT_WServIntegStep 1st stage constructor
32 CT_WServIntegStep::CT_WServIntegStep()
34 SetTestStepName(KT_WServIntegStep);
37 CT_WServIntegStep::~CT_WServIntegStep()
45 @return TVerdict pass / fail
49 enum TVerdict CT_WServIntegStep::doTestStepL()
53 ERR_PRINTF1(_L("Executing Base class"));
57 return TestStepResult();
60 void CT_WServIntegStep::WaitForTestL(const TDesC& aFileName, const TInt& aMaxTimeSeconds)
63 TInt err = KErrNotFound;
65 TInt endTimer = aMaxTimeSeconds*1000000; // convert to milli secs
68 err = myFile.Open(iFs,aFileName,EFileRead);
70 while (err != KErrNone && myTimer < endTimer)
74 err = myFile.Open(iFs,aFileName,EFileRead);
78 if (err != KErrNotFound)
81 iFileList.AppendL(&aFileName);
85 void CT_WServIntegStep::GetConfigDataL(const TDesC& aData, const TDesC& aName)
89 TBuf<KMaxTestExecuteCommandLength> tempStore;
93 // populate config data with that contained in [default] section
96 tempStore.Format(aData, ++index);
97 moreData=GetStringFromConfig(KDefaultSectionName(), tempStore, data);
100 tempStore.Format(aName, index);
101 moreData=GetStringFromConfig(KDefaultSectionName(), tempStore, name);
105 iWServConfigData.AddDataL(name, data);
109 ERR_PRINTF2(_L("data %S has no name"), &data);
110 SetTestStepResult(EFail);
115 // update config data with that contained in the config section
116 // appropriate to the test case being executed
121 tempStore.Format(aData, ++index);
122 moreData=GetStringFromConfig(ConfigSection(), tempStore, data);
125 tempStore.Format(aName, index);
126 moreData=GetStringFromConfig(ConfigSection(), tempStore, name);
130 TRAPD(err,iWServConfigData.AddDataL(name, data));
131 if (err==KErrAlreadyExists)
133 iWServConfigData.ReplaceData(name, data);
145 ERR_PRINTF2(_L("data %S has no name"), &data);
146 SetTestStepResult(EFail);
152 void CT_WServIntegStep::PrintConfigDataL(const TDesC& aFileName)
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));
161 CleanupStack::PopAndDestroy(&writer); // writer
163 CIniData* myData=CIniData::NewL(aFileName);
164 CleanupStack::PushL(myData);
166 for (TInt index=0;index<iWServConfigData.NoOfEntriesL();index++)
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);
172 TInt err = myData->AddValue(KDefaultSectionName, name, data);
173 INFO_PRINTF3(_L("AddValue - Expected: %d, Actual: %d"), KErrNone, err);
177 myData->WriteToFileL();
178 iFileList.AppendL(&aFileName);
179 CleanupStack::PopAndDestroy(myData);
182 void CT_WServIntegStep::CheckResultsL(const TDesC& aData, const TDesC& aName,const TDesC& aFileName)
184 GetConfigDataL(aData,aName);
186 CIniData* myData=CIniData::NewL(aFileName);
187 iFileList.AppendL(&aFileName);
188 CleanupStack::PushL(myData);
190 for (TInt index=0;index<iWServConfigData.NoOfEntriesL();index++)
192 TPtrC name = iWServConfigData.GetName(index);
193 TPtrC data = iWServConfigData.GetData(index);
196 TBool found = myData->FindVar(KDefaultSectionName, name, actData);
199 INFO_PRINTF4(_L("Result: %S, Expected: %S, Actual: %S"), &name, &data, &actData);
205 ERR_PRINTF3(_L("NOT FOUND: Result: %S, \t\tExpected Value: %S"), &name, &data);
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)
211 ERR_PRINTF3(_L("NOT FOUND: Result: %S, \t\tExpected Value: %S"), &name, &data);
217 CleanupStack::PopAndDestroy(myData);
222 void CT_WServIntegStep::PrintResultsL(const TDesC& aFileName)
225 CleanupClosePushL(resultFile);
226 User::LeaveIfError(resultFile.Open(iFs,aFileName,EFileRead));
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;
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)
245 INFO_PRINTF2(_L("Printing result file: %S"), &aFileName);
246 INFO_PRINTF2(_L("%S"), &printData);
248 CleanupStack::PopAndDestroy(3);
250 //resultFile.Close();
253 TInt CT_WServIntegStep::CreateTestProcessL(const TDesC& aApp, const TProcessPriority& aPriority)
255 INFO_PRINTF2(_L("Starting App: %S"), &aApp);
258 TInt createErr = process.Create(aApp, KNullDesC);
260 if (createErr == KErrNone)
262 process.SetPriority(aPriority);
263 TEST(process.Priority()==aPriority);
264 INFO_PRINTF3(_L("Process Priority: Actual: %d, Expected: %d"), process.Priority(), aPriority);
266 iProcessList.AppendL(process);
272 void CT_WServIntegStep::ClearConfigData()
274 iWServConfigData.Empty();
277 void CT_WServIntegStep::CleanUp()
279 INFO_PRINTF1(_L("Test clean up"));
281 TInt count = iProcessList.Count();
284 for (index = 0; index < count; index++)
287 INFO_PRINTF3(_L("Process Check: Actual: %d, Expected: %d"), iProcessList[index].ExitReason(), KErrNone);
288 TEST(iProcessList[index].ExitReason()==KErrNone);
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);
295 iProcessList.Reset();
297 count = iFileList.Count();
298 for (index = 0; index < count; index++)
300 INFO_PRINTF2(_L("Deleting Config File Name: %S"), iFileList[index]);
301 TInt err = iFs.Delete(*iFileList[index]);
310 void CT_WServIntegStep::PrintTestStepName()
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
318 timeStamp.HomeTime();
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("************************************************************"));
326 enum TVerdict CT_WServIntegStep::doTestStepPreambleL()
328 TVerdict ret=CTestStep::doTestStepPreambleL();
330 User::LeaveIfError(iFs.Connect());
335 enum TVerdict CT_WServIntegStep::doTestStepPostambleL()
337 return TestStepResult();