|
1 /* |
|
2 * Copyright (c) 2007 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 |
|
19 // CLASS HEADER |
|
20 #include "MT_CFContextSourceManager.h" |
|
21 |
|
22 // EXTERNAL INCLUDES |
|
23 #include <bautils.h> |
|
24 #include <ecom/ecom.h> |
|
25 #include <e32property.h> |
|
26 #include <EUnitMacros.h> |
|
27 #include "CFContextSourceManager.h" |
|
28 #include "cfcontextsourcesettingsmanager.h" |
|
29 #include "cfcontextsubscription.h" |
|
30 #include "cfcontextsourcesettingarray.h" |
|
31 |
|
32 #include "testcontextsourceplugin.h" |
|
33 #include "cfenvutils.h" |
|
34 |
|
35 // CONSTANTS |
|
36 |
|
37 _LIT_SECURITY_POLICY_PASS( KPassSec ); |
|
38 |
|
39 const TInt KUIDNameStartPos = 1; |
|
40 const TInt KUIDNameEndPos = 8; |
|
41 |
|
42 const TUid KTestContextSourcePluginImplUid = {0x10002001}; |
|
43 const TInt KOneSecond = 1000000; |
|
44 const TInt KThreeSeconds = 3 * KOneSecond; |
|
45 const TInt KPluginLoadWaitDelay = KThreeSeconds; // 3 second |
|
46 |
|
47 // Drive letter hard coded since context source plug-in settings |
|
48 // can only exist in ROM |
|
49 _LIT( KSettingsPathRom, "z:\\private\\10282BC4\\Settings\\" ); |
|
50 |
|
51 // Folder extension |
|
52 _LIT( KFolderExt, "\\" ); |
|
53 |
|
54 // Setting file extension |
|
55 _LIT( KSettingExtension, "*.xml" ); |
|
56 |
|
57 namespace |
|
58 { |
|
59 template <class T> |
|
60 class CleanupResetAndDestroy |
|
61 { |
|
62 public: |
|
63 inline static void PushL(T& aRef); |
|
64 private: |
|
65 static void ResetAndDestroy(TAny *aPtr); |
|
66 }; |
|
67 template <class T> |
|
68 inline void CleanupResetAndDestroyPushL(T& aRef); |
|
69 |
|
70 |
|
71 template <class T> |
|
72 inline void CleanupResetAndDestroy<T>::PushL(T& aRef) |
|
73 {CleanupStack::PushL(TCleanupItem(&ResetAndDestroy,&aRef));} |
|
74 template <class T> |
|
75 void CleanupResetAndDestroy<T>::ResetAndDestroy(TAny *aPtr) |
|
76 {(STATIC_CAST(T*,aPtr))->ResetAndDestroy();} |
|
77 template <class T> |
|
78 inline void CleanupResetAndDestroyPushL(T& aRef) |
|
79 {CleanupResetAndDestroy<T>::PushL(aRef);} |
|
80 } |
|
81 |
|
82 |
|
83 // CONSTRUCTION |
|
84 MT_CFContextSourceManager* MT_CFContextSourceManager::NewL() |
|
85 { |
|
86 MT_CFContextSourceManager* self = MT_CFContextSourceManager::NewLC(); |
|
87 CleanupStack::Pop(); |
|
88 |
|
89 return self; |
|
90 } |
|
91 |
|
92 MT_CFContextSourceManager* MT_CFContextSourceManager::NewLC() |
|
93 { |
|
94 MT_CFContextSourceManager* self = new( ELeave ) MT_CFContextSourceManager(); |
|
95 CleanupStack::PushL( self ); |
|
96 |
|
97 self->ConstructL(); |
|
98 |
|
99 return self; |
|
100 } |
|
101 |
|
102 // Destructor (virtual by CBase) |
|
103 MT_CFContextSourceManager::~MT_CFContextSourceManager() |
|
104 { |
|
105 Teardown(); |
|
106 |
|
107 // Enable screen saver |
|
108 CFEnvUtils::EnableScreenSaver( ETrue ); |
|
109 } |
|
110 |
|
111 // Default constructor |
|
112 MT_CFContextSourceManager::MT_CFContextSourceManager() |
|
113 { |
|
114 } |
|
115 |
|
116 // Second phase construct |
|
117 void MT_CFContextSourceManager::ConstructL() |
|
118 { |
|
119 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
120 // It generates the test case table. |
|
121 CEUnitTestSuiteClass::ConstructL(); |
|
122 |
|
123 // Disable screen saver |
|
124 CFEnvUtils::EnableScreenSaver( EFalse ); |
|
125 } |
|
126 |
|
127 // METHODS |
|
128 |
|
129 void MT_CFContextSourceManager::UnsubscribeContexts( |
|
130 MCFContextSubscriptionListener& /*aObserver*/ ) |
|
131 { |
|
132 |
|
133 } |
|
134 |
|
135 TInt MT_CFContextSourceManager::PublishContext( |
|
136 CCFContextObject& /*aContext*/, |
|
137 RThread& /*aClientThread */) |
|
138 { |
|
139 return KErrNone; |
|
140 } |
|
141 |
|
142 TInt MT_CFContextSourceManager::PublishContext( |
|
143 CCFContextObject& /*aContext*/, |
|
144 CCFContextDataObject& /*aData*/, |
|
145 RThread& /*aClientThread */) |
|
146 { |
|
147 return KErrNone; |
|
148 } |
|
149 |
|
150 TInt MT_CFContextSourceManager::SubscribeContext( |
|
151 CCFContextSubscription* aSubscription, |
|
152 MCFContextSubscriptionListener* /*aListener*/, |
|
153 RThread& /*aClientThread */) |
|
154 { |
|
155 // Need to delete the subscription since test suite simulates |
|
156 // CFW and CFW takes ownership of the subscripion. |
|
157 delete aSubscription; |
|
158 |
|
159 return KErrNone; |
|
160 } |
|
161 |
|
162 void MT_CFContextSourceManager::UnsubscribeContext( |
|
163 CCFContextSubscription& /*aSubscription*/, |
|
164 MCFContextSubscriptionListener& /*aListener */) |
|
165 { |
|
166 |
|
167 } |
|
168 |
|
169 TInt MT_CFContextSourceManager::RequestContext( |
|
170 RContextObjectArray& /*aResultBuffer*/, |
|
171 CCFContextQuery& /*aContextQuery*/, |
|
172 RThread& /*aClientThread */) |
|
173 { |
|
174 return KErrNone; |
|
175 } |
|
176 |
|
177 TInt MT_CFContextSourceManager::DefineContext( const TDesC& /*aContextSource*/, |
|
178 const TDesC& /*aContextType*/, |
|
179 const TSecurityPolicy& /*aSecurityPolicy */) |
|
180 { |
|
181 return KErrNone; |
|
182 } |
|
183 |
|
184 TInt MT_CFContextSourceManager::DefineContext( const TDesC& /*aContextSource*/, |
|
185 const TDesC& /*aContextType*/, |
|
186 const TSecurityPolicy& /*aReadWritePolicy*/, |
|
187 MCFContextSource& /*aOwner */) |
|
188 { |
|
189 return KErrNone; |
|
190 } |
|
191 |
|
192 TInt MT_CFContextSourceManager::DefineContext( const TDesC& /*aContextSource*/, |
|
193 const TDesC& /*aContextType*/, |
|
194 const TSecurityPolicy& /*aReadPolicy*/, |
|
195 const TSecurityPolicy& /*aWritePolicy*/, |
|
196 MCFContextSource& /*aOwner */) |
|
197 { |
|
198 return KErrNone; |
|
199 } |
|
200 |
|
201 TInt MT_CFContextSourceManager::GetSecurityPolicy( |
|
202 const TDesC& /*aContextSource*/, |
|
203 const TDesC& /*aContextType*/, |
|
204 TSecurityPolicy& aPolicy ) |
|
205 { |
|
206 aPolicy = KPassSec; |
|
207 return KErrNone; |
|
208 } |
|
209 |
|
210 TInt MT_CFContextSourceManager::GetReadSecurityPolicy( const TDesC& /*aContextSource*/, |
|
211 const TDesC& /*aContextType*/, |
|
212 TSecurityPolicy& aPolicy ) |
|
213 { |
|
214 aPolicy = KPassSec; |
|
215 return KErrNone; |
|
216 } |
|
217 |
|
218 TInt MT_CFContextSourceManager::GetWriteSecurityPolicy( const TDesC& /*aContextSource*/, |
|
219 const TDesC& /*aContextType*/, |
|
220 TSecurityPolicy& aPolicy ) |
|
221 { |
|
222 aPolicy = KPassSec; |
|
223 return KErrNone; |
|
224 } |
|
225 |
|
226 TInt MT_CFContextSourceManager::DefineContext( const TDesC& /*aContextSource*/, |
|
227 const TDesC& /*aContextType*/, |
|
228 const TSecurityPolicy& /*aReadPolicy*/, |
|
229 const TSecurityPolicy& /*aWritePolicy*/, |
|
230 MCFContextSource* /*aPublisher*/, |
|
231 const TUid& /*aPublisherUid*/ ) |
|
232 { |
|
233 return KErrNone; |
|
234 } |
|
235 |
|
236 void MT_CFContextSourceManager::DeregisterPublisher( MCFContextSource& /*aPublisher*/ ) |
|
237 { |
|
238 |
|
239 } |
|
240 |
|
241 TInt MT_CFContextSourceManager::InstallContextSourceSetting( RFile& /*aSettingFile*/, |
|
242 const TUid& /*aContextSourceUid*/, |
|
243 RThread& /*aClientThread */) |
|
244 { |
|
245 return KErrNone; |
|
246 } |
|
247 |
|
248 TInt MT_CFContextSourceManager::UninstallContextSourceSetting( |
|
249 const TDesC& /*aSettingFilename*/, |
|
250 const TUid& /*aContextSourceUid*/, |
|
251 RThread& /*aClientThread */) |
|
252 { |
|
253 return KErrNone; |
|
254 } |
|
255 |
|
256 TInt MT_CFContextSourceManager::UninstallContextSourceSettings( |
|
257 const TUid& /*aContextSourceUid*/, |
|
258 RThread& /*aClientThread */) |
|
259 { |
|
260 return KErrNone; |
|
261 } |
|
262 |
|
263 TInt MT_CFContextSourceManager::PublishContextFromAction( |
|
264 CCFContextObject& /*aContext*/, |
|
265 TBool /*aAutoDefine*/ ) |
|
266 { |
|
267 return KErrNone; |
|
268 } |
|
269 |
|
270 void MT_CFContextSourceManager::SetupL( ) |
|
271 { |
|
272 User::LeaveIfError( iFs.Connect() ); |
|
273 |
|
274 iContextSourceManager = CCFContextSourceManager::NewL( *this, iFs ); |
|
275 iSettingsManager = CCFContextSourceSettingsManager::NewL( iFs ); |
|
276 |
|
277 iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
278 iWait = new( ELeave ) CActiveSchedulerWait; |
|
279 } |
|
280 |
|
281 void MT_CFContextSourceManager::SetupEmptyL( ) |
|
282 { |
|
283 |
|
284 } |
|
285 |
|
286 void MT_CFContextSourceManager::SetupPluginsL( ) |
|
287 { |
|
288 SetupL(); |
|
289 |
|
290 // Disable checks |
|
291 TInt err = RProperty::Set( KContextSourceTestCategory, KDisableChecks, 0 ); |
|
292 |
|
293 // Need to initialize ECom since otherwise it seems that we leak memory |
|
294 // Something to do with ECom initialization.. possibly TLS related issues. |
|
295 |
|
296 // This also initializes XML Parses because ParseSettingsL is called. |
|
297 // First time use of CMDXMLParser reserves some memory which is not |
|
298 // immediately freed. |
|
299 TBool fail = EFalse; |
|
300 TContextSourceInitParams params( *this ); |
|
301 RImplInfoPtrArray list; |
|
302 CleanupResetAndDestroyPushL( list ); |
|
303 REComSession::ListImplementationsL( KContextSourcePlugInInterface, list ); |
|
304 |
|
305 TInt count = list.Count(); |
|
306 CImplementationInformation* info = NULL; |
|
307 for( TInt i = 0; i < count; i++ ) |
|
308 { |
|
309 info = list[i]; |
|
310 CCFContextSourcePlugIn* plugIn = NULL; |
|
311 TRAP_IGNORE( plugIn = CreateAndInitializePlugInL( |
|
312 info->ImplementationUid(), |
|
313 params ) ); |
|
314 delete plugIn; |
|
315 } |
|
316 |
|
317 // Clean up |
|
318 CleanupStack::PopAndDestroy( &list ); |
|
319 } |
|
320 |
|
321 void MT_CFContextSourceManager::Teardown( ) |
|
322 { |
|
323 delete iContextSourceManager; |
|
324 iContextSourceManager = NULL; |
|
325 |
|
326 delete iSettingsManager; |
|
327 iSettingsManager = NULL; |
|
328 |
|
329 delete iPeriodic; |
|
330 iPeriodic = NULL; |
|
331 |
|
332 if( iWait ) |
|
333 { |
|
334 if( iWait->IsStarted() ) |
|
335 { |
|
336 iWait->AsyncStop(); |
|
337 } |
|
338 delete iWait; |
|
339 iWait = NULL; |
|
340 } |
|
341 |
|
342 iFs.Close(); |
|
343 } |
|
344 |
|
345 TInt MT_CFContextSourceManager::CallBack( TAny* aSelf ) |
|
346 { |
|
347 MT_CFContextSourceManager* self = static_cast<MT_CFContextSourceManager*>( aSelf ); |
|
348 self->iPeriodic->Cancel(); |
|
349 if( self->iWait->IsStarted() ) |
|
350 { |
|
351 self->iWait->AsyncStop(); |
|
352 } |
|
353 return KErrNone; |
|
354 } |
|
355 |
|
356 void MT_CFContextSourceManager::Wait( TTimeIntervalMicroSeconds32& aDelay ) |
|
357 { |
|
358 if( iPeriodic ) |
|
359 { |
|
360 if( !iPeriodic->IsActive() ) |
|
361 { |
|
362 TCallBack cb( CallBack, this ); |
|
363 iPeriodic->Start( aDelay, aDelay, cb ); |
|
364 iWait->Start(); |
|
365 } |
|
366 } |
|
367 } |
|
368 |
|
369 CCFContextSourcePlugIn* MT_CFContextSourceManager::CreateAndInitializePlugInL( |
|
370 const TUid& aImplementationUid, |
|
371 TContextSourceInitParams& aParams ) |
|
372 { |
|
373 // Create plug-in |
|
374 CCFContextSourcePlugIn* plugIn = CCFContextSourcePlugIn::NewL( |
|
375 aImplementationUid, |
|
376 &aParams ); |
|
377 CleanupStack::PushL( plugIn ); |
|
378 |
|
379 // Handle settings |
|
380 HBufC* settingFile = HBufC::NewLC( KMaxFileName ); |
|
381 TPtr settingFilePtr = settingFile->Des(); |
|
382 if( ConfigureSettingFolder( settingFilePtr, aImplementationUid ) ) |
|
383 { |
|
384 // Setting folder found, parse settings |
|
385 settingFilePtr.Append( KSettingExtension ); |
|
386 CCFContextSourceSettingArray* settings = |
|
387 CCFContextSourceSettingArray::NewLC(); |
|
388 ParsePlugInSettingsL( settingFilePtr, *settings ); |
|
389 |
|
390 // Forward settings to plug-in |
|
391 // Plug-in takes ownership of the array |
|
392 CleanupStack::Pop( settings ); |
|
393 plugIn->HandleSettingL( settings ); |
|
394 } |
|
395 |
|
396 CleanupStack::PopAndDestroy( settingFile ); |
|
397 |
|
398 // Define context |
|
399 plugIn->DefineContextsL(); |
|
400 |
|
401 // Initialize |
|
402 plugIn->InitializeL(); |
|
403 |
|
404 // Cleanup |
|
405 CleanupStack::Pop( plugIn ); |
|
406 |
|
407 return plugIn; |
|
408 } |
|
409 |
|
410 TBool MT_CFContextSourceManager::ConfigureSettingFolder( TDes& aFile, |
|
411 const TUid& aUid ) |
|
412 { |
|
413 // Check rom |
|
414 // '[12345678]' -> 'z:\private\10282BC4\Settings\12345678\' |
|
415 aFile.Append( KSettingsPathRom ); |
|
416 aFile.Append( aUid.Name().Mid( |
|
417 KUIDNameStartPos, |
|
418 KUIDNameEndPos ) ); |
|
419 aFile.Append( KFolderExt ); |
|
420 |
|
421 return BaflUtils::PathExists( iFs, aFile ); |
|
422 } |
|
423 |
|
424 void MT_CFContextSourceManager::ParsePlugInSettingsL( const TDesC& aFolder, |
|
425 CCFContextSourceSettingArray& aSettings ) |
|
426 { |
|
427 CDir* dirList = NULL; |
|
428 TInt err = iFs.GetDir( aFolder, |
|
429 KEntryAttMaskSupported, |
|
430 ESortByName, |
|
431 dirList ); |
|
432 if( err == KErrNone ) |
|
433 { |
|
434 CleanupStack::PushL( dirList ); |
|
435 TInt count = dirList->Count(); |
|
436 HBufC* file = HBufC::NewLC( KMaxFileName ); |
|
437 TPtr filePtr = file->Des(); |
|
438 for( TInt i = 0; i < count; i++ ) |
|
439 { |
|
440 // Configure full file path |
|
441 filePtr.Copy( aFolder.Left( |
|
442 aFolder.Length() - KSettingExtension().Length() ) ); |
|
443 filePtr.Append( (*dirList)[i].iName ); |
|
444 |
|
445 // Parse settings |
|
446 iSettingsManager->ParseSettingsL( filePtr, aSettings ); |
|
447 } |
|
448 |
|
449 CleanupStack::PopAndDestroy( file ); |
|
450 CleanupStack::PopAndDestroy( dirList ); |
|
451 } |
|
452 } |
|
453 |
|
454 //----------------------------------------------------------------------------- |
|
455 // MT_CFContextSourceManager::MT_CCFContextSourceManager_NewLL |
|
456 //----------------------------------------------------------------------------- |
|
457 // |
|
458 void MT_CFContextSourceManager::MT_CCFContextSourceManager_NewLL( ) |
|
459 { |
|
460 RFs fs; |
|
461 User::LeaveIfError( fs.Connect() ); |
|
462 CleanupClosePushL( fs ); |
|
463 |
|
464 CCFContextSourceManager* instance = |
|
465 CCFContextSourceManager::NewL( *this, fs ); |
|
466 CleanupStack::PushL( instance ); |
|
467 |
|
468 EUNIT_ASSERT_DESC( instance, "CCFContextSourceManager instance not created!" ); |
|
469 |
|
470 CleanupStack::PopAndDestroy( instance ); |
|
471 CleanupStack::PopAndDestroy( &fs ); |
|
472 } |
|
473 |
|
474 //----------------------------------------------------------------------------- |
|
475 // MT_CFContextSourceManager::MT_CCFContextSourceManager_NewLL |
|
476 //----------------------------------------------------------------------------- |
|
477 // |
|
478 void MT_CFContextSourceManager::MT_CCFContextSourceManager_NewLCL( ) |
|
479 { |
|
480 RFs fs; |
|
481 User::LeaveIfError( fs.Connect() ); |
|
482 CleanupClosePushL( fs ); |
|
483 |
|
484 CCFContextSourceManager* instance = |
|
485 CCFContextSourceManager::NewLC( *this, fs ); |
|
486 |
|
487 EUNIT_ASSERT_DESC( instance, "CCFContextSourceManager instance not created!" ); |
|
488 |
|
489 CleanupStack::PopAndDestroy( instance ); |
|
490 CleanupStack::PopAndDestroy( &fs ); |
|
491 } |
|
492 |
|
493 //----------------------------------------------------------------------------- |
|
494 // MT_CFContextSourceManager::MT_CCFContextSourceManager_InitializePhaseL1L |
|
495 //----------------------------------------------------------------------------- |
|
496 // |
|
497 void MT_CFContextSourceManager::MT_CCFContextSourceManager_InitializePhaseL1L( ) |
|
498 { |
|
499 // Activate checks |
|
500 TInt err = RProperty::Set( KContextSourceTestCategory, KDisableChecks, 1 ); |
|
501 |
|
502 // Load only first phase plug-ins (TestContextSourcePlugin) |
|
503 MCFStarterObserver* instance = |
|
504 static_cast<MCFStarterObserver*>( iContextSourceManager ); |
|
505 instance->InitializePhaseL( CCFPhaseBase::ECFDeviceStarting ); |
|
506 TTimeIntervalMicroSeconds32 interval( KPluginLoadWaitDelay ); |
|
507 Wait( interval ); |
|
508 } |
|
509 |
|
510 //----------------------------------------------------------------------------- |
|
511 // MT_CFContextSourceManager::MT_CCFContextSourceManager_InitializePhaseL2L |
|
512 //----------------------------------------------------------------------------- |
|
513 // |
|
514 void MT_CFContextSourceManager::MT_CCFContextSourceManager_InitializePhaseL2L( ) |
|
515 { |
|
516 // Activate checks |
|
517 TInt err = RProperty::Set( KContextSourceTestCategory, KDisableChecks, 1 ); |
|
518 |
|
519 // Load all phases |
|
520 MCFStarterObserver* instance = |
|
521 static_cast<MCFStarterObserver*>( iContextSourceManager ); |
|
522 instance->InitializePhaseL( CCFPhaseBase::ECFDeviceStarting ); |
|
523 TTimeIntervalMicroSeconds32 interval( KPluginLoadWaitDelay ); |
|
524 Wait( interval ); |
|
525 instance->InitializePhaseL( CCFPhaseBase::ECFDeviceStarted ); |
|
526 Wait( interval ); |
|
527 instance->InitializePhaseL( CCFPhaseBase::ECFLoadingPlugins ); |
|
528 Wait( interval ); |
|
529 instance->InitializePhaseL( CCFPhaseBase::ECFLoadingRules ); |
|
530 Wait( interval ); |
|
531 instance->InitializePhaseL( CCFPhaseBase::ECFCfwReady ); |
|
532 Wait( interval ); |
|
533 } |
|
534 |
|
535 //----------------------------------------------------------------------------- |
|
536 // MT_CFContextSourceManager::MT_CCFContextSourceManager_InstallUninstallSettingL |
|
537 //----------------------------------------------------------------------------- |
|
538 // |
|
539 void MT_CFContextSourceManager::MT_CCFContextSourceManager_InstallUninstallSettingL( ) |
|
540 { |
|
541 MT_CCFContextSourceManager_InitializePhaseL2L(); |
|
542 |
|
543 // Open the file. |
|
544 RFile settingFile; |
|
545 TInt err = settingFile.Open( iFs, |
|
546 _L("z:\\data\\cftestdata\\testsettings\\testcontextsourcesetting3.xml"), |
|
547 EFileRead ); |
|
548 EUNIT_ASSERT_DESC( err == KErrNone, "Error when opening settings3!" ); |
|
549 CleanupClosePushL( settingFile ); // CLEANUP<< settingFile |
|
550 |
|
551 RThread client; |
|
552 CleanupClosePushL( client ); // CLEANUP<< client |
|
553 |
|
554 // 1. Install setting succeeds |
|
555 iContextSourceManager->InstallSettingL( settingFile, |
|
556 KTestContextSourcePluginImplUid, |
|
557 client ); |
|
558 |
|
559 TBool fileExists = BaflUtils::FileExists( iFs, |
|
560 _L( "C:\\Private\\10282BC4\\Settings\\10002001\\20000fb1_testcontextsourcesetting3.xml" ) ) ; |
|
561 EUNIT_ASSERT_DESC( fileExists, "Error, cannot find settings3 file after install!" ); |
|
562 |
|
563 // 2. Uninstall setting succeeds |
|
564 iContextSourceManager->UninstallSettingL( |
|
565 _L("testcontextsourcesetting3.xml"), |
|
566 KTestContextSourcePluginImplUid, |
|
567 client ); |
|
568 |
|
569 fileExists = BaflUtils::FileExists( iFs, |
|
570 _L( "C:\\Private\\10282BC4\\Settings\\10002001\\20000fb1_testcontextsourcesetting3.xml" ) ) ; |
|
571 EUNIT_ASSERT_DESC( !fileExists, "Error, settings3 file exists after uninstall!" ); |
|
572 |
|
573 // 3. Install setting leaves during UpdateSettingsL |
|
574 RFile settingFile2; |
|
575 err = settingFile2.Open( iFs, |
|
576 _L("z:\\data\\cftestdata\\testsettings\\testcontextsourcesetting7.xml"), |
|
577 EFileRead ); |
|
578 EUNIT_ASSERT_DESC( err == KErrNone, "Error when opening settings7!" ); |
|
579 CleanupClosePushL( settingFile2 ); // CLEANUP<< settingFile2 |
|
580 |
|
581 EUNIT_ASSERT_SPECIFIC_LEAVE( |
|
582 iContextSourceManager->InstallSettingL( settingFile2, |
|
583 KTestContextSourcePluginImplUid, |
|
584 client ), |
|
585 KErrGeneral ); |
|
586 |
|
587 // 4. Uninstall setting succeeds |
|
588 iContextSourceManager->UninstallSettingL( |
|
589 _L("testcontextsourcesetting7.xml"), |
|
590 KTestContextSourcePluginImplUid, |
|
591 client ); |
|
592 |
|
593 fileExists = BaflUtils::FileExists( iFs, |
|
594 _L( "C:\\Private\\10282BC4\\Settings\\10002001\\20000fb1_testcontextsourcesetting7.xml" ) ) ; |
|
595 EUNIT_ASSERT_DESC( !fileExists, "Error, settings3 file exists after uninstall!" ); |
|
596 |
|
597 CleanupStack::PopAndDestroy( &settingFile2 ); // CLEANUP>> settingFile2 |
|
598 CleanupStack::PopAndDestroy( &client ); // CLEANUP>> client |
|
599 CleanupStack::PopAndDestroy( &settingFile ); // CLEANUP>> settingFile |
|
600 } |
|
601 |
|
602 //----------------------------------------------------------------------------- |
|
603 // MT_CFContextSourceManager::MT_CCFContextSourceManager_TestContextSourcePluginsMemoryL |
|
604 //----------------------------------------------------------------------------- |
|
605 // |
|
606 void MT_CFContextSourceManager::MT_CCFContextSourceManager_TestContextSourcePluginsMemoryL( ) |
|
607 { |
|
608 // Disable checks |
|
609 TInt err = RProperty::Set( KContextSourceTestCategory, KDisableChecks, 0 ); |
|
610 |
|
611 TBool fail = EFalse; |
|
612 TContextSourceInitParams params( *this ); |
|
613 RImplInfoPtrArray list; |
|
614 CleanupResetAndDestroyPushL( list ); |
|
615 REComSession::ListImplementationsL( KContextSourcePlugInInterface, list ); |
|
616 |
|
617 EUNIT_PRINT( _L("Found %d plugins."), list.Count() ); |
|
618 |
|
619 TInt count = list.Count(); |
|
620 CImplementationInformation* info = NULL; |
|
621 for( TInt i = 0; i < count; i++ ) |
|
622 { |
|
623 info = list[i]; |
|
624 // Force ECom to clean up garbage so it doesn't affect memory consumption. |
|
625 REComSession::FinalClose(); |
|
626 |
|
627 TInt before = 0; |
|
628 TInt after = 0; |
|
629 before = User::CountAllocCells(); |
|
630 |
|
631 CCFContextSourcePlugIn* plugIn = NULL; |
|
632 TRAPD( err, plugIn = CreateAndInitializePlugInL( |
|
633 info->ImplementationUid(), |
|
634 params ) ); |
|
635 if( err == KErrNone ) |
|
636 { |
|
637 TAny* ptr = plugIn->Extension( KNullUid ); |
|
638 EUNIT_ASSERT_DESC( !ptr, "Invalid extension interface returned" ); |
|
639 delete plugIn; |
|
640 plugIn = NULL; |
|
641 |
|
642 // Force ECom to clean up garbage |
|
643 REComSession::FinalClose(); |
|
644 |
|
645 after = User::CountAllocCells(); |
|
646 if( before != after ) |
|
647 { |
|
648 fail = ETrue; |
|
649 EUNIT_PRINT( _L("Plug-in [Name: %S], [Uid: 0x%x] leaked %d cells."), |
|
650 &info->DisplayName(), |
|
651 info->ImplementationUid().iUid, |
|
652 after - before ); |
|
653 } |
|
654 else |
|
655 { |
|
656 EUNIT_PRINT( _L("Plug-in [Name: %S], [Uid: 0x%x] did not leak memory."), |
|
657 &info->DisplayName(), |
|
658 info->ImplementationUid().iUid ); |
|
659 } |
|
660 } |
|
661 else |
|
662 { |
|
663 EUNIT_PRINT( _L("Failed to load plug-in [Name: %S], [Uid: 0x%x]."), |
|
664 &info->DisplayName(), |
|
665 info->ImplementationUid().iUid ); |
|
666 } |
|
667 } |
|
668 |
|
669 if( fail ) |
|
670 { |
|
671 EUNIT_PRINT( _L("Memory leaks detected!") ); |
|
672 EUNIT_ASSERT( EFalse ); |
|
673 } |
|
674 else |
|
675 { |
|
676 EUNIT_PRINT( _L("No memory leaks detected in plug-ins.") ); |
|
677 } |
|
678 |
|
679 // Clean up |
|
680 CleanupStack::PopAndDestroy( &list ); |
|
681 } |
|
682 |
|
683 // TEST TABLE |
|
684 |
|
685 EUNIT_BEGIN_TEST_TABLE( |
|
686 MT_CFContextSourceManager, |
|
687 "CFContextSourceManager module test", |
|
688 "MODULE" ) |
|
689 |
|
690 EUNIT_TEST( |
|
691 "NewL - test ", |
|
692 "CCFContextSourceManager", |
|
693 "NewL", |
|
694 "FUNCTIONALITY", |
|
695 SetupEmptyL, MT_CCFContextSourceManager_NewLL, Teardown) |
|
696 |
|
697 EUNIT_TEST( |
|
698 "NewLC - test ", |
|
699 "CCFContextSourceManager", |
|
700 "NewLC", |
|
701 "FUNCTIONALITY", |
|
702 SetupEmptyL, MT_CCFContextSourceManager_NewLCL, Teardown) |
|
703 |
|
704 EUNIT_TEST( |
|
705 "InitializePhaseL 1 - test ", |
|
706 "CCFContextSourceManager", |
|
707 "InitializePhaseL", |
|
708 "FUNCTIONALITY", |
|
709 SetupL, MT_CCFContextSourceManager_InitializePhaseL1L, Teardown) |
|
710 |
|
711 EUNIT_TEST( |
|
712 "InitializePhaseL 2 - test ", |
|
713 "CCFContextSourceManager", |
|
714 "InitializePhaseL", |
|
715 "FUNCTIONALITY", |
|
716 SetupL, MT_CCFContextSourceManager_InitializePhaseL2L, Teardown) |
|
717 |
|
718 EUNIT_TEST( |
|
719 "Install/Uninstall Setting - test ", |
|
720 "CCFContextSourceManager", |
|
721 "Install/UninstallSettingL", |
|
722 "FUNCTIONALITY", |
|
723 SetupL, MT_CCFContextSourceManager_InstallUninstallSettingL, Teardown) |
|
724 |
|
725 EUNIT_TEST( |
|
726 "Check plug-ins for memory leaks - test ", |
|
727 "CCFContextSourceManager", |
|
728 "Construction", |
|
729 "FUNCTIONALITY", |
|
730 SetupPluginsL, MT_CCFContextSourceManager_TestContextSourcePluginsMemoryL, Teardown) |
|
731 |
|
732 EUNIT_END_TEST_TABLE |
|
733 |
|
734 // END OF FILE |