1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
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"