meetingrequest/mrmbutilsextension/tsrc/unit/mrmbutilsextension/src/UT_cmrmbutilssettings.cpp
branchRCL_3
changeset 12 4ce476e64c59
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
       
     1 /*
       
     2 * Copyright (c) 2008 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "UT_cmrmbutilssettings.h"
       
    19 #include "mrmbutilsextensioncrkeys.h"
       
    20 #include "cmrmbutilssettings.h"
       
    21 #include "cfsmailclient.h"
       
    22 
       
    23 #include <eunitmacros.h>
       
    24 #include <eunitdecorators.h>
       
    25 #include <centralrepository.h>
       
    26 
       
    27 namespace { // codescanner::namespace
       
    28 
       
    29 
       
    30 // Initial cenrep value
       
    31 const TInt KCenRepInitValue( 0 );
       
    32 
       
    33 // Dummy cenrep value used in tests
       
    34 const TInt KDummyCenRepValue( 1000 );
       
    35 
       
    36 // Length for CRC buffer 
       
    37 const TInt KCRCBufferLen(32);
       
    38 
       
    39 }
       
    40 
       
    41 // - Construction -----------------------------------------------------------
       
    42 
       
    43 UT_CMRMBUtilsSettings::UT_CMRMBUtilsSettings()
       
    44     {
       
    45     }
       
    46 
       
    47 UT_CMRMBUtilsSettings::~UT_CMRMBUtilsSettings()
       
    48     {
       
    49     }
       
    50 
       
    51 UT_CMRMBUtilsSettings* UT_CMRMBUtilsSettings::NewL()
       
    52     {
       
    53     UT_CMRMBUtilsSettings* self = UT_CMRMBUtilsSettings::NewLC();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }
       
    57 
       
    58 UT_CMRMBUtilsSettings* UT_CMRMBUtilsSettings::NewLC()
       
    59     {
       
    60     UT_CMRMBUtilsSettings* self = new( ELeave ) UT_CMRMBUtilsSettings();
       
    61     CleanupStack::PushL( self );
       
    62     self->ConstructL();
       
    63     return self;
       
    64     }
       
    65 
       
    66 void UT_CMRMBUtilsSettings::ConstructL()
       
    67     {
       
    68     CEUnitTestSuiteClass::ConstructL();
       
    69     }
       
    70 
       
    71 // - Test methods -----------------------------------------------------------
       
    72 
       
    73 void UT_CMRMBUtilsSettings::SetupL(  )
       
    74     {
       
    75     iMailClient = CFSMailClient::NewL();
       
    76     iSettings = CMRMBUtilsSettings::NewL( *iMailClient );
       
    77     iCenRep = CRepository::NewL( KCRUidMRDefaultCMailMRMailbox );
       
    78     
       
    79     ResetcenRep();
       
    80     }
       
    81 
       
    82 void UT_CMRMBUtilsSettings::SetupWithMailboxesL()
       
    83     {
       
    84     SetupL();
       
    85     
       
    86     TFSMailMsgId msgId;
       
    87     iMailClient->ListMailBoxes( msgId, iMailboxes );
       
    88     }
       
    89 
       
    90 void UT_CMRMBUtilsSettings::ResetcenRep()
       
    91     {
       
    92     iCenRep->Set( KMRUIS60DefMailbox,   KCenRepInitValue ); 
       
    93     iCenRep->Set( KMRUICMailMailboxUID, KCenRepInitValue ); 
       
    94     iCenRep->Set( KMRUICMailMailboxID,  KCenRepInitValue );    
       
    95     }
       
    96 
       
    97 void UT_CMRMBUtilsSettings::Teardown()
       
    98     {
       
    99     ResetcenRep();    
       
   100 
       
   101     iMailboxes.ResetAndDestroy();
       
   102     iMailClient->Close();
       
   103     
       
   104     if ( iCenRep )
       
   105         {
       
   106         delete iCenRep;
       
   107         iCenRep = NULL;
       
   108         }
       
   109     
       
   110     if ( iSettings )
       
   111         {
       
   112         delete iSettings;
       
   113         iSettings = NULL;
       
   114         }
       
   115     }
       
   116 
       
   117 void UT_CMRMBUtilsSettings::T_SetDefaultMailboxSettingL()
       
   118     {
       
   119     TInt mailboxCount( iMailboxes.Count() );
       
   120     
       
   121     EUNIT_ASSERT_DESC(
       
   122             iMailboxes.Count(),
       
   123             "No any mailboxes defined in the system" );
       
   124     
       
   125     for (TInt i(0); i < mailboxCount; ++i )
       
   126         {
       
   127         CFSMailBox* mailbox( iMailboxes[i] );
       
   128         TFSMailMsgId mailboxId( mailbox->GetId() );
       
   129         
       
   130         TBuf<KCRCBufferLen> crcBuffer;
       
   131         crcBuffer.AppendNum( mailboxId.PluginId().iUid );
       
   132         crcBuffer.AppendNum( mailboxId.Id() );
       
   133         
       
   134         TUint32 cmailMailboxCrc( 0 );
       
   135         Mem::Crc32( cmailMailboxCrc, 
       
   136                 crcBuffer.Ptr(), 
       
   137                 crcBuffer.Size() );        
       
   138         
       
   139         iSettings->SetDefaultMailboxSettingL( cmailMailboxCrc );
       
   140         
       
   141         TInt cenRepValue( KCenRepInitValue );
       
   142         TInt err = iCenRep->Get( KMRUIS60DefMailbox, cenRepValue );
       
   143         
       
   144         EUNIT_ASSERT_DESC( 
       
   145                 KErrNone == err,
       
   146                 "Error reading cenrep ");
       
   147         
       
   148         EUNIT_ASSERT_EQUALS_DESC( 
       
   149                 cenRepValue, 
       
   150                 cmailMailboxCrc, 
       
   151                 "KMRUIS60DefMailbox mismatch" );
       
   152 
       
   153         cenRepValue = KCenRepInitValue;
       
   154         err = iCenRep->Get( KMRUICMailMailboxUID, cenRepValue );
       
   155         
       
   156         EUNIT_ASSERT_DESC( 
       
   157                 KErrNone == err,
       
   158                 "Error reading cenrep ");
       
   159         
       
   160         EUNIT_ASSERT_EQUALS_DESC( 
       
   161                 cenRepValue, 
       
   162                 mailboxId.PluginId().iUid, 
       
   163                 "KMRUICMailMailboxUID mismatch" );
       
   164 
       
   165         cenRepValue = KCenRepInitValue;
       
   166         err = iCenRep->Get( KMRUICMailMailboxID, cenRepValue );
       
   167         
       
   168         EUNIT_ASSERT_DESC( 
       
   169                 KErrNone == err,
       
   170                 "Error reading cenrep ");
       
   171         
       
   172         EUNIT_ASSERT_EQUALS_DESC( 
       
   173                 cenRepValue, 
       
   174                 mailboxId.Id(), 
       
   175                 "KMRUICMailMailboxID mismatch" );        
       
   176         }
       
   177     }
       
   178 
       
   179 void UT_CMRMBUtilsSettings::T_GetDefaultMailboxSettingsL()
       
   180     {
       
   181     TInt mailboxCount( iMailboxes.Count() );
       
   182     
       
   183     EUNIT_ASSERT_DESC(
       
   184             iMailboxes.Count(),
       
   185             "No any mailboxes defined in the system" );
       
   186     
       
   187     for (TInt i(0); i < mailboxCount; ++i )
       
   188         {
       
   189         CFSMailBox* mailbox( iMailboxes[i] );
       
   190         TFSMailMsgId mailboxId( mailbox->GetId() );
       
   191         
       
   192         TBuf<KCRCBufferLen> crcBuffer;
       
   193         crcBuffer.AppendNum( mailboxId.PluginId().iUid );
       
   194         crcBuffer.AppendNum( mailboxId.Id() );
       
   195         
       
   196         TUint32 cmailMailboxCrc( 0 );
       
   197         Mem::Crc32( cmailMailboxCrc, 
       
   198                 crcBuffer.Ptr(), 
       
   199                 crcBuffer.Size() );
       
   200         
       
   201         TInt S60mailboxId( cmailMailboxCrc );
       
   202         TInt cmailMailboxUID( mailboxId.PluginId().iUid );
       
   203         TInt cmailMailboxId( mailboxId.Id() );
       
   204         
       
   205         iCenRep->Set( KMRUIS60DefMailbox,   S60mailboxId );
       
   206         iCenRep->Set( KMRUICMailMailboxUID, cmailMailboxUID ); 
       
   207         iCenRep->Set( KMRUICMailMailboxID,  cmailMailboxId );
       
   208         
       
   209         S60mailboxId = KCenRepInitValue;
       
   210         iSettings->GetDefaultMailboxSettingsL( S60mailboxId );
       
   211         
       
   212         EUNIT_ASSERT_EQUALS_DESC( 
       
   213                 S60mailboxId, 
       
   214                 cmailMailboxCrc, 
       
   215                 "GetDefaultMailboxSettingsL mismatch" ); 
       
   216         }
       
   217     }
       
   218 
       
   219 void UT_CMRMBUtilsSettings::T_CenRepSetDefaultMailboxSettingL()
       
   220     {
       
   221     iSettings->SetDefaultCMailMRMailBoxL( 
       
   222             KDummyCenRepValue,
       
   223             TUid::Uid( KDummyCenRepValue ),
       
   224             KDummyCenRepValue );
       
   225     
       
   226     TInt cenRepValue( KCenRepInitValue );
       
   227     TInt err = iCenRep->Get( KMRUIS60DefMailbox, cenRepValue );
       
   228     
       
   229     EUNIT_ASSERT_DESC( 
       
   230             KErrNone == err,
       
   231             "Error reading cenrep ");
       
   232     
       
   233     EUNIT_ASSERT_EQUALS_DESC( 
       
   234             cenRepValue, 
       
   235             KDummyCenRepValue, 
       
   236             "KMRUIS60DefMailbox mismatch" );
       
   237 
       
   238     cenRepValue = KCenRepInitValue;
       
   239     err = iCenRep->Get( KMRUICMailMailboxUID, cenRepValue );
       
   240     
       
   241     EUNIT_ASSERT_DESC( 
       
   242             KErrNone == err,
       
   243             "Error reading cenrep ");
       
   244     
       
   245     EUNIT_ASSERT_EQUALS_DESC( 
       
   246             cenRepValue, 
       
   247             KDummyCenRepValue, 
       
   248             "KMRUICMailMailboxUID mismatch" );
       
   249 
       
   250     cenRepValue = KCenRepInitValue;
       
   251     err = iCenRep->Get( KMRUICMailMailboxID, cenRepValue );
       
   252     
       
   253     EUNIT_ASSERT_DESC( 
       
   254             KErrNone == err,
       
   255             "Error reading cenrep ");
       
   256     
       
   257     EUNIT_ASSERT_EQUALS_DESC( 
       
   258             cenRepValue, 
       
   259             KDummyCenRepValue, 
       
   260             "KMRUICMailMailboxID mismatch" );    
       
   261     }
       
   262 
       
   263 void UT_CMRMBUtilsSettings::T_CenRepGetDefaultMailboxSettingsL()
       
   264     {    
       
   265     iCenRep->Set( KMRUIS60DefMailbox,   KDummyCenRepValue ); 
       
   266     iCenRep->Set( KMRUICMailMailboxUID, KDummyCenRepValue ); 
       
   267     iCenRep->Set( KMRUICMailMailboxID,  KDummyCenRepValue );      
       
   268     
       
   269     TInt defaultBox( KCenRepInitValue );
       
   270     TUid mailboxPluginUID = TUid::Uid( KCenRepInitValue );
       
   271     TInt mailboxId = KCenRepInitValue;
       
   272     
       
   273     iSettings->GetDefaultCMailMRMailBoxL( 
       
   274             defaultBox,
       
   275             mailboxPluginUID,
       
   276             mailboxId );
       
   277     
       
   278     EUNIT_ASSERT_EQUALS_DESC( 
       
   279             defaultBox, 
       
   280             KDummyCenRepValue, 
       
   281             "KMRUIS60DefMailbox mismatch" );  
       
   282     
       
   283     EUNIT_ASSERT_EQUALS_DESC( 
       
   284             mailboxPluginUID.iUid, 
       
   285             KDummyCenRepValue, 
       
   286             "KMRUICMailMailboxUID mismatch" );
       
   287     
       
   288     EUNIT_ASSERT_EQUALS_DESC( 
       
   289             mailboxId, 
       
   290             KDummyCenRepValue, 
       
   291             "KMRUICMailMailboxID mismatch" );
       
   292     }
       
   293 
       
   294 // - EUnit test table -------------------------------------------------------
       
   295 
       
   296 EUNIT_BEGIN_TEST_TABLE(
       
   297     UT_CMRMBUtilsSettings,
       
   298     "Unit test: mrmbutilsextension",
       
   299     "UNIT" )
       
   300 
       
   301 EUNIT_TEST(
       
   302     "Testing setting default mailbox",
       
   303     "CMRMbUtilsExtensionImpl",
       
   304     "NewL",
       
   305     "FUNCTIONALITY",
       
   306     SetupWithMailboxesL, T_SetDefaultMailboxSettingL, Teardown)
       
   307 
       
   308 EUNIT_TEST(
       
   309     "Testing getting default mailbox",
       
   310     "CMRMbUtilsExtensionImpl",
       
   311     "NewL",
       
   312     "FUNCTIONALITY",
       
   313     SetupWithMailboxesL, T_GetDefaultMailboxSettingsL, Teardown)    
       
   314     
       
   315 EUNIT_TEST(
       
   316     "Testing setting default mailbox to cenrep",
       
   317     "CMRMbUtilsExtensionImpl",
       
   318     "NewL",
       
   319     "FUNCTIONALITY",
       
   320     SetupL, T_CenRepSetDefaultMailboxSettingL, Teardown)
       
   321     
       
   322 EUNIT_TEST(
       
   323     "Testing getting default mailbox from cenrep",
       
   324     "CMRMbUtilsExtensionImpl",
       
   325     "NewL",
       
   326     "FUNCTIONALITY",
       
   327     SetupL, T_CenRepGetDefaultMailboxSettingsL, Teardown)
       
   328     
       
   329 EUNIT_END_TEST_TABLE
       
   330 
       
   331 // EOF