void Ut_NotificationManager::testAddMissedCallNotification()
{
    CommHistory::Event event = createMissedCallEvent(CONTACT_1_REMOTE_ID, internalId(contact1));
    // One notification from contact 1
    NotificationManager* nm = NotificationManager::instance();
    nm->addNotification(createPersonalNotification(event));
    NotificationGroup group = nm->notificationGroup(event.type());

    QVERIFY(nm->countNotifications(group) == 1);
    QVERIFY(nm->countContacts(group) == 1);
    QVERIFY(nm->removeNotificationGroup(event.type()));
    QVERIFY(nm->countNotifications(group) == 0);
    QVERIFY(nm->countContacts(group) == 0);

    // Multiple notifications from contact 1
    CommHistory::Event event1 = createMissedCallEvent(CONTACT_1_REMOTE_ID, internalId(contact1));
    CommHistory::Event event2 = createMissedCallEvent(CONTACT_1_REMOTE_ID, internalId(contact1));
    nm->addNotification(createPersonalNotification(event1));
    nm->addNotification(createPersonalNotification(event2));
    QVERIFY(nm->countNotifications(group) == 2);
    QVERIFY(nm->countContacts(group) == 1);
    QVERIFY(nm->removeNotificationGroup(event1.type()));
    QVERIFY(nm->countNotifications(group) == 0);
    QVERIFY(nm->countContacts(group) == 0);
}
void Ut_NotificationManager::testMissedCallNotification()
{
    CommHistory::Event event = createMissedCallEvent(CONTACT_1_REMOTE_ID, internalId(contact1));
    // One notification from contact 1
    NotificationManager* nm = NotificationManager::instance();
    nm->m_NotificationTimer.stop();
    nm->removeNotificationGroup(event.type());
    removeGroup(event.type());

    QVERIFY(getGroup(event.type(), 10) == 0);

    nm->showNotification(event, CONTACT_1_REMOTE_ID);

    waitForCompletion(nm);

    MNotificationGroup *mgtGroup = getGroup(event.type(), 5000);
    QVERIFY(mgtGroup);
    QVERIFY(mgtGroup->isPublished());
    QVERIFY(mgtGroup->summary().contains(CONTACT_1_REMOTE_ID));
    QCOMPARE(mgtGroup->body(), txt_qtn_call_missed(1));

    NotificationGroup group = nm->notificationGroup(event.type());

    QVERIFY(nm->countContacts(group) == 1);
    QVERIFY(nm->countNotifications(group) == 1);

    waitForCompletion(nm);

    // Multiple notifications from contact 1
    CommHistory::Event event1 = createMissedCallEvent(CONTACT_1_REMOTE_ID, internalId(contact1));
    nm->showNotification(event1, CONTACT_1_REMOTE_ID);

    waitForCompletion(nm);

    mgtGroup = getGroup(event.type(), 5000);
    QVERIFY(mgtGroup);
    QVERIFY(mgtGroup->isPublished());
    QVERIFY(mgtGroup->summary().contains(CONTACT_1_REMOTE_ID));
    QCOMPARE(mgtGroup->body(), txt_qtn_call_missed(2));

    QVERIFY(nm->countContacts(group) == 1);
    QVERIFY(nm->countNotifications(group) == 2);

    waitForCompletion(nm);

    CommHistory::Event event2 = createMissedCallEvent(CONTACT_2_REMOTE_ID, internalId(contact2));
    nm->showNotification(event2, CONTACT_2_REMOTE_ID);

    waitForCompletion(nm); //wait for contact resolving

    mgtGroup = getGroup(event.type(), 5000);
    QVERIFY(mgtGroup);
    QVERIFY(mgtGroup->isPublished());
    QVERIFY(mgtGroup->summary().contains(CONTACT_1_REMOTE_ID));
    QVERIFY(mgtGroup->summary().contains(CONTACT_2_REMOTE_ID));
    QCOMPARE(mgtGroup->body(), txt_qtn_call_missed(3));

    QVERIFY(nm->countContacts(group) == 2);
    QVERIFY(nm->countNotifications(group) == 3);
}
void Ut_NotificationManager::testRemoveNotificationGrouop()
{
    NotificationManager* nm = NotificationManager::instance();

    // One IM notification from contact 1
    CommHistory::Event event = createImEvent(CONTACT_1_REMOTE_ID, internalId(contact1));
    nm->addNotification(createPersonalNotification(event));

    // 1st time to remove NotificationGroup, return true
    QVERIFY(nm->removeNotificationGroup(event.type()));
    // 2nd time to remove the same NotificationGroup, return false
    QVERIFY(!nm->removeNotificationGroup(event.type()));

    //Mutile IM notifications from contact 1
    CommHistory::Event event1 = createMissedCallEvent(CONTACT_1_REMOTE_ID, internalId(contact1));
    CommHistory::Event event2 = createMissedCallEvent(CONTACT_1_REMOTE_ID, internalId(contact1));
    nm->addNotification(createPersonalNotification(event1));
    nm->addNotification(createPersonalNotification(event2));

    // 1st time to remove NotificationGroup, return true
    QVERIFY(nm->removeNotificationGroup(event1.type()));
    // 2nd time to remove the same NotificationGroup, return false
    QVERIFY(!nm->removeNotificationGroup(event1.type()));
}
PersonalNotification Ut_NotificationManager::createPersonalNotification(const CommHistory::Event &event)
{
    return PersonalNotification(event.remoteUid(), event.localUid(), event.type(),
                                event.remoteUid(), CommHistory::Group::ChatTypeP2P,
                                event.contactId());
}