mds_plat/context_engine_plugin_api/tsrc/src/ContextEnginePluginTestBlocks.cpp
changeset 0 c53acadfccc6
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2008-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 
       
    19 // [INCLUDE FILES] - do not remove
       
    20 #include <e32svr.h>
       
    21 #include <ecom.h>
       
    22 #include <StifParser.h>
       
    23 #include <StifTestEventInterface.h>
       
    24 #include <StifTestInterface.h>
       
    25 #include "ContextEnginePluginTest.h"
       
    26 
       
    27 #include <harvesterdata.h>
       
    28 #include "mdsutils.h"
       
    29 #include "mdeconstants.h"
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CContextEnginePluginTest::Delete
       
    35 // Delete here all resources allocated and opened from test methods. 
       
    36 // Called from destructor. 
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 void CContextEnginePluginTest::Delete() 
       
    40     {
       
    41 
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CContextEnginePluginTest::RunMethodL
       
    46 // Run specified method. Contains also table of test mothods and their names.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 TInt CContextEnginePluginTest::RunMethodL( 
       
    50     CStifItemParser& aItem ) 
       
    51     {
       
    52 
       
    53     static TStifFunctionInfo const KFunctions[] =
       
    54         {  
       
    55         // Copy this line for every implemented function.
       
    56         // First string is the function name used in TestScripter script file.
       
    57         // Second is the actual implementation member function. 
       
    58 
       
    59         // engine		
       
    60         ENTRY( "BeginTestSession", CContextEnginePluginTest::BeginTestSessionL ),
       
    61         ENTRY( "EndTestSession", CContextEnginePluginTest::EndTestSession ),
       
    62         ENTRY( "CreateObjects", CContextEnginePluginTest::CreateObjectsL ),
       
    63         ENTRY( "DeleteObjects", CContextEnginePluginTest::DeleteObjectsL ),
       
    64         ENTRY( "CreateContextEngineWithObserver", CContextEnginePluginTest::CreateContextEngine1L ),
       
    65         ENTRY( "CreateContextEngineWithoutObserver", CContextEnginePluginTest::CreateContextEngine2L ),
       
    66         ENTRY( "ReleaseContextEngineInstance", CContextEnginePluginTest::ReleaseInstanceL ),
       
    67         ENTRY( "SetMdESessionTest", CContextEnginePluginTest::SetMdeSessionL ),
       
    68         ENTRY( "PluginCount", CContextEnginePluginTest::PluginCount ),
       
    69         ENTRY( "Destroy", CContextEnginePluginTest::Destroy ),
       
    70         ENTRY( "ContextEngineStaticData", CContextEnginePluginTest::ContextEngineStaticData ),
       
    71 
       
    72         ENTRY( "ContextSnapshots", CContextEnginePluginTest::ContextSnapshotsL ),
       
    73         ENTRY( "MultipleSnapshots", CContextEnginePluginTest::MultipleSnapshotsL ),
       
    74         
       
    75         // plugin
       
    76         ENTRY( "LoadPlugin", CContextEnginePluginTest::LoadPluginL ),
       
    77 
       
    78         };
       
    79 
       
    80     const TInt count = sizeof( KFunctions ) / 
       
    81                         sizeof( TStifFunctionInfo );
       
    82 
       
    83     return RunInternalL( KFunctions, count, aItem );
       
    84 
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CContextEnginePluginTest::HandleSessionOpened
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CContextEnginePluginTest::HandleSessionOpened( CMdESession& /*aClient*/, TInt aError )
       
    92     {
       
    93     _LIT( KMsg, "CallBck HandleSessionOpened - Error code : %d" );
       
    94     TBuf <100> msg;
       
    95     msg.Format(KMsg, aError);
       
    96     iLog->Log( msg );     
       
    97     RDebug::Print( msg );
       
    98     
       
    99     // session event
       
   100     TEventIf event( TEventIf::ESetEvent, _L("Session") );
       
   101     TestModuleIf().Event( event );
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CContextEnginePluginTest::HandleSessionError
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CContextEnginePluginTest::HandleSessionError( CMdESession& /*aClient*/, TInt aError )
       
   109     {
       
   110     _LIT( KMsg, "CallBck HandleSessionError - Error code : %d" );
       
   111     TBuf <100> msg;
       
   112     msg.Format(KMsg, aError);
       
   113     iLog->Log( msg );
       
   114     RDebug::Print( msg );
       
   115     
       
   116     // session event
       
   117     TEventIf event( TEventIf::ESetEvent, _L("Session") );
       
   118     TestModuleIf().Event( event );
       
   119     }   
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CContextEnginePluginTest::ContextInitializationStatus
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void CContextEnginePluginTest::ContextInitializationStatus( TInt aError )
       
   126     {
       
   127     _LIT( KMsg, "CallBck ContextInitializationStatus - Error code : %d" );
       
   128     TBuf <100> msg;
       
   129     msg.Format(KMsg, aError);
       
   130     iLog->Log( msg );
       
   131     RDebug::Print( msg );
       
   132     
       
   133     iInitCount++;
       
   134     
       
   135     // session event
       
   136     TEventIf event( TEventIf::ESetEvent, _L("Init") );
       
   137     TestModuleIf().Event( event );
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CContextEnginePluginTest::ContextSnapshotStatus
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CContextEnginePluginTest::ContextSnapshotStatus( CHarvesterData* aHD )
       
   145     {
       
   146     _LIT( KMsg1, "Enter ContextSnapshotStatus" );
       
   147     iLog->Log( KMsg1 );  
       
   148     RDebug::Print( KMsg1 );
       
   149     
       
   150     _LIT( KMsg, "CallBck ContextSnapshotStatus - Error code : %d" );
       
   151     TBuf <100> msg;
       
   152     msg.Format(KMsg, aHD->ErrorCode());
       
   153     iLog->Log( msg );
       
   154     RDebug::Print( msg );
       
   155     
       
   156     if( !aHD )
       
   157         {
       
   158         iErrorCode = KErrUnknown;
       
   159         }
       
   160     
       
   161     if( aHD && iErrorCode == KErrNone )
       
   162         {
       
   163         iErrorCode = aHD->ErrorCode();
       
   164         }
       
   165     
       
   166     iSnapshotCount++;
       
   167     
       
   168     // session event
       
   169     TEventIf event( TEventIf::ESetEvent, _L("Snapshot") );
       
   170     TestModuleIf().Event( event );
       
   171     
       
   172     _LIT( KMsg2, "Exit ContextSnapshotStatus" );
       
   173     iLog->Log( KMsg2 );  
       
   174     RDebug::Print( KMsg2 );
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CContextEnginePluginTest::PluginInitializationStatus
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CContextEnginePluginTest::PluginInitializationStatus( TInt aError )
       
   182     {
       
   183     _LIT( KMsg, "CallBck PluginInitializationStatus - Error code : %d" );
       
   184     TBuf <100> msg;
       
   185     msg.Format(KMsg, aError);
       
   186     iLog->Log( msg );
       
   187     RDebug::Print( msg );
       
   188     
       
   189     iInitCount++;
       
   190     
       
   191     // session event
       
   192     TEventIf event( TEventIf::ESetEvent, _L("Init") );
       
   193     TestModuleIf().Event( event );
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CContextEnginePluginTest::PluginSnapshotStatus
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 void CContextEnginePluginTest::PluginSnapshotStatus( CHarvesterData* aHD )
       
   201     {
       
   202     _LIT( KMsg1, "Enter PluginSnapshotStatus" );
       
   203     iLog->Log( KMsg1 );  
       
   204     RDebug::Print( KMsg1 );
       
   205     
       
   206     _LIT( KMsg, "CallBck PluginSnapshotStatus - Error code : %d" );
       
   207     TBuf <100> msg;
       
   208     msg.Format(KMsg, aHD->ErrorCode());
       
   209     iLog->Log( msg );
       
   210     RDebug::Print( msg );
       
   211     
       
   212     if( !aHD )
       
   213         {
       
   214         iErrorCode = KErrUnknown;
       
   215         }
       
   216     
       
   217     if( aHD && iErrorCode == KErrNone )
       
   218         {
       
   219         iErrorCode = aHD->ErrorCode();
       
   220         }
       
   221     
       
   222     iSnapshotCount++;
       
   223     
       
   224     // session event
       
   225     TEventIf event( TEventIf::ESetEvent, _L("Snapshot") );
       
   226     TestModuleIf().Event( event );
       
   227     
       
   228     _LIT( KMsg2, "Exit PluginSnapshotStatus" );
       
   229     iLog->Log( KMsg2 );  
       
   230     RDebug::Print( KMsg2 );
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CContextEnginePluginTest::ActiveWait
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CContextEnginePluginTest::ActiveWait( TInt aTimeout )
       
   238     {
       
   239     _LIT( KMsg1, "Enter ActiveWait" );
       
   240     iLog->Log( KMsg1 );
       
   241     RDebug::Print( KMsg1 );
       
   242 
       
   243     TTimeIntervalMicroSeconds32 timeout( aTimeout );
       
   244     RTimer timer;
       
   245     TRequestStatus status;
       
   246 
       
   247     timer.CreateLocal();
       
   248     timer.After(status,timeout);
       
   249 
       
   250     User::WaitForAnyRequest();
       
   251     
       
   252     timer.Close();
       
   253     
       
   254     _LIT( KMsg2, "Exit ActiveWait" );
       
   255     iLog->Log( KMsg2 );
       
   256     RDebug::Print( KMsg2 );
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CContextEnginePluginTest::BeginTestSessionL
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 TInt CContextEnginePluginTest::BeginTestSessionL( CStifItemParser& /* aItem */ )
       
   264     {
       
   265     iMdEClient = NULL;
       
   266     TRAPD( error, iMdEClient = CMdESession::NewL( *this ) );
       
   267     iErrorCode = KErrNone;
       
   268 
       
   269     _LIT( KMsg, "Exit BeginTestSession - Error code : %d" );
       
   270     TBuf <100> msg;
       
   271     msg.Format(KMsg, error);
       
   272     iLog->Log( msg );
       
   273     RDebug::Print( msg );
       
   274     
       
   275     iInitCount = 0;
       
   276     iSnapshotCount = 0;
       
   277     iInitTarget = 0;
       
   278     iSnapshotTarget = 0;
       
   279     
       
   280     iPluginSet = EFalse;
       
   281     
       
   282     User::LeaveIfError( error );
       
   283     
       
   284     return KErrNone;
       
   285     }    
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // CContextEnginePluginTest::EndTestSession
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 TInt CContextEnginePluginTest::EndTestSession( CStifItemParser& /* aItem */ )
       
   292 	{
       
   293     _LIT( KMsg1, "Enter EndTestSession" );
       
   294     iLog->Log( KMsg1 );  
       
   295     RDebug::Print( KMsg1 );
       
   296 	
       
   297 	iIds.Close();
       
   298 	iObjectArray.Close();
       
   299 	    
       
   300     if ( iContextEngine )
       
   301         {
       
   302         iContextEngine->ReleaseInstance();
       
   303         iContextEngine = NULL;
       
   304         }
       
   305     
       
   306     if ( iPlugin )
       
   307         {
       
   308         delete iPlugin;
       
   309         iPlugin = NULL;
       
   310         }
       
   311     
       
   312     if ( iLocationPlugin && !iPluginSet )
       
   313         {
       
   314         delete iLocationPlugin;
       
   315         iLocationPlugin = NULL;
       
   316         }
       
   317     
       
   318     if ( iCalendarPlugin )
       
   319         {
       
   320         delete iCalendarPlugin;
       
   321         iCalendarPlugin = NULL;
       
   322         }
       
   323 	
       
   324 	if ( iMdEClient )
       
   325 		{
       
   326 	    delete iMdEClient;
       
   327 	    iMdEClient = NULL;
       
   328 	    }
       
   329 	
       
   330 	iHD = NULL;
       
   331     
       
   332     REComSession::FinalClose();
       
   333 	
       
   334     if( iInitCount != iInitTarget )
       
   335         {
       
   336         return KErrUnknown;
       
   337         }
       
   338     
       
   339     if( iSnapshotCount != iSnapshotTarget )
       
   340         {
       
   341         return KErrUnknown;
       
   342         }
       
   343     
       
   344     _LIT( KMsg2, "Exit EndTestSession" );
       
   345     iLog->Log( KMsg2 );  
       
   346     RDebug::Print( KMsg2 );
       
   347 	
       
   348     return iErrorCode;
       
   349     }
       
   350 
       
   351 // -----------------------------------------------------------------------------
       
   352 // CContextEnginePluginTest::CreateObjects
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 TInt CContextEnginePluginTest::CreateObjectsL( CStifItemParser& aItem )
       
   356     {
       
   357 	CMdENamespaceDef& defaultNamespace = iMdEClient->GetDefaultNamespaceDefL();
       
   358 	CMdEObjectDef& imageDef = defaultNamespace.GetObjectDefL( MdeConstants::Image::KImageObject );
       
   359 	
       
   360 	// Mandatory parameters for any object.
       
   361 	CMdEPropertyDef& creationDef = imageDef.GetPropertyDefL( MdeConstants::Object::KCreationDateProperty );
       
   362 	CMdEPropertyDef& modifiedDef = imageDef.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty );
       
   363 	CMdEPropertyDef& sizeDef = imageDef.GetPropertyDefL( MdeConstants::Object::KSizeProperty );
       
   364 	CMdEPropertyDef& itemTypeDef = imageDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty );
       
   365 	
       
   366 	CMdEPropertyDef& descriptionPropertyDef = imageDef.GetPropertyDefL( MdeConstants::MediaObject::KDescriptionProperty );
       
   367 	CMdEPropertyDef& widthDef = imageDef.GetPropertyDefL( MdeConstants::MediaObject::KWidthProperty ); 
       
   368 	CMdEPropertyDef& heightDef = imageDef.GetPropertyDefL( MdeConstants::MediaObject::KHeightProperty ); 
       
   369 	CMdEPropertyDef& makeDef = imageDef.GetPropertyDefL( MdeConstants::Image::KMakeProperty );
       
   370 	CMdEPropertyDef& modelDef = imageDef.GetPropertyDefL( MdeConstants::Image::KModelProperty );
       
   371     
       
   372 	CMdEObject* object = NULL;
       
   373 	TItemId objectId(0);
       
   374 	TTime currTime;
       
   375 	TPtrC inputFile;
       
   376 	TInt count(0);
       
   377 	TBuf <100> msg;
       
   378 	
       
   379 	iIds.Reset();
       
   380 	
       
   381 	User::LeaveIfError( aItem.GetNextInt( count ));
       
   382 	
       
   383 	for ( TInt i = 0; i < count; ++i )
       
   384 		{			
       
   385 		User::LeaveIfError( aItem.GetNextString( inputFile ));
       
   386 		
       
   387 		// create object
       
   388 		iMdEClient->RemoveObjectL(inputFile);
       
   389 		object = iMdEClient->NewObjectLC(imageDef, inputFile);
       
   390 		
       
   391 		currTime.HomeTime();
       
   392 		object->AddTimePropertyL(creationDef, currTime);
       
   393 		object->AddTimePropertyL(modifiedDef, currTime);
       
   394 		object->AddUint32PropertyL( sizeDef, 0 );
       
   395 		object->AddTextPropertyL( itemTypeDef, MdeConstants::Image::KImageObject );
       
   396 		
       
   397 		objectId = iMdEClient->AddObjectL(*object);
       
   398 		iIds.Append(objectId);
       
   399 		
       
   400 		CleanupStack::PopAndDestroy(object);
       
   401 		object = NULL;
       
   402 		
       
   403 		// open object for modification
       
   404 		TRAPD( openError, object = iMdEClient->OpenObjectL(objectId) );
       
   405 			
       
   406 		if ( !object || openError != KErrNone )
       
   407 			{
       
   408 			_LIT( KOpenErr, "        ModifyObjects - Open error : %d" );
       
   409 		    msg.Format(KOpenErr, openError);
       
   410 		    iLog->Log( msg );
       
   411 		    RDebug::Print(msg);
       
   412 		    
       
   413 		    User::LeaveIfError(openError);
       
   414 			}
       
   415 
       
   416 		CleanupStack::PushL( object );		
       
   417 		
       
   418 		// add properties
       
   419    		CMdEProperty* property = NULL;
       
   420    		
       
   421    		// Description
       
   422    		_LIT( KDesc, "Description" );
       
   423 		object->Property( descriptionPropertyDef, property );
       
   424 		
       
   425 		if ( property )
       
   426 			{					
       
   427 			property->SetTextValueL( KDesc );
       
   428 			}
       
   429 		else
       
   430 			{
       
   431 			object->AddTextPropertyL( descriptionPropertyDef, KDesc );
       
   432 			}
       
   433 		
       
   434 		property = NULL;
       
   435 		
       
   436 		// Width
       
   437 		object->Property( widthDef, property );
       
   438 		
       
   439 		if ( property )
       
   440 			{
       
   441 			property->SetUint16ValueL( 100 );
       
   442 			}
       
   443 		else
       
   444 			{
       
   445 			object->AddUint16PropertyL( widthDef, 100 );
       
   446 			}
       
   447 		
       
   448 		property = NULL;
       
   449 			
       
   450 		// Height
       
   451 		object->Property( heightDef, property );
       
   452 		
       
   453 		if ( property )
       
   454 			{
       
   455 			property->SetUint16ValueL( 100 );
       
   456 			}
       
   457 		else
       
   458 			{
       
   459 			object->AddUint16PropertyL( heightDef, 100 );
       
   460 			}
       
   461 		
       
   462 		property = NULL;
       
   463 		
       
   464 		// Maker
       
   465 		object->Property( makeDef, property );
       
   466 		
       
   467         _LIT( KOnkia, "Maker" );
       
   468 		if ( property )
       
   469 			{
       
   470 			property->SetTextValueL( KOnkia );
       
   471 			}
       
   472 		else
       
   473 			{
       
   474 			object->AddTextPropertyL( makeDef, KOnkia );
       
   475 			}
       
   476 			
       
   477 		property = NULL;
       
   478 			
       
   479 		// Model
       
   480 		object->Property( modelDef, property );
       
   481         _LIT( KModel, "Model" );
       
   482 		if ( property )
       
   483 			{					
       
   484 			property->SetTextValueL( KModel );
       
   485 			}
       
   486 		else
       
   487 			{
       
   488 			object->AddTextPropertyL( modelDef, KModel );
       
   489 			}
       
   490 		
       
   491 		// Commit object
       
   492 		TRAPD( commitError, iMdEClient->CommitObjectL(*object) );
       
   493 		if ( commitError != KErrNone )
       
   494 			{		
       
   495 			_LIT( KCommErr, "        CreateObjects - Commit error : %d" );
       
   496 		    msg.Format(KCommErr, commitError);
       
   497 		    iLog->Log( msg );
       
   498 		    RDebug::Print(msg);
       
   499 		    
       
   500 		    User::LeaveIfError(commitError);
       
   501 			}
       
   502 		
       
   503 		CleanupStack::PopAndDestroy(object);
       
   504 		object = NULL;
       
   505 		}
       
   506 	
       
   507     _LIT( KMsg, "Exit    EndCreateObjects" );
       
   508     iLog->Log( KMsg );  
       
   509     RDebug::Print( KMsg );
       
   510 	
       
   511     return KErrNone;
       
   512     }
       
   513 
       
   514 // -----------------------------------------------------------------------------
       
   515 // CContextEnginePluginTest::DeleteObjects
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 TInt CContextEnginePluginTest::DeleteObjectsL( CStifItemParser& /* aItem */ )
       
   519     {
       
   520     ActiveWait( 2000000 );
       
   521     
       
   522     _LIT( KMsg1, "Enter EndDeleteObjects" );
       
   523     iLog->Log( KMsg1 );  
       
   524     RDebug::Print( KMsg1 );
       
   525     
       
   526 	TInt count(0);
       
   527     count = iIds.Count();
       
   528 	
       
   529 	for ( TInt i = 0; i < count; ++i )
       
   530 		{
       
   531 		TInt id = iIds[i];
       
   532 	    iMdEClient->RemoveObjectL( id );
       
   533 		}
       
   534 	
       
   535 	iIds.Reset();
       
   536     
       
   537     _LIT( KMsg2, "Exit EndDeleteObjects" );
       
   538     iLog->Log( KMsg2 );  
       
   539     RDebug::Print( KMsg2 );
       
   540 	
       
   541     return KErrNone;
       
   542     }
       
   543 
       
   544 // -----------------------------------------------------------------------------
       
   545 // CContextEnginePluginTest::CreateContextEngine1L
       
   546 // -----------------------------------------------------------------------------
       
   547 //
       
   548 TInt CContextEnginePluginTest::CreateContextEngine1L( CStifItemParser& /* aItem */ )
       
   549     {
       
   550     _LIT( KMsg1, "Enter CreateContextEngine" );
       
   551     iLog->Log( KMsg1 );  
       
   552     RDebug::Print( KMsg1 );
       
   553     
       
   554     iInitTarget = 1;
       
   555     
       
   556     iContextEngine = NULL;
       
   557     iContextEngine = CContextEngine::GetInstanceL( this );
       
   558     
       
   559     if( !iContextEngine )
       
   560         {
       
   561         User::Leave( KErrUnknown );
       
   562         }
       
   563     
       
   564     _LIT( KMsg2, "Exit CreateContextEngine" );
       
   565     iLog->Log( KMsg2 );  
       
   566     RDebug::Print( KMsg2 );
       
   567     
       
   568     return KErrNone;
       
   569     }
       
   570 
       
   571 // -----------------------------------------------------------------------------
       
   572 // CContextEnginePluginTest::CreateContextEngine2L
       
   573 // -----------------------------------------------------------------------------
       
   574 //
       
   575 TInt CContextEnginePluginTest::CreateContextEngine2L( CStifItemParser& /* aItem */ )
       
   576     {
       
   577     _LIT( KMsg1, "Enter CreateContextEngine" );
       
   578     iLog->Log( KMsg1 );  
       
   579     RDebug::Print( KMsg1 );
       
   580     
       
   581     iContextEngine = NULL;
       
   582     iContextEngine = CContextEngine::GetInstanceL();
       
   583     
       
   584     // 4 seconds
       
   585     TTimeIntervalMicroSeconds32 timeout(4000000);
       
   586     RTimer timer;
       
   587     TRequestStatus status;
       
   588 
       
   589     timer.CreateLocal();
       
   590     timer.After( status,timeout );
       
   591 
       
   592     User::WaitForAnyRequest();
       
   593     
       
   594     timer.Close();
       
   595     
       
   596     if( !iContextEngine )
       
   597         {
       
   598         User::Leave( KErrUnknown );
       
   599         }
       
   600     
       
   601     _LIT( KMsg2, "Exit CreateContextEngine" );
       
   602     iLog->Log( KMsg2 );  
       
   603     RDebug::Print( KMsg2 );
       
   604 	
       
   605     return KErrNone;
       
   606     }
       
   607 
       
   608 // -----------------------------------------------------------------------------
       
   609 // CContextEnginePluginTest::CreateContextEngine2L
       
   610 // -----------------------------------------------------------------------------
       
   611 //
       
   612 TInt CContextEnginePluginTest::ReleaseInstanceL( CStifItemParser& /* aItem */ )
       
   613     {
       
   614     _LIT( KMsg1, "Enter ReleaseInstanceL" );
       
   615     iLog->Log( KMsg1 );  
       
   616     RDebug::Print( KMsg1 );
       
   617     
       
   618     if( !iContextEngine )
       
   619         {
       
   620         User::Leave( KErrUnknown );
       
   621         }
       
   622     
       
   623     iContextEngine->ReleaseInstance();
       
   624     
       
   625     iContextEngine = NULL;
       
   626     
       
   627     _LIT( KMsg2, "Exit ReleaseInstanceL" );
       
   628     iLog->Log( KMsg2 );  
       
   629     RDebug::Print( KMsg2 );
       
   630     
       
   631     return KErrNone;
       
   632     }
       
   633 
       
   634 // -----------------------------------------------------------------------------
       
   635 // CContextEnginePluginTest::CreateContextEngine2L
       
   636 // -----------------------------------------------------------------------------
       
   637 //
       
   638 TInt CContextEnginePluginTest::SetMdeSessionL( CStifItemParser& /* aItem */ )
       
   639     {
       
   640     _LIT( KMsg1, "Enter SetMdeSessionL" );
       
   641     iLog->Log( KMsg1 );  
       
   642     RDebug::Print( KMsg1 );
       
   643     
       
   644     iInitTarget = 1;
       
   645     
       
   646     iContextEngine = NULL;
       
   647     iContextEngine = CContextEngine::GetInstanceL( this );
       
   648     
       
   649     if( !iContextEngine )
       
   650         {
       
   651         User::Leave( KErrUnknown );
       
   652         }
       
   653     
       
   654     iContextEngine->SetMdeSession( iMdEClient );
       
   655     
       
   656     if( !iContextEngine || !iMdEClient )
       
   657         {
       
   658         User::Leave( KErrUnknown );
       
   659         }
       
   660     
       
   661     iContextEngine->SetMdeSession( NULL );
       
   662     
       
   663     if( !iContextEngine )
       
   664         {
       
   665         User::Leave( KErrUnknown );
       
   666         }
       
   667     
       
   668     _LIT( KMsg2, "Exit SetMdeSessionL" );
       
   669     iLog->Log( KMsg2 );  
       
   670     RDebug::Print( KMsg2 );
       
   671     
       
   672     return KErrNone;
       
   673     }
       
   674 
       
   675 // -----------------------------------------------------------------------------
       
   676 // CContextEnginePluginTest::ContextSnapshots
       
   677 // -----------------------------------------------------------------------------
       
   678 //
       
   679 TInt CContextEnginePluginTest::ContextSnapshotsL( CStifItemParser& aItem )
       
   680     {
       
   681     _LIT( KMsg1, "Enter ContextSnapshots" );
       
   682     iLog->Log( KMsg1 );  
       
   683     RDebug::Print( KMsg1 );
       
   684     
       
   685     iSnapshotTarget = 9;
       
   686     
       
   687     const TInt KLoopCount = 3;
       
   688     TInt count = iIds.Count();
       
   689     
       
   690     CMdEObject* mdeObject;
       
   691     iObjectArray.Reset();
       
   692     
       
   693     // choose if plugin tested, otherwise engine
       
   694     TPtrC testPlugin;
       
   695     TBool plugin = EFalse;
       
   696     User::LeaveIfError( aItem.GetNextString( testPlugin ));
       
   697     _LIT( pluginString, "plugin" );
       
   698     if( testPlugin == pluginString )
       
   699     	{
       
   700     	plugin = ETrue;
       
   701     	}
       
   702     
       
   703     // get object
       
   704     mdeObject = iMdEClient->GetObjectL( iIds[0] );
       
   705 
       
   706     HBufC* uriBuf = mdeObject->Uri().AllocLC();
       
   707     iHD = CHarvesterData::NewL( uriBuf );
       
   708     iHD->SetMdeObject( mdeObject );
       
   709     CleanupStack::Pop( uriBuf );
       
   710     
       
   711     // snapshots
       
   712     for ( TInt i = 0; i < KLoopCount; i++ )
       
   713         {
       
   714         if (plugin)
       
   715         	{
       
   716         	iPlugin->ContextSnapshot( *this, *iHD );
       
   717         	}
       
   718         else
       
   719         	{
       
   720         	iContextEngine->ContextSnapshot( *this, *iHD );
       
   721         	}
       
   722         }
       
   723     mdeObject = NULL;
       
   724     
       
   725     mdeObject = iMdEClient->GetObjectL( iIds[1] );
       
   726     uriBuf = mdeObject->Uri().AllocLC();
       
   727     iHD = CHarvesterData::NewL( uriBuf );
       
   728     iHD->SetMdeObject( mdeObject );
       
   729     CleanupStack::Pop( uriBuf );
       
   730     
       
   731     // snapshots
       
   732     for ( TInt i = 0; i < KLoopCount; i++ )
       
   733         {
       
   734         if (plugin)
       
   735         	{
       
   736         	iPlugin->ContextSnapshot( *this, *iHD );
       
   737         	}
       
   738         else
       
   739         	{
       
   740         	iContextEngine->ContextSnapshot( *this, *iHD );
       
   741         	}
       
   742         }    
       
   743     mdeObject = NULL;
       
   744     
       
   745     mdeObject = iMdEClient->GetObjectL( iIds[2] );
       
   746     uriBuf = mdeObject->Uri().AllocLC();
       
   747     iHD = CHarvesterData::NewL( uriBuf );
       
   748     iHD->SetMdeObject( mdeObject );
       
   749     CleanupStack::Pop( uriBuf );
       
   750     
       
   751     // snapshots
       
   752     for ( TInt i = 0; i < KLoopCount; i++ )
       
   753         {
       
   754         if (plugin)
       
   755         	{
       
   756         	iPlugin->ContextSnapshot( *this, *iHD );
       
   757         	}
       
   758         else
       
   759         	{
       
   760         	iContextEngine->ContextSnapshot( *this, *iHD );
       
   761         	}
       
   762         }  
       
   763     
       
   764     _LIT( KMsg2, "Exit ContextSnapshots" );
       
   765     iLog->Log( KMsg2 );  
       
   766     RDebug::Print( KMsg2 );
       
   767 
       
   768     return KErrNone;
       
   769     }
       
   770 
       
   771 // -----------------------------------------------------------------------------
       
   772 // CContextEnginePluginTest::MultipleSnapshots
       
   773 // -----------------------------------------------------------------------------
       
   774 //
       
   775 TInt CContextEnginePluginTest::MultipleSnapshotsL( CStifItemParser& aItem )
       
   776     {
       
   777     _LIT( KMsg1, "Enter MultipleSnapshots" );
       
   778     iLog->Log( KMsg1 );  
       
   779     RDebug::Print( KMsg1 );
       
   780     
       
   781     iSnapshotTarget = 3;
       
   782     
       
   783     TInt count = iIds.Count();
       
   784     
       
   785     CMdEObject* mdeObject;
       
   786     iObjectArray.Reset();
       
   787     
       
   788     // choose if plugin tested, otherwise engine
       
   789     TPtrC testPlugin;
       
   790     TBool plugin = EFalse;
       
   791     User::LeaveIfError( aItem.GetNextString( testPlugin ));
       
   792     _LIT( pluginString, "plugin" );
       
   793     if( testPlugin == pluginString )
       
   794     	{
       
   795     	plugin = ETrue;
       
   796     	}
       
   797     
       
   798     // multiple objects
       
   799 	for ( TInt i = 0; i < count; ++i )
       
   800 		{
       
   801 	    iHD = NULL;
       
   802 	    mdeObject = NULL;
       
   803 		
       
   804 	    mdeObject = iMdEClient->GetObjectL( iIds[i] );
       
   805 	    HBufC* uriBuf = mdeObject->Uri().AllocLC();
       
   806 	    iHD = CHarvesterData::NewL( uriBuf );
       
   807 	    iHD->SetMdeObject( mdeObject );
       
   808 	    CleanupStack::Pop( uriBuf );
       
   809 	    
       
   810 	    iObjectArray.Append( iHD );
       
   811 		}
       
   812 	
       
   813 	// snapshots
       
   814     if( plugin )
       
   815 		{
       
   816 		iPlugin->ContextSnapshot( *this, iObjectArray );
       
   817 		}
       
   818 	else
       
   819 		{
       
   820 		iContextEngine->ContextSnapshot( *this, iObjectArray );
       
   821 		}
       
   822     
       
   823     _LIT( KMsg2, "Exit MultipleSnapshots" );
       
   824     iLog->Log( KMsg2 );  
       
   825     RDebug::Print( KMsg2 );
       
   826     
       
   827     return KErrNone;
       
   828     }
       
   829 
       
   830 // -----------------------------------------------------------------------------
       
   831 // CContextEnginePluginTest::PluginCount
       
   832 // -----------------------------------------------------------------------------
       
   833 //
       
   834 TInt CContextEnginePluginTest::PluginCount( CStifItemParser& /* aItem */ )
       
   835     {
       
   836     _LIT( KMsg1, "Enter PluginCount" );
       
   837     iLog->Log( KMsg1 );  
       
   838     RDebug::Print( KMsg1 );
       
   839     
       
   840     TInt count(0);
       
   841     count = iContextEngine->PluginCount();
       
   842     
       
   843     if( count != 2 )
       
   844         {
       
   845         return KErrNotFound;
       
   846         }
       
   847     
       
   848     _LIT( KMsg, "Exit PluginCount : %d" );
       
   849     TBuf <100> msg;
       
   850     msg.Format(KMsg, count);
       
   851     iLog->Log( msg );
       
   852     RDebug::Print(msg);
       
   853 	
       
   854     _LIT( KMsg2, "Enter PluginCount" );
       
   855     iLog->Log( KMsg2 );  
       
   856     RDebug::Print( KMsg2 );
       
   857     
       
   858     return KErrNone;
       
   859     }
       
   860 
       
   861 // -----------------------------------------------------------------------------
       
   862 // CContextEnginePluginTest::Destroy
       
   863 // -----------------------------------------------------------------------------
       
   864 //
       
   865 TInt CContextEnginePluginTest::Destroy( CStifItemParser& /* aItem */ )
       
   866     {
       
   867     _LIT( KMsg1, "Enter Destroy" );
       
   868     iLog->Log( KMsg1 );  
       
   869     RDebug::Print( KMsg1 );
       
   870     
       
   871     iContextEngine->Destroy();
       
   872 	
       
   873     _LIT( KMsg2, "Exit Destroy" );
       
   874     iLog->Log( KMsg2 );  
       
   875     RDebug::Print( KMsg2 );
       
   876     
       
   877     return KErrNone;
       
   878     }
       
   879 
       
   880 // -----------------------------------------------------------------------------
       
   881 // CContextEnginePluginTest::ContextEngineStaticData
       
   882 // -----------------------------------------------------------------------------
       
   883 //
       
   884 TInt CContextEnginePluginTest::ContextEngineStaticData( CStifItemParser& /* aItem */ )
       
   885     {
       
   886     _LIT( KMsg1, "Enter ContextEngineStaticData" );
       
   887     iLog->Log( KMsg1 );  
       
   888     RDebug::Print( KMsg1 );
       
   889     
       
   890     const TInt KContextEngineTLSKey = 0x200009f6;
       
   891     
       
   892     CContextEngineStaticData* data = static_cast<CContextEngineStaticData*>(
       
   893             UserSvr::DllTls(KContextEngineTLSKey) );
       
   894     
       
   895     if( !data )
       
   896         {
       
   897         return KErrUnknown;
       
   898         }
       
   899     
       
   900     _LIT( KMsg2, "Exit ContextEngineStaticData" );
       
   901     iLog->Log( KMsg2 );  
       
   902     RDebug::Print( KMsg2 );
       
   903 	
       
   904     return KErrNone;
       
   905     }
       
   906 
       
   907 // -----------------------------------------------------------------------------
       
   908 // CContextEnginePluginTest::LoadPluginL
       
   909 // -----------------------------------------------------------------------------
       
   910 //
       
   911 TInt CContextEnginePluginTest::LoadPluginL( CStifItemParser& /* aItem */ )
       
   912     {
       
   913     _LIT( KMsg1, "Enter LoadPlugins" );
       
   914     iLog->Log( KMsg1 );
       
   915     RDebug::Print( KMsg1 );
       
   916     
       
   917     iInitTarget = 2;
       
   918     
       
   919     TUid calendarContextUID = { 0x102823CB }; // calendar context plugin uid
       
   920     TUid locationContextUID = { 0x200071D0 }; // location context plugin uid
       
   921     
       
   922     RImplInfoPtrArray infoArray;
       
   923     	
       
   924 	TCleanupItem cleanupItem( MdsUtils::CleanupEComArray, &infoArray );
       
   925 	CleanupStack::PushL( cleanupItem );
       
   926 	
       
   927 	CContextPlugin::ListImplementationsL( infoArray );
       
   928 	TInt count( 0 );
       
   929 	count = infoArray.Count();
       
   930 	
       
   931 	TBool locationPluginFound( EFalse );
       
   932 	TBool calendarPluginFound( EFalse );
       
   933 	for ( TInt i=0; i < count; i++ )
       
   934 		{
       
   935 		TUid uid = infoArray[i]->ImplementationUid();
       
   936 		
       
   937 		// context plugin found
       
   938 		if( uid == locationContextUID )
       
   939 			{
       
   940 			iLocationPlugin = CContextPlugin::NewL( uid );
       
   941 			iLocationPlugin->SetMdeSession(*iMdEClient);
       
   942 			iLocationPlugin->Init(*this);
       
   943 			locationPluginFound = ETrue;
       
   944 			iPlugin = iLocationPlugin;
       
   945 			iPluginSet = ETrue;
       
   946 			}		
       
   947 		else if( uid == calendarContextUID )
       
   948 	        {
       
   949 	        iCalendarPlugin = CContextPlugin::NewL( uid );
       
   950 	        iCalendarPlugin->SetMdeSession(*iMdEClient);
       
   951 	        iCalendarPlugin->Init(*this);
       
   952 	        calendarPluginFound = ETrue;
       
   953 	        }   
       
   954 		}
       
   955 	
       
   956 	CleanupStack::PopAndDestroy( &infoArray ); // infoArray, results in a call to CleanupEComArray
       
   957     
       
   958 	if( !locationPluginFound )
       
   959 	    {
       
   960 	    _LIT( KLocation, "Location context plugin not found" );
       
   961 	    iLog->Log( KLocation );
       
   962 	    RDebug::Print( KLocation );
       
   963 	    return KErrNotFound;
       
   964 	    }
       
   965 	
       
   966     if( !calendarPluginFound )
       
   967         {
       
   968         _LIT( KCalendar, "Calendar context plugin not found" );
       
   969         iLog->Log( KCalendar );
       
   970         RDebug::Print( KCalendar );
       
   971         return KErrNotFound;
       
   972         }
       
   973     
       
   974     _LIT( KMsg2, "Exit LoadPlugins" );
       
   975     iLog->Log( KMsg2 );
       
   976     RDebug::Print( KMsg2 );
       
   977     
       
   978     return KErrNone;
       
   979     }
       
   980 
       
   981 //  [End of File] - Do not remove