File indexing completed on 2024-11-10 04:50:01

0001 /*
0002   SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 #include "itemcontexttest.h"
0008 #include "../itemcontext.h"
0009 #include <Akonadi/Item>
0010 #include <QTest>
0011 ItemContextTest::ItemContextTest(QObject *parent)
0012     : QObject(parent)
0013 {
0014 }
0015 
0016 ItemContextTest::~ItemContextTest() = default;
0017 
0018 void ItemContextTest::shouldHaveDefaultValue()
0019 {
0020     Akonadi::Item item(42);
0021     MailCommon::ItemContext itemContext(item, true);
0022     QCOMPARE(itemContext.item(), item);
0023     QVERIFY(!itemContext.moveTargetCollection().isValid());
0024     QVERIFY(!itemContext.needsPayloadStore());
0025     QVERIFY(!itemContext.needsFlagStore());
0026     QVERIFY(itemContext.needsFullPayload());
0027     QVERIFY(!itemContext.deleteItem());
0028 
0029     MailCommon::ItemContext itemContext2(item, false);
0030     QCOMPARE(itemContext2.item(), item);
0031     QVERIFY(!itemContext2.moveTargetCollection().isValid());
0032     QVERIFY(!itemContext2.needsPayloadStore());
0033     QVERIFY(!itemContext2.needsFlagStore());
0034     QVERIFY(!itemContext2.needsFullPayload());
0035     QVERIFY(!itemContext2.deleteItem());
0036 }
0037 
0038 void ItemContextTest::shouldAssignContext_data()
0039 {
0040     QTest::addColumn<bool>("needspayloadstore");
0041     QTest::addColumn<bool>("needsflagstore");
0042     QTest::addColumn<bool>("needsfullpayload");
0043     QTest::addColumn<bool>("deleteitem");
0044     QTest::newRow("no boolean") << false << false << false << false;
0045     QTest::newRow("needspayloadstore") << true << false << false << false;
0046     QTest::newRow("needsflagstore") << false << true << false << false;
0047     QTest::newRow("needsfullpayload") << false << false << true << false;
0048     QTest::newRow("deleteitem") << false << false << false << true;
0049     QTest::newRow("all") << true << true << true << true;
0050 
0051     QTest::newRow("T T F F") << true << true << false << false;
0052     QTest::newRow("T T T F") << true << true << true << false;
0053 
0054     QTest::newRow("F T F F") << false << true << false << false;
0055     QTest::newRow("F F T F") << false << false << true << false;
0056     QTest::newRow("F T T F") << false << true << true << false;
0057     QTest::newRow("F T T T") << false << true << true << true;
0058     QTest::newRow("F F F T") << false << false << false << true;
0059 
0060     QTest::newRow("F T F T") << false << true << false << true;
0061     QTest::newRow("F F F T") << false << false << false << true;
0062 }
0063 
0064 void ItemContextTest::shouldAssignContext()
0065 {
0066     QFETCH(bool, needspayloadstore);
0067     QFETCH(bool, needsflagstore);
0068     QFETCH(bool, needsfullpayload);
0069     QFETCH(bool, deleteitem);
0070 
0071     Akonadi::Item item(42);
0072     MailCommon::ItemContext itemContext(item, needsfullpayload);
0073 
0074     if (needspayloadstore) {
0075         itemContext.setNeedsPayloadStore();
0076     }
0077     if (needsflagstore) {
0078         itemContext.setNeedsFlagStore();
0079     }
0080     if (deleteitem) {
0081         itemContext.setDeleteItem();
0082     }
0083     QCOMPARE(itemContext.item(), item);
0084     QCOMPARE(itemContext.needsFlagStore(), needsflagstore);
0085     QCOMPARE(itemContext.needsFullPayload(), needsfullpayload);
0086     QCOMPARE(itemContext.needsPayloadStore(), needspayloadstore);
0087     QCOMPARE(itemContext.deleteItem(), deleteitem);
0088 }
0089 
0090 void ItemContextTest::shouldAssignCollection()
0091 {
0092     Akonadi::Item item(42);
0093     Akonadi::Collection col(12);
0094     MailCommon::ItemContext itemContext(item, true);
0095     itemContext.setMoveTargetCollection(col);
0096     QCOMPARE(itemContext.item(), item);
0097     QCOMPARE(itemContext.moveTargetCollection(), col);
0098 }
0099 
0100 QTEST_MAIN(ItemContextTest)
0101 
0102 #include "moc_itemcontexttest.cpp"