Changeset View
Changeset View
Standalone View
Standalone View
dataengines/notifications/notifications_test.cpp
- This file was added.
1 | #include <QtTest> | ||||
---|---|---|---|---|---|
2 | #include <QObject> | ||||
3 | #include <QDebug> | ||||
4 | #include "notificationsanitizer.h" | ||||
5 | | ||||
6 | class NotificationTest : public QObject | ||||
7 | { | ||||
8 | Q_OBJECT | ||||
9 | public: | ||||
10 | NotificationTest() {} | ||||
11 | private Q_SLOTS: | ||||
12 | void parse_data(); | ||||
13 | void parse(); | ||||
14 | }; | ||||
15 | | ||||
16 | void NotificationTest::parse_data() | ||||
17 | { | ||||
18 | QTest::addColumn<QString>("messageIn"); | ||||
19 | QTest::addColumn<QString>("expectedOut"); | ||||
20 | | ||||
21 | QTest::newRow("basic no HTML") << "I am a notification" << "I am a notification"; | ||||
22 | QTest::newRow("whitespace") << " I am a notification " << "I am a notification"; | ||||
23 | | ||||
24 | QTest::newRow("basic html") << "I am <b>the</b> notification" << "I am <b>the</b> notification"; | ||||
25 | QTest::newRow("nested html") << "I am <i><b>the</b></i> notification" << "I am <i><b>the</b></i> notification"; | ||||
26 | | ||||
27 | QTest::newRow("no extra tags") << "I am <blink>the</blink> notification" << "I am the notification"; | ||||
28 | QTest::newRow("no extra attrs") << "I am <b style=\"font-weight:20\">the</b> notification" << "I am <b>the</b> notification"; | ||||
29 | | ||||
30 | QTest::newRow("newlines") << "I am\nthe\nnotification" << "I am<br/>the<br/>notification"; | ||||
31 | QTest::newRow("multinewlines") << "I am\n\nthe\n\n\nnotification" << "I am<br/>the<br/>notification"; | ||||
32 | | ||||
33 | QTest::newRow("amp") << "me&you" << "me&you"; | ||||
34 | QTest::newRow("double escape") << "foo & <bar>" << "foo & <bar>"; | ||||
35 | | ||||
36 | QTest::newRow("quotes") << "'foo'" << "'foo'";//as label can't handle this normally valid entity | ||||
37 | | ||||
38 | 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"; | ||||
39 | | ||||
40 | //this input is technically wrong, so the output is also wrong, but QTextHtmlParser does the same thing | ||||
41 | 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>"; | ||||
42 | | ||||
43 | 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"; | ||||
44 | 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>"; | ||||
45 | | ||||
46 | 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"; | ||||
47 | } | ||||
48 | | ||||
49 | void NotificationTest::parse() | ||||
50 | { | ||||
51 | QFETCH(QString, messageIn); | ||||
52 | QFETCH(QString, expectedOut); | ||||
53 | | ||||
54 | const QString out = NotificationSanitizer::parse(messageIn); | ||||
55 | expectedOut = "<?xml version=\"1.0\"?><html>" + expectedOut + "</html>\n"; | ||||
56 | QCOMPARE(out, expectedOut); | ||||
57 | } | ||||
58 | | ||||
59 | | ||||
60 | QTEST_GUILESS_MAIN(NotificationTest) | ||||
61 | | ||||
62 | #include "notifications_test.moc" |