1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28#include <QtTest/QtTest>
29
30#include <QtCore/QFileInfo>
31
32#include "../../../src/assistant/qhelpgenerator/qhelpprojectdata_p.h"
33
34class tst_QHelpProjectData : public QObject
35{
36 Q_OBJECT
37
38private slots:
39 void initTestCase();
40
41 void readData();
42 void namespaceName();
43 void virtualFolder();
44 void customFilters();
45 void filterSections();
46 void metaData();
47 void rootPath();
48
49private:
50 QString m_inputFile;
51};
52
53void tst_QHelpProjectData::initTestCase()
54{
55 const QString path = QLatin1String(SRCDIR);
56 m_inputFile = path + QLatin1String("/data/test.qhp");
57}
58
59void tst_QHelpProjectData::readData()
60{
61 QHelpProjectData data;
62 if (!data.readData(fileName: m_inputFile))
63 QFAIL("Cannot parse qhp file!");
64}
65
66void tst_QHelpProjectData::namespaceName()
67{
68 QHelpProjectData data;
69 if (!data.readData(fileName: m_inputFile))
70 QFAIL("Cannot read qhp file!");
71 QCOMPARE(data.namespaceName(), QString("trolltech.com.1.0.0.test"));
72}
73
74void tst_QHelpProjectData::virtualFolder()
75{
76 QHelpProjectData data;
77 if (!data.readData(fileName: m_inputFile))
78 QFAIL("Cannot read qhp file!");
79 QCOMPARE(data.virtualFolder(), QString("testFolder"));
80}
81
82void tst_QHelpProjectData::customFilters()
83{
84 QHelpProjectData data;
85 if (!data.readData(fileName: m_inputFile))
86 QFAIL("Cannot read qhp file!");
87
88 const QList<QHelpDataCustomFilter> filters = data.customFilters();
89 QCOMPARE(filters.count(), 2);
90
91 for (const QHelpDataCustomFilter &f : filters) {
92 if (f.name == QLatin1String("Custom Filter 1")) {
93 for (const QString &id : f.filterAttributes) {
94 if (id != QLatin1String("test")
95 && id != QLatin1String("filter1"))
96 QFAIL("Wrong filter attribute!");
97 }
98 } else if (f.name == QLatin1String("Custom Filter 2")) {
99 for (const QString &id : f.filterAttributes) {
100 if (id != QLatin1String("test")
101 && id != QLatin1String("filter2"))
102 QFAIL("Wrong filter attribute!");
103 }
104 } else {
105 QFAIL("Unexpected filter name!");
106 }
107 }
108}
109
110void tst_QHelpProjectData::filterSections()
111{
112 QHelpProjectData data;
113 if (!data.readData(fileName: m_inputFile))
114 QFAIL("Cannot read qhp file!");
115
116 const QList<QHelpDataFilterSection> sections = data.filterSections();
117 QCOMPARE(sections.count(), 2);
118
119 for (const QHelpDataFilterSection &s : sections) {
120 if (s.filterAttributes().contains(str: "filter1")) {
121 const auto indices = s.indices();
122 QCOMPARE(indices.size(), 5);
123 for (const QHelpDataIndexItem &idx : indices) {
124 if (idx.name == QLatin1String("foo")) {
125 QCOMPARE(idx.identifier, QString("Test::foo"));
126 } else if (idx.name == QLatin1String("bar")) {
127 QCOMPARE(idx.reference, QString("test.html#bar"));
128 } else if (idx.name == QLatin1String("bla")) {
129 QCOMPARE(idx.identifier, QString("Test::bla"));
130 } else if (idx.name == QLatin1String("einstein")) {
131 QCOMPARE(idx.reference, QString("people.html#einstein"));
132 } else if (idx.name == QLatin1String("newton")) {
133 QCOMPARE(idx.identifier, QString("People::newton"));
134 } else {
135 QFAIL("Unexpected index!");
136 }
137 }
138 QCOMPARE(s.contents().count(), 1);
139 QCOMPARE(s.contents().first()->children().count(), 5);
140 } else if (s.filterAttributes().contains(str: "filter2")) {
141 QCOMPARE(s.contents().count(), 1);
142 const QStringList lst = {
143 "cars.html",
144 "classic.css",
145 "fancy.html",
146 };
147 auto files = s.files();
148 std::sort(first: files.begin(), last: files.end());
149 QCOMPARE(files, lst);
150 } else {
151 QFAIL("Unexpected filter attribute!");
152 }
153 }
154}
155
156void tst_QHelpProjectData::metaData()
157{
158 QHelpProjectData data;
159 if (!data.readData(fileName: m_inputFile))
160 QFAIL("Cannot read qhp file!");
161
162 QCOMPARE(data.metaData().count(), 2);
163 QCOMPARE(data.metaData().value("author").toString(),
164 QString("Digia Plc and/or its subsidiary(-ies)"));
165}
166
167void tst_QHelpProjectData::rootPath()
168{
169 QHelpProjectData data;
170 if (!data.readData(fileName: m_inputFile))
171 QFAIL("Cannot read qhp file!");
172
173 QFileInfo fi(m_inputFile);
174 QCOMPARE(data.rootPath(), fi.absolutePath());
175}
176
177QTEST_MAIN(tst_QHelpProjectData)
178#include "tst_qhelpprojectdata.moc"
179

source code of qttools/tests/auto/qhelpprojectdata/tst_qhelpprojectdata.cpp