summaryrefslogtreecommitdiffstats
path: root/src/qdoc/qdoc/tests/utilities
diff options
context:
space:
mode:
Diffstat (limited to 'src/qdoc/qdoc/tests/utilities')
-rw-r--r--src/qdoc/qdoc/tests/utilities/CMakeLists.txt21
-rw-r--r--src/qdoc/qdoc/tests/utilities/tst_utilities.cpp134
2 files changed, 155 insertions, 0 deletions
diff --git a/src/qdoc/qdoc/tests/utilities/CMakeLists.txt b/src/qdoc/qdoc/tests/utilities/CMakeLists.txt
new file mode 100644
index 000000000..dd2883d32
--- /dev/null
+++ b/src/qdoc/qdoc/tests/utilities/CMakeLists.txt
@@ -0,0 +1,21 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## tst_utilities Test:
+#####################################################################
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_utilities LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_utilities
+ SOURCES
+ ${CMAKE_CURRENT_LIST_DIR}/tst_utilities.cpp
+
+ ${CMAKE_CURRENT_LIST_DIR}/../../src/qdoc/utilities.cpp
+ INCLUDE_DIRECTORIES
+ ${CMAKE_CURRENT_LIST_DIR}/../../src/
+)
diff --git a/src/qdoc/qdoc/tests/utilities/tst_utilities.cpp b/src/qdoc/qdoc/tests/utilities/tst_utilities.cpp
new file mode 100644
index 000000000..160e4d15c
--- /dev/null
+++ b/src/qdoc/qdoc/tests/utilities/tst_utilities.cpp
@@ -0,0 +1,134 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include "qdoc/utilities.h"
+
+#include <QtTest/QtTest>
+
+class tst_Utilities : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void loggingCategoryName();
+ void loggingCategoryDefaults();
+ void startDebugging();
+ void stopDebugging();
+ void debugging();
+ void callSeparatorForOneWord();
+ void callSeparatorForMoreThanOneWord();
+ void callCommaForOneWord();
+ void callCommaForTwoWords();
+ void callCommaForThreeWords();
+};
+
+void tst_Utilities::loggingCategoryName()
+{
+ const QString expected = "qt.qdoc";
+ QCOMPARE(lcQdoc().categoryName(), expected);
+}
+
+void tst_Utilities::loggingCategoryDefaults()
+{
+ QVERIFY(lcQdoc().isCriticalEnabled());
+ QVERIFY(lcQdoc().isWarningEnabled());
+ QVERIFY(!lcQdoc().isDebugEnabled());
+ QVERIFY(lcQdoc().isInfoEnabled());
+}
+
+void tst_Utilities::startDebugging()
+{
+ QVERIFY(!lcQdoc().isDebugEnabled());
+ Utilities::startDebugging("test");
+ QVERIFY(lcQdoc().isDebugEnabled());
+}
+
+void tst_Utilities::stopDebugging()
+{
+ Utilities::startDebugging("test");
+ QVERIFY(lcQdoc().isDebugEnabled());
+ Utilities::stopDebugging("test");
+ QVERIFY(!lcQdoc().isDebugEnabled());
+}
+
+void tst_Utilities::debugging()
+{
+ QVERIFY(!lcQdoc().isDebugEnabled());
+ QVERIFY(!Utilities::debugging());
+ Utilities::startDebugging("test");
+ QVERIFY(lcQdoc().isDebugEnabled());
+ QVERIFY(Utilities::debugging());
+}
+
+void tst_Utilities::callSeparatorForOneWord()
+{
+ const QStringList listOfWords { "one" };
+ const QString expected = QStringLiteral("one.");
+
+ int index = 0;
+ QString result;
+ for (const auto &word : listOfWords) {
+ result.append(word);
+ result.append(Utilities::separator(index++, listOfWords.size()));
+ }
+ QCOMPARE(result, expected);
+}
+
+void tst_Utilities::callSeparatorForMoreThanOneWord()
+{
+ const QStringList listOfWords { "one", "two" };
+ const QString expected = QStringLiteral("one and two.");
+
+ int index = 0;
+ QString result;
+ for (const auto &word : listOfWords) {
+ result.append(word);
+ result.append(Utilities::separator(index++, listOfWords.size()));
+ }
+ QCOMPARE(result, expected);
+}
+
+void tst_Utilities::callCommaForOneWord()
+{
+ const QStringList listOfWords { "one" };
+ const QString expected = QStringLiteral("one");
+
+ int index = 0;
+ QString result;
+ for (const auto &word : listOfWords) {
+ result.append(word);
+ result.append(Utilities::comma(index++, listOfWords.size()));
+ }
+ QCOMPARE(result, expected);
+}
+void tst_Utilities::callCommaForTwoWords()
+{
+ const QStringList listOfWords { "one", "two" };
+ const QString expected = QStringLiteral("one and two");
+
+ int index = 0;
+ QString result;
+ for (const auto &word : listOfWords) {
+ result.append(word);
+ result.append(Utilities::comma(index++, listOfWords.size()));
+ }
+ QCOMPARE(result, expected);
+}
+
+void tst_Utilities::callCommaForThreeWords()
+{
+ const QStringList listOfWords { "one", "two", "three" };
+ const QString expected = QStringLiteral("one, two, and three");
+
+ int index = 0;
+ QString result;
+ for (const auto &word : listOfWords) {
+ result.append(word);
+ result.append(Utilities::comma(index++, listOfWords.size()));
+ }
+ QCOMPARE(result, expected);
+}
+
+QTEST_APPLESS_MAIN(tst_Utilities)
+
+#include "tst_utilities.moc"