mds_plat/harvester_framework_api/tsrc/HarvesterPluginTest/src/HarvesterPluginTestBlocks.cpp
changeset 0 c53acadfccc6
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2002 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 <StifParser.h>
       
    22 #include <StifTestEventInterface.h>
       
    23 #include <StifTestInterface.h>
       
    24 #include "HarvesterPluginTest.h"
       
    25 
       
    26 #include "mdsutils.h"
       
    27 #include "harvesterblacklist.h"
       
    28 #include "mdeobject.h"
       
    29 #include "mdeobjecthandler.h"
       
    30 
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CHarvesterPluginTest::Delete
       
    36 // Delete here all resources allocated and opened from test methods. 
       
    37 // Called from destructor. 
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 void CHarvesterPluginTest::Delete() 
       
    41     {
       
    42 
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CHarvesterPluginTest::RunMethodL
       
    47 // Run specified method. Contains also table of test mothods and their names.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 TInt CHarvesterPluginTest::RunMethodL( 
       
    51     CStifItemParser& aItem ) 
       
    52     {
       
    53 
       
    54     static TStifFunctionInfo const KFunctions[] =
       
    55         {  
       
    56         // Copy this line for every implemented function.
       
    57         // First string is the function name used in TestScripter script file.
       
    58         // Second is the actual implementation member function. 
       
    59 
       
    60         ENTRY( "BeginTestSession", CHarvesterPluginTest::BeginTestSessionL ),
       
    61         ENTRY( "EndTestSession", CHarvesterPluginTest::EndTestSession ),
       
    62         ENTRY( "LoadPlugins", CHarvesterPluginTest::LoadPluginsL ),
       
    63         ENTRY( "TestFunctions", CHarvesterPluginTest::TestFunctionsL ),
       
    64         		
       
    65         };
       
    66 
       
    67     const TInt count = sizeof( KFunctions ) / 
       
    68                         sizeof( TStifFunctionInfo );
       
    69 
       
    70     return RunInternalL( KFunctions, count, aItem );
       
    71 
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CHarvesterPluginTest::HandleSessionOpened
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CHarvesterPluginTest::HandleSessionOpened( CMdESession& /*aClient*/, TInt aError )
       
    79     {
       
    80     _LIT( KMsg, "CallBck HandleSessionOpened - Error code : %d" );
       
    81     TBuf <100> msg;
       
    82     msg.Format(KMsg, aError);
       
    83     iLog->Log( msg );     
       
    84     RDebug::Print(msg);
       
    85     
       
    86     TRAP_IGNORE( iMdeObjectHandler = CMdeObjectHandler::NewL( *iMdeSession ) );
       
    87     
       
    88     // session event
       
    89     TEventIf event( TEventIf::ESetEvent, _L("Session") );
       
    90     TestModuleIf().Event( event );
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CHarvesterPluginTest::HandleSessionError
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CHarvesterPluginTest::HandleSessionError( CMdESession& /*aClient*/, TInt aError )
       
    98     {
       
    99     _LIT( KMsg, "CallBck HandleSessionError - Error code : %d" );
       
   100     TBuf <100> msg;
       
   101     msg.Format(KMsg, aError);
       
   102     iLog->Log( msg );
       
   103     RDebug::Print(msg);
       
   104     
       
   105     // session event
       
   106     TEventIf event( TEventIf::ESetEvent, _L("Session") );
       
   107     TestModuleIf().Event( event );
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CHarvesterPluginTest::HarvestingCompleted
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CHarvesterPluginTest::HarvestingCompleted( CHarvesterData* /* aHarvesterData */ )
       
   115 	{ 
       
   116     // harvest event
       
   117     TEventIf event( TEventIf::ESetEvent, _L("Harvest") );
       
   118     TestModuleIf().Event( event );
       
   119 	}
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CHarvesterPluginTest::BeginTestSessionL
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 TInt CHarvesterPluginTest::BeginTestSessionL( CStifItemParser& /* aItem */ )
       
   126     {
       
   127     TRAPD( error, iMdeSession = CMdESession::NewL( *this ) );
       
   128 
       
   129     iSession = CMdEHarvesterSession::NewL( *iMdeSession );
       
   130     
       
   131     iCtxEngine = NULL;
       
   132     	
       
   133     iBlacklist = CHarvesterBlacklist::NewL();
       
   134     
       
   135     _LIT( KMsg, "Exit BeginTestSession - Error code : %d" );
       
   136     TBuf <100> msg;
       
   137     msg.Format(KMsg, error);
       
   138     iLog->Log( msg );
       
   139     RDebug::Print( msg );
       
   140     
       
   141     User::LeaveIfError( error );
       
   142     
       
   143     return KErrNone;
       
   144     }    
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CHarvesterPluginTest::EndTestSession
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 TInt CHarvesterPluginTest::EndTestSession( CStifItemParser& /* aItem */ )
       
   151 	{       
       
   152 	iPluginInfoArray.ResetAndDestroy();
       
   153 	iPluginInfoArray.Close();
       
   154 	
       
   155 	REComSession::FinalClose();
       
   156     
       
   157     if ( iCtxEngine )
       
   158     	{
       
   159     	iCtxEngine->ReleaseInstance();
       
   160     	iCtxEngine = NULL;
       
   161     	}
       
   162 
       
   163     if ( iBlacklist )
       
   164         {
       
   165         iBlacklist->CloseDatabase();
       
   166         delete iBlacklist;
       
   167         }
       
   168     
       
   169     if ( iSession )
       
   170     	{
       
   171     	delete iSession;
       
   172     	iSession = NULL;
       
   173     	}
       
   174     
       
   175     if ( iMdeObjectHandler )
       
   176     	{
       
   177     	delete iMdeObjectHandler;
       
   178     	iMdeObjectHandler = NULL;
       
   179     	}
       
   180 
       
   181     if( iMdeSession )
       
   182     	{
       
   183     	delete iMdeSession;
       
   184     	iMdeSession = NULL;
       
   185     	}
       
   186     
       
   187     _LIT( KMsg, "Exit    EndTestSession" );
       
   188     iLog->Log( KMsg );  
       
   189     RDebug::Print(KMsg);
       
   190 	
       
   191     return KErrNone;
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CHarvesterPluginTest::LoadPluginsL
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 TInt CHarvesterPluginTest::LoadPluginsL( CStifItemParser& /* aItem */ )
       
   199     {
       
   200     _LIT( KMsg1, "Enter LoadPlugins" );
       
   201     iLog->Log( KMsg1 );
       
   202     RDebug::Print( KMsg1 );
       
   203     
       
   204     RImplInfoPtrArray infoArray;
       
   205     	
       
   206 	TCleanupItem cleanupItem( MdsUtils::CleanupEComArray, &infoArray );
       
   207 	CleanupStack::PushL( cleanupItem );
       
   208 	
       
   209 	CHarvesterPlugin::ListImplementationsL( infoArray );
       
   210 	TInt count( 0 );
       
   211 	count = infoArray.Count();
       
   212 	
       
   213 	if( count == 0 )
       
   214 	    {
       
   215 	    return KErrNotFound;
       
   216 	    }
       
   217 	
       
   218 	for ( TInt i=0; i < count; i++ )
       
   219 		{
       
   220 		// Parse the file extensions and resolve plug-in's uids from infoArray to iDataTypeArray
       
   221         TBufC8<256> type;
       
   222         TBufC8<256> opaque;
       
   223         
       
   224         type = infoArray[i]->DataType();
       
   225         opaque = infoArray[i]->OpaqueData();
       
   226         TUid implUID = infoArray[i]->ImplementationUid(); 
       
   227                 
       
   228         AddNewPluginL(type, opaque, implUID);
       
   229 		}
       
   230 	
       
   231 	CleanupStack::PopAndDestroy( &infoArray ); // infoArray, results in a call to CleanupEComArray
       
   232     
       
   233     _LIT( KMsg2, "Exit    LoadPlugins" );
       
   234     iLog->Log( KMsg2 );
       
   235     RDebug::Print( KMsg2 );
       
   236     
       
   237     return KErrNone;
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CHarvesterPluginTest::TestFunctionsL
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 TInt CHarvesterPluginTest::TestFunctionsL( CStifItemParser& aItem )
       
   245     {
       
   246     _LIT( KMsg1, "Enter TestFunctions" );
       
   247     iLog->Log( KMsg1 );
       
   248     RDebug::Print( KMsg1 );
       
   249     
       
   250 	TPtrC inputFile;
       
   251 	User::LeaveIfError( aItem.GetNextString( inputFile ) );
       
   252 	
       
   253 	iMdeSession->RemoveObjectL( inputFile );
       
   254 	
       
   255 	TBuf<100> aObjectDef;
       
   256 	
       
   257 	GetObjectDef( inputFile, aObjectDef, EFalse );
       
   258     
       
   259 	// harvesterdata object
       
   260 	HBufC* uriBuf = inputFile.AllocLC();
       
   261 	CHarvesterData* data = CHarvesterData::NewL( uriBuf );
       
   262 	data->SetPluginObserver( *this );
       
   263 	CMdEObject* mdeObject = NULL;
       
   264 	_LIT( string, "Image" );
       
   265 	mdeObject = iMdeObjectHandler->GetMetadataObjectL( *data, string );
       
   266 	data->SetMdeObject( mdeObject );
       
   267 	CleanupStack::Pop( uriBuf );
       
   268 	
       
   269 	HarvestL( data );
       
   270 	
       
   271     _LIT( KMsg2, "Exit TestFunctions" );
       
   272     iLog->Log( KMsg2 );
       
   273     RDebug::Print( KMsg2 );
       
   274     
       
   275     return KErrNone;
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // GetObjectDef
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 TBool CHarvesterPluginTest::GetObjectDef(const TDesC& aUri, TDes& aObjectDef, TBool aCheck)
       
   283 	{
       
   284 	CHarvesterPluginInfo* hpi = NULL; 
       
   285 
       
   286 	TRAPD( err, hpi = GetHPIFromFileNameL(aUri) );
       
   287 	if ( err != KErrNone )
       
   288 		{
       
   289 		aObjectDef.Zero();
       
   290 		return EFalse;
       
   291 		}
       
   292 
       
   293 	if ( !hpi )
       
   294 		{
       
   295 		aObjectDef.Zero();
       
   296 		}
       
   297 	else
       
   298 		{
       
   299 		if( hpi->iObjectTypes.Count() > 1)
       
   300 			{
       
   301 			if( aCheck )
       
   302 				{
       
   303 				aObjectDef.Zero();
       
   304 				return ETrue;
       
   305 				}
       
   306 			
       
   307 			if ( ! hpi->iPlugin )
       
   308 	    		{
       
   309 	    		TRAPD( error, hpi->iPlugin = CHarvesterPlugin::NewL( hpi->iPluginUid ) );
       
   310 	             if( error )
       
   311 	                    {
       
   312 	                    aObjectDef.Zero();
       
   313 	                    return EFalse;
       
   314 	                    }
       
   315 	             else
       
   316 	                 {
       
   317 	                 hpi->iPlugin->SetQueue( hpi->iQueue );
       
   318 	                 }
       
   319 	    		}
       
   320 			hpi->iPlugin->GetObjectType( aUri, aObjectDef );
       
   321 			}
       
   322 		else
       
   323 			{
       
   324 			aObjectDef.Copy( *(hpi->iObjectTypes[0]) );
       
   325 			}
       
   326 		}
       
   327 	
       
   328 	return EFalse;
       
   329 	}
       
   330 
       
   331 // ---------------------------------------------------------------------------
       
   332 // HarvestL
       
   333 // ---------------------------------------------------------------------------
       
   334 //
       
   335 TInt CHarvesterPluginTest::HarvestL( CHarvesterData* aHD )
       
   336 	{
       
   337     _LIT( KMsg1, "Enter HarvestL" );
       
   338     iLog->Log( KMsg1 );
       
   339     RDebug::Print( KMsg1 );
       
   340 	
       
   341 	CHarvesterPluginInfo* hpi = aHD->HarvesterPluginInfo();
       
   342 	
       
   343 	if ( !hpi ) 
       
   344 		{
       
   345 		 hpi = GetHPIFromFileNameL( aHD->Uri() );
       
   346 		}
       
   347 	
       
   348 	if ( hpi )
       
   349 		{
       
   350 		if ( ! hpi->iPlugin )
       
   351     		{
       
   352     		hpi->iPlugin = CHarvesterPlugin::NewL( hpi->iPluginUid );
       
   353     		hpi->iPlugin->SetQueue( hpi->iQueue );
       
   354     		hpi->iPlugin->SetBlacklist( *iBlacklist );
       
   355     		}
       
   356 		
       
   357 	    if( aHD->ObjectType() == EFastHarvest || aHD->Origin() == MdeConstants::Object::ECamera )
       
   358 	    	{
       
   359 	    	hpi->iQueue.Insert( aHD, 0 );
       
   360 	    	}
       
   361 	    else
       
   362 			{
       
   363 			hpi->iQueue.AppendL( aHD );
       
   364 			}
       
   365 	    
       
   366 		hpi->iPlugin->StartHarvest();
       
   367 	
       
   368 	    _LIT( KMsg2, "Exit HarvestL" );
       
   369 	    iLog->Log( KMsg2 );
       
   370 	    RDebug::Print( KMsg2 );
       
   371 		
       
   372 		return KErrNone;
       
   373 		}
       
   374 	
       
   375 	return KErrNotFound;
       
   376 	}
       
   377 
       
   378 // -----------------------------------------------------------------------------
       
   379 // AddNewPluginL
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 void CHarvesterPluginTest::AddNewPluginL( const TDesC8& aType, const TDesC8& aOpaque, TUid aPluginUid )
       
   383     {      
       
   384     CHarvesterPluginInfo* pluginInfo = new (ELeave) CHarvesterPluginInfo;
       
   385     CleanupStack::PushL( pluginInfo );
       
   386 
       
   387     // get file extensions
       
   388     TLex8 lex( aOpaque );
       
   389     while ( !lex.Eos() )
       
   390         {
       
   391         /* Tokenizing file extensions using TLex8 */
       
   392         lex.SkipSpaceAndMark();
       
   393 
       
   394         TPtrC8 extToken = lex.NextToken();
       
   395 
       
   396         HBufC* str = HBufC::NewLC( extToken.Length() );
       
   397         str->Des().Copy( extToken );
       
   398         pluginInfo->iExtensions.AppendL( str );
       
   399         CleanupStack::Pop( str );
       
   400         }
       
   401 
       
   402     // get object types
       
   403     TLex8 lexObjectTypes( aType );
       
   404     while ( !lexObjectTypes.Eos() )
       
   405         {
       
   406         /* Tokenizing object types using TLex8 */
       
   407         lexObjectTypes.SkipSpaceAndMark();
       
   408         
       
   409         TPtrC8 objectTypeToken = lexObjectTypes.NextToken();
       
   410 
       
   411         HBufC* str = HBufC::NewLC( objectTypeToken.Length() );
       
   412         str->Des().Copy( objectTypeToken );
       
   413         pluginInfo->iObjectTypes.AppendL( str );
       
   414         CleanupStack::Pop( str );
       
   415         }
       
   416 
       
   417     /* We set plugin as NULL - we only load them when needed */
       
   418     pluginInfo->iPlugin = NULL;
       
   419     pluginInfo->iPluginUid = aPluginUid;
       
   420     iPluginInfoArray.AppendL( pluginInfo );
       
   421     CleanupStack::Pop( pluginInfo );
       
   422     }
       
   423 
       
   424 // ---------------------------------------------------------------------------
       
   425 // GetHPIFromFileNameL
       
   426 // ---------------------------------------------------------------------------
       
   427 //
       
   428 CHarvesterPluginInfo* CHarvesterPluginTest::GetHPIFromFileNameL(const TDesC& aFileName)
       
   429 	{
       
   430     _LIT( KMsg1, "Enter GetHPIFromFileNameL" );
       
   431     iLog->Log( KMsg1 );
       
   432     RDebug::Print( KMsg1 );
       
   433 	
       
   434 	TParsePtrC parser( aFileName );
       
   435     
       
   436     // without trailing dot "."
       
   437     TPtrC ptr = parser.Ext();
       
   438     if ( ptr.Length() > 1 )
       
   439     	{
       
   440     	ptr.Set( ptr.Mid( 1 ) );
       
   441     	}
       
   442 
       
   443     _LIT( KMsg2, "Exit GetHPIFromFileNameL" );
       
   444     iLog->Log( KMsg2 );
       
   445     RDebug::Print( KMsg2 );
       
   446     
       
   447 	return GetFromNormalFileL( ptr );
       
   448 	}
       
   449 
       
   450 // ---------------------------------------------------------------------------
       
   451 // GetFromNormalFile
       
   452 // ---------------------------------------------------------------------------
       
   453 //
       
   454 CHarvesterPluginInfo* CHarvesterPluginTest::GetFromNormalFileL( TDesC& aExt )
       
   455 	{
       
   456     _LIT( KMsg1, "Enter GetFromNormalFileL" );
       
   457     iLog->Log( KMsg1 );
       
   458     RDebug::Print( KMsg1 );
       
   459 	
       
   460 	CHarvesterPluginInfo* retVal = NULL;
       
   461 
       
   462 	for ( TInt i = iPluginInfoArray.Count(); --i >= 0; )
       
   463         {
       
   464         CHarvesterPluginInfo* info = iPluginInfoArray[i];
       
   465         TBool found = EFalse;
       
   466         
       
   467         for ( TInt k = info->iExtensions.Count(); --k >= 0; )
       
   468             {
       
   469             TDesC* ext = info->iExtensions[k];
       
   470             
       
   471             // checking against supported plugin file extensions
       
   472             TInt result = ext->CompareF( aExt );
       
   473             if ( result == 0 )
       
   474                 {
       
   475                 retVal = info;
       
   476                 found = ETrue;
       
   477                 break;
       
   478                 }
       
   479             }
       
   480         if ( found )
       
   481         	{
       
   482         	break;
       
   483         	}
       
   484         }
       
   485 
       
   486     _LIT( KMsg2, "Exit GetFromNormalFileL" );
       
   487     iLog->Log( KMsg2 );
       
   488     RDebug::Print( KMsg2 );
       
   489 	
       
   490 	return retVal;
       
   491 	}
       
   492 
       
   493 //  [End of File] - Do not remove