From b2d3a7dac9ca968b5800b6da1661e632a7ea9e90 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 19 Oct 2018 15:22:17 +0200 Subject: shiboken/ApiExtractor tests: Use qrc files for test resources This removes the need to copy around test files and the test will also run when launched from a different directory. Extend and fix the declare_test() CMake macro to also add resource files, add .qrc files and modify the tests accordingly. Task-number: PYSIDE-834 Change-Id: Id469e0b11837f7c6a7d71a20494ac019a32d8ed0 Reviewed-by: Christian Tismer --- sources/shiboken2/ApiExtractor/tests/CMakeLists.txt | 17 +++++++++-------- .../shiboken2/ApiExtractor/tests/testcodeinjection.cpp | 6 ++---- .../shiboken2/ApiExtractor/tests/testcodeinjection.qrc | 5 +++++ .../ApiExtractor/tests/testmodifydocumentation.cpp | 2 +- .../ApiExtractor/tests/testmodifydocumentation.qrc | 5 +++++ 5 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 sources/shiboken2/ApiExtractor/tests/testcodeinjection.qrc create mode 100644 sources/shiboken2/ApiExtractor/tests/testmodifydocumentation.qrc (limited to 'sources') diff --git a/sources/shiboken2/ApiExtractor/tests/CMakeLists.txt b/sources/shiboken2/ApiExtractor/tests/CMakeLists.txt index 860a37d9d..e100ef493 100644 --- a/sources/shiboken2/ApiExtractor/tests/CMakeLists.txt +++ b/sources/shiboken2/ApiExtractor/tests/CMakeLists.txt @@ -4,13 +4,18 @@ find_package(Qt5Test) find_package(Qt5Xml) find_package(Qt5XmlPatterns) +set(CMAKE_AUTORCC ON) + macro(declare_test testname) # gone: qt4_automoc("${testname}.cpp") - if (EXISTS "${testname}.h") - add_executable(${testname} "${testname}.h ${testname}.cpp") - else () - add_executable(${testname} "${testname}.cpp") + set(SOURCES "${testname}.cpp") + if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${testname}.h") + list(APPEND SOURCES "${testname}.h") + endif () + if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${testname}.qrc") + list(APPEND SOURCES "${testname}.qrc") endif () + add_executable(${testname} ${SOURCES}) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${apiextractor_SOURCE_DIR} @@ -35,8 +40,6 @@ declare_test(testabstractmetatype) declare_test(testaddfunction) declare_test(testarrayargument) declare_test(testcodeinjection) -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/utf8code.txt" - "${CMAKE_CURRENT_BINARY_DIR}/utf8code.txt" COPYONLY) declare_test(testcontainer) declare_test(testconversionoperator) declare_test(testconversionruletag) @@ -68,7 +71,5 @@ declare_test(testvoidarg) declare_test(testtyperevision) if (NOT DISABLE_DOCSTRINGS) declare_test(testmodifydocumentation) - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/a.xml" - "${CMAKE_CURRENT_BINARY_DIR}/a.xml" COPYONLY) endif() diff --git a/sources/shiboken2/ApiExtractor/tests/testcodeinjection.cpp b/sources/shiboken2/ApiExtractor/tests/testcodeinjection.cpp index bf1057ee9..68da25373 100644 --- a/sources/shiboken2/ApiExtractor/tests/testcodeinjection.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testcodeinjection.cpp @@ -40,13 +40,11 @@ void TestCodeInjections::testReadFileUtf8() int argc = 0; char *argv[] = {NULL}; QCoreApplication app(argc, argv); - QString filePath = QDir::currentPath(); QString xmlCode = QLatin1String("\ \n\ \n\ - \n\ - \n\ + \n\ + \n\ \n\ \n\ \n"); diff --git a/sources/shiboken2/ApiExtractor/tests/testcodeinjection.qrc b/sources/shiboken2/ApiExtractor/tests/testcodeinjection.qrc new file mode 100644 index 000000000..61d59567b --- /dev/null +++ b/sources/shiboken2/ApiExtractor/tests/testcodeinjection.qrc @@ -0,0 +1,5 @@ + + + utf8code.txt + + diff --git a/sources/shiboken2/ApiExtractor/tests/testmodifydocumentation.cpp b/sources/shiboken2/ApiExtractor/tests/testmodifydocumentation.cpp index 7911a5eb1..f615befb4 100644 --- a/sources/shiboken2/ApiExtractor/tests/testmodifydocumentation.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testmodifydocumentation.cpp @@ -60,7 +60,7 @@ R"( QCOMPARE(docMods[1].code().trimmed(), QLatin1String("Some changed contents here")); QCOMPARE(docMods[1].signature(), QString()); QtDocParser docParser; - docParser.setDocumentationDataDirectory(QDir::currentPath()); + docParser.setDocumentationDataDirectory(QLatin1String(":")); docParser.fillDocumentation(classA); const QString actualDocSimplified = classA->documentation().value().simplified(); diff --git a/sources/shiboken2/ApiExtractor/tests/testmodifydocumentation.qrc b/sources/shiboken2/ApiExtractor/tests/testmodifydocumentation.qrc new file mode 100644 index 000000000..76b1bfc61 --- /dev/null +++ b/sources/shiboken2/ApiExtractor/tests/testmodifydocumentation.qrc @@ -0,0 +1,5 @@ + + + a.xml + + -- cgit v1.2.3