File indexing completed on 2025-03-09 04:54:38

0001 /*
0002   SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 #include "messageviewerutilstest.h"
0008 #include "utils/messageviewerutil.h"
0009 #include <QTest>
0010 QTEST_GUILESS_MAIN(MessageViewerUtilsTest)
0011 
0012 MessageViewerUtilsTest::MessageViewerUtilsTest(QObject *parent)
0013     : QObject(parent)
0014 {
0015 }
0016 
0017 void MessageViewerUtilsTest::shouldExcludeHeader_data()
0018 {
0019     QTest::addColumn<QString>("header");
0020     QTest::addColumn<bool>("exclude");
0021     QTest::newRow("emptylist") << QString() << false;
0022     QTest::newRow("div1") << QStringLiteral("<div><p>ff</p></div></head>") << true;
0023     QTest::newRow("body1") << QStringLiteral("<style>\nbody > div:nth-child(2) {\ndisplay: none !important;\n}\n</style>") << true;
0024 }
0025 
0026 void MessageViewerUtilsTest::shouldExcludeHeader()
0027 {
0028     QFETCH(QString, header);
0029     QFETCH(bool, exclude);
0030     QCOMPARE(MessageViewer::Util::excludeExtraHeader(header), exclude);
0031 }
0032 
0033 void MessageViewerUtilsTest::shouldContainsExternalReferences_data()
0034 {
0035     QTest::addColumn<QString>("filename");
0036     QTest::addColumn<QString>("extraHead");
0037     QTest::addColumn<bool>("hasExternalReference");
0038     QTest::newRow("noimage.txt") << QStringLiteral("noimage.txt") << QString() << false;
0039     QTest::newRow("image.txt") << QStringLiteral("image.txt") << QString() << true;
0040     QTest::newRow("image2.txt") << QStringLiteral("image2.txt") << QString() << true;
0041     QTest::newRow("noimage2.txt") << QStringLiteral("noimage2.txt") << QString() << false;
0042     QTest::newRow("noimage3.txt") << QStringLiteral("noimage3.txt") << QString() << false;
0043     //    before
0044     //      PASS   : MessageViewerUtilsTest::shouldContainsExternalReferences(noimage.txt)
0045     //      RESULT : MessageViewerUtilsTest::shouldContainsExternalReferences():"noimage.txt":
0046     //      0.0015 msecs per iteration (total: 52, iterations: 32768)
0047     //      PASS   : MessageViewerUtilsTest::shouldContainsExternalReferences(image.txt)
0048     //      RESULT : MessageViewerUtilsTest::shouldContainsExternalReferences():"image.txt":
0049     //      0.0018 msecs per iteration (total: 60, iterations: 32768)
0050     //      PASS   : MessageViewerUtilsTest::shouldContainsExternalReferences(image2.txt)
0051     //      RESULT : MessageViewerUtilsTest::shouldContainsExternalReferences():"image2.txt":
0052     //      0.058 msecs per iteration (total: 60, iterations: 1024)
0053     //      PASS   : MessageViewerUtilsTest::shouldContainsExternalReferences(noimage2.txt)
0054     //      RESULT : MessageViewerUtilsTest::shouldContainsExternalReferences():"noimage2.txt":
0055     //      0.060 msecs per iteration (total: 62, iterations: 1024)
0056     //      PASS   : MessageViewerUtilsTest::shouldContainsExternalReferences(noimage3.txt)
0057     //      RESULT : MessageViewerUtilsTest::shouldContainsExternalReferences():"noimage3.txt":
0058 
0059     // AFTER
0060     // RESULT : MessageViewerUtilsTest::shouldContainsExternalReferences():"noimage.txt":
0061     //     0.0014 msecs per iteration (total: 98, iterations: 65536)
0062     // PASS   : MessageViewerUtilsTest::shouldContainsExternalReferences(image.txt)
0063     // RESULT : MessageViewerUtilsTest::shouldContainsExternalReferences():"image.txt":
0064     //     0.0017 msecs per iteration (total: 57, iterations: 32768)
0065     // PASS   : MessageViewerUtilsTest::shouldContainsExternalReferences(image2.txt)
0066     // RESULT : MessageViewerUtilsTest::shouldContainsExternalReferences():"image2.txt":
0067     //     0.0073 msecs per iteration (total: 60, iterations: 8192)
0068     // PASS   : MessageViewerUtilsTest::shouldContainsExternalReferences(noimage2.txt)
0069     // RESULT : MessageViewerUtilsTest::shouldContainsExternalReferences():"noimage2.txt":
0070     //     0.0023 msecs per iteration (total: 78, iterations: 32768)
0071     // PASS   : MessageViewerUtilsTest::shouldContainsExternalReferences(noimage3.txt)
0072     // RESULT : MessageViewerUtilsTest::shouldContainsExternalReferences():"noimage3.txt":
0073     //     0.0023 msecs per iteration (total: 78, iterations: 32768)
0074 }
0075 
0076 void MessageViewerUtilsTest::shouldContainsExternalReferences()
0077 {
0078     QFETCH(QString, filename);
0079     QFETCH(QString, extraHead);
0080     QFETCH(bool, hasExternalReference);
0081     const QString curPath = QStringLiteral(MESSAGEVIEWER_UTIL_DATA_DIR "/");
0082     QFile file(curPath + filename);
0083     QVERIFY(file.open(QIODevice::ReadOnly));
0084     const QString html = QString::fromLatin1(file.readAll());
0085     QBENCHMARK {
0086         QCOMPARE(MessageViewer::Util::containsExternalReferences(html, extraHead), hasExternalReference);
0087     }
0088 }
0089 
0090 void MessageViewerUtilsTest::shouldExtractHtml()
0091 {
0092     QFETCH(QString, input);
0093     QFETCH(MessageViewer::Util::HtmlMessageInfo, output);
0094     const MessageViewer::Util::HtmlMessageInfo processHtml = MessageViewer::Util::processHtml(input);
0095     bool equal = processHtml == output;
0096     if (!equal) {
0097         qDebug() << " processed " << processHtml;
0098         qDebug() << " ref " << output;
0099     }
0100     QVERIFY(equal);
0101 }
0102 
0103 void MessageViewerUtilsTest::shouldExtractHtml_data()
0104 {
0105     QTest::addColumn<QString>("input");
0106     QTest::addColumn<MessageViewer::Util::HtmlMessageInfo>("output");
0107     QTest::newRow("empty") << QString() << MessageViewer::Util::HtmlMessageInfo();
0108     {
0109         const QString input = QStringLiteral("<html><head></head><body>foo</body></html>");
0110         MessageViewer::Util::HtmlMessageInfo output;
0111         output.htmlSource = QStringLiteral("foo");
0112         output.bodyStyle = QStringLiteral("<body>");
0113         QTest::newRow("test1") << input << output;
0114     }
0115     {
0116         const QString input = QStringLiteral("<html><head></head><body>foo</body></html></div>");
0117         MessageViewer::Util::HtmlMessageInfo output;
0118         output.htmlSource = QStringLiteral("foo");
0119         output.bodyStyle = QStringLiteral("<body>");
0120         QTest::newRow("test2") << input << output;
0121     }
0122     {
0123         const QString input = QStringLiteral(
0124             "That's interesting. I don't see new commits or anything relevant to it on the author's releases. I don't actually know why the author uses the "
0125             "other library as they do seem to have similar data... Maybe some other functions that are easier to use.<br><br><br>All the "
0126             "best,<br><br>C<br><br><br>-------- Original Message --------<br>On Mar 3, 2020, 09:56, foo wrote:<blockquote "
0127             "class=\"protonmail_quote\"><br><!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
0128             "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\r\n<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\r\np, li { "
0129             "white-space: pre-wrap; }\r\n</style></head><body>\r\n<p>Hey bla,</p>\r\n<p>&nbsp;</p>\r\n<p>how are things going? Done your "
0130             "PhD?</p>\r\n<p>&nbsp;</p>\r\n<p>On a recent installation I had an issue with the Orthanc-Module, during initialization of the "
0131             "database:</p>\r\n<p><span style=\" font-family:'monospace';\"><br />   from .datetime import DateTime </span><span style=\" "
0132             "font-family:'monospace','Noto Sans';\"><br />'Something' as changed in the setup of timezone data (between December and now so to "
0133             "say).</span></p>\r\n<p><span style=\" font-family:'monospace','Noto Sans';\">To make the story short, this module pytzdata comes from the "
0134             "pypi-package pytzdata and contains basically the same stuff as pytz.</span></p>\r\n<p><span style=\" font-family:'monospace','Noto "
0135             "Sans';\">Except that pendulum and pytzdata is from the same author.</span></p>\r\n<p><span style=\" font-family:'monospace','Noto Sans';\">Do you "
0136             "have an idea why he not uses pytz, as everybody else?</span></p>\r\n<p>&nbsp;</p>\r\n<p>Thanks</p>\r\n<p>&nbsp;</p>\r\n<p>-- </p>\r\n<p>T: "
0137             "@coogor</p>\r\n<p>Matrix: @docb:matrix.org</p>\r\n<p>PGP Fingerprint: 2E7F 3A19 A4A4 844A 3D09 7656 822D EB64 A3BA "
0138             "290D</p>\r\n<p>&nbsp;</p>\r\n<p>http://gnuhealth.ghf2020.org</p></body></html></div>");
0139         MessageViewer::Util::HtmlMessageInfo output;
0140         output.extraHead = QStringLiteral("<meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\r\np, li { white-space: pre-wrap; }\r\n</style>");
0141         output.bodyStyle = QStringLiteral("<body>");
0142         output.htmlSource = QStringLiteral(
0143             "That's interesting. I don't see new commits or anything relevant to it on the author's releases. I don't actually know why the author uses the "
0144             "other library as they do seem to have similar data... Maybe some other functions that are easier to use.<br><br><br>All the "
0145             "best,<br><br>C<br><br><br>-------- Original Message --------<br>On Mar 3, 2020, 09:56, foo wrote:<blockquote "
0146             "class=\"protonmail_quote\"><br><p>Hey bla,</p>\r\n<p>&nbsp;</p>\r\n<p>how are things going? Done your PhD?</p>\r\n<p>&nbsp;</p>\r\n<p>On a recent "
0147             "installation I had an issue with the Orthanc-Module, during initialization of the database:</p>\r\n<p><span style=\" "
0148             "font-family:'monospace';\"><br />   from .datetime import DateTime </span><span style=\" font-family:'monospace','Noto Sans';\"><br />'Something' "
0149             "as changed in the setup of timezone data (between December and now so to say).</span></p>\r\n<p><span style=\" font-family:'monospace','Noto "
0150             "Sans';\">To make the story short, this module pytzdata comes from the pypi-package pytzdata and contains basically the same stuff as "
0151             "pytz.</span></p>\r\n<p><span style=\" font-family:'monospace','Noto Sans';\">Except that pendulum and pytzdata is from the same "
0152             "author.</span></p>\r\n<p><span style=\" font-family:'monospace','Noto Sans';\">Do you have an idea why he not uses pytz, as everybody "
0153             "else?</span></p>\r\n<p>&nbsp;</p>\r\n<p>Thanks</p>\r\n<p>&nbsp;</p>\r\n<p>-- </p>\r\n<p>T: @coogor</p>\r\n<p>Matrix: "
0154             "@docb:matrix.org</p>\r\n<p>PGP Fingerprint: 2E7F 3A19 A4A4 844A 3D09 7656 822D EB64 A3BA "
0155             "290D</p>\r\n<p>&nbsp;</p>\r\n<p>http://gnuhealth.ghf2020.org</p>");
0156         QTest::newRow("bug418482") << input << output;
0157     }
0158     {
0159         const QString input = QStringLiteral(
0160             "HTML REPLY<br>\nSECOND LINE<br>\n-- <br>\n<html><head><meta http-equiv=\"Content-Type\" content=\"text/plain; charset=utf-8\" /></head><body  "
0161             "style=\"overflow-wrap:break-word; word-break: break-word;white-space:pre-wrap;\"><div>You wrote:<blockquote style=\"margin: 0.8ex 0pt 0pt 0.8ex; "
0162             "border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;\">HTML QUOTE\n\nSECOND LINE\n</blockquote></div></body></html>");
0163         MessageViewer::Util::HtmlMessageInfo output;
0164         output.htmlSource = QStringLiteral(
0165             "HTML REPLY<br>\nSECOND LINE<br>\n-- <br>\n<div>You wrote:<blockquote style=\"margin: 0.8ex 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, "
0166             "204); padding-left: 1ex;\">HTML QUOTE\n\nSECOND LINE\n</blockquote></div>");
0167         output.bodyStyle = QStringLiteral("<body  style=\"overflow-wrap:break-word; word-break: break-word;white-space:pre-wrap;\">");
0168         output.extraHead = QStringLiteral("<meta http-equiv=\"Content-Type\" content=\"text/plain; charset=utf-8\" />");
0169         QTest::newRow("bug419949") << input << output;
0170     }
0171     {
0172         // Bug head + div
0173         const QString input = QStringLiteral(
0174             "<html style=\"background: #5555ff;min-height:500px;\">\n<head>\n<style>\nbody div div {display: "
0175             "none;}\n</style>\n<div>\n<p><b>goo<\b></p></div><p>ff</p></head><body></body></html>");
0176         MessageViewer::Util::HtmlMessageInfo output;
0177         output.htmlSource = QString();
0178         output.bodyStyle = QStringLiteral("<body>");
0179         output.extraHead = QString();
0180         QTest::newRow("headdiv") << input << output;
0181     }
0182 }
0183 
0184 void MessageViewerUtilsTest::shouldExtractBodyStyle()
0185 {
0186     QFETCH(QString, input);
0187     QFETCH(QString, output);
0188     QCOMPARE(MessageViewer::Util::parseBodyStyle(input), output);
0189 }
0190 
0191 void MessageViewerUtilsTest::shouldExtractBodyStyle_data()
0192 {
0193     QTest::addColumn<QString>("input");
0194     QTest::addColumn<QString>("output");
0195     QTest::newRow("empty") << QString() << QString();
0196     QTest::newRow("test1") << QStringLiteral("<body  style=\"overflow-wrap:break-word; word-break: break-word;white-space:pre-wrap;\">")
0197                            << QStringLiteral(" style=\"overflow-wrap:break-word;word-break: break-word;\"");
0198 }
0199 
0200 void MessageViewerUtilsTest::shouldExtractHtmlBenchmark()
0201 {
0202     QFETCH(QString, input);
0203     QFETCH(MessageViewer::Util::HtmlMessageInfo, output);
0204     QBENCHMARK {
0205         const MessageViewer::Util::HtmlMessageInfo processHtml = MessageViewer::Util::processHtml(input);
0206         bool equal = processHtml == output;
0207         if (!equal) {
0208             qDebug() << " processed " << processHtml;
0209             qDebug() << " ref " << output;
0210         }
0211         QVERIFY(equal);
0212     }
0213 }
0214 
0215 void MessageViewerUtilsTest::shouldExtractHtmlBenchmark_data()
0216 {
0217     QTest::addColumn<QString>("input");
0218     QTest::addColumn<MessageViewer::Util::HtmlMessageInfo>("output");
0219     QTest::newRow("empty") << QString() << MessageViewer::Util::HtmlMessageInfo();
0220     {
0221         const QString input = QStringLiteral("<html><head></head><body>foo</body></html>");
0222         MessageViewer::Util::HtmlMessageInfo output;
0223         output.htmlSource = QStringLiteral("foo");
0224         output.bodyStyle = QStringLiteral("<body>");
0225         QTest::newRow("test1") << input << output;
0226     }
0227     {
0228         const QString input = QStringLiteral("<html><head></head><body>foo</body></html></div>");
0229         MessageViewer::Util::HtmlMessageInfo output;
0230         output.htmlSource = QStringLiteral("foo");
0231         output.bodyStyle = QStringLiteral("<body>");
0232         QTest::newRow("test2") << input << output;
0233     }
0234     {
0235         const QString input = QStringLiteral(
0236             "That's interesting. I don't see new commits or anything relevant to it on the author's releases. I don't actually know why the author uses the "
0237             "other library as they do seem to have similar data... Maybe some other functions that are easier to use.<br><br><br>All the "
0238             "best,<br><br>C<br><br><br>-------- Original Message --------<br>On Mar 3, 2020, 09:56, foo wrote:<blockquote "
0239             "class=\"protonmail_quote\"><br><!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
0240             "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\r\n<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\r\np, li { "
0241             "white-space: pre-wrap; }\r\n</style></head><body>\r\n<p>Hey bla,</p>\r\n<p>&nbsp;</p>\r\n<p>how are things going? Done your "
0242             "PhD?</p>\r\n<p>&nbsp;</p>\r\n<p>On a recent installation I had an issue with the Orthanc-Module, during initialization of the "
0243             "database:</p>\r\n<p><span style=\" font-family:'monospace';\"><br />   from .datetime import DateTime </span><span style=\" "
0244             "font-family:'monospace','Noto Sans';\"><br />'Something' as changed in the setup of timezone data (between December and now so to "
0245             "say).</span></p>\r\n<p><span style=\" font-family:'monospace','Noto Sans';\">To make the story short, this module pytzdata comes from the "
0246             "pypi-package pytzdata and contains basically the same stuff as pytz.</span></p>\r\n<p><span style=\" font-family:'monospace','Noto "
0247             "Sans';\">Except that pendulum and pytzdata is from the same author.</span></p>\r\n<p><span style=\" font-family:'monospace','Noto Sans';\">Do you "
0248             "have an idea why he not uses pytz, as everybody else?</span></p>\r\n<p>&nbsp;</p>\r\n<p>Thanks</p>\r\n<p>&nbsp;</p>\r\n<p>-- </p>\r\n<p>T: "
0249             "@coogor</p>\r\n<p>Matrix: @docb:matrix.org</p>\r\n<p>PGP Fingerprint: 2E7F 3A19 A4A4 844A 3D09 7656 822D EB64 A3BA "
0250             "290D</p>\r\n<p>&nbsp;</p>\r\n<p>http://gnuhealth.ghf2020.org</p></body></html></div>");
0251         MessageViewer::Util::HtmlMessageInfo output;
0252         output.extraHead = QStringLiteral("<meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\r\np, li { white-space: pre-wrap; }\r\n</style>");
0253         output.bodyStyle = QStringLiteral("<body>");
0254 
0255         output.htmlSource = QStringLiteral(
0256             "That's interesting. I don't see new commits or anything relevant to it on the author's releases. I don't actually know why the author uses the "
0257             "other library as they do seem to have similar data... Maybe some other functions that are easier to use.<br><br><br>All the "
0258             "best,<br><br>C<br><br><br>-------- Original Message --------<br>On Mar 3, 2020, 09:56, foo wrote:<blockquote "
0259             "class=\"protonmail_quote\"><br><p>Hey bla,</p>\r\n<p>&nbsp;</p>\r\n<p>how are things going? Done your PhD?</p>\r\n<p>&nbsp;</p>\r\n<p>On a recent "
0260             "installation I had an issue with the Orthanc-Module, during initialization of the database:</p>\r\n<p><span style=\" "
0261             "font-family:'monospace';\"><br />   from .datetime import DateTime </span><span style=\" font-family:'monospace','Noto Sans';\"><br />'Something' "
0262             "as changed in the setup of timezone data (between December and now so to say).</span></p>\r\n<p><span style=\" font-family:'monospace','Noto "
0263             "Sans';\">To make the story short, this module pytzdata comes from the pypi-package pytzdata and contains basically the same stuff as "
0264             "pytz.</span></p>\r\n<p><span style=\" font-family:'monospace','Noto Sans';\">Except that pendulum and pytzdata is from the same "
0265             "author.</span></p>\r\n<p><span style=\" font-family:'monospace','Noto Sans';\">Do you have an idea why he not uses pytz, as everybody "
0266             "else?</span></p>\r\n<p>&nbsp;</p>\r\n<p>Thanks</p>\r\n<p>&nbsp;</p>\r\n<p>-- </p>\r\n<p>T: @coogor</p>\r\n<p>Matrix: "
0267             "@docb:matrix.org</p>\r\n<p>PGP Fingerprint: 2E7F 3A19 A4A4 844A 3D09 7656 822D EB64 A3BA "
0268             "290D</p>\r\n<p>&nbsp;</p>\r\n<p>http://gnuhealth.ghf2020.org</p>");
0269         QTest::newRow("bug418482") << input << output;
0270     }
0271     {
0272         const QString input = QStringLiteral(
0273             "HTML REPLY<br>\nSECOND LINE<br>\n-- <br>\n<html><head><meta http-equiv=\"Content-Type\" content=\"text/plain; charset=utf-8\" /></head><body  "
0274             "style=\"overflow-wrap:break-word; word-break: break-word;white-space:pre-wrap;\"><div>You wrote:<blockquote style=\"margin: 0.8ex 0pt 0pt 0.8ex; "
0275             "border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;\">HTML QUOTE\n\nSECOND LINE\n</blockquote></div></body></html>");
0276         MessageViewer::Util::HtmlMessageInfo output;
0277         output.htmlSource = QStringLiteral(
0278             "HTML REPLY<br>\nSECOND LINE<br>\n-- <br>\n<div>You wrote:<blockquote style=\"margin: 0.8ex 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, "
0279             "204); padding-left: 1ex;\">HTML QUOTE\n\nSECOND LINE\n</blockquote></div>");
0280         output.bodyStyle = QStringLiteral("<body  style=\"overflow-wrap:break-word; word-break: break-word;white-space:pre-wrap;\">");
0281         output.extraHead = QStringLiteral("<meta http-equiv=\"Content-Type\" content=\"text/plain; charset=utf-8\" />");
0282         QTest::newRow("bug419949") << input << output;
0283     }
0284     // Before
0285     // RESULT : MessageViewerUtilsTest::shouldExtractHtml():"empty":
0286     //     0.099 msecs per iteration (total: 51, iterations: 512)
0287     // PASS   : MessageViewerUtilsTest::shouldExtractHtml(test1)
0288     // RESULT : MessageViewerUtilsTest::shouldExtractHtml():"test1":
0289     //     0.10 msecs per iteration (total: 54, iterations: 512)
0290     // PASS   : MessageViewerUtilsTest::shouldExtractHtml(bug418482)
0291     // RESULT : MessageViewerUtilsTest::shouldExtractHtml():"bug418482":
0292     //     0.11 msecs per iteration (total: 58, iterations: 512)
0293     // PASS   : MessageViewerUtilsTest::shouldExtractHtml(bug419949)
0294     // RESULT : MessageViewerUtilsTest::shouldExtractHtml():"bug419949":
0295     //     0.10 msecs per iteration (total: 54, iterations: 512)
0296 
0297     // After
0298     // RESULT : MessageViewerUtilsTest::shouldExtractHtml():"empty":
0299     //     0.0014 msecs per iteration (total: 95, iterations: 65536)
0300     // PASS   : MessageViewerUtilsTest::shouldExtractHtml(test1)
0301     // RESULT : MessageViewerUtilsTest::shouldExtractHtml():"test1":
0302     //     0.0031 msecs per iteration (total: 51, iterations: 16384)
0303     // PASS   : MessageViewerUtilsTest::shouldExtractHtml(test2)
0304     // RESULT : MessageViewerUtilsTest::shouldExtractHtml():"test2":
0305     //     0.0031 msecs per iteration (total: 51, iterations: 16384)
0306     // PASS   : MessageViewerUtilsTest::shouldExtractHtml(bug418482)
0307     // RESULT : MessageViewerUtilsTest::shouldExtractHtml():"bug418482":
0308     //     0.0095 msecs per iteration (total: 78, iterations: 8192)
0309     // PASS   : MessageViewerUtilsTest::shouldExtractHtml(bug419949)
0310     // RESULT : MessageViewerUtilsTest::shouldExtractHtml():"bug419949":
0311     //     0.0046 msecs per iteration (total: 76, iterations: 16384)
0312 }
0313 
0314 void MessageViewerUtilsTest::shouldUseCorrectCodec()
0315 {
0316     QFETCH(QByteArray, currentCodec);
0317     QFETCH(QByteArray, data);
0318     QFETCH(QByteArray, codecResult);
0319     QBENCHMARK {
0320         QCOMPARE(MessageViewer::Util::htmlCodec(data, currentCodec), codecResult);
0321     }
0322     // BEFORE
0323     // PASS   : MessageViewerUtilsTest::shouldUseCorrectCodec(empty UTF-8)
0324     // RESULT : MessageViewerUtilsTest::shouldUseCorrectCodec():"empty UTF-8":
0325     //     0.00014 msecs per iteration (total: 76, iterations: 524288)
0326     // PASS   : MessageViewerUtilsTest::shouldUseCorrectCodec(empty2 UTF-8)
0327     // RESULT : MessageViewerUtilsTest::shouldUseCorrectCodec():"empty2 UTF-8":
0328     //     0.00014 msecs per iteration (total: 76, iterations: 524288)
0329     // PASS   : MessageViewerUtilsTest::shouldUseCorrectCodec(codec windows-1252)
0330     // RESULT : MessageViewerUtilsTest::shouldUseCorrectCodec():"codec windows-1252":
0331     //     0.00016 msecs per iteration (total: 84, iterations: 524288)
0332     // PASS   : MessageViewerUtilsTest::shouldUseCorrectCodec(codec windows-1252 with meta charset)
0333     // RESULT : MessageViewerUtilsTest::shouldUseCorrectCodec():"codec windows-1252 with meta charset":
0334     //     0.00020 msecs per iteration (total: 55, iterations: 262144)
0335     // PASS   : MessageViewerUtilsTest::shouldUseCorrectCodec(codec windows-1252 with meta charset-2)
0336     // RESULT : MessageViewerUtilsTest::shouldUseCorrectCodec():"codec windows-1252 with meta charset-2":
0337     //     0.00026 msecs per iteration (total: 70, iterations: 262144)
0338 }
0339 
0340 void MessageViewerUtilsTest::shouldUseCorrectCodec_data()
0341 {
0342     QTest::addColumn<QByteArray>("currentCodec");
0343     QTest::addColumn<QByteArray>("data");
0344     QTest::addColumn<QByteArray>("codecResult");
0345     QTest::newRow("empty UTF-8") << QByteArray("UTF-8") << QByteArray() << QByteArray("UTF-8");
0346     QTest::newRow("empty2 UTF-8") << QByteArray("UTF-8") << QByteArray("foo bla blo") << QByteArray("UTF-8");
0347     QTest::newRow("us-ascii") << QByteArray("us-ascii") << QByteArray("foo bla blo") << QByteArray("iso-8859-1");
0348     QTest::newRow("codec windows-1252") << QByteArray("windows-1252") << QByteArray("foo bla blo") << QByteArray("windows-1252");
0349     QTest::newRow("codec windows-1252 with meta charset")
0350         << QByteArray("windows-1252") << QByteArray("foo bla blo <meta charset=\"utf-8\">") << QByteArray("UTF-8");
0351     QTest::newRow("codec windows-1252 with meta charset-2")
0352         << QByteArray("windows-1252") << QByteArray("foo bla blo <meta charset=UTF-8>") << QByteArray("UTF-8");
0353 }
0354 
0355 #include "moc_messageviewerutilstest.cpp"