~ubuntu-branches/ubuntu/wily/webbrowser-app/wily-proposed

« back to all changes in this revision

Viewing changes to tests/unittests/tst_CommandLineParserTests.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2013-06-05 05:03:05 UTC
  • Revision ID: package-import@ubuntu.com-20130605050305-qgpd9x3s01m06dca
Tags: upstream-0.20daily13.06.05
ImportĀ upstreamĀ versionĀ 0.20daily13.06.05

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This file is part of webbrowser-app.
 
5
 *
 
6
 * webbrowser-app is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * webbrowser-app is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
// Qt
 
20
#include <QtTest/QtTest>
 
21
 
 
22
// local
 
23
#include "commandline-parser.h"
 
24
 
 
25
class CommandLineParserTests : public QObject
 
26
{
 
27
    Q_OBJECT
 
28
 
 
29
private Q_SLOTS:
 
30
    void shouldDisplayHelp_data()
 
31
    {
 
32
        QTest::addColumn<QStringList>("args");
 
33
        QTest::addColumn<bool>("help");
 
34
        QString BINARY("webbrowser-app");
 
35
        QString URL("http://ubuntu.com");
 
36
        QTest::newRow("no switch") << (QStringList() << BINARY) << false;
 
37
        QTest::newRow("no switch with URL") << (QStringList() << BINARY << URL) << false;
 
38
        QTest::newRow("short switch only") << (QStringList() << BINARY << "-h") << true;
 
39
        QTest::newRow("long switch only") << (QStringList() << BINARY << "--help") << true;
 
40
        QTest::newRow("short switch before URL") << (QStringList() << BINARY << "-h" << URL) << true;
 
41
        QTest::newRow("long switch before URL") << (QStringList() << BINARY << "--help" << URL) << true;
 
42
        QTest::newRow("short switch after URL") << (QStringList() << BINARY << URL << "-h") << true;
 
43
        QTest::newRow("long switch after URL") << (QStringList() << BINARY << URL << "--help") << true;
 
44
        QTest::newRow("short switch typo") << (QStringList() << BINARY << "-j") << false;
 
45
        QTest::newRow("long switch typo") << (QStringList() << BINARY << "--helo") << false;
 
46
        QTest::newRow("short switch long") << (QStringList() << BINARY << "--h") << false;
 
47
        QTest::newRow("long switch short") << (QStringList() << BINARY << "-help") << false;
 
48
        QTest::newRow("short switch uppercase") << (QStringList() << BINARY << "-H") << false;
 
49
        QTest::newRow("long switch uppercase") << (QStringList() << BINARY << "--HELP") << false;
 
50
    }
 
51
 
 
52
    void shouldDisplayHelp()
 
53
    {
 
54
        QFETCH(QStringList, args);
 
55
        QFETCH(bool, help);
 
56
        QCOMPARE(CommandLineParser(args).help(), help);
 
57
    }
 
58
 
 
59
    void shouldBeChromeless_data()
 
60
    {
 
61
        QTest::addColumn<QStringList>("args");
 
62
        QTest::addColumn<bool>("chromeless");
 
63
        QString BINARY("webbrowser-app");
 
64
        QString URL("http://ubuntu.com");
 
65
        QTest::newRow("no switch") << (QStringList() << BINARY) << false;
 
66
        QTest::newRow("switch only") << (QStringList() << BINARY << "--chromeless") << true;
 
67
        QTest::newRow("switch before URL") << (QStringList() << BINARY << "--chromeless" << URL) << true;
 
68
        QTest::newRow("switch after URL") << (QStringList() << BINARY << URL << "--chromeless") << true;
 
69
        QTest::newRow("switch typo") << (QStringList() << BINARY << "--chromeles") << false;
 
70
        QTest::newRow("switch uppercase") << (QStringList() << BINARY << "--CHROMELESS") << false;
 
71
        QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "-h" << "--chromeless") << false;
 
72
        QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "--help" << "--chromeless") << false;
 
73
    }
 
74
 
 
75
    void shouldBeChromeless()
 
76
    {
 
77
        QFETCH(QStringList, args);
 
78
        QFETCH(bool, chromeless);
 
79
        QCOMPARE(CommandLineParser(args).chromeless(), chromeless);
 
80
    }
 
81
 
 
82
    void shouldBeFullscreen_data()
 
83
    {
 
84
        QTest::addColumn<QStringList>("args");
 
85
        QTest::addColumn<bool>("fullscreen");
 
86
        QString BINARY("webbrowser-app");
 
87
        QString URL("http://ubuntu.com");
 
88
        QTest::newRow("no switch") << (QStringList() << BINARY) << false;
 
89
        QTest::newRow("switch only") << (QStringList() << BINARY << "--fullscreen") << true;
 
90
        QTest::newRow("switch before URL") << (QStringList() << BINARY << "--fullscreen" << URL) << true;
 
91
        QTest::newRow("switch after URL") << (QStringList() << BINARY << URL << "--fullscreen") << true;
 
92
        QTest::newRow("switch typo") << (QStringList() << BINARY << "--fulscreen") << false;
 
93
        QTest::newRow("switch uppercase") << (QStringList() << BINARY << "--FULLSCREEN") << false;
 
94
        QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "-h" << "--fullscreen") << false;
 
95
        QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "--help" << "--fullscreen") << false;
 
96
    }
 
97
 
 
98
    void shouldBeFullscreen()
 
99
    {
 
100
        QFETCH(QStringList, args);
 
101
        QFETCH(bool, fullscreen);
 
102
        QCOMPARE(CommandLineParser(args).fullscreen(), fullscreen);
 
103
    }
 
104
 
 
105
    void shouldRecordURL_data()
 
106
    {
 
107
        QTest::addColumn<QStringList>("args");
 
108
        QTest::addColumn<QUrl>("url");
 
109
        QString BINARY("webbrowser-app");
 
110
        QString DEFAULT("http://www.ubuntu.com");
 
111
        QString URL1("http://example.org");
 
112
        QString URL2("http://example.com");
 
113
        QTest::newRow("no URL") << (QStringList() << BINARY) << QUrl(DEFAULT);
 
114
        QTest::newRow("no URL with switches") << (QStringList() << BINARY << "--chromeless" << "--fullscreen") << QUrl(DEFAULT);
 
115
        QTest::newRow("help precludes URL") << (QStringList() << BINARY << "-h" << URL1) << QUrl(DEFAULT);
 
116
        QTest::newRow("help precludes URL") << (QStringList() << BINARY << "--help" << URL1) << QUrl(DEFAULT);
 
117
        QTest::newRow("one URL") << (QStringList() << BINARY << URL1) << QUrl(URL1);
 
118
        QTest::newRow("several URLs") << (QStringList() << BINARY << URL1 << URL2) << QUrl(URL1);
 
119
        QTest::newRow("missing scheme") << (QStringList() << BINARY << "ubuntu.com") << QUrl("http://ubuntu.com");
 
120
        QTest::newRow("malformed URL") << (QStringList() << BINARY << "@") << QUrl(DEFAULT);
 
121
        QTest::newRow("malformed URL") << (QStringList() << BINARY << "@" << URL1) << QUrl(URL1);
 
122
        QTest::newRow("homepage switch only") << (QStringList() << BINARY << "--homepage=http://example.com") << QUrl("http://example.com");
 
123
        QTest::newRow("homepage switch overrides URL") << (QStringList() << BINARY << "--homepage=http://example.com" << "http://ubuntu.com") << QUrl("http://example.com");
 
124
        QTest::newRow("empty homepage switch") << (QStringList() << BINARY << "--homepage=") << QUrl(DEFAULT);
 
125
        QTest::newRow("homepage switch missing scheme") << (QStringList() << BINARY << "--homepage=example.com") << QUrl("http://example.com");
 
126
    }
 
127
 
 
128
    void shouldRecordURL()
 
129
    {
 
130
        QFETCH(QStringList, args);
 
131
        QFETCH(QUrl, url);
 
132
        QCOMPARE(CommandLineParser(args).url(), url);
 
133
    }
 
134
 
 
135
    void shouldHaveDesktopFileHint_data()
 
136
    {
 
137
        QTest::addColumn<QStringList>("args");
 
138
        QTest::addColumn<QString>("hint");
 
139
        QString BINARY("webbrowser-app");
 
140
 
 
141
        QTest::newRow("no hint") << (QStringList() << BINARY) << "";
 
142
        QTest::newRow("full path hint") << (QStringList() << BINARY << "--desktop_file_hint=/usr/share/applications/webbrowser-app.desktop") << "webbrowser-app";
 
143
        QTest::newRow("only .desktop file") << (QStringList() << BINARY << "--desktop_file_hint=webbrowser-app.desktop") << "webbrowser-app";
 
144
        QTest::newRow("webapp") << (QStringList() << BINARY << "--desktop_file_hint=/usr/share/applications/amazon-webapp.desktop") << "amazon-webapp";
 
145
    }
 
146
 
 
147
    void shouldHaveDesktopFileHint()
 
148
    {
 
149
        QFETCH(QStringList, args);
 
150
        QFETCH(QString, hint);
 
151
        QCOMPARE(CommandLineParser(args).desktopFileHint(), hint);
 
152
    }
 
153
 
 
154
    void shouldRunRemoteInspector_data()
 
155
    {
 
156
        QTest::addColumn<QStringList>("args");
 
157
        QTest::addColumn<bool>("inspector");
 
158
        QString BINARY("webbrowser-app");
 
159
        QString URL("http://ubuntu.com");
 
160
        QTest::newRow("no switch") << (QStringList() << BINARY) << false;
 
161
        QTest::newRow("switch only") << (QStringList() << BINARY << "--inspector") << true;
 
162
        QTest::newRow("switch before URL") << (QStringList() << BINARY << "--inspector" << URL) << true;
 
163
        QTest::newRow("switch after URL") << (QStringList() << BINARY << URL << "--inspector") << true;
 
164
        QTest::newRow("switch typo") << (QStringList() << BINARY << "--ispector") << false;
 
165
        QTest::newRow("switch uppercase") << (QStringList() << BINARY << "--INSPECTOR") << false;
 
166
        QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "-h" << "--inspector") << false;
 
167
        QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "--help" << "--inspector") << false;
 
168
    }
 
169
 
 
170
    void shouldRunRemoteInspector()
 
171
    {
 
172
        QFETCH(QStringList, args);
 
173
        QFETCH(bool, inspector);
 
174
        QCOMPARE(CommandLineParser(args).remoteInspector(), inspector);
 
175
    }
 
176
};
 
177
 
 
178
QTEST_MAIN(CommandLineParserTests)
 
179
#include "tst_CommandLineParserTests.moc"