File: itipjobtest.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 (144 lines) | stat: -rw-r--r-- 4,633 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
/*
  SPDX-FileCopyrightText: 2023 Daniel Vrátil <dvratil@kde.org>

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

#include "itipjobtest.h"
#include "qtest_messagecomposer.h"

#include <QDebug>
#include <QTest>

#include <KMime/Content>
#include <KMime/Headers>
using namespace KMime;

#include <MessageComposer/Composer>
#include <MessageComposer/GlobalPart>
#include <MessageComposer/ItipJob>
#include <MessageComposer/ItipPart>

using namespace MessageComposer;
using namespace MessageCore;

QTEST_MAIN(ItipJobTest)

static QString testItip = QStringLiteral(R"(
BEGIN:VCALENDAR
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
CREATED:20230508T143456Z
ORGANIZER;CN=Konqi:MAILTO:konqi@example.com
ATTENDEE;CN=Kate;RSVP=TRUE;ROLE=REQ-PARTICIPANT:MAILTO:kate@example.com
CREATED:20230508T143456Z
UID:KOrganizer-1673850046.1067
SUMMARY:Krypto Party
DTSTART;VALUE=DATE:20230520
DTEND;VALUE=DATE:20230520
END:VEVENT
END:VCALENDAR)");

static QString testItipMessage = QStringLiteral("Hi all, let's do some crypto partying!");

void ItipJobTest::testInvitationWithAttachment()
{
    auto part = std::make_unique<ItipPart>();
    part->setOutlookConformInvitation(false);
    part->setInvitation(testItip);
    part->setInvitationBody(testItipMessage);

    Composer composer;
    ItipJob job(part.get(), &composer);
    job.setAutoDelete(false);
    QVERIFY(job.exec());

    auto *content = job.content();
    content->assemble();
    QVERIFY(content);

    QCOMPARE(content->contentType(false)->mimeType(), "multipart/mixed");
    const auto subparts = content->contents();
    QCOMPARE(subparts.size(), 2);
    const auto msgPart = subparts[0];
    QCOMPARE(msgPart->contentType(false)->mimeType(), "text/plain");
    QCOMPARE(msgPart->contentDisposition(false)->disposition(), KMime::Headers::CDinline);
    QCOMPARE(msgPart->decodedText(), testItipMessage);

    const auto itipPart = subparts[1];
    QCOMPARE(itipPart->contentType(false)->mimeType(), "text/calendar");
    QCOMPARE(itipPart->contentType(false)->name(), QStringLiteral("cal.ics"));
    QCOMPARE(itipPart->contentType(false)->parameter("method"), QStringLiteral("request"));
    QCOMPARE(itipPart->contentType(false)->charset(), "utf-8");
    QCOMPARE(itipPart->contentDisposition(false)->disposition(), KMime::Headers::CDattachment);
    QCOMPARE(itipPart->decodedText(), testItip);
}

void ItipJobTest::testInvitationWithoutAttachment()
{
    auto part = std::make_unique<ItipPart>();
    part->setOutlookConformInvitation(false);
    part->setInvitationBody(testItipMessage);

    Composer composer;
    ItipJob job(part.get(), &composer);
    job.setAutoDelete(false);
    QVERIFY(job.exec());

    auto *content = job.content();
    content->assemble();
    QVERIFY(content);

    QCOMPARE(content->contentType(false)->mimeType(), "text/plain");
    QCOMPARE(content->contentDisposition(false)->disposition(), KMime::Headers::CDinline);
    QCOMPARE(content->decodedText(), testItipMessage);
}

void ItipJobTest::testOutlookInvitationWithAttachment()
{
    auto part = std::make_unique<ItipPart>();
    part->setOutlookConformInvitation(true);
    part->setInvitation(testItip);
    part->setInvitationBody(testItipMessage);

    Composer composer;
    ItipJob job(part.get(), &composer);
    job.setAutoDelete(false);
    QVERIFY(job.exec());

    auto *content = job.content();
    content->assemble();
    QVERIFY(content);

    QCOMPARE(content->contentType(false)->mimeType(), "text/calendar");
    QCOMPARE(content->contentType(false)->name(), QStringLiteral("cal.ics"));
    QCOMPARE(content->contentType(false)->parameter("method"), QStringLiteral("request"));
    QCOMPARE(content->contentType(false)->charset(), "utf-8");
    QCOMPARE(content->contentDisposition(false)->disposition(), KMime::Headers::CDinline);
    QCOMPARE(content->decodedText(), testItip);
}

void ItipJobTest::testOutlookInvitationWithoutAttachment()
{
    auto part = std::make_unique<ItipPart>();
    part->setOutlookConformInvitation(true);
    part->setInvitationBody(testItipMessage);

    Composer composer;
    ItipJob job(part.get(), &composer);
    job.setAutoDelete(false);
    QVERIFY(job.exec());

    auto *content = job.content();
    content->assemble();
    QVERIFY(content);

    QCOMPARE(content->contentType(false)->mimeType(), "text/calendar");
    QCOMPARE(content->contentType(false)->name(), QStringLiteral("cal.ics"));
    QCOMPARE(content->contentType(false)->parameter("method"), QStringLiteral("request"));
    QCOMPARE(content->contentType(false)->charset(), "utf-8");
    QVERIFY(content->decodedText().isEmpty());
}

#include "moc_itipjobtest.cpp"