logsui/logsengine/tsrc/ut_logsengine/src/ut_logsevent.cpp
changeset 17 90fe74753f71
parent 15 76d2cf7a585e
equal deleted inserted replaced
15:76d2cf7a585e 17:90fe74753f71
   131 }
   131 }
   132 
   132 
   133 void UT_LogsEvent::testUpdateRemotePartyFromContacts()
   133 void UT_LogsEvent::testUpdateRemotePartyFromContacts()
   134 {
   134 {
   135     // No search term
   135     // No search term
       
   136     unsigned int testContactId = 99;
       
   137     unsigned int testNoContactId = 0;
       
   138     QtContactsStubsHelper::setContactId( testContactId );
   136     QContactManager manager;
   139     QContactManager manager;
   137     LogsEvent event;
   140     LogsEvent event;
   138     QVERIFY( event.updateRemotePartyFromContacts(manager).length() == 0 );
   141     QString remoteParty;   
       
   142     QVERIFY( !event.updateRemotePartyFromContacts(manager, remoteParty) );
       
   143     QVERIFY( remoteParty.isEmpty() );
   139     QVERIFY( event.remoteParty().length() == 0 );
   144     QVERIFY( event.remoteParty().length() == 0 );
       
   145     QCOMPARE( event.contactLocalId(), testNoContactId );
   140     
   146     
   141     // Number as search term, no match
   147     // Number as search term, no match
   142     event.setNumber("12345");
   148     event.setNumber("12345");
   143     QVERIFY( event.updateRemotePartyFromContacts(manager).length() == 0 );
   149     QVERIFY( !event.updateRemotePartyFromContacts(manager, remoteParty) );
       
   150     QVERIFY( remoteParty.isEmpty() );
   144     QVERIFY( event.remoteParty().length() == 0 );
   151     QVERIFY( event.remoteParty().length() == 0 );
       
   152     QCOMPARE( event.contactLocalId(), testNoContactId );
   145     
   153     
   146     // Number as search term, match
   154     // Number as search term, match
   147     QtContactsStubsHelper::setContactNames("first", "last");
   155     QtContactsStubsHelper::setContactNames("first", "last");
   148     event.setNumber("11112222");
   156     event.setNumber("11112222");
   149     QString newRemoteParty = event.updateRemotePartyFromContacts(manager);
   157     QString newRemoteParty;
   150     QVERIFY( newRemoteParty.length() > 0 );
   158     QVERIFY( event.updateRemotePartyFromContacts(manager, newRemoteParty) );
       
   159     QVERIFY( !newRemoteParty.isEmpty() );
   151     QVERIFY( newRemoteParty == event.remoteParty() );
   160     QVERIFY( newRemoteParty == event.remoteParty() );
       
   161     QCOMPARE( event.contactLocalId(), testContactId );
       
   162     
       
   163     // Even if contact is unnamed, contact id is stored
       
   164     LogsEvent eventNoContactName;
       
   165     eventNoContactName.setNumber("11112222");
       
   166     QtContactsStubsHelper::setContactNames("", "");
       
   167     newRemoteParty.clear();
       
   168     QVERIFY( eventNoContactName.updateRemotePartyFromContacts(manager, newRemoteParty) );
       
   169     QVERIFY( newRemoteParty.isEmpty() );
       
   170     QVERIFY( newRemoteParty == eventNoContactName.remoteParty() );
       
   171     QCOMPARE( eventNoContactName.contactLocalId(), testContactId );
   152     
   172     
   153     // Voip address as search term, no match
   173     // Voip address as search term, no match
       
   174     QtContactsStubsHelper::setContactNames("first", "last");
   154     LogsEvent event2;
   175     LogsEvent event2;
   155     LogsEventData* eventData = new LogsEventData;
   176     LogsEventData* eventData = new LogsEventData;
   156     eventData->mRemoteUrl = "1.2.3.4";
   177     eventData->mRemoteUrl = "1.2.3.4";
   157     event2.setLogsEventData(eventData);
   178     event2.setLogsEventData(eventData);
   158     event2.setEventType(LogsEvent::TypeVoIPCall);
   179     event2.setEventType(LogsEvent::TypeVoIPCall);
   159     QVERIFY( event2.updateRemotePartyFromContacts(manager).length() == 0 );
   180     QVERIFY( !event2.updateRemotePartyFromContacts(manager, remoteParty) );
       
   181     QVERIFY( remoteParty.isEmpty() );
   160     QVERIFY( event2.remoteParty().length() == 0 );
   182     QVERIFY( event2.remoteParty().length() == 0 );
       
   183     QCOMPARE( event2.contactLocalId(), testNoContactId );
   161     
   184     
   162     // Voip address as search term, match
   185     // Voip address as search term, match
   163     eventData->mRemoteUrl = "11112222";
   186     eventData->mRemoteUrl = "11112222";
   164     newRemoteParty = event2.updateRemotePartyFromContacts(manager);
   187     newRemoteParty.clear();
   165     QVERIFY( newRemoteParty.length() > 0 );
   188     QVERIFY( event2.updateRemotePartyFromContacts(manager, newRemoteParty) );
       
   189     QVERIFY( !newRemoteParty.isEmpty() );
   166     QVERIFY( newRemoteParty == event.remoteParty() );
   190     QVERIFY( newRemoteParty == event.remoteParty() );
       
   191     QCOMPARE( event2.contactLocalId(), testContactId );
   167 }
   192 }
   168 
   193 
   169 void UT_LogsEvent::testParseContactName()
   194 void UT_LogsEvent::testParseContactName()
   170 {
   195 {
   171     LogsEvent event;
   196     LogsEvent event;