|
1 // Copyright (c) 2005-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 // This test requires Cone\Tef\TConeTestExe to be built first.\n |
|
15 // This test is fully automated and performs the following tasks\n |
|
16 // 1. Launches TConeTestExe.\n |
|
17 // 2. Closes TConeTestExe.\n |
|
18 // 3. Compares the standard results file with results file generated by TConeTestExe.\n |
|
19 // |
|
20 // |
|
21 |
|
22 /** |
|
23 @file |
|
24 @internalComponent - Internal Symbian test code |
|
25 */ |
|
26 #include <e32test.h> |
|
27 #include <coemain.h> |
|
28 #include <coecntrl.h> |
|
29 #include <coeaui.h> |
|
30 #include <e32keys.h> |
|
31 #include <basched.h> |
|
32 #include <apgtask.h> |
|
33 #include <apacmdln.h> |
|
34 #include <apgcli.h> |
|
35 #include <apgwgnam.h> |
|
36 #include <e32base.h> |
|
37 #include <eikenv.h> |
|
38 #include <ecom/ecom.h> |
|
39 |
|
40 #include "TCone4StepExe.h" |
|
41 //! Sample Executable Name used in TCone4 TestExe Step.\n |
|
42 _LIT(KAppName, "TConeTestExe"); |
|
43 //! Executable launched in TCone4 TestExe Step.\n |
|
44 _LIT(KAppFileName, "z:\\sys\\bin\\TConeTestExe.exe"); |
|
45 |
|
46 |
|
47 //! File which stores the results of TCone4Step . |
|
48 _LIT(KConeTestResultsFileName, "c:\\system\\conetest\\ConeTestResultsFile2.txt"); |
|
49 |
|
50 //! File which contains the expected results which needs to be compared with the results |
|
51 //! generated form the test |
|
52 _LIT(KConeTestStdFileName,"z:\\conetest\\ConeTestStdFile.txt"); |
|
53 |
|
54 //!random error code |
|
55 const TInt KErrFileContentNotMatched = -421; |
|
56 |
|
57 //! A CTestCoeAppUi derived class.\n |
|
58 /** |
|
59 The class is the AppUi class for the TCone4Step test case.\n |
|
60 */ |
|
61 class CCone4ExeTestAppUi : public CTestCoeAppUi |
|
62 { |
|
63 public: // from CCoeAppUi |
|
64 //! Single Argument Constructor for CCone4ExeTestAppUi Class.\n |
|
65 CCone4ExeTestAppUi(CTmsTestStep* aStep) : |
|
66 CTestCoeAppUi(aStep){} |
|
67 ~CCone4ExeTestAppUi(); |
|
68 // from CCoeAppUi |
|
69 void ConstructL(); |
|
70 void RunTestStepL(TInt aNumStep); |
|
71 |
|
72 void LoadAppL(); |
|
73 void CompareConeTestFileL(); |
|
74 TInt CloseApp(); |
|
75 }; |
|
76 /** |
|
77 Second phase constructor for the CCone4ExeTestAppUi class.\n |
|
78 Invokes the base class CTestCoeAppUi ConstructL function.\n |
|
79 Starts the asynchronous execution of tests using Auto test manager.\n |
|
80 */ |
|
81 void CCone4ExeTestAppUi::ConstructL() |
|
82 { |
|
83 CTestCoeAppUi::ConstructL(); |
|
84 AutoTestManager().StartAutoTest(); |
|
85 } |
|
86 |
|
87 /** |
|
88 Destructor for CCone4ExeTestAppUi class.\n |
|
89 */ |
|
90 CCone4ExeTestAppUi::~CCone4ExeTestAppUi() |
|
91 { |
|
92 } |
|
93 /** |
|
94 Auxilliary Function for all test cases.\n |
|
95 This function is iteratively called by the RunL function of the Autotestmanager |
|
96 asynchronously.\n |
|
97 Calls the following functions in succession\n |
|
98 1. LoadAppL()\n |
|
99 2. CloseApp()\n |
|
100 3. CompareConeTestFileL()\n |
|
101 */ |
|
102 void CCone4ExeTestAppUi::RunTestStepL(TInt aNumStep) |
|
103 { |
|
104 User::After(TTimeIntervalMicroSeconds32(2000000)); |
|
105 switch(aNumStep) |
|
106 { |
|
107 case 1: |
|
108 { |
|
109 SetTestStepID(_L("UIF-TCone4StepExe-LoadAppL")); |
|
110 INFO_PRINTF1(_L("Loading TConeTestApp")); |
|
111 TRAPD(ret, LoadAppL()); |
|
112 TEST(ret==KErrNone); |
|
113 RecordTestResultL(); |
|
114 } |
|
115 break; |
|
116 case 2: |
|
117 SetTestStepID(_L("UIF-TCone4StepExe-CloseApp")); |
|
118 INFO_PRINTF1(_L("Closing TConeTestApp")); |
|
119 TEST(CloseApp()==KErrNone); |
|
120 RecordTestResultL(); |
|
121 break; |
|
122 case 3: |
|
123 { |
|
124 SetTestStepID(_L("UIF-TCone4StepExe-CompareConeTestFileL")); |
|
125 INFO_PRINTF1(_L("Comparing the results file with standard results file")); |
|
126 TRAPD(ret, CompareConeTestFileL()); |
|
127 TEST(ret==KErrNone); |
|
128 RecordTestResultL(); |
|
129 CloseTMSGraphicsStep(); |
|
130 } |
|
131 break; |
|
132 case 4: |
|
133 AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass); |
|
134 break; |
|
135 default: |
|
136 break; |
|
137 } |
|
138 } |
|
139 |
|
140 /** |
|
141 @SYMTestCaseID UIF-TCone4StepExe-LoadAppL |
|
142 |
|
143 @SYMPREQ |
|
144 |
|
145 @SYMTestCaseDesc Launches the TConeTestApp application.\n |
|
146 |
|
147 @SYMTestPriority High |
|
148 |
|
149 @SYMTestStatus Implemented |
|
150 |
|
151 @SYMTestActions : Launches an test application as follows.\n |
|
152 Instantiates a CApaCommandLine object and sets the appName as the LibraryName.\n |
|
153 Sets the command to EApaCommandOpen.\n |
|
154 Opens a RApaLsSession.\n |
|
155 Sends a request to the apparc server to start the application.\n |
|
156 |
|
157 @SYMTestExpectedResults The application should be started without any error.\n |
|
158 |
|
159 @SYMTestType : CIT |
|
160 */ |
|
161 void CCone4ExeTestAppUi::LoadAppL() |
|
162 { |
|
163 TBuf<256> fileNameBuf(KAppFileName()); |
|
164 TFileName appName = fileNameBuf; |
|
165 |
|
166 CApaCommandLine* cmdLine=CApaCommandLine::NewLC(); |
|
167 cmdLine->SetExecutableNameL(appName); |
|
168 cmdLine->SetCommandL(EApaCommandOpen); |
|
169 RApaLsSession ls; |
|
170 |
|
171 User::LeaveIfError(ls.Connect()); |
|
172 CleanupClosePushL(ls); |
|
173 User::LeaveIfError(ls.StartApp(*cmdLine)); |
|
174 CleanupStack::PopAndDestroy(2); // ls and cmdLine |
|
175 } |
|
176 |
|
177 |
|
178 /** |
|
179 @SYMTestCaseID UIF-TCone4StepExe-CloseApp |
|
180 |
|
181 @SYMPREQ |
|
182 |
|
183 @SYMTestCaseDesc Closes the TConeTestApp application.\n |
|
184 |
|
185 @SYMTestPriority High |
|
186 |
|
187 @SYMTestStatus Implemented |
|
188 |
|
189 @SYMTestActions : Closes a test application as follows.\n |
|
190 Gets the currently running tasks list using TApaTaskList.\n |
|
191 Gets the current task using TApaTaskList::FindApp() \n |
|
192 Ends the application using TApaTaskList::EndTask().\n |
|
193 |
|
194 @SYMTestExpectedResults The application should be closed without any error.\n |
|
195 |
|
196 @SYMTestType : CIT |
|
197 */ |
|
198 |
|
199 TInt CCone4ExeTestAppUi::CloseApp() |
|
200 { |
|
201 TApaTaskList taskList(CCoeEnv::Static()->WsSession()); |
|
202 TApaTask task = taskList.FindApp(KAppName); |
|
203 task.EndTask(); |
|
204 return KErrNone; |
|
205 } |
|
206 |
|
207 /** |
|
208 @SYMTestCaseID UIF-TCone4StepExe-CompareConeTestFileL |
|
209 |
|
210 @SYMPREQ |
|
211 |
|
212 @SYMTestCaseDesc Tests standard results file with the generated results file. |
|
213 |
|
214 @SYMTestPriority High |
|
215 |
|
216 @SYMTestStatus Implemented |
|
217 |
|
218 @SYMTestActions Reads in the standard result file and the one generated. |
|
219 |
|
220 @SYMTestExpectedResults. The test verifies that the files are the same. |
|
221 |
|
222 @SYMTestType : CIT |
|
223 */ |
|
224 void CCone4ExeTestAppUi::CompareConeTestFileL() |
|
225 { |
|
226 RFs fs; |
|
227 RFile rFileResults; |
|
228 RFile rFileStd; |
|
229 |
|
230 User::LeaveIfError(fs.Connect()); |
|
231 CleanupClosePushL( fs ); |
|
232 |
|
233 User::LeaveIfError( rFileResults.Open(fs,KConeTestResultsFileName,EFileRead | EFileShareAny) ); |
|
234 CleanupClosePushL( rFileResults ); |
|
235 |
|
236 User::LeaveIfError( rFileStd.Open(fs,KConeTestStdFileName,EFileRead) ); |
|
237 CleanupClosePushL( rFileStd ); |
|
238 |
|
239 TBuf8<240> bufReadStd; |
|
240 TBuf8<240> bufReadResults; |
|
241 |
|
242 // Read from the results generated for the static object test |
|
243 User::LeaveIfError( rFileResults.Read(bufReadResults) ); |
|
244 // Read from the standard file which contains the results that has to be generated |
|
245 User::LeaveIfError( rFileStd.Read(bufReadStd) ); |
|
246 |
|
247 CleanupStack::PopAndDestroy( 3, &fs ); |
|
248 |
|
249 |
|
250 // Compare the generated results with the standard results |
|
251 if( (bufReadResults.Compare(bufReadStd)) != 0 ) |
|
252 { |
|
253 TBuf<256> resultsWide; |
|
254 TBuf<256> stdWide; |
|
255 resultsWide.Copy( bufReadResults ); |
|
256 stdWide.Copy( bufReadStd ); |
|
257 |
|
258 ERR_PRINTF1( _L("Results files differ.") ); |
|
259 INFO_PRINTF2( _L("results descriptor length %d"), bufReadResults.Length() ); |
|
260 ERR_PRINTF2( _L("Test results:-\n%S"), &resultsWide ); |
|
261 ERR_PRINTF2( _L("Expected results:-\n%S"), &stdWide ); |
|
262 |
|
263 User::Leave( KErrFileContentNotMatched ); |
|
264 } |
|
265 } |
|
266 /** |
|
267 Constructor for CTCone4StepExe class.\n |
|
268 Sets the test step name.\n |
|
269 */ |
|
270 CTCone4StepExe::CTCone4StepExe() |
|
271 { |
|
272 SetTestStepName(KTCone4StepExe); |
|
273 } |
|
274 /** |
|
275 Destructor for CTCone4StepExe class.\n |
|
276 */ |
|
277 CTCone4StepExe::~CTCone4StepExe() |
|
278 { |
|
279 } |
|
280 /** |
|
281 Completes the construction of the Control Environment(CCoeEnv object).\n |
|
282 Instantiates the CCone4TestAppUi class which serves as a AppUi class.\n |
|
283 Sets the CCone4ExeTestAppUi object as the application's user interface object.\n |
|
284 Invokes the second phase constructor of the application's UI.\n |
|
285 */ |
|
286 void CTCone4StepExe::ConstructAppL(CCoeEnv* aCoe) |
|
287 { // runs inside a TRAP harness |
|
288 aCoe->ConstructL(); |
|
289 CCone4ExeTestAppUi* appUi= new (ELeave) CCone4ExeTestAppUi(this); |
|
290 aCoe->SetAppUi(appUi); |
|
291 appUi->ConstructL(); |
|
292 } |
|
293 /** |
|
294 Entry function for CTCone4Exe Test Step.\n |
|
295 Sets up the control environment.\n |
|
296 Constructs and Launches the CTCone4 Test application.\n |
|
297 */ |
|
298 TVerdict CTCone4StepExe::doTestStepL() // main function called by E32 |
|
299 { |
|
300 |
|
301 PreallocateHALBuffer(); |
|
302 __UHEAP_MARK; |
|
303 |
|
304 CCoeEnv* coe=new(ELeave) CCoeEnv; |
|
305 TRAPD(err,ConstructAppL(coe)); |
|
306 |
|
307 if (!err) |
|
308 coe->ExecuteD(); |
|
309 else |
|
310 { |
|
311 SetTestStepResult(EFail); |
|
312 delete coe; |
|
313 } |
|
314 REComSession::FinalClose(); |
|
315 __UHEAP_MARKEND; |
|
316 |
|
317 INFO_PRINTF1(_L("Test Finished")); |
|
318 return TestStepResult(); |
|
319 } |