contextframework/cfw/tsrc/public/basic/UT_CCFContextManager/UT_CCFContextManager.cpp
changeset 0 2e3d3ce01487
child 19 924385140d98
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     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 "UT_CCFContextManager.h"
       
    21 
       
    22 //  EXTERNAL INCLUDES
       
    23 #include <EUnitMacros.h>
       
    24 
       
    25 
       
    26 //  INTERNAL INCLUDES
       
    27 #include "CFContextManager.h"
       
    28 #include "CFContextIndication.h"
       
    29 #include "CFContextSubscription.h"
       
    30 #include "cfcontextobjectimpl.h"
       
    31 #include "cfenvutils.h"
       
    32 
       
    33 
       
    34 // CONSTRUCTION
       
    35 UT_CCFContextManager* UT_CCFContextManager::NewL()
       
    36     {
       
    37     UT_CCFContextManager* self = UT_CCFContextManager::NewLC();
       
    38     CleanupStack::Pop();
       
    39 
       
    40     return self;
       
    41     }
       
    42 
       
    43 UT_CCFContextManager* UT_CCFContextManager::NewLC()
       
    44     {
       
    45     UT_CCFContextManager* self = new( ELeave ) UT_CCFContextManager();
       
    46     CleanupStack::PushL( self );
       
    47 
       
    48     self->ConstructL();
       
    49 
       
    50     return self;
       
    51     }
       
    52 
       
    53 // Destructor (virtual by CBase)
       
    54 UT_CCFContextManager::~UT_CCFContextManager()
       
    55     {
       
    56     // ETrue screen saver
       
    57     CFEnvUtils::EnableScreenSaver( ETrue );
       
    58     }
       
    59 
       
    60 // Default constructor
       
    61 UT_CCFContextManager::UT_CCFContextManager()
       
    62     {
       
    63     }
       
    64 
       
    65 // Second phase construct
       
    66 void UT_CCFContextManager::ConstructL()
       
    67     {
       
    68     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    69     // It generates the test case table.
       
    70     CEUnitTestSuiteClass::ConstructL();
       
    71 
       
    72     // Disable screen saver
       
    73     CFEnvUtils::EnableScreenSaver( EFalse );
       
    74     }
       
    75 
       
    76 
       
    77 // INTERFACE IMPLEMENTATIONS
       
    78 
       
    79 // from MCFContextSubscriptionListener
       
    80 void UT_CCFContextManager::ContextIndicationL( 
       
    81 	CCFContextIndication* aIndication )
       
    82 	{
       
    83 	iIndication = ETrue;
       
    84 	delete iContextIndication;
       
    85 	iContextIndication = aIndication;		
       
    86     }
       
    87 
       
    88 // from MCFContextSubscriptionListener
       
    89 TInt UT_CCFContextManager::Client( RThread& aThread ) const
       
    90 	{
       
    91 	aThread = RThread();
       
    92 	return KErrNone;
       
    93 	}
       
    94         
       
    95 // from MCFContextSubscriptionListener
       
    96 void UT_CCFContextManager::HandleContextSubscriptionError( TInt /*aError*/,
       
    97             const TDesC& /*aSource*/,
       
    98             const TDesC& /*aType*/ )
       
    99     {
       
   100     iSubscriptionError = ETrue;
       
   101     StopWait();
       
   102     }
       
   103 
       
   104 
       
   105 
       
   106 
       
   107 // from MCFContextSource
       
   108 void UT_CCFContextManager::Subscribers( const TDesC& aContextSource,
       
   109     const TDesC& aContextType )
       
   110 	{
       
   111 	iSubscribersCalled = ETrue;
       
   112 	EUNIT_ASSERT_DESC( iExpectedSubscribersSource.Compare( aContextSource ) == 0,
       
   113 			"No expected source");
       
   114 	EUNIT_ASSERT_DESC( iExpectedSubscribersType.Compare( aContextType ) == 0,
       
   115 			"No expected type");
       
   116 	}
       
   117 
       
   118 // from MCFContextSource
       
   119 void UT_CCFContextManager::NoSubscribers( const TDesC& aContextSource,
       
   120     const TDesC& aContextType )
       
   121 	{
       
   122 	iNoSubscribersCalled = ETrue;
       
   123 	EUNIT_ASSERT_DESC( iExpectedSubscribersSource.Compare( aContextSource ) == 0,
       
   124 	"No expected source");
       
   125 	EUNIT_ASSERT_DESC( iExpectedSubscribersType.Compare( aContextType ) == 0,
       
   126 	"No expected type");
       
   127 	}
       
   128 
       
   129 // from MCFContextSource
       
   130 void UT_CCFContextManager::HandleCommand(
       
   131     const CCFContextSourceCommand& /*aCommand*/ )
       
   132     {
       
   133     // Nothing to do.
       
   134     }
       
   135 
       
   136 
       
   137 // from MCFSecurityChecker
       
   138 TBool UT_CCFContextManager::CheckClientSecurity( const RThread& aClientThread,
       
   139 	const TSecurityPolicy& aSecurityPolicy )
       
   140 	{
       
   141     // Security check only needed if request is from other process than CF
       
   142     TBool securityPassed = ETrue;
       
   143     
       
   144     if ( iBypassSecurityCheck == 0 )
       
   145     	{
       
   146     	securityPassed = aSecurityPolicy.CheckPolicy( aClientThread );
       
   147     	}
       
   148     else
       
   149     	{
       
   150     	iBypassSecurityCheck--;	
       
   151     	}
       
   152     return securityPassed;
       
   153 	}
       
   154 
       
   155 
       
   156 //  METHODS
       
   157 
       
   158 
       
   159 void UT_CCFContextManager::SetupForNewL(  )
       
   160     {
       
   161 	iWait = new( ELeave ) CActiveSchedulerWait;
       
   162     }
       
   163 
       
   164 void UT_CCFContextManager::StopWait()
       
   165 	{
       
   166 	if( iWait )
       
   167         {
       
   168         if( iWait->IsStarted() )
       
   169             {
       
   170             iWait->AsyncStop();
       
   171             }
       
   172         delete iWait;
       
   173         iWait = NULL;
       
   174         }	
       
   175 	}
       
   176 
       
   177 void UT_CCFContextManager::TeardownForNewL(  )
       
   178     {
       
   179 	if( iWait )
       
   180         {
       
   181         if( iWait->IsStarted() )
       
   182             {
       
   183             iWait->AsyncStop();
       
   184             }
       
   185         delete iWait;
       
   186         iWait = NULL;
       
   187         }
       
   188     }
       
   189 
       
   190 
       
   191 void UT_CCFContextManager::SetupL(  )
       
   192     {
       
   193 	SetupForNewL();
       
   194 	iCFContextManager = CCFContextManager::NewL( *this );
       
   195 	iCFContextManagerInterface = iCFContextManager;
       
   196     }
       
   197 
       
   198 void UT_CCFContextManager::Teardown(  )
       
   199     {
       
   200     delete iContextIndication;
       
   201     iContextIndication = NULL;
       
   202 	delete iCFContextManager;
       
   203 	iCFContextManagerInterface = NULL;
       
   204 	iIndication = EFalse;
       
   205 	iSubscriptionError = EFalse;
       
   206 	iSubscribersCalled = EFalse;
       
   207 	iNoSubscribersCalled = EFalse;
       
   208 	TeardownForNewL();
       
   209     }
       
   210 
       
   211 
       
   212 void UT_CCFContextManager::SetupContextCacheL()
       
   213 	{
       
   214 	RThread thread;
       
   215 	CleanupClosePushL(thread);
       
   216 	CCFContextObject* co = CCFContextObject::NewLC();
       
   217 	static _LIT_SECURITY_POLICY_PASS( alwaysPass );
       
   218 	
       
   219 	static _LIT_SECURITY_POLICY_FAIL( alwaysFail );
       
   220 
       
   221 	// CONTEXT 1
       
   222 	co->SetSourceL(_L("SourceA"));
       
   223 	co->SetTypeL(_L("TypeA"));
       
   224 	co->SetValueL(_L("ValueBA"));
       
   225 	EUNIT_ASSERT_NO_LEAVE (
       
   226 		iCFContextManagerInterface->DefineContextL( co->Source(),
       
   227 		co->Type(), alwaysPass, alwaysPass ) );
       
   228 	EUNIT_ASSERT_NO_LEAVE (
       
   229 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   230 
       
   231 	// CONTEXT 2
       
   232 	co->SetSourceL(_L("SourceB"));
       
   233 	co->SetTypeL(_L("TypeA"));
       
   234 	co->SetValueL(_L("ValueBA"));
       
   235 	EUNIT_ASSERT_NO_LEAVE (
       
   236 		iCFContextManagerInterface->DefineContextL( co->Source(),
       
   237 		co->Type(), alwaysPass, alwaysPass ) );
       
   238 	EUNIT_ASSERT_NO_LEAVE (
       
   239 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   240 
       
   241 	// CONTEXT 3
       
   242 	co->SetSourceL(_L("SourceC"));
       
   243 	co->SetTypeL(_L("TypeC"));
       
   244 	co->SetValueL(_L("ValueCC"));
       
   245 	EUNIT_ASSERT_NO_LEAVE (
       
   246 		iCFContextManagerInterface->DefineContextL( co->Source(),
       
   247 		co->Type(), alwaysPass, alwaysPass ) );
       
   248 	EUNIT_ASSERT_NO_LEAVE (
       
   249 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   250 
       
   251 	// CONTEXT 4
       
   252 	co->SetSourceL(_L("SourceC"));
       
   253 	co->SetTypeL(_L("TypeD"));
       
   254 	co->SetValueL(_L("ValueCD"));
       
   255 	EUNIT_ASSERT_NO_LEAVE (
       
   256 		iCFContextManagerInterface->DefineContextL( co->Source(),
       
   257 		co->Type(), alwaysPass, alwaysPass ) );
       
   258 	EUNIT_ASSERT_NO_LEAVE (
       
   259 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   260 
       
   261 	// CONTEXT 5
       
   262 	co->SetSourceL(_L("SourceC"));
       
   263 	co->SetTypeL(_L("TypeC.SubtypeA"));
       
   264 	co->SetValueL(_L("ValueCCA"));
       
   265 	EUNIT_ASSERT_NO_LEAVE (
       
   266 		iCFContextManagerInterface->DefineContextL( co->Source(),
       
   267 		co->Type(), alwaysPass, alwaysPass ) );
       
   268 	EUNIT_ASSERT_NO_LEAVE (
       
   269 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   270 
       
   271 	// CONTEXT 6
       
   272 	co->SetSourceL(_L("SourceC"));
       
   273 	co->SetTypeL(_L("TypeC.SubtypeB"));
       
   274 	co->SetValueL(_L("ValueCCB"));
       
   275 	EUNIT_ASSERT_NO_LEAVE (
       
   276 		iCFContextManagerInterface->DefineContextL( co->Source(),
       
   277 		co->Type(), alwaysPass, alwaysPass ) );
       
   278 	EUNIT_ASSERT_NO_LEAVE (
       
   279 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   280 
       
   281 
       
   282 	// bypass security check so that we publish context with high capabilities
       
   283 
       
   284 	// CONTEXT  - no read or write access
       
   285 	co->SetSourceL(_L("SourceE"));
       
   286 	co->SetTypeL(_L("TypeE.NoaccessA"));
       
   287 	co->SetValueL(_L("ValueEEA"));
       
   288 	EUNIT_ASSERT_NO_LEAVE (
       
   289 		iCFContextManagerInterface->DefineContextL( co->Source(),
       
   290 		co->Type(), alwaysFail, alwaysFail ) );
       
   291 	iBypassSecurityCheck = 1;
       
   292 	EUNIT_ASSERT_NO_LEAVE (
       
   293 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   294 
       
   295 	// CONTEXT - no write access
       
   296 	co->SetSourceL(_L("SourceE"));
       
   297 	co->SetTypeL(_L("TypeE.NoWriteAccessA"));
       
   298 	co->SetValueL(_L("ValueEEA"));
       
   299 	EUNIT_ASSERT_NO_LEAVE (
       
   300 		iCFContextManagerInterface->DefineContextL( co->Source(),
       
   301 		co->Type(), alwaysPass, alwaysFail ) );
       
   302 	iBypassSecurityCheck = 1;
       
   303 	EUNIT_ASSERT_NO_LEAVE (
       
   304 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   305 
       
   306 	// CONTEXT - no read access
       
   307 	co->SetSourceL(_L("SourceE"));
       
   308 	co->SetTypeL(_L("TypeE.NoReadAccessA"));
       
   309 	co->SetValueL(_L("ValueEEA"));
       
   310 	EUNIT_ASSERT_NO_LEAVE (
       
   311 		iCFContextManagerInterface->DefineContextL( co->Source(),
       
   312 		co->Type(), alwaysFail, alwaysPass ) );
       
   313 	iBypassSecurityCheck = 1;
       
   314 	EUNIT_ASSERT_NO_LEAVE (
       
   315 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   316 	
       
   317 	// CONTEXT - full access
       
   318 	co->SetSourceL(_L("SourceE"));
       
   319 	co->SetTypeL(_L("TypeE.AccessB"));
       
   320 	co->SetValueL(_L("ValueEEB"));
       
   321 	EUNIT_ASSERT_NO_LEAVE (
       
   322 		iCFContextManagerInterface->DefineContextL( co->Source(),
       
   323 		co->Type(), alwaysPass, alwaysPass ) );
       
   324 	iBypassSecurityCheck = 1;
       
   325 	EUNIT_ASSERT_NO_LEAVE (
       
   326 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   327 
       
   328 	CleanupStack::PopAndDestroy( co );
       
   329 	CleanupStack::PopAndDestroy( &thread );
       
   330 	}
       
   331 
       
   332 TInt UT_CCFContextManager::FindContext(RContextObjectArray& aArray, 
       
   333 	const TDesC& aSource, const TDesC& aType, const TDesC& aValue)
       
   334 	{
       
   335 	TInt index = KErrNotFound;
       
   336 	for (TInt i = 0; i < aArray.Count(); i++)
       
   337 		{
       
   338 		if (aArray[i]->Source() == aSource &&
       
   339 			aArray[i]->Type() == aType)
       
   340 			{
       
   341 			if (index == KErrNotFound)
       
   342 				{
       
   343 				index = i;
       
   344 				if (aArray[i]->Value() == aValue)
       
   345 					{
       
   346 					return index;	
       
   347 					}
       
   348 				else
       
   349 					{
       
   350 					return -3; // found but wrong value!
       
   351 					}
       
   352 				}
       
   353 			else 
       
   354 				{
       
   355 				index = -2; // Duplicate found!
       
   356 				}
       
   357 			}
       
   358 		}
       
   359 	return index;
       
   360 	} 
       
   361 
       
   362 
       
   363 // TESTS
       
   364 
       
   365 void UT_CCFContextManager::UT_CCFContextManager_NewLL(  )
       
   366     {
       
   367     CCFContextManager* instance = CCFContextManager::NewL( *this );
       
   368     CleanupStack::PushL ( instance );
       
   369     EUNIT_ASSERT_DESC ( instance, "CCFContextManager not created!" );
       
   370     CleanupStack::PopAndDestroy( instance );
       
   371     }
       
   372 
       
   373 void UT_CCFContextManager::UT_CCFContextManager_NewLCL(  )
       
   374     {
       
   375     CCFContextManager* instance = CCFContextManager::NewLC( *this );
       
   376     EUNIT_ASSERT_DESC ( instance, "CCFContextManager not created!" );
       
   377     CleanupStack::PopAndDestroy( instance );
       
   378     }
       
   379 
       
   380 void UT_CCFContextManager::UT_CCFContextManager_PublishContextLL(  )
       
   381     {
       
   382 	RThread thread;
       
   383 	CleanupClosePushL(thread);
       
   384 
       
   385 	CCFContextObject* co = CCFContextObject::NewLC();
       
   386 	co->SetSourceL(_L("testsource"));
       
   387 	co->SetTypeL(_L("testtype"));
       
   388 	co->SetValueL(_L("testvalue"));
       
   389 	EUNIT_ASSERT_LEAVE ( iCFContextManagerInterface
       
   390 		->PublishContextL( *co, thread ) );
       
   391 		//, "Context published succeed without defining!" );
       
   392 	
       
   393 	static _LIT_SECURITY_POLICY_PASS( alwaysPass );
       
   394 	EUNIT_ASSERT_NO_LEAVE ( 
       
   395 		iCFContextManagerInterface->DefineContextL( _L("testsource"),
       
   396 		_L("testtype"), alwaysPass, alwaysPass ) );
       
   397 	
       
   398 	EUNIT_ASSERT_NO_LEAVE ( 
       
   399 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   400 		
       
   401 	CleanupStack::PopAndDestroy( co );
       
   402 	CleanupStack::PopAndDestroy( &thread );
       
   403     }
       
   404 
       
   405 
       
   406 void UT_CCFContextManager::UT_CCFContextManager_RequestContextL_2L(  )
       
   407     {
       
   408 	RThread thread;
       
   409 	CleanupClosePushL(thread);
       
   410 	
       
   411 	SetupContextCacheL();
       
   412 
       
   413 	RContextObjectArray resultBuffer;
       
   414 	resultBuffer.Reset();
       
   415 
       
   416 	// QUERY 1
       
   417 
       
   418 	CCFContextQuery* query = CCFContextQuery::NewLC( KNullDesC, KNullDesC );
       
   419 	query->SetSourceL(_L("SourceC"));
       
   420 	query->SetTypeL(_L("TypeC"));
       
   421 	
       
   422     EUNIT_ASSERT_NO_LEAVE( 
       
   423     	iCFContextManagerInterface->RequestContextL(
       
   424     	resultBuffer,
       
   425         *query,
       
   426         thread )
       
   427 		);
       
   428 
       
   429 	EUNIT_ASSERT_DESC( resultBuffer.Count() == 1, 
       
   430 		"More than 1 context returned!" );
       
   431 
       
   432 	TInt index = FindContext(resultBuffer, _L("SourceC"), _L("TypeC"), _L("ValueCC"));
       
   433 	EUNIT_ASSERT_DESC( index >= 0, "ResultError!" );
       
   434 
       
   435 	// QUERY 2
       
   436 	
       
   437 	query->SetSourceL(_L("SourceC"));
       
   438 	query->SetTypeL(_L(""));
       
   439 	
       
   440 	resultBuffer.Reset();
       
   441 	query->SetSubTypeMatch(ETrue);
       
   442 
       
   443 	EUNIT_ASSERT_NO_LEAVE( 
       
   444     	iCFContextManagerInterface->RequestContextL(
       
   445     	resultBuffer,
       
   446         *query,
       
   447         thread )
       
   448 		);
       
   449 
       
   450 	EUNIT_ASSERT_DESC( resultBuffer.Count() == 4, 
       
   451 		"Did not return 4 contexts!" );
       
   452 
       
   453 	index = FindContext(resultBuffer, _L("SourceC"), _L("TypeC"), _L("ValueCC"));
       
   454 	EUNIT_ASSERT_DESC( index >= 0, "ResultError!" );
       
   455 
       
   456 	index = FindContext(resultBuffer, _L("SourceC"), _L("TypeD"), _L("ValueCD"));
       
   457 	EUNIT_ASSERT_DESC( index >= 0, "ResultError!" );
       
   458 
       
   459 	index = FindContext(resultBuffer, _L("SourceC"), _L("TypeC.SubtypeA"), _L("ValueCCA"));
       
   460 	EUNIT_ASSERT_DESC( index >= 0, "ResultError!" );
       
   461 
       
   462 	index = FindContext(resultBuffer, _L("SourceC"), _L("TypeC.SubtypeB"), _L("ValueCCB"));
       
   463 	EUNIT_ASSERT_DESC( index >= 0, "ResultError!" );
       
   464 
       
   465 	resultBuffer.Close();
       
   466 	CleanupStack::PopAndDestroy( query );
       
   467 	CleanupStack::PopAndDestroy( &thread );
       
   468     }
       
   469 
       
   470 void UT_CCFContextManager::UT_CCFContextManager_DefineContextLL(  )
       
   471     {
       
   472 	RThread thread;
       
   473 	CleanupClosePushL(thread);
       
   474 
       
   475 	// define context 1
       
   476 	static _LIT_SECURITY_POLICY_PASS( alwaysPass );
       
   477 	EUNIT_ASSERT_NO_LEAVE ( 
       
   478 		iCFContextManagerInterface->DefineContextL( _L("testsource"),
       
   479 		_L("testtype"), alwaysPass, alwaysPass ) );
       
   480 
       
   481 	// try to redefine 
       
   482     EUNIT_ASSERT_NO_LEAVE ( 
       
   483 		iCFContextManagerInterface->DefineContextL( _L("testsource"),
       
   484 		_L("testtype"), alwaysPass, alwaysPass ) );
       
   485 
       
   486 	CleanupStack::PopAndDestroy( &thread );	
       
   487     }
       
   488 
       
   489 void UT_CCFContextManager::UT_CCFContextManager_DefineContextL2L(  )
       
   490     {
       
   491 	RThread thread;
       
   492 	CleanupClosePushL(thread);
       
   493 
       
   494 	TUid uid = TUid::Uid( 123 );
       
   495 	
       
   496 	// define context 1
       
   497 	static _LIT_SECURITY_POLICY_PASS( alwaysPass );
       
   498 	EUNIT_ASSERT_NO_LEAVE ( 
       
   499 		iCFContextManagerInterface->DefineContextL( _L("testsource"),
       
   500 		_L("testtype"), alwaysPass, alwaysPass, this, uid ) );
       
   501 
       
   502 	// try to redefine 
       
   503 	EUNIT_ASSERT_NO_LEAVE ( 
       
   504 		iCFContextManagerInterface->DefineContextL( _L("testsource"),
       
   505 		_L("testtype"), alwaysPass, alwaysPass, this, uid ) );
       
   506 
       
   507 	// try to redefine with another UID
       
   508 	TUid anotherUid = TUid::Uid( 345 );
       
   509 	EUNIT_ASSERT_LEAVE (
       
   510 		iCFContextManagerInterface->DefineContextL( _L("testsource"),
       
   511 		_L("testtype"), alwaysPass, alwaysPass, this, anotherUid ) );
       
   512 	
       
   513 	// check that we get the subscribers notification
       
   514 	CCFContextSubscription* subscription = CCFContextSubscription::NewLC();
       
   515 	subscription->SetContextSourceL(_L("testsource"));
       
   516 	subscription->SetContextTypeL(_L("testtype"));
       
   517 	CleanupStack::Pop( subscription );
       
   518 
       
   519 	iSubscribersCalled = EFalse;
       
   520 	iExpectedSubscribersSource.Copy(_L("testsource"));
       
   521 	iExpectedSubscribersType.Copy(_L("testtype"));
       
   522 	
       
   523 	// make subscription	
       
   524 	EUNIT_ASSERT_NO_LEAVE (
       
   525 		iCFContextManagerInterface->SubscribeContextL(subscription,
       
   526 		this, thread) );
       
   527 	
       
   528 	EUNIT_ASSERT( iSubscribersCalled );
       
   529 	iSubscribersCalled = EFalse;
       
   530 	iNoSubscribersCalled = EFalse;
       
   531 	
       
   532 	
       
   533 	EUNIT_ASSERT_NO_LEAVE (
       
   534 			iCFContextManagerInterface->RemoveSubscription( *subscription,
       
   535 			*this) );
       
   536 
       
   537 	EUNIT_ASSERT( iNoSubscribersCalled );
       
   538 	
       
   539 	
       
   540 	CleanupStack::PopAndDestroy( &thread );	
       
   541     }
       
   542 
       
   543 
       
   544 
       
   545 void UT_CCFContextManager::UT_CCFContextManager_RequestContextL_3L(  )
       
   546     {
       
   547 	RThread thread;
       
   548 	CleanupClosePushL(thread);
       
   549 	
       
   550 	SetupContextCacheL();
       
   551 	CCFContextObject* co;
       
   552 	
       
   553     EUNIT_ASSERT_NO_LEAVE( 
       
   554     	co = iCFContextManagerInterface->RequestContextL(
       
   555     	_L("TypeA"),
       
   556         _L("SourceA"),
       
   557         thread )
       
   558 		);
       
   559 
       
   560 	EUNIT_ASSERT_DESC( co->Source() == _L("SourceA"), "Source doesn't match!");
       
   561 	EUNIT_ASSERT_DESC( co->Type() == _L("TypeA"), "Type doesn't match!");
       
   562 	EUNIT_ASSERT_DESC( co->Value() == _L("ValueBA"), "Value doesn't match!");
       
   563 
       
   564 	CleanupStack::PopAndDestroy( &thread );	
       
   565     }
       
   566 
       
   567 void UT_CCFContextManager::UT_CCFContextManager_SubscribeContextLL(  )
       
   568     {
       
   569 	RThread thread;
       
   570 	CleanupClosePushL(thread);
       
   571 
       
   572 	SetupContextCacheL();
       
   573 
       
   574 	CCFContextSubscription* subscription = CCFContextSubscription::NewLC();
       
   575 	subscription->SetContextSourceL(_L("SourceC"));
       
   576 	subscription->SetContextTypeL(_L("TypeC"));
       
   577 	CleanupStack::Pop( subscription );
       
   578 
       
   579 	// make subscription	
       
   580 	EUNIT_ASSERT_NO_LEAVE (
       
   581 		iCFContextManagerInterface->SubscribeContextL(subscription,
       
   582 		this, thread) );
       
   583 
       
   584 
       
   585 	CCFContextObject* co = CCFContextObject::NewLC();
       
   586 	co->SetSourceL(_L("SourceC"));
       
   587 	co->SetTypeL(_L("TypeC"));
       
   588 	co->SetValueL(_L("ValueCC2"));
       
   589 	EUNIT_ASSERT_NO_LEAVE (
       
   590 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   591 	
       
   592 	// check that we get the published context
       
   593 	EUNIT_ASSERT_DESC ( iIndication, "Context indication did not arrive");
       
   594 	const CCFContextObject* indicatedCo = &iContextIndication->Context();
       
   595 	EUNIT_ASSERT_DESC ( indicatedCo->Source() == _L("SourceC"),
       
   596 		"Source of indication does not match!" );
       
   597 	EUNIT_ASSERT_DESC ( indicatedCo->Type() == _L("TypeC"),
       
   598 		"Type of indication does not match!" );
       
   599 	EUNIT_ASSERT_DESC ( indicatedCo->Value() == _L("ValueCC2"),
       
   600 		"Value of indication does not match!" );
       
   601 	iIndication = EFalse;
       
   602 	
       
   603 	// Publish a context 	
       
   604 	//CCFContextObject co;
       
   605 	co->SetSourceL(_L("SourceC"));
       
   606 	co->SetTypeL(_L("TypeC.SubtypeB"));
       
   607 	co->SetValueL(_L("ValueCCB2"));
       
   608 	EUNIT_ASSERT_NO_LEAVE (
       
   609 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   610 	
       
   611 	// check that we did not get the published context
       
   612 	EUNIT_ASSERT_DESC ( !iIndication,
       
   613 		"Context indication arrived for context not listened!");
       
   614 
       
   615 
       
   616 	// check that when value not changed, still indicated default
       
   617 	co->SetSourceL(_L("SourceC"));
       
   618 	co->SetTypeL(_L("TypeC"));
       
   619 	co->SetValueL(_L("ValueCC2"));
       
   620 	EUNIT_ASSERT_NO_LEAVE (
       
   621 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   622 	
       
   623 	// check that we get the published context
       
   624 	EUNIT_ASSERT_DESC ( iIndication, "Context indication did not arrive");
       
   625 	indicatedCo = &iContextIndication->Context();
       
   626 	EUNIT_ASSERT_DESC ( indicatedCo->Source() == _L("SourceC"),
       
   627 		"Source of indication does not match!" );
       
   628 	EUNIT_ASSERT_DESC ( indicatedCo->Type() == _L("TypeC"),
       
   629 		"Type of indication does not match!" );
       
   630 	EUNIT_ASSERT_DESC ( indicatedCo->Value() == _L("ValueCC2"),
       
   631 		"Value of indication does not match!" );
       
   632 	iIndication = EFalse;
       
   633 	
       
   634 	// Test subscription for subtypes
       
   635 	iIndication = EFalse;
       
   636 
       
   637 	CCFContextSubscription* subscription2 = CCFContextSubscription::NewL();
       
   638 	subscription2->SetContextSourceL(_L("SourceC"));
       
   639 	subscription2->SetContextTypeL(_L("TypeC"));
       
   640 	subscription2->SetSubTypeMatch( ETrue );
       
   641 	subscription2->SetOnlyChangesIndicated( ETrue );
       
   642 
       
   643 	// make subscription	
       
   644 	EUNIT_ASSERT_NO_LEAVE (
       
   645 		iCFContextManagerInterface->SubscribeContextL(subscription2,
       
   646 		this, thread) );
       
   647 
       
   648 
       
   649 	//CCFContextObject co;
       
   650 	co->SetSourceL(_L("SourceC"));
       
   651 	co->SetTypeL(_L("TypeC.SubtypeA"));
       
   652 	co->SetValueL(_L("ValueCCA2"));
       
   653 	EUNIT_ASSERT_NO_LEAVE (
       
   654 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   655 	
       
   656 	// check that we get the published context
       
   657 	EUNIT_ASSERT_DESC ( iIndication, "Context indication did not arrive");
       
   658 	indicatedCo = &iContextIndication->Context();
       
   659 	EUNIT_ASSERT_DESC ( indicatedCo->Source() == _L("SourceC"),
       
   660 		"Source of indication does not match!" );
       
   661 	EUNIT_ASSERT_DESC ( indicatedCo->Type() == _L("TypeC.SubtypeA"),
       
   662 		"Type of indication does not match!" );
       
   663 	EUNIT_ASSERT_DESC ( indicatedCo->Value() == _L("ValueCCA2"),
       
   664 		"Value of indication does not match!" );
       
   665 	iIndication = EFalse;
       
   666 
       
   667 
       
   668 	// because of SetOnlyChangesIndicated( ETrue ) we should not get
       
   669 	// an indication when the remain the same
       
   670 	//CCFContextObject co;
       
   671 	co->SetSourceL(_L("SourceC"));
       
   672 	co->SetTypeL(_L("TypeC.SubtypeA"));
       
   673 	co->SetValueL(_L("ValueCCA2"));
       
   674 	EUNIT_ASSERT_NO_LEAVE (
       
   675 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   676 	
       
   677 	// check that we get the published context
       
   678 	EUNIT_ASSERT_DESC ( !iIndication, 
       
   679 		"Context indication despite of same value");
       
   680 
       
   681 
       
   682 
       
   683 	// Test subscription cases where there is no enough capabilities
       
   684 	CCFContextSubscription* subscription3 = CCFContextSubscription::NewL();
       
   685 	subscription3->SetContextSourceL(_L("SourceE"));
       
   686 	subscription3->SetContextTypeL(_L("TypeE.NoaccessA"));
       
   687 	//subscription2->SetSubTypeMatch( ETrue );
       
   688 	//subscription2->SetOnlyChangesIndicated( ETrue );
       
   689 
       
   690 	// make subscription	
       
   691 	EUNIT_ASSERT_NO_LEAVE (
       
   692 		iCFContextManagerInterface->SubscribeContextL(subscription3,
       
   693 		this, thread) );
       
   694 	
       
   695 	EUNIT_ASSERT_DESC ( iSubscriptionError,
       
   696 	"No subscription error when subscribing context defined with impossible capabilities");
       
   697 
       
   698 
       
   699 	// Verity that the subscription with insufficient capabilities does not
       
   700 	// indicate 
       
   701 	//CCFContextObject co;
       
   702 	iIndication = EFalse;
       
   703 	co->SetSourceL(_L("SourceE"));
       
   704 	co->SetTypeL(_L("TypeE.NoaccessA"));
       
   705 	co->SetValueL(_L("ValueEEA2"));
       
   706 	iBypassSecurityCheck = ETrue;
       
   707 	EUNIT_ASSERT_NO_LEAVE (
       
   708 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   709 	iBypassSecurityCheck = EFalse;
       
   710 	
       
   711 	// check that we get the published context
       
   712 	EUNIT_ASSERT_DESC ( !iIndication, 
       
   713 		"Context indication despite of insufficient capabilities");
       
   714 	
       
   715 	// Make a subscription with subtypes for TypeE
       
   716 	iSubscriptionError = EFalse;
       
   717 	CCFContextSubscription* subscription4 = CCFContextSubscription::NewL();
       
   718 	subscription4->SetContextSourceL(_L("SourceE"));
       
   719 	subscription4->SetContextTypeL(_L("TypeE"));
       
   720 	subscription4->SetSubTypeMatch( ETrue );
       
   721 	//subscription2->SetOnlyChangesIndicated( ETrue );
       
   722 
       
   723 	// make subscription	
       
   724 	EUNIT_ASSERT_NO_LEAVE (
       
   725 		iCFContextManagerInterface->SubscribeContextL(subscription4,
       
   726 		this, thread) );
       
   727 	
       
   728 	EUNIT_ASSERT_DESC ( iSubscriptionError,
       
   729 	"No subscription error when subscribing context defined with impossible capabilities");
       
   730 
       
   731 
       
   732 	// Verity that the subscription with insufficient capabilities does not
       
   733 	// indicate 
       
   734 	//CCFContextObject co;
       
   735 	iIndication = EFalse;
       
   736 	co->SetSourceL(_L("SourceE"));
       
   737 	co->SetTypeL(_L("TypeE.NoaccessA"));
       
   738 	co->SetValueL(_L("ValueEEA3"));
       
   739 	iBypassSecurityCheck = 1;
       
   740 	EUNIT_ASSERT_NO_LEAVE (
       
   741 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   742 	
       
   743 	// check that we do not get the published context
       
   744 	EUNIT_ASSERT_DESC ( !iIndication, 
       
   745 		"Context indication despite of insufficient capabilities");
       
   746 	
       
   747 	
       
   748 	// Check that the subtree with sufficient capabilities indicates
       
   749 	// indicate 
       
   750 	//CCFContextObject co;
       
   751 	iIndication = EFalse;
       
   752 	co->SetSourceL(_L("SourceE"));
       
   753 	co->SetTypeL(_L("TypeE.AccessB"));
       
   754 	co->SetValueL(_L("ValueEEB2"));
       
   755 	iBypassSecurityCheck = 1;
       
   756 	EUNIT_ASSERT_NO_LEAVE (
       
   757 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   758 
       
   759 	
       
   760 	// check that we get the published context
       
   761 	EUNIT_ASSERT_DESC ( iIndication, 
       
   762 		"Did not get indication for TypeE.AccessB although sufficient capabilities");
       
   763 
       
   764 
       
   765 	// define and publish context to verify cases if already made
       
   766 	// subscriptions subscribe right way to new definitions
       
   767 	
       
   768 	static _LIT_SECURITY_POLICY_PASS( alwaysPass );
       
   769 	
       
   770 	static _LIT_SECURITY_POLICY_FAIL( alwaysFail );
       
   771 	
       
   772 	
       
   773 	iSubscriptionError = EFalse;
       
   774 	
       
   775 	// CONTEXT 
       
   776 	co->SetSourceL(_L("SourceE"));
       
   777 	co->SetTypeL(_L("TypeE.NoaccessC"));
       
   778 	co->SetValueL(_L("ValueEEC"));
       
   779 	EUNIT_ASSERT_NO_LEAVE (
       
   780 		iCFContextManagerInterface->DefineContextL( co->Source(),
       
   781 		co->Type(), alwaysFail, alwaysFail ) );
       
   782 		
       
   783 	EUNIT_ASSERT_DESC ( iSubscriptionError,
       
   784 	"No subscription error when impossible capabilities!");
       
   785 		
       
   786 		
       
   787 	iIndication = EFalse;		
       
   788 	iBypassSecurityCheck = 1;
       
   789 	EUNIT_ASSERT_NO_LEAVE (
       
   790 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   791 
       
   792 	EUNIT_ASSERT_DESC ( !iIndication, 
       
   793 		"Indication for TypeE.NoaccessC although insufficient capabilities!");
       
   794 
       
   795 	iSubscriptionError = EFalse;
       
   796 
       
   797 	// CONTEXT 
       
   798 	co->SetSourceL(_L("SourceE"));
       
   799 	co->SetTypeL(_L("TypeE.AccessD"));
       
   800 	co->SetValueL(_L("ValueEED"));
       
   801 	EUNIT_ASSERT_NO_LEAVE (
       
   802 		iCFContextManagerInterface->DefineContextL( co->Source(),
       
   803 		co->Type(), alwaysPass, alwaysPass ) );
       
   804 
       
   805 	EUNIT_ASSERT_DESC ( !iSubscriptionError,
       
   806 	"Subscription error when capabilities are sufficient!");
       
   807 
       
   808 	iIndication = EFalse;
       
   809 	iBypassSecurityCheck = 1;
       
   810 	EUNIT_ASSERT_NO_LEAVE (
       
   811 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   812 
       
   813 	EUNIT_ASSERT_DESC ( iIndication, 
       
   814 		"No indication for TypeE.AccessD although sufficient capabilities!");
       
   815 	
       
   816 	
       
   817 	
       
   818 	// Test subscription cases where there is no enough capabilities
       
   819 	iSubscriptionError = EFalse;
       
   820 	CCFContextSubscription* subscription5 = CCFContextSubscription::NewL();
       
   821 	subscription5->SetContextSourceL(_L("SourceE"));
       
   822 	subscription5->SetContextTypeL(_L("TypeE.NoReadAccessA"));
       
   823 	//subscription2->SetSubTypeMatch( ETrue );
       
   824 	//subscription2->SetOnlyChangesIndicated( ETrue );
       
   825 
       
   826 	// make subscription	
       
   827 	EUNIT_ASSERT_NO_LEAVE (
       
   828 		iCFContextManagerInterface->SubscribeContextL(subscription5,
       
   829 		this, thread) );
       
   830 	
       
   831 	EUNIT_ASSERT_DESC ( iSubscriptionError,
       
   832 	"No subscription error when subscribing context defined with impossible capabilities");
       
   833 
       
   834 	
       
   835 	// Verity that the subscription with insufficient capabilities does not
       
   836 	// indicate 
       
   837 	//CCFContextObject co;
       
   838 	iIndication = EFalse;
       
   839 	co->SetSourceL(_L("SourceE"));
       
   840 	co->SetTypeL(_L("TypeE.NoReadAccessA"));
       
   841 	co->SetValueL(_L("ValueEEA3"));
       
   842 	
       
   843 	// with write access we do not have to bypass security check
       
   844 	// iBypassSecurityCheck = 1; 
       
   845 	EUNIT_ASSERT_NO_LEAVE (
       
   846 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   847 	
       
   848 	// check that we do not get the published context
       
   849 	EUNIT_ASSERT_DESC ( !iIndication, 
       
   850 		"Context indication despite of insufficient capabilities");
       
   851 
       
   852 	
       
   853 
       
   854 	// Test subscription cases where there is no enough capabilities
       
   855 	iSubscriptionError = EFalse;
       
   856 	CCFContextSubscription* subscription6 = CCFContextSubscription::NewL();
       
   857 	subscription6->SetContextSourceL(_L("SourceE"));
       
   858 	subscription6->SetContextTypeL(_L("TypeE.NoWriteAccessA"));
       
   859 	//subscription2->SetSubTypeMatch( ETrue );
       
   860 	//subscription2->SetOnlyChangesIndicated( ETrue );
       
   861 
       
   862 	// make subscription	
       
   863 	EUNIT_ASSERT_NO_LEAVE (
       
   864 		iCFContextManagerInterface->SubscribeContextL(subscription6,
       
   865 		this, thread) );
       
   866 	
       
   867 	EUNIT_ASSERT_DESC ( !iSubscriptionError,
       
   868 	"Subscription error when subscribing context defined with impossible capabilities");
       
   869 	
       
   870 	// Verity that we cannot publish context with no write access
       
   871 	// indicate 
       
   872 	//CCFContextObject co;
       
   873 	iIndication = EFalse;
       
   874 	co->SetSourceL(_L("SourceE"));
       
   875 	co->SetTypeL(_L("TypeE.NoWriteAccessA"));
       
   876 	co->SetValueL(_L("ValueEEA3"));
       
   877 	
       
   878 	// do not bypass
       
   879 	iBypassSecurityCheck = 0;
       
   880 	
       
   881 	EUNIT_ASSERT_LEAVE (
       
   882 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   883 	
       
   884 	// check that we do not get the published context
       
   885 	EUNIT_ASSERT_DESC ( !iIndication, 
       
   886 		"Context indication despite of insufficient capabilities");
       
   887 
       
   888 	
       
   889 	
       
   890 	
       
   891 	CleanupStack::PopAndDestroy( co );
       
   892 	CleanupStack::PopAndDestroy( &thread );
       
   893     }
       
   894 
       
   895 void UT_CCFContextManager::UT_CCFContextManager_RemoveSubscriptionL(  )
       
   896     {
       
   897 	RThread thread;
       
   898 	CleanupClosePushL(thread);
       
   899 
       
   900 	CCFContextSubscription* subscription = CCFContextSubscription::NewLC();
       
   901 	subscription->SetContextSourceL(_L("testsource"));
       
   902 	subscription->SetContextTypeL(_L("listenedtype"));
       
   903 	CleanupStack::Pop( subscription );
       
   904 
       
   905 	// make subscription	
       
   906 	EUNIT_ASSERT_NO_LEAVE (
       
   907 		iCFContextManagerInterface->SubscribeContextL(subscription,
       
   908 		this, thread) );
       
   909 
       
   910 	// define context
       
   911 	static _LIT_SECURITY_POLICY_PASS( alwaysPass );
       
   912 	EUNIT_ASSERT_NO_LEAVE (
       
   913 		iCFContextManagerInterface->DefineContextL( _L("testsource"),
       
   914 		_L("listenedtype"), alwaysPass, alwaysPass ) );
       
   915 
       
   916 	EUNIT_ASSERT_NO_LEAVE (
       
   917 		iCFContextManagerInterface->RemoveSubscription(*subscription,
       
   918 		*this) );
       
   919 
       
   920 	CCFContextObject* co = CCFContextObject::NewLC();
       
   921 	co->SetSourceL(_L("testsource"));
       
   922 	co->SetTypeL(_L("listenedtype"));
       
   923 	co->SetValueL(_L("testvalue"));
       
   924 	EUNIT_ASSERT_NO_LEAVE (
       
   925 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
   926 	
       
   927 	// check that we get the published context
       
   928 	EUNIT_ASSERT_DESC ( !iIndication, "Context indication shoud not have arrived");
       
   929 	iIndication = EFalse;
       
   930 		
       
   931 	CleanupStack::PopAndDestroy( co );
       
   932 	CleanupStack::PopAndDestroy( &thread );
       
   933     }
       
   934 
       
   935 void UT_CCFContextManager::UT_CCFContextManager_RemoveSubscription2L()
       
   936     {
       
   937     RThread thread;
       
   938     CleanupClosePushL(thread);
       
   939 
       
   940     CCFContextSubscription* dummySubscription = CCFContextSubscription::NewLC();
       
   941     dummySubscription->SetContextSourceL(_L("testsource"));
       
   942     dummySubscription->SetContextTypeL(_L("listenedtype"));
       
   943     CleanupStack::Pop( dummySubscription );
       
   944 
       
   945     // make the dummy subscription
       
   946     EUNIT_ASSERT_NO_LEAVE (
       
   947         iCFContextManagerInterface->SubscribeContextL(dummySubscription,
       
   948         this, thread) );
       
   949 
       
   950     CCFContextSubscription* subscription = CCFContextSubscription::NewLC();
       
   951     subscription->SetContextSourceL(_L("testsource"));
       
   952     subscription->SetContextTypeL(_L("listenedtype"));
       
   953     CleanupStack::Pop( subscription );
       
   954 
       
   955     // make subscription    
       
   956     EUNIT_ASSERT_NO_LEAVE (
       
   957         iCFContextManagerInterface->SubscribeContextL(subscription,
       
   958         this, thread) );
       
   959 
       
   960     // define context
       
   961     static _LIT_SECURITY_POLICY_PASS( alwaysPass );
       
   962     EUNIT_ASSERT_NO_LEAVE (
       
   963         iCFContextManagerInterface->DefineContextL( _L("testsource"),
       
   964         _L("listenedtype"), alwaysPass, alwaysPass ) );
       
   965 
       
   966     EUNIT_ASSERT_NO_LEAVE (
       
   967         iCFContextManagerInterface->RemoveSubscription(*subscription,
       
   968         *this) );
       
   969 
       
   970     CCFContextObject* co = CCFContextObject::NewLC();
       
   971     co->SetSourceL(_L("testsource"));
       
   972     co->SetTypeL(_L("listenedtype"));
       
   973     co->SetValueL(_L("testvalue"));
       
   974     EUNIT_ASSERT_NO_LEAVE (
       
   975         iCFContextManagerInterface->PublishContextL( *co, thread ) );   
       
   976     
       
   977     // check that we get the published context
       
   978     EUNIT_ASSERT_DESC ( !iIndication, "Context indication shoud not have arrived");
       
   979     iIndication = EFalse;
       
   980 
       
   981     CleanupStack::PopAndDestroy( co );
       
   982     CleanupStack::PopAndDestroy( &thread );
       
   983     }
       
   984 
       
   985 void UT_CCFContextManager::UT_CCFContextManager_RemoveSubscriptionsL(  )
       
   986     {
       
   987     RThread thread;
       
   988 	CleanupClosePushL(thread);
       
   989 
       
   990 	CCFContextSubscription* subscription = CCFContextSubscription::NewLC();
       
   991 	subscription->SetContextSourceL(_L("testsource"));
       
   992 	subscription->SetContextTypeL(_L("listenedtype"));
       
   993 	CleanupStack::Pop( subscription );
       
   994 
       
   995 	// make subscription	
       
   996 	EUNIT_ASSERT_NO_LEAVE (
       
   997 		iCFContextManagerInterface->SubscribeContextL(subscription,
       
   998 		this, thread) );
       
   999 
       
  1000 	// define context
       
  1001 	static _LIT_SECURITY_POLICY_PASS( alwaysPass );
       
  1002 	EUNIT_ASSERT_NO_LEAVE (
       
  1003 		iCFContextManagerInterface->DefineContextL( _L("testsource"),
       
  1004 		_L("listenedtype"), alwaysPass, alwaysPass ) );
       
  1005 
       
  1006 	EUNIT_ASSERT_NO_LEAVE (
       
  1007 		iCFContextManagerInterface->RemoveSubscriptions(this) );
       
  1008 
       
  1009 	CCFContextObject* co = CCFContextObject::NewLC();
       
  1010 	co->SetSourceL(_L("testsource"));
       
  1011 	co->SetTypeL(_L("listenedtype"));
       
  1012 	co->SetValueL(_L("testvalue"));
       
  1013 	EUNIT_ASSERT_NO_LEAVE (
       
  1014 		iCFContextManagerInterface->PublishContextL( *co, thread ) );	
       
  1015 	
       
  1016 	// check that we get the published context
       
  1017 	EUNIT_ASSERT_DESC ( !iIndication, "Context indication did not arrive");
       
  1018 	iIndication = EFalse;
       
  1019 		
       
  1020 	CleanupStack::PopAndDestroy( co );
       
  1021 	CleanupStack::PopAndDestroy( &thread );
       
  1022     }
       
  1023 
       
  1024 void UT_CCFContextManager::UT_CCFContextManager_DeregisterPublisherL(  )
       
  1025     {
       
  1026 	RThread thread;
       
  1027 	CleanupClosePushL(thread);
       
  1028 
       
  1029 	TUid uid = TUid::Uid( 123 );
       
  1030 	
       
  1031 	// define context 1
       
  1032 	static _LIT_SECURITY_POLICY_PASS( alwaysPass );
       
  1033 	EUNIT_ASSERT_NO_LEAVE ( 
       
  1034 		iCFContextManagerInterface->DefineContextL( _L("testsource"),
       
  1035 		_L("testtype"), alwaysPass, alwaysPass, this, uid ) );
       
  1036 
       
  1037 	
       
  1038 	// do deregistering
       
  1039 	iCFContextManagerInterface->DeregisterPublisher( *this );
       
  1040 	
       
  1041 	// check that we get the subscribers notification
       
  1042 	CCFContextSubscription* subscription = CCFContextSubscription::NewLC();
       
  1043 	subscription->SetContextSourceL(_L("testsource"));
       
  1044 	subscription->SetContextTypeL(_L("testtype"));
       
  1045 	CleanupStack::Pop( subscription );
       
  1046 
       
  1047 	iSubscribersCalled = EFalse;
       
  1048 	iExpectedSubscribersSource.Copy(_L("testsource"));
       
  1049 	iExpectedSubscribersType.Copy(_L("testtype"));
       
  1050 	
       
  1051 	// make subscription	
       
  1052 	EUNIT_ASSERT_NO_LEAVE (
       
  1053 		iCFContextManagerInterface->SubscribeContextL(subscription,
       
  1054 		this, thread) );
       
  1055 	
       
  1056 	EUNIT_ASSERT( !iSubscribersCalled );
       
  1057 	iSubscribersCalled = EFalse;
       
  1058 	iNoSubscribersCalled = EFalse;
       
  1059 	
       
  1060 	
       
  1061 	EUNIT_ASSERT_NO_LEAVE (
       
  1062 			iCFContextManagerInterface->RemoveSubscription( *subscription,
       
  1063 			*this) );
       
  1064 
       
  1065 	EUNIT_ASSERT( !iNoSubscribersCalled );
       
  1066 	
       
  1067 	
       
  1068 	CleanupStack::PopAndDestroy( &thread );	
       
  1069     }
       
  1070 
       
  1071 
       
  1072 
       
  1073 //  TEST TABLE
       
  1074 
       
  1075 EUNIT_BEGIN_TEST_TABLE(
       
  1076     UT_CCFContextManager,
       
  1077     "CCFContextManager class unit test.",
       
  1078     "UNIT" )
       
  1079 
       
  1080 EUNIT_TEST(
       
  1081     "NewL - test ",
       
  1082     "CCFContextManager",
       
  1083     "NewL",
       
  1084     "FUNCTIONALITY",
       
  1085     SetupForNewL, UT_CCFContextManager_NewLL, TeardownForNewL)
       
  1086 
       
  1087 EUNIT_TEST(
       
  1088     "NewLC - test ",
       
  1089     "CCFContextManager",
       
  1090     "NewLC",
       
  1091     "FUNCTIONALITY",
       
  1092     SetupForNewL, UT_CCFContextManager_NewLCL, TeardownForNewL)
       
  1093 
       
  1094 EUNIT_TEST(
       
  1095     "PublishContextL - test ",
       
  1096     "CCFContextManager",
       
  1097     "PublishContextL",
       
  1098     "FUNCTIONALITY",
       
  1099     SetupL, UT_CCFContextManager_PublishContextLL, Teardown)
       
  1100 
       
  1101 EUNIT_TEST(
       
  1102     "RequestContextL - test ",
       
  1103     "CCFContextManager",
       
  1104     "RequestContextL",
       
  1105     "FUNCTIONALITY",
       
  1106     SetupL, UT_CCFContextManager_RequestContextL_2L, Teardown)
       
  1107 
       
  1108 EUNIT_TEST(
       
  1109     "DefineContextL - test ",
       
  1110     "CCFContextManager",
       
  1111     "DefineContextL",
       
  1112     "FUNCTIONALITY",
       
  1113     SetupL, UT_CCFContextManager_DefineContextLL, Teardown)
       
  1114     
       
  1115 EUNIT_TEST(
       
  1116     "DefineContextL2 - test ",
       
  1117     "CCFContextManager",
       
  1118     "DefineContextL2",
       
  1119     "FUNCTIONALITY",
       
  1120     SetupL, UT_CCFContextManager_DefineContextL2L, Teardown)
       
  1121 
       
  1122 EUNIT_TEST(
       
  1123     "RequestContextL - test ",
       
  1124     "CCFContextManager",
       
  1125     "RequestContextL",
       
  1126     "FUNCTIONALITY",
       
  1127     SetupL, UT_CCFContextManager_RequestContextL_3L, Teardown)
       
  1128 
       
  1129 EUNIT_TEST(
       
  1130     "AddSubscriptionL - test ",
       
  1131     "CCFContextManager",
       
  1132     "AddSubscriptionL",
       
  1133     "FUNCTIONALITY",
       
  1134     SetupL, UT_CCFContextManager_SubscribeContextLL, Teardown)
       
  1135 
       
  1136 EUNIT_TEST(
       
  1137     "RemoveSubscription - test ",
       
  1138     "CCFContextManager",
       
  1139     "RemoveSubscription",
       
  1140     "FUNCTIONALITY",
       
  1141     SetupL, UT_CCFContextManager_RemoveSubscriptionL, Teardown)
       
  1142 
       
  1143 EUNIT_TEST(
       
  1144     "RemoveSubscription2 - two identical subscriptions and removing the last one",
       
  1145     "CCFContextManager",
       
  1146     "RemoveSubscription",
       
  1147     "FUNCTIONALITY",
       
  1148     SetupL, UT_CCFContextManager_RemoveSubscription2L, Teardown)
       
  1149 
       
  1150 EUNIT_TEST(
       
  1151     "RemoveSubscriptions - via listener interface",
       
  1152     "CCFContextManager",
       
  1153     "RemoveSubscription",
       
  1154     "FUNCTIONALITY",
       
  1155     SetupL, UT_CCFContextManager_RemoveSubscriptionsL, Teardown)
       
  1156 
       
  1157 EUNIT_TEST(
       
  1158     "DeregisterPublisher - test ",
       
  1159     "CCFContextManager",
       
  1160     "DeregisterPublisher",
       
  1161     "FUNCTIONALITY",
       
  1162     SetupL, UT_CCFContextManager_DeregisterPublisherL, Teardown)
       
  1163     
       
  1164 
       
  1165 EUNIT_END_TEST_TABLE
       
  1166 
       
  1167 //  END OF FILE