|
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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // @file |
|
15 // @internalComponent - Internal Symbian test code |
|
16 // Test for UIKON GT0143 Typhoon Work Series 60 Changes |
|
17 // REQ758.8: Change TApaTask::BringToForeground to send a |
|
18 // EApaSystemEventBroughtToForeground to the relevant window group |
|
19 // This test requires Apparc\Tsrc\SampleApp to be built first |
|
20 // The test runs in the full GUI emulator and can be launched from |
|
21 // z:\system\programs\t_foreground.dll |
|
22 // This test is fully automated and performs the following tasks |
|
23 // - Launches SampleApp |
|
24 // - Calls TApaTask::BringToForeground to send a Window Server |
|
25 // event to SimpleApparcTestApp |
|
26 // - Waits on a Rendezvous in the process |
|
27 // - SimpleApparcTestApp handles the window server event by overriding |
|
28 // CCoeAppUi::HandleSystemEventL |
|
29 // - SimpleApparcTestApp's HandleSystemEventL checks the window server event |
|
30 // is of type EApaSystemEventBroughtToForeground and if so signals |
|
31 // using a Rendezvous in the process |
|
32 // - T_Foreground closes SimpleApparcTestApp |
|
33 // This test calls TApaTask::BringToForeground on SimpleApparcTestApp to send |
|
34 // a window server message to SimpleApparcTestApp |
|
35 // |
|
36 // |
|
37 |
|
38 |
|
39 |
|
40 #include <coeaui.h> |
|
41 #include <coemain.h> |
|
42 #include <coedef.h> |
|
43 #include <coecntrl.h> |
|
44 #include <basched.h> |
|
45 #include <ecom.h> |
|
46 #include <apparc.h> |
|
47 #include <e32cmn.h> |
|
48 |
|
49 #include <apgtask.h> |
|
50 |
|
51 #include <apacmdln.h> |
|
52 #include <apgcli.h> |
|
53 #include <apgwgnam.h> |
|
54 #include <e32base.h> |
|
55 #include <eikenv.h> |
|
56 |
|
57 #include "t_foreground.h" |
|
58 |
|
59 _LIT(KAppName, "SimpleApparcTestApp"); |
|
60 _LIT(KAppFileName, "z:\\sys\\bin\\SimpleApparcTestApp.exe"); |
|
61 _LIT(KAppFile, "c:\\logs\\testApp.txt"); |
|
62 const TInt KNonExistantWgId = KErrNotFound; |
|
63 |
|
64 //////////////////////////////////////////////////////////////////////////////////// |
|
65 // |
|
66 // The CTestDriver class runs a series of tests on timer callback |
|
67 // |
|
68 //////////////////////////////////////////////////////////////////////////////////// |
|
69 |
|
70 CTestDriver::CTestDriver(CCoeAppUi& aAppUi) : iAppUi(aAppUi) |
|
71 { |
|
72 } |
|
73 |
|
74 CTestDriver::~CTestDriver() |
|
75 { |
|
76 } |
|
77 |
|
78 void CTestDriver::LoadAppL() |
|
79 { |
|
80 TBuf<256> fileNameBuf(KAppFileName); |
|
81 TFileName appName = fileNameBuf; |
|
82 |
|
83 CApaCommandLine* cmdLine=CApaCommandLine::NewLC(); |
|
84 cmdLine->SetExecutableNameL(appName); |
|
85 cmdLine->SetCommandL(EApaCommandOpen); |
|
86 RApaLsSession ls; |
|
87 |
|
88 User::LeaveIfError(ls.Connect()); |
|
89 CleanupClosePushL(ls); |
|
90 User::LeaveIfError(ls.StartApp(*cmdLine)); |
|
91 CleanupStack::PopAndDestroy(2); // ls and cmdLine |
|
92 } |
|
93 |
|
94 void CTestDriver::BringToForegroundL() |
|
95 { |
|
96 User::After(10000000); |
|
97 TApaTaskList taskList(CCoeEnv::Static()->WsSession()); |
|
98 TApaTask task = taskList.FindApp(KAppName); |
|
99 |
|
100 RThread thread; |
|
101 User::LeaveIfError(thread.Open(task.ThreadId())); |
|
102 CleanupClosePushL(thread); |
|
103 RProcess process; |
|
104 User::LeaveIfError(thread.Process(process)); |
|
105 CleanupClosePushL(process); |
|
106 |
|
107 TRequestStatus requestStatus; |
|
108 process.Rendezvous(requestStatus); |
|
109 task.BringToForeground(); |
|
110 User::WaitForRequest(requestStatus); |
|
111 CleanupStack::PopAndDestroy(&process); |
|
112 CleanupStack::PopAndDestroy(&thread); |
|
113 |
|
114 User::LeaveIfError(requestStatus.Int()); |
|
115 } |
|
116 |
|
117 void CTestDriver::CloseAppL() |
|
118 { |
|
119 TApaTaskList taskList(CCoeEnv::Static()->WsSession()); |
|
120 TApaTask task = taskList.FindApp(KAppName); |
|
121 User::LeaveIfError(task.Exists()); |
|
122 task.KillTask(); |
|
123 } |
|
124 |
|
125 |
|
126 /** |
|
127 @SYMTestCaseID APPFWK-APPARC-0053 |
|
128 |
|
129 @SYMDEF DEF092013 |
|
130 |
|
131 @SYMTestCaseDesc Tests Whether the TApaTask::SwitchCreateFile returns the right return code. |
|
132 @SYMTestPriority High |
|
133 |
|
134 @SYMTestStatus Implemented |
|
135 |
|
136 @SYMTestActions Give a NonExistant file name that has to be created.This method checks that |
|
137 the file does not get created but on its default implementation returns KErrNone or System Wide errors. |
|
138 |
|
139 |
|
140 @SYMTestExpectedResults The test passes if the return value is KErrNone , It means the request has been successfuly sent to |
|
141 the windows Server session. |
|
142 */ |
|
143 |
|
144 TInt CTestDriver::SwitchCreate() |
|
145 { |
|
146 TApaTaskList taskList(CCoeEnv::Static()->WsSession()); |
|
147 TApaTask task = taskList.FindApp(KAppName); |
|
148 |
|
149 TInt errForCreate=task.SwitchCreateFile(KAppFile); |
|
150 return errForCreate; |
|
151 } |
|
152 |
|
153 |
|
154 /** |
|
155 @SYMTestCaseID APPFWK-APPARC-0054. |
|
156 |
|
157 @SYMDEF DEF092013 |
|
158 |
|
159 @SYMTestCaseDesc Tests Whether the TApaTask::SwitchOpenFile returns the right return code. |
|
160 |
|
161 @SYMTestPriority High |
|
162 |
|
163 @SYMTestStatus Implemented |
|
164 |
|
165 @SYMTestActions Give a NonExistant file name that has to be Opened.This method checks that |
|
166 the file does not get opened but on its default implementation returns KErrNone or System Wide errors. |
|
167 |
|
168 |
|
169 @SYMTestExpectedResults The test passes if the return value is KErrNone , It means the request has been successfuly sent to |
|
170 the windows Server session. |
|
171 |
|
172 |
|
173 */ |
|
174 TInt CTestDriver::SwitchOpen() |
|
175 { |
|
176 TApaTaskList taskList(CCoeEnv::Static()->WsSession()); |
|
177 TApaTask task = taskList.FindApp(KAppName); |
|
178 |
|
179 TInt errForOpen=task.SwitchOpenFile(KAppFile); |
|
180 return errForOpen; |
|
181 } |
|
182 |
|
183 /** |
|
184 @SYMTestCaseID T_Foreground-CloseNonExistantWindowGroupTask |
|
185 |
|
186 @SYMDEF INC086383 |
|
187 |
|
188 @SYMTestCaseDesc Tests CloseNonExistantWindowGroupTask to ensure that the kernel doesn't get terminated when KillTask() is called on a non-existant window group Id. |
|
189 |
|
190 @SYMTestPriority High |
|
191 |
|
192 @SYMTestStatus Implemented |
|
193 |
|
194 @SYMTestActions First, construct TApaTask with a non-existant window group Id. Then close the app by calling KillTask(). |
|
195 API Calls:\n |
|
196 TApaTask::SetWgId(TInt aWgId);\n |
|
197 TApaTask::KillTask();\n |
|
198 |
|
199 @SYMTestExpectedResults The test passes if it is able to complete without the test being killed off. |
|
200 */ |
|
201 void CTestDriver::CloseNonExistantWindowGroupTask() |
|
202 { |
|
203 // close the app with a non-existant window group ID |
|
204 TApaTask task(CCoeEnv::Static()->WsSession()); |
|
205 task.SetWgId(KNonExistantWgId); |
|
206 |
|
207 // KillTask has not effect on a non existing task |
|
208 task.KillTask(); |
|
209 } |
|
210 |
|
211 class CTestDriver; |
|
212 |
|
213 |
|
214 //////////////////////////////////////////////////////////////////////////////////// |
|
215 // |
|
216 // class CTestForegroundAppUi |
|
217 // |
|
218 //////////////////////////////////////////////////////////////////////////////////// |
|
219 |
|
220 CTestForegroundAppUi::CTestForegroundAppUi(CTestStep* aStep) : CTestCoeAppUi(aStep) |
|
221 { |
|
222 } |
|
223 |
|
224 void CTestForegroundAppUi::ConstructL() |
|
225 { |
|
226 CTestCoeAppUi::ConstructL(); |
|
227 iDriver=new (ELeave) CTestDriver(*this); |
|
228 AutoTestManager().StartAutoTest(); |
|
229 } |
|
230 |
|
231 |
|
232 CTestForegroundAppUi::~CTestForegroundAppUi() |
|
233 { |
|
234 delete iDriver; |
|
235 } |
|
236 |
|
237 void CTestForegroundAppUi::RunTestStepL(TInt aNumStep) |
|
238 { |
|
239 User::After(TTimeIntervalMicroSeconds32(1000000)); |
|
240 switch(aNumStep) |
|
241 { |
|
242 case 1: |
|
243 { |
|
244 INFO_PRINTF1(_L("LoadingApp")); |
|
245 TRAPD(ret, iDriver->LoadAppL()); |
|
246 TEST(ret==KErrNone); |
|
247 } |
|
248 break; |
|
249 case 2: |
|
250 { |
|
251 INFO_PRINTF1(_L("TApaTask::BringToForeground")); |
|
252 TRAPD(ret, iDriver->BringToForegroundL()); |
|
253 TEST(ret==KErrNone); |
|
254 } |
|
255 break; |
|
256 case 3: |
|
257 INFO_PRINTF1(_L("TApaTask::SwitchCreate")); |
|
258 TEST(iDriver->SwitchCreate()==KErrNone); |
|
259 break; |
|
260 case 4: |
|
261 INFO_PRINTF1(_L("TApaTask::SwitchOpen")); |
|
262 TEST(iDriver->SwitchOpen()==KErrNone); |
|
263 break; |
|
264 case 5: |
|
265 INFO_PRINTF1(_L("Closing App")); |
|
266 TRAPD(ret, iDriver->CloseAppL()); |
|
267 TEST(ret==KErrNone); |
|
268 break; |
|
269 case 6: |
|
270 INFO_PRINTF1(_L("Closing App with an invalid window group ID")); |
|
271 //There's no return value here we can check. The system doesn't complain about closing a non existant task |
|
272 iDriver->CloseNonExistantWindowGroupTask(); |
|
273 break; |
|
274 case 7: |
|
275 AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass); |
|
276 break; |
|
277 default: |
|
278 break; |
|
279 } |
|
280 } |
|
281 |
|
282 |
|
283 //////////////////////////////////////////////////////////////////////////////////// |
|
284 // |
|
285 // class CTestForegroundStep |
|
286 // |
|
287 //////////////////////////////////////////////////////////////////////////////////// |
|
288 |
|
289 CTestForegroundStep::CTestForegroundStep() |
|
290 { |
|
291 SetTestStepName(KTestForegroundStep); |
|
292 } |
|
293 |
|
294 CTestForegroundStep::~CTestForegroundStep() |
|
295 { |
|
296 } |
|
297 |
|
298 |
|
299 void CTestForegroundStep::ConstructAppL(CCoeEnv* aCoe) |
|
300 { // runs inside a TRAP harness |
|
301 aCoe->ConstructL(); |
|
302 CTestForegroundAppUi* appUi= new (ELeave) CTestForegroundAppUi(this); |
|
303 aCoe->SetAppUi(appUi); |
|
304 appUi->ConstructL(); |
|
305 } |
|
306 |
|
307 |
|
308 TVerdict CTestForegroundStep::doTestStepL() // main function called by E32 |
|
309 { |
|
310 INFO_PRINTF1(_L("Test Started")); |
|
311 |
|
312 PreallocateHALBuffer(); |
|
313 |
|
314 __UHEAP_MARK; |
|
315 |
|
316 CCoeEnv* coe=new(ELeave) CCoeEnv; |
|
317 TRAPD(err,ConstructAppL(coe)); |
|
318 |
|
319 if (!err) |
|
320 coe->ExecuteD(); |
|
321 else |
|
322 { |
|
323 SetTestStepResult(EFail); |
|
324 delete coe; |
|
325 } |
|
326 |
|
327 REComSession::FinalClose(); |
|
328 |
|
329 __UHEAP_MARKEND; |
|
330 |
|
331 INFO_PRINTF1(_L("Test Finished")); |
|
332 return TestStepResult(); |
|
333 } |