void MemEventModelTest::deleteEvent() { EventModel *model = new EventModel(); Event event; event.setType(Event::IMEvent); event.setDirection(Event::Inbound); event.setGroupId(group.id()); event.setStartTime(QDateTime::fromString("2009-08-26T09:37:47Z", Qt::ISODate)); event.setEndTime(QDateTime::fromString("2009-08-26T09:37:47Z", Qt::ISODate)); event.setLocalUid("/org/freedesktop/Telepathy/Account/gabble/jabber/dut_40localhost0"); event.setRemoteUid("td@localhost"); event.setFreeText("deletetest"); QSignalSpy eventsCommitted(model, SIGNAL(eventsCommitted(const QList<CommHistory::Event>&, bool))); QVERIFY(model->addEvent(event)); QVERIFY(waitSignal(eventsCommitted, WAIT_TIMEOUT)); QVERIFY(model->deleteEvent(event)); QVERIFY(waitSignal(eventsCommitted, WAIT_TIMEOUT)); QTest::qWait(CALM_TIMEOUT); delete model; }
void MemEventModelTest::addEvent() { MALLINFO_DUMP("start"); EventModel *model = new EventModel(); MALLINFO_DUMP("model ready"); Event e1; e1.setGroupId(group.id()); e1.setType(Event::IMEvent); e1.setDirection(Event::Outbound); e1.setStartTime(QDateTime::fromString("2010-01-08T13:37:00Z", Qt::ISODate)); e1.setEndTime(QDateTime::fromString("2010-01-08T13:37:00Z", Qt::ISODate)); e1.setLocalUid("/org/freedesktop/Telepathy/Account/gabble/jabber/dut_40localhost0"); e1.setRemoteUid("td@localhost"); e1.setFreeText("addEvents 1"); QVERIFY(model->addEvent(e1)); QSignalSpy eventsCommitted(model, SIGNAL(eventsCommitted(const QList<CommHistory::Event>&, bool))); QVERIFY(waitSignal(eventsCommitted, WAIT_TIMEOUT)); QTest::qWait(CALM_TIMEOUT); MALLINFO_DUMP("query done"); delete model; MALLINFO_DUMP("done"); }
void MemEventModelTest::modifyEvent() { EventModel *model = new EventModel(); Event im; im.setType(Event::IMEvent); im.setDirection(Event::Outbound); im.setGroupId(group.id()); im.setStartTime(QDateTime::fromString("2009-08-26T09:37:47Z", Qt::ISODate)); im.setEndTime(QDateTime::fromString("2009-08-26T09:37:47Z", Qt::ISODate)); im.setLocalUid("/org/freedesktop/Telepathy/Account/gabble/jabber/dut_40localhost0"); im.setRemoteUid("td@localhost"); im.setFreeText("imtest"); QSignalSpy eventsCommitted(model, SIGNAL(eventsCommitted(const QList<CommHistory::Event>&, bool))); QVERIFY(model->addEvent(im)); QVERIFY(waitSignal(eventsCommitted, WAIT_TIMEOUT)); im.resetModifiedProperties(); im.setFreeText("imtest \"q\" modified\t tabs"); im.setStartTime(QDateTime::currentDateTime()); im.setEndTime(QDateTime::currentDateTime()); im.setIsRead(false); // should we actually test more properties? QVERIFY(model->modifyEvent(im)); QVERIFY(waitSignal(eventsCommitted, WAIT_TIMEOUT)); QTest::qWait(CALM_TIMEOUT); delete model; }
//Private functions bool SyncModelTest::addEvent(int parentId, int groupId, const QDateTime& sentReceivedTime, const QString& localId, const QString& remoteId, const QString& text, bool read) { EventModel model; watcher.setModel(&model); Event e; e.setType(Event::SMSEvent); e.setParentId(parentId); if (parentId == ::INBOX || parentId >= ::MYFOLDER) { e.setDirection(Event::Inbound); } else { e.setDirection(Event::Outbound); } e.setGroupId(groupId); e.setStartTime(sentReceivedTime); e.setEndTime(sentReceivedTime); e.setLocalUid(localId); e.setRemoteUid(remoteId); e.setFreeText(text); e.setIsRead(read); bool ret_val = model.addEvent(e); watcher.waitForSignals(1, 1); itemId = e.id(); return ret_val; }
void MemEventModelTest::addEvents() { MALLINFO_DUMP("start"); MALLINFO_DUMP("model ready"); int mem=0; int lastMem=0; for (int i = 0; i < 100; i++) { EventModel *model = new EventModel(); Event e1; e1.setGroupId(group.id()); e1.setType(Event::IMEvent); e1.setDirection(Event::Outbound); e1.setStartTime(QDateTime::fromString("2010-01-08T13:37:00Z", Qt::ISODate)); e1.setEndTime(QDateTime::fromString("2010-01-08T13:37:00Z", Qt::ISODate)); e1.setLocalUid("/org/freedesktop/Telepathy/Account/gabble/jabber/dut_40localhost0"); e1.setRemoteUid("td@localhost"); e1.setFreeText(QString("addEvents %1").arg(i)); QVERIFY(model->addEvent(e1)); QSignalSpy eventsCommitted(model, SIGNAL(eventsCommitted(const QList<CommHistory::Event>&, bool))); QVERIFY(waitSignal(eventsCommitted, WAIT_TIMEOUT)); waitWithDeletes(100); delete model; waitWithDeletes(100); MALLINFO_DUMP("query done"); struct mallinfo m = mallinfo(); if (i >= 50) mem += m.uordblks - lastMem; lastMem = m.uordblks; } QTest::qWait(CALM_TIMEOUT); MALLINFO_DUMP("ALL DONE"); qDebug() << "AVG LEAK" << mem/50; MALLINFO_DUMP("done"); }
int DeclarativeGroupManager::createOutgoingMessageEvent(int groupId, const QString &localUid, const QString &remoteUid, const QString &text) { if (groupId < 0) { // Try to find an appropriate group GroupObject *group = findGroup(localUid, remoteUid); if (group) { groupId = group->id(); } else { Group g; g.setLocalUid(localUid); g.setRemoteUids(QStringList() << remoteUid); g.setChatType(Group::ChatTypeP2P); DEBUG() << Q_FUNC_INFO << "Creating group for" << localUid << remoteUid; if (!addGroup(g)) { qWarning() << Q_FUNC_INFO << "Failed creating group"; return -1; } groupId = g.id(); } } Event event; if (localUid.indexOf("/ring/tel/") >= 0) event.setType(Event::SMSEvent); else event.setType(Event::IMEvent); event.setDirection(Event::Outbound); event.setIsRead(true); event.setLocalUid(localUid); event.setRemoteUid(remoteUid); event.setFreeText(text); event.setStartTime(QDateTime::currentDateTime()); event.setEndTime(event.startTime()); event.setStatus(Event::SendingStatus); event.setGroupId(groupId); DEBUG() << Q_FUNC_INFO << groupId << localUid << remoteUid << text; EventModel model; if (model.addEvent(event)) return event.id(); qWarning() << Q_FUNC_INFO << "Failed creating event"; return -1; }
QString MmsHandler::messageNotification(const QString &imsi, const QString &from, const QString &subject, uint expiry, const QByteArray &data) { Event event; event.setType(Event::MMSEvent); event.setStartTime(QDateTime::currentDateTime()); event.setEndTime(event.startTime()); event.setDirection(Event::Inbound); event.setLocalUid(RING_ACCOUNT_PATH); event.setRemoteUid(from); event.setSubject(subject); event.setExtraProperty("mms-notification-imsi", imsi); event.setExtraProperty("mms-expiry", expiry); event.setExtraProperty("mms-push-data", data.toBase64()); bool manualDownload = isDataProhibited(); event.setStatus(manualDownload ? Event::ManualNotificationStatus : Event::WaitingStatus); if (!setGroupForEvent(event)) { qCritical() << "Failed to handle group for MMS notification event; message dropped:" << event.toString(); return QString(); } EventModel model; if (!model.addEvent(event)) { qCritical() << "Failed to save MMS notification event; message dropped" << event.toString(); return QString(); } if (!manualDownload) { m_activeEvents.append(event.id()); } else { // Show a notification when manual download is needed NotificationManager::instance()->showNotification(event, from, Group::ChatTypeP2P); } DEBUG() << "Created MMS notification event:" << event.toString(); return manualDownload ? QString() : QString::number(event.id()); }
int addTestEvent(EventModel &model, Event::EventType type, Event::EventDirection direction, const QString &account, int groupId, const QString &text, bool isDraft, bool isMissedCall, const QDateTime &when, const QString &remoteUid, bool toModelOnly, const QString messageToken) { Event event; event.setType(type); event.setDirection(direction); event.setGroupId(groupId); event.setStartTime(when); if (type == Event::CallEvent) event.setEndTime(when.addSecs(100)); else event.setEndTime(event.startTime()); event.setLocalUid(account); if (remoteUid.isEmpty()) { event.setRemoteUid(type == Event::SMSEvent ? "555123456" : "td@localhost"); } else { event.setRemoteUid(remoteUid); } event.setFreeText(text); event.setIsDraft( isDraft ); event.setIsMissedCall( isMissedCall ); event.setMessageToken(messageToken); if (model.addEvent(event, toModelOnly)) { addedEventIds.insert(event.id()); return event.id(); } return -1; }