diff options
author | Paul Wicking <paul.wicking@qt.io> | 2018-10-10 15:59:52 +0200 |
---|---|---|
committer | Paul Wicking <paul.wicking@qt.io> | 2018-10-16 15:23:05 +0000 |
commit | 10b3e1eb28b9d4190bdb40bfde9ca2a629e0dd0c (patch) | |
tree | 940c2471ea3e7803ec6e50cc2242405b3b809c4a /tests | |
parent | cece9dd864e847f3360c9bdd19cfaa75d8203738 (diff) |
QDoc: Add more unit tests for QDocGlobals
This change adds a set of simple unittests for QDocGlobals,
aiming for close to full coverage. It also cleans up the
unittest project includes to avoid unnecessary overhead or
unresolved includes in tests.
Fixes: QTBUG-71166
Change-Id: Ia8c81ea3b598b4eaadc56c16e0f84416aca90d6b
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qdoc/qdocglobals/qdocglobals.pro | 6 | ||||
-rw-r--r-- | tests/auto/qdoc/qdocglobals/tst_qdocglobals.cpp | 205 |
2 files changed, 195 insertions, 16 deletions
diff --git a/tests/auto/qdoc/qdocglobals/qdocglobals.pro b/tests/auto/qdoc/qdocglobals/qdocglobals.pro index eecfc35f5..fa7ddb8e0 100644 --- a/tests/auto/qdoc/qdocglobals/qdocglobals.pro +++ b/tests/auto/qdoc/qdocglobals/qdocglobals.pro @@ -1,7 +1,9 @@ CONFIG += testcase QT = core testlib TARGET = tst_qdocglobals +INCLUDEPATH += $$PWD/../../../../src/qdoc -include($$PWD/../../../../src/qdoc/qdoc.pri) +HEADERS += $$PWD/../../../../src/qdoc/qdocglobals.h -SOURCES += tst_qdocglobals.cpp +SOURCES += $$PWD/../../../../src/qdoc/qdocglobals.cpp \ + tst_qdocglobals.cpp diff --git a/tests/auto/qdoc/qdocglobals/tst_qdocglobals.cpp b/tests/auto/qdoc/qdocglobals/tst_qdocglobals.cpp index d534a9646..286363500 100644 --- a/tests/auto/qdoc/qdocglobals/tst_qdocglobals.cpp +++ b/tests/auto/qdoc/qdocglobals/tst_qdocglobals.cpp @@ -26,31 +26,208 @@ ** ****************************************************************************/ -#include <QtTest/QtTest> #include "qdocglobals.h" -class qdocglobals : public QObject +#include <QtCore/qhash.h> +#include <QtCore/qstringlist.h> +#include <QtTest/QtTest> + +class testQDocGlobals : public QObject { Q_OBJECT private slots: - void testClassMembersInitializeToFalse(); + void testClassMembersInitializeToFalseOrEmpty(); + void testEnableHighlighting(); + void testSetShowInternal(); + void testSetSingleExec(); + void testSetWriteQaPages(); + void testRedirectDocumentationToDevNull(); + void testSetNoLinkErrors(); + void testSetAutoLinkErrors(); + void testSetObsoleteLinks(); + void testAddDefine(); + void testAddIncludePath(); + void testDependModules(); + void testAppendToIndexDirs(); + void testSetCurrentDir(); + void testPreviousCurrentDir(); + void testDefaults(); }; -void qdocglobals::testClassMembersInitializeToFalse() +void testQDocGlobals::testClassMembersInitializeToFalseOrEmpty() +{ + QDocGlobals qdocTestGlobals; + QCOMPARE(qdocTestGlobals.highlighting(), false); + QCOMPARE(qdocTestGlobals.showInternal(), false); + QCOMPARE(qdocTestGlobals.singleExec(), false); + QCOMPARE(qdocTestGlobals.writeQaPages(), false); + QCOMPARE(qdocTestGlobals.redirectDocumentationToDevNull(), false); + QCOMPARE(qdocTestGlobals.noLinkErrors(), false); + QCOMPARE(qdocTestGlobals.autolinkErrors(), false); + QCOMPARE(qdocTestGlobals.obsoleteLinks(), false); + + QVERIFY(qdocTestGlobals.defines().isEmpty()); + QVERIFY(qdocTestGlobals.includesPaths().isEmpty()); + QVERIFY(qdocTestGlobals.dependModules().isEmpty()); + QVERIFY(qdocTestGlobals.indexDirs().isEmpty()); + QVERIFY(qdocTestGlobals.currentDir().isEmpty()); + QVERIFY(qdocTestGlobals.previousCurrentDir().isEmpty()); + QVERIFY(qdocTestGlobals.defaults().isEmpty()); +} + +void testQDocGlobals::testEnableHighlighting() +{ + QDocGlobals qdocTestGlobals; + qdocTestGlobals.enableHighlighting(true); + QVERIFY(qdocTestGlobals.highlighting()); +} + +void testQDocGlobals::testSetShowInternal() +{ + QDocGlobals qdocTestGlobals; + qdocTestGlobals.setShowInternal(true); + QVERIFY(qdocTestGlobals.showInternal()); +} + +void testQDocGlobals::testSetSingleExec() +{ + QDocGlobals qdocTestGlobals; + qdocTestGlobals.setSingleExec(true); + QVERIFY(qdocTestGlobals.singleExec()); +} + +void testQDocGlobals::testSetWriteQaPages() +{ + QDocGlobals qdocTestGlobals; + qdocTestGlobals.setWriteQaPages(true); + QVERIFY(qdocTestGlobals.writeQaPages()); +} + +void testQDocGlobals::testRedirectDocumentationToDevNull() +{ + QDocGlobals qdocTestGlobals; + qdocTestGlobals.setRedirectDocumentationToDevNull(true); + QVERIFY(qdocTestGlobals.redirectDocumentationToDevNull()); +} + +void testQDocGlobals::testSetNoLinkErrors() +{ + QDocGlobals qdocTestGlobals; + qdocTestGlobals.setNoLinkErrors(true); + QVERIFY(qdocTestGlobals.noLinkErrors()); +} + +void testQDocGlobals::testSetAutoLinkErrors() +{ + QDocGlobals qdocTestGlobals; + qdocTestGlobals.setAutolinkErrors(true); + QVERIFY(qdocTestGlobals.autolinkErrors()); +} + +void testQDocGlobals::testSetObsoleteLinks() +{ + QDocGlobals qdocTestGlobals; + qdocTestGlobals.setObsoleteLinks(true); + QVERIFY(qdocTestGlobals.obsoleteLinks()); +} + +void testQDocGlobals::testAddDefine() +{ + QDocGlobals qdocTestGlobals; + QStringList defineTestList1 = { QStringLiteral("qtforpython") }; + QStringList defineTestList2 = { QStringLiteral("example") }; + QStringList expected; + expected << defineTestList1 << defineTestList2; + + qdocTestGlobals.addDefine(defineTestList1); + QCOMPARE(qdocTestGlobals.defines().size(), 1); + qdocTestGlobals.addDefine(defineTestList2); + QCOMPARE(qdocTestGlobals.defines().size(), 2); + QCOMPARE(qdocTestGlobals.defines(), expected); +} + +void testQDocGlobals::testAddIncludePath() { - QDocGlobals qdocGlobals; - QCOMPARE(qdocGlobals.highlighting(), false); - QCOMPARE(qdocGlobals.showInternal(), false); - QCOMPARE(qdocGlobals.singleExec(), false); - QCOMPARE(qdocGlobals.writeQaPages(), false); - QCOMPARE(qdocGlobals.redirectDocumentationToDevNull(), false); - QCOMPARE(qdocGlobals.noLinkErrors(), false); - QCOMPARE(qdocGlobals.autolinkErrors(), false); - QCOMPARE(qdocGlobals.obsoleteLinks(), false); + QDocGlobals qdocTestGlobals; + QString testFlag = "-I"; + QString testPath0 = "/qt5/qtdoc/doc/."; + QString testPath1 = "/qt5/qtbase/mkspecs/linux-g++"; + QStringList expected = { "-I/qt5/qtdoc/doc/.", + "-I/qt5/qtbase/mkspecs/linux-g++" }; + + qdocTestGlobals.addIncludePath(testFlag, testPath0); + qdocTestGlobals.addIncludePath(testFlag, testPath1); + QStringList result = qdocTestGlobals.includesPaths(); + QCOMPARE(result, expected); +} + +void testQDocGlobals::testDependModules() +{ + QDocGlobals qdocTestGlobals; + QStringList expected = { "qdoc", "qmake", "qtcore", "qthelp", "qtqml" }; + + qdocTestGlobals.dependModules() = expected; + QCOMPARE(qdocTestGlobals.dependModules().size(), 5); + QCOMPARE(qdocTestGlobals.dependModules(), expected); +} + +void testQDocGlobals::testAppendToIndexDirs() +{ + QDocGlobals qdocTestGlobals; + QString testPath = "/qt5/qtbase/doc"; + QStringList expected; + expected << testPath; + + qdocTestGlobals.appendToIndexDirs(testPath); + QCOMPARE(qdocTestGlobals.indexDirs(), expected); +} + +void testQDocGlobals::testSetCurrentDir() +{ + QDocGlobals qdocTestGlobals; + QString expected = "/qt5/qtdoc/doc/config"; + + qdocTestGlobals.setCurrentDir(expected); + QCOMPARE(qdocTestGlobals.currentDir(), expected); +} + +void testQDocGlobals::testPreviousCurrentDir() +{ + QDocGlobals qdocTestGlobals; + QString expected = "/qt5/qtdoc/doc"; + + qdocTestGlobals.setCurrentDir(expected); + QCOMPARE(qdocTestGlobals.currentDir(), expected); +} + +void testQDocGlobals::testDefaults() +{ + QDocGlobals qdocTestGlobals; + + QHash<QString, QString> expected = { + {"codeindent", "0"}, {"falsehoods", "0"}, + {"fileextensions", "*.cpp *.h *.qdoc *.qml"}, {"language", "Cpp"}, + {"outputformats", "HTML"}, {"tabsize", "8"}}; + + qdocTestGlobals.defaults().insert(QStringLiteral("codeindent"), + QLatin1String("0")); + qdocTestGlobals.defaults().insert(QStringLiteral("falsehoods"), + QLatin1String("0")); + qdocTestGlobals.defaults().insert(QStringLiteral("fileextensions"), + QLatin1String("*.cpp *.h *.qdoc *.qml")); + qdocTestGlobals.defaults().insert(QStringLiteral("language"), + QLatin1String("Cpp")); + qdocTestGlobals.defaults().insert(QStringLiteral("outputformats"), + QLatin1String("HTML")); + qdocTestGlobals.defaults().insert(QStringLiteral("tabsize"), + QLatin1String("8")); + + QHash<QString, QString> result = qdocTestGlobals.defaults(); + QCOMPARE(result, expected); } -QTEST_APPLESS_MAIN(qdocglobals) +QTEST_APPLESS_MAIN(testQDocGlobals) #include "tst_qdocglobals.moc" |