Update licenseheader text in source files for qtxmlpatterns Qt module
[profile/ivi/qtxmlpatterns.git] / tests / auto / qapplicationargumentparser / tst_qapplicationargumentparser.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42
43 //
44 //  W A R N I N G
45 //  -------------
46 //
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.
50 //
51 // We mean it.
52
53 #include "qapplicationargumentparser_p.h"
54 #include "qapplicationargument_p.h"
55 #include <QtTest/QtTest>
56
57 Q_DECLARE_METATYPE(QList<QApplicationArgument>);
58 Q_DECLARE_METATYPE(QApplicationArgumentParser::ExitCode);
59
60 /*!
61   \class tst_QApplicationArgumentParser
62   \brief The class tst_QApplicationArgumentParser tests class QApplicationArgumentParser.
63   \internal
64   \since 4.5
65
66 */
67 class tst_QApplicationArgumentParser : public QObject
68 {
69     Q_OBJECT
70 private slots:
71     void negativeTest() const;
72     void negativeTest_data() const;
73     void mandatoryArguments() const;
74     void mandatoryArguments_data() const;
75 };
76
77 /*
78 Comments from notes.txt:
79
80 Different arg types:
81 * -name <mandatory value>
82 * -name <no value, it's a switch>
83
84 Both of these types in addition have a cardinality. For instance:
85 -name -name -name
86 -name value1 -name value2 -name value3
87
88 Possible Tests
89 -------------------
90     ./foo -ab -cd -
91     ./foo -ab -cd - - -
92     ./foo -ab -cd - input1 input
93     ./foo -help -
94     ./foo - -help
95
96
97     // -switch has upper limit of 2
98     ./foo -switch -switch -switch
99
100     // -switch has upper limit of 1
101     ./foo -switch -switch
102
103     // -switch has lower limit of 1
104     ./foo
105
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
111     ./foo -option
112     ./foo -option -option -option2
113     ./foo -option -
114     ./foo -option - -
115 */
116
117 void tst_QApplicationArgumentParser::negativeTest() const
118 {
119 }
120
121 void tst_QApplicationArgumentParser::negativeTest_data() const
122 {
123     QTest::addColumn<QStringList>("inputArgs");
124     QTest::addColumn<QApplicationArgumentParser::ExitCode>("expectedExitCode");
125     QTest::addColumn<QString>("expectedStderr");
126     QTest::addColumn<QList<QApplicationArgument> >("declarations");
127 }
128
129 void tst_QApplicationArgumentParser::mandatoryArguments() const
130 {
131    QFETCH(QStringList, inputArgs);
132    QFETCH(QList<QApplicationArgument>, inputDecls);
133
134    QApplicationArgumentParser parser(inputArgs);
135    parser.setDeclaredArguments(inputDecls);
136
137    QVERIFY(!parser.parse());
138    QCOMPARE(parser.exitCode(), QApplicationArgumentParser::ParseError);
139 }
140
141 void tst_QApplicationArgumentParser::mandatoryArguments_data() const
142 {
143     QTest::addColumn<QStringList>("inputArgs");
144     QTest::addColumn<QList<QApplicationArgument> >("inputDecls");
145
146     {
147         QStringList in;
148         in << "./appName";
149
150         QList<QApplicationArgument> decls;
151         QApplicationArgument arg1("name", QString(), QVariant::String);
152         arg1.setMinimumOccurrence(1);
153         decls.append(arg1);
154
155         QTest::newRow("A single, named, argument") << in << decls;
156     }
157 }
158
159 QTEST_APPLESS_MAIN(tst_QApplicationArgumentParser)
160 #include "tst_qapplicationargumentparser.moc"