mds_pub/content_listing_framework_api/tsrc/src/T_CLFApiModuleTests.cpp
changeset 0 c53acadfccc6
child 1 acef663c1218
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of CLF API test 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include "T_CLFApiModuleTests.h"
       
    21 #include <s32mem.h> 
       
    22 #include <eunitmacros.h>
       
    23 
       
    24 // the header for the tested class
       
    25 #include <ContentListingFactory.h>
       
    26 #include <MCLFChangedItemObserver.h>
       
    27 #include <MCLFContentListingEngine.h>
       
    28 #include <MCLFCustomGrouper.h>
       
    29 #include <MCLFCustomSorter.h>
       
    30 #include <MCLFItem.h>
       
    31 #include <MCLFItemListModel.h>
       
    32 #include <MCLFModifiableItem.h>
       
    33 #include <MCLFOperationObserver.h>
       
    34 #include <MCLFPostFilter.h>
       
    35 #include <MCLFSortingStyle.h>
       
    36 #include <T_ContentListingFramework.rsg>
       
    37 #include <collate.h>
       
    38 #include <PathInfo.h>
       
    39 #include <MCLFProcessObserver.h>
       
    40 #include <CLFContentListingExtended.hrh>
       
    41 
       
    42 //CONSTS
       
    43 #ifdef __WINSCW__
       
    44 _LIT( KTestResourceFile, "z:\\resource\\T_ContentListingFramework.rsc" );
       
    45 #else
       
    46 _LIT( KTestResourceFile, "c:\\sys\\bin\\T_ContentListingFramework.rsc" );
       
    47 #endif
       
    48 _LIT( KTestFileNameBase, "CLFTestFiles\\TestFile" );
       
    49 _LIT( KTestFileExt, ".txt" );
       
    50 
       
    51 const TCLFFieldId KMultibleSortingTestField1 = 0x80000001;
       
    52 const TCLFFieldId KMultibleSortingTestField2 = 0x80000002;
       
    53 const TCLFFieldId KMultibleSortingTestField3 = 0x80000003;
       
    54 const TCLFFieldId KMultibleSortingTestField4 = 0x80000004;
       
    55 const TCLFFieldId KMultibleSortingTestField5 = 0x80000005;
       
    56 const TCLFFieldId KMultibleSortingTestField6 = 0x80000006;
       
    57 
       
    58 const TInt KCLFUpdateFoldersSemanticId = 0x1000;
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // class CMGXAsyncCallback
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 class CCLFAsyncCallback : public CBase
       
    65     {
       
    66     public:
       
    67         ~CCLFAsyncCallback()
       
    68             {
       
    69             if ( iActiveWait.IsStarted() )
       
    70                 {
       
    71                 iActiveWait.AsyncStop();
       
    72                 }
       
    73             }
       
    74     public:
       
    75         static void AfterL( TTimeIntervalMicroSeconds32 aInterval )
       
    76             {
       
    77             CCLFAsyncCallback* self = new( ELeave ) CCLFAsyncCallback();
       
    78             CleanupStack::PushL( self );
       
    79             CPeriodic* periodic = CPeriodic::NewL( CActive::EPriorityIdle );
       
    80             CleanupStack::PushL( periodic );
       
    81             TCallBack callBack( CallBackL, self );
       
    82             TTimeIntervalMicroSeconds32 interval( 1000000 );
       
    83             periodic->Start( aInterval, aInterval, callBack );
       
    84             self->iActiveWait.Start();
       
    85             periodic->Cancel();
       
    86             CleanupStack::PopAndDestroy( 2 ); // periodic, self
       
    87             }
       
    88 
       
    89         static TInt CallBackL( TAny* aObject )
       
    90             {
       
    91             CCLFAsyncCallback* self = reinterpret_cast< CCLFAsyncCallback* >( aObject );
       
    92             if ( self->iActiveWait.IsStarted() )
       
    93                 {
       
    94                 self->iActiveWait.AsyncStop();
       
    95                 }
       
    96             return EFalse;
       
    97             }
       
    98             
       
    99     private:
       
   100         CActiveSchedulerWait iActiveWait;
       
   101     };
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // class TTestOperationObserver
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 class TTestOperationObserver : public MCLFOperationObserver
       
   108     {
       
   109     public:
       
   110         TTestOperationObserver()
       
   111             // set invalid values
       
   112             : iOperationEvent( TCLFOperationEvent( -1 ) ), iError( 1 ), iWait( NULL )
       
   113             {}
       
   114         void HandleOperationEventL( TCLFOperationEvent aOperationEvent,
       
   115                                     TInt aError )
       
   116             {
       
   117             iError = aError;
       
   118             iOperationEvent = aOperationEvent;
       
   119             if( iWait &&
       
   120                 iWait->IsStarted() )
       
   121                 {
       
   122                 iWait->AsyncStop();
       
   123                 }
       
   124             }
       
   125         TCLFOperationEvent iOperationEvent;
       
   126         TInt iError;
       
   127         CActiveSchedulerWait* iWait;
       
   128 
       
   129     };
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // class TTestCustomSorter
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 class TTestCustomSorter : public MCLFCustomSorter
       
   136     {
       
   137     public:
       
   138         TTestCustomSorter() : iSortItems( EFalse )
       
   139             {
       
   140             }
       
   141         void SortItemsL( RPointerArray<MCLFItem>& /*aItemArray*/ )
       
   142             {
       
   143             //aItemArray;
       
   144             iSortItems = ETrue;
       
   145             }
       
   146         TBool iSortItems;
       
   147 
       
   148     };
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // class TTestCustomGrouper
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 class TTestCustomGrouper : public MCLFCustomGrouper
       
   155     {
       
   156     public:
       
   157         TTestCustomGrouper() : iGroupCount( 2 ), iCopyItems( EFalse ), iModifiableItems( NULL )
       
   158             {
       
   159             }
       
   160         void GroupItemsL( const TArray<MCLFItem*>& /*aSourceList*/,
       
   161                           RPointerArray<MCLFItem>& aGroupedList )
       
   162             {
       
   163             //aSourceList;
       
   164             if( iCopyItems )
       
   165                 {
       
   166                 TInt count( iModifiableItems->Count() );
       
   167                 for( TInt i = 0 ; i < count ; ++i )
       
   168                     {
       
   169                     aGroupedList.AppendL( (*iModifiableItems)[i] );
       
   170                     }
       
   171                 }
       
   172             else if( iModifiableItems )
       
   173                 {
       
   174                 iModifiableItems->ResetAndDestroy();
       
   175                 for( TInt i = 0 ; i < iGroupCount ; ++i )
       
   176                     {
       
   177                     MCLFModifiableItem* item = ContentListingFactory::NewModifiableItemLC();
       
   178                     iModifiableItems->AppendL( item );
       
   179                     CleanupStack::Pop(); // item
       
   180                     aGroupedList.AppendL( item );
       
   181                     }
       
   182                 }
       
   183             }
       
   184         TInt iGroupCount;
       
   185         TBool iCopyItems;
       
   186         RPointerArray<MCLFModifiableItem>* iModifiableItems;
       
   187     };
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // class TTestPostFilter
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 class TTestPostFilter : public MCLFPostFilter
       
   194     {
       
   195     public:
       
   196         TTestPostFilter() : iShouldFilterCount( 5 ), iAllFilter( EFalse )
       
   197             {
       
   198             }
       
   199 
       
   200         void FilterItemsL( const TArray<MCLFItem*>& aItemList,
       
   201                            RPointerArray<MCLFItem>& aFilteredItemList )
       
   202             {
       
   203             iFilteredCount = 0;
       
   204             if( iAllFilter )
       
   205                 {
       
   206                 iFilteredCount = aItemList.Count();
       
   207                 return;
       
   208                 }
       
   209             for( TInt i = 0 ; i < aItemList.Count() ; ++i )
       
   210                 {
       
   211                 if( i < iShouldFilterCount  )
       
   212                     {
       
   213                     iFilteredCount++;
       
   214                     }
       
   215                 else
       
   216                     {
       
   217                     aFilteredItemList.AppendL( aItemList[i] );
       
   218                     }
       
   219                 }
       
   220             }
       
   221         TInt iShouldFilterCount;
       
   222         TBool iAllFilter;
       
   223         TInt iFilteredCount;
       
   224 
       
   225     };
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // class TTestChangedItemObserver
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 class TTestChangedItemObserver : public MCLFChangedItemObserver
       
   232     {
       
   233     public:
       
   234         TTestChangedItemObserver()
       
   235             : iHandleItemChange( EFalse ),
       
   236               iLastError( KErrNone ),
       
   237               iChangedArray( NULL ),
       
   238               iWait( NULL )      
       
   239             {
       
   240             }
       
   241         void HandleItemChangeL( const TArray<TCLFItemId>& aItemIDArray )
       
   242             {
       
   243             iHandleItemChange = ETrue;
       
   244             if( iChangedArray )
       
   245                 {
       
   246                 iChangedArray->Reset();
       
   247                 for( TInt i = 0 ; i < aItemIDArray.Count() ; ++i )
       
   248                     {
       
   249                     iChangedArray->AppendL( aItemIDArray[i] );
       
   250                     }
       
   251                 }
       
   252             if( iWait && iWait->IsStarted() )
       
   253                 {
       
   254                 iWait->AsyncStop();
       
   255                 }
       
   256 
       
   257             }
       
   258         void HandleError( TInt aError )
       
   259             {
       
   260             iLastError = aError;
       
   261             if( iWait && iWait->IsStarted() )
       
   262                 {
       
   263                 iWait->AsyncStop();
       
   264                 }
       
   265             }
       
   266         TInt iHandleItemChange;
       
   267         TInt iLastError;
       
   268         RArray<TCLFItemId>* iChangedArray;
       
   269         CActiveSchedulerWait* iWait;
       
   270     };
       
   271 
       
   272 // ---------------------------------------------------------------------------
       
   273 // class TTestCLFProcessObserver
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 class TTestCLFProcessObserver : public MCLFProcessObserver
       
   277     {
       
   278     public:
       
   279         TTestCLFProcessObserver()
       
   280             : iStartEvent( EFalse ), iEndEvent( EFalse )
       
   281             {}
       
   282         void HandleCLFProcessEventL( TCLFProcessEvent aProcessEvent )
       
   283             {
       
   284             switch ( aProcessEvent )
       
   285                 {
       
   286                 case ECLFUpdateStart:
       
   287                     {
       
   288                     iStartEvent = ETrue;
       
   289                     break;
       
   290                     }
       
   291                 case ECLFUpdateStop:
       
   292                     {
       
   293                     iEndEvent = ETrue;
       
   294                     break;
       
   295                     }
       
   296                 default:
       
   297                     {
       
   298                     User::Panic( _L("CLF module test"), 1 );
       
   299                     }
       
   300                 }
       
   301             }
       
   302         void Reset()
       
   303             {
       
   304             iStartEvent = EFalse;
       
   305             iEndEvent = EFalse;
       
   306             }
       
   307         TBool iStartEvent;
       
   308         TBool iEndEvent;
       
   309     };
       
   310 
       
   311 void SerializeL( const MDesCArray& aDataArray, CBufBase& aBuffer )
       
   312     {
       
   313     const TInt count( aDataArray.MdcaCount() );
       
   314     RBufWriteStream writeStream( aBuffer );
       
   315     CleanupClosePushL( writeStream );
       
   316     writeStream.WriteInt32L( count );
       
   317     for( TInt i = 0 ; i < count ; ++i )
       
   318         {
       
   319         const TDesC& des = aDataArray.MdcaPoint( i );
       
   320         TInt length( des.Length() );
       
   321         writeStream.WriteInt32L( length );
       
   322         writeStream.WriteL( des, length );
       
   323         }
       
   324     CleanupStack::PopAndDestroy( &writeStream );
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // T_CLFApiModuleTests::NewLC()
       
   329 // Create the testing class
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 T_CLFApiModuleTests* T_CLFApiModuleTests::NewLC()
       
   333     {
       
   334     T_CLFApiModuleTests* self = new(ELeave) T_CLFApiModuleTests;
       
   335 
       
   336     CleanupStack::PushL( self );
       
   337     // need to generate the table, so call base classes
       
   338     // second phase constructor
       
   339     self->ConstructL();
       
   340     return self;
       
   341     }
       
   342 
       
   343 
       
   344 // ---------------------------------------------------------------------------
       
   345 // T_CLFApiModuleTests::ConstructL()
       
   346 // ---------------------------------------------------------------------------
       
   347 //
       
   348 void T_CLFApiModuleTests::ConstructL()
       
   349     {
       
   350     CEUnitTestSuiteClass::ConstructL();
       
   351     }
       
   352 
       
   353 // ---------------------------------------------------------------------------
       
   354 // T_CLFApiModuleTests::~T_CLFApiModuleTests()
       
   355 // ---------------------------------------------------------------------------
       
   356 //
       
   357 T_CLFApiModuleTests::~T_CLFApiModuleTests()
       
   358     {
       
   359     Teardown();
       
   360     }
       
   361 
       
   362 /**
       
   363  * Assistance methods
       
   364  */
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // T_CLFApiModuleTests::ResourceL
       
   368 // ---------------------------------------------------------------------------
       
   369 //
       
   370 void T_CLFApiModuleTests::ResourceL( TInt aResourceId )
       
   371     {
       
   372     delete iDataBuffer;
       
   373     iDataBuffer = NULL;
       
   374     iDataBuffer = iResourceFile.AllocReadL( aResourceId );
       
   375     iResourceReader.SetBuffer( iDataBuffer );
       
   376     }
       
   377 
       
   378 // ---------------------------------------------------------------------------
       
   379 // T_CLFApiModuleTests::SortingStyleResourceL
       
   380 // ---------------------------------------------------------------------------
       
   381 //
       
   382 void T_CLFApiModuleTests::SortingStyleResourceL()
       
   383     {
       
   384     ResourceL( R_SORTING_STYLE );
       
   385     }
       
   386 
       
   387 // ---------------------------------------------------------------------------
       
   388 // T_CLFApiModuleTests::ListModelResourceL
       
   389 // ---------------------------------------------------------------------------
       
   390 //
       
   391 void T_CLFApiModuleTests::ListModelResourceL()
       
   392     {
       
   393     ResourceL( R_LIST_MODEL );
       
   394     }
       
   395 
       
   396 // ---------------------------------------------------------------------------
       
   397 // T_CLFApiModuleTests::CreateNewFileL
       
   398 // ---------------------------------------------------------------------------
       
   399 //
       
   400 void T_CLFApiModuleTests::CreateNewFileL( TInt aNumber, TDes& aFileName )
       
   401     {
       
   402     aFileName.Copy( PathInfo::PhoneMemoryRootPath() );
       
   403     aFileName.Append( KTestFileNameBase );
       
   404     TBuf<125> buf;
       
   405     buf.Num( aNumber );
       
   406     aFileName.Append( buf );
       
   407     aFileName.Append( KTestFileExt );
       
   408 
       
   409     RFile file;
       
   410     BaflUtils::EnsurePathExistsL( iFs, aFileName );
       
   411     TInt error( file.Replace( iFs, aFileName, EFileShareAny | EFileWrite ) );
       
   412     if( error == KErrNone )
       
   413         {
       
   414         error = file.Write( _L8("Test data") );
       
   415         }
       
   416     file.Close();
       
   417     User::LeaveIfError( error );
       
   418     }
       
   419 
       
   420 // ---------------------------------------------------------------------------
       
   421 // T_CLFApiModuleTests::FindTestFileIdL
       
   422 // ---------------------------------------------------------------------------
       
   423 //
       
   424 TCLFItemId T_CLFApiModuleTests::FindTestFileIdL( TInt aNumber )
       
   425     {
       
   426     TCLFItemId id( 0 );
       
   427     MCLFItemListModel* model = iEngine->CreateListModelLC( *iTestObserver );
       
   428     iMimeTypeArray->AppendL( _L("*") );
       
   429 
       
   430     iTestObserver->iWait = &iWait;
       
   431     model->SetWantedMimeTypesL( *iMimeTypeArray );
       
   432     model->RefreshL();
       
   433     iWait.Start();
       
   434 
       
   435     TFileName testFileName( PathInfo::PhoneMemoryRootPath() );
       
   436     testFileName.Append( KTestFileNameBase );
       
   437     TBuf<125> buf;
       
   438     buf.Num( aNumber );
       
   439     testFileName.Append( buf );
       
   440     testFileName.Append( KTestFileExt );
       
   441     for( TInt i = 0 ; i < model->ItemCount() ; ++i )
       
   442         {
       
   443         const MCLFItem& item = model->Item( i );
       
   444         TPtrC fileName;
       
   445         if( item.GetField( ECLFFieldIdFileNameAndPath, fileName ) != KErrNone )
       
   446             {
       
   447             continue;
       
   448             }
       
   449         if( fileName.CompareF( testFileName ) == 0 )
       
   450             {
       
   451             id = item.ItemId();
       
   452             break;
       
   453             }
       
   454         }
       
   455     CleanupStack::PopAndDestroy(); // model
       
   456     return id;
       
   457     }
       
   458 
       
   459 // ---------------------------------------------------------------------------
       
   460 // T_CLFApiModuleTests::CheckFileNameShortingL
       
   461 // ---------------------------------------------------------------------------
       
   462 //
       
   463 TBool T_CLFApiModuleTests::CheckFileNameShortingL()
       
   464     {
       
   465     TCollationMethod m = *Mem::CollationMethodByIndex( 0 );
       
   466     m.iFlags |= TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase;
       
   467 
       
   468     for( TInt i = 0 ; i < iListModel->ItemCount() -1 ; ++i )
       
   469         {
       
   470         const MCLFItem& item = iListModel->Item( i );
       
   471         const MCLFItem& item1 = iListModel->Item( i + 1 );
       
   472         TPtrC name;
       
   473         TPtrC name1;
       
   474 
       
   475         if( item.GetField( ECLFFieldIdFileName, name ) != KErrNone ||
       
   476             item1.GetField( ECLFFieldIdFileName, name1 ) != KErrNone )
       
   477             {
       
   478             return EFalse;
       
   479             }
       
   480         if( name.CompareC( name1, 3, &m ) > 0 )
       
   481             {
       
   482             return EFalse;
       
   483             }
       
   484         }
       
   485     return ETrue;
       
   486     }
       
   487 
       
   488 // ---------------------------------------------------------------------------
       
   489 // T_CLFApiModuleTests::CheckFileSizeShortingL
       
   490 // ---------------------------------------------------------------------------
       
   491 //
       
   492 TBool T_CLFApiModuleTests::CheckFileSizeShortingL()
       
   493     {
       
   494     for( TInt i = 0 ; i < iListModel->ItemCount() -1 ; ++i )
       
   495         {
       
   496         const MCLFItem& item = iListModel->Item( i );
       
   497         const MCLFItem& item1 = iListModel->Item( i + 1 );
       
   498         TInt32 size;
       
   499         TInt32 size1;
       
   500         if( item.GetField( ECLFFieldIdFileSize, size ) != KErrNone ||
       
   501             item1.GetField( ECLFFieldIdFileSize, size1 ) != KErrNone )
       
   502             {
       
   503             return EFalse;
       
   504             }
       
   505         if( size < size1 )
       
   506             {
       
   507             return EFalse;
       
   508             }
       
   509         }
       
   510     return ETrue;
       
   511     }
       
   512 
       
   513 // ---------------------------------------------------------------------------
       
   514 // T_CLFApiModuleTests::CheckMultibleSortingShortingL
       
   515 // ---------------------------------------------------------------------------
       
   516 //
       
   517 TBool T_CLFApiModuleTests::CheckMultibleSortingShortingL()
       
   518     {
       
   519     const MCLFItem* item = &( iListModel->Item( 0 ) );
       
   520     TInt32 data( 0 );
       
   521     if( item->GetField( KMultibleSortingTestField2, data ) != KErrNone ||
       
   522         data != 5 )
       
   523         {
       
   524         return EFalse;
       
   525         }
       
   526     item = &( iListModel->Item( 1 ) );
       
   527     if( item->GetField( KMultibleSortingTestField2, data ) != KErrNone ||
       
   528         data != 4 )
       
   529         {
       
   530         return EFalse;
       
   531         }
       
   532     item = &( iListModel->Item( 2 ) );
       
   533     if( item->GetField( KMultibleSortingTestField2, data ) != KErrNone ||
       
   534         data != 3 )
       
   535         {
       
   536         return EFalse;
       
   537         }
       
   538     item = &( iListModel->Item( 3 ) );
       
   539     if( item->GetField( KMultibleSortingTestField3, data ) != KErrNone ||
       
   540         data != 6 )
       
   541         {
       
   542         return EFalse;
       
   543         }
       
   544     item = &( iListModel->Item( 4 ) );
       
   545     if( item->GetField( KMultibleSortingTestField3, data ) != KErrNone ||
       
   546         data != 7 )
       
   547         {
       
   548         return EFalse;
       
   549         }
       
   550     item = &( iListModel->Item( 5 ) );
       
   551     if( item->GetField( KMultibleSortingTestField3, data ) != KErrNone ||
       
   552         data != 8 )
       
   553         {
       
   554         return EFalse;
       
   555         }
       
   556     item = &( iListModel->Item( 6 ) );
       
   557     if( item->GetField( KMultibleSortingTestField4, data ) != KErrNone ||
       
   558         data != 9 )
       
   559         {
       
   560         return EFalse;
       
   561         }
       
   562     item = &( iListModel->Item( 7 ) );
       
   563     if( item->GetField( KMultibleSortingTestField4, data ) != KErrNone ||
       
   564         data != 10 )
       
   565         {
       
   566         return EFalse;
       
   567         }
       
   568     item = &( iListModel->Item( 8 ) );
       
   569     if( item->GetField( KMultibleSortingTestField4, data ) != KErrNone ||
       
   570         data != 11 )
       
   571         {
       
   572         return EFalse;
       
   573         }
       
   574 // unsorted start
       
   575     item = &( iListModel->Item( 9 ) );
       
   576     if( item->GetField( KMultibleSortingTestField6, data ) != KErrNone ||
       
   577         ( data < 15 || data > 17 ) )
       
   578         {
       
   579         return EFalse;
       
   580         }
       
   581     item = &( iListModel->Item( 10 ) );
       
   582     if( item->GetField( KMultibleSortingTestField6, data ) != KErrNone ||
       
   583         ( data < 15 || data > 17 ) )
       
   584         {
       
   585         return EFalse;
       
   586         }
       
   587     item = &( iListModel->Item( 11 ) );
       
   588     if( item->GetField( KMultibleSortingTestField6, data ) != KErrNone ||
       
   589         ( data < 15 || data > 17 ) )
       
   590         {
       
   591         return EFalse;
       
   592         }
       
   593 // unsorted end
       
   594     item = &( iListModel->Item( 12 ) );
       
   595     if( item->GetField( KMultibleSortingTestField5, data ) != KErrNone ||
       
   596         data != 12 )
       
   597         {
       
   598         return EFalse;
       
   599         }
       
   600     item = &( iListModel->Item( 13 ) );
       
   601     if( item->GetField( KMultibleSortingTestField5, data ) != KErrNone ||
       
   602         data != 13 )
       
   603         {
       
   604         return EFalse;
       
   605         }
       
   606     item = &( iListModel->Item( 14 ) );
       
   607     if( item->GetField( KMultibleSortingTestField5, data ) != KErrNone ||
       
   608         data != 14 )
       
   609         {
       
   610         return EFalse;
       
   611         }
       
   612     item = &( iListModel->Item( 15 ) );
       
   613     if( item->GetField( KMultibleSortingTestField1, data ) != KErrNone ||
       
   614         data != 0 )
       
   615         {
       
   616         return EFalse;
       
   617         }
       
   618     item = &( iListModel->Item( 16 ) );
       
   619     if( item->GetField( KMultibleSortingTestField1, data ) != KErrNone ||
       
   620         data != 1 )
       
   621         {
       
   622         return EFalse;
       
   623         }
       
   624     item = &( iListModel->Item( 17 ) );
       
   625     if( item->GetField( KMultibleSortingTestField1, data ) != KErrNone ||
       
   626         data != 2 )
       
   627         {
       
   628         return EFalse;
       
   629         }
       
   630 
       
   631     return ETrue;
       
   632     }
       
   633 
       
   634 // ---------------------------------------------------------------------------
       
   635 // T_CLFApiModuleTests::CheckMultibleSortingShorting2L
       
   636 // ---------------------------------------------------------------------------
       
   637 //
       
   638 TBool T_CLFApiModuleTests::CheckMultibleSortingShorting2L()
       
   639     {
       
   640 // check sorted
       
   641     const MCLFItem* item = &( iListModel->Item( 0 ) );
       
   642     TInt32 data( 0 );
       
   643     if( item->GetField( KMultibleSortingTestField5, data ) != KErrNone ||
       
   644         data != 12 )
       
   645         {
       
   646         return EFalse;
       
   647         }
       
   648     item = &( iListModel->Item( 1 ) );
       
   649     if( item->GetField( KMultibleSortingTestField5, data ) != KErrNone ||
       
   650         data != 13 )
       
   651         {
       
   652         return EFalse;
       
   653         }
       
   654     item = &( iListModel->Item( 2 ) );
       
   655     if( item->GetField( KMultibleSortingTestField5, data ) != KErrNone ||
       
   656         data != 14 )
       
   657         {
       
   658         return EFalse;
       
   659         }
       
   660     item = &( iListModel->Item( 3 ) );
       
   661     if( item->GetField( KMultibleSortingTestField6, data ) != KErrNone ||
       
   662         data != 15 )
       
   663         {
       
   664         return EFalse;
       
   665         }
       
   666     item = &( iListModel->Item( 4 ) );
       
   667     if( item->GetField( KMultibleSortingTestField6, data ) != KErrNone ||
       
   668         data != 16 )
       
   669         {
       
   670         return EFalse;
       
   671         }
       
   672     item = &( iListModel->Item( 5 ) );
       
   673     if( item->GetField( KMultibleSortingTestField6, data ) != KErrNone ||
       
   674         data != 17 )
       
   675         {
       
   676         return EFalse;
       
   677         }
       
   678 // check unsorted
       
   679     for( TInt i = 6 ; i < 18 ; ++i )
       
   680         {
       
   681         item = &( iListModel->Item( i ) );
       
   682         if( item->GetField( KMultibleSortingTestField1, data ) != KErrNone )
       
   683             {
       
   684             if( item->GetField( KMultibleSortingTestField2, data ) != KErrNone )
       
   685                 {
       
   686                 if( item->GetField( KMultibleSortingTestField3, data ) != KErrNone )
       
   687                     {
       
   688                     if( item->GetField( KMultibleSortingTestField4, data ) != KErrNone )
       
   689                         {
       
   690                         return EFalse;
       
   691                         }
       
   692                     }
       
   693                 }
       
   694             }
       
   695         if( data < 0 || data > 11 )
       
   696             {
       
   697             return EFalse;
       
   698             }
       
   699         }
       
   700 
       
   701     return ETrue;
       
   702     }
       
   703 
       
   704 // ---------------------------------------------------------------------------
       
   705 // T_CLFApiModuleTests::CheckFileDateShortingL
       
   706 // ---------------------------------------------------------------------------
       
   707 //
       
   708 TBool T_CLFApiModuleTests::CheckFileDateShortingL()
       
   709     {
       
   710     for( TInt i = 0 ; i < iListModel->ItemCount() -1 ; ++i )
       
   711         {
       
   712         const MCLFItem& item = iListModel->Item( i );
       
   713         const MCLFItem& item1 = iListModel->Item( i + 1 );
       
   714         TTime date;
       
   715         TTime date1;
       
   716         if( item.GetField( ECLFFieldIdFileDate, date ) != KErrNone ||
       
   717             item1.GetField( ECLFFieldIdFileDate, date1 ) != KErrNone )
       
   718             {
       
   719             return EFalse;
       
   720             }
       
   721         if( date > date1 )
       
   722             {
       
   723             return EFalse;
       
   724             }
       
   725         }
       
   726     return ETrue;
       
   727     }
       
   728 
       
   729 // ---------------------------------------------------------------------------
       
   730 // T_CLFApiModuleTests::CheckFileTypesL
       
   731 // ---------------------------------------------------------------------------
       
   732 //
       
   733 TBool T_CLFApiModuleTests::CheckFileTypesL( const MDesCArray& aMimeTypeArray,
       
   734                                             const TArray<TInt>& aMediaTypes )
       
   735     {
       
   736     for( TInt i = 0 ; i < iListModel->ItemCount() ; ++i )
       
   737         {
       
   738         TPtrC mimeType;
       
   739         TInt32 mediaType;
       
   740         TInt error = iListModel->Item( i ).GetField( ECLFFieldIdMimeType, mimeType );
       
   741         if( iListModel->Item( i ).GetField( ECLFFieldIdMediaType, mediaType ) != KErrNone )
       
   742             {
       
   743             return EFalse;
       
   744             }
       
   745         TBool mimeTypeVal( EFalse );
       
   746         TBool mediaTypeVal( EFalse );
       
   747         if( error == KErrNone )
       
   748             {
       
   749             mimeTypeVal = CheckMimeTypesL( aMimeTypeArray, mimeType );
       
   750             }
       
   751         mediaTypeVal = CheckMediaTypesL( aMediaTypes, TCLFMediaType( mediaType ) );
       
   752         if( !( mimeTypeVal || mediaTypeVal ) )
       
   753             {
       
   754             return EFalse;
       
   755             }
       
   756         }
       
   757     return ETrue;
       
   758     }
       
   759 
       
   760 // ---------------------------------------------------------------------------
       
   761 // T_CLFApiModuleTests::CheckMimeTypesL
       
   762 // ---------------------------------------------------------------------------
       
   763 //
       
   764 TBool T_CLFApiModuleTests::CheckMimeTypesL( const MDesCArray& aMimeTypeArray,
       
   765                                             const TDesC& aMimeType )
       
   766     {
       
   767     for( TInt j = 0 ; j < aMimeTypeArray.MdcaCount() ; ++j )
       
   768         {
       
   769         if( aMimeTypeArray.MdcaPoint( j ).Match( aMimeType ) == KErrNotFound )
       
   770             {
       
   771             return ETrue;
       
   772             }
       
   773         }
       
   774     return EFalse;
       
   775     }
       
   776 
       
   777 // ---------------------------------------------------------------------------
       
   778 // T_CLFApiModuleTests::CheckMediaTypesL
       
   779 // ---------------------------------------------------------------------------
       
   780 //
       
   781 TBool T_CLFApiModuleTests::CheckMediaTypesL( const TArray<TInt>& aMediaTypes,
       
   782                                              TCLFMediaType aMediaType )
       
   783     {
       
   784     for( TInt j = 0 ; j < aMediaTypes.Count() ; ++j )
       
   785         {
       
   786         if( aMediaTypes[j] == aMediaType )
       
   787             {
       
   788             return ETrue;
       
   789             }
       
   790         }
       
   791     return EFalse;
       
   792     }
       
   793 
       
   794 // ---------------------------------------------------------------------------
       
   795 // T_CLFApiModuleTests::MakeOpaqueDataL
       
   796 // ---------------------------------------------------------------------------
       
   797 //
       
   798 HBufC8* T_CLFApiModuleTests::MakeOpaqueDataL( const MDesCArray& aFiles )
       
   799     {
       
   800     CDesCArray* folderArray = new ( ELeave ) CDesCArraySeg( 8 );
       
   801     CleanupStack::PushL( folderArray );
       
   802     TInt count( aFiles.MdcaCount() );
       
   803     for( TInt i = 0 ; i < count ; ++i )
       
   804         {
       
   805         TPtrC folderPath( TParsePtrC(
       
   806                             aFiles.MdcaPoint( i ) ).DriveAndPath() );
       
   807         TInt tmp( 0 );
       
   808         if( folderArray->Find( folderPath, tmp, ECmpFolded ) != 0 )
       
   809             {
       
   810             folderArray->AppendL( folderPath );
       
   811             }
       
   812         }
       
   813 
       
   814     CBufBase* dynBuffer = CBufFlat::NewL( 64 );
       
   815     CleanupStack::PushL( dynBuffer );
       
   816     SerializeL( *folderArray, *dynBuffer );
       
   817     HBufC8* ret = dynBuffer->Ptr( 0 ).AllocL();
       
   818     CleanupStack::PopAndDestroy( 2, folderArray );
       
   819     return ret;
       
   820     }
       
   821 
       
   822 // ---------------------------------------------------------------------------
       
   823 // T_CLFApiModuleTests::MakeMultibleSortingItemsL
       
   824 // ---------------------------------------------------------------------------
       
   825 //
       
   826 void T_CLFApiModuleTests::MakeMultibleSortingItemsL(
       
   827                         RPointerArray<MCLFModifiableItem>& aItemArray )
       
   828     {
       
   829     for( TInt i = 0 ; i < 18 ; ++i )
       
   830         {
       
   831         MCLFModifiableItem* item = ContentListingFactory::NewModifiableItemLC();
       
   832         aItemArray.AppendL( item );
       
   833         CleanupStack::Pop();
       
   834 
       
   835         if( i < 3 )
       
   836             {
       
   837             item->AddFieldL( KMultibleSortingTestField1, i );
       
   838             }
       
   839         else if( i < 6 )
       
   840             {
       
   841             item->AddFieldL( KMultibleSortingTestField2, i );
       
   842             }
       
   843         else if( i < 9 )
       
   844             {
       
   845             item->AddFieldL( KMultibleSortingTestField3, i );
       
   846             }
       
   847         else if( i < 12 )
       
   848             {
       
   849             item->AddFieldL( KMultibleSortingTestField4, i );
       
   850             }
       
   851         else if( i < 15 )
       
   852             {
       
   853             item->AddFieldL( KMultibleSortingTestField5, i );
       
   854             }
       
   855         else
       
   856             {
       
   857             item->AddFieldL( KMultibleSortingTestField6, i );
       
   858             }
       
   859         }
       
   860     }
       
   861 
       
   862 // ---------------------------------------------------------------------------
       
   863 // T_CLFApiModuleTests::FindItem
       
   864 // ---------------------------------------------------------------------------
       
   865 //
       
   866 const MCLFItem* T_CLFApiModuleTests::FindItem( MCLFItemListModel& aModel, TCLFItemId aItemId )
       
   867     {
       
   868     for( TInt i = 0 ; i < aModel.ItemCount() ; ++i )
       
   869         {
       
   870         const MCLFItem& item = aModel.Item( i );
       
   871         if( item.ItemId() == aItemId )
       
   872             {
       
   873             return &item;
       
   874             }
       
   875         }
       
   876     return NULL;
       
   877     }
       
   878 
       
   879 /**
       
   880  * Setup
       
   881  */
       
   882 
       
   883 // ---------------------------------------------------------------------------
       
   884 // T_CLFApiModuleTests::BaseSetupL
       
   885 // ---------------------------------------------------------------------------
       
   886 // 
       
   887 void T_CLFApiModuleTests::BaseSetupL()
       
   888     {
       
   889     iFs.Close();
       
   890     iResourceFile.Close();
       
   891     
       
   892     User::LeaveIfError( iFs.Connect() );
       
   893     TFileName fileName( KTestResourceFile );
       
   894     BaflUtils::NearestLanguageFile( iFs, fileName );
       
   895     iResourceFile.OpenL( iFs, KTestResourceFile );
       
   896     iResourceFile.ConfirmSignatureL( 0 );
       
   897     }
       
   898 
       
   899 // ---------------------------------------------------------------------------
       
   900 // T_CLFApiModuleTests::SortingStyleResourceSetupL
       
   901 // ---------------------------------------------------------------------------
       
   902 // 
       
   903 void T_CLFApiModuleTests::SortingStyleResourceSetupL()
       
   904     {
       
   905     BaseSetupL();
       
   906     SortingStyleResourceL();
       
   907     }
       
   908 
       
   909 // ---------------------------------------------------------------------------
       
   910 // T_CLFApiModuleTests::CreateModelSetupL
       
   911 // ---------------------------------------------------------------------------
       
   912 // 
       
   913 void T_CLFApiModuleTests::CreateModelSetupL()
       
   914     {
       
   915     iEngine = ContentListingFactory::NewContentListingEngineLC();
       
   916     CleanupStack::Pop();
       
   917     iTestObserver  = new (ELeave) TTestOperationObserver;
       
   918     }
       
   919 
       
   920 // ---------------------------------------------------------------------------
       
   921 // T_CLFApiModuleTests::CreateModelFromResourceSetupL
       
   922 // ---------------------------------------------------------------------------
       
   923 // 
       
   924 void T_CLFApiModuleTests::CreateModelFromResourceSetupL()
       
   925     {
       
   926     BaseSetupL();
       
   927     CreateModelSetupL();
       
   928     ListModelResourceL();
       
   929     }
       
   930 
       
   931 // ---------------------------------------------------------------------------
       
   932 // T_CLFApiModuleTests::ListModelSetupL
       
   933 // ---------------------------------------------------------------------------
       
   934 // 
       
   935 void T_CLFApiModuleTests::ListModelSetupL()
       
   936     {
       
   937     BaseSetupL();
       
   938     CreateModelSetupL();
       
   939     iListModel = iEngine->CreateListModelLC( *iTestObserver );
       
   940     CleanupStack::Pop();
       
   941 
       
   942     iSortingStyle = ContentListingFactory::NewSortingStyleLC();
       
   943     CleanupStack::Pop();
       
   944     iSortingStyle1 = ContentListingFactory::NewSortingStyleLC();
       
   945     CleanupStack::Pop();
       
   946     iSortingStyle2 = ContentListingFactory::NewSortingStyleLC();
       
   947     CleanupStack::Pop();
       
   948     iSortingStyle3 = ContentListingFactory::NewSortingStyleLC();
       
   949     CleanupStack::Pop();
       
   950 
       
   951     iTestSorter = new (ELeave) TTestCustomSorter;
       
   952     iTestSorter1 = new (ELeave) TTestCustomSorter;
       
   953     iTestGrouper = new (ELeave) TTestCustomGrouper;
       
   954     iTestGrouper1 = new (ELeave) TTestCustomGrouper;
       
   955     iTestFilter = new (ELeave) TTestPostFilter;
       
   956     iTestFilter1 = new (ELeave) TTestPostFilter;
       
   957     iMimeTypeArray = new (ELeave) CDesCArrayFlat( 8 );
       
   958     iMimeTypeArray1 = new (ELeave) CDesCArrayFlat( 8 );
       
   959     }
       
   960 
       
   961 // ---------------------------------------------------------------------------
       
   962 // T_CLFApiModuleTests::MultibleSortingSetupL
       
   963 // ---------------------------------------------------------------------------
       
   964 // 
       
   965 void T_CLFApiModuleTests::MultibleSortingSetupL()
       
   966     {
       
   967     ListModelSetupL();
       
   968     MakeMultibleSortingItemsL( iModifiableItems );
       
   969 
       
   970 // use custom grouper to make own items
       
   971     iTestGrouper->iModifiableItems = &iModifiableItems;
       
   972     iTestGrouper->iCopyItems = ETrue;
       
   973     iListModel->SetCustomGrouper( iTestGrouper );
       
   974 
       
   975 // set sorters
       
   976     iSortingStyle->ResetL();
       
   977     iSortingStyle->SetSortingDataType( ECLFItemDataTypeTInt32 );
       
   978     iSortingStyle->AddFieldL( KMultibleSortingTestField1 );
       
   979     iSortingStyle->SetUndefinedItemPosition( ECLFSortingStyleUndefinedFirst );
       
   980 
       
   981     iSortingStyle1->ResetL();
       
   982     iSortingStyle1->SetSortingDataType( ECLFItemDataTypeTInt32 );
       
   983     iSortingStyle1->AddFieldL( KMultibleSortingTestField2 );
       
   984     iSortingStyle1->SetUndefinedItemPosition( ECLFSortingStyleUndefinedEnd );
       
   985     iSortingStyle1->SetOrdering( ECLFOrderingDescending );
       
   986 
       
   987     iSortingStyle2->ResetL();
       
   988     iSortingStyle2->SetSortingDataType( ECLFItemDataTypeTInt32 );
       
   989     iSortingStyle2->AddFieldL( KMultibleSortingTestField3 );
       
   990     iSortingStyle2->AddFieldL( KMultibleSortingTestField4 );
       
   991     iSortingStyle2->SetUndefinedItemPosition( ECLFSortingStyleUndefinedEnd );
       
   992 
       
   993     iSortingStyle3->ResetL();
       
   994     iSortingStyle3->SetSortingDataType( ECLFItemDataTypeTInt32 );
       
   995     iSortingStyle3->AddFieldL( KMultibleSortingTestField5 );
       
   996     iSortingStyle3->SetUndefinedItemPosition( ECLFSortingStyleUndefinedFirst );
       
   997 
       
   998     iListModel->SetSortingStyle( iSortingStyle );
       
   999     iListModel->AppendSecondarySortingStyleL( *iSortingStyle1 );
       
  1000     iListModel->AppendSecondarySortingStyleL( *iSortingStyle2 );
       
  1001     iListModel->AppendSecondarySortingStyleL( *iSortingStyle3 );
       
  1002     }
       
  1003 
       
  1004 // ---------------------------------------------------------------------------
       
  1005 // T_CLFApiModuleTests::MultibleSortingResourceSetupL
       
  1006 // ---------------------------------------------------------------------------
       
  1007 // 
       
  1008 void T_CLFApiModuleTests::MultibleSortingResourceSetupL()
       
  1009     {
       
  1010     ListModelSetupL();
       
  1011     delete iListModel;
       
  1012     iListModel = NULL;
       
  1013     ResourceL( R_LIST_MODEL_MULTIBLE );
       
  1014     iListModel = iEngine->CreateListModelLC( *iTestObserver, iResourceReader );
       
  1015     CleanupStack::Pop();
       
  1016 
       
  1017 // use custom grouper to make own items
       
  1018     MakeMultibleSortingItemsL( iModifiableItems );
       
  1019     iTestGrouper->iModifiableItems = &iModifiableItems;
       
  1020     iTestGrouper->iCopyItems = ETrue;
       
  1021     iListModel->SetCustomGrouper( iTestGrouper );
       
  1022 
       
  1023     }
       
  1024 
       
  1025 // ---------------------------------------------------------------------------
       
  1026 // T_CLFApiModuleTests::ListModelAllFileItemsSetupL
       
  1027 // ---------------------------------------------------------------------------
       
  1028 // 
       
  1029 void T_CLFApiModuleTests::ListModelAllFileItemsSetupL()
       
  1030     {
       
  1031     ListModelSetupL();
       
  1032     iMediaTypeArray.AppendL( ECLFMediaTypeVideo );
       
  1033     iMediaTypeArray.AppendL( ECLFMediaTypeImage );
       
  1034     iMediaTypeArray.AppendL( ECLFMediaTypeSound );
       
  1035     iMediaTypeArray.AppendL( ECLFMediaTypeMusic );
       
  1036     iMediaTypeArray.AppendL( ECLFMediaTypeStreamingURL );
       
  1037     iMediaTypeArray.AppendL( ECLFMediaTypePlaylist );
       
  1038     iListModel->SetWantedMediaTypesL( iMediaTypeArray.Array() );
       
  1039     iTestObserver->iWait = &iWait;
       
  1040     iListModel->RefreshL();
       
  1041     iWait.Start();
       
  1042     iItemCount = iListModel->ItemCount();
       
  1043     }
       
  1044 
       
  1045 // ---------------------------------------------------------------------------
       
  1046 // T_CLFApiModuleTests::ListModelSetupFromResourceL
       
  1047 // ---------------------------------------------------------------------------
       
  1048 // 
       
  1049 void T_CLFApiModuleTests::ListModelSetupFromResourceL()
       
  1050     {
       
  1051     BaseSetupL();
       
  1052     CreateModelSetupL();
       
  1053     ListModelResourceL();
       
  1054     iListModel = iEngine->CreateListModelLC( *iTestObserver, iResourceReader );
       
  1055     CleanupStack::Pop();
       
  1056     }
       
  1057 
       
  1058 // ---------------------------------------------------------------------------
       
  1059 // T_CLFApiModuleTests::EngineTestSetupL
       
  1060 // ---------------------------------------------------------------------------
       
  1061 // 
       
  1062 void T_CLFApiModuleTests::EngineTestSetupL()
       
  1063     {
       
  1064     User::LeaveIfError( iFs.Connect() );
       
  1065     iTestObserver  = new (ELeave) TTestOperationObserver;
       
  1066     iMimeTypeArray = new (ELeave) CDesCArrayFlat( 8 );
       
  1067     iEngine = ContentListingFactory::NewContentListingEngineLC();
       
  1068     CleanupStack::Pop();
       
  1069     iChangedItemObserver = new (ELeave) TTestChangedItemObserver;
       
  1070     iChangedItemObserver1 = new (ELeave) TTestChangedItemObserver;
       
  1071     iTestCLFProcessObserver = new (ELeave) TTestCLFProcessObserver;
       
  1072     iTestCLFProcessObserver1 = new (ELeave) TTestCLFProcessObserver;
       
  1073     }
       
  1074 
       
  1075 // ---------------------------------------------------------------------------
       
  1076 // T_CLFApiModuleTests::SortingStyleTestSetupL
       
  1077 // ---------------------------------------------------------------------------
       
  1078 // 
       
  1079 void T_CLFApiModuleTests::SortingStyleTestSetupL()
       
  1080     {
       
  1081     iSortingStyle = ContentListingFactory::NewSortingStyleLC();
       
  1082     CleanupStack::Pop();
       
  1083     }
       
  1084 
       
  1085 // ---------------------------------------------------------------------------
       
  1086 // T_CLFApiModuleTests::SortingStyleResourceTestSetupL
       
  1087 // ---------------------------------------------------------------------------
       
  1088 // 
       
  1089 void T_CLFApiModuleTests::SortingStyleResourceTestSetupL()
       
  1090     {
       
  1091     SortingStyleResourceSetupL();
       
  1092     iSortingStyle1 = ContentListingFactory::NewSortingStyleLC( iResourceReader );
       
  1093     CleanupStack::Pop();
       
  1094 
       
  1095     ResourceL( R_SORTING_STYLE_EMPTY );
       
  1096     iSortingStyle = ContentListingFactory::NewSortingStyleLC( iResourceReader );
       
  1097     CleanupStack::Pop();
       
  1098 
       
  1099     ResourceL( R_SORTING_STYLE_UNDEFINEDITEM );
       
  1100     iSortingStyle2 = ContentListingFactory::NewSortingStyleLC( iResourceReader );
       
  1101     CleanupStack::Pop();
       
  1102     }
       
  1103 
       
  1104 // ---------------------------------------------------------------------------
       
  1105 // T_CLFApiModuleTests::ModifiableItemTestSetupL
       
  1106 // ---------------------------------------------------------------------------
       
  1107 // 
       
  1108 void T_CLFApiModuleTests::ModifiableItemTestSetupL()
       
  1109     {
       
  1110     iModifiableItem = ContentListingFactory::NewModifiableItemLC();
       
  1111     CleanupStack::Pop();
       
  1112     }
       
  1113 
       
  1114 // ---------------------------------------------------------------------------
       
  1115 // T_CLFApiModuleTests::ItemTestSetupL
       
  1116 // ---------------------------------------------------------------------------
       
  1117 // 
       
  1118 void T_CLFApiModuleTests::ItemTestSetupL()
       
  1119     {
       
  1120     ListModelSetupL();
       
  1121     CreateNewFileL( 12, iFileName );
       
  1122     iEngine->UpdateItemsL();
       
  1123     iMimeTypeArray->Reset();
       
  1124     iMimeTypeArray->AppendL( _L("*") );
       
  1125     iListModel->SetWantedMimeTypesL( *iMimeTypeArray );
       
  1126 
       
  1127     iTestObserver->iWait = &iWait;
       
  1128     iListModel->RefreshL();
       
  1129     iWait.Start();
       
  1130 
       
  1131     for( TInt i = 0 ; i < iListModel->ItemCount() ; ++i )
       
  1132         {
       
  1133         const MCLFItem& item = iListModel->Item( i );
       
  1134         TPtrC fn;
       
  1135         item.GetField( ECLFFieldIdFileNameAndPath, fn );
       
  1136         if( iFileName.CompareF( fn ) == 0 )
       
  1137             {
       
  1138             iItem = &item;
       
  1139             }
       
  1140         }
       
  1141 
       
  1142     EUNIT_ASSERT( iItem ); // Item should be in model
       
  1143 
       
  1144     }
       
  1145 
       
  1146 /**
       
  1147  * Teardown
       
  1148  */
       
  1149 
       
  1150 // ---------------------------------------------------------------------------
       
  1151 // T_CLFApiModuleTests::Teardown
       
  1152 // ---------------------------------------------------------------------------
       
  1153 // 
       
  1154 void T_CLFApiModuleTests::Teardown()
       
  1155     {
       
  1156     iResourceFile.Close();
       
  1157     iFs.Close();
       
  1158     iMediaTypeArray.Reset();
       
  1159     iMediaTypeArray.Close();
       
  1160     iMediaTypeArray1.Reset();
       
  1161     iMediaTypeArray1.Close();
       
  1162     iUpdateItemIdArray.Reset();
       
  1163     iUpdateItemIdArray.Close();
       
  1164     iChangedArray.Reset();
       
  1165     iChangedArray.Close();
       
  1166     iModifiableItems.ResetAndDestroy();
       
  1167     iModifiableItems.Close();
       
  1168     
       
  1169     delete iListModel;
       
  1170     iListModel = NULL;
       
  1171     delete iEngine;
       
  1172     iEngine = NULL;
       
  1173     delete iSortingStyle;
       
  1174     iSortingStyle = NULL;
       
  1175     delete iSortingStyle1;
       
  1176     iSortingStyle1 = NULL;
       
  1177     delete iSortingStyle2;
       
  1178     iSortingStyle2 = NULL;
       
  1179     delete iSortingStyle3;
       
  1180     iSortingStyle3 = NULL;
       
  1181     delete iDataBuffer;
       
  1182     iDataBuffer = NULL;    
       
  1183     delete iTestObserver;
       
  1184     iTestObserver = NULL;
       
  1185     delete iTestSorter;
       
  1186     iTestSorter = NULL;
       
  1187     delete iTestSorter1;
       
  1188     iTestSorter1 = NULL;
       
  1189     delete iTestGrouper;
       
  1190     iTestGrouper = NULL;
       
  1191     delete iTestGrouper1;
       
  1192     iTestGrouper1 = NULL;
       
  1193     delete iTestFilter;
       
  1194     iTestFilter = NULL;
       
  1195     delete iTestFilter1;
       
  1196     iTestFilter1 = NULL;
       
  1197     delete iMimeTypeArray;
       
  1198     iMimeTypeArray = NULL;
       
  1199     delete iMimeTypeArray1;
       
  1200     iMimeTypeArray1 = NULL;
       
  1201     delete iChangedItemObserver;
       
  1202     iChangedItemObserver = NULL;
       
  1203     delete iChangedItemObserver1;
       
  1204     iChangedItemObserver1 = NULL;
       
  1205     delete iOpaqueData;
       
  1206     iOpaqueData = NULL;
       
  1207     delete iModifiableItem;
       
  1208     iModifiableItem = NULL;
       
  1209     delete iTestCLFProcessObserver1;
       
  1210     iTestCLFProcessObserver1 = NULL;
       
  1211     delete iTestCLFProcessObserver;
       
  1212     iTestCLFProcessObserver = NULL;
       
  1213     
       
  1214     TTimeIntervalMicroSeconds32 time = 1000000;
       
  1215     TRAP_IGNORE( CCLFAsyncCallback::AfterL( time ) );
       
  1216     }
       
  1217 
       
  1218 /**
       
  1219  * Tests, construction
       
  1220  */
       
  1221 
       
  1222 // ---------------------------------------------------------------------------
       
  1223 // T_CLFApiModuleTests::CreateEngineTestL
       
  1224 // ---------------------------------------------------------------------------
       
  1225 // 
       
  1226 void T_CLFApiModuleTests::CreateEngineTestL()
       
  1227     {
       
  1228     MCLFContentListingEngine* engine = NULL;
       
  1229     engine = ContentListingFactory::NewContentListingEngineLC();
       
  1230     EUNIT_ASSERT( engine );
       
  1231     CleanupStack::PopAndDestroy();
       
  1232     engine = NULL;
       
  1233     engine = ContentListingFactory::NewContentListingEngineLC();
       
  1234     CleanupStack::Pop();
       
  1235     EUNIT_ASSERT( engine );
       
  1236     delete engine;
       
  1237     }
       
  1238 
       
  1239 // ---------------------------------------------------------------------------
       
  1240 // T_CLFApiModuleTests::CreateModifiableItemTestL
       
  1241 // ---------------------------------------------------------------------------
       
  1242 // 
       
  1243 void T_CLFApiModuleTests::CreateModifiableItemTestL()
       
  1244     {
       
  1245     MCLFModifiableItem* item = NULL;
       
  1246     item = ContentListingFactory::NewModifiableItemLC();
       
  1247     EUNIT_ASSERT( item );
       
  1248     CleanupStack::PopAndDestroy();
       
  1249     item = NULL;
       
  1250     item = ContentListingFactory::NewModifiableItemLC();
       
  1251     CleanupStack::Pop();
       
  1252     EUNIT_ASSERT( item );
       
  1253     delete item;
       
  1254     }
       
  1255 
       
  1256 // ---------------------------------------------------------------------------
       
  1257 // T_CLFApiModuleTests::CreateSortignStyleTestL
       
  1258 // ---------------------------------------------------------------------------
       
  1259 // 
       
  1260 void T_CLFApiModuleTests::CreateSortignStyleTestL()
       
  1261     {
       
  1262     MCLFSortingStyle* sortingStyle = NULL;
       
  1263     sortingStyle = ContentListingFactory::NewSortingStyleLC();
       
  1264     EUNIT_ASSERT( sortingStyle );
       
  1265     CleanupStack::PopAndDestroy();
       
  1266     sortingStyle = NULL;
       
  1267     sortingStyle = ContentListingFactory::NewSortingStyleLC();
       
  1268     CleanupStack::Pop();
       
  1269     EUNIT_ASSERT( sortingStyle );
       
  1270     delete sortingStyle;
       
  1271     }
       
  1272 
       
  1273 // ---------------------------------------------------------------------------
       
  1274 // T_CLFApiModuleTests::CreateSortignStyleFromResourceTestL
       
  1275 // ---------------------------------------------------------------------------
       
  1276 // 
       
  1277 void T_CLFApiModuleTests::CreateSortignStyleFromResourceTestL()
       
  1278     {
       
  1279     MCLFSortingStyle* sortingStyle = NULL;
       
  1280     sortingStyle = ContentListingFactory::NewSortingStyleLC( iResourceReader );
       
  1281     EUNIT_ASSERT( sortingStyle );
       
  1282     CleanupStack::PopAndDestroy();
       
  1283     sortingStyle = NULL;
       
  1284 
       
  1285     SortingStyleResourceL(); // refresh resource reader
       
  1286     sortingStyle = ContentListingFactory::NewSortingStyleLC( iResourceReader );
       
  1287     CleanupStack::Pop();
       
  1288     EUNIT_ASSERT( sortingStyle );
       
  1289     delete sortingStyle;
       
  1290     }
       
  1291 
       
  1292 // ---------------------------------------------------------------------------
       
  1293 // T_CLFApiModuleTests::CreateListModelTestL
       
  1294 // ---------------------------------------------------------------------------
       
  1295 // 
       
  1296 void T_CLFApiModuleTests::CreateListModelTestL()
       
  1297     {
       
  1298     MCLFItemListModel* model = NULL;
       
  1299     model = iEngine->CreateListModelLC( *iTestObserver );
       
  1300     EUNIT_ASSERT( model );
       
  1301     CleanupStack::PopAndDestroy();
       
  1302     model = NULL;
       
  1303 
       
  1304     model = iEngine->CreateListModelLC( *iTestObserver );
       
  1305     CleanupStack::Pop();
       
  1306     EUNIT_ASSERT( model );
       
  1307     delete model;
       
  1308     }
       
  1309 
       
  1310 // ---------------------------------------------------------------------------
       
  1311 // T_CLFApiModuleTests::CreateListModelFromResourceTestL
       
  1312 // ---------------------------------------------------------------------------
       
  1313 // 
       
  1314 void T_CLFApiModuleTests::CreateListModelFromResourceTestL()
       
  1315     {
       
  1316     MCLFItemListModel* model = NULL;
       
  1317     model = iEngine->CreateListModelLC( *iTestObserver, iResourceReader );
       
  1318     EUNIT_ASSERT( model );
       
  1319     CleanupStack::PopAndDestroy();
       
  1320     model = NULL;
       
  1321 
       
  1322     ListModelResourceL();
       
  1323     model = iEngine->CreateListModelLC( *iTestObserver, iResourceReader );
       
  1324     CleanupStack::Pop();
       
  1325     EUNIT_ASSERT( model );
       
  1326     delete model;
       
  1327 
       
  1328 
       
  1329     ResourceL( R_LIST_MODEL_INCORRECT_VERSION );
       
  1330     EUNIT_ASSERT_SPECIFIC_LEAVE( iEngine->CreateListModelLC( *iTestObserver, iResourceReader ), KErrNotSupported );
       
  1331    }
       
  1332 
       
  1333 /**
       
  1334  * Tests, engine
       
  1335  */
       
  1336 
       
  1337 // ---------------------------------------------------------------------------
       
  1338 // T_CLFApiModuleTests::UpdateItemsTestL
       
  1339 // ---------------------------------------------------------------------------
       
  1340 // 
       
  1341 void T_CLFApiModuleTests::UpdateItemsTestL()
       
  1342     {
       
  1343     // MDS will do the updating automatically in the background,
       
  1344     // thus only checking that the methods return correctly
       
  1345     iChangedItemObserver->iWait = &iWait;
       
  1346     iChangedItemObserver->iChangedArray = &iChangedArray;
       
  1347     iEngine->AddChangedItemObserverL( *iChangedItemObserver );
       
  1348     iEngine->AddCLFProcessObserverL( *iTestCLFProcessObserver );
       
  1349     iEngine->AddCLFProcessObserverL( *iTestCLFProcessObserver1 );
       
  1350 
       
  1351     CreateNewFileL( 0, iFileName );
       
  1352     CreateNewFileL( 1, iFileName );
       
  1353     CreateNewFileL( 2, iFileName );
       
  1354     CreateNewFileL( 3, iFileName );
       
  1355     CreateNewFileL( 4, iFileName );
       
  1356     CreateNewFileL( 5, iFileName );
       
  1357 
       
  1358 // update server
       
  1359 // to avoid incorrect test result
       
  1360     CreateNewFileL( 0, iFileName );
       
  1361     iEngine->UpdateItemsL();
       
  1362 
       
  1363     EUNIT_ASSERT( iChangedItemObserver->iLastError == KErrNone );
       
  1364 
       
  1365     iChangedArray.Reset();
       
  1366     iEngine->RemoveCLFProcessObserver( *iTestCLFProcessObserver1 );
       
  1367     iChangedItemObserver->iHandleItemChange = EFalse;
       
  1368     iChangedItemObserver1->iHandleItemChange = EFalse;
       
  1369     iTestCLFProcessObserver->Reset();
       
  1370     iTestCLFProcessObserver1->Reset();
       
  1371     iEngine->UpdateItemsL();
       
  1372     }
       
  1373 
       
  1374 // ---------------------------------------------------------------------------
       
  1375 // T_CLFApiModuleTests::UpdateItemsWithIdTestL
       
  1376 // ---------------------------------------------------------------------------
       
  1377 // 
       
  1378 void T_CLFApiModuleTests::UpdateItemsWithIdTestL()
       
  1379     {
       
  1380     // MDS will do the updating automatically in the background,
       
  1381     // thus only checking that the methods return correctly
       
  1382     iChangedItemObserver->iWait = &iWait;
       
  1383     iChangedItemObserver->iChangedArray = &iChangedArray;
       
  1384     iEngine->AddChangedItemObserverL( *iChangedItemObserver );
       
  1385     iEngine->AddChangedItemObserverL( *iChangedItemObserver1 );
       
  1386     iEngine->AddCLFProcessObserverL( *iTestCLFProcessObserver );
       
  1387 
       
  1388     CreateNewFileL( 0, iFileName );
       
  1389     CreateNewFileL( 1, iFileName );
       
  1390     CreateNewFileL( 2, iFileName );
       
  1391 
       
  1392 // update server
       
  1393 // to avoid incorrect test result
       
  1394     CreateNewFileL( 0, iFileName );
       
  1395     iEngine->UpdateItemsL();
       
  1396     
       
  1397     EUNIT_ASSERT( iChangedItemObserver->iLastError == KErrNone );
       
  1398 
       
  1399 // start testing
       
  1400 // update by id
       
  1401     TUint id1 = FindTestFileIdL( 1 );
       
  1402     TUint id0 = FindTestFileIdL( 0 );
       
  1403     TUint id2 = FindTestFileIdL( 2 );
       
  1404     iUpdateItemIdArray.AppendL( id1 );
       
  1405     iChangedItemObserver->iHandleItemChange = EFalse;
       
  1406     iChangedItemObserver1->iHandleItemChange = EFalse;
       
  1407     iTestCLFProcessObserver->Reset();
       
  1408     iTestCLFProcessObserver1->Reset();
       
  1409     CreateNewFileL( 0, iFileName );
       
  1410     CreateNewFileL( 1, iFileName );
       
  1411     iEngine->UpdateItemsL( iUpdateItemIdArray.Array() );
       
  1412     
       
  1413     EUNIT_ASSERT( iChangedItemObserver->iLastError == KErrNone );
       
  1414 
       
  1415     iEngine->RemoveChangedItemObserver( *iChangedItemObserver1 );
       
  1416     iEngine->AddCLFProcessObserverL( *iTestCLFProcessObserver1 );
       
  1417 
       
  1418     iChangedItemObserver->iHandleItemChange = EFalse;
       
  1419     iChangedItemObserver1->iHandleItemChange = EFalse;
       
  1420     iTestCLFProcessObserver->Reset();
       
  1421     iTestCLFProcessObserver1->Reset();
       
  1422     iUpdateItemIdArray.AppendL( id0 );
       
  1423     iUpdateItemIdArray.AppendL( id2 );
       
  1424     
       
  1425 // update server
       
  1426 // to avoid incorrect test result
       
  1427     iEngine->UpdateItemsL();
       
  1428     
       
  1429     EUNIT_ASSERT( iChangedItemObserver->iLastError == KErrNone );
       
  1430     
       
  1431     CreateNewFileL( 0, iFileName );
       
  1432     CreateNewFileL( 1, iFileName );
       
  1433     CreateNewFileL( 2, iFileName );
       
  1434     iChangedArray.Reset();
       
  1435     
       
  1436     iEngine->UpdateItemsL( iUpdateItemIdArray.Array() );
       
  1437     }
       
  1438 
       
  1439 // ---------------------------------------------------------------------------
       
  1440 // T_CLFApiModuleTests::UpdateItemsWithOpaqueDataFolderTestL
       
  1441 // ---------------------------------------------------------------------------
       
  1442 // 
       
  1443 void T_CLFApiModuleTests::UpdateItemsWithOpaqueDataFolderTestL()
       
  1444     {
       
  1445     // update server
       
  1446     // to avoid incorrect test result
       
  1447     iEngine->UpdateItemsL();
       
  1448     iWait.Start();
       
  1449 
       
  1450     // start testing
       
  1451     // update by opaque data
       
  1452     // folders data
       
  1453     iSemanticId = KCLFUpdateFoldersSemanticId;
       
  1454     delete iOpaqueData;
       
  1455     iOpaqueData = NULL;
       
  1456 
       
  1457     CDesCArray* fileArray = new (ELeave) CDesCArraySeg( 8 );
       
  1458     iOpaqueData = MakeOpaqueDataL( *fileArray );
       
  1459     // Calls internally same MDS method as when updating all data
       
  1460     // thus only interested if this call leaves
       
  1461     iEngine->UpdateItemsL( iSemanticId, *iOpaqueData );
       
  1462     }
       
  1463 
       
  1464 /**
       
  1465  * Tests, list model
       
  1466  */
       
  1467 
       
  1468 // ---------------------------------------------------------------------------
       
  1469 // T_CLFApiModuleTests::RefreshTestL
       
  1470 // ---------------------------------------------------------------------------
       
  1471 //  
       
  1472 void T_CLFApiModuleTests::RefreshTestL()
       
  1473     {
       
  1474     iMimeTypeArray->Reset();
       
  1475     iMimeTypeArray->AppendL( _L("*") );
       
  1476     iListModel->SetWantedMimeTypesL( *iMimeTypeArray );
       
  1477 
       
  1478     iTestObserver->iWait = &iWait;
       
  1479     iTestObserver->iError = 100;
       
  1480     iListModel->RefreshL();
       
  1481     iWait.Start();
       
  1482     EUNIT_ASSERT( iTestObserver->iOperationEvent == ECLFRefreshComplete );
       
  1483     EUNIT_ASSERT( iTestObserver->iError == KErrNone );
       
  1484     EUNIT_ASSERT( iListModel->ItemCount() > 0 );
       
  1485 
       
  1486 // cancel refresh
       
  1487     iListModel->RefreshL();
       
  1488     iListModel->CancelRefresh();
       
  1489     }
       
  1490 
       
  1491 // ---------------------------------------------------------------------------
       
  1492 // T_CLFApiModuleTests::SetSortingStyleTestL
       
  1493 // ---------------------------------------------------------------------------
       
  1494 // 
       
  1495 void T_CLFApiModuleTests::SetSortingStyleTestL()
       
  1496     {
       
  1497     iListModel->SetSortingStyle( NULL );
       
  1498     iListModel->RefreshL( ECLFRefreshAll );
       
  1499     EUNIT_ASSERT( !CheckFileNameShortingL() );
       
  1500 
       
  1501 // file name sorting
       
  1502     iSortingStyle->ResetL();
       
  1503     iSortingStyle->SetSortingDataType( ECLFItemDataTypeDesC );
       
  1504     iSortingStyle->AddFieldL( ECLFFieldIdFileName );
       
  1505     iListModel->SetSortingStyle( iSortingStyle );
       
  1506     iListModel->RefreshL( ECLFRefreshAll );
       
  1507     EUNIT_ASSERT( CheckFileNameShortingL() );
       
  1508 
       
  1509 // file size sorting
       
  1510     iSortingStyle1->ResetL();
       
  1511     iSortingStyle1->SetOrdering( ECLFOrderingDescending );
       
  1512     iSortingStyle1->SetSortingDataType( ECLFItemDataTypeTInt32 );
       
  1513     iSortingStyle1->AddFieldL( ECLFFieldIdFileSize );
       
  1514     iListModel->SetSortingStyle( iSortingStyle1 );
       
  1515     iListModel->RefreshL( ECLFRefreshAll );
       
  1516     EUNIT_ASSERT( CheckFileSizeShortingL() );
       
  1517 
       
  1518     iListModel->SetSortingStyle( NULL );
       
  1519     iListModel->RefreshL( ECLFRefreshAll );
       
  1520     EUNIT_ASSERT( !CheckFileNameShortingL() );
       
  1521     EUNIT_ASSERT( !CheckFileSizeShortingL() );
       
  1522     EUNIT_ASSERT( !CheckFileDateShortingL() );
       
  1523 
       
  1524 // time sorting
       
  1525     iSortingStyle->ResetL();
       
  1526     iSortingStyle->SetSortingDataType( ECLFItemDataTypeTTime );
       
  1527     iSortingStyle->AddFieldL( ECLFFieldIdFileDate );
       
  1528     iListModel->SetSortingStyle( iSortingStyle );
       
  1529     iListModel->RefreshL( ECLFRefreshAll );
       
  1530     EUNIT_ASSERT( CheckFileDateShortingL() );
       
  1531 
       
  1532 // parameter test (time)
       
  1533     iListModel->SetSortingStyle( NULL );
       
  1534     iListModel->RefreshL( ECLFRefreshAll );
       
  1535     EUNIT_ASSERT( !CheckFileNameShortingL() );
       
  1536     EUNIT_ASSERT( !CheckFileSizeShortingL() );
       
  1537     EUNIT_ASSERT( !CheckFileDateShortingL() );
       
  1538 
       
  1539     iListModel->SetSortingStyle( iSortingStyle );
       
  1540     iListModel->RefreshL( ECLFRefreshPostFilter );
       
  1541     EUNIT_ASSERT( !CheckFileNameShortingL() );
       
  1542     EUNIT_ASSERT( !CheckFileSizeShortingL() );
       
  1543     EUNIT_ASSERT( !CheckFileDateShortingL() );
       
  1544 
       
  1545     iListModel->RefreshL( ECLFRefreshGrouping );
       
  1546     EUNIT_ASSERT( !CheckFileNameShortingL() );
       
  1547     EUNIT_ASSERT( !CheckFileSizeShortingL() );
       
  1548     EUNIT_ASSERT( !CheckFileDateShortingL() );
       
  1549 
       
  1550     iListModel->RefreshL( ECLFRefreshSorting );
       
  1551     EUNIT_ASSERT( !CheckFileNameShortingL() );
       
  1552     EUNIT_ASSERT( !CheckFileSizeShortingL() );
       
  1553     EUNIT_ASSERT( CheckFileDateShortingL() );
       
  1554 
       
  1555 // custom sorter (overwrite sorting style)
       
  1556     iTestSorter->iSortItems = EFalse;
       
  1557 
       
  1558     iListModel->SetCustomSorter( iTestSorter );
       
  1559     iListModel->RefreshL( ECLFRefreshAll );
       
  1560     EUNIT_ASSERT( iTestSorter->iSortItems );
       
  1561     EUNIT_ASSERT( !CheckFileNameShortingL() );
       
  1562     EUNIT_ASSERT( !CheckFileSizeShortingL() );
       
  1563     EUNIT_ASSERT( !CheckFileDateShortingL() );
       
  1564     }
       
  1565 
       
  1566 // ---------------------------------------------------------------------------
       
  1567 // T_CLFApiModuleTests::SetCustomSorterTestL
       
  1568 // ---------------------------------------------------------------------------
       
  1569 //
       
  1570 void T_CLFApiModuleTests::SetCustomSorterTestL()
       
  1571     {
       
  1572     iTestSorter->iSortItems = EFalse;
       
  1573     iTestSorter1->iSortItems = EFalse;
       
  1574 
       
  1575     iListModel->SetCustomSorter( NULL );
       
  1576     iListModel->RefreshL( ECLFRefreshAll );
       
  1577     EUNIT_ASSERT( !iTestSorter->iSortItems );
       
  1578     EUNIT_ASSERT( !iTestSorter1->iSortItems );
       
  1579 
       
  1580     iTestSorter->iSortItems = EFalse;
       
  1581     iTestSorter1->iSortItems = EFalse;
       
  1582 
       
  1583     iListModel->SetCustomSorter( iTestSorter );
       
  1584     iListModel->RefreshL( ECLFRefreshAll );
       
  1585     EUNIT_ASSERT( iTestSorter->iSortItems );
       
  1586     EUNIT_ASSERT( !iTestSorter1->iSortItems );
       
  1587 
       
  1588     iTestSorter->iSortItems = EFalse;
       
  1589     iTestSorter1->iSortItems = EFalse;
       
  1590 
       
  1591     iListModel->SetCustomSorter( iTestSorter1 );
       
  1592     iListModel->RefreshL( ECLFRefreshAll );
       
  1593     EUNIT_ASSERT( !iTestSorter->iSortItems );
       
  1594     EUNIT_ASSERT( iTestSorter1->iSortItems );
       
  1595 
       
  1596     iTestSorter->iSortItems = EFalse;
       
  1597     iTestSorter1->iSortItems = EFalse;
       
  1598 
       
  1599     iListModel->SetCustomSorter( NULL );
       
  1600     iListModel->RefreshL( ECLFRefreshAll );
       
  1601     EUNIT_ASSERT( !iTestSorter->iSortItems );
       
  1602     EUNIT_ASSERT( !iTestSorter1->iSortItems );
       
  1603 
       
  1604     iTestSorter->iSortItems = EFalse;
       
  1605     iTestSorter1->iSortItems = EFalse;
       
  1606 
       
  1607     iListModel->SetCustomSorter( iTestSorter );
       
  1608     iListModel->RefreshL( ECLFRefreshAll );
       
  1609     EUNIT_ASSERT( iTestSorter->iSortItems );
       
  1610     EUNIT_ASSERT( !iTestSorter1->iSortItems );
       
  1611 
       
  1612     iTestSorter->iSortItems = EFalse;
       
  1613     iTestSorter1->iSortItems = EFalse;
       
  1614 
       
  1615     iListModel->SetCustomSorter( iTestSorter1 );
       
  1616     iListModel->RefreshL( ECLFRefreshAll );
       
  1617     EUNIT_ASSERT( !iTestSorter->iSortItems );
       
  1618     EUNIT_ASSERT( iTestSorter1->iSortItems );
       
  1619 
       
  1620 // parameter test
       
  1621     iTestSorter->iSortItems = EFalse;
       
  1622     iTestSorter1->iSortItems = EFalse;
       
  1623 
       
  1624     iListModel->SetCustomSorter( NULL );
       
  1625     iListModel->RefreshL( ECLFRefreshAll );
       
  1626     EUNIT_ASSERT( !iTestSorter->iSortItems );
       
  1627     EUNIT_ASSERT( !iTestSorter1->iSortItems );
       
  1628 
       
  1629 
       
  1630     iTestSorter->iSortItems = EFalse;
       
  1631     iTestSorter1->iSortItems = EFalse;
       
  1632 
       
  1633     iListModel->SetCustomSorter( iTestSorter );
       
  1634     iListModel->RefreshL( ECLFRefreshPostFilter );
       
  1635     EUNIT_ASSERT( !iTestSorter->iSortItems );
       
  1636     EUNIT_ASSERT( !iTestSorter1->iSortItems );
       
  1637 
       
  1638     iListModel->RefreshL( ECLFRefreshGrouping );
       
  1639     EUNIT_ASSERT( !iTestSorter->iSortItems );
       
  1640     EUNIT_ASSERT( !iTestSorter1->iSortItems );
       
  1641 
       
  1642     iListModel->RefreshL( ECLFRefreshSorting );
       
  1643     EUNIT_ASSERT( iTestSorter->iSortItems );
       
  1644     EUNIT_ASSERT( !iTestSorter1->iSortItems );
       
  1645 
       
  1646     }
       
  1647 
       
  1648 // ---------------------------------------------------------------------------
       
  1649 // T_CLFApiModuleTests::GroupingTestL
       
  1650 // ---------------------------------------------------------------------------
       
  1651 //
       
  1652 void T_CLFApiModuleTests::GroupingTestL()
       
  1653     {
       
  1654     iTestGrouper->iModifiableItems = &iModifiableItems;
       
  1655     iTestGrouper1->iModifiableItems = &iModifiableItems;
       
  1656 
       
  1657 // No grouping
       
  1658     iListModel->SetCustomGrouper( NULL );
       
  1659     iListModel->RefreshL( ECLFRefreshAll );
       
  1660     EUNIT_ASSERT( iListModel->ItemCount() == iItemCount );
       
  1661 
       
  1662 // couple groups
       
  1663     iListModel->SetCustomGrouper( iTestGrouper );
       
  1664     iListModel->RefreshL( ECLFRefreshAll );
       
  1665     EUNIT_ASSERT( iListModel->ItemCount() == iModifiableItems.Count() );
       
  1666 
       
  1667 // 0 groups
       
  1668     iTestGrouper1->iGroupCount = 0;
       
  1669     iListModel->SetCustomGrouper( iTestGrouper1 );
       
  1670     iListModel->RefreshL( ECLFRefreshAll );
       
  1671     EUNIT_ASSERT( iListModel->ItemCount() == iModifiableItems.Count() );
       
  1672 
       
  1673 // No grouping
       
  1674     iListModel->SetCustomGrouper( NULL );
       
  1675     iListModel->RefreshL( ECLFRefreshAll );
       
  1676     EUNIT_ASSERT( iListModel->ItemCount() == iItemCount );
       
  1677 // Music album grouping
       
  1678     iListModel->SetGroupingStyle( ECLFMusicAlbumGrouping );
       
  1679     iListModel->RefreshL( ECLFRefreshAll );
       
  1680     EUNIT_ASSERT( iListModel->ItemCount() != iItemCount );
       
  1681 // No grouping
       
  1682     iListModel->SetGroupingStyle( ECLFNoGrouping );
       
  1683     iListModel->RefreshL( ECLFRefreshAll );
       
  1684     EUNIT_ASSERT( iListModel->ItemCount() == iItemCount );
       
  1685 
       
  1686 // test parameters
       
  1687     iTestGrouper->iGroupCount = 1000;
       
  1688     iListModel->SetCustomGrouper( iTestGrouper );
       
  1689     iListModel->RefreshL( ECLFRefreshPostFilter );
       
  1690     EUNIT_ASSERT( iListModel->ItemCount() == iItemCount );
       
  1691     iListModel->RefreshL( ECLFRefreshSorting );
       
  1692     EUNIT_ASSERT( iListModel->ItemCount() == iItemCount );
       
  1693     iListModel->RefreshL( ECLFRefreshGrouping );
       
  1694     EUNIT_ASSERT( iListModel->ItemCount() == iModifiableItems.Count() );
       
  1695     }
       
  1696 
       
  1697 // ---------------------------------------------------------------------------
       
  1698 // T_CLFApiModuleTests::SetPostFilterTestL
       
  1699 // ---------------------------------------------------------------------------
       
  1700 //
       
  1701 void T_CLFApiModuleTests::SetPostFilterTestL()
       
  1702     {
       
  1703 // no filter
       
  1704     iListModel->SetPostFilter( NULL );
       
  1705     iListModel->RefreshL( ECLFRefreshAll );
       
  1706     EUNIT_ASSERT( iListModel->ItemCount() == iItemCount );
       
  1707 
       
  1708 // filter couple items
       
  1709     iListModel->SetPostFilter( iTestFilter );
       
  1710     iListModel->RefreshL( ECLFRefreshAll );
       
  1711     EUNIT_ASSERT( ( iListModel->ItemCount() + iTestFilter->iFilteredCount ) == iItemCount );
       
  1712 
       
  1713 // filter all items
       
  1714     iListModel->SetPostFilter( iTestFilter1 );
       
  1715     iTestFilter1->iAllFilter = ETrue;
       
  1716     iListModel->RefreshL( ECLFRefreshAll );
       
  1717     EUNIT_ASSERT( ( iListModel->ItemCount() + iTestFilter1->iFilteredCount ) == iItemCount );
       
  1718 
       
  1719 // no filter
       
  1720     iListModel->SetPostFilter( NULL );
       
  1721     iListModel->RefreshL( ECLFRefreshAll );
       
  1722     EUNIT_ASSERT( iListModel->ItemCount() == iItemCount );
       
  1723 
       
  1724 // filter one item
       
  1725     iListModel->SetPostFilter( iTestFilter );
       
  1726     iTestFilter->iShouldFilterCount = 1;
       
  1727     iListModel->RefreshL( ECLFRefreshAll );
       
  1728     EUNIT_ASSERT( ( iListModel->ItemCount() + iTestFilter->iFilteredCount ) == iItemCount );
       
  1729 
       
  1730 // filter couple items
       
  1731     iListModel->SetPostFilter( iTestFilter1 );
       
  1732     iTestFilter1->iAllFilter = EFalse;
       
  1733     iListModel->RefreshL( ECLFRefreshAll );
       
  1734     EUNIT_ASSERT( ( iListModel->ItemCount() + iTestFilter1->iFilteredCount ) == iItemCount );
       
  1735 
       
  1736 // test parameters
       
  1737     iListModel->SetPostFilter( NULL );
       
  1738     iListModel->RefreshL( ECLFRefreshAll );
       
  1739     EUNIT_ASSERT( iListModel->ItemCount() == iItemCount );
       
  1740     iListModel->SetPostFilter( iTestFilter1 );
       
  1741     iTestFilter1->iAllFilter = ETrue;
       
  1742     iListModel->RefreshL( ECLFRefreshSorting );
       
  1743     EUNIT_ASSERT( iListModel->ItemCount() == iItemCount );
       
  1744     iListModel->RefreshL( ECLFRefreshGrouping );
       
  1745     EUNIT_ASSERT( iListModel->ItemCount() == iItemCount );
       
  1746     iListModel->RefreshL( ECLFRefreshPostFilter );
       
  1747     EUNIT_ASSERT( ( iListModel->ItemCount() + iTestFilter1->iFilteredCount ) == iItemCount );
       
  1748     }
       
  1749 
       
  1750 // ---------------------------------------------------------------------------
       
  1751 // T_CLFApiModuleTests::SetWantedMimeTypesTestL
       
  1752 // ---------------------------------------------------------------------------
       
  1753 //
       
  1754 void T_CLFApiModuleTests::SetWantedMimeTypesTestL()
       
  1755     {
       
  1756     iTestObserver->iWait = &iWait;
       
  1757 
       
  1758 // list not defined (mimetype)
       
  1759     iListModel->RefreshL();
       
  1760     iWait.Start();
       
  1761     EUNIT_ASSERT( iListModel->ItemCount() == 0 );
       
  1762 
       
  1763 // couple mime types
       
  1764     iMimeTypeArray->Reset();
       
  1765     iMimeTypeArray->AppendL( _L( "audio/mpeg" ) );
       
  1766     iMimeTypeArray->AppendL( _L( "audio/aac" ) );
       
  1767     iMimeTypeArray->AppendL( _L( "audio/mp3" ) );
       
  1768     iMimeTypeArray->AppendL( _L( "audio/x-mp3" ) );
       
  1769     iMimeTypeArray->AppendL( _L( "audio/mp4" ) );
       
  1770     iMimeTypeArray->AppendL( _L( "audio/3gpp" ) );
       
  1771     iMimeTypeArray->AppendL( _L( "audio/m4a" ) );
       
  1772     iMimeTypeArray->AppendL( _L( "audio/3gpp2" ) );
       
  1773     iMimeTypeArray->AppendL( _L( "audio/mpeg4") );
       
  1774     iListModel->SetWantedMimeTypesL( *iMimeTypeArray );
       
  1775     iListModel->RefreshL();
       
  1776     iWait.Start();
       
  1777     EUNIT_ASSERT( CheckFileTypesL( *iMimeTypeArray, iMediaTypeArray.Array() ) );
       
  1778 
       
  1779 // unsupported mimetype
       
  1780     iMimeTypeArray1->Reset();
       
  1781     iMimeTypeArray1->AppendL( _L("ei tämmöstä ees pitäis olla")  );
       
  1782     iListModel->SetWantedMimeTypesL( *iMimeTypeArray1 );
       
  1783     iListModel->RefreshL();
       
  1784     iWait.Start();
       
  1785     EUNIT_ASSERT( iListModel->ItemCount() == 0 );
       
  1786 
       
  1787 // empty mimetype list
       
  1788     iMimeTypeArray1->Reset();
       
  1789     iListModel->SetWantedMimeTypesL( *iMimeTypeArray1 );
       
  1790     iListModel->RefreshL();
       
  1791     iWait.Start();
       
  1792     EUNIT_ASSERT( iListModel->ItemCount() == 0 );
       
  1793 
       
  1794 // from resource (mimetype)
       
  1795     iMimeTypeArray->Reset();
       
  1796     iMimeTypeArray->AppendL( _L("image/*")  );
       
  1797     iMimeTypeArray->AppendL( _L("audio/*")  );
       
  1798 
       
  1799     ResourceL( R_MIME_TYPE_ARRAY );
       
  1800     iListModel->SetWantedMimeTypesL( iResourceReader );
       
  1801     iListModel->RefreshL();
       
  1802     iWait.Start();
       
  1803     EUNIT_ASSERT( CheckFileTypesL( *iMimeTypeArray, iMediaTypeArray.Array() ) );
       
  1804 
       
  1805     ResourceL( R_MIME_TYPE_ARRAY_EMPTY );
       
  1806     iListModel->SetWantedMimeTypesL( iResourceReader );
       
  1807     iListModel->RefreshL();
       
  1808     iWait.Start();
       
  1809     EUNIT_ASSERT( iListModel->ItemCount() == 0 );
       
  1810 
       
  1811 // incorrect resource version
       
  1812     ResourceL( R_MIME_TYPE_ARRAY_INCORRECT_VERSION );
       
  1813     EUNIT_ASSERT_SPECIFIC_LEAVE( iListModel->SetWantedMimeTypesL( iResourceReader ), KErrNotSupported );
       
  1814     }
       
  1815 
       
  1816 // ---------------------------------------------------------------------------
       
  1817 // T_CLFApiModuleTests::SetWantedMediaTypesTestL
       
  1818 // ---------------------------------------------------------------------------
       
  1819 //
       
  1820 void T_CLFApiModuleTests::SetWantedMediaTypesTestL()
       
  1821     {
       
  1822     iTestObserver->iWait = &iWait;
       
  1823 
       
  1824 // list not defined (mediatype)
       
  1825     iListModel->RefreshL();
       
  1826     iWait.Start();
       
  1827     EUNIT_ASSERT( iListModel->ItemCount() == 0 );
       
  1828 
       
  1829 // couple media types
       
  1830     iMediaTypeArray.AppendL( ECLFMediaTypeVideo );
       
  1831     iMediaTypeArray.AppendL( ECLFMediaTypeImage );
       
  1832     iMediaTypeArray.AppendL( ECLFMediaTypeSound );
       
  1833     iMediaTypeArray.AppendL( ECLFMediaTypeMusic );
       
  1834     iMediaTypeArray.AppendL( ECLFMediaTypeStreamingURL );
       
  1835     iMediaTypeArray.AppendL( ECLFMediaTypePlaylist );
       
  1836     iMediaTypeArray.AppendL( TCLFMediaType( ECLFMediaTypeCollection ) );
       
  1837 
       
  1838     iListModel->SetWantedMediaTypesL( iMediaTypeArray.Array() );
       
  1839     iListModel->RefreshL();
       
  1840     iWait.Start();
       
  1841     EUNIT_ASSERT( CheckFileTypesL( *iMimeTypeArray, iMediaTypeArray.Array() ) );
       
  1842 
       
  1843 // empty media type list list
       
  1844     iListModel->SetWantedMediaTypesL( iMediaTypeArray1.Array() );
       
  1845     iListModel->RefreshL();
       
  1846     iWait.Start();
       
  1847     EUNIT_ASSERT( iListModel->ItemCount() == 0 );
       
  1848 
       
  1849 // media type list from resource
       
  1850     iMediaTypeArray.Reset();
       
  1851     iMediaTypeArray.AppendL( ECLFMediaTypeImage );
       
  1852     iMediaTypeArray.AppendL( TCLFMediaType( ECLFMediaTypeCollection ) );
       
  1853     ResourceL( R_MEDIA_TYPE_ARRAY );
       
  1854     iListModel->SetWantedMediaTypesL( iResourceReader );
       
  1855     iListModel->RefreshL();
       
  1856     iWait.Start();
       
  1857     EUNIT_ASSERT( CheckFileTypesL( *iMimeTypeArray, iMediaTypeArray.Array() ) );
       
  1858 
       
  1859 // empty media type list from resource
       
  1860     ResourceL( R_MEDIA_TYPE_ARRAY_EMPTY );
       
  1861     iListModel->SetWantedMediaTypesL( iResourceReader );
       
  1862     iListModel->RefreshL();
       
  1863     iWait.Start();
       
  1864     EUNIT_ASSERT( iListModel->ItemCount() == 0 );
       
  1865     }
       
  1866 
       
  1867 // ---------------------------------------------------------------------------
       
  1868 // T_CLFApiModuleTests::SetWantedMediaAndMimeTypesTestL
       
  1869 // ---------------------------------------------------------------------------
       
  1870 //
       
  1871 void T_CLFApiModuleTests::SetWantedMediaAndMimeTypesTestL()
       
  1872     {
       
  1873     iTestObserver->iWait = &iWait;
       
  1874 
       
  1875     iListModel->RefreshL();
       
  1876     iWait.Start();
       
  1877     EUNIT_ASSERT( iListModel->ItemCount() == 0 );
       
  1878 
       
  1879 // couple types
       
  1880     iMimeTypeArray->AppendL( _L( "audio/mpeg" ) );
       
  1881     iMimeTypeArray->AppendL( _L( "audio/aac" ) );
       
  1882     iMimeTypeArray->AppendL( _L( "audio/mp3" ) );
       
  1883     iMimeTypeArray->AppendL( _L( "audio/x-mp3" ) );
       
  1884     iMimeTypeArray->AppendL( _L( "audio/mp4" ) );
       
  1885     iMimeTypeArray->AppendL( _L( "audio/3gpp" ) );
       
  1886     iMimeTypeArray->AppendL( _L( "audio/m4a" ) );
       
  1887     iMimeTypeArray->AppendL( _L( "audio/3gpp2" ) );
       
  1888     iMimeTypeArray->AppendL( _L( "audio/mpeg4") );
       
  1889     iListModel->SetWantedMimeTypesL( *iMimeTypeArray );
       
  1890 
       
  1891     iMediaTypeArray.AppendL( ECLFMediaTypeVideo );
       
  1892     iListModel->SetWantedMediaTypesL( iMediaTypeArray.Array() );
       
  1893     iListModel->RefreshL();
       
  1894     iWait.Start();
       
  1895     EUNIT_ASSERT( CheckFileTypesL( *iMimeTypeArray, iMediaTypeArray.Array() ) );
       
  1896 
       
  1897 // refresh again
       
  1898     iListModel->RefreshL();
       
  1899     iWait.Start();
       
  1900     EUNIT_ASSERT( CheckFileTypesL( *iMimeTypeArray, iMediaTypeArray.Array() ) );
       
  1901 
       
  1902 // empty lists
       
  1903     iMediaTypeArray.Reset();
       
  1904     iMimeTypeArray->Reset();
       
  1905     iListModel->SetWantedMediaTypesL( iMediaTypeArray.Array() );
       
  1906     iListModel->SetWantedMimeTypesL( *iMimeTypeArray );
       
  1907     iListModel->RefreshL();
       
  1908     iWait.Start();
       
  1909     EUNIT_ASSERT( iListModel->ItemCount() == 0 );
       
  1910     }
       
  1911 
       
  1912 // ---------------------------------------------------------------------------
       
  1913 // T_CLFApiModuleTests::MultibleSortingTestL
       
  1914 // ---------------------------------------------------------------------------
       
  1915 //
       
  1916 void T_CLFApiModuleTests::MultibleSortingTestL()
       
  1917     {
       
  1918 
       
  1919     iListModel->RefreshL( ECLFRefreshAll );
       
  1920     EUNIT_ASSERT( CheckMultibleSortingShortingL() );
       
  1921 
       
  1922 // resort
       
  1923 
       
  1924     iSortingStyle->ResetL();
       
  1925     iSortingStyle->SetSortingDataType( ECLFItemDataTypeTInt32 );
       
  1926     iSortingStyle->AddFieldL( KMultibleSortingTestField6 );
       
  1927     iSortingStyle->AddFieldL( KMultibleSortingTestField5 );
       
  1928     iSortingStyle->SetUndefinedItemPosition( ECLFSortingStyleUndefinedEnd );
       
  1929     iListModel->SetSortingStyle( iSortingStyle );
       
  1930     iListModel->RefreshL( ECLFRefreshAll );
       
  1931     EUNIT_ASSERT( CheckMultibleSortingShorting2L() );
       
  1932 
       
  1933     }
       
  1934 
       
  1935 /*
       
  1936 * Test model item(s) obsolate functionality
       
  1937 */
       
  1938 
       
  1939 // ---------------------------------------------------------------------------
       
  1940 // ModelItemsChangedTestL
       
  1941 // ---------------------------------------------------------------------------
       
  1942 //
       
  1943 void T_CLFApiModuleTests::ModelItemsChangedTestL()
       
  1944     {
       
  1945     const TInt newFileNumber( 10 );
       
  1946 
       
  1947 // create test files
       
  1948     CreateNewFileL( 0, iFileName );
       
  1949     CreateNewFileL( 1, iFileName );
       
  1950     CreateNewFileL( 2, iFileName );
       
  1951     CreateNewFileL( newFileNumber, iFileName );
       
  1952     User::LeaveIfError( iFs.Delete( iFileName ) );
       
  1953 
       
  1954 // update server
       
  1955 // to avoid incorrect test result
       
  1956     CreateNewFileL( 0, iFileName );
       
  1957     iEngine->UpdateItemsL();
       
  1958 
       
  1959 // create list model with all files
       
  1960     iMimeTypeArray->Reset();
       
  1961     iMimeTypeArray->AppendL( _L("*") );
       
  1962     iListModel->SetWantedMimeTypesL( *iMimeTypeArray );
       
  1963 
       
  1964     iTestObserver->iWait = &iWait;
       
  1965     iTestObserver->iError = 100;
       
  1966     iListModel->RefreshL();
       
  1967     iWait.Start();  // wait until model is refreshed
       
  1968     EUNIT_ASSERT( iTestObserver->iOperationEvent == ECLFRefreshComplete );
       
  1969     EUNIT_ASSERT( iTestObserver->iError == KErrNone );
       
  1970     EUNIT_ASSERT( iListModel->ItemCount() > 0 );
       
  1971 
       
  1972     const TInt listModelItemCount( iListModel->ItemCount() );
       
  1973     const TCLFItemId testId( FindTestFileIdL( 0 ) );
       
  1974 
       
  1975 // test with modified item
       
  1976     CreateNewFileL( 0, iFileName );
       
  1977     iEngine->UpdateItemsL();
       
  1978     iWait.Start(); // wait until model outdated event is received
       
  1979 
       
  1980     EUNIT_ASSERT( iTestObserver->iOperationEvent == ECLFModelOutdated );
       
  1981     EUNIT_ASSERT( iTestObserver->iError == KErrNone );
       
  1982     EUNIT_ASSERT( iListModel->ItemCount() == listModelItemCount );
       
  1983     EUNIT_ASSERT( NULL != FindItem( *iListModel, testId ) );
       
  1984 
       
  1985     iTestObserver->iError = 100;
       
  1986     iListModel->RefreshL();
       
  1987     iWait.Start();  // wait until model is refreshed
       
  1988     EUNIT_ASSERT( iTestObserver->iOperationEvent == ECLFRefreshComplete );
       
  1989     EUNIT_ASSERT( iTestObserver->iError == KErrNone );
       
  1990     EUNIT_ASSERT( iListModel->ItemCount() == listModelItemCount );
       
  1991     EUNIT_ASSERT( NULL != FindItem( *iListModel, testId ) );
       
  1992 
       
  1993 // test with new item
       
  1994     CreateNewFileL( newFileNumber, iFileName );
       
  1995     iEngine->UpdateItemsL();
       
  1996     iWait.Start(); // wait until model outdated event is received
       
  1997 
       
  1998     EUNIT_ASSERT( iTestObserver->iOperationEvent == ECLFModelOutdated );
       
  1999     EUNIT_ASSERT( iTestObserver->iError == KErrNone );
       
  2000     EUNIT_ASSERT( iListModel->ItemCount() == listModelItemCount );
       
  2001 
       
  2002     iTestObserver->iError = 100;
       
  2003     iListModel->RefreshL();
       
  2004     iWait.Start();  // wait until model is refreshed
       
  2005     EUNIT_ASSERT( iTestObserver->iOperationEvent == ECLFRefreshComplete );
       
  2006     EUNIT_ASSERT( iTestObserver->iError == KErrNone );
       
  2007     EUNIT_ASSERT( iListModel->ItemCount() == listModelItemCount + 1 );
       
  2008 
       
  2009 // delete file
       
  2010     User::LeaveIfError( iFs.Delete( iFileName ) );
       
  2011     iEngine->UpdateItemsL();
       
  2012     iWait.Start(); // wait until model outdated event is received
       
  2013 
       
  2014     EUNIT_ASSERT( iTestObserver->iOperationEvent == ECLFModelOutdated );
       
  2015     EUNIT_ASSERT( iTestObserver->iError == KErrNone );
       
  2016     EUNIT_ASSERT( iListModel->ItemCount() == listModelItemCount + 1 );
       
  2017 
       
  2018     iTestObserver->iError = 100;
       
  2019     iListModel->RefreshL();
       
  2020     iWait.Start();  // wait until model is refreshed
       
  2021     EUNIT_ASSERT( iTestObserver->iOperationEvent == ECLFRefreshComplete );
       
  2022     EUNIT_ASSERT( iTestObserver->iError == KErrNone );
       
  2023     EUNIT_ASSERT( iListModel->ItemCount() == listModelItemCount );
       
  2024     }
       
  2025 
       
  2026 /**
       
  2027  * Tests, Modifiable item
       
  2028  */
       
  2029 
       
  2030 // ---------------------------------------------------------------------------
       
  2031 // T_CLFApiModuleTests::MIFieldTestL
       
  2032 // ---------------------------------------------------------------------------
       
  2033 // 
       
  2034 void T_CLFApiModuleTests::MIFieldTestL()
       
  2035     {
       
  2036     const TUint KTestField1 = 1;
       
  2037     const TUint KTestField2 = 112312312;
       
  2038     const TUint KTestField3 = 13333;
       
  2039     const TUint KTestFieldIncorrect = 2;
       
  2040 
       
  2041     TTime time( 100 );
       
  2042     TInt32 integer( 12 );
       
  2043     TBuf<30> data( _L("data") );
       
  2044     iModifiableItem->AddFieldL( KTestField1, time );
       
  2045     iModifiableItem->AddFieldL( KTestField2, integer );
       
  2046     iModifiableItem->AddFieldL( KTestField3, data );
       
  2047 
       
  2048 // data type test
       
  2049     EUNIT_ASSERT( iModifiableItem->DataType(
       
  2050                                 KTestField1 ) == ECLFItemDataTypeTTime );
       
  2051     EUNIT_ASSERT( iModifiableItem->DataType(
       
  2052                                 KTestField2 ) == ECLFItemDataTypeTInt32 );
       
  2053     EUNIT_ASSERT( iModifiableItem->DataType(
       
  2054                                 KTestField3 ) == ECLFItemDataTypeDesC );
       
  2055     EUNIT_ASSERT( iModifiableItem->DataType(
       
  2056                                 KTestFieldIncorrect ) == ECLFItemDataTypeNull );
       
  2057     EUNIT_ASSERT( iModifiableItem->DataType(
       
  2058                                 ECLFFieldIdNull ) == ECLFItemDataTypeNull );
       
  2059 
       
  2060 // get field
       
  2061     TTime time1( 0 );
       
  2062     TInt32 integer1( 0 );
       
  2063     TPtrC ptr;
       
  2064     EUNIT_ASSERT( KErrNone == iModifiableItem->GetField(
       
  2065                                                 KTestField1, time1 ) );
       
  2066     EUNIT_ASSERT( time == time1 );
       
  2067     EUNIT_ASSERT( KErrNone == iModifiableItem->GetField(
       
  2068                                                 KTestField2, integer1 ) );
       
  2069     EUNIT_ASSERT( integer == integer1 );
       
  2070     EUNIT_ASSERT( KErrNone == iModifiableItem->GetField(
       
  2071                                                 KTestField3, ptr ) );
       
  2072     EUNIT_ASSERT( data == ptr );
       
  2073 
       
  2074 // incorrect field id
       
  2075     EUNIT_ASSERT( KErrNotFound == iModifiableItem->GetField(
       
  2076                                                 KTestFieldIncorrect, ptr ) );
       
  2077     EUNIT_ASSERT( KErrNotFound == iModifiableItem->GetField(
       
  2078                                                 KTestFieldIncorrect, integer1 ) );
       
  2079     EUNIT_ASSERT( KErrNotFound == iModifiableItem->GetField(
       
  2080                                                 KTestFieldIncorrect, time1 ) );
       
  2081 
       
  2082 // incorrect field type
       
  2083     EUNIT_ASSERT( KErrNotSupported == iModifiableItem->GetField(
       
  2084                                                 KTestField1, ptr ) );
       
  2085     EUNIT_ASSERT( KErrNotSupported == iModifiableItem->GetField(
       
  2086                                                 KTestField3, integer1 ) );
       
  2087     EUNIT_ASSERT( KErrNotSupported == iModifiableItem->GetField(
       
  2088                                                 KTestField2, time1 ) );
       
  2089 
       
  2090 
       
  2091     EUNIT_ASSERT( iModifiableItem->ItemId() == 0 );
       
  2092     }
       
  2093 
       
  2094 /**
       
  2095  * Tests, item
       
  2096  */
       
  2097 
       
  2098 // ---------------------------------------------------------------------------
       
  2099 // T_CLFApiModuleTests::ItemFieldTestL
       
  2100 // ---------------------------------------------------------------------------
       
  2101 // 
       
  2102 void T_CLFApiModuleTests::ItemFieldTestL()
       
  2103     {
       
  2104 // data type test
       
  2105     EUNIT_ASSERT( iItem->DataType(
       
  2106                                 ECLFFieldIdFileDate ) == ECLFItemDataTypeTTime );
       
  2107     EUNIT_ASSERT( iItem->DataType(
       
  2108                                 ECLFFieldIdFileSize ) == ECLFItemDataTypeTInt32 );
       
  2109     EUNIT_ASSERT( iItem->DataType(
       
  2110                                 ECLFFieldIdFileNameAndPath ) == ECLFItemDataTypeDesC );
       
  2111     EUNIT_ASSERT( iItem->DataType(
       
  2112                                 ECLFFieldIdNull ) == ECLFItemDataTypeNull );
       
  2113 
       
  2114 // get field
       
  2115     TTime time1( 0 );
       
  2116     TInt32 integer1( 0 );
       
  2117     TPtrC ptr;
       
  2118     TEntry entry;
       
  2119     User::LeaveIfError( iFs.Entry( iFileName, entry ) );
       
  2120 
       
  2121     EUNIT_ASSERT( KErrNone == iItem->GetField( ECLFFieldIdFileDate, time1 ) );
       
  2122     EUNIT_ASSERT( entry.iModified == time1 );
       
  2123     EUNIT_ASSERT( KErrNone == iItem->GetField( ECLFFieldIdFileSize, integer1 ) );
       
  2124     EUNIT_ASSERT( entry.iSize == integer1 );
       
  2125     EUNIT_ASSERT( KErrNone == iItem->GetField( ECLFFieldIdFileNameAndPath, ptr ) );
       
  2126     EUNIT_ASSERT( iFileName == ptr );
       
  2127 
       
  2128     TParsePtrC parse( iFileName );
       
  2129 
       
  2130     EUNIT_ASSERT( KErrNone == iItem->GetField( ECLFFieldIdFileExtension, ptr ) );
       
  2131     EUNIT_ASSERT( parse.Ext() == ptr );
       
  2132 
       
  2133     EUNIT_ASSERT( KErrNone == iItem->GetField( ECLFFieldIdFileName, ptr ) );
       
  2134     EUNIT_ASSERT( parse.Name() == ptr );
       
  2135 
       
  2136     EUNIT_ASSERT( KErrNone == iItem->GetField( ECLFFieldIdPath, ptr ) );
       
  2137     EUNIT_ASSERT( parse.Path() == ptr );
       
  2138 
       
  2139     EUNIT_ASSERT( KErrNone == iItem->GetField( ECLFFieldIdDrive, ptr ) );
       
  2140     EUNIT_ASSERT( parse.Drive() == ptr );
       
  2141 
       
  2142 
       
  2143 // incorrect field id
       
  2144     EUNIT_ASSERT( KErrNotFound == iItem->GetField(
       
  2145                                                 ECLFFieldIdNull, ptr ) );
       
  2146     EUNIT_ASSERT( KErrNotFound == iItem->GetField(
       
  2147                                                 ECLFFieldIdNull, integer1 ) );
       
  2148     EUNIT_ASSERT( KErrNotFound == iItem->GetField(
       
  2149                                                 ECLFFieldIdNull, time1 ) );
       
  2150 
       
  2151 // incorrect field type
       
  2152     EUNIT_ASSERT( KErrNotSupported == iItem->GetField(
       
  2153                                                 ECLFFieldIdFileSize, ptr ) );
       
  2154     EUNIT_ASSERT( KErrNotSupported == iItem->GetField(
       
  2155                                                 ECLFFieldIdFileDate, integer1 ) );
       
  2156     EUNIT_ASSERT( KErrNotSupported == iItem->GetField(
       
  2157                                                 ECLFFieldIdFileNameAndPath, time1 ) );
       
  2158 
       
  2159 
       
  2160     EUNIT_ASSERT( iItem->ItemId() != 0 );
       
  2161     }
       
  2162 
       
  2163 /**
       
  2164  * Tests, Sorting style
       
  2165  */
       
  2166 
       
  2167 // ---------------------------------------------------------------------------
       
  2168 // T_CLFApiModuleTests::SortingStyleResourceTestL
       
  2169 // ---------------------------------------------------------------------------
       
  2170 //  
       
  2171 void T_CLFApiModuleTests::SortingStyleResourceTestL()
       
  2172     {
       
  2173     const TInt KArray1IdCount( 4 );
       
  2174     const TInt KArray2IdCount( 1 );
       
  2175 
       
  2176 
       
  2177     RArray<TCLFItemId> itemIdArray;
       
  2178     CleanupClosePushL( itemIdArray );
       
  2179 
       
  2180     EUNIT_ASSERT( iSortingStyle->Ordering() == ECLFOrderingAscending );
       
  2181     EUNIT_ASSERT( iSortingStyle1->Ordering() == ECLFOrderingDescending );
       
  2182     EUNIT_ASSERT( iSortingStyle2->Ordering() == ECLFOrderingDescending );
       
  2183     EUNIT_ASSERT( iSortingStyle->SortingDataType() == ECLFItemDataTypeTInt32 );
       
  2184     EUNIT_ASSERT( iSortingStyle1->SortingDataType() == ECLFItemDataTypeDesC );
       
  2185     EUNIT_ASSERT( iSortingStyle2->SortingDataType() == ECLFItemDataTypeDesC );
       
  2186 
       
  2187     iSortingStyle->GetFieldsL( itemIdArray );
       
  2188 
       
  2189     EUNIT_ASSERT( itemIdArray.Count() == 0 );
       
  2190 
       
  2191     itemIdArray.Reset();
       
  2192     iSortingStyle1->GetFieldsL( itemIdArray );
       
  2193 
       
  2194     EUNIT_ASSERT( itemIdArray.Count() == KArray1IdCount );
       
  2195 
       
  2196     itemIdArray.Reset();
       
  2197     iSortingStyle2->GetFieldsL( itemIdArray );
       
  2198 
       
  2199     EUNIT_ASSERT( itemIdArray.Count() == KArray2IdCount );
       
  2200 
       
  2201     CleanupStack::PopAndDestroy( &itemIdArray ); // itemIdArray.Close
       
  2202     }
       
  2203 
       
  2204 // ---------------------------------------------------------------------------
       
  2205 // T_CLFApiModuleTests::SortingStyleOrderingTestL
       
  2206 // ---------------------------------------------------------------------------
       
  2207 // 
       
  2208 void T_CLFApiModuleTests::SortingStyleOrderingTestL()
       
  2209     {
       
  2210     iSortingStyle->SetOrdering( ECLFOrderingAscending );
       
  2211     EUNIT_ASSERT( iSortingStyle->Ordering() == ECLFOrderingAscending );
       
  2212     iSortingStyle->SetOrdering( ECLFOrderingDescending );
       
  2213     EUNIT_ASSERT( iSortingStyle->Ordering() == ECLFOrderingDescending );
       
  2214     iSortingStyle->SetOrdering( ECLFOrderingAscending );
       
  2215     EUNIT_ASSERT( iSortingStyle->Ordering() == ECLFOrderingAscending );
       
  2216     }
       
  2217 
       
  2218 // ---------------------------------------------------------------------------
       
  2219 // T_CLFApiModuleTests::SortingStyleDataTypeTestL
       
  2220 // ---------------------------------------------------------------------------
       
  2221 // 
       
  2222 void T_CLFApiModuleTests::SortingStyleDataTypeTestL()
       
  2223     {
       
  2224     iSortingStyle->SetSortingDataType( ECLFItemDataTypeTInt32 );
       
  2225     EUNIT_ASSERT( iSortingStyle->SortingDataType() == ECLFItemDataTypeTInt32 );
       
  2226     iSortingStyle->SetSortingDataType( ECLFItemDataTypeDesC );
       
  2227     EUNIT_ASSERT( iSortingStyle->SortingDataType() == ECLFItemDataTypeDesC );
       
  2228     iSortingStyle->SetSortingDataType( ECLFItemDataTypeTTime );
       
  2229     EUNIT_ASSERT( iSortingStyle->SortingDataType() == ECLFItemDataTypeTTime );
       
  2230     iSortingStyle->SetSortingDataType( ECLFItemDataTypeNull );
       
  2231     EUNIT_ASSERT( iSortingStyle->SortingDataType() == ECLFItemDataTypeNull );
       
  2232     iSortingStyle->SetSortingDataType( ECLFItemDataTypeTInt32 );
       
  2233     EUNIT_ASSERT( iSortingStyle->SortingDataType() == ECLFItemDataTypeTInt32 );
       
  2234     }
       
  2235 
       
  2236 // ---------------------------------------------------------------------------
       
  2237 // T_CLFApiModuleTests::SortingStyleUndefinedItemPositionTestL
       
  2238 // ---------------------------------------------------------------------------
       
  2239 // 
       
  2240 void T_CLFApiModuleTests::SortingStyleUndefinedItemPositionTestL()
       
  2241     {
       
  2242     iSortingStyle->SetUndefinedItemPosition( ECLFSortingStyleUndefinedEnd );
       
  2243     EUNIT_ASSERT( iSortingStyle->UndefinedItemPosition() == ECLFSortingStyleUndefinedEnd );
       
  2244     iSortingStyle->SetUndefinedItemPosition( ECLFSortingStyleUndefinedFirst );
       
  2245     EUNIT_ASSERT( iSortingStyle->UndefinedItemPosition() == ECLFSortingStyleUndefinedFirst );
       
  2246     iSortingStyle->SetUndefinedItemPosition( ECLFSortingStyleUndefinedEnd );
       
  2247     EUNIT_ASSERT( iSortingStyle->UndefinedItemPosition() == ECLFSortingStyleUndefinedEnd );
       
  2248     }
       
  2249 
       
  2250 // ---------------------------------------------------------------------------
       
  2251 // T_CLFApiModuleTests::SortingStyleFieldTestL
       
  2252 // ---------------------------------------------------------------------------
       
  2253 // 
       
  2254 void T_CLFApiModuleTests::SortingStyleFieldTestL()
       
  2255     {
       
  2256     RArray<TCLFItemId> itemIdArray;
       
  2257     CleanupClosePushL( itemIdArray );
       
  2258 
       
  2259     iSortingStyle->GetFieldsL( itemIdArray );
       
  2260     EUNIT_ASSERT( itemIdArray.Count() == 0 );
       
  2261 
       
  2262     iSortingStyle->AddFieldL( ECLFFieldIdFileName );
       
  2263     iSortingStyle->AddFieldL( ECLFFieldIdCollectionId );
       
  2264     iSortingStyle->AddFieldL( ECLFFieldIdCollectionName );
       
  2265     iSortingStyle->AddFieldL( ECLFFieldIdArtist );
       
  2266 
       
  2267     iSortingStyle->GetFieldsL( itemIdArray );
       
  2268 
       
  2269     EUNIT_ASSERT( itemIdArray.Count() == 4 );
       
  2270 
       
  2271     itemIdArray.Reset();
       
  2272     iSortingStyle->ResetL();
       
  2273     iSortingStyle->GetFieldsL( itemIdArray );
       
  2274     EUNIT_ASSERT( itemIdArray.Count() == 0 );
       
  2275 
       
  2276     CleanupStack::PopAndDestroy( &itemIdArray ); // itemIdArray.Close
       
  2277     }
       
  2278 
       
  2279 // ---------------------------------------------------------------------------
       
  2280 // Test case table for this test suite class
       
  2281 // ---------------------------------------------------------------------------
       
  2282 // 
       
  2283 
       
  2284 EUNIT_BEGIN_TEST_TABLE( T_CLFApiModuleTests, "T_CLFApiModuleTests", "MODULE" )
       
  2285 
       
  2286 // Constructor tests
       
  2287     EUNIT_TEST( "Create engine",
       
  2288                 "",
       
  2289                 "",
       
  2290                 "FUNCTIONALITY",
       
  2291                 BaseSetupL,
       
  2292                 CreateEngineTestL,
       
  2293                 Teardown )
       
  2294 
       
  2295     EUNIT_TEST( "Create modifiable item",
       
  2296                 "",
       
  2297                 "",
       
  2298                 "FUNCTIONALITY",
       
  2299                 BaseSetupL,
       
  2300                 CreateModifiableItemTestL,
       
  2301                 Teardown )
       
  2302 
       
  2303     EUNIT_TEST( "Create sorting style",
       
  2304                 "",
       
  2305                 "",
       
  2306                 "FUNCTIONALITY",
       
  2307                 BaseSetupL,
       
  2308                 CreateSortignStyleTestL,
       
  2309                 Teardown )
       
  2310 
       
  2311     EUNIT_TEST( "Create sorting style from resource",
       
  2312                 "",
       
  2313                 "",
       
  2314                 "FUNCTIONALITY",
       
  2315                 SortingStyleResourceSetupL,
       
  2316                 CreateSortignStyleFromResourceTestL,
       
  2317                 Teardown )
       
  2318 
       
  2319     EUNIT_TEST( "Create list model",
       
  2320                 "",
       
  2321                 "",
       
  2322                 "FUNCTIONALITY",
       
  2323                 CreateModelSetupL,
       
  2324                 CreateListModelTestL,
       
  2325                 Teardown )
       
  2326 
       
  2327     EUNIT_TEST( "Create list model from resource",
       
  2328                 "",
       
  2329                 "",
       
  2330                 "FUNCTIONALITY",
       
  2331                 CreateModelFromResourceSetupL,
       
  2332                 CreateListModelFromResourceTestL,
       
  2333                 Teardown )
       
  2334 
       
  2335 // Engine tests
       
  2336 
       
  2337     EUNIT_TEST( "Engine update test",
       
  2338                 "",
       
  2339                 "",
       
  2340                 "FUNCTIONALITY",
       
  2341                 EngineTestSetupL,
       
  2342                 UpdateItemsTestL,
       
  2343                 Teardown )
       
  2344 
       
  2345     EUNIT_TEST( "Engine update test",
       
  2346                 "",
       
  2347                 "",
       
  2348                 "FUNCTIONALITY",
       
  2349                 EngineTestSetupL,
       
  2350                 UpdateItemsWithIdTestL,
       
  2351                 Teardown )
       
  2352 
       
  2353     EUNIT_TEST( "Engine update test",
       
  2354                 "",
       
  2355                 "",
       
  2356                 "FUNCTIONALITY",
       
  2357                 EngineTestSetupL,
       
  2358                 UpdateItemsWithOpaqueDataFolderTestL,
       
  2359                 Teardown )
       
  2360 
       
  2361 // Sorting Style tests
       
  2362     EUNIT_TEST( "Sorting style from resource",
       
  2363                 "",
       
  2364                 "",
       
  2365                 "FUNCTIONALITY",
       
  2366                 SortingStyleResourceTestSetupL,
       
  2367                 SortingStyleResourceTestL,
       
  2368                 Teardown )
       
  2369 
       
  2370     EUNIT_TEST( "Sorting style ordering test",
       
  2371                 "",
       
  2372                 "",
       
  2373                 "FUNCTIONALITY",
       
  2374                 SortingStyleTestSetupL,
       
  2375                 SortingStyleOrderingTestL,
       
  2376                 Teardown )
       
  2377 
       
  2378     EUNIT_TEST( "Sorting style data type test",
       
  2379                 "",
       
  2380                 "",
       
  2381                 "FUNCTIONALITY",
       
  2382                 SortingStyleTestSetupL,
       
  2383                 SortingStyleDataTypeTestL,
       
  2384                 Teardown )
       
  2385 
       
  2386     EUNIT_TEST( "Sorting style undefined item position test",
       
  2387                 "",
       
  2388                 "",
       
  2389                 "FUNCTIONALITY",
       
  2390                 SortingStyleTestSetupL,
       
  2391                 SortingStyleUndefinedItemPositionTestL,
       
  2392                 Teardown )
       
  2393 
       
  2394     EUNIT_TEST( "Sorting style field test",
       
  2395                 "",
       
  2396                 "",
       
  2397                 "FUNCTIONALITY",
       
  2398                 SortingStyleTestSetupL,
       
  2399                 SortingStyleFieldTestL,
       
  2400                 Teardown )
       
  2401 
       
  2402 // List model tests
       
  2403     EUNIT_TEST( "List model refresh test",
       
  2404                 "",
       
  2405                 "",
       
  2406                 "FUNCTIONALITY",
       
  2407                 ListModelSetupL,
       
  2408                 RefreshTestL,
       
  2409                 Teardown )
       
  2410 
       
  2411     EUNIT_TEST( "List model sorting style test",
       
  2412                 "",
       
  2413                 "",
       
  2414                 "FUNCTIONALITY",
       
  2415                 ListModelAllFileItemsSetupL,
       
  2416                 SetSortingStyleTestL,
       
  2417                 Teardown )
       
  2418 
       
  2419     EUNIT_TEST( "List model custom sorter test",
       
  2420                 "",
       
  2421                 "",
       
  2422                 "FUNCTIONALITY",
       
  2423                 ListModelAllFileItemsSetupL,
       
  2424                 SetCustomSorterTestL,
       
  2425                 Teardown )
       
  2426 
       
  2427     EUNIT_TEST( "List model grouping test",
       
  2428                 "",
       
  2429                 "",
       
  2430                 "FUNCTIONALITY",
       
  2431                 ListModelAllFileItemsSetupL,
       
  2432                 GroupingTestL,
       
  2433                 Teardown )
       
  2434 
       
  2435     EUNIT_TEST( "List model post filter test",
       
  2436                 "",
       
  2437                 "",
       
  2438                 "FUNCTIONALITY",
       
  2439                 ListModelAllFileItemsSetupL,
       
  2440                 SetPostFilterTestL,
       
  2441                 Teardown )
       
  2442 
       
  2443     EUNIT_TEST( "List model wanted mime types test",
       
  2444                 "",
       
  2445                 "",
       
  2446                 "FUNCTIONALITY",
       
  2447                 ListModelSetupL,
       
  2448                 SetWantedMimeTypesTestL,
       
  2449                 Teardown )
       
  2450 
       
  2451     EUNIT_TEST( "List model wanted media types test",
       
  2452                 "",
       
  2453                 "",
       
  2454                 "FUNCTIONALITY",
       
  2455                 ListModelSetupL,
       
  2456                 SetWantedMediaTypesTestL,
       
  2457                 Teardown )
       
  2458 
       
  2459     EUNIT_TEST( "List model wanted media and mime types",
       
  2460                 "",
       
  2461                 "",
       
  2462                 "FUNCTIONALITY",
       
  2463                 ListModelSetupL,
       
  2464                 SetWantedMediaAndMimeTypesTestL,
       
  2465                 Teardown )
       
  2466 
       
  2467     EUNIT_TEST( "List model multible sorters",
       
  2468                 "",
       
  2469                 "",
       
  2470                 "FUNCTIONALITY",
       
  2471                 MultibleSortingSetupL,
       
  2472                 MultibleSortingTestL,
       
  2473                 Teardown )
       
  2474 
       
  2475     EUNIT_TEST( "List model multible sorters",
       
  2476                 "",
       
  2477                 "",
       
  2478                 "FUNCTIONALITY",
       
  2479                 MultibleSortingResourceSetupL,
       
  2480                 MultibleSortingTestL,
       
  2481                 Teardown )
       
  2482 
       
  2483     EUNIT_TEST( "List model changed items",
       
  2484                 "",
       
  2485                 "",
       
  2486                 "FUNCTIONALITY",
       
  2487                 ListModelSetupL,
       
  2488                 ModelItemsChangedTestL,
       
  2489                 Teardown )
       
  2490 
       
  2491 
       
  2492 // Modifiable item tests
       
  2493     EUNIT_TEST( "Modifiable item test",
       
  2494                 "",
       
  2495                 "",
       
  2496                 "FUNCTIONALITY",
       
  2497                 ModifiableItemTestSetupL,
       
  2498                 MIFieldTestL,
       
  2499                 Teardown )
       
  2500 
       
  2501 // Item tests
       
  2502     EUNIT_TEST( "Item test",
       
  2503                 "",
       
  2504                 "",
       
  2505                 "FUNCTIONALITY",
       
  2506                 ItemTestSetupL,
       
  2507                 ItemFieldTestL,
       
  2508                 Teardown )
       
  2509 
       
  2510 
       
  2511 EUNIT_END_TEST_TABLE
       
  2512 
       
  2513 //  End of File