summaryrefslogtreecommitdiffstats
path: root/src/qdoc/qdoc/tests/qdoccommandlineparser/tst_qdoccommandlineparser.cpp
blob: e78de042592359c1c61275c8def9db7859b63219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include "qdoc/qdoccommandlineparser.h"

#include <QtCore/qstringlist.h>
#include <QtTest/QtTest>

class tst_QDocCommandLineParser : public QObject
{
    Q_OBJECT

private slots:
    void defaultConstructor();
    void process();
    void argumentsFromCommandLineAndFile();
};

void tst_QDocCommandLineParser::defaultConstructor()
{
    QDocCommandLineParser parser;

    QVERIFY2(parser.applicationDescription() == QStringLiteral("Qt documentation generator"),
             "The application description is incorrect.");
}

void tst_QDocCommandLineParser::process()
{
    const QStringList arguments =
        QStringLiteral("/src/qt5/qtbase/bin/qdoc "
                       "-outputdir "
                       "/src/qt5/qtbase/doc/qtgamepad "
                       "-installdir "
                       "/src/qt5/qtbase/doc "
                       "/src/qt5/qtgamepad/src/gamepad/doc/qtgamepad.qdocconf "
                       "-prepare "
                       "-indexdir "
                       "/src/qt5/qtbase/doc "
                       "-no-link-errors "
                       "-I. "
                       "-I/src/qt5/qtbase/include "
                       "-I/src/qt5/qtbase/include/QtGamepad "
                       "-I/src/qt5/qtbase/include/QtGamepad/5.14.0 "
                       "-I/src/qt5/qtbase/include/QtGamepad/5.14.0/QtGamepad "
                       "-I/src/qt5/qtbase/include/QtCore/5.14.0 "
                       "-I/src/qt5/qtbase/include/QtCore/5.14.0/QtCore "
                       "-I/src/qt5/qtbase/include/QtGui "
                       "-I/src/qt5/qtbase/include/QtCore "
                       "-I.moc "
                       "-isystem "
                       "/usr/include/libdrm "
                       "-I/src/qt5/qtbase/mkspecs/linux-g++"
        ).split(QString(" "));
    const QStringList expectedIncludePaths =
        QStringLiteral(". "
                       "/src/qt5/qtbase/include "
                       "/src/qt5/qtbase/include/QtGamepad "
                       "/src/qt5/qtbase/include/QtGamepad/5.14.0 "
                       "/src/qt5/qtbase/include/QtGamepad/5.14.0/QtGamepad "
                       "/src/qt5/qtbase/include/QtCore/5.14.0 "
                       "/src/qt5/qtbase/include/QtCore/5.14.0/QtCore "
                       "/src/qt5/qtbase/include/QtGui "
                       "/src/qt5/qtbase/include/QtCore "
                       ".moc "
                       "/src/qt5/qtbase/mkspecs/linux-g++"
        ).split(QString(" "));
    const QStringList expectedSystemIncludePath(QStringLiteral("/usr/include/libdrm"));

    QDocCommandLineParser parser;
    parser.process(arguments);

    QVERIFY(parser.isSet(parser.outputDirOption));
    QCOMPARE(parser.value(parser.outputDirOption), QStringLiteral("/src/qt5/qtbase/doc/qtgamepad"));
    QVERIFY(parser.isSet(parser.installDirOption));
    QCOMPARE(parser.value(parser.installDirOption), QStringLiteral("/src/qt5/qtbase/doc"));
    QVERIFY(parser.isSet(parser.prepareOption));
    QVERIFY(parser.isSet(parser.indexDirOption));
    QCOMPARE(parser.value(parser.indexDirOption), QStringLiteral("/src/qt5/qtbase/doc"));
    QVERIFY(parser.isSet(parser.noLinkErrorsOption));
    QVERIFY(parser.isSet(parser.includePathOption));
    QCOMPARE(parser.values(parser.includePathOption), expectedIncludePaths);
    QVERIFY(parser.isSet(parser.includePathSystemOption));
    QCOMPARE(parser.values(parser.includePathSystemOption), expectedSystemIncludePath);

    QVERIFY(!parser.isSet(parser.timestampsOption));
    QVERIFY(!parser.isSet(parser.dependsOption));
    QVERIFY(!parser.isSet(parser.highlightingOption));
    QVERIFY(!parser.isSet(parser.showInternalOption));
    QVERIFY(!parser.isSet(parser.redirectDocumentationToDevNullOption));
    QVERIFY(!parser.isSet(parser.noExamplesOption));
    QVERIFY(!parser.isSet(parser.autoLinkErrorsOption));
    QVERIFY(!parser.isSet(parser.debugOption));
    QVERIFY(!parser.isSet(parser.generateOption));
    QVERIFY(!parser.isSet(parser.logProgressOption));
    QVERIFY(!parser.isSet(parser.singleExecOption));
    QVERIFY(!parser.isSet(parser.frameworkOption));

    const QStringList expectedPositionalArgument = {
        QStringLiteral("/src/qt5/qtgamepad/src/gamepad/doc/qtgamepad.qdocconf")
    };
    QCOMPARE(parser.positionalArguments(), expectedPositionalArgument);
}

void tst_QDocCommandLineParser::argumentsFromCommandLineAndFile()
{
    const QString atFilePath("@" + QFINDTESTDATA("tst_arguments.txt"));
    const QStringList arguments { "/src/qt5/qtbase/bin/qdoc", atFilePath };

    QDocCommandLineParser parser;
    parser.process(arguments);

    const QStringList expectedIncludePaths =
        QStringLiteral(". "
                       "/src/qt5/qtbase/include "
                       "/src/qt5/qtbase/include/QtGamepad "
                       "/src/qt5/qtbase/include/QtGamepad/5.14.0 "
                       "/src/qt5/qtbase/include/QtGamepad/5.14.0/QtGamepad "
                       "/src/qt5/qtbase/include/QtCore/5.14.0 "
                       "/src/qt5/qtbase/include/QtCore/5.14.0/QtCore "
                       "/src/qt5/qtbase/include/QtGui "
                       "/src/qt5/qtbase/include/QtCore "
                       ".moc "
                       "/src/qt5/qtbase/mkspecs/linux-g++"
        ).split(QString(" "));
    const QStringList expectedSystemIncludePath(QStringLiteral("/usr/include/libdrm"));
    const QStringList expectedPositionalArgument = {
        QStringLiteral("/src/qt5/qtgamepad/src/gamepad/doc/qtgamepad.qdocconf")
    };

    QVERIFY(parser.isSet(parser.outputDirOption));
    QCOMPARE(parser.value(parser.outputDirOption), QStringLiteral("/src/qt5/qtbase/doc/qtgamepad"));
    QVERIFY(parser.isSet(parser.installDirOption));
    QCOMPARE(parser.value(parser.installDirOption), QStringLiteral("/src/qt5/qtbase/doc"));
    QVERIFY(parser.isSet(parser.prepareOption));
    QVERIFY(parser.isSet(parser.indexDirOption));
    QCOMPARE(parser.value(parser.indexDirOption), QStringLiteral("/src/qt5/qtbase/doc"));
    QVERIFY(parser.isSet(parser.noLinkErrorsOption));
    QVERIFY(parser.isSet(parser.includePathOption));
    QCOMPARE(parser.values(parser.includePathOption), expectedIncludePaths);
    QVERIFY(parser.isSet(parser.includePathSystemOption));
    QCOMPARE(parser.values(parser.includePathSystemOption), expectedSystemIncludePath);

    QVERIFY(!parser.isSet(parser.timestampsOption));
    QVERIFY(!parser.isSet(parser.dependsOption));
    QVERIFY(!parser.isSet(parser.highlightingOption));
    QVERIFY(!parser.isSet(parser.showInternalOption));
    QVERIFY(!parser.isSet(parser.redirectDocumentationToDevNullOption));
    QVERIFY(!parser.isSet(parser.noExamplesOption));
    QVERIFY(!parser.isSet(parser.autoLinkErrorsOption));
    QVERIFY(!parser.isSet(parser.debugOption));
    QVERIFY(!parser.isSet(parser.generateOption));
    QVERIFY(!parser.isSet(parser.logProgressOption));
    QVERIFY(!parser.isSet(parser.singleExecOption));
    QVERIFY(!parser.isSet(parser.frameworkOption));

    QCOMPARE(parser.positionalArguments(), expectedPositionalArgument);
}

QTEST_APPLESS_MAIN(tst_QDocCommandLineParser)

#include "tst_qdoccommandlineparser.moc"