| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
#include <QtTest/QtTest> |
| 4 |
|
| 5 |
#include <QtCore/QFileInfo> |
| 6 |
|
| 7 |
#include "../../../src/assistant/qhelpgenerator/qhelpprojectdata_p.h" |
| 8 |
|
| 9 |
class tst_QHelpProjectData : public QObject |
| 10 |
{ |
| 11 |
Q_OBJECT |
| 12 |
|
| 13 |
private slots: |
| 14 |
void initTestCase(); |
| 15 |
|
| 16 |
void readData(); |
| 17 |
void namespaceName(); |
| 18 |
void virtualFolder(); |
| 19 |
void customFilters(); |
| 20 |
void filterSections(); |
| 21 |
void metaData(); |
| 22 |
void rootPath(); |
| 23 |
|
| 24 |
private: |
| 25 |
QString m_inputFile; |
| 26 |
}; |
| 27 |
|
| 28 |
void tst_QHelpProjectData::initTestCase() |
| 29 |
{ |
| 30 |
const QString path = QLatin1String(SRCDIR); |
| 31 |
m_inputFile = path + QLatin1String("/data/test.qhp"); |
| 32 |
} |
| 33 |
|
| 34 |
void tst_QHelpProjectData::readData() |
| 35 |
{ |
| 36 |
QHelpProjectData data; |
| 37 |
if (!data.readData(m_inputFile)) |
| 38 |
QFAIL("Cannot parse qhp file!"); |
| 39 |
} |
| 40 |
|
| 41 |
void tst_QHelpProjectData::namespaceName() |
| 42 |
{ |
| 43 |
QHelpProjectData data; |
| 44 |
if (!data.readData(m_inputFile)) |
| 45 |
QFAIL("Cannot read qhp file!"); |
| 46 |
QCOMPARE(data.namespaceName(), QString("trolltech.com.1.0.0.test")); |
| 47 |
} |
| 48 |
|
| 49 |
void tst_QHelpProjectData::virtualFolder() |
| 50 |
{ |
| 51 |
QHelpProjectData data; |
| 52 |
if (!data.readData(m_inputFile)) |
| 53 |
QFAIL("Cannot read qhp file!"); |
| 54 |
QCOMPARE(data.virtualFolder(), QString("testFolder")); |
| 55 |
} |
| 56 |
|
| 57 |
void tst_QHelpProjectData::customFilters() |
| 58 |
{ |
| 59 |
QHelpProjectData data; |
| 60 |
if (!data.readData(m_inputFile)) |
| 61 |
QFAIL("Cannot read qhp file!"); |
| 62 |
|
| 63 |
const QList<QHelpDataCustomFilter> filters = data.customFilters(); |
| 64 |
QCOMPARE(filters.size(), 2); |
| 65 |
|
| 66 |
for (const QHelpDataCustomFilter &f : filters) { |
| 67 |
if (f.name == QLatin1String("Custom Filter 1")) { |
| 68 |
for (const QString &id : f.filterAttributes) { |
| 69 |
if (id != QLatin1String("test") |
| 70 |
&& id != QLatin1String("filter1")) |
| 71 |
QFAIL("Wrong filter attribute!"); |
| 72 |
} |
| 73 |
} else if (f.name == QLatin1String("Custom Filter 2")) { |
| 74 |
for (const QString &id : f.filterAttributes) { |
| 75 |
if (id != QLatin1String("test") |
| 76 |
&& id != QLatin1String("filter2")) |
| 77 |
QFAIL("Wrong filter attribute!"); |
| 78 |
} |
| 79 |
} else { |
| 80 |
QFAIL("Unexpected filter name!"); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
void tst_QHelpProjectData::filterSections() |
| 86 |
{ |
| 87 |
QHelpProjectData data; |
| 88 |
if (!data.readData(m_inputFile)) |
| 89 |
QFAIL("Cannot read qhp file!"); |
| 90 |
|
| 91 |
const QList<QHelpDataFilterSection> sections = data.filterSections(); |
| 92 |
QCOMPARE(sections.size(), 2); |
| 93 |
|
| 94 |
for (const QHelpDataFilterSection &s : sections) { |
| 95 |
if (s.filterAttributes().contains("filter1")) { |
| 96 |
const auto indices = s.indices(); |
| 97 |
QCOMPARE(indices.size(), 5); |
| 98 |
for (const QHelpDataIndexItem &idx : indices) { |
| 99 |
if (idx.name == QLatin1String("foo")) { |
| 100 |
QCOMPARE(idx.identifier, QString("Test::foo")); |
| 101 |
} else if (idx.name == QLatin1String("bar")) { |
| 102 |
QCOMPARE(idx.reference, QString("test.html#bar")); |
| 103 |
} else if (idx.name == QLatin1String("bla")) { |
| 104 |
QCOMPARE(idx.identifier, QString("Test::bla")); |
| 105 |
} else if (idx.name == QLatin1String("einstein")) { |
| 106 |
QCOMPARE(idx.reference, QString("people.html#einstein")); |
| 107 |
} else if (idx.name == QLatin1String("newton")) { |
| 108 |
QCOMPARE(idx.identifier, QString("People::newton")); |
| 109 |
} else { |
| 110 |
QFAIL("Unexpected index!"); |
| 111 |
} |
| 112 |
} |
| 113 |
QCOMPARE(s.contents().size(), 1); |
| 114 |
QCOMPARE(s.contents().first()->children().size(), 5); |
| 115 |
} else if (s.filterAttributes().contains("filter2")) { |
| 116 |
QCOMPARE(s.contents().size(), 1); |
| 117 |
const QStringList lst = { |
| 118 |
"cars.html", |
| 119 |
"classic.css", |
| 120 |
"fancy.html", |
| 121 |
}; |
| 122 |
auto files = s.files(); |
| 123 |
std::sort(files.begin(), files.end()); |
| 124 |
QCOMPARE(files, lst); |
| 125 |
} else { |
| 126 |
QFAIL("Unexpected filter attribute!"); |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
void tst_QHelpProjectData::metaData() |
| 132 |
{ |
| 133 |
QHelpProjectData data; |
| 134 |
if (!data.readData(m_inputFile)) |
| 135 |
QFAIL("Cannot read qhp file!"); |
| 136 |
|
| 137 |
QCOMPARE(data.metaData().size(), 2); |
| 138 |
QCOMPARE(data.metaData().value("author").toString(), |
| 139 |
QString("Digia Plc and/or its subsidiary(-ies)")); |
| 140 |
} |
| 141 |
|
| 142 |
void tst_QHelpProjectData::rootPath() |
| 143 |
{ |
| 144 |
QHelpProjectData data; |
| 145 |
if (!data.readData(m_inputFile)) |
| 146 |
QFAIL("Cannot read qhp file!"); |
| 147 |
|
| 148 |
QFileInfo fi(m_inputFile); |
| 149 |
QCOMPARE(data.rootPath(), fi.absolutePath()); |
| 150 |
} |
| 151 |
|
| 152 |
QTEST_MAIN(tst_QHelpProjectData) |
| 153 |
#include "tst_qhelpprojectdata.moc" |