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