void tst_QMessageFilter::testIdPreFilter() { QMessageFilter filter = QMessageFilter::byId(QMessageId(email_prefix+"123"), QMessageDataComparator::Equal); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), false); filter = QMessageFilter::byId(QMessageId(sms_prefix+"123"), QMessageDataComparator::Equal); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), false); filter = QMessageFilter::byId(QMessageId(email_prefix+"123"), QMessageDataComparator::NotEqual); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true); filter = QMessageFilter::byId(QMessageId(), QMessageDataComparator::Equal); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true); filter = QMessageFilter::byId(QMessageId(), QMessageDataComparator::NotEqual); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true); QMessageIdList idList; idList.append(QMessageId(email_prefix+"123")); idList.append(QMessageId(email_prefix+"124")); filter = QMessageFilter::byId(idList, QMessageDataComparator::Includes); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), false); filter = QMessageFilter::byId(idList, QMessageDataComparator::Excludes); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true); idList.clear(); idList.append(QMessageId(sms_prefix+"123")); idList.append(QMessageId(sms_prefix+"124")); filter = QMessageFilter::byId(idList, QMessageDataComparator::Includes); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), false); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true); filter = QMessageFilter::byId(idList, QMessageDataComparator::Excludes); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true); idList.clear(); idList.append(QMessageId(email_prefix+"123")); idList.append(QMessageId(sms_prefix+"124")); filter = QMessageFilter::byId(idList, QMessageDataComparator::Includes); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true); filter = QMessageFilter::byId(idList, QMessageDataComparator::Excludes); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true); QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true); }
void MessagingHelper::filterMessages(QMessageIdList& messageIds, const QMessageFilter& filter) { if (messageIds.count() && !filter.isEmpty()) { QMessageFilterPrivate* pf = QMessageFilterPrivate::implementation(filter); if ((pf->_field == QMessageFilterPrivate::None) && (pf->_filterList.count() == 0)) { if (pf->_notFilter) { // There is only one filter: empty ~QMessageFilter() // => accountIds must be cleared messageIds.clear(); return; } else { // There is only one filter: empty QMessageFilter() // => accountIds list can remain intact return; } } if (pf->_valid) { QMessageStore* store = QMessageStore::instance(); for (int i=messageIds.count()-1; i >= 0; i--) { QMessage message = store->message(messageIds[i]); if (!pf->filter(message)) { messageIds.removeAt(i); } } } } }
void tst_QMessageFilter::testIdFilter() { #if defined(Q_WS_MAEMO_5) QMessage message; QMessagePrivate* privateMessage = QMessagePrivate::implementation(message); privateMessage->_id = QMessageId("123"); QMessageFilter filter = QMessageFilter::byId(QMessageId("123"), QMessageDataComparator::Equal); QMessageFilterPrivate* pf = QMessageFilterPrivate::implementation(filter); QCOMPARE(pf->filter(message), true); filter = QMessageFilter::byId(QMessageId("124"), QMessageDataComparator::Equal); pf = QMessageFilterPrivate::implementation(filter); QCOMPARE(pf->filter(message), false); filter = QMessageFilter::byId(QMessageId("123"), QMessageDataComparator::NotEqual); pf = QMessageFilterPrivate::implementation(filter); QCOMPARE(pf->filter(message), false); filter = QMessageFilter::byId(QMessageId("124"), QMessageDataComparator::NotEqual); pf = QMessageFilterPrivate::implementation(filter); QCOMPARE(pf->filter(message), true); QMessageIdList idList; idList.append(QMessageId("123")); idList.append(QMessageId("124")); idList.append(QMessageId("125")); filter = QMessageFilter::byId(idList, QMessageDataComparator::Includes); pf = QMessageFilterPrivate::implementation(filter); QCOMPARE(pf->filter(message), true); filter = QMessageFilter::byId(idList, QMessageDataComparator::Excludes); pf = QMessageFilterPrivate::implementation(filter); QCOMPARE(pf->filter(message), false); idList.clear(); idList.append(QMessageId("124")); idList.append(QMessageId("125")); idList.append(QMessageId("126")); filter = QMessageFilter::byId(idList, QMessageDataComparator::Includes); pf = QMessageFilterPrivate::implementation(filter); QCOMPARE(pf->filter(message), false); filter = QMessageFilter::byId(idList, QMessageDataComparator::Excludes); pf = QMessageFilterPrivate::implementation(filter); QCOMPARE(pf->filter(message), true); #endif }
void MessagingHelper::applyOffsetAndLimitToMessageIdList(QMessageIdList& messageIds, int limit, int offset) { if (messageIds.count() == 0) { return; } if (offset > 0) { if (offset > messageIds.count()) { messageIds.clear(); } else { for (int i = 0; i < offset; i++) { messageIds.removeFirst(); } } } if (limit > 0) { for (int i = messageIds.count()-1; i >= limit; i--) { messageIds.removeAt(i); } } }