multipartjobtest.cpp 3.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
  Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>

  This library is free software; you can redistribute it and/or modify it
  under the terms of the GNU Library General Public License as published by
  the Free Software Foundation; either version 2 of the License, or (at your
  option) any later version.

  This library is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
  License for more details.

  You should have received a copy of the GNU Library General Public License
  along with this library; see the file COPYING.LIB.  If not, write to the
  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  02110-1301, USA.
*/

#include "multipartjobtest.h"

#include <QDebug>
Laurent Montel's avatar
Laurent Montel committed
23
#include <QTest>
24
25
26
27
28
29
30
31
32
33
34
35
36
37

#include <kmime/kmime_content.h>
using namespace KMime;

#include <MessageComposer/Composer>
#include <MessageComposer/GlobalPart>
#include <MessageComposer/SinglepartJob>
#include <MessageComposer/MultipartJob>
using namespace MessageComposer;

QTEST_MAIN(MultipartJobTest)

void MultipartJobTest::testMultipartMixed()
{
38
39
    Composer composer;
    MultipartJob *mjob = new MultipartJob(&composer);
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
    mjob->setMultipartSubtype("mixed");

    QByteArray data1("one");
    QByteArray data2("two");
    QByteArray type1("text/plain");
    QByteArray type2("application/x-mors-ontologica");

    {
        SinglepartJob *cjob = new SinglepartJob(mjob);
        cjob->setData(data1);
        cjob->contentType()->setMimeType(type1);
    }

    {
        SinglepartJob *cjob = new SinglepartJob(mjob);
        cjob->setData(data2);
        cjob->contentType()->setMimeType(type2);
    }

    QVERIFY(mjob->exec());
    Content *result = mjob->content();
    result->assemble();
    qDebug() << result->encodedContent();

    QVERIFY(result->contentType(false));
65
    QCOMPARE(result->contentType(false)->mimeType(), QByteArray("multipart/mixed"));
66
67
68
69
70
71
    QCOMPARE(result->contents().count(), 2);

    {
        Content *c = result->contents().at(0);
        QCOMPARE(c->body(), data1);
        QVERIFY(c->contentType(false));
72
        QCOMPARE(c->contentType(false)->mimeType(), type1);
73
74
75
76
77
78
    }

    {
        Content *c = result->contents().at(1);
        QCOMPARE(c->body(), data2);
        QVERIFY(c->contentType(false));
79
        QCOMPARE(c->contentType(false)->mimeType(), type2);
80
81
82
83
84
85
86
    }
}

void MultipartJobTest::test8BitPropagation()
{
    // If a subpart is 8bit, its parent must be 8bit too.

87
88
89
    Composer composer;
    composer.globalPart()->set8BitAllowed(true);
    MultipartJob *mjob = new MultipartJob(&composer);
90
91
92
93
94
95
96
97
98
99
100
101
    mjob->setMultipartSubtype("mixed");
    MultipartJob *mjob2 = new MultipartJob(mjob);
    mjob2->setMultipartSubtype("mixed");
    SinglepartJob *cjob = new SinglepartJob(mjob2);
    QByteArray data("time is so short and I'm sure there must be something more");
    cjob->setData(data);
    cjob->contentTransferEncoding()->setEncoding(Headers::CE8Bit);
    QVERIFY(mjob->exec());
    Content *content = mjob->content();
    content->assemble();
    qDebug() << content->encodedContent();
    QVERIFY(content->contentTransferEncoding(false));
102
    QCOMPARE(content->contentTransferEncoding(false)->encoding(), Headers::CE8Bit);
Laurent Montel's avatar
Laurent Montel committed
103
    delete mjob;
104
}