imagehandling_plat/thumbnailmanager_api/tsrc/src/ThumbnailManagerTestBlocks.cpp
changeset 0 2014ca87e772
child 10 ee674526fac5
equal deleted inserted replaced
-1:000000000000 0:2014ca87e772
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Thumbnail Manager API tests
       
    15 *
       
    16 */
       
    17 
       
    18 // [INCLUDE FILES] - do not remove
       
    19 #include <e32svr.h>
       
    20 #include <StifParser.h>
       
    21 #include <Stiftestinterface.h>
       
    22 
       
    23 #include <fbs.h>
       
    24 #include <sqldb.h>
       
    25 #include <ImageConversion.h>
       
    26 #include <thumbnailmanager.h>
       
    27 
       
    28 #include "ThumbnailManagerTest.h"
       
    29 
       
    30 
       
    31 // ============================= LOCAL FUNCTIONS ===============================
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CThumbnailManagerTest::Delete
       
    37 // Delete here all resources allocated and opened from test methods. 
       
    38 // Called from destructor. 
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 void CThumbnailManagerTest::Delete() 
       
    42     {
       
    43     delete iPreviewThumbnail;
       
    44     iPreviewThumbnail = NULL;
       
    45     delete iThumbnail;
       
    46     iThumbnail = NULL;
       
    47     delete iEngine;
       
    48     iEngine = NULL;
       
    49     delete iObjectSource;
       
    50     iObjectSource = NULL;
       
    51     delete iCenrep;
       
    52     iCenrep = NULL;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CThumbnailManagerTest::RunMethodL
       
    57 // Run specified method. Contains also table of test mothods and their names.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 TInt CThumbnailManagerTest::RunMethodL( CStifItemParser& aItem ) 
       
    61     {
       
    62     static TStifFunctionInfo const KFunctions[] =
       
    63         {  
       
    64         ENTRY( "CreateInstanceL", CThumbnailManagerTest::CreateInstanceL ),
       
    65         ENTRY( "DeleteInstance", CThumbnailManagerTest::DeleteInstance ),
       
    66         ENTRY( "SetThumbnailSizeL", CThumbnailManagerTest::SetThumbnailSizeL ),
       
    67         ENTRY( "CheckThumbnailSizeL", CThumbnailManagerTest::CheckThumbnailSizeL ),
       
    68         ENTRY( "SetThumbnailEnumSizeL", CThumbnailManagerTest::SetThumbnailEnumSizeL ),
       
    69         ENTRY( "CreateSourceInstancePathL", CThumbnailManagerTest::CreateSourceInstancePathL ),
       
    70         ENTRY( "CreateSourceInstanceHandleL", CThumbnailManagerTest::CreateSourceInstanceHandleL ),
       
    71         ENTRY( "CreateSourceInstanceBufferL", CThumbnailManagerTest::CreateSourceInstanceBufferL ),
       
    72         ENTRY( "CreateSourceInstanceBitmapL", CThumbnailManagerTest::CreateSourceInstanceBitmapL ),
       
    73         ENTRY( "DeleteSourceInstance", CThumbnailManagerTest::DeleteSourceInstance ),
       
    74         ENTRY( "GetThumbnailL", CThumbnailManagerTest::GetThumbnailL ),
       
    75         ENTRY( "GetThumbnailByIdL", CThumbnailManagerTest::GetThumbnailByIdL ),
       
    76         ENTRY( "SetThumbnailL", CThumbnailManagerTest::SetThumbnailL ),
       
    77         ENTRY( "ImportThumbnailL", CThumbnailManagerTest::ImportThumbnailL ),
       
    78         ENTRY( "CheckPreviewThumbnailL", CThumbnailManagerTest::CheckPreviewThumbnailL ),
       
    79         ENTRY( "CheckThumbnailL", CThumbnailManagerTest::CheckThumbnailL ),
       
    80         ENTRY( "CheckThumbnailCenrepL", CThumbnailManagerTest::CheckThumbnailCenrepL ),
       
    81         ENTRY( "CancelPrevious", CThumbnailManagerTest::CancelPrevious ),
       
    82         ENTRY( "ChangePreviousPriority", CThumbnailManagerTest::ChangePreviousPriority ),
       
    83         ENTRY( "SetFlagsL", CThumbnailManagerTest::SetFlagsL ),
       
    84         ENTRY( "CheckFlags", CThumbnailManagerTest::CheckFlags ),
       
    85         ENTRY( "SetQualityPreferenceL", CThumbnailManagerTest::SetQualityPreferenceL ),
       
    86         ENTRY( "CheckQualityPreference", CThumbnailManagerTest::CheckQualityPreference ),
       
    87         ENTRY( "SetDisplayModeL", CThumbnailManagerTest::SetDisplayModeL ),
       
    88         ENTRY( "CheckDisplayModeL", CThumbnailManagerTest::CheckDisplayModeL ),
       
    89         ENTRY( "DeleteThumbnails", CThumbnailManagerTest::DeleteThumbnails ),
       
    90         ENTRY( "DeleteThumbnailsByIdL", CThumbnailManagerTest::DeleteThumbnailsByIdL ),
       
    91         ENTRY( "CreateThumbnails", CThumbnailManagerTest::CreateThumbnails ),
       
    92         ENTRY( "UpdatePathL", CThumbnailManagerTest::UpdatePathL ),
       
    93         ENTRY( "GetSupportedMimeTypesL", CThumbnailManagerTest::GetSupportedMimeTypesL )
       
    94         };
       
    95 
       
    96     const TInt count = sizeof( KFunctions ) / sizeof( TStifFunctionInfo );
       
    97 
       
    98     return RunInternalL( KFunctions, count, aItem );
       
    99     }
       
   100 
       
   101 TInt CThumbnailManagerTest::CreateInstanceL( CStifItemParser&  /*aItem*/ )
       
   102     {
       
   103     _LIT( KPanicTxt, "CreateInstanceL" );
       
   104     __ASSERT_ALWAYS( !iEngine, User::Panic( KPanicTxt, 0 ));
       
   105     
       
   106     iEngine = CThumbnailManager::NewL( *this );
       
   107     
       
   108     iCenrep = CThumbnailCenRep::NewL();
       
   109     iPersistentSizes = iCenrep->GetPersistentSizes();
       
   110     
       
   111     iCurrentThumbnailSize = EUnknownThumbnailSize;
       
   112     iDoNotCreate = EFalse;
       
   113     iCreateThumbnails =  EFalse;
       
   114 
       
   115     return KErrNone;
       
   116     }
       
   117 
       
   118 TInt CThumbnailManagerTest::DeleteInstance( CStifItemParser&  /*aItem*/ )
       
   119     {
       
   120     // Bitmaps must be deleted before CThumbnailManager, since
       
   121     // CThumbnailManager will close the FBS session
       
   122     delete iPreviewThumbnail;
       
   123     iPreviewThumbnail = NULL;
       
   124     delete iThumbnail;
       
   125     iThumbnail = NULL;
       
   126     delete iEngine;
       
   127     iEngine = NULL;
       
   128     delete iObjectSource;
       
   129     iObjectSource = NULL;
       
   130     delete iCenrep;
       
   131     iCenrep = NULL;
       
   132     
       
   133     return KErrNone;
       
   134     }
       
   135 
       
   136 TInt CThumbnailManagerTest::SetThumbnailSizeL( CStifItemParser& aItem )
       
   137     {
       
   138     _LIT( KPanicTxt, "SetThumbnailSizeL" );
       
   139     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 0 ));
       
   140 
       
   141     TInt width = 0;
       
   142     TInt height = 0;
       
   143     User::LeaveIfError( aItem.GetNextInt( width ));
       
   144     User::LeaveIfError( aItem.GetNextInt( height ));
       
   145     iEngine->SetThumbnailSizeL( TSize( width, height ));
       
   146     return KErrNone;
       
   147     }
       
   148 
       
   149 TInt CThumbnailManagerTest::CheckThumbnailSizeL( CStifItemParser& aItem )
       
   150     {
       
   151     _LIT( KPanicTxt, "CheckThumbnailSize" );
       
   152     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 0 ));
       
   153 
       
   154     TInt width = 0;
       
   155     TInt height = 0;
       
   156     User::LeaveIfError( aItem.GetNextInt( width ));
       
   157     User::LeaveIfError( aItem.GetNextInt( height ));
       
   158     TInt ret = KErrArgument;
       
   159     TSize size = iEngine->ThumbnailSize();
       
   160     
       
   161     if ( size == TSize( width, height ))
       
   162         {
       
   163         ret = KErrNone;
       
   164         }
       
   165     
       
   166     return ret;
       
   167     }
       
   168 
       
   169 TInt CThumbnailManagerTest::SetThumbnailEnumSizeL( CStifItemParser& aItem )
       
   170     {
       
   171     _LIT( KPanicTxt, "SetThumbnailEnumSizeL" );
       
   172     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 0 ));
       
   173 
       
   174     TInt enumSize = 0;
       
   175     User::LeaveIfError( aItem.GetNextInt( enumSize ));
       
   176     
       
   177     iEngine->SetThumbnailSizeL( (TThumbnailSize)enumSize );
       
   178     iCurrentThumbnailSize = (TThumbnailSize)enumSize;
       
   179     
       
   180     return KErrNone;
       
   181     }
       
   182 
       
   183 TInt CThumbnailManagerTest::SetFlagsL( CStifItemParser& aItem )
       
   184     {
       
   185     _LIT( KPanicTxt, "SetFlagsL" );
       
   186     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 0 ));
       
   187 
       
   188     TInt flags = 0;
       
   189     User::LeaveIfError( aItem.GetNextInt( flags ));
       
   190 
       
   191     iEngine->SetFlagsL(( CThumbnailManager::TThumbnailFlags )flags );
       
   192     
       
   193     if (flags == CThumbnailManager::EDoNotCreate)
       
   194         {
       
   195         iDoNotCreate = ETrue;
       
   196         }
       
   197     else 
       
   198         {
       
   199         iDoNotCreate = EFalse;
       
   200         }
       
   201     
       
   202     return KErrNone;
       
   203     }
       
   204 
       
   205 TInt CThumbnailManagerTest::CheckFlags( CStifItemParser& aItem )
       
   206     {
       
   207     _LIT( KPanicTxt, "CheckFlags" );
       
   208     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 0 ));
       
   209 
       
   210     TInt flags = 0;
       
   211     aItem.GetNextInt( flags );
       
   212 
       
   213     if ( iEngine->Flags() != flags )
       
   214         {
       
   215         return KErrArgument;
       
   216         }
       
   217     
       
   218     return KErrNone;
       
   219     }
       
   220 
       
   221 TInt CThumbnailManagerTest::SetQualityPreferenceL( CStifItemParser& aItem
       
   222     )
       
   223     {
       
   224     _LIT( KPanicTxt, "SetQualityPreferenceL" );
       
   225     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 0 ));
       
   226 
       
   227     TInt qp = 0;
       
   228     User::LeaveIfError( aItem.GetNextInt( qp ));
       
   229 
       
   230     iEngine->SetQualityPreferenceL( (CThumbnailManager::TThumbnailQualityPreference)qp );
       
   231     return KErrNone;
       
   232     }
       
   233 
       
   234 TInt CThumbnailManagerTest::CheckQualityPreference( CStifItemParser&
       
   235     aItem )
       
   236     {
       
   237     _LIT( KPanicTxt, "CheckQualityPreference" );
       
   238     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 0 ));
       
   239 
       
   240     TInt qp = 0;
       
   241     aItem.GetNextInt( qp );
       
   242 
       
   243     if ( iEngine->QualityPreference() != qp )
       
   244         {
       
   245         return KErrArgument;
       
   246         }
       
   247     
       
   248     return KErrNone;
       
   249     }
       
   250 
       
   251 TInt CThumbnailManagerTest::SetDisplayModeL( CStifItemParser& aItem )
       
   252     {
       
   253     _LIT( KPanicTxt, "SetDisplayModeL" );
       
   254     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 0 ));
       
   255 
       
   256     TInt displaymode = 0;
       
   257     User::LeaveIfError( aItem.GetNextInt( displaymode ));
       
   258 
       
   259     iEngine->SetDisplayModeL( (TDisplayMode)displaymode );
       
   260     return KErrNone;
       
   261     }
       
   262 
       
   263 TInt CThumbnailManagerTest::CheckDisplayModeL( CStifItemParser& aItem )
       
   264     {
       
   265     _LIT( KPanicTxt, "CheckDisplayModeL" );
       
   266     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 0 ));
       
   267 
       
   268     TInt displaymode = 0;
       
   269     User::LeaveIfError( aItem.GetNextInt( displaymode ));
       
   270 
       
   271     if ( iEngine->DisplayMode() != displaymode )
       
   272         {
       
   273         return KErrArgument;
       
   274         }
       
   275     
       
   276     return KErrNone;
       
   277     }
       
   278 
       
   279 TInt CThumbnailManagerTest::CreateSourceInstancePathL( CStifItemParser& aItem )
       
   280     {
       
   281     _LIT( KPanicTxt, "CreateSrcPath" );
       
   282     __ASSERT_ALWAYS( !iObjectSource, User::Panic( KPanicTxt, 0 ));
       
   283 
       
   284     TPtrC path;
       
   285     User::LeaveIfError( aItem.GetNextString( path ));
       
   286 
       
   287     TInt id = 0;
       
   288     aItem.GetNextInt( id );
       
   289     
       
   290     TFileName filePath( iDataPath );
       
   291     filePath.Append( path );
       
   292     filePath.ZeroTerminate();
       
   293     
       
   294     iLog->Log( _L( "CreateSourceInstancePathL - path = %S" ), &filePath );
       
   295     
       
   296     delete iObjectSource;
       
   297     iObjectSource = NULL;
       
   298     
       
   299     iObjectSource = CThumbnailObjectSource::NewL( filePath, id );
       
   300     return KErrNone;
       
   301     }
       
   302 
       
   303 TInt CThumbnailManagerTest::CreateSourceInstanceHandleL( CStifItemParser& aItem )
       
   304     {
       
   305     _LIT( KPanicTxt, "CreateSrcHandle" );
       
   306     __ASSERT_ALWAYS( !iObjectSource, User::Panic( KPanicTxt, 0 ));
       
   307 
       
   308     TPtrC path;
       
   309     User::LeaveIfError( aItem.GetNextString( path ));
       
   310 
       
   311     TFileName filePath( iDataPath );
       
   312     filePath.Append( path );
       
   313     filePath.ZeroTerminate();    
       
   314     
       
   315     User::LeaveIfError( iFile.Open( iFs, filePath, EFileShareReadersOrWriters ));
       
   316     iLog->Log( _L( "CreateSourceInstanceHandleL - path = %S" ), &filePath );
       
   317     
       
   318     delete iObjectSource;
       
   319     iObjectSource = NULL;
       
   320     iObjectSource = CThumbnailObjectSource::NewL( iFile );
       
   321     return KErrNone;
       
   322     }
       
   323 
       
   324 TInt CThumbnailManagerTest::CreateSourceInstanceBufferL( CStifItemParser& aItem )
       
   325     {
       
   326     _LIT( KPanicTxt, "CreateSrcBuffer" );
       
   327     __ASSERT_ALWAYS( !iObjectSource, User::Panic( KPanicTxt, 0 ));
       
   328 
       
   329     TPtrC path;
       
   330     User::LeaveIfError( aItem.GetNextString( path ));
       
   331 
       
   332     TPtrC mimeType;
       
   333     User::LeaveIfError( aItem.GetNextString( mimeType ));
       
   334     
       
   335     TFileName filePath( iDataPath );
       
   336     filePath.Append( path );
       
   337     filePath.ZeroTerminate();    
       
   338     
       
   339     User::LeaveIfError( iFile.Open( iFs, filePath, EFileShareReadersOrWriters ));
       
   340     iLog->Log( _L( "CreateSourceInstanceBufferL - path = %S" ), &filePath );
       
   341     
       
   342     TInt64 size;
       
   343     User::LeaveIfError( iFile.Size( size ) );
       
   344     iBuffer = HBufC8::NewL( size );
       
   345     TPtr8 ptr = iBuffer->Des();
       
   346     iFile.Read( ptr );
       
   347     iFile.Close();
       
   348     
       
   349     delete iObjectSource;
       
   350     iObjectSource = NULL;
       
   351     iObjectSource = CThumbnailObjectSource::NewL( iBuffer, mimeType, filePath );
       
   352     
       
   353     iBuffer = NULL;
       
   354     return KErrNone;
       
   355     }
       
   356 
       
   357 TInt CThumbnailManagerTest::CreateSourceInstanceBitmapL( CStifItemParser& aItem )
       
   358     {
       
   359     _LIT( KPanicTxt, "CreateSrcBuffer" );
       
   360     __ASSERT_ALWAYS( !iObjectSource, User::Panic( KPanicTxt, 0 ));
       
   361 
       
   362     TPtrC path;
       
   363     User::LeaveIfError( aItem.GetNextString( path ));
       
   364     
       
   365     TFileName filePath( iDataPath );
       
   366     filePath.Append( path );
       
   367     filePath.ZeroTerminate();    
       
   368     
       
   369     TPtrC target;
       
   370     User::LeaveIfError( aItem.GetNextString( target ));
       
   371     
       
   372     TFileName targetPath( iDataPath );
       
   373     targetPath.Append( target );
       
   374     targetPath.ZeroTerminate(); 
       
   375     
       
   376     iLog->Log( _L( "CreateSourceInstanceBitmapL - bitmap = %S" ), &filePath );
       
   377     iLog->Log( _L( "CreateSourceInstanceBitmapL - target = %S" ), &targetPath );
       
   378     
       
   379     iBitmap = new (ELeave) CFbsBitmap();
       
   380     User::LeaveIfError(iBitmap->Load(filePath, 0));
       
   381 
       
   382     delete iObjectSource;
       
   383     iObjectSource = NULL;
       
   384     iObjectSource = CThumbnailObjectSource::NewL( iBitmap, targetPath );
       
   385     
       
   386     return KErrNone;
       
   387     }
       
   388 
       
   389 TInt CThumbnailManagerTest::DeleteSourceInstance( CStifItemParser& /*aItem*/ )
       
   390     {
       
   391     delete iObjectSource;
       
   392     iObjectSource = NULL;
       
   393     return KErrNone;
       
   394     }
       
   395 
       
   396 TInt CThumbnailManagerTest::GetThumbnailL( CStifItemParser& aItem )
       
   397     {
       
   398     _LIT( KPanicTxt, "GetThumbnailL" );
       
   399     __ASSERT_ALWAYS( iObjectSource, User::Panic( KPanicTxt, 0 ));
       
   400     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 1 ));
       
   401 
       
   402     TInt clientData = NULL;
       
   403     TInt priority = 0;
       
   404 
       
   405     TInt err = aItem.GetNextInt( clientData );
       
   406     if ( !err )
       
   407         {
       
   408         aItem.GetNextInt( priority );
       
   409         }
       
   410 
       
   411     iPreviousRequestId = iEngine->GetThumbnailL( *iObjectSource, ( TAny* )
       
   412         clientData, priority );
       
   413     iLog->Log( _L( "GetThumbnailL - request id %d" ), iPreviousRequestId );
       
   414     
       
   415     if (!iDoNotCreate)
       
   416         {
       
   417         iCreateThumbnails = EFalse;
       
   418         }
       
   419     
       
   420     return KErrNone;
       
   421     }
       
   422 
       
   423 TInt CThumbnailManagerTest::GetThumbnailByIdL( CStifItemParser& aItem )
       
   424     {
       
   425     _LIT( KPanicTxt, "GetThumbnailByIdL" );
       
   426     __ASSERT_ALWAYS( iObjectSource, User::Panic( KPanicTxt, 0 ));
       
   427     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 1 ));
       
   428 
       
   429     TInt id = 0;
       
   430     TInt clientData = NULL;
       
   431     TInt priority = 0;
       
   432 
       
   433     User::LeaveIfError( aItem.GetNextInt( id ));
       
   434     TInt err = aItem.GetNextInt( clientData );
       
   435     if ( !err )
       
   436         {
       
   437         aItem.GetNextInt( priority );
       
   438         }
       
   439 
       
   440     iPreviousRequestId = iEngine->GetThumbnailL( id, (TAny*)clientData, priority );
       
   441     iLog->Log( _L( "GetThumbnailByIdL - request id %d" ), iPreviousRequestId );
       
   442     
       
   443     if (!iDoNotCreate)
       
   444         {
       
   445         iCreateThumbnails = EFalse;
       
   446         }
       
   447     
       
   448     return KErrNone;
       
   449     }
       
   450 
       
   451 TInt CThumbnailManagerTest::SetThumbnailL( CStifItemParser& aItem )
       
   452     {
       
   453     _LIT( KPanicTxt, "SetThumbnailL" );
       
   454     __ASSERT_ALWAYS( iObjectSource, User::Panic( KPanicTxt, 0 ));
       
   455     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 1 ));
       
   456 
       
   457     TInt clientData = NULL;
       
   458     TInt priority = 0;
       
   459 
       
   460     TInt err = aItem.GetNextInt( clientData );
       
   461     if ( !err )
       
   462         {
       
   463         aItem.GetNextInt( priority );
       
   464         }
       
   465 
       
   466     iPreviousRequestId = iEngine->SetThumbnailL( *iObjectSource, ( TAny* )
       
   467         clientData, priority );
       
   468     iLog->Log( _L( "SetThumbnailL - request id %d" ), iPreviousRequestId );
       
   469     
       
   470     if (!iDoNotCreate)
       
   471         {
       
   472         iCreateThumbnails = EFalse;
       
   473         }
       
   474     
       
   475     return KErrNone;
       
   476     }
       
   477 
       
   478 TInt CThumbnailManagerTest::ImportThumbnailL( CStifItemParser& aItem )
       
   479     {
       
   480     _LIT( KPanicTxt, "ImportThumbnailL" );
       
   481     __ASSERT_ALWAYS( iObjectSource, User::Panic( KPanicTxt, 0 ));
       
   482     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 1 ));
       
   483 
       
   484     TInt clientData = NULL;
       
   485     TInt priority = 0;
       
   486     TPtrC path;
       
   487     
       
   488     User::LeaveIfError( aItem.GetNextString( path ));
       
   489 
       
   490     TFileName filePath( iDataPath );
       
   491     filePath.Append( path );
       
   492     filePath.ZeroTerminate();
       
   493     
       
   494     TInt err = aItem.GetNextInt( clientData );
       
   495     if ( !err )
       
   496         {
       
   497         aItem.GetNextInt( priority );
       
   498         }
       
   499 
       
   500     iPreviousRequestId = iEngine->ImportThumbnailL( *iObjectSource, filePath,
       
   501                                                     (TAny*)clientData, priority );
       
   502     iLog->Log( _L( "ImportThumbnailL - request id %d" ), iPreviousRequestId );
       
   503     
       
   504     if (!iDoNotCreate)
       
   505         {
       
   506         iCreateThumbnails = EFalse;
       
   507         }
       
   508     
       
   509     return KErrNone;
       
   510     }
       
   511 
       
   512 void CThumbnailManagerTest::ThumbnailPreviewReady( MThumbnailData&
       
   513     aThumbnail, TThumbnailRequestId aId )
       
   514     {
       
   515     iLog->Log( _L( "ThumbnailPreviewReady aId=%d" ), aId );
       
   516     delete iPreviewThumbnail;
       
   517     iPreviewThumbnail = aThumbnail.DetachBitmap();
       
   518     iPreviewThumbnailCbId = aId;
       
   519     Signal( KErrNone );
       
   520     }
       
   521 
       
   522 void CThumbnailManagerTest::ThumbnailReady( TInt aError, MThumbnailData&
       
   523     aThumbnail, TThumbnailRequestId aId )
       
   524     {
       
   525     iLog->Log( _L( "ThumbnailReady aError=%d aId=%d" ), aError, aId );
       
   526     delete iThumbnail;
       
   527     iThumbnail = aThumbnail.DetachBitmap();
       
   528     iThumbnailCbId = aId;
       
   529     
       
   530     // ignore KErrNotFound, if auto create disabled (CreateThumbnails used)
       
   531     if (aError == KErrNotFound && iCreateThumbnails)
       
   532         {
       
   533         for ( TInt i = 0 ; i < iPersistentSizes.Count(); i++ )
       
   534             {
       
   535             if ( iPersistentSizes[i].iType == iCurrentThumbnailSize &&
       
   536                  !iPersistentSizes[i].iAutoCreate )
       
   537                 {
       
   538                 aError = KErrNone;
       
   539                 break;
       
   540                 }
       
   541             }
       
   542         }
       
   543     
       
   544     Signal( aError );
       
   545     }
       
   546 
       
   547 TInt CThumbnailManagerTest::CheckPreviewThumbnailL( CStifItemParser& aItem )
       
   548     {
       
   549     if ( iPreviewThumbnail )
       
   550         {
       
   551         TInt width = 0;
       
   552         TInt height = 0;
       
   553         TInt displaymode = 0;
       
   554         User::LeaveIfError( aItem.GetNextInt( width ));
       
   555         User::LeaveIfError( aItem.GetNextInt( height ));
       
   556         User::LeaveIfError( aItem.GetNextInt( displaymode ));
       
   557         TSize size = iPreviewThumbnail->SizeInPixels();
       
   558         iLog->Log( _L( 
       
   559             "CheckPreviewThumbnailL - bitmap size %dx%d (expecting %dx%d)" ),
       
   560             size.iWidth, size.iHeight, width, height );
       
   561         iLog->Log( _L( "CheckPreviewThumbnailL - bitmap mode %d (expecting %d)"
       
   562             ), iPreviewThumbnail->DisplayMode(), displaymode );
       
   563         if ( size != TSize( width, height ))
       
   564             {
       
   565             iLog->Log( _L( "CheckPreviewThumbnailL - size mismatch" ));
       
   566             User::Leave( KErrArgument );
       
   567             }
       
   568         else if ( displaymode != iPreviewThumbnail->DisplayMode())
       
   569             {
       
   570             iLog->Log( _L( "CheckPreviewThumbnailL - displaymode mismatch" ));
       
   571             User::Leave( KErrArgument );
       
   572             }
       
   573         else
       
   574             {
       
   575             iLog->Log( _L( "CheckPreviewThumbnailL - ok" ));
       
   576             }
       
   577         }
       
   578     else
       
   579         {
       
   580         // Bitmap missing
       
   581         iLog->Log( _L( "CheckPreviewThumbnailL - preview bitmap NULL" ));
       
   582         User::Leave( KErrUnknown );
       
   583         }
       
   584     return KErrNone;
       
   585     }
       
   586 
       
   587 TInt CThumbnailManagerTest::CheckThumbnailL( CStifItemParser& aItem )
       
   588     {
       
   589     if ( iThumbnail )
       
   590         {
       
   591         TInt width = 0;
       
   592         TInt height = 0;
       
   593         TInt displaymode = 0;
       
   594         User::LeaveIfError( aItem.GetNextInt( width ));
       
   595         User::LeaveIfError( aItem.GetNextInt( height ));
       
   596         User::LeaveIfError( aItem.GetNextInt( displaymode ));
       
   597         TSize size = iThumbnail->SizeInPixels();
       
   598         iLog->Log( _L( "CheckThumbnailL - bitmap size %dx%d (expecting %dx%d)" )
       
   599             , size.iWidth, size.iHeight, width, height );
       
   600         iLog->Log( _L( "CheckThumbnailL - bitmap mode %d (expecting %d)" ),
       
   601             iThumbnail->DisplayMode(), displaymode );
       
   602         
       
   603         // one needs to match, aspect ratio scaling makes this difficult...
       
   604         if ( size.iWidth != width && size.iHeight != height )
       
   605             {
       
   606             iLog->Log( _L( "CheckThumbnailL - size mismatch" ));
       
   607             User::Leave( KErrArgument );
       
   608             }
       
   609         else if ( displaymode != iThumbnail->DisplayMode())
       
   610             {
       
   611             iLog->Log( _L( "CheckThumbnailL - displaymode mismatch" ));
       
   612             }
       
   613         else
       
   614             {
       
   615             iLog->Log( _L( "CheckThumbnailL - ok" ));
       
   616             }
       
   617         }
       
   618     else
       
   619         {
       
   620         // Bitmap missing
       
   621         iLog->Log( _L( "CheckThumbnailL - bitmap NULL" ));
       
   622         User::Leave( KErrNotFound );
       
   623         }
       
   624     return KErrNone;
       
   625     }
       
   626 
       
   627 TInt CThumbnailManagerTest::CheckThumbnailCenrepL( CStifItemParser& aItem )
       
   628     {
       
   629     TInt err = KErrNone;
       
   630     TBool full = EFalse;
       
   631     
       
   632     TInt sizeType;
       
   633     TInt displaymode = 0;
       
   634     User::LeaveIfError( aItem.GetNextInt( sizeType ));
       
   635     User::LeaveIfError( aItem.GetNextInt( displaymode ));
       
   636     
       
   637     TThumbnailSize size = (TThumbnailSize)sizeType;
       
   638     if (size == EImageFullScreenThumbnailSize ||
       
   639         size == EVideoFullScreenThumbnailSize ||
       
   640         size == EAudioFullScreenThumbnailSize)
       
   641         {
       
   642         full = ETrue;
       
   643         }
       
   644     
       
   645     if ( iThumbnail )
       
   646         {
       
   647         TInt width = 0;
       
   648         TInt height = 0;
       
   649         
       
   650         for ( TInt i = 0 ; i < iPersistentSizes.Count(); i++ )
       
   651             {
       
   652             if ( iPersistentSizes[i].iType == size )
       
   653                 {
       
   654                 width = iPersistentSizes[i].iSize.iWidth;
       
   655                 height = iPersistentSizes[i].iSize.iHeight;
       
   656                 break;
       
   657                 }
       
   658             }
       
   659         
       
   660         TSize thumbSize = iThumbnail->SizeInPixels();
       
   661         
       
   662         iLog->Log( _L( "CheckThumbnailCenrepL - bitmap size %dx%d (expecting %dx%d)" )
       
   663             , thumbSize.iWidth, thumbSize.iHeight, width, height );
       
   664         iLog->Log( _L( "CheckThumbnailCenrepL - bitmap mode %d (expecting %d)" ),
       
   665             iThumbnail->DisplayMode(), displaymode );
       
   666         
       
   667         // one needs to match, and both need to be smaller than cenrep value
       
   668         if ( (thumbSize.iWidth == width || thumbSize.iHeight == height) &&
       
   669              thumbSize.iWidth <= width && thumbSize.iHeight <= height)
       
   670             {
       
   671             iLog->Log( _L( "CheckThumbnailCenrepL - ok" ));
       
   672             }
       
   673         else if (full && (thumbSize.iWidth <= width && thumbSize.iHeight <= height))
       
   674             {
       
   675             iLog->Log( _L( "CheckThumbnailCenrepL - fullscreen ok, not upscaled" ));
       
   676             }
       
   677         else
       
   678             {
       
   679             iLog->Log( _L( "CheckThumbnailCenrepL - size mismatch" ));
       
   680             err = KErrArgument;
       
   681             }
       
   682         
       
   683         // check display mode
       
   684         if ( displaymode != iThumbnail->DisplayMode())
       
   685             {
       
   686             iLog->Log( _L( "CheckThumbnailCenrepL - displaymode mismatch" ));
       
   687             err = KErrArgument;
       
   688             }
       
   689         }
       
   690     else
       
   691         {
       
   692         for ( TInt i = 0 ; i < iPersistentSizes.Count(); i++ )
       
   693             {
       
   694             if ( iPersistentSizes[i].iType == size && iPersistentSizes[i].iAutoCreate)
       
   695                 {
       
   696                 // Bitmap missing
       
   697                 iLog->Log( _L( "CheckThumbnailCenrepL - bitmap NULL" ));
       
   698                 err = KErrNotFound;
       
   699                 break;
       
   700                 }
       
   701             }
       
   702         }
       
   703     
       
   704     return err;
       
   705     }
       
   706 
       
   707 TInt CThumbnailManagerTest::CancelPrevious( CStifItemParser&  /*aItem*/ )
       
   708     {
       
   709     _LIT( KPanicTxt, "CancelPrevious" );
       
   710     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 0 ));
       
   711 
       
   712     TInt err = iEngine->CancelRequest( iPreviousRequestId );
       
   713     iLog->Log( _L( "CancelPrevious() returned %d" ), err );
       
   714     return err;
       
   715     }
       
   716 
       
   717 TInt CThumbnailManagerTest::ChangePreviousPriority( CStifItemParser&
       
   718     aItem )
       
   719     {
       
   720     _LIT( KPanicTxt, "ChangePreviousPriority" );
       
   721     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 0 ));
       
   722 
       
   723     TInt priority = 0;
       
   724     aItem.GetNextInt( priority );
       
   725 
       
   726     TInt err = iEngine->ChangePriority( iPreviousRequestId, priority );
       
   727     iLog->Log( _L( "ChangePriority() returned %d" ), err );
       
   728     return err;
       
   729     }
       
   730 
       
   731 
       
   732 TInt CThumbnailManagerTest::DeleteThumbnails( CStifItemParser&  /*aItem*/ )
       
   733     {
       
   734     iEngine->DeleteThumbnails( *iObjectSource );
       
   735     return KErrNone;
       
   736     }
       
   737 
       
   738 TInt CThumbnailManagerTest::DeleteThumbnailsByIdL( CStifItemParser&  aItem )
       
   739     {
       
   740     TInt id = 0;
       
   741     User::LeaveIfError( aItem.GetNextInt( id ));
       
   742     
       
   743     iEngine->DeleteThumbnails( id );
       
   744     return KErrNone;
       
   745     }
       
   746     
       
   747     
       
   748 TInt CThumbnailManagerTest::CreateThumbnails( CStifItemParser& aItem )
       
   749     {
       
   750     _LIT( KPanicTxt, "CreateThumbnails" );
       
   751     __ASSERT_ALWAYS( iObjectSource, User::Panic( KPanicTxt, 0 ));
       
   752     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 1 ));
       
   753 
       
   754     TInt priority = 0;
       
   755 
       
   756     aItem.GetNextInt( priority );
       
   757 
       
   758     TInt id;
       
   759     id = iEngine->CreateThumbnails( *iObjectSource, priority );
       
   760     if (id < 0)
       
   761         {
       
   762         iLog->Log( _L( "CreateThumbnails - error %d" ), id );
       
   763         return id;  
       
   764         }
       
   765     else
       
   766         {
       
   767         iPreviousRequestId = id;
       
   768         iLog->Log( _L( "CreateThumbnails - request id %d" ), iPreviousRequestId );
       
   769         }
       
   770     
       
   771     iCreateThumbnails = ETrue;
       
   772     
       
   773     return KErrNone;
       
   774     }
       
   775 
       
   776 TInt CThumbnailManagerTest::UpdatePathL( CStifItemParser& aItem )
       
   777     {
       
   778     _LIT( KPanicTxt, "UpdatePath" );
       
   779     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 0 ));
       
   780 
       
   781     TInt id = 0;
       
   782     TPtrC path;
       
   783     User::LeaveIfError( aItem.GetNextInt( id ));
       
   784     User::LeaveIfError( aItem.GetNextString( path ));
       
   785     
       
   786     TFileName filePath( iDataPath );
       
   787     filePath.Append( path );
       
   788     filePath.ZeroTerminate();
       
   789     
       
   790     iLog->Log( _L( "UpdatePath - path = %S" ), &filePath );
       
   791 
       
   792     iEngine->UpdateThumbnailsL(id, filePath, 0, 1000, CActive::EPriorityIdle);
       
   793 
       
   794     return KErrNone;
       
   795     }
       
   796 
       
   797 TInt CThumbnailManagerTest::GetSupportedMimeTypesL( CStifItemParser& /*aItem*/ )
       
   798     {
       
   799     _LIT( KPanicTxt, "GetSupportedMimeTypesL" );
       
   800     __ASSERT_ALWAYS( iEngine, User::Panic( KPanicTxt, 0 ));
       
   801 
       
   802     iEngine->GetSupportedMimeTypesL();
       
   803 
       
   804     return KErrNone;
       
   805     }
       
   806 
       
   807 
       
   808 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   809 // None
       
   810 
       
   811 //  [End of File] - Do not remove