widgetmanager/tsrc/wmunittest/src/wmunittest_sortorder.cpp
changeset 1 5315654608de
parent 0 f72a12da539e
child 2 08c6ee43b396
equal deleted inserted replaced
0:f72a12da539e 1:5315654608de
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description:  test blocks for CWmPersistentWidgetorder
       
    15 *
       
    16 */
       
    17 
       
    18 //INCLUDE FILES
       
    19 #include <e32svr.h>
       
    20 #include <stdlib.h>
       
    21 #include <stifparser.h>
       
    22 #include <stiftestinterface.h>
       
    23 #include <bautils.h>
       
    24 #include <aknsskininstance.h>
       
    25 #include "wmunittest.h"
       
    26 // components to test
       
    27 #include "wmpersistentwidgetorder.h"
       
    28 #include "wmwidgetdata.h"
       
    29 #include <hscontentinfo.h>
       
    30 #include <hscontentinfoarray.h>
       
    31 #include <widgetregistryclient.h> // widgetreqistry
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CWmUnitTest::WidgetOrderCreateL
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 TInt CWmUnitTest::WidgetOrderCreateL( CStifItemParser& /*aItem*/ )
       
    41     {
       
    42     if ( iWmWidgetOrder != 0 ) User::Leave( KErrArgument );
       
    43     TInt ret = KErrNone;
       
    44     _CLEANUPCHECK_BEGIN
       
    45     iWmWidgetOrder = CWmPersistentWidgetOrder::NewL( iFs );
       
    46     _CLEANUPCHECK_END
       
    47     _RETURN("WidgetOrderCreateL End", ret);
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CWmUnitTest::WidgetOrderDeleteL
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 TInt CWmUnitTest::WidgetOrderDeleteL( CStifItemParser& /*aItem*/ )
       
    55     {
       
    56     if ( iWmWidgetOrder == 0 ) User::Leave( KErrArgument );
       
    57     TInt ret = KErrNone;
       
    58     delete iWmWidgetOrder;
       
    59     iWmWidgetOrder = 0;
       
    60     _RETURN("WidgetOrderDeleteL End", ret);
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CWmUnitTest::WidgetOrderLoadL
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 TInt CWmUnitTest::WidgetOrderLoadL( CStifItemParser& /*aItem*/ )
       
    68     {
       
    69     if ( iWmWidgetOrder == 0 ) User::Leave( KErrArgument );
       
    70     TInt ret = KErrNone;
       
    71     _CLEANUPCHECK_BEGIN
       
    72     iWmWidgetOrder->LoadL();
       
    73     _CLEANUPCHECK_END
       
    74     _RETURN("WidgetOrderLoadL End", ret);
       
    75     }
       
    76 
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CWmUnitTest::WidgetOrderSaveL
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 TInt CWmUnitTest::WidgetOrderSaveL( CStifItemParser& /*aItem*/ )
       
    83     {
       
    84     if ( iWmWidgetOrder == 0 ) User::Leave( KErrArgument );
       
    85     TInt ret = KErrNone;
       
    86 
       
    87     _CLEANUPCHECK_BEGIN
       
    88     RWidgetDataValues array;
       
    89     CleanupClosePushL( array );
       
    90     CreateWidgetDataArrayL( array, iMass );
       
    91     iWmWidgetOrder->StoreL( array );
       
    92     array.ResetAndDestroy();
       
    93     CleanupStack::Pop( &array );
       
    94     _CLEANUPCHECK_END
       
    95 
       
    96     _RETURN("WidgetOrderSaveL End", ret);
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CWmUnitTest::WidgetOrderCheckIsEmptyL
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 TInt CWmUnitTest::WidgetOrderCheckIsEmptyL( CStifItemParser& aItem )
       
   104     {
       
   105     if ( iWmWidgetOrder == 0 ) User::Leave( KErrArgument );
       
   106     TInt ret = KErrNone;
       
   107     TInt expectedResult;
       
   108     aItem.GetNextInt( expectedResult );
       
   109 
       
   110     if ( iWmWidgetOrder->IsEmpty() && !expectedResult )
       
   111         ret = KErrGeneral;
       
   112     if ( !iWmWidgetOrder->IsEmpty() && expectedResult )
       
   113         ret = KErrGeneral;
       
   114 
       
   115     _RETURN("WidgetOrderCheckIsEmptyL End", ret);
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CWmUnitTest::WidgetOrderUseL
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 TInt CWmUnitTest::WidgetOrderUseL( CStifItemParser& /*aItem*/ )
       
   123     {
       
   124     if ( iWmWidgetOrder == 0 ) User::Leave( KErrArgument );
       
   125     TInt ret = KErrNone;
       
   126 
       
   127     _CLEANUPCHECK_BEGIN
       
   128     // test IndexOf
       
   129     RWidgetDataValues array;
       
   130     CreateWidgetDataArrayL( array, iMass );
       
   131     for( TInt i=0; i<array.Count() && ret==KErrNone; ++i )
       
   132         {
       
   133         TInt index = iWmWidgetOrder->IndexOf( *array[i] );
       
   134         if ( index < KErrNotFound || index >= array.Count() )
       
   135             ret = KErrUnknown; // illegal index
       
   136         }
       
   137     array.ResetAndDestroy();
       
   138     _CLEANUPCHECK_END
       
   139 
       
   140     _RETURN("WidgetOrderUseL End", ret);
       
   141     }
       
   142 
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CWmUnitTest::CreateWidgetDataArrayL
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CWmUnitTest::CreateWidgetDataArrayL( RWidgetDataValues& aArray, TInt aCount )
       
   149     {
       
   150     // first create an array of content info classes
       
   151     CHsContentInfoArray* contentArray = CHsContentInfoArray::NewL();
       
   152     CleanupStack::PushL( contentArray );
       
   153     CreateContentInfoArrayL( *contentArray, aCount );
       
   154     // connect to widget registry
       
   155     RWidgetRegistryClientSession registryClient;
       
   156     User::LeaveIfError( registryClient.Connect() );
       
   157     CleanupClosePushL( registryClient );
       
   158 
       
   159     for( TInt i=0; i<contentArray->Array().Count(); ++i )
       
   160         {
       
   161         CWmWidgetData* data = CWmWidgetData::NewL(
       
   162                 *contentArray->Array()[i], &registryClient);
       
   163         CleanupStack::PushL( data );
       
   164         aArray.AppendL( data );
       
   165         CleanupStack::Pop( data );
       
   166         delete contentArray->Array()[i];
       
   167         contentArray->Array()[i] = 0;
       
   168         }
       
   169  
       
   170     registryClient.Disconnect();
       
   171     CleanupStack::PopAndDestroy( &registryClient );
       
   172     CleanupStack::PopAndDestroy( contentArray );
       
   173     }
       
   174 
       
   175 
       
   176 // End of File