File: skeletonmessagejobtest.cpp

package info (click to toggle)
messagelib 4%3A24.12.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 83,448 kB
  • sloc: cpp: 106,765; xml: 375; sh: 25; makefile: 15
file content (212 lines) | stat: -rw-r--r-- 7,266 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
  SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>

  SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "skeletonmessagejobtest.h"

#include <QDebug>
#include <QTest>

#include <KMime/Message>

#include <MessageComposer/Composer>
#include <MessageComposer/GlobalPart>
#include <MessageComposer/InfoPart>
#include <MessageComposer/SkeletonMessageJob>
using namespace MessageComposer;

QTEST_MAIN(SkeletonMessageJobTest)

void SkeletonMessageJobTest::testSubject_data()
{
    QTest::addColumn<QString>("subject");

    QTest::newRow("simple subject") << QStringLiteral("Antaa virrata sateen...");
    QTest::newRow("non-ascii subject") << QStringLiteral("Muzicologă în bej, vând whisky și tequila, preț fix.");
    // NOTE: This works fine, but shows ??s in the debug output.  Why?
}

void SkeletonMessageJobTest::testSubject()
{
    // An InfoPart should belong to a Composer, even if we don't use the composer itself.
    auto composer = new Composer;
    InfoPart *infoPart = composer->infoPart();
    GlobalPart *globalPart = composer->globalPart();
    Q_ASSERT(infoPart);

    QFETCH(QString, subject);
    // qDebug() << subject;
    infoPart->setSubject(subject);
    auto sjob = new SkeletonMessageJob(infoPart, globalPart, composer);
    QVERIFY(sjob->exec());
    KMime::Message *message = sjob->message();
    QVERIFY(message->subject(false));
    qDebug() << message->subject(false)->asUnicodeString();
    QCOMPARE(subject, message->subject(false)->asUnicodeString());
    delete message;
    delete composer;
}

void SkeletonMessageJobTest::testAddresses_data()
{
    QTest::addColumn<QString>("from");
    QTest::addColumn<QStringList>("replyto");
    QTest::addColumn<QStringList>("to");
    QTest::addColumn<QStringList>("cc");
    QTest::addColumn<QStringList>("bcc");

    {
        QString from = QStringLiteral("one@example.com");
        QStringList to;
        to << QStringLiteral("two@example.com");
        QStringList cc;
        cc << QStringLiteral("three@example.com");
        QStringList bcc;
        bcc << QStringLiteral("four@example.com");
        QString replyto = QStringLiteral("five@example.com");

        QTest::newRow("simple single address") << from << QStringList{replyto} << to << cc << bcc;
    }

    {
        QString from = QStringLiteral("one@example.com");
        QStringList to;
        to << QStringLiteral("two@example.com");
        to << QStringLiteral("two.two@example.com");
        QStringList cc;
        cc << QStringLiteral("three@example.com");
        cc << QStringLiteral("three.three@example.com");
        QStringList bcc;
        bcc << QStringLiteral("four@example.com");
        bcc << QStringLiteral("four.four@example.com");
        QString replyto = QStringLiteral("five@example.com");

        QTest::newRow("simple multi address") << from << QStringList{replyto} << to << cc << bcc;
    }

    {
        QString from = QStringLiteral("Me <one@example.com>");
        QStringList to;
        to << QStringLiteral("You <two@example.com>");
        to << QStringLiteral("two.two@example.com");
        QStringList cc;
        cc << QStringLiteral("And you <three@example.com>");
        cc << QStringLiteral("three.three@example.com");
        QStringList bcc;
        bcc << QStringLiteral("And you too <four@example.com>");
        bcc << QStringLiteral("four.four@example.com");
        QString replyto = QStringLiteral("You over there <five@example.com>");

        QTest::newRow("named multi address") << from << QStringList{replyto} << to << cc << bcc;
    }

    {
        QString from = QStringLiteral("Şîşkin <one@example.com>");
        QStringList to;
        to << QStringLiteral("Ivan Turbincă <two@example.com>");
        to << QStringLiteral("two.two@example.com");
        QStringList cc;
        cc << QStringLiteral("Luceafărul <three@example.com>");
        cc << QStringLiteral("three.three@example.com");
        QStringList bcc;
        bcc << QStringLiteral("Zburătorul <four@example.com>");
        bcc << QStringLiteral("four.four@example.com");
        QString replyto = QStringLiteral("Şîşzbură <five@example.com>");

        QTest::newRow("non-ascii named multi address") << from << QStringList{replyto} << to << cc << bcc;
    }
}

void SkeletonMessageJobTest::testAddresses()
{
    // An InfoPart should belong to a Composer, even if we don't use the composer itself.
    auto composer = new Composer;
    InfoPart *infoPart = composer->infoPart();
    GlobalPart *globalPart = composer->globalPart();
    Q_ASSERT(infoPart);

    QFETCH(QString, from);
    QFETCH(QStringList, replyto);
    QFETCH(QStringList, to);
    QFETCH(QStringList, cc);
    QFETCH(QStringList, bcc);
    infoPart->setFrom(from);
    infoPart->setReplyTo(replyto);
    infoPart->setTo(to);
    infoPart->setCc(cc);
    infoPart->setBcc(bcc);
    auto sjob = new SkeletonMessageJob(infoPart, globalPart, composer);
    QVERIFY(sjob->exec());
    KMime::Message *message = sjob->message();

    {
        QVERIFY(message->from(false));
        // qDebug() << "From:" << message->from()->asUnicodeString();
        QCOMPARE(from, message->from()->asUnicodeString());
    }

    {
        QVERIFY(message->replyTo(false));
        // qDebug() << "Reply-To:" << message->replyTo()->asUnicodeString();
        QCOMPARE(replyto.join(QLatin1Char(',')), message->replyTo()->asUnicodeString());
    }

    {
        QVERIFY(message->to(false));
        // qDebug() << "To:" << message->to()->asUnicodeString();
        const auto mailboxes{message->to(false)->mailboxes()};
        for (const auto &addr : mailboxes) {
            // qDebug() << addr.prettyAddress();
            QVERIFY(to.contains(addr.prettyAddress()));
            to.removeOne(addr.prettyAddress());
        }
        QVERIFY(to.isEmpty());
    }

    {
        QVERIFY(message->cc(false));
        // qDebug() << "Cc:" << message->cc()->asUnicodeString();
        const auto mailboxes{message->cc(false)->mailboxes()};
        for (const auto &addr : mailboxes) {
            // qDebug() << addr.prettyAddress();
            QVERIFY(cc.contains(addr.prettyAddress()));
            cc.removeOne(addr.prettyAddress());
        }
        QVERIFY(cc.isEmpty());
    }

    {
        QVERIFY(message->bcc(false));
        // qDebug() << "Bcc:" << message->bcc()->asUnicodeString();
        const auto mailboxes{message->bcc(false)->mailboxes()};
        for (const auto &addr : mailboxes) {
            // qDebug() << addr.prettyAddress();
            QVERIFY(bcc.contains(addr.prettyAddress()));
            bcc.removeOne(addr.prettyAddress());
        }
        QVERIFY(bcc.isEmpty());
    }
    delete message;
    delete composer;
}

void SkeletonMessageJobTest::testMessageID()
{
    auto composer = new Composer();
    InfoPart *infoPart = composer->infoPart();
    GlobalPart *globalPart = composer->globalPart();
    Q_ASSERT(infoPart);

    auto sjob = new SkeletonMessageJob(infoPart, globalPart, composer);
    QVERIFY(sjob->exec());
    KMime::Message *message = sjob->message();
    QVERIFY(message->messageID(false));
    QVERIFY(!message->messageID(false)->isEmpty());
    delete message;
    delete sjob;
    delete composer;
}

#include "moc_skeletonmessagejobtest.cpp"