diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2017-12-09 12:20:58 (GMT) |
---|---|---|
committer | Sebastian Holtermann <sebholt@xwmw.org> | 2017-12-13 12:50:18 (GMT) |
commit | e9fcd1545facf6300181db843260008e1069c7b4 (patch) | |
tree | d8baae614e46dd067ce6ccb3a26e63cd65cab0ae /Tests/QtAutogen | |
parent | 54b4ff2aee015768a990cb3fccb79f8e87b38a19 (diff) | |
download | CMake-e9fcd1545facf6300181db843260008e1069c7b4.zip CMake-e9fcd1545facf6300181db843260008e1069c7b4.tar.gz CMake-e9fcd1545facf6300181db843260008e1069c7b4.tar.bz2 |
Autogen: Tests: Separate RerunMocPlugin test
Diffstat (limited to 'Tests/QtAutogen')
24 files changed, 292 insertions, 0 deletions
diff --git a/Tests/QtAutogen/CommonTests.cmake b/Tests/QtAutogen/CommonTests.cmake index 94413a3..b03c282 100644 --- a/Tests/QtAutogen/CommonTests.cmake +++ b/Tests/QtAutogen/CommonTests.cmake @@ -33,3 +33,6 @@ ADD_AUTOGEN_TEST(StaticLibraryCycle slc) ADD_AUTOGEN_TEST(Complex QtAutogen) # Rerun tests ADD_AUTOGEN_TEST(RerunMocBasic) +if(NOT QT_TEST_VERSION STREQUAL 4) + ADD_AUTOGEN_TEST(RerunMocPlugin) +endif() diff --git a/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt b/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt new file mode 100644 index 0000000..076de8b --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt @@ -0,0 +1,105 @@ +cmake_minimum_required(VERSION 3.10) +project(RerunMocPlugin) +include("../AutogenTest.cmake") + +# Tests Q_PLUGIN_METADATA and CMAKE_AUTOMOC_DEPEND_FILTERS +# json file change detection + +# Dummy executable to generate a clean target +add_executable(dummy dummy.cpp) + +# Utility variables +set(timeformat "%Y%j%H%M%S") +set(mocPlugSrcDir "${CMAKE_CURRENT_SOURCE_DIR}/MocPlugin") +set(mocPlugBinDir "${CMAKE_CURRENT_BINARY_DIR}/MocPlugin") + +# Initial buid +try_compile(MOC_PLUGIN + "${mocPlugBinDir}" + "${mocPlugSrcDir}" + MocPlugin + CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}" + "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}" + OUTPUT_VARIABLE output +) +if (NOT MOC_PLUGIN) + message(SEND_ERROR "Initial build of mocPlugin failed. Output: ${output}") +endif() + +find_library(plAFile "PlugA" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) +find_library(plBFile "PlugB" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) +find_library(plCFile "PlugC" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) +find_library(plDFile "PlugD" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) +find_library(plEFile "PlugE" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) + +# - Ensure that the timestamp will change. +# - Change the json files referenced by Q_PLUGIN_METADATA +# - Rebuild +file(TIMESTAMP "${plAFile}" plABefore "${timeformat}") +file(TIMESTAMP "${plBFile}" plBBefore "${timeformat}") +file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}") +file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}") +file(TIMESTAMP "${plEFile}" plEBefore "${timeformat}") + +execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleC.json") +configure_file("${mocPlugSrcDir}/jsonIn/StyleE.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD.json") +configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/StyleE.json") +execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}") + +file(TIMESTAMP "${plAFile}" plAAfter "${timeformat}") +file(TIMESTAMP "${plBFile}" plBAfter "${timeformat}") +file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}") +file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}") +file(TIMESTAMP "${plEFile}" plEAfter "${timeformat}") + +if (plAAfter GREATER plABefore) + message(SEND_ERROR "file (${plAFile}) should not have changed!") +endif() +if (plBAfter GREATER plBBefore) + message(SEND_ERROR "file (${plBFile}) should not have changed!") +endif() +if (NOT plCAfter GREATER plCBefore) + message(SEND_ERROR "file (${plCFile}) should have changed!") +endif() +if (NOT plDAfter GREATER plDBefore) + message(SEND_ERROR "file (${plDFile}) should have changed!") +endif() +if (NOT plEAfter GREATER plEBefore) + # There's a bug in Ninja on Windows + # https://gitlab.kitware.com/cmake/cmake/issues/16776 + if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja")) + message(SEND_ERROR "file (${plEFile}) should have changed!") + endif() +endif() + +# - Ensure that the timestamp will change. +# - Change the json files referenced by A_CUSTOM_MACRO +# - Rebuild +file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}") +file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}") +file(TIMESTAMP "${plEFile}" plEBefore "${timeformat}") + +execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +configure_file("${mocPlugSrcDir}/jsonIn/StyleE.json" "${mocPlugBinDir}/jsonFiles/StyleC_Custom.json") +configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD_Custom.json") +configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleE_Custom.json") +execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}") + +file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}") +file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}") +file(TIMESTAMP "${plEFile}" plEAfter "${timeformat}") + +if (NOT plCAfter GREATER plCBefore) + message(SEND_ERROR "file (${plCFile}) should have changed!") +endif() +if (NOT plDAfter GREATER plDBefore) + message(SEND_ERROR "file (${plDFile}) should have changed!") +endif() +if (NOT plEAfter GREATER plEBefore) + # There's a bug in Ninja on Windows + # https://gitlab.kitware.com/cmake/cmake/issues/16776 + if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja")) + message(SEND_ERROR "file (${plEFile}) should have changed!") + endif() +endif() diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/CMakeLists.txt b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/CMakeLists.txt new file mode 100644 index 0000000..bc0085f --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.10) +project(MocPlugin) +include("../../AutogenTest.cmake") + +if (NOT QT_TEST_VERSION STREQUAL 5) + message(SEND_ERROR "Invalid Qt version specified.") +endif() + +set(CMAKE_AUTOMOC_DEPEND_FILTERS + "A_CUSTOM_MACRO" + "[\n][ \t]*A_CUSTOM_MACRO[ \t\r\n]*\\([^,]+,[ \t\r\n]*\"([^\"]+)\"" +) + +configure_file(jsonIn/StyleC.json jsonFiles/StyleC.json) +configure_file(jsonIn/StyleC.json jsonFiles/StyleC_Custom.json) +configure_file(jsonIn/StyleD.json jsonFiles/sub/StyleD.json) +configure_file(jsonIn/StyleD.json jsonFiles/sub/StyleD_Custom.json) +configure_file(jsonIn/StyleE.json jsonFiles/StyleE.json) +configure_file(jsonIn/StyleE.json jsonFiles/StyleE_Custom.json) + +# Enable AUTOMOC +set(CMAKE_AUTOMOC TRUE) + +include_directories("${CMAKE_CURRENT_BINARY_DIR}/jsonFiles") +link_libraries(Qt5::Widgets) + +add_library(PlugA STATIC StyleA.cpp) +add_library(PlugB STATIC StyleB.cpp) +add_library(PlugC STATIC StyleC.cpp) +add_library(PlugD STATIC StyleD.cpp) +add_library(PlugE STATIC StyleE.cpp) diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleA.cpp b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleA.cpp new file mode 100644 index 0000000..b5e8753 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleA.cpp @@ -0,0 +1,6 @@ +#include "StyleA.hpp" + +QStyle* StyleA::create(const QString& key) +{ + return 0; +} diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleA.hpp b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleA.hpp new file mode 100644 index 0000000..35158a4 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleA.hpp @@ -0,0 +1,17 @@ +#ifndef STYLEA_HPP +#define STYLEA_HPP + +#include "UtilityMacros.hpp" +#include <QStylePlugin> + +class StyleA : public QStylePlugin +{ + Q_OBJECT + // Json file in source local directory + Q_PLUGIN_METADATA(IID "org.styles.A" FILE "StyleA.json") + A_CUSTOM_MACRO(SomeArg, "StyleA_Custom.json", AnotherArg) +public: + QStyle* create(const QString& key); +}; + +#endif diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleA.json b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleA.json new file mode 100644 index 0000000..cc33953 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleA.json @@ -0,0 +1 @@ +{ "Keys": [ "Rocket", "Starbuster" ] } diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleA_Custom.json b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleA_Custom.json new file mode 100644 index 0000000..cc33953 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleA_Custom.json @@ -0,0 +1 @@ +{ "Keys": [ "Rocket", "Starbuster" ] } diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleB.cpp b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleB.cpp new file mode 100644 index 0000000..17d4400 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleB.cpp @@ -0,0 +1,6 @@ +#include "StyleB.hpp" + +QStyle* StyleB::create(const QString& key) +{ + return 0; +} diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleB.hpp b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleB.hpp new file mode 100644 index 0000000..15b79c5 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleB.hpp @@ -0,0 +1,17 @@ +#ifndef STYLEB_HPP +#define STYLEB_HPP + +#include "UtilityMacros.hpp" +#include <QStylePlugin> + +class StyleB : public QStylePlugin +{ + Q_OBJECT + // Json file in source local subdirectory + Q_PLUGIN_METADATA(IID "org.styles.B" FILE "jsonIn/StyleB.json") + A_CUSTOM_MACRO(SomeArg, "jsonIn/StyleB_Custom.json", AnotherArg) +public: + QStyle* create(const QString& key); +}; + +#endif diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleC.cpp b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleC.cpp new file mode 100644 index 0000000..37e7564 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleC.cpp @@ -0,0 +1,6 @@ +#include "StyleC.hpp" + +QStyle* StyleC::create(const QString& key) +{ + return 0; +} diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleC.hpp b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleC.hpp new file mode 100644 index 0000000..b0a4115 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleC.hpp @@ -0,0 +1,17 @@ +#ifndef STYLEC_HPP +#define STYLEC_HPP + +#include "UtilityMacros.hpp" +#include <QStylePlugin> + +class StyleC : public QStylePlugin +{ + Q_OBJECT + // Json file in global root directory + Q_PLUGIN_METADATA(IID "org.styles.C" FILE "StyleC.json") + A_CUSTOM_MACRO(SomeArg, "StyleC_Custom.json", AnotherArg) +public: + QStyle* create(const QString& key); +}; + +#endif diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleD.cpp b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleD.cpp new file mode 100644 index 0000000..7e4b121 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleD.cpp @@ -0,0 +1,6 @@ +#include "StyleD.hpp" + +QStyle* StyleD::create(const QString& key) +{ + return 0; +} diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleD.hpp b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleD.hpp new file mode 100644 index 0000000..9696aaa --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleD.hpp @@ -0,0 +1,17 @@ +#ifndef STYLED_HPP +#define STYLED_HPP + +#include "UtilityMacros.hpp" +#include <QStylePlugin> + +class StyleD : public QStylePlugin +{ + Q_OBJECT + // Json file in global sub director + Q_PLUGIN_METADATA(IID "org.styles.D" FILE "sub/StyleD.json") + A_CUSTOM_MACRO(SomeArg, "sub/StyleD_Custom.json", AnotherArg) +public: + QStyle* create(const QString& key); +}; + +#endif diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleE.cpp b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleE.cpp new file mode 100644 index 0000000..3448319 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleE.cpp @@ -0,0 +1,9 @@ +#include "StyleE.hpp" + +QStyle* StyleE::create(const QString& key) +{ + return 0; +} + +// AUTOMOC the StyleEInclude.hpp header +#include "moc_StyleEInclude.cpp" diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleE.hpp b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleE.hpp new file mode 100644 index 0000000..a069034 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleE.hpp @@ -0,0 +1,10 @@ +#ifndef STYLEE_HPP +#define STYLEE_HPP + +// The included file is not in the sources list and won't be detected by +// AUTOMOC source file with the same base name. +// It is registered to AUTOMOCed via a moc_<NAME>.cpp include in StyleE.cpp +// though. +#include "StyleEInclude.hpp" + +#endif diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleEInclude.hpp b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleEInclude.hpp new file mode 100644 index 0000000..f9734db --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/StyleEInclude.hpp @@ -0,0 +1,17 @@ +#ifndef STYLEE_INCLUDE_HPP +#define STYLEE_INCLUDE_HPP + +#include "UtilityMacros.hpp" +#include <QStylePlugin> + +class StyleE : public QStylePlugin +{ + Q_OBJECT + // Json files in global root directory + Q_PLUGIN_METADATA(IID "org.styles.E" FILE "StyleE.json") + A_CUSTOM_MACRO(SomeArg, "StyleE_Custom.json", AnotherArg) +public: + QStyle* create(const QString& key); +}; + +#endif diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/UtilityMacros.hpp b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/UtilityMacros.hpp new file mode 100644 index 0000000..53a4284 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/UtilityMacros.hpp @@ -0,0 +1,7 @@ +#ifndef UTILITYMACROS_HPP +#define UTILITYMACROS_HPP + +// Empty test macro definition +#define A_CUSTOM_MACRO(name, jsonFile, pluginRegistrations) + +#endif diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleB.json b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleB.json new file mode 100644 index 0000000..cd155dc --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleB.json @@ -0,0 +1 @@ +{ "Keys": [ "Red", "Green" ] } diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleB_Custom.json b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleB_Custom.json new file mode 100644 index 0000000..129cac4 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleB_Custom.json @@ -0,0 +1 @@ +{ "Keys": [ "Rocket", "StarbusterB" ] } diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleC.json b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleC.json new file mode 100644 index 0000000..119aaa4 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleC.json @@ -0,0 +1 @@ +{ "Keys": [ "Boat", "Ship" ] } diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleD.json b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleD.json new file mode 100644 index 0000000..732c547 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleD.json @@ -0,0 +1 @@ +{ "Keys": [ "Bike", "Car" ] } diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleE.json b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleE.json new file mode 100644 index 0000000..5412c94 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/jsonIn/StyleE.json @@ -0,0 +1 @@ +{ "Keys": [ "Floor", "Ceiling" ] } diff --git a/Tests/QtAutogen/RerunMocPlugin/MocPlugin/main.cpp b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/main.cpp new file mode 100644 index 0000000..3ba2ddc --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/MocPlugin/main.cpp @@ -0,0 +1,6 @@ +#include "StyleA.hpp" + +int main(int argv, char** args) +{ + return 0; +} diff --git a/Tests/QtAutogen/RerunMocPlugin/dummy.cpp b/Tests/QtAutogen/RerunMocPlugin/dummy.cpp new file mode 100644 index 0000000..4837a76 --- /dev/null +++ b/Tests/QtAutogen/RerunMocPlugin/dummy.cpp @@ -0,0 +1,5 @@ + +int main(int argv, char** args) +{ + return 0; +} |