phonebookengines/contactsmodel/tsrc/T_ContactViewEvents.cpp
changeset 24 0ba2181d7c28
parent 0 e686773b3f54
equal deleted inserted replaced
0:e686773b3f54 24:0ba2181d7c28
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 /*
     2 // All rights reserved.
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 // This component and the accompanying materials are made available
     3 * All rights reserved.
     4 // under the terms of "Eclipse Public License v1.0"
     4 * This component and the accompanying materials are made available
     5 // which accompanies this distribution, and is available
     5 * under the terms of "Eclipse Public License v1.0"
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 * which accompanies this distribution, and is available
     7 //
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 // Initial Contributors:
     8 *
     9 // Nokia Corporation - initial contribution.
     9 * Initial Contributors:
    10 //
    10 * Nokia Corporation - initial contribution.
    11 // Contributors:
    11 *
    12 //
    12 * Contributors:
    13 // Description:
    13 *
    14 //
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
    15 
    18 
    16 #include <e32test.h>
    19 #include <e32test.h>
    17 #include <cntdef.h>
    20 #include <cntdef.h>
    18 #include <cntdb.h>
    21 #include <cntdb.h>
    19 #include <cntitem.h>
    22 #include <cntitem.h>
    20 #include <cntfield.h>
    23 #include <cntfield.h>
    21 #include <cntfldst.h>
    24 #include <cntfldst.h>
    22 #include <cntviewbase.h>
    25 #include <cntviewbase.h>
    23 
    26 
    24 #include "CContactViewEventQueue.h"
    27 #include "ccontactvieweventqueue.h"
    25 #include "CContactDbEventQueue.h"
    28 #include "ccontactdbeventqueue.h"
    26 
    29 
    27 _LIT(KTestName, "T_GroupViewEvents");
    30 _LIT(KTestName, "T_GroupViewEvents");
    28 
    31 
    29 _LIT(KTestDbName, "c:T_GroupViewEvents.cdb");
    32 _LIT(KTestDbName, "c:T_GroupViewEvents.cdb");
    30 
    33 
   290 LOCAL_C CTestResources* DoTestAddContactAPILC(TBool aShowContactInGrp)
   293 LOCAL_C CTestResources* DoTestAddContactAPILC(TBool aShowContactInGrp)
   291     {
   294     {
   292     //add 2 contacts and check if localview send events
   295     //add 2 contacts and check if localview send events
   293     CTestResources* res = CTestResources::NewLC(aShowContactInGrp);
   296     CTestResources* res = CTestResources::NewLC(aShowContactInGrp);
   294     
   297     
   295     const TContactItemId contactId = res->CreateTestContactL(_L("Example1"));
   298     const TContactItemId contactId = res->CreateTestContactL(_L("Joplin"));
   296     res->iContactIdArray->AddL(contactId);
   299     res->iContactIdArray->AddL(contactId);
   297 
   300 
   298     // Check that iLocalView sends an event
   301     // Check that iLocalView sends an event
   299     TContactViewEvent event;
   302     TContactViewEvent event;
   300     test(res->iLocalViewEventQueue->ListenForEvent(10,event));
   303     test(res->iLocalViewEventQueue->ListenForEvent(10,event));
   308 	    test(res->iLocalViewEventQueue->ListenForEvent(10,event));
   311 	    test(res->iLocalViewEventQueue->ListenForEvent(10,event));
   309 	    test(event.iEventType == TContactViewEvent::EGroupChanged);
   312 	    test(event.iEventType == TContactViewEvent::EGroupChanged);
   310 	    test(event.iContactId == res->iGrpId);
   313 	    test(event.iContactId == res->iGrpId);
   311 		}
   314 		}
   312 
   315 
   313     const TContactItemId contactId1 = res->CreateTestContactL(_L("Example2"));
   316     const TContactItemId contactId1 = res->CreateTestContactL(_L("Vidin"));
   314     res->iContactIdArray->AddL(contactId1);
   317     res->iContactIdArray->AddL(contactId1);
   315 
   318 
   316     //get the EItemAdd event
   319     //get the EItemAdd event
   317     test(res->iLocalViewEventQueue->ListenForEvent(10,event));
   320     test(res->iLocalViewEventQueue->ListenForEvent(10,event));
   318     test(event.iEventType == TContactViewEvent::EItemAdded);
   321     test(event.iEventType == TContactViewEvent::EItemAdded);
   724 
   727 
   725     CTestResources* res = CTestResources::NewLC(ETrue, ETrue);
   728     CTestResources* res = CTestResources::NewLC(ETrue, ETrue);
   726     TContactViewEvent viewEvent;
   729     TContactViewEvent viewEvent;
   727     
   730     
   728     // Create 2 contacts
   731     // Create 2 contacts
   729     TContactItemId firstContactId = res->CreateTestContactL(_L("ExampleA"));
   732     TContactItemId firstContactId = res->CreateTestContactL(_L("Apan"));
   730     TContactItemId secondContactId = res->CreateTestContactL(_L("ExampleB"));
   733     TContactItemId secondContactId = res->CreateTestContactL(_L("Baname"));
   731         
   734         
   732 	//we should have 5 events here
   735 	//we should have 5 events here
   733 	test(res->iNewAPIGroupViewEventQueue->ListenForEvent(10,viewEvent));
   736 	test(res->iNewAPIGroupViewEventQueue->ListenForEvent(10,viewEvent));
   734 	test(viewEvent.iEventType == TContactViewEvent::EReady);
   737 	test(viewEvent.iEventType == TContactViewEvent::EReady);
   735 	test(res->iNewAPIGroupViewEventQueue->ListenForEvent(10,viewEvent));
   738 	test(res->iNewAPIGroupViewEventQueue->ListenForEvent(10,viewEvent));
   749     CleanupStack::PushL(firstContact);
   752     CleanupStack::PushL(firstContact);
   750     CContactItem* secondContact = res->iDb->OpenContactL(secondContactId);
   753     CContactItem* secondContact = res->iDb->OpenContactL(secondContactId);
   751     CleanupStack::PushL(secondContact);
   754     CleanupStack::PushL(secondContact);
   752     
   755     
   753     // change name
   756     // change name
   754     SetTextFieldL(*firstContact, KUidContactFieldFamilyName, _L("ExampleA1"));
   757     SetTextFieldL(*firstContact, KUidContactFieldFamilyName, _L("Apan1"));
   755     SetTextFieldL(*secondContact, KUidContactFieldFamilyName, _L("1ExampleB"));
   758     SetTextFieldL(*secondContact, KUidContactFieldFamilyName, _L("1Baname"));
   756 
   759 
   757 	res->iNewAPIGroupViewEventQueue->Flush();
   760 	res->iNewAPIGroupViewEventQueue->Flush();
   758 	res->iNewAPIFindViewEventQueue->Flush();
   761 	res->iNewAPIFindViewEventQueue->Flush();
   759 	res->iNewAPISubViewEventQueue->Flush();
   762 	res->iNewAPISubViewEventQueue->Flush();
   760 	
   763 	
   784     firstContact = res->iDb->OpenContactL(firstContactId);
   787     firstContact = res->iDb->OpenContactL(firstContactId);
   785     CleanupStack::PushL(firstContact);
   788     CleanupStack::PushL(firstContact);
   786     secondContact = res->iDb->OpenContactL(secondContactId);
   789     secondContact = res->iDb->OpenContactL(secondContactId);
   787     CleanupStack::PushL(secondContact);
   790     CleanupStack::PushL(secondContact);
   788     // change back contacts
   791     // change back contacts
   789     SetTextFieldL(*firstContact, KUidContactFieldFamilyName, _L("ExampleA"));
   792     SetTextFieldL(*firstContact, KUidContactFieldFamilyName, _L("Apan"));
   790     SetTextFieldL(*secondContact, KUidContactFieldFamilyName, _L("ExampleB"));
   793     SetTextFieldL(*secondContact, KUidContactFieldFamilyName, _L("Baname"));
   791     res->iDb->CommitContactL(*firstContact);	
   794     res->iDb->CommitContactL(*firstContact);	
   792     res->iDb->CommitContactL(*secondContact);
   795     res->iDb->CommitContactL(*secondContact);
   793     //just consume events
   796     //just consume events
   794     while(res->iNewAPIGroupViewEventQueue->ListenForEvent(1, viewEvent))
   797     while(res->iNewAPIGroupViewEventQueue->ListenForEvent(1, viewEvent))
   795     	{
   798     	{
   803     firstContact = res->iDb->OpenContactL(firstContactId);
   806     firstContact = res->iDb->OpenContactL(firstContactId);
   804     CleanupStack::PushL(firstContact);
   807     CleanupStack::PushL(firstContact);
   805     secondContact = res->iDb->OpenContactL(secondContactId);
   808     secondContact = res->iDb->OpenContactL(secondContactId);
   806     CleanupStack::PushL(secondContact);
   809     CleanupStack::PushL(secondContact);
   807     // change back contacts
   810     // change back contacts
   808     SetTextFieldL(*firstContact, KUidContactFieldFamilyName, _L("ExampleA1"));
   811     SetTextFieldL(*firstContact, KUidContactFieldFamilyName, _L("Apan1"));
   809     SetTextFieldL(*secondContact, KUidContactFieldFamilyName, _L("1ExampleB"));
   812     SetTextFieldL(*secondContact, KUidContactFieldFamilyName, _L("1Baname"));
   810     res->iDb->CommitContactL(*firstContact);	
   813     res->iDb->CommitContactL(*firstContact);	
   811     res->iDb->CommitContactL(*secondContact);
   814     res->iDb->CommitContactL(*secondContact);
   812     
   815     
   813     // check events and count in group view after these changes
   816     // check events and count in group view after these changes
   814     test(res->iNewAPIGroupViewEventQueue->ListenForEvent(10, viewEvent)); 
   817     test(res->iNewAPIGroupViewEventQueue->ListenForEvent(10, viewEvent));