|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * CSysErrCmdTest class implementation. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <e32debug.h> |
|
20 #include <stifparser.h> |
|
21 #include <stiftestinterface.h> |
|
22 |
|
23 #include <aknglobalnote.h> |
|
24 #include <akncapserverclient.h> |
|
25 #include <ssm/ssmcustomcommand.h> |
|
26 |
|
27 #include "syserrcmdtest.h" |
|
28 #include "syserrcmdfactory.h" |
|
29 #include "syserrcmdtestsstub.h" |
|
30 #include "trace.h" |
|
31 |
|
32 // INTERNAL INCLUDES |
|
33 NONSHARABLE_CLASS( TWaitInfo ) |
|
34 { |
|
35 public: |
|
36 |
|
37 CPeriodic* iPeriodic; |
|
38 CActiveSchedulerWait* iWait; |
|
39 }; |
|
40 |
|
41 |
|
42 /** |
|
43 * Call back method when we need to stop active scheduler wait. |
|
44 */ |
|
45 LOCAL_C TInt WaitCallBack( TAny* aSelf ) |
|
46 { |
|
47 if( aSelf ) |
|
48 { |
|
49 TWaitInfo* info = static_cast<TWaitInfo*>( aSelf ); |
|
50 if( info->iPeriodic ) |
|
51 { |
|
52 info->iPeriodic->Cancel(); |
|
53 } |
|
54 if( info->iWait ) |
|
55 { |
|
56 if( info->iWait->IsStarted() ) |
|
57 { |
|
58 info->iWait->AsyncStop(); |
|
59 } |
|
60 } |
|
61 } |
|
62 |
|
63 return KErrNone; |
|
64 } |
|
65 |
|
66 /** |
|
67 * Helper method to wait current scheduler before teardown is completed. |
|
68 */ |
|
69 LOCAL_C void WaitL( TInt aIntervalInMicorseconds ) |
|
70 { |
|
71 TWaitInfo info; |
|
72 |
|
73 // Construct periodic |
|
74 CPeriodic* periodic = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
75 CleanupStack::PushL( periodic ); |
|
76 info.iPeriodic = periodic; |
|
77 |
|
78 // Construct active scheduler wait |
|
79 CActiveSchedulerWait* wait = new( ELeave ) CActiveSchedulerWait; |
|
80 CleanupStack::PushL( wait ); |
|
81 info.iWait = wait; |
|
82 |
|
83 // Start timer and wait |
|
84 TCallBack cb( WaitCallBack, &info ); |
|
85 periodic->Start( aIntervalInMicorseconds, aIntervalInMicorseconds, cb ); |
|
86 wait->Start(); |
|
87 |
|
88 // Cleanup |
|
89 CleanupStack::PopAndDestroy( wait ); |
|
90 CleanupStack::PopAndDestroy( periodic ); |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------- |
|
94 // CSysErrCmdTest::LibEntryL |
|
95 // Returns: Poiter to CSysErrCmdTest class |
|
96 // --------------------------------------------------------- |
|
97 EXPORT_C CSysErrCmdTest* LibEntryL( CTestModuleIf& aTestModuleIf ) |
|
98 { |
|
99 FUNC_LOG; |
|
100 |
|
101 CSysErrCmdTest* libEntry( CSysErrCmdTest::NewL( aTestModuleIf ) ); |
|
102 return libEntry; |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------- |
|
106 // CSysErrCmdTest::CSysErrCmdTest |
|
107 // --------------------------------------------------------- |
|
108 CSysErrCmdTest::CSysErrCmdTest( CTestModuleIf& aTestModuleIf ) : |
|
109 CScriptBase( aTestModuleIf ) |
|
110 { |
|
111 FUNC_LOG; |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------- |
|
115 // CSysErrCmdTest::ConstructL |
|
116 // --------------------------------------------------------- |
|
117 void CSysErrCmdTest::ConstructL() |
|
118 { |
|
119 FUNC_LOG; |
|
120 |
|
121 iExecuteHandler = CAsyncRequestHandler<CSysErrCmdTest>::NewL( |
|
122 *this, |
|
123 HandleIssueRequest, |
|
124 HandleRunL, |
|
125 HandleRunError, |
|
126 HandleDoCancel, |
|
127 CAsyncRequestHandler<CSysErrCmdTest>::ERequestOneShot ); |
|
128 |
|
129 User::LeaveIfError( iFs.Connect() ); |
|
130 |
|
131 iCustCmdEnvStub = SysErrCmdTestsStub::CustomCommandEnvStubL( iFs ); |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------- |
|
135 // CSysErrCmdTest::NewL |
|
136 // --------------------------------------------------------- |
|
137 CSysErrCmdTest* CSysErrCmdTest::NewL( CTestModuleIf& aTestModuleIf ) |
|
138 { |
|
139 FUNC_LOG; |
|
140 |
|
141 CSysErrCmdTest* self = new (ELeave) CSysErrCmdTest( aTestModuleIf ); |
|
142 CleanupStack::PushL( self ); |
|
143 self->ConstructL(); |
|
144 CleanupStack::Pop( self ); |
|
145 return self; |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------- |
|
149 // CSysErrCmdTest::~CSysErrCmdTest |
|
150 // --------------------------------------------------------- |
|
151 CSysErrCmdTest::~CSysErrCmdTest() |
|
152 { |
|
153 iFs.Close(); |
|
154 delete iExecuteHandler; |
|
155 delete iCustCmdEnvStub; |
|
156 FUNC_LOG; |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------- |
|
160 // CSysErrCmdTest::RunMethodL |
|
161 // --------------------------------------------------------- |
|
162 TInt CSysErrCmdTest::RunMethodL( CStifItemParser& aItem ) |
|
163 { |
|
164 FUNC_LOG; |
|
165 |
|
166 const TStifFunctionInfo KFunctions[] = |
|
167 { |
|
168 // Copy this line for every implemented function. |
|
169 // First string is the function name used in TestScripter script file. |
|
170 // Second is the actual implementation member function. |
|
171 ENTRY( "CreateAndDestroy", CSysErrCmdTest::CreateAndDestroyL ), |
|
172 ENTRY( "InitAndClose", CSysErrCmdTest::InitAndCloseL ), |
|
173 ENTRY( "Execute", CSysErrCmdTest::ExecuteL ), |
|
174 ENTRY( "ExecuteCancel", CSysErrCmdTest::ExecuteCancelL ), |
|
175 ENTRY( "ExecuteAfterGlobalNote", CSysErrCmdTest::ShowAfterAknGlobalNoteL ), |
|
176 ENTRY( "ExecuteAfterUiServiceGlobalNote", CSysErrCmdTest::ShowAfterUiServerGlobalNoteL ) |
|
177 }; |
|
178 const TInt count( sizeof( KFunctions ) / sizeof( TStifFunctionInfo ) ); |
|
179 TInt ret( RunInternalL( KFunctions, count, aItem ) ); |
|
180 return ret; |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------- |
|
184 // CSysErrCmdTest::CreateAndDestroyL |
|
185 // --------------------------------------------------------- |
|
186 |
|
187 TInt CSysErrCmdTest::CreateAndDestroyL( CStifItemParser& aItem ) |
|
188 { |
|
189 FUNC_LOG; |
|
190 ( void )aItem; |
|
191 MSsmCustomCommand* sysErrCmd = SysErrCmdFactory::SysErrCmdNewL(); |
|
192 sysErrCmd->Release(); |
|
193 return KErrNone; |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------- |
|
197 // CSysErrCmdTest::InitAndCloseL |
|
198 // --------------------------------------------------------- |
|
199 TInt CSysErrCmdTest::InitAndCloseL( CStifItemParser& aItem ) |
|
200 { |
|
201 FUNC_LOG; |
|
202 ( void )aItem; |
|
203 |
|
204 MSsmCustomCommand* sysErrCmd = SysErrCmdFactory::SysErrCmdNewL(); |
|
205 |
|
206 TInt err( sysErrCmd->Initialize( iCustCmdEnvStub ) ); |
|
207 ERROR( err, "Failed to init syserrcmd" ); |
|
208 User::LeaveIfError( err ); |
|
209 |
|
210 sysErrCmd->Close(); |
|
211 sysErrCmd->Release(); |
|
212 |
|
213 return KErrNone; |
|
214 } |
|
215 // --------------------------------------------------------- |
|
216 // CSysErrCmdTest::ExecuteL |
|
217 // --------------------------------------------------------- |
|
218 |
|
219 TInt CSysErrCmdTest::ExecuteL( CStifItemParser& aItem ) |
|
220 { |
|
221 FUNC_LOG; |
|
222 ( void )aItem; |
|
223 iSysErrCmd = SysErrCmdFactory::SysErrCmdNewL(); |
|
224 TInt err( iSysErrCmd->Initialize( iCustCmdEnvStub ) ); |
|
225 ERROR( err, "Failed to init syserrcmd" ); |
|
226 User::LeaveIfError( err ); |
|
227 |
|
228 iExecuteHandler->IssueRequest(); |
|
229 |
|
230 WaitL( 5000 ); |
|
231 |
|
232 iSysErrCmd->Close(); |
|
233 iSysErrCmd->Release(); |
|
234 |
|
235 INFO_1( "Execution result %d", iExecutionResult ); |
|
236 |
|
237 return iExecutionResult; |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------- |
|
241 // CSysErrCmdTest::ExecuteL |
|
242 // --------------------------------------------------------- |
|
243 |
|
244 TInt CSysErrCmdTest::ExecuteCancelL( CStifItemParser& aItem ) |
|
245 { |
|
246 FUNC_LOG; |
|
247 ( void )aItem; |
|
248 iSysErrCmd = SysErrCmdFactory::SysErrCmdNewL(); |
|
249 TInt err( iSysErrCmd->Initialize( iCustCmdEnvStub ) ); |
|
250 ERROR( err, "Failed to init syserrcmd" ); |
|
251 User::LeaveIfError( err ); |
|
252 |
|
253 iExecuteHandler->IssueRequest(); |
|
254 |
|
255 WaitL( 5000 ); |
|
256 |
|
257 iSysErrCmd->ExecuteCancel(); |
|
258 |
|
259 WaitL( 5000 ); |
|
260 |
|
261 iSysErrCmd->Close(); |
|
262 iSysErrCmd->Release(); |
|
263 |
|
264 INFO_1( "ExecutionCancel result %d", iExecutionResult ); |
|
265 |
|
266 return ( iExecutionResult == KErrCancel ) ? KErrNone : KErrGeneral; |
|
267 } |
|
268 |
|
269 // --------------------------------------------------------- |
|
270 // CSysErrCmdTest::ShowAfterAknGlobalNoteL |
|
271 // --------------------------------------------------------- |
|
272 TInt CSysErrCmdTest::ShowAfterAknGlobalNoteL( CStifItemParser& aItem ) |
|
273 { |
|
274 CAknGlobalNote* note = CAknGlobalNote::NewLC(); |
|
275 note->ShowNoteL( EAknGlobalInformationNote, _L("CAknGlobalNote::ShowNoteL()") ); |
|
276 CleanupStack::PopAndDestroy( note ); |
|
277 |
|
278 return ExecuteL( aItem ); |
|
279 } |
|
280 |
|
281 // --------------------------------------------------------- |
|
282 // CSysErrCmdTest::ShowAfterUiServerGlobalNoteL |
|
283 // --------------------------------------------------------- |
|
284 TInt CSysErrCmdTest::ShowAfterUiServerGlobalNoteL( CStifItemParser& aItem ) |
|
285 { |
|
286 RAknUiServer aknSrv; |
|
287 |
|
288 User::LeaveIfError( aknSrv.Connect() ); |
|
289 |
|
290 CleanupClosePushL( aknSrv ); |
|
291 |
|
292 aknSrv.ShowGlobalNoteL( _L("RAknUiServer::ShowGlobalNoteL()"), EAknGlobalInformationNote ); |
|
293 |
|
294 CleanupStack::PopAndDestroy( &aknSrv ); |
|
295 |
|
296 return ExecuteL( aItem ); |
|
297 } |
|
298 |
|
299 // --------------------------------------------------------- |
|
300 // CSysErrCmdTest::HandleIssueRequest |
|
301 // --------------------------------------------------------- |
|
302 |
|
303 void CSysErrCmdTest::HandleIssueRequest( TRequestStatus& aRequest ) |
|
304 { |
|
305 FUNC_LOG; |
|
306 |
|
307 iSysErrCmd->Execute( KNullDesC8, aRequest ); |
|
308 |
|
309 } |
|
310 // --------------------------------------------------------- |
|
311 // CSysErrCmdTest::HandleRunL |
|
312 // --------------------------------------------------------- |
|
313 |
|
314 void CSysErrCmdTest::HandleRunL( TInt aStatus ) |
|
315 { |
|
316 FUNC_LOG; |
|
317 INFO_1( "CSysErrCmdTest::HandleRunL %d", aStatus ); |
|
318 |
|
319 if ( KErrNone != aStatus ) |
|
320 { |
|
321 iExecutionResult = aStatus; |
|
322 } |
|
323 } |
|
324 // --------------------------------------------------------- |
|
325 // CSysErrCmdTest::HandleRunError |
|
326 // --------------------------------------------------------- |
|
327 |
|
328 TInt CSysErrCmdTest::HandleRunError( TInt aError ) |
|
329 { |
|
330 FUNC_LOG; |
|
331 ERROR( aError, "CSysErrCmdTest::HandleRunError" ); |
|
332 return KErrNone; |
|
333 } |
|
334 // --------------------------------------------------------- |
|
335 // CSysErrCmdTest::HandleDoCancel |
|
336 // --------------------------------------------------------- |
|
337 |
|
338 void CSysErrCmdTest::HandleDoCancel() |
|
339 { |
|
340 FUNC_LOG; |
|
341 } |
|
342 |
|
343 |