2
* Copyright 2013 Canonical Ltd.
4
* This file is part of ubuntu-browser.
6
* ubuntu-browser is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; version 3.
10
* ubuntu-browser 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 Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
#include <QtTest/QtTest>
24
#include "commandline-parser.h"
26
class CommandLineParserTests : public QObject
31
void shouldDisplayHelp_data()
33
QTest::addColumn<QStringList>("args");
34
QTest::addColumn<bool>("help");
35
QString BINARY("ubuntu-browser");
36
QString URL("http://ubuntu.com");
37
QTest::newRow("no switch") << (QStringList() << BINARY) << false;
38
QTest::newRow("no switch with URL") << (QStringList() << BINARY << URL) << false;
39
QTest::newRow("short switch only") << (QStringList() << BINARY << "-h") << true;
40
QTest::newRow("long switch only") << (QStringList() << BINARY << "--help") << true;
41
QTest::newRow("short switch before URL") << (QStringList() << BINARY << "-h" << URL) << true;
42
QTest::newRow("long switch before URL") << (QStringList() << BINARY << "--help" << URL) << true;
43
QTest::newRow("short switch after URL") << (QStringList() << BINARY << URL << "-h") << true;
44
QTest::newRow("long switch after URL") << (QStringList() << BINARY << URL << "--help") << true;
45
QTest::newRow("short switch typo") << (QStringList() << BINARY << "-j") << false;
46
QTest::newRow("long switch typo") << (QStringList() << BINARY << "--helo") << false;
47
QTest::newRow("short switch long") << (QStringList() << BINARY << "--h") << false;
48
QTest::newRow("long switch short") << (QStringList() << BINARY << "-help") << false;
49
QTest::newRow("short switch uppercase") << (QStringList() << BINARY << "-H") << false;
50
QTest::newRow("long switch uppercase") << (QStringList() << BINARY << "--HELP") << false;
53
void shouldDisplayHelp()
55
QFETCH(QStringList, args);
57
QCOMPARE(CommandLineParser(args).help(), help);
60
void shouldBeChromeless_data()
62
QTest::addColumn<QStringList>("args");
63
QTest::addColumn<bool>("chromeless");
64
QString BINARY("ubuntu-browser");
65
QString URL("http://ubuntu.com");
66
QTest::newRow("no switch") << (QStringList() << BINARY) << false;
67
QTest::newRow("switch only") << (QStringList() << BINARY << "--chromeless") << true;
68
QTest::newRow("switch before URL") << (QStringList() << BINARY << "--chromeless" << URL) << true;
69
QTest::newRow("switch after URL") << (QStringList() << BINARY << URL << "--chromeless") << true;
70
QTest::newRow("switch typo") << (QStringList() << BINARY << "--chromeles") << false;
71
QTest::newRow("switch uppercase") << (QStringList() << BINARY << "--CHROMELESS") << false;
72
QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "-h" << "--chromeless") << false;
73
QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "--help" << "--chromeless") << false;
76
void shouldBeChromeless()
78
QFETCH(QStringList, args);
79
QFETCH(bool, chromeless);
80
QCOMPARE(CommandLineParser(args).chromeless(), chromeless);
83
void shouldBeFullscreen_data()
85
QTest::addColumn<QStringList>("args");
86
QTest::addColumn<bool>("fullscreen");
87
QString BINARY("ubuntu-browser");
88
QString URL("http://ubuntu.com");
89
QTest::newRow("no switch") << (QStringList() << BINARY) << false;
90
QTest::newRow("switch only") << (QStringList() << BINARY << "--fullscreen") << true;
91
QTest::newRow("switch before URL") << (QStringList() << BINARY << "--fullscreen" << URL) << true;
92
QTest::newRow("switch after URL") << (QStringList() << BINARY << URL << "--fullscreen") << true;
93
QTest::newRow("switch typo") << (QStringList() << BINARY << "--fulscreen") << false;
94
QTest::newRow("switch uppercase") << (QStringList() << BINARY << "--FULLSCREEN") << false;
95
QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "-h" << "--fullscreen") << false;
96
QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "--help" << "--fullscreen") << false;
99
void shouldBeFullscreen()
101
QFETCH(QStringList, args);
102
QFETCH(bool, fullscreen);
103
QCOMPARE(CommandLineParser(args).fullscreen(), fullscreen);
106
void shouldRecordURL_data()
108
QTest::addColumn<QStringList>("args");
109
QTest::addColumn<QUrl>("url");
110
QString BINARY("ubuntu-browser");
111
QString DEFAULT("http://www.ubuntu.com");
112
QString URL1("http://example.org");
113
QString URL2("http://example.com");
114
QTest::newRow("no URL") << (QStringList() << BINARY) << QUrl(DEFAULT);
115
QTest::newRow("no URL with switches") << (QStringList() << BINARY << "--chromeless" << "--fullscreen") << QUrl(DEFAULT);
116
QTest::newRow("help precludes URL") << (QStringList() << BINARY << "-h" << URL1) << QUrl(DEFAULT);
117
QTest::newRow("help precludes URL") << (QStringList() << BINARY << "--help" << URL1) << QUrl(DEFAULT);
118
QTest::newRow("one URL") << (QStringList() << BINARY << URL1) << QUrl(URL1);
119
QTest::newRow("several URLs") << (QStringList() << BINARY << URL1 << URL2) << QUrl(URL1);
122
void shouldRecordURL()
124
QFETCH(QStringList, args);
126
QCOMPARE(CommandLineParser(args).url(), url);
130
QTEST_MAIN(CommandLineParserTests)
131
#include "tst_CommandLineParserTests.moc"