idlehomescreen/widgetmanager/tsrc/wmunittest/src/wmunittest_sortorder.cpp
branchRCL_3
changeset 15 ff572dfe6d86
parent 2 08c6ee43b396
equal deleted inserted replaced
9:f966699dea19 15:ff572dfe6d86
    24 #include <aknsskininstance.h>
    24 #include <aknsskininstance.h>
    25 #include "wmunittest.h"
    25 #include "wmunittest.h"
    26 // components to test
    26 // components to test
    27 #include "wmpersistentwidgetorder.h"
    27 #include "wmpersistentwidgetorder.h"
    28 #include "wmwidgetdata.h"
    28 #include "wmwidgetdata.h"
       
    29 #include "wmwidgetorderdata.h"
    29 #include <hscontentinfo.h>
    30 #include <hscontentinfo.h>
    30 #include <hscontentinfoarray.h>
    31 #include <hscontentinfoarray.h>
    31 #include <widgetregistryclient.h> // widgetreqistry
    32 #include <widgetregistryclient.h> // widgetreqistry
    32 
    33 
    33 // ============================ MEMBER FUNCTIONS ===============================
    34 // ============================ MEMBER FUNCTIONS ===============================
    83     {
    84     {
    84     if ( iWmWidgetOrder == 0 ) User::Leave( KErrArgument );
    85     if ( iWmWidgetOrder == 0 ) User::Leave( KErrArgument );
    85     TInt ret = KErrNone;
    86     TInt ret = KErrNone;
    86 
    87 
    87     _CLEANUPCHECK_BEGIN
    88     _CLEANUPCHECK_BEGIN
    88     RWidgetDataValues array;
    89     ROrderArray array;
    89     CleanupClosePushL( array );
    90     CleanupClosePushL( array );
    90     CreateWidgetDataArrayL( array, iMass );
    91     CreateWidgetDataArrayL( array, iMass );
    91     iWmWidgetOrder->StoreL( array );
    92     iWmWidgetOrder->StoreL( array );
    92     array.ResetAndDestroy();
    93     array.ResetAndDestroy();
    93     CleanupStack::Pop( &array );
    94     CleanupStack::Pop( &array );
   124     if ( iWmWidgetOrder == 0 ) User::Leave( KErrArgument );
   125     if ( iWmWidgetOrder == 0 ) User::Leave( KErrArgument );
   125     TInt ret = KErrNone;
   126     TInt ret = KErrNone;
   126 
   127 
   127     _CLEANUPCHECK_BEGIN
   128     _CLEANUPCHECK_BEGIN
   128     // test IndexOf
   129     // test IndexOf
   129     RWidgetDataValues array;
   130     ROrderArray array;
   130     CreateWidgetDataArrayL( array, iMass );
   131     CreateWidgetDataArrayL( array, iMass );
   131     for( TInt i=0; i<array.Count() && ret==KErrNone; ++i )
   132     for( TInt i=0; i<array.Count() && ret==KErrNone; ++i )
   132         {
   133         {
   133         TInt index = iWmWidgetOrder->IndexOf( *array[i] );
   134         TInt index = iWmWidgetOrder->IndexOf( *array[i] );
   134         if ( index < KErrNotFound || index >= array.Count() )
   135         if ( index < KErrNotFound || index >= array.Count() )
   143 
   144 
   144 // -----------------------------------------------------------------------------
   145 // -----------------------------------------------------------------------------
   145 // CWmUnitTest::CreateWidgetDataArrayL
   146 // CWmUnitTest::CreateWidgetDataArrayL
   146 // -----------------------------------------------------------------------------
   147 // -----------------------------------------------------------------------------
   147 //
   148 //
   148 void CWmUnitTest::CreateWidgetDataArrayL( RWidgetDataValues& aArray, TInt aCount )
   149 void CWmUnitTest::CreateWidgetDataArrayL( ROrderArray& aArray, TInt aCount )
   149     {
   150     {
   150     // first create an array of content info classes
   151     // first create an array of content info classes
   151     CHsContentInfoArray* contentArray = CHsContentInfoArray::NewL();
   152     CHsContentInfoArray* contentArray = CHsContentInfoArray::NewL();
   152     CleanupStack::PushL( contentArray );
   153     CleanupStack::PushL( contentArray );
   153     CreateContentInfoArrayL( *contentArray, aCount );
   154     CreateContentInfoArrayL( *contentArray, aCount );
   154     // connect to widget registry
       
   155     RWidgetRegistryClientSession registryClient;
       
   156     User::LeaveIfError( registryClient.Connect() );
       
   157     CleanupClosePushL( registryClient );
       
   158     TSize dummySize(40,40);
       
   159     CWmResourceLoader* resLoader = NULL; // not used in this case
       
   160     while( contentArray->Array().Count() > 0 )
       
   161         {        
       
   162         CWmWidgetData* data = CWmWidgetData::NewL(
       
   163                 dummySize, *resLoader, 
       
   164                 contentArray->Array()[0],
       
   165                 &registryClient);
       
   166 
   155 
   167         contentArray->Array().Remove( 0 );
   156     for ( TInt i = 0; i < contentArray->Array().Count(); i++ )
       
   157         {
       
   158         CHsContentInfo* contentInfo = contentArray->Array()[i];
       
   159         CWmWidgetOrderData* data = CWmWidgetOrderData::NewL(
       
   160                 contentInfo->PublisherId(), 
       
   161                 UidFromString ( contentInfo->Uid() ), 
       
   162                 contentInfo->Name(),
       
   163                 iWmWidgetOrder );
       
   164         
   168         CleanupStack::PushL( data );
   165         CleanupStack::PushL( data );
   169         aArray.AppendL( data );
   166         aArray.AppendL( data );
   170         CleanupStack::Pop( data );
   167         CleanupStack::Pop( data );
   171         }
   168         }
   172  
   169 
   173     registryClient.Disconnect();
   170     contentArray->Array().ResetAndDestroy();
   174     CleanupStack::PopAndDestroy( &registryClient );
       
   175     CleanupStack::PopAndDestroy( contentArray );
   171     CleanupStack::PopAndDestroy( contentArray );
   176     }
   172     }
   177 
   173 
       
   174 TUid CWmUnitTest::UidFromString( const TDesC8& aUidString ) const
       
   175     {
       
   176     TUid uid( TUid::Null() );
       
   177     const TInt KHexPrefixLength = 2;
       
   178     if ( aUidString.Length() > KHexPrefixLength )
       
   179         {
       
   180         TUint id = 0;
       
   181         TLex8 lex( aUidString.Mid( KHexPrefixLength ) );
       
   182         if ( lex.Val( id, EHex ) == KErrNone )
       
   183             {
       
   184             uid.iUid = (TInt32)id;
       
   185             }
       
   186         }
       
   187     return uid;
       
   188     }
   178 
   189 
   179 // End of File
   190 // End of File