diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-03-17 08:30:55 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-03-17 14:42:47 +0100 |
commit | 64f4fcdfcfd9a6869e8f0ad42c02051b663e61ad (patch) | |
tree | 2ba5a73d9168892d7d2647af21652aa981bbbdfe | |
parent | 61ba805cb5b5d2dc053acd8761d934f005d4094d (diff) |
shiboken6/documentation generator: Add a manual test tool for QtXmlToSphinx
Add a test tool similar to qtxmltosphinxtest, but with command line parameters.
It is standalone-buildable.
Change-Id: Id02f4b1b74a0ce7e011f0ae388869d8dda47bbf4
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r-- | sources/shiboken6/tests/qtxmltosphinx/CMakeLists.txt | 29 | ||||
-rw-r--r-- | sources/shiboken6/tests/qtxmltosphinx/main.cpp | 130 |
2 files changed, 159 insertions, 0 deletions
diff --git a/sources/shiboken6/tests/qtxmltosphinx/CMakeLists.txt b/sources/shiboken6/tests/qtxmltosphinx/CMakeLists.txt new file mode 100644 index 000000000..cc73ac727 --- /dev/null +++ b/sources/shiboken6/tests/qtxmltosphinx/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.16) + +# Standalone-buildable + +project(qtxmltosphinx) + +set(CMAKE_AUTOMOC ON) + +find_package(Qt6 COMPONENTS Core) + +set(generator_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../generator) +set(api_extractor_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../ApiExtractor) + +set(qtxmltosphinx_SRC + ${generator_src_dir}/qtdoc/qtxmltosphinx.cpp + ${api_extractor_src_dir}/codesniphelpers.cpp + ${api_extractor_src_dir}/textstream.cpp + main.cpp) + +add_executable(qtxmltosphinx ${qtxmltosphinx_SRC}) + +target_include_directories(qtxmltosphinx PRIVATE + ${CMAKE_CURRENT_BINARY_DIR} + ${api_extractor_src_dir} + ${generator_src_dir} + ${generator_src_dir}/shiboken + ${generator_src_dir}/qtdoc) + +target_link_libraries(qtxmltosphinx PRIVATE Qt::Core) diff --git a/sources/shiboken6/tests/qtxmltosphinx/main.cpp b/sources/shiboken6/tests/qtxmltosphinx/main.cpp new file mode 100644 index 000000000..2e34bdedd --- /dev/null +++ b/sources/shiboken6/tests/qtxmltosphinx/main.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of Qt for Python. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtxmltosphinxinterface.h" +#include "qtxmltosphinx.h" + +#include <QtCore/QCommandLineParser> +#include <QtCore/QCoreApplication> +#include <QtCore/QDebug> +#include <QtCore/QFile> +#include <QtCore/QLoggingCategory> + +#include <exception> +#include <iostream> + +static const char help[] = R"(QtXmlToSphinx WebXML to rst converter + +A manual test for converting WebXML files to rst files for checking +formatting. +)"; + +Q_LOGGING_CATEGORY(lcQtXmlToSphinx, "qt.xmltosphinx"); + +static std::ostream &operator<<(std::ostream &str, const QString &s) +{ + str << s.toUtf8().constData(); + return str; +} + +class QtXmlToSphinxDocGenerator : public QtXmlToSphinxDocGeneratorInterface +{ +public: + QtXmlToSphinxDocGenerator() = default; + + QString expandFunction(const QString &) const override; + QString expandClass(const QString &, const QString &) const override; + QString resolveContextForMethod(const QString &, + const QString &) const override; + const QLoggingCategory &loggingCategory() const override; + QtXmlToSphinxLink resolveLink(const QtXmlToSphinxLink &link) const override; +}; + +// QtXmlToSphinxDocGeneratorInterface +QString QtXmlToSphinxDocGenerator::expandFunction(const QString &) const +{ + return {}; +} + +QString QtXmlToSphinxDocGenerator::expandClass(const QString &, const QString &) const +{ + return {}; +} + +QString QtXmlToSphinxDocGenerator::resolveContextForMethod(const QString &, const QString &) const +{ + return {}; +} + +const QLoggingCategory &QtXmlToSphinxDocGenerator::loggingCategory() const +{ + return lcQtXmlToSphinx(); +} + +QtXmlToSphinxLink QtXmlToSphinxDocGenerator::resolveLink(const QtXmlToSphinxLink &link) const +{ + return link; +} + +static bool run(const QString &fileName) +{ + QtXmlToSphinxDocGenerator generator; + QtXmlToSphinxParameters parameters; + + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + std::cerr << "Cannot open " << fileName << ": " << file.errorString() << '\n'; + return false; + } + const QString xml = QString::fromUtf8(file.readAll()); + file.close(); + std::cout << QtXmlToSphinx(&generator, parameters, xml).result(); + return true; +} + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + + QCommandLineParser commandLineParser; + commandLineParser.setApplicationDescription(QString::fromLatin1(help)); + commandLineParser.addHelpOption(); + commandLineParser.addPositionalArgument(u"[file]"_qs, u"WebXML file to process."_qs); + commandLineParser.process(QCoreApplication::arguments()); + if (commandLineParser.positionalArguments().isEmpty()) + commandLineParser.showHelp(0); // quits + + int exitCode = 1; + try { + if (run(commandLineParser.positionalArguments().constFirst())) + exitCode = 0; + } catch (const std::exception &e) { + std::cerr << "An exception occurred: " << e.what() << '\n'; + } + return exitCode; +} |