homescreensrv_plat/hs_settings_api/tsrc/src/mt_hspluginsettings.cpp
branchRCL_3
changeset 28 053c6c7c14f3
equal deleted inserted replaced
27:2c7f27287390 28:053c6c7c14f3
       
     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: EUnit test for homescreen settings API, main suite
       
    15 *
       
    16 */
       
    17 
       
    18 // External includes
       
    19 #include <digia/eunit/eunitmacros.h>
       
    20 #include <e32std.h>
       
    21 #include <e32cmn.h>
       
    22 
       
    23 // Internal includes
       
    24 #include <hspluginsettings.h>
       
    25 #include <MT_HsPluginSettings.h>
       
    26 #include <itemmap.h>
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 //----------------------------------------------------------------------------
       
    31 // MT_HsPluginSettings::NewL( )
       
    32 //----------------------------------------------------------------------------
       
    33 //
       
    34 MT_HsPluginSettings* MT_HsPluginSettings::NewL()
       
    35     {
       
    36     MT_HsPluginSettings* self = MT_HsPluginSettings::NewLC();
       
    37     CleanupStack::Pop( self );
       
    38     return self;
       
    39     }
       
    40 
       
    41 //----------------------------------------------------------------------------
       
    42 // MT_HsPluginSettings::NewLC( )
       
    43 //----------------------------------------------------------------------------
       
    44 //
       
    45 MT_HsPluginSettings* MT_HsPluginSettings::NewLC()
       
    46     {
       
    47     MT_HsPluginSettings* self = new( ELeave ) MT_HsPluginSettings();
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL();
       
    50     return self;
       
    51     }
       
    52 
       
    53 //----------------------------------------------------------------------------
       
    54 // MT_HsPluginSettings::~MT_HsPluginSettings( )
       
    55 //----------------------------------------------------------------------------
       
    56 //
       
    57 MT_HsPluginSettings::~MT_HsPluginSettings()
       
    58     {
       
    59     }
       
    60 
       
    61 //----------------------------------------------------------------------------
       
    62 // MT_HsPluginSettings::MT_HsPluginSettings( )
       
    63 //----------------------------------------------------------------------------
       
    64 //
       
    65 MT_HsPluginSettings::MT_HsPluginSettings()
       
    66     {
       
    67     }
       
    68 
       
    69 //----------------------------------------------------------------------------
       
    70 // MT_HsPluginSettings::ConstructL( )
       
    71 //----------------------------------------------------------------------------
       
    72 //
       
    73 void MT_HsPluginSettings::ConstructL()
       
    74     {
       
    75     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    76     // It generates the test case table.
       
    77     CEUnitTestSuiteClass::ConstructL();
       
    78     }
       
    79 
       
    80 //----------------------------------------------------------------------------
       
    81 // MT_HsPluginSettings::SetupL( )
       
    82 //----------------------------------------------------------------------------
       
    83 //
       
    84 void MT_HsPluginSettings::SetupL(  )
       
    85     {
       
    86     iObserver = CHomescreenSettingsObserver::NewL();
       
    87     HSPluginSettingsIf::CHomescreenSettings::InitializeL( _L8( "271012080" ) );
       
    88     iHomescreenSettings = HSPluginSettingsIf::CHomescreenSettings::Instance();    
       
    89     iHomescreenSettings->AddObserverL( iObserver );
       
    90     }
       
    91 
       
    92 //----------------------------------------------------------------------------
       
    93 // MT_HsPluginSettings::Teardown( )
       
    94 //----------------------------------------------------------------------------
       
    95 //
       
    96 void MT_HsPluginSettings::Teardown(  )
       
    97     {
       
    98     iHomescreenSettings->RemoveObserver( iObserver );
       
    99     HSPluginSettingsIf::CHomescreenSettings::UnInitialize();
       
   100     iHomescreenSettings = NULL;
       
   101     
       
   102     if( iObserver )
       
   103         {
       
   104         delete iObserver;
       
   105         iObserver = NULL;
       
   106         }
       
   107     }
       
   108 
       
   109 //----------------------------------------------------------------------------
       
   110 // MT_HsPluginSettings::TestGetSettingsL( )
       
   111 //----------------------------------------------------------------------------
       
   112 //
       
   113 void MT_HsPluginSettings::TestGetSettingsL()
       
   114     {
       
   115     _LIT8( KId, "1" ); // Plugin with ID 1 should be present - usually
       
   116     //_LIT8( KId, "0x2001f482" ); // root config UId - GetSettingsL does not work with uids
       
   117 
       
   118     RPointerArray<HSPluginSettingsIf::CItemMap> settingItems;
       
   119     CleanupClosePushL( settingItems );
       
   120 
       
   121     TInt err = iHomescreenSettings->GetSettingsL( KId, settingItems );
       
   122     if ( err )
       
   123         {
       
   124         EUNIT_PRINT( _L( "Warning: Get plugin settings failed" ) );
       
   125         }
       
   126 
       
   127     CleanupStack::Pop( &settingItems );
       
   128     settingItems.ResetAndDestroy();
       
   129 
       
   130     EUNIT_ASSERT( ETrue );
       
   131     }
       
   132 
       
   133 //----------------------------------------------------------------------------
       
   134 // MT_HsPluginSettings::TestSetSettingsL( )
       
   135 //----------------------------------------------------------------------------
       
   136 //
       
   137 void MT_HsPluginSettings::TestSetSettingsL()
       
   138     {
       
   139     _LIT8( KId, "1" ); // Plugin with ID 1 should be present - usually
       
   140     //_LIT8( KId, "0x2001f482" ); // root config UId - does not work with uids
       
   141 
       
   142     RPointerArray<HSPluginSettingsIf::CItemMap> settingItems;
       
   143     CleanupClosePushL( settingItems );
       
   144 
       
   145     TInt err =  iHomescreenSettings->SetSettingsL( KId, settingItems, EFalse );
       
   146     if ( err )
       
   147         {
       
   148         EUNIT_PRINT( _L( "Warning: Set plugin settings function failed" ) );
       
   149         }
       
   150 
       
   151     CleanupStack::Pop( &settingItems );
       
   152     settingItems.ResetAndDestroy();
       
   153 
       
   154     EUNIT_ASSERT( ETrue );
       
   155     }
       
   156 
       
   157 //  EUnit test table
       
   158 
       
   159 EUNIT_BEGIN_TEST_TABLE(
       
   160     MT_HsPluginSettings,
       
   161     "Test hspluginsettings",
       
   162     "MODULE")
       
   163 
       
   164 EUNIT_TEST(
       
   165     "Test GetSettingsL",
       
   166     "GetSettingsL",
       
   167     "All",
       
   168     "FUNCTIONALITY",
       
   169     SetupL, TestGetSettingsL, Teardown)
       
   170 
       
   171 EUNIT_TEST(
       
   172     "Test SetSettingsL",
       
   173     "SetSettingsL",
       
   174     "All",
       
   175     "FUNCTIONALITY",
       
   176     SetupL, TestSetSettingsL, Teardown)
       
   177     
       
   178 EUNIT_END_TEST_TABLE