contentctrl_plat/adapter_customization_api/tsrc/ContactAdapter/cnsmldummymodsfetcher_test.cpp
branchRCL_3
changeset 14 b922b9936679
equal deleted inserted replaced
8:ad0f53516d84 14:b922b9936679
       
     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:  Source code file for contact adapter's modfetcher unit tests.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "CNSmlDummyModsFetcher_Test.h"
       
    19 #include <EUnitMacros.h>
       
    20 #include <EUnitDecorators.h>
       
    21 #include <CNTDB.H>
       
    22 #include <cntfield.h>
       
    23 #include <CNTFLDST.H>
       
    24 #include <nsmlsnapshotitem.h>
       
    25 #include <e32hashtab.h>
       
    26 #include <nsmlchangefinder.h>
       
    27 
       
    28 // VPbk includes
       
    29 #include <cvpbkcontactstoreuriarray.h>
       
    30 #include <tvpbkcontactstoreuriptr.h>
       
    31 #include <cvpbkcontactmanager.h>
       
    32 #include <VPbkContactStoreUris.h>
       
    33 #include <MVPbkContactStoreList.h>
       
    34 #include <CVPbkContactViewDefinition.h>
       
    35 #include <MVPbkContactLink.h>
       
    36 
       
    37 #include "CNSmlAdapterTestUtilities.h"
       
    38 #include "nsmldummymodsfetcher.h"
       
    39 
       
    40 namespace
       
    41     {
       
    42     _LIT( KTestDB, "c:eunitdb" );
       
    43     }
       
    44 
       
    45 //// Implementation UID for contacts adapter
       
    46 const TUint KNSmlContactsAdapterImplUid = 0x101F6DDD;
       
    47 
       
    48 // - Construction -----------------------------------------------------------
       
    49 
       
    50 CNSmlDummyModsFetcher_Test* CNSmlDummyModsFetcher_Test::NewL()
       
    51     {
       
    52     CNSmlDummyModsFetcher_Test* self = CNSmlDummyModsFetcher_Test::NewLC();
       
    53     CleanupStack::Pop();
       
    54     return self;
       
    55     }
       
    56 
       
    57 CNSmlDummyModsFetcher_Test* CNSmlDummyModsFetcher_Test::NewLC()
       
    58     {
       
    59     CNSmlDummyModsFetcher_Test* self = new( ELeave ) CNSmlDummyModsFetcher_Test();
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL();
       
    62     return self;
       
    63     }
       
    64 
       
    65 CNSmlDummyModsFetcher_Test::~CNSmlDummyModsFetcher_Test()
       
    66     {
       
    67     iReadStream.Close();
       
    68     delete iTestData;
       
    69 
       
    70     delete iCNSmlDummyModsFetcher;
       
    71 
       
    72     delete iChangeFinder;
       
    73 
       
    74     delete iTestUtilities;
       
    75 
       
    76     delete iContactManager;
       
    77     }
       
    78 
       
    79 CNSmlDummyModsFetcher_Test::CNSmlDummyModsFetcher_Test():
       
    80     iKey( TKeyArrayFix( _FOFF( TNSmlSnapshotItem, ItemId() ), ECmpTInt ))
       
    81     {
       
    82     }
       
    83 
       
    84 void CNSmlDummyModsFetcher_Test::ConstructL()
       
    85     {
       
    86     CEUnitTestSuiteClass::ConstructL();
       
    87     }
       
    88 
       
    89 // - Test methods -----------------------------------------------------------
       
    90 
       
    91 // ++++++++++++ SETUP METHODS ++++++++++++
       
    92 
       
    93 void CNSmlDummyModsFetcher_Test::SetupL(  )
       
    94     {
       
    95     EUNIT_PRINT( _L("SetupL: begin"));
       
    96     iTestUtilities = CNSmlAdapterTestUtilities::NewL();
       
    97     iTestUtilities->SetupAndPopulateContactDbL( KTestDB );
       
    98     iContactDatabase = iTestUtilities->GetDb();
       
    99 
       
   100     iTestData = HBufC8::NewL( 1024 );
       
   101     iReadStream.Open( *iTestData );
       
   102 
       
   103     EUNIT_PRINT( _L("SetupL: contact mgr"));
       
   104 
       
   105     // Create contact manager
       
   106     CVPbkContactStoreUriArray* uriArray = CVPbkContactStoreUriArray::NewLC();
       
   107     uriArray->AppendL( TVPbkContactStoreUriPtr( VPbkContactStoreUris::DefaultCntDbUri() ) );
       
   108     iContactManager = CVPbkContactManager::NewL(*uriArray);
       
   109     CleanupStack::PopAndDestroy(uriArray);
       
   110 
       
   111     // Create store and open it
       
   112     EUNIT_PRINT( _L("SetupL: store"));
       
   113     iStore = iContactManager->ContactStoresL().Find(
       
   114         TVPbkContactStoreUriPtr( VPbkContactStoreUris::DefaultCntDbUri() ) );
       
   115     iStore->OpenL( *this );
       
   116 
       
   117     iSyncHistory = EFalse;
       
   118     iSnapshotRegistered = EFalse;
       
   119 
       
   120     // Create platform ChangeFinder
       
   121     EUNIT_PRINT( _L("SetupL: ChangeFinder"));
       
   122     TRAPD(err, iChangeFinder = CNSmlChangeFinder::NewL(
       
   123         *this, iKey, iSyncHistory, KNSmlContactsAdapterImplUid ));
       
   124     if( err != KErrNone )
       
   125         {
       
   126         EUNIT_PRINT( _L("ChangeFinder Error: %d"), err );
       
   127         }
       
   128 
       
   129     // Finally, create ModsFetcher && assert allocation
       
   130     EUNIT_PRINT( _L("SetupL: ModsFetcher"));
       
   131     iCNSmlDummyModsFetcher = new (ELeave) CNSmlDummyModsFetcher(
       
   132         iSnapshotRegistered,
       
   133         *iContactManager,
       
   134         *iStore,
       
   135         iKey,
       
   136         *iChangeFinder );
       
   137 
       
   138     EUNIT_ASSERT( iCNSmlDummyModsFetcher );
       
   139 
       
   140     iCNSmlDummyModsFetcher->ConstructL();
       
   141 
       
   142     iLastChanged = Time::NullTTime();
       
   143 
       
   144     EUNIT_PRINT( _L("SetupL -end"));
       
   145     }
       
   146 
       
   147 void CNSmlDummyModsFetcher_Test::SetupCreateItemL()
       
   148     {
       
   149     SetupL();
       
   150     iCardId = iTestUtilities->AddContactL( _L("Test"), KNullDesC(),
       
   151         KNullDesC() );
       
   152     }
       
   153 
       
   154 
       
   155 // ++++++++++++ TEARDOWN METHODS ++++++++++++
       
   156 
       
   157 void CNSmlDummyModsFetcher_Test::Teardown()
       
   158     {
       
   159     iReadStream.Close();
       
   160     delete iTestData;
       
   161     iTestData = NULL;
       
   162 
       
   163     EUNIT_PRINT( _L("Teardown"));
       
   164     delete iCNSmlDummyModsFetcher;
       
   165     iCNSmlDummyModsFetcher = NULL;
       
   166     EUNIT_PRINT( _L("Teardown-2"));
       
   167 
       
   168     delete iChangeFinder;
       
   169     EUNIT_PRINT( _L("Teardown-3"));
       
   170 
       
   171     EUNIT_PRINT( _L("Teardown-4"));
       
   172 
       
   173     EUNIT_PRINT( _L("Teardown-5"));
       
   174     if ( iContactManager )
       
   175         {
       
   176             if(iStore)
       
   177             {
       
   178             iStore->Close( *this );
       
   179             }
       
   180         delete iContactManager;
       
   181         iContactManager = NULL;
       
   182         }
       
   183     EUNIT_PRINT( _L("Teardown-6"));
       
   184     TRAP_IGNORE( iTestUtilities->TeardownAndEmptyContactDbL( KTestDB ) );
       
   185     delete iTestUtilities;
       
   186     iTestUtilities = NULL;
       
   187     iCardId = 0;
       
   188     EUNIT_PRINT( _L("Teardown-7"));
       
   189     }
       
   190 
       
   191 void CNSmlDummyModsFetcher_Test::CreateViewL()
       
   192     {
       
   193     CVPbkContactViewDefinition* viewDef = CVPbkContactViewDefinition::NewL();
       
   194     CleanupStack::PushL( viewDef );
       
   195     viewDef->SetType( EVPbkContactsView );
       
   196 
       
   197     //viewDef->SetUriL( iStore->StoreProperties().Uri().UriDes() );
       
   198 
       
   199     iContactViewBase = iContactManager->CreateContactViewLC( 
       
   200                                          *this, 
       
   201                                          *viewDef, 
       
   202                                          iContactManager->FieldTypes() );
       
   203     CleanupStack::Pop();
       
   204     CleanupStack::PopAndDestroy( viewDef );
       
   205     } 
       
   206 
       
   207 // ++++++++++++ ACTUAL TEST METHODS ++++++++++++
       
   208 
       
   209 // ------------------ From MSmlSyncRelationship ---------------------
       
   210 TSmlSyncTaskKey CNSmlDummyModsFetcher_Test::SyncTaskKey() const
       
   211     {
       
   212     EUNIT_PRINT( _L("SyncTaskKey"));
       
   213     return 0;
       
   214     }
       
   215 
       
   216 void CNSmlDummyModsFetcher_Test::OpenReadStreamLC(RReadStream& aReadStream, TUid /*aStreamUid*/)
       
   217     {
       
   218     EUNIT_PRINT( _L("OpenReadStreamLC"));
       
   219     aReadStream = iReadStream;
       
   220     CleanupClosePushL( iReadStream );
       
   221 
       
   222     EUNIT_PRINT( _L("OpenReadStreamLC - end"));
       
   223     }
       
   224 
       
   225 void CNSmlDummyModsFetcher_Test::OpenWriteStreamLC(RWriteStream& /*aWriteStream*/, TUid /*aStreamUid*/)
       
   226     {
       
   227     EUNIT_PRINT( _L("OpenWriteStreamLC"));
       
   228     }
       
   229 
       
   230 TBool CNSmlDummyModsFetcher_Test::IsStreamPresentL(TUid /*aStreamUid*/) const
       
   231     {
       
   232     EUNIT_PRINT( _L("IsStreamPresentL"));
       
   233     return EFalse;
       
   234     }
       
   235 // ---------------- MSmlSyncRelationship END -----------------------
       
   236 
       
   237 // ------------------ From MVPbkContactStoreObserver ---------------------
       
   238 void CNSmlDummyModsFetcher_Test::StoreReady(
       
   239     MVPbkContactStore& /*aContactStore*/ )
       
   240     {
       
   241     }
       
   242 
       
   243 void CNSmlDummyModsFetcher_Test::StoreUnavailable(
       
   244     MVPbkContactStore& /*aContactStore*/, TInt /*aReason*/)
       
   245     {
       
   246     }
       
   247 
       
   248 void CNSmlDummyModsFetcher_Test::HandleStoreEventL(
       
   249         MVPbkContactStore& /*aContactStore*/,
       
   250         TVPbkContactStoreEvent /*aStoreEvent*/)
       
   251     {
       
   252     }
       
   253 
       
   254 // ------------------  From MVPbkContactViewObserver ---------------------
       
   255 void CNSmlDummyModsFetcher_Test::ContactViewReady( MVPbkContactViewBase& /*aView*/ )
       
   256     {
       
   257     }   
       
   258     
       
   259 void CNSmlDummyModsFetcher_Test::ContactViewUnavailable(
       
   260             MVPbkContactViewBase& /*aView*/ )
       
   261     {
       
   262     }
       
   263 
       
   264 void CNSmlDummyModsFetcher_Test::ContactAddedToView(
       
   265             MVPbkContactViewBase& /*aView*/, 
       
   266             TInt /*aIndex*/, 
       
   267             const MVPbkContactLink& /*aContactLink*/ )
       
   268     {
       
   269     }
       
   270 
       
   271 void CNSmlDummyModsFetcher_Test::ContactRemovedFromView(
       
   272             MVPbkContactViewBase& /*aView*/, 
       
   273             TInt /*aIndex*/, 
       
   274             const MVPbkContactLink& /*aContactLink*/ )
       
   275     { 
       
   276     }
       
   277     
       
   278 void CNSmlDummyModsFetcher_Test::ContactViewError(
       
   279             MVPbkContactViewBase& /*aView*/, 
       
   280             TInt /*aError*/, 
       
   281             TBool /*aErrorNotified*/ )
       
   282     { 
       
   283     }
       
   284 
       
   285 // ---------------- MVPbkContactStoreObserver END -----------------------
       
   286 
       
   287 // Helper functions
       
   288 
       
   289 CContactItemField* CNSmlDummyModsFetcher_Test::CreateConfidentialLC()
       
   290     {
       
   291     CContactItemField* confidentialField =
       
   292         CContactItemField::NewLC( KStorageTypeText, KUidContactFieldClass );
       
   293     confidentialField->SetMapping( KUidContactFieldVCardMapClass );
       
   294     confidentialField->TextStorage()->SetTextL( KNSmlContactSyncNoSync );
       
   295     EUNIT_PRINT( _L("CreateConfidentialLC - END"));
       
   296     return confidentialField;
       
   297     }
       
   298 
       
   299 
       
   300 // - EUnit test table -------------------------------------------------------
       
   301 
       
   302 EUNIT_BEGIN_TEST_TABLE(
       
   303     CNSmlDummyModsFetcher_Test,
       
   304     "Unit tests for CNSmlDummyModsFetcher.",
       
   305     "UNIT" )
       
   306 
       
   307 EUNIT_TEST(
       
   308     "CNSmlContactsModsFetcher allocation",
       
   309     "CNSmlContactsModsFetcher",
       
   310     "Allocation",
       
   311     "FUNCTIONALITY",
       
   312     SetupL, Empty, Teardown)
       
   313 
       
   314 EUNIT_END_TEST_TABLE