|
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 * |
|
16 */ |
|
17 |
|
18 #include <W32STD.H> |
|
19 #include <e32property.h> |
|
20 #include <cadef.h> |
|
21 #include <badesca.h> |
|
22 #include <apgtask.h> |
|
23 #include <AknTaskList.h> |
|
24 #include <apgcli.h> |
|
25 #include <APACMDLN.h> |
|
26 #include <EIKENV.h> |
|
27 |
|
28 #include "castorageproxy.h" |
|
29 #include "cainnerentry.h" |
|
30 #include "cainnerquery.h" |
|
31 #include "caarraycleanup.inl" |
|
32 #include "casrvplugin.h" |
|
33 |
|
34 |
|
35 #include "waitactive.h" |
|
36 #include "casrvtestutils.h" |
|
37 #include "testconsts.h" |
|
38 |
|
39 |
|
40 //----------------------------------------------------------------------- |
|
41 // CONSTRUCTION |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CTestUtils* CTestUtils::NewL() |
|
45 { |
|
46 CTestUtils* self = CTestUtils::NewLC(); |
|
47 CleanupStack::Pop(); |
|
48 |
|
49 return self; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CTestUtils* CTestUtils::NewLC() |
|
57 { |
|
58 CTestUtils* self = new( ELeave ) CTestUtils(); |
|
59 CleanupStack::PushL( self ); |
|
60 |
|
61 self->ConstructL(); |
|
62 |
|
63 return self; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // Destructor (virtual by CBase) |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CTestUtils::~CTestUtils() |
|
71 { |
|
72 iFileManager->Delete(KTestDbDest); |
|
73 iFileManager->Delete(KTestMmcHistDest); |
|
74 delete iFileManager; iFileManager = NULL; |
|
75 iFs.Close(); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // Default constructor |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 CTestUtils::CTestUtils() |
|
83 { |
|
84 |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // Second phase construct |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 void CTestUtils::ConstructL() |
|
92 { |
|
93 User::LeaveIfError( iFs.Connect() ); |
|
94 iFileManager = CFileMan::NewL( iFs ); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CTestUtils::WaitL(TInt aMicroSec) |
|
102 { |
|
103 CWaitActive* wait = CWaitActive::NewL(); |
|
104 wait->Wait(aMicroSec); |
|
105 delete wait; |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // CTestUtils::GetRProperty |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 TInt CTestUtils::GetRProperty( TUid aCategory, TUint aKey, TDes& aValue ) |
|
113 { |
|
114 return RProperty::Get( aCategory, aKey, aValue ); |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // CTestUtils::GetRProperty |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 TInt CTestUtils::GetRProperty( TUid aCategory, TUint aKey, TInt& aValue ) |
|
122 { |
|
123 return RProperty::Get( aCategory, aKey, aValue ); |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CTestUtils::SetRProperty |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 TInt CTestUtils::SetRProperty( TUid aCategory, TUint aKey, const TDesC& aValue ) |
|
131 { |
|
132 return RProperty::Set( aCategory, aKey, aValue ); |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // CTestUtils::SetRProperty |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 TInt CTestUtils::SetRProperty( TUid aCategory, TUint aKey, TInt aValue ) |
|
140 { |
|
141 return RProperty::Set( aCategory, aKey, aValue ); |
|
142 } |
|
143 |
|
144 |
|
145 //----------------------------------------------------------------------- |
|
146 // |
|
147 //----------------------------------------------------------------------- |
|
148 TInt CTestUtils::Copy( const TDesC& aSource, const TDesC& aDest ) |
|
149 { |
|
150 return iFileManager->Copy(aSource, aDest); |
|
151 } |
|
152 |
|
153 //----------------------------------------------------------------------- |
|
154 // |
|
155 //----------------------------------------------------------------------- |
|
156 TInt CTestUtils::CopyDb() |
|
157 { |
|
158 return Copy(KTestDbSource, KTestDbDest); |
|
159 } |
|
160 |
|
161 //----------------------------------------------------------------------- |
|
162 // |
|
163 //----------------------------------------------------------------------- |
|
164 TBool CTestUtils::AppExistsInStorageL( TInt aUid, CCaStorageProxy* aStorage) |
|
165 { |
|
166 TBool exists(EFalse); |
|
167 CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC(); |
|
168 satAppQuery->SetUid( aUid ); |
|
169 RPointerArray<CCaInnerEntry> resultArray; |
|
170 CleanupResetAndDestroyPushL( resultArray ); |
|
171 aStorage->GetEntriesL( satAppQuery, resultArray ); |
|
172 |
|
173 if ( resultArray.Count() ) |
|
174 { |
|
175 CCaInnerEntry* dbg = resultArray[0]; |
|
176 exists = ETrue; |
|
177 } |
|
178 |
|
179 CleanupStack::PopAndDestroy( &resultArray ); |
|
180 CleanupStack::PopAndDestroy( satAppQuery ); |
|
181 |
|
182 return exists; |
|
183 } |
|
184 |
|
185 //----------------------------------------------------------------------- |
|
186 // |
|
187 //----------------------------------------------------------------------- |
|
188 TBool CTestUtils::ComponentExistsInStorageL( Usif::TComponentId aComponentId, |
|
189 CCaStorageProxy* aStorage) |
|
190 { |
|
191 TBool exists(EFalse); |
|
192 CCaInnerQuery* appQuery = CCaInnerQuery::NewLC(); |
|
193 RBuf componentIdDes; |
|
194 componentIdDes.CleanupClosePushL(); |
|
195 componentIdDes.CreateL( sizeof(Usif::TComponentId) + 1 ); |
|
196 componentIdDes.AppendNum( aComponentId ); |
|
197 |
|
198 appQuery->AddAttributeL( KCaComponentId, componentIdDes ); |
|
199 RPointerArray<CCaInnerEntry> resultArray; |
|
200 CleanupResetAndDestroyPushL( resultArray ); |
|
201 aStorage->GetEntriesL( appQuery, resultArray ); |
|
202 |
|
203 if ( resultArray.Count() ) |
|
204 { |
|
205 CCaInnerEntry* dbg = resultArray[0]; |
|
206 exists = ETrue; |
|
207 } |
|
208 |
|
209 CleanupStack::PopAndDestroy( &resultArray ); |
|
210 CleanupStack::PopAndDestroy( &componentIdDes ); |
|
211 CleanupStack::PopAndDestroy( appQuery ); |
|
212 |
|
213 return exists; |
|
214 } |
|
215 |
|
216 //----------------------------------------------------------------------- |
|
217 // |
|
218 //----------------------------------------------------------------------- |
|
219 CCaInnerEntry* CTestUtils::GetAppEntryL( TInt aUid, CCaStorageProxy* aStorage) |
|
220 { |
|
221 CCaInnerEntry* entry = NULL; |
|
222 CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC(); |
|
223 satAppQuery->SetUid( aUid ); |
|
224 RPointerArray<CCaInnerEntry> resultArray; |
|
225 CleanupResetAndDestroyPushL( resultArray ); |
|
226 aStorage->GetEntriesL( satAppQuery, resultArray ); |
|
227 |
|
228 if ( resultArray.Count() ) |
|
229 { |
|
230 entry = resultArray[0]; |
|
231 resultArray.Remove(0); |
|
232 } |
|
233 |
|
234 CleanupStack::PopAndDestroy( &resultArray ); |
|
235 CleanupStack::PopAndDestroy( satAppQuery ); |
|
236 |
|
237 return entry; |
|
238 } |
|
239 |
|
240 //----------------------------------------------------------------------- |
|
241 // |
|
242 //----------------------------------------------------------------------- |
|
243 TInt CTestUtils::AppsWithFlagsOffL( TInt aFlags, CCaStorageProxy* aStorage) |
|
244 { |
|
245 CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC(); |
|
246 CDesC16ArrayFlat* appType = |
|
247 new (ELeave) CDesC16ArrayFlat( 1 ); |
|
248 CleanupStack::PushL( appType ); |
|
249 appType->AppendL( KCaTypeApp ); |
|
250 satAppQuery->SetEntryTypeNames( appType ); |
|
251 |
|
252 satAppQuery->SetFlagsOff( aFlags ); |
|
253 RPointerArray<CCaInnerEntry> resultArray; |
|
254 CleanupResetAndDestroyPushL( resultArray ); |
|
255 aStorage->GetEntriesL( satAppQuery, resultArray ); |
|
256 |
|
257 TInt count = resultArray.Count(); |
|
258 CleanupStack::PopAndDestroy( &resultArray ); |
|
259 CleanupStack::Pop( appType ); |
|
260 CleanupStack::PopAndDestroy( satAppQuery ); |
|
261 |
|
262 return count; |
|
263 } |
|
264 |
|
265 |
|
266 //----------------------------------------------------------------------- |
|
267 // |
|
268 //----------------------------------------------------------------------- |
|
269 TInt CTestUtils::GetAppFlagsL( TInt aUid, CCaStorageProxy* aStorage) |
|
270 { |
|
271 TInt flags(0); |
|
272 CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC(); |
|
273 satAppQuery->SetUid( aUid ); |
|
274 RPointerArray<CCaInnerEntry> resultArray; |
|
275 CleanupResetAndDestroyPushL( resultArray ); |
|
276 aStorage->GetEntriesL( satAppQuery, resultArray ); |
|
277 |
|
278 if ( resultArray.Count() ) |
|
279 { |
|
280 CCaInnerEntry* dbg = resultArray[0]; |
|
281 flags = resultArray[0]->GetFlags(); |
|
282 } |
|
283 |
|
284 CleanupStack::PopAndDestroy( &resultArray ); |
|
285 CleanupStack::PopAndDestroy( satAppQuery ); |
|
286 |
|
287 return flags; |
|
288 } |
|
289 |
|
290 |
|
291 //----------------------------------------------------------------------- |
|
292 // |
|
293 //----------------------------------------------------------------------- |
|
294 void CTestUtils::RemoveAppL( TInt aUid, CCaStorageProxy* aStorage) |
|
295 { |
|
296 CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC(); |
|
297 satAppQuery->SetUid( aUid ); |
|
298 RPointerArray<CCaInnerEntry> resultArray; |
|
299 CleanupResetAndDestroyPushL( resultArray ); |
|
300 aStorage->GetEntriesL( satAppQuery, resultArray ); |
|
301 |
|
302 if ( resultArray.Count() ) |
|
303 { |
|
304 CCaInnerEntry* dbg = resultArray[0]; |
|
305 RArray<TInt> idsToRemove; |
|
306 CleanupClosePushL(idsToRemove); |
|
307 idsToRemove.AppendL( resultArray[0]->GetId() ); |
|
308 aStorage->RemoveL(idsToRemove); |
|
309 CleanupStack::PopAndDestroy( &idsToRemove ); |
|
310 } |
|
311 |
|
312 CleanupStack::PopAndDestroy( &resultArray ); |
|
313 CleanupStack::PopAndDestroy( satAppQuery ); |
|
314 } |
|
315 |
|
316 //----------------------------------------------------------------------- |
|
317 // |
|
318 //----------------------------------------------------------------------- |
|
319 |
|
320 void CTestUtils::CopyMmcHistory() |
|
321 { |
|
322 iFileManager->Copy( KTestMmcHistSource, KTestMmcHistDest ); |
|
323 } |
|
324 |
|
325 |
|
326 //----------------------------------------------------------------------- |
|
327 // |
|
328 //----------------------------------------------------------------------- |
|
329 TUint CTestUtils::FindAppUidL( const TDesC& aName, CCaStorageProxy* aStorage ) |
|
330 { |
|
331 CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC(); |
|
332 CDesC16ArrayFlat* appType = |
|
333 new (ELeave) CDesC16ArrayFlat( 1 ); |
|
334 CleanupStack::PushL( appType ); |
|
335 appType->AppendL( KCaTypeApp ); |
|
336 satAppQuery->SetEntryTypeNames( appType ); |
|
337 |
|
338 RPointerArray<CCaInnerEntry> resultArray; |
|
339 CleanupResetAndDestroyPushL( resultArray ); |
|
340 aStorage->GetEntriesL( satAppQuery, resultArray ); |
|
341 |
|
342 TUint appUid(0); |
|
343 for ( TInt i = 0; i < resultArray.Count(); i++ ) |
|
344 { |
|
345 if ( resultArray[i]->GetText() == aName ) |
|
346 { |
|
347 appUid = resultArray[i]->GetUid(); |
|
348 } |
|
349 } |
|
350 CleanupStack::PopAndDestroy( &resultArray ); |
|
351 CleanupStack::Pop( appType ); |
|
352 CleanupStack::PopAndDestroy( satAppQuery ); |
|
353 |
|
354 return appUid; |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 TInt CTestUtils::SimpleCloseTaskL(TInt aUid) |
|
360 { |
|
361 RWsSession session; |
|
362 TInt error = session.Connect(); |
|
363 TUid uidApp( TUid::Uid( aUid )) ; |
|
364 TApaTaskList taskList( session ); |
|
365 TApaTask task = taskList.FindApp( uidApp ); |
|
366 |
|
367 if( task.Exists() ) |
|
368 { |
|
369 task.EndTask(); |
|
370 } |
|
371 else |
|
372 { |
|
373 error = KErrNotFound; |
|
374 } |
|
375 |
|
376 WaitL( 4000000 ); |
|
377 session.Close(); |
|
378 WaitL( 1000000 ); |
|
379 |
|
380 return error; |
|
381 } |
|
382 |
|
383 // ---------------------------------------------------------------------------- |
|
384 // |
|
385 void CTestUtils::InstallFinishedL() |
|
386 { |
|
387 iActiveWait->AsyncStop(); |
|
388 } |
|
389 |
|
390 |
|
391 // --------------------------------------------------------- |
|
392 // CTestUtils::LaunchApplicationL |
|
393 // --------------------------------------------------------- |
|
394 |
|
395 CCaSrvPlugin* CTestUtils::LoadPluginL( TUid aImplUid, TPluginParams aPluginParams ) |
|
396 { |
|
397 RImplInfoPtrArray infoArray; |
|
398 |
|
399 // Note that a special cleanup function is required to reset and destroy |
|
400 // all items in the array, and then close it. |
|
401 CleanupResetAndDestroyPushL( infoArray ); |
|
402 CCaSrvPlugin::ListAllImplementationsL( infoArray ); |
|
403 |
|
404 // Loop through each info for each implementation |
|
405 // and create and use each in turn |
|
406 CCaSrvPlugin* plug = NULL; |
|
407 for( TInt i = 0; i < infoArray.Count(); i++ ) |
|
408 { |
|
409 // Slice off first sub-section in the data section |
|
410 TUid current_plugin = infoArray[i]->ImplementationUid(); |
|
411 if ( current_plugin == aImplUid ) |
|
412 { |
|
413 plug = CCaSrvPlugin::NewL( current_plugin, &aPluginParams ); |
|
414 break; |
|
415 } |
|
416 } |
|
417 CleanupStack::PopAndDestroy( &infoArray ); |
|
418 return plug; |
|
419 } |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 // --------------------------------------------------------- |
|
425 // CTestUtils::LaunchApplicationL |
|
426 // --------------------------------------------------------- |
|
427 // |
|
428 TInt CTestUtils::LaunchApplicationL( const TUid aUid ) |
|
429 { |
|
430 RWsSession wsSession; |
|
431 User::LeaveIfError( wsSession.Connect() ); |
|
432 CleanupClosePushL<RWsSession>( wsSession ); |
|
433 |
|
434 CAknTaskList* taskList = CAknTaskList::NewL( wsSession ); |
|
435 TApaTask task = taskList->FindRootApp( aUid ); |
|
436 delete taskList; |
|
437 |
|
438 if ( task.Exists() ) |
|
439 { |
|
440 task.BringToForeground(); |
|
441 } |
|
442 else |
|
443 { |
|
444 TApaAppInfo appInfo; |
|
445 TApaAppCapabilityBuf capabilityBuf; |
|
446 RApaLsSession appArcSession; |
|
447 User::LeaveIfError( appArcSession.Connect() ); |
|
448 CleanupClosePushL<RApaLsSession>( appArcSession ); |
|
449 |
|
450 User::LeaveIfError( appArcSession.GetAppInfo( appInfo, aUid ) ); |
|
451 User::LeaveIfError( appArcSession.GetAppCapability( capabilityBuf, aUid ) ); |
|
452 |
|
453 TApaAppCapability& caps = capabilityBuf(); |
|
454 TFileName appName = appInfo.iFullName; |
|
455 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
|
456 cmdLine->SetExecutableNameL( appName ); |
|
457 |
|
458 if ( caps.iLaunchInBackground ) |
|
459 { |
|
460 cmdLine->SetCommandL( EApaCommandBackground ); |
|
461 } |
|
462 else |
|
463 { |
|
464 cmdLine->SetCommandL( EApaCommandRun ); |
|
465 } |
|
466 |
|
467 User::LeaveIfError( appArcSession.StartApp( *cmdLine ) ); |
|
468 |
|
469 CleanupStack::PopAndDestroy( cmdLine ); |
|
470 CleanupStack::PopAndDestroy( &appArcSession ); |
|
471 } |
|
472 CleanupStack::PopAndDestroy( &wsSession ); |
|
473 |
|
474 //verification if app has really launched |
|
475 WaitL(20000000); |
|
476 RWsSession verWsSession; |
|
477 User::LeaveIfError( verWsSession.Connect() ); |
|
478 CleanupClosePushL<RWsSession>( verWsSession ); |
|
479 |
|
480 CAknTaskList* verTaskList = CAknTaskList::NewL( verWsSession ); |
|
481 TApaTask verTask = verTaskList->FindRootApp( aUid ); |
|
482 delete verTaskList; |
|
483 |
|
484 TInt result(KErrGeneral); |
|
485 if ( verTask.Exists() ) |
|
486 { |
|
487 result = KErrNone; |
|
488 } |
|
489 CleanupStack::PopAndDestroy( &verWsSession ); |
|
490 return result; |
|
491 } |
|
492 |
|
493 |