Changeset View
Changeset View
Standalone View
Standalone View
templateparser/autotests/templateparserjobtest.cpp
Show First 20 Lines • Show All 213 Lines • ▼ Show 20 Line(s) | 202 | // QCOMPARE(msg->contents().size(), 0); | |||
---|---|---|---|---|---|
214 | parser->processWithTemplate(QString()); | 214 | parser->processWithTemplate(QString()); | ||
215 | QVERIFY(spy.wait()); | 215 | QVERIFY(spy.wait()); | ||
216 | 216 | | |||
217 | const QString convertedPlainTextContent = parser->plainMessageText(false, TemplateParser::TemplateParserJob::NoSelectionAllowed); | 217 | const QString convertedPlainTextContent = parser->plainMessageText(false, TemplateParser::TemplateParserJob::NoSelectionAllowed); | ||
218 | 218 | | |||
219 | QCOMPARE(convertedPlainTextContent, referenceData); | 219 | QCOMPARE(convertedPlainTextContent, referenceData); | ||
220 | } | 220 | } | ||
221 | 221 | | |||
222 | void TemplateParserJobTest::test_forwardPlain_data() | ||||
223 | { | ||||
224 | QTest::addColumn<QString>("mailFileName"); | ||||
225 | QTest::addColumn<QString>("referenceFileName"); | ||||
226 | | ||||
227 | QDir dir(QStringLiteral(MAIL_DATA_DIR)); | ||||
228 | const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); | ||||
229 | foreach (const QString &file, l) { | ||||
230 | const QString expectedFile = dir.path() + QLatin1Char('/') + file + QStringLiteral(".plain.reply"); | ||||
231 | if (!QFile::exists(expectedFile)) { | ||||
232 | continue; | ||||
233 | } | ||||
234 | QTest::newRow(file.toLatin1().constData()) << QString(dir.path() + QLatin1Char('/') + file) << expectedFile; | ||||
235 | } | ||||
236 | } | ||||
237 | | ||||
238 | void TemplateParserJobTest::test_forwardPlain() | ||||
239 | { | ||||
240 | QFETCH(QString, mailFileName); | ||||
241 | QFETCH(QString, referenceFileName); | ||||
242 | | ||||
243 | // load input mail | ||||
244 | QFile mailFile(mailFileName); | ||||
245 | QVERIFY(mailFile.open(QIODevice::ReadOnly)); | ||||
246 | const QByteArray mailData = KMime::CRLFtoLF(mailFile.readAll()); | ||||
247 | QVERIFY(!mailData.isEmpty()); | ||||
248 | KMime::Message::Ptr msg(new KMime::Message); | ||||
249 | KMime::Message::Ptr origMsg(new KMime::Message); | ||||
250 | origMsg->setContent(mailData); | ||||
251 | origMsg->parse(); | ||||
252 | | ||||
253 | // load expected result | ||||
254 | QFile referenceFile(referenceFileName); | ||||
255 | QVERIFY(referenceFile.open(QIODevice::ReadOnly)); | ||||
256 | const QByteArray referenceRawData = KMime::CRLFtoLF(referenceFile.readAll()); | ||||
257 | const QString referenceData = QString::fromLatin1(referenceRawData); | ||||
258 | QVERIFY(!referenceData.isEmpty()); | ||||
259 | | ||||
260 | TemplateParser::TemplateParserJob *parser = new TemplateParser::TemplateParserJob(msg, TemplateParser::TemplateParserJob::Forward); | ||||
261 | parser->d->mOrigMsg = origMsg; | ||||
262 | | ||||
263 | QSignalSpy spy(parser, &TemplateParser::TemplateParserJob::parsingDone); | ||||
264 | parser->processWithTemplate(QString()); | ||||
265 | QVERIFY(spy.wait()); | ||||
266 | | ||||
267 | const QString convertedPlainTextContent = parser->plainMessageText(false, TemplateParser::TemplateParserJob::NoSelectionAllowed); | ||||
268 | | ||||
269 | QCOMPARE(convertedPlainTextContent, referenceData); | ||||
270 | } | ||||
271 | | ||||
272 | void TemplateParserJobTest::test_forwardHtml_data() | ||||
273 | { | ||||
274 | QTest::addColumn<QString>("mailFileName"); | ||||
275 | QTest::addColumn<QString>("referenceFileName"); | ||||
276 | | ||||
277 | QDir dir(QStringLiteral(MAIL_DATA_DIR)); | ||||
278 | const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); | ||||
279 | foreach (const QString &file, l) { | ||||
280 | const QString expectedFile = dir.path() + QLatin1Char('/') + file + QStringLiteral(".html.reply"); | ||||
281 | if (!QFile::exists(expectedFile)) { | ||||
282 | continue; | ||||
283 | } | ||||
284 | QTest::newRow(file.toLatin1().constData()) << QString(dir.path() + QLatin1Char('/') + file) << expectedFile; | ||||
285 | } | ||||
286 | } | ||||
287 | | ||||
288 | void TemplateParserJobTest::test_forwardHtml() | ||||
289 | { | ||||
290 | QFETCH(QString, mailFileName); | ||||
291 | QFETCH(QString, referenceFileName); | ||||
292 | | ||||
293 | // load input mail | ||||
294 | QFile mailFile(mailFileName); | ||||
295 | QVERIFY(mailFile.open(QIODevice::ReadOnly)); | ||||
296 | const QByteArray mailData = KMime::CRLFtoLF(mailFile.readAll()); | ||||
297 | QVERIFY(!mailData.isEmpty()); | ||||
298 | KMime::Message::Ptr msg(new KMime::Message); | ||||
299 | KMime::Message::Ptr origMsg(new KMime::Message); | ||||
300 | origMsg->setContent(mailData); | ||||
301 | origMsg->parse(); | ||||
302 | | ||||
303 | // load expected result | ||||
304 | QFile referenceFile(referenceFileName); | ||||
305 | QVERIFY(referenceFile.open(QIODevice::ReadOnly)); | ||||
306 | const QByteArray referenceRawData = KMime::CRLFtoLF(referenceFile.readAll()); | ||||
307 | const QString referenceData = QString::fromLatin1(referenceRawData); | ||||
308 | QVERIFY(!referenceData.isEmpty()); | ||||
309 | | ||||
310 | TemplateParser::TemplateParserJob *parser = new TemplateParser::TemplateParserJob(msg, TemplateParser::TemplateParserJob::Forward); | ||||
311 | parser->d->mOrigMsg = origMsg; | ||||
312 | | ||||
313 | QSignalSpy spy(parser, &TemplateParser::TemplateParserJob::parsingDone); | ||||
314 | parser->processWithTemplate(QString()); | ||||
315 | QVERIFY(spy.wait()); | ||||
316 | | ||||
317 | QString convertedHtmlContent = parser->htmlMessageText(false, TemplateParser::TemplateParserJob::NoSelectionAllowed); | ||||
318 | // referenceData is read from a file and most text editors add a \n at the end of the last line | ||||
319 | if (!convertedHtmlContent.endsWith(QStringLiteral("\n"))) { | ||||
320 | convertedHtmlContent += QStringLiteral("\n"); | ||||
321 | } | ||||
322 | | ||||
323 | QCOMPARE(convertedHtmlContent, referenceData); | ||||
324 | } | ||||
325 | | ||||
326 | void TemplateParserJobTest::test_forwardedAttachments_data() | ||||
327 | { | ||||
328 | QTest::addColumn<QString>("mailFileName"); | ||||
329 | QTest::addColumn<QString>("referenceFileName"); | ||||
330 | | ||||
331 | QDir dir(QStringLiteral(MAIL_DATA_DIR)); | ||||
332 | const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); | ||||
333 | foreach (const QString &file, l) { | ||||
334 | if (!QFile::exists(dir.path() + QLatin1Char('/') + file + QStringLiteral(".html.reply"))) { | ||||
335 | continue; | ||||
336 | } | ||||
337 | QString expectedFile = dir.path() + QLatin1Char('/') + file + QStringLiteral(".forwarded.mbox"); | ||||
338 | QTest::newRow(file.toLatin1().constData()) << QString(dir.path() + QLatin1Char('/') + file) << expectedFile; | ||||
339 | } | ||||
340 | } | ||||
341 | | ||||
342 | void TemplateParserJobTest::test_forwardedAttachments() | ||||
343 | { | ||||
344 | QFETCH(QString, mailFileName); | ||||
345 | QFETCH(QString, referenceFileName); | ||||
346 | | ||||
347 | // load input mail | ||||
348 | QFile mailFile(mailFileName); | ||||
349 | QVERIFY(mailFile.open(QIODevice::ReadOnly)); | ||||
350 | const QByteArray mailData = KMime::CRLFtoLF(mailFile.readAll()); | ||||
351 | QVERIFY(!mailData.isEmpty()); | ||||
352 | KMime::Message::Ptr msg(new KMime::Message); | ||||
353 | KMime::Message::Ptr origMsg(new KMime::Message); | ||||
354 | origMsg->setContent(mailData); | ||||
355 | origMsg->parse(); | ||||
356 | | ||||
357 | bool referenceExists = QFile::exists(referenceFileName); | ||||
358 | | ||||
359 | TemplateParser::TemplateParserJob *parser = new TemplateParser::TemplateParserJob(msg, TemplateParser::TemplateParserJob::Forward); | ||||
360 | parser->d->mOrigMsg = origMsg; | ||||
361 | | ||||
362 | QSignalSpy spy(parser, &TemplateParser::TemplateParserJob::parsingDone); | ||||
363 | parser->processWithTemplate(QString()); | ||||
364 | QVERIFY(spy.wait()); | ||||
365 | | ||||
366 | if (referenceExists) { | ||||
367 | QFile referenceFile(referenceFileName); | ||||
368 | QVERIFY(referenceFile.open(QIODevice::ReadOnly)); | ||||
369 | const QByteArray referenceRawData = KMime::CRLFtoLF(referenceFile.readAll()); | ||||
370 | const KMime::Message::Ptr referenceMsg(new KMime::Message); | ||||
371 | referenceMsg->setContent(referenceRawData); | ||||
372 | referenceMsg->parse(); | ||||
373 | | ||||
374 | QCOMPARE(msg->contents().size(), referenceMsg->contents().size()); | ||||
375 | for (int i=1; i < msg->contents().size(); i++) { | ||||
376 | QCOMPARE(msg->contents()[i]->encodedContent(), referenceMsg->contents()[i]->encodedContent()); | ||||
377 | } | ||||
378 | } else { | ||||
379 | QCOMPARE(msg->contents().size(), 0); | ||||
380 | } | ||||
381 | | ||||
382 | } | ||||
383 | | ||||
222 | void TemplateParserJobTest::test_processWithTemplatesForBody_data() | 384 | void TemplateParserJobTest::test_processWithTemplatesForBody_data() | ||
223 | { | 385 | { | ||
224 | QTest::addColumn<QString>("command"); | 386 | QTest::addColumn<QString>("command"); | ||
225 | QTest::addColumn<QString>("text"); | 387 | QTest::addColumn<QString>("text"); | ||
226 | QTest::addColumn<QString>("expected"); | 388 | QTest::addColumn<QString>("expected"); | ||
227 | QTest::addColumn<QString>("selection"); | 389 | QTest::addColumn<QString>("selection"); | ||
228 | 390 | | |||
229 | QTest::newRow("%OTEXT") << "%OTEXT" << "Original text.\nLine two." << "Original text.\nLine two." << ""; | 391 | QTest::newRow("%OTEXT") << "%OTEXT" << "Original text.\nLine two." << "Original text.\nLine two." << ""; | ||
▲ Show 20 Lines • Show All 178 Lines • Show Last 20 Lines |