1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
47 // This file is not part of the Qt API. It exists purely as an
48 // implementation detail. This header file may change from version to
49 // version without notice, or even be removed.
53 #include "qapplicationargumentparser_p.h"
54 #include "qapplicationargument_p.h"
55 #include <QtTest/QtTest>
57 Q_DECLARE_METATYPE(QList<QApplicationArgument>);
58 Q_DECLARE_METATYPE(QApplicationArgumentParser::ExitCode);
61 \class tst_QApplicationArgumentParser
62 \brief The class tst_QApplicationArgumentParser tests class QApplicationArgumentParser.
67 class tst_QApplicationArgumentParser : public QObject
71 void negativeTest() const;
72 void negativeTest_data() const;
73 void mandatoryArguments() const;
74 void mandatoryArguments_data() const;
78 Comments from notes.txt:
81 * -name <mandatory value>
82 * -name <no value, it's a switch>
84 Both of these types in addition have a cardinality. For instance:
86 -name value1 -name value2 -name value3
92 ./foo -ab -cd - input1 input
97 // -switch has upper limit of 2
98 ./foo -switch -switch -switch
100 // -switch has upper limit of 1
101 ./foo -switch -switch
103 // -switch has lower limit of 1
106 ./foo -switch cruft -switch
107 ./foo -option value1 cruft -option value2
108 ./foo -option value1 cruft cruft -option value2
109 ./foo -option value1 cruft cruft cruft -option value2
110 ./foo -option -option -option2 -option2
112 ./foo -option -option -option2
117 void tst_QApplicationArgumentParser::negativeTest() const
121 void tst_QApplicationArgumentParser::negativeTest_data() const
123 QTest::addColumn<QStringList>("inputArgs");
124 QTest::addColumn<QApplicationArgumentParser::ExitCode>("expectedExitCode");
125 QTest::addColumn<QString>("expectedStderr");
126 QTest::addColumn<QList<QApplicationArgument> >("declarations");
129 void tst_QApplicationArgumentParser::mandatoryArguments() const
131 QFETCH(QStringList, inputArgs);
132 QFETCH(QList<QApplicationArgument>, inputDecls);
134 QApplicationArgumentParser parser(inputArgs);
135 parser.setDeclaredArguments(inputDecls);
137 QVERIFY(!parser.parse());
138 QCOMPARE(parser.exitCode(), QApplicationArgumentParser::ParseError);
141 void tst_QApplicationArgumentParser::mandatoryArguments_data() const
143 QTest::addColumn<QStringList>("inputArgs");
144 QTest::addColumn<QList<QApplicationArgument> >("inputDecls");
150 QList<QApplicationArgument> decls;
151 QApplicationArgument arg1("name", QString(), QVariant::String);
152 arg1.setMinimumOccurrence(1);
155 QTest::newRow("A single, named, argument") << in << decls;
159 QTEST_APPLESS_MAIN(tst_QApplicationArgumentParser)
160 #include "tst_qapplicationargumentparser.moc"