Changeset View
Changeset View
Standalone View
Standalone View
templateparser/autotests/templateparserjobtest.cpp
Show First 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | 64 | { | |||
---|---|---|---|---|---|
98 | QVERIFY(!parser->d->mOtp->plainTextContent().isEmpty()); | 98 | QVERIFY(!parser->d->mOtp->plainTextContent().isEmpty()); | ||
99 | 99 | | |||
100 | const QString convertedHtmlContent = parser->htmlMessageText(false, TemplateParser::TemplateParserJob::NoSelectionAllowed); | 100 | const QString convertedHtmlContent = parser->htmlMessageText(false, TemplateParser::TemplateParserJob::NoSelectionAllowed); | ||
101 | QVERIFY(!convertedHtmlContent.isEmpty()); | 101 | QVERIFY(!convertedHtmlContent.isEmpty()); | ||
102 | 102 | | |||
103 | QCOMPARE(convertedHtmlContent, referenceData); | 103 | QCOMPARE(convertedHtmlContent, referenceData); | ||
104 | } | 104 | } | ||
105 | 105 | | |||
106 | void TemplateParserJobTest::test_replyHtml_data() | ||||
107 | { | ||||
108 | QTest::addColumn<QString>("mailFileName"); | ||||
109 | QTest::addColumn<QString>("referenceFileName"); | ||||
110 | | ||||
111 | QDir dir(QStringLiteral(MAIL_DATA_DIR)); | ||||
112 | const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); | ||||
113 | foreach (const QString &file, l) { | ||||
114 | const QString expectedFile = dir.path() + QLatin1Char('/') + file + QStringLiteral(".html.reply"); | ||||
115 | if (!QFile::exists(expectedFile)) { | ||||
116 | continue; | ||||
117 | } | ||||
118 | QTest::newRow(file.toLatin1().constData()) << QString(dir.path() + QLatin1Char('/') + file) << expectedFile; | ||||
119 | } | ||||
120 | } | ||||
121 | | ||||
122 | void TemplateParserJobTest::test_replyHtml() | ||||
123 | { | ||||
124 | QFETCH(QString, mailFileName); | ||||
125 | QFETCH(QString, referenceFileName); | ||||
126 | | ||||
127 | // load input mail | ||||
128 | QFile mailFile(mailFileName); | ||||
129 | QVERIFY(mailFile.open(QIODevice::ReadOnly)); | ||||
130 | const QByteArray mailData = KMime::CRLFtoLF(mailFile.readAll()); | ||||
131 | QVERIFY(!mailData.isEmpty()); | ||||
132 | KMime::Message::Ptr msg(new KMime::Message); | ||||
133 | KMime::Message::Ptr origMsg(new KMime::Message); | ||||
134 | origMsg->setContent(mailData); | ||||
135 | origMsg->parse(); | ||||
136 | | ||||
137 | // load expected result | ||||
138 | QFile referenceFile(referenceFileName); | ||||
139 | QVERIFY(referenceFile.open(QIODevice::ReadOnly)); | ||||
140 | const QByteArray referenceRawData = KMime::CRLFtoLF(referenceFile.readAll()); | ||||
141 | const QString referenceData = QString::fromLatin1(referenceRawData); | ||||
142 | QVERIFY(!referenceData.isEmpty()); | ||||
143 | | ||||
144 | TemplateParser::TemplateParserJob *parser = new TemplateParser::TemplateParserJob(msg, TemplateParser::TemplateParserJob::NewMessage); | ||||
145 | KIdentityManagement::IdentityManager *identMan = new KIdentityManagement::IdentityManager; | ||||
146 | parser->setIdentityManager(identMan); | ||||
147 | | ||||
148 | parser->d->mOrigMsg = origMsg; | ||||
149 | | ||||
150 | QSignalSpy spy(parser, &TemplateParser::TemplateParserJob::parsingDone); | ||||
151 | parser->processWithTemplate(QString()); | ||||
152 | QVERIFY(spy.wait()); | ||||
153 | | ||||
154 | QString convertedHtmlContent = parser->htmlMessageText(false, TemplateParser::TemplateParserJob::NoSelectionAllowed); | ||||
155 | QVERIFY(!convertedHtmlContent.isEmpty()); | ||||
156 | | ||||
157 | // referenceData is read from a file and most text editors add a \n at the end of the last line | ||||
158 | if (!convertedHtmlContent.endsWith(QStringLiteral("\n"))) { | ||||
159 | convertedHtmlContent += QStringLiteral("\n"); | ||||
160 | } | ||||
161 | | ||||
162 | QCOMPARE(convertedHtmlContent, referenceData); | ||||
163 | } | ||||
164 | | ||||
165 | | ||||
106 | void TemplateParserJobTest::test_replyPlain_data() | 166 | void TemplateParserJobTest::test_replyPlain_data() | ||
107 | { | 167 | { | ||
108 | QTest::addColumn<QString>("mailFileName"); | 168 | QTest::addColumn<QString>("mailFileName"); | ||
109 | QTest::addColumn<QString>("referenceFileName"); | 169 | QTest::addColumn<QString>("referenceFileName"); | ||
110 | 170 | | |||
111 | QDir dir(QStringLiteral(MAIL_DATA_DIR)); | 171 | QDir dir(QStringLiteral(MAIL_DATA_DIR)); | ||
112 | const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); | 172 | const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); | ||
113 | foreach (const QString &file, l) { | 173 | foreach (const QString &file, l) { | ||
Show All 29 Lines | 183 | { | |||
143 | 203 | | |||
144 | TemplateParser::TemplateParserJob *parser = new TemplateParser::TemplateParserJob(msg, TemplateParser::TemplateParserJob::Reply); | 204 | TemplateParser::TemplateParserJob *parser = new TemplateParser::TemplateParserJob(msg, TemplateParser::TemplateParserJob::Reply); | ||
145 | parser->d->mOrigMsg = origMsg; | 205 | parser->d->mOrigMsg = origMsg; | ||
146 | 206 | | |||
147 | QSignalSpy spy(parser, &TemplateParser::TemplateParserJob::parsingDone); | 207 | QSignalSpy spy(parser, &TemplateParser::TemplateParserJob::parsingDone); | ||
148 | parser->processWithTemplate(QString()); | 208 | parser->processWithTemplate(QString()); | ||
149 | QVERIFY(spy.wait()); | 209 | QVERIFY(spy.wait()); | ||
150 | 210 | | |||
151 | const QString convertedHtmlContent = parser->plainMessageText(false, TemplateParser::TemplateParserJob::NoSelectionAllowed); | 211 | const QString convertedPlainTextContent = parser->plainMessageText(false, TemplateParser::TemplateParserJob::NoSelectionAllowed); | ||
152 | 212 | | |||
153 | QCOMPARE(convertedHtmlContent, referenceData); | 213 | QCOMPARE(convertedPlainTextContent, referenceData); | ||
154 | } | 214 | } | ||
155 | 215 | | |||
156 | void TemplateParserJobTest::test_processWithTemplatesForBody_data() | 216 | void TemplateParserJobTest::test_processWithTemplatesForBody_data() | ||
157 | { | 217 | { | ||
158 | QTest::addColumn<QString>("command"); | 218 | QTest::addColumn<QString>("command"); | ||
159 | QTest::addColumn<QString>("text"); | 219 | QTest::addColumn<QString>("text"); | ||
160 | QTest::addColumn<QString>("expected"); | 220 | QTest::addColumn<QString>("expected"); | ||
161 | QTest::addColumn<QString>("selection"); | 221 | QTest::addColumn<QString>("selection"); | ||
▲ Show 20 Lines • Show All 180 Lines • Show Last 20 Lines |