/* * Copyright (C) 2017 David Edmundson * * This program 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 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 * 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 #include #include #include "notification.h" class NotificationTest : public QObject { Q_OBJECT public: NotificationTest() {} private Q_SLOTS: void parse_data(); void parse(); }; void NotificationTest::parse_data() { QTest::addColumn("messageIn"); QTest::addColumn("expectedOut"); QTest::newRow("basic no HTML") << "I am a notification" << "I am a notification"; QTest::newRow("whitespace") << " I am a notification " << "I am a notification"; QTest::newRow("basic html") << "I am the notification" << "I am the notification"; QTest::newRow("nested html") << "I am the notification" << "I am the notification"; QTest::newRow("no extra tags") << "I am the notification" << "I am the notification"; QTest::newRow("no extra attrs") << "I am the notification" << "I am the notification"; QTest::newRow("newlines") << "I am\nthe\nnotification" << "I am
the
notification"; QTest::newRow("multinewlines") << "I am\n\nthe\n\n\nnotification" << "I am
the
notification"; QTest::newRow("amp") << "me&you" << "me&you"; QTest::newRow("double escape") << "foo & <bar>" << "foo & <bar>"; QTest::newRow("quotes") << "'foo'" << "'foo'";//as label can't handle this normally valid entity QTest::newRow("image normal") << "This is \"cheese\"/ and more text" << "This is \"cheese\"/ and more text"; //this input is technically wrong, so the output is also wrong, but QTextHtmlParser does the "right" thing QTest::newRow("image normal no close") << "This is \"cheese\" and more text" << "This is \"cheese\" and more text"; QTest::newRow("image remote URL") << "This is \"cheese\" and more text" << "This is \"cheese\"/ and more text"; //more bad formatted options. To some extent actual output doesn't matter. Garbage in, garbage out. //the important thing is that it doesn't contain anything that could be parsed as the remote URL QTest::newRow("image remote URL no close") << "This is \" alt=\"cheese\"> and more text" << "This is \"cheese\" and more text"; QTest::newRow("image remote URL double open") << "This is <\" and more text" << "This is "; QTest::newRow("image remote URL no entity close") << "This is \"cheese\" and more text" << "This is "; QTest::newRow("link") << "This is a link and more text" << "This is a link and more text"; } void NotificationTest::parse() { QFETCH(QString, messageIn); QFETCH(QString, expectedOut); NotificationManager::Notification notification; notification.setBody(messageIn); expectedOut = "" + expectedOut + "\n"; QCOMPARE(notification.body(), expectedOut); } QTEST_GUILESS_MAIN(NotificationTest) #include "notifications_test.moc"