Autogen: Tests: Add Q_PLUGIN_METADATA test

This commit is contained in:
Sebastian Holtermann
2017-02-17 13:50:33 +01:00
committed by Brad King
parent 39c4819eaa
commit cd74daf06f
17 changed files with 203 additions and 2 deletions

View File

@@ -86,7 +86,8 @@ try_compile(RCC_DEPENDS
"${CMAKE_CURRENT_BINARY_DIR}/autorcc_depends"
"${CMAKE_CURRENT_SOURCE_DIR}/autorcc_depends"
autorcc_depends
CMAKE_FLAGS "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}" "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
CMAKE_FLAGS "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
"-DQT_TEST_VERSION=${QT_TEST_VERSION}"
"-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}"
OUTPUT_VARIABLE output
)
@@ -121,7 +122,8 @@ try_compile(MOC_RERUN
"${CMAKE_CURRENT_BINARY_DIR}/automoc_rerun"
"${CMAKE_CURRENT_SOURCE_DIR}/automoc_rerun"
automoc_rerun
CMAKE_FLAGS "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}" "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
CMAKE_FLAGS "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
"-DQT_TEST_VERSION=${QT_TEST_VERSION}"
"-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}"
OUTPUT_VARIABLE output
)
@@ -214,6 +216,61 @@ add_subdirectory(mocIncludeStrict)
# Tests various include moc patterns
add_subdirectory(mocIncludeRelaxed)
# -- Test
# Tests Q_PLUGIN_METADATA json file change detection
if (NOT QT_TEST_VERSION STREQUAL 4)
try_compile(MOC_PLUGIN
"${CMAKE_CURRENT_BINARY_DIR}/mocPlugin"
"${CMAKE_CURRENT_SOURCE_DIR}/mocPlugin"
mocPlugin
CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
"-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}"
OUTPUT_VARIABLE output
)
if (NOT MOC_PLUGIN)
message(SEND_ERROR "Initial build of mocPlugin failed. Output: ${output}")
endif()
set(timeformat "%Y%j%H%M%S")
set(mocPluginBinDir "${CMAKE_CURRENT_BINARY_DIR}/mocPlugin")
find_library(style_a_file "PluginStyleA" "${mocPluginBinDir}")
find_library(style_b_file "PluginStyleB" "${mocPluginBinDir}")
find_library(style_c_file "PluginStyleC" "${mocPluginBinDir}")
find_library(style_d_file "PluginStyleD" "${mocPluginBinDir}")
file(TIMESTAMP "${style_a_file}" style_a_before "${timeformat}")
file(TIMESTAMP "${style_b_file}" style_b_before "${timeformat}")
file(TIMESTAMP "${style_c_file}" style_c_before "${timeformat}")
file(TIMESTAMP "${style_d_file}" style_d_before "${timeformat}")
# Ensure that the timestamp will change and touch the json files
execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${mocPluginBinDir}/jsonFiles/StyleC.json")
execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${mocPluginBinDir}/jsonFiles/sub/StyleD.json")
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mocPlugin"
)
file(TIMESTAMP "${style_a_file}" style_a_after "${timeformat}")
file(TIMESTAMP "${style_b_file}" style_b_after "${timeformat}")
file(TIMESTAMP "${style_c_file}" style_c_after "${timeformat}")
file(TIMESTAMP "${style_d_file}" style_d_after "${timeformat}")
if (style_a_after GREATER style_a_before)
message(SEND_ERROR "file (${style_a_file}) should not have changed!")
endif()
if (style_b_after GREATER style_b_before)
message(SEND_ERROR "file (${style_b_file}) should not have changed!")
endif()
if (NOT style_c_after GREATER style_c_before)
message(SEND_ERROR "file (${style_c_file}) should have changed!")
endif()
if (NOT style_d_after GREATER style_d_before)
message(SEND_ERROR "file (${style_d_file}) should have changed!")
endif()
endif()
# -- Test
# Complex test case
add_subdirectory(complex)

View File

@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.8)
if (NOT QT_TEST_VERSION STREQUAL 5)
message(SEND_ERROR "Invalid Qt version specified.")
endif()
find_package(Qt5Widgets REQUIRED)
if(Qt5_POSITION_INDEPENDENT_CODE AND CMAKE_CXX_COMPILE_OPTIONS_PIC)
add_definitions(${CMAKE_CXX_COMPILE_OPTIONS_PIC})
endif()
configure_file(jsonIn/StyleC.json jsonFiles/StyleC.json @ONLY)
configure_file(jsonIn/StyleD.json jsonFiles/sub/StyleD.json @ONLY)
# Enable automoc
set(CMAKE_AUTOMOC TRUE)
include_directories("${CMAKE_CURRENT_BINARY_DIR}/jsonFiles")
link_libraries(Qt5::Widgets)
add_library(PluginStyleA MODULE StyleA.cpp)
add_library(PluginStyleB MODULE StyleB.cpp)
add_library(PluginStyleC MODULE StyleC.cpp)
add_library(PluginStyleD MODULE StyleD.cpp)
add_library(PluginStyleE MODULE StyleE.cpp)

View File

@@ -0,0 +1,6 @@
#include "StyleA.hpp"
QStyle* StyleA::create(const QString& key)
{
return 0;
}

View File

@@ -0,0 +1,15 @@
#ifndef STYLEA_HPP
#define STYLEA_HPP
#include <QStylePlugin>
class StyleA : public QStylePlugin
{
Q_OBJECT
// Json file in local directory
Q_PLUGIN_METADATA(IID "org.styles.A" FILE "StyleA.json")
public:
QStyle* create(const QString& key);
};
#endif

View File

@@ -0,0 +1 @@
{ "Keys": [ "Rocket", "Starbuster" ] }

View File

@@ -0,0 +1,6 @@
#include "StyleB.hpp"
QStyle* StyleB::create(const QString& key)
{
return 0;
}

View File

@@ -0,0 +1,15 @@
#ifndef STYLEB_HPP
#define STYLEB_HPP
#include <QStylePlugin>
class StyleB : public QStylePlugin
{
Q_OBJECT
// Json file in local subdirectory
Q_PLUGIN_METADATA(IID "org.styles.B" FILE "jsonIn/StyleB.json")
public:
QStyle* create(const QString& key);
};
#endif

View File

@@ -0,0 +1,6 @@
#include "StyleC.hpp"
QStyle* StyleC::create(const QString& key)
{
return 0;
}

View File

@@ -0,0 +1,15 @@
#ifndef STYLEC_HPP
#define STYLEC_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")
public:
QStyle* create(const QString& key);
};
#endif

View File

@@ -0,0 +1,17 @@
#include "StyleD.hpp"
class StyleD : public QStylePlugin
{
Q_OBJECT
// Json file in global sub director
Q_PLUGIN_METADATA(IID "org.styles.D" FILE "sub/StyleD.json")
public:
QStyle* create(const QString& key);
};
QStyle* StyleD::create(const QString& key)
{
return 0;
}
#include "StyleD.moc"

View File

@@ -0,0 +1,8 @@
#ifndef STYLED_HPP
#define STYLED_HPP
#include <QStylePlugin>
class StyleD;
#endif

View File

@@ -0,0 +1,6 @@
#include "StyleE.hpp"
QStyle* StyleE::create(const QString& key)
{
return 0;
}

View File

@@ -0,0 +1,15 @@
#ifndef STYLEE_HPP
#define STYLEE_HPP
#include <QStylePlugin>
class StyleE : public QStylePlugin
{
Q_OBJECT
// No Json file
Q_PLUGIN_METADATA(IID "org.styles.E")
public:
QStyle* create(const QString& key);
};
#endif

View File

@@ -0,0 +1 @@
{ "Keys": [ "Rocket", "StarbusterB" ] }

View File

@@ -0,0 +1 @@
{ "Keys": [ "Rocket", "StarbusterC" ] }

View File

@@ -0,0 +1 @@
{ "Keys": [ "Rocket", "StarbusterD" ] }

View File

@@ -0,0 +1,6 @@
#include "StyleA.hpp"
int main(int argv, char** args)
{
return 0;
}