idlehomescreen/widgetmanager/tsrc/wmunittest/src/wmunittest_plugin.cpp
changeset 1 5315654608de
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 CWmPlugin
       
    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 "wmplugin.h"
       
    28 #include <hscontentinfo.h>
       
    29 #include <hscontentinfoarray.h>
       
    30 
       
    31 // MACROS
       
    32 #define _LOG(a) iLog->Log(_L(a))
       
    33 #define _RETURN(a, b) iLog->Log(_L("\treturn: %d"),b); \
       
    34                      iLog->Log(_L(a)); \
       
    35                      return b; \
       
    36 
       
    37 #define _CLEANUPCHECK_BEGIN \
       
    38     CBase* __check = new (ELeave) CBase(); \
       
    39     CleanupStack::PushL( __check );
       
    40 
       
    41 #define _CLEANUPCHECK_END \
       
    42     CleanupStack::PopAndDestroy( __check );
       
    43 
       
    44 // CONSTANTS
       
    45 const TInt KName = 100;
       
    46 const TInt KDescription = 101;
       
    47 const TInt KLogoPath = 102;
       
    48 const TInt KCanBeAdded = 103;
       
    49 const TInt KCanBeRemoved = 104;
       
    50 
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS ===============================
       
    53 
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CWmUnitTest::PluginCreateL
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 TInt CWmUnitTest::PluginCreateL( CStifItemParser& /*aItem*/ )
       
    60     {
       
    61     if ( iWmPlugin != 0 ) User::Leave( KErrArgument );
       
    62     TInt ret = KErrNone;
       
    63     _CLEANUPCHECK_BEGIN
       
    64     iWmPlugin = CWmPlugin::NewL();
       
    65     iWmPlugin->SetContentController( this );
       
    66     _CLEANUPCHECK_END
       
    67     _RETURN("PluginCreateL End", ret);
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CWmUnitTest::PluginDeleteL
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 TInt CWmUnitTest::PluginDeleteL( CStifItemParser& /*aItem*/ )
       
    75     {
       
    76     if ( iWmPlugin == 0 ) User::Leave( KErrArgument );
       
    77     TInt ret = KErrNone;
       
    78     delete iWmPlugin;
       
    79     iWmPlugin = 0;
       
    80     _RETURN("PluginDeleteL End", ret);
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CWmUnitTest::PluginActivateL
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 TInt CWmUnitTest::PluginActivateL( CStifItemParser& /*aItem*/ )
       
    88     {
       
    89     if ( iWmPlugin == 0 ) User::Leave( KErrArgument );
       
    90     iWmPlugin->Activate();
       
    91     _RETURN("PluginActivateL End", KErrNone);
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CWmUnitTest::PluginDeactivateL
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 TInt CWmUnitTest::PluginDeactivateL( CStifItemParser& /*aItem*/ )
       
    99     {
       
   100     if ( iWmPlugin == 0 ) User::Leave( KErrArgument );
       
   101     iWmPlugin->Deactivate();
       
   102     _RETURN("PluginActivateL End", KErrNone);
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CWmUnitTest::PluginWidgetsChangedL
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 TInt CWmUnitTest::PluginWidgetsChangedL( CStifItemParser& /*aItem*/ )
       
   110     {
       
   111     if ( iWmPlugin == 0 ) User::Leave( KErrArgument );
       
   112     iWmPlugin->NotifyWidgetListChanged();
       
   113     _RETURN("PluginWidgetsChangedL End", KErrNone);
       
   114     }
       
   115 
       
   116 // =============================================================================
       
   117 // Methods from MHsContentController
       
   118 // =============================================================================
       
   119 
       
   120 TInt CWmUnitTest::WidgetListL( CHsContentInfoArray& aArray )
       
   121     {
       
   122     CreateContentInfoArrayL( aArray, iMass );
       
   123     return KErrNone;
       
   124     }
       
   125 
       
   126 TInt CWmUnitTest::ViewListL( CHsContentInfoArray& /*aArray*/ )
       
   127     {
       
   128     return KErrNone;
       
   129     }
       
   130 
       
   131 TInt CWmUnitTest::AppListL( CHsContentInfoArray& /*aArray*/ )
       
   132     {
       
   133     return KErrNone;
       
   134     }
       
   135 
       
   136 TInt CWmUnitTest::AddWidgetL( CHsContentInfo& /*aInfo*/ )
       
   137     {
       
   138     return KErrNone;
       
   139     }
       
   140 
       
   141 TInt CWmUnitTest::RemoveWidgetL( CHsContentInfo& /*aInfo*/ )
       
   142     {
       
   143     return KErrNone;
       
   144     }
       
   145 
       
   146 TInt CWmUnitTest::AddViewL( CHsContentInfo& /*aInfo*/ )
       
   147     {
       
   148     return KErrNone;
       
   149     }
       
   150 
       
   151 TInt CWmUnitTest::RemoveViewL( CHsContentInfo& /*aInfo*/ )
       
   152     {
       
   153     return KErrNone;
       
   154     }
       
   155 
       
   156 TInt CWmUnitTest::ActivateViewL( CHsContentInfo& /*aInfo*/ )
       
   157     {
       
   158     return KErrNone;
       
   159     }
       
   160 
       
   161 TInt CWmUnitTest::ActivateAppL( CHsContentInfo& /*aInfo*/ )
       
   162     {
       
   163     return KErrNone;
       
   164     }
       
   165 
       
   166 
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CWmUnitTest::ChangeContentL
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 TInt CWmUnitTest::ChangeContentL( CStifItemParser& aItem )
       
   173     {
       
   174     aItem.GetNextInt( iChangeIndex );    
       
   175     aItem.GetNextInt( iChangeType );
       
   176     TPtrC changeValue;
       
   177     aItem.SetParsingType( CStifItemParser::EQuoteStyleParsing );
       
   178     aItem.GetNextString( changeValue );
       
   179     delete iChangeValue;
       
   180     iChangeValue = NULL;
       
   181     iChangeValue = changeValue.AllocL();
       
   182     _RETURN("ChangeContentL End", KErrNone);
       
   183     }
       
   184 
       
   185 // string -> bool conversion function
       
   186 TBool s2b( const TDesC& str )
       
   187     {
       
   188     return ( str == _L("1") ? ETrue : EFalse );
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CWmUnitTest::CreateContentInfoArrayL
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CWmUnitTest::CreateContentInfoArrayL( CHsContentInfoArray& aArray, TInt aCount )
       
   196     {
       
   197     for( TInt i=0; i<aCount; ++i )
       
   198         {
       
   199         CHsContentInfo* info = CHsContentInfo::NewLC();
       
   200         TBuf<64> name;
       
   201         name.Format( _L("Widget_%d"), i );
       
   202         info->SetNameL( name );
       
   203         TBuf8<20> id;
       
   204         id.Num( i );
       
   205         info->SetUidL( id );
       
   206         info->SetTypeL( _L8("template") );
       
   207         info->SetIconPathL( _L("uid(0x2000DAD2)") );
       
   208         info->SetCanBeAdded( ETrue );
       
   209         info->SetDescriptionL(_L("Default plaa plaa plaa plaa plaa plaa plaa"));
       
   210         
       
   211         aArray.Array().AppendL( info );
       
   212         CleanupStack::Pop( info );
       
   213         }
       
   214     
       
   215     // change content
       
   216     if ( iChangeIndex >= 0 && iChangeIndex < aCount )
       
   217         {
       
   218         CHsContentInfo* info = aArray.Array()[iChangeIndex];
       
   219         if ( iChangeType == KName )
       
   220             { info->SetNameL( *iChangeValue ); }
       
   221         else if ( iChangeType == KDescription )
       
   222             { info->SetDescriptionL( *iChangeValue ); }
       
   223         else if ( iChangeType == KLogoPath )
       
   224             { info->SetIconPathL( *iChangeValue ); }
       
   225         else if ( iChangeType == KCanBeAdded )
       
   226             { info->SetCanBeAdded( s2b(*iChangeValue) ); }
       
   227         else if ( iChangeType == KCanBeRemoved )
       
   228             { info->SetCanBeRemoved( s2b(*iChangeValue) ); }
       
   229         }
       
   230     }
       
   231 
       
   232 // End of File