diff --git a/messageviewer/autotests/viewertest.cpp b/messageviewer/autotests/viewertest.cpp index 597fbea6..27677ca2 100644 --- a/messageviewer/autotests/viewertest.cpp +++ b/messageviewer/autotests/viewertest.cpp @@ -1,96 +1,121 @@ /* Copyright (c) 2014-2016 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "viewertest.h" #include #include "messageviewer/viewer.h" #include #include ViewerTest::ViewerTest() { } void ViewerTest::shouldHaveDefaultValuesOnCreation() { MessageViewer::Viewer *viewer = new MessageViewer::Viewer(0, 0, new KActionCollection(this)); viewer->show(); QTest::qWaitForWindowExposed(viewer); QWidget *mViewer = viewer->findChild(QStringLiteral("mViewer")); QVERIFY(mViewer); QCOMPARE(mViewer->isVisible(), true); QWidget *sliderContainer = viewer->findChild(QStringLiteral("slidercontainer")); QVERIFY(sliderContainer); QCOMPARE(sliderContainer->isVisible(), false); QWidget *colorBar = viewer->findChild(QStringLiteral("mColorBar")); QVERIFY(colorBar); QWidget *scandetectionWidget = viewer->findChild(QStringLiteral("scandetectionwarning")); QVERIFY(scandetectionWidget); QCOMPARE(scandetectionWidget->isVisible(), false); QWidget *openattachementfolderwidget = viewer->findChild(QStringLiteral("openattachementfolderwidget")); QVERIFY(openattachementfolderwidget); QCOMPARE(openattachementfolderwidget->isVisible(), false); QVERIFY(viewer->toggleFixFontAction()); QVERIFY(viewer->toggleMimePartTreeAction()); QVERIFY(viewer->selectAllAction()); QVERIFY(viewer->copyURLAction()); QVERIFY(viewer->copyAction()); QVERIFY(viewer->urlOpenAction()); QVERIFY(viewer->speakTextAction()); QVERIFY(viewer->copyImageLocation()); QVERIFY(viewer->viewSourceAction()); QVERIFY(viewer->findInMessageAction()); QVERIFY(viewer->saveAsAction()); QVERIFY(viewer->saveMessageDisplayFormatAction()); QVERIFY(viewer->resetMessageDisplayFormatAction()); QVERIFY(viewer->urlClicked().isEmpty()); QVERIFY(viewer->imageUrlClicked().isEmpty()); QCOMPARE(viewer->isFixedFont(), false); QVERIFY(viewer->shareServiceUrlMenu()); delete viewer; } -void ViewerTest::shouldDisplayMessage() -{ - QByteArray data = +static const char s_mail1[] = "From: Konqui \n" "To: Friends \n" "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n" "Subject: Sample message\n" "MIME-Version: 1.0\n" "Content-type: text/plain; charset=us-ascii\n" "\n" "\n" "This is a test message.\n" "\n"; - KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); - msgPtr->setContent(data); +static const char s_mail2[] = + "From: David Faure \n" + "To: Friends \n" + "Date: Sun, 31 Aug 2016 23:56:48 +0200 (CEST)\n" + "Subject: Second mail\n" + "MIME-Version: 1.0\n" + "Content-type: text/plain; charset=\"us-ascii\"\n" + "\n" + "\n" + "This is the second message.\n" + "\n"; + +KMime::Message::Ptr createMsg(const char* data) +{ + KMime::Message::Ptr msgPtr(new KMime::Message()); + msgPtr->setContent(QByteArray(data)); msgPtr->parse(); + return msgPtr; +} +void ViewerTest::shouldDisplayMessage() +{ MessageViewer::Viewer viewer(0, 0, new KActionCollection(this)); - viewer.setMessage(msgPtr, MimeTreeParser::Force); + viewer.setMessage(createMsg(s_mail1), MimeTreeParser::Force); // not sure what to check, but at least we check it neither crashes nor hangs + // TODO: retrieve message text and check it +} + +void ViewerTest::shouldSwitchToAnotherMessage() +{ + MessageViewer::Viewer viewer(0, 0, new KActionCollection(this)); + viewer.setMessage(createMsg(s_mail1), MimeTreeParser::Force); + + viewer.setMessage(createMsg(s_mail2), MimeTreeParser::Force); } QTEST_MAIN(ViewerTest) diff --git a/messageviewer/autotests/viewertest.h b/messageviewer/autotests/viewertest.h index 3bbc13ec..6a204561 100644 --- a/messageviewer/autotests/viewertest.h +++ b/messageviewer/autotests/viewertest.h @@ -1,32 +1,33 @@ /* Copyright (c) 2014-2016 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef VIEWERTEST_H #define VIEWERTEST_H #include class ViewerTest : public QObject { Q_OBJECT public: ViewerTest(); private Q_SLOTS: void shouldHaveDefaultValuesOnCreation(); void shouldDisplayMessage(); + void shouldSwitchToAnotherMessage(); }; #endif // VIEWERTEST_H