Changeset View
Changeset View
Standalone View
Standalone View
libnotificationmanager/autotests/notifications_test.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2017 David Edmundson <davidedmundson@kde.org> | ||||
3 | * | ||||
4 | * This program is free software you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Library General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2 of the License, or (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | * Library General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public License | ||||
15 | * along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | * Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include <QtTest> | ||||
21 | #include <QObject> | ||||
22 | #include <QDebug> | ||||
23 | | ||||
24 | #include "notification.h" | ||||
25 | | ||||
26 | class NotificationTest : public QObject | ||||
27 | { | ||||
28 | Q_OBJECT | ||||
29 | public: | ||||
30 | NotificationTest() {} | ||||
31 | private Q_SLOTS: | ||||
32 | void parse_data(); | ||||
33 | void parse(); | ||||
34 | }; | ||||
35 | | ||||
36 | void NotificationTest::parse_data() | ||||
37 | { | ||||
38 | QTest::addColumn<QString>("messageIn"); | ||||
39 | QTest::addColumn<QString>("expectedOut"); | ||||
40 | | ||||
41 | QTest::newRow("basic no HTML") << "I am a notification" << "I am a notification"; | ||||
42 | QTest::newRow("whitespace") << " I am a notification " << "I am a notification"; | ||||
43 | | ||||
44 | QTest::newRow("basic html") << "I am <b>the</b> notification" << "I am <b>the</b> notification"; | ||||
45 | QTest::newRow("nested html") << "I am <i><b>the</b></i> notification" << "I am <i><b>the</b></i> notification"; | ||||
46 | | ||||
47 | QTest::newRow("no extra tags") << "I am <blink>the</blink> notification" << "I am the notification"; | ||||
48 | QTest::newRow("no extra attrs") << "I am <b style=\"font-weight:20\">the</b> notification" << "I am <b>the</b> notification"; | ||||
49 | | ||||
50 | QTest::newRow("newlines") << "I am\nthe\nnotification" << "I am<br/>the<br/>notification"; | ||||
51 | QTest::newRow("multinewlines") << "I am\n\nthe\n\n\nnotification" << "I am<br/>the<br/>notification"; | ||||
52 | | ||||
53 | QTest::newRow("amp") << "me&you" << "me&you"; | ||||
54 | QTest::newRow("double escape") << "foo & <bar>" << "foo & <bar>"; | ||||
55 | | ||||
56 | QTest::newRow("quotes") << "'foo'" << "'foo'";//as label can't handle this normally valid entity | ||||
57 | | ||||
58 | QTest::newRow("image normal") << "This is <img src=\"file:://foo/boo.png\" alt=\"cheese\"/> and more text" << "This is <img src=\"file:://foo/boo.png\" alt=\"cheese\"/> and more text"; | ||||
59 | | ||||
60 | //this input is technically wrong, so the output is also wrong, but QTextHtmlParser does the "right" thing | ||||
61 | QTest::newRow("image normal no close") << "This is <img src=\"file:://foo/boo.png\" alt=\"cheese\"> and more text" << "This is <img src=\"file:://foo/boo.png\" alt=\"cheese\"> and more text</img>"; | ||||
62 | | ||||
63 | QTest::newRow("image remote URL") << "This is <img src=\"http://foo.com/boo.png\" alt=\"cheese\" /> and more text" << "This is <img alt=\"cheese\"/> and more text"; | ||||
64 | | ||||
65 | //more bad formatted options. To some extent actual output doesn't matter. Garbage in, garbabe out. | ||||
66 | //the important thing is that it doesn't contain anything that could be parsed as the remote URL | ||||
67 | QTest::newRow("image remote URL no close") << "This is <img src=\"http://foo.com/boo.png>\" alt=\"cheese\"> and more text" << "This is <img alt=\"cheese\"> and more text</img>"; | ||||
68 | QTest::newRow("image remote URL double open") << "This is <<img src=\"http://foo.com/boo.png>\" and more text" << "This is "; | ||||
69 | QTest::newRow("image remote URL no entitiy close") << "This is <img src=\"http://foo.com/boo.png\" and more text" << "This is "; | ||||
70 | QTest::newRow("image remote URL space in element name") << "This is < img src=\"http://foo.com/boo.png\" alt=\"cheese\" /> and more text" << "This is "; | ||||
71 | | ||||
72 | QTest::newRow("link") << "This is a link <a href=\"http://foo.com/boo\"/> and more text" << "This is a link <a href=\"http://foo.com/boo\"/> and more text"; | ||||
73 | } | ||||
74 | | ||||
75 | void NotificationTest::parse() | ||||
76 | { | ||||
77 | QFETCH(QString, messageIn); | ||||
78 | QFETCH(QString, expectedOut); | ||||
79 | | ||||
80 | NotificationManager::Notification notification; | ||||
81 | notification.setBody(messageIn); | ||||
82 | | ||||
83 | expectedOut = "<?xml version=\"1.0\"?><html>" + expectedOut + "</html>\n"; | ||||
84 | | ||||
85 | QCOMPARE(notification.body(), expectedOut); | ||||
86 | } | ||||
87 | | ||||
88 | QTEST_GUILESS_MAIN(NotificationTest) | ||||
89 | | ||||
90 | #include "notifications_test.moc" |