~osomon/webbrowser-app/create-downloads-folder

« back to all changes in this revision

Viewing changes to tests/unittests/tst_CommandLineParserTests.cpp

  • Committer: Olivier Tilloy
  • Date: 2013-01-30 11:54:04 UTC
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: olivier.tilloy@canonical.com-20130130115404-2q8d06xsn84bn2rv
Unit tests for the command line parser.

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 ubuntu-browser.
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 *
 
18
 */
 
19
 
 
20
// Qt
 
21
#include <QtTest/QtTest>
 
22
 
 
23
// local
 
24
#include "commandline-parser.h"
 
25
 
 
26
class CommandLineParserTests : public QObject
 
27
{
 
28
    Q_OBJECT
 
29
 
 
30
private Q_SLOTS:
 
31
    void shouldDisplayHelp_data()
 
32
    {
 
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;
 
51
    }
 
52
 
 
53
    void shouldDisplayHelp()
 
54
    {
 
55
        QFETCH(QStringList, args);
 
56
        QFETCH(bool, help);
 
57
        QCOMPARE(CommandLineParser(args).help(), help);
 
58
    }
 
59
 
 
60
    void shouldBeChromeless_data()
 
61
    {
 
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;
 
74
    }
 
75
 
 
76
    void shouldBeChromeless()
 
77
    {
 
78
        QFETCH(QStringList, args);
 
79
        QFETCH(bool, chromeless);
 
80
        QCOMPARE(CommandLineParser(args).chromeless(), chromeless);
 
81
    }
 
82
 
 
83
    void shouldBeFullscreen_data()
 
84
    {
 
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;
 
97
    }
 
98
 
 
99
    void shouldBeFullscreen()
 
100
    {
 
101
        QFETCH(QStringList, args);
 
102
        QFETCH(bool, fullscreen);
 
103
        QCOMPARE(CommandLineParser(args).fullscreen(), fullscreen);
 
104
    }
 
105
 
 
106
    void shouldRecordURL_data()
 
107
    {
 
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);
 
120
    }
 
121
 
 
122
    void shouldRecordURL()
 
123
    {
 
124
        QFETCH(QStringList, args);
 
125
        QFETCH(QUrl, url);
 
126
        QCOMPARE(CommandLineParser(args).url(), url);
 
127
    }
 
128
};
 
129
 
 
130
QTEST_MAIN(CommandLineParserTests)
 
131
#include "tst_CommandLineParserTests.moc"