From 0e2f4830ba8914e954572bd80feea4eb2477f897 Mon Sep 17 00:00:00 2001 From: Vicente Eduardo Ferrer Garcia Date: Thu, 4 Aug 2022 00:13:34 +0300 Subject: [PATCH] Add reproducible test (from ctest) of pull request https://github.com/metacall/core/pull/303 --- source/cli/plugins/core_plugin/CMakeLists.txt | 2 +- source/extensions/CMakeLists.txt | 3 - .../plugin_extension/CMakeLists.txt | 2 +- source/tests/CMakeLists.txt | 3 +- .../CMakeLists.txt | 148 ++++++++++++++++++ .../source/main.cpp | 28 ++++ ...ll_plugin_extension_destroy_order_test.cpp | 68 ++++++++ 7 files changed, 248 insertions(+), 6 deletions(-) create mode 100644 source/tests/metacall_plugin_extension_destroy_order_test/CMakeLists.txt create mode 100644 source/tests/metacall_plugin_extension_destroy_order_test/source/main.cpp create mode 100644 source/tests/metacall_plugin_extension_destroy_order_test/source/metacall_plugin_extension_destroy_order_test.cpp diff --git a/source/cli/plugins/core_plugin/CMakeLists.txt b/source/cli/plugins/core_plugin/CMakeLists.txt index 850d033bc..414acc8d2 100644 --- a/source/cli/plugins/core_plugin/CMakeLists.txt +++ b/source/cli/plugins/core_plugin/CMakeLists.txt @@ -1,5 +1,5 @@ # Check if this loader is enabled -if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_EXTENSIONS OR NOT OPTION_BUILD_EXTENSIONS_LOAD) +if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_EXTENSIONS) return() endif() diff --git a/source/extensions/CMakeLists.txt b/source/extensions/CMakeLists.txt index 26604bfc1..ddaa058d7 100644 --- a/source/extensions/CMakeLists.txt +++ b/source/extensions/CMakeLists.txt @@ -3,8 +3,5 @@ if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_ return() endif() -# Extension options -option(OPTION_BUILD_EXTENSIONS_PLUGIN "Build plugin extension." ON) - # Extension sub-projects add_subdirectory(plugin_extension) diff --git a/source/extensions/plugin_extension/CMakeLists.txt b/source/extensions/plugin_extension/CMakeLists.txt index 6ff08a499..99f9ba175 100644 --- a/source/extensions/plugin_extension/CMakeLists.txt +++ b/source/extensions/plugin_extension/CMakeLists.txt @@ -1,5 +1,5 @@ # Check if this loader is enabled -if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_EXTENSIONS OR NOT OPTION_BUILD_EXTENSIONS_PLUGIN) +if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_EXTENSIONS) return() endif() diff --git a/source/tests/CMakeLists.txt b/source/tests/CMakeLists.txt index 4188ead4d..aec0acf6a 100644 --- a/source/tests/CMakeLists.txt +++ b/source/tests/CMakeLists.txt @@ -230,4 +230,5 @@ add_subdirectory(metacall_library_path_without_env_vars_test) add_subdirectory(metacall_ext_test) add_subdirectory(metacall_plugin_extension_test) add_subdirectory(metacall_plugin_extension_local_test) -add_subdirectory(metacall_core_plugin_test) \ No newline at end of file +add_subdirectory(metacall_plugin_extension_destroy_order_test) +add_subdirectory(metacall_core_plugin_test) diff --git a/source/tests/metacall_plugin_extension_destroy_order_test/CMakeLists.txt b/source/tests/metacall_plugin_extension_destroy_order_test/CMakeLists.txt new file mode 100644 index 000000000..7955e30f0 --- /dev/null +++ b/source/tests/metacall_plugin_extension_destroy_order_test/CMakeLists.txt @@ -0,0 +1,148 @@ +# Check if this loader is enabled +if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_EXTENSIONS) + return() +endif() + +# +# Executable name and options +# + +# Target name +set(target metacall-plugin-extension-destroy-order-test) +message(STATUS "Test ${target}") + +# +# Compiler warnings +# + +include(Warnings) + +# +# Compiler security +# + +include(SecurityFlags) + +# +# Sources +# + +set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}") +set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source") + +set(sources + ${source_path}/main.cpp + ${source_path}/metacall_plugin_extension_destroy_order_test.cpp +) + +# Group source files +set(header_group "Header Files (API)") +set(source_group "Source Files") +source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$" + ${header_group} ${headers}) +source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$" + ${source_group} ${sources}) + +# +# Create executable +# + +# Build executable +add_executable(${target} + ${sources} +) + +# Create namespaced alias +add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target}) + +# +# Project options +# + +set_target_properties(${target} + PROPERTIES + ${DEFAULT_PROJECT_OPTIONS} + FOLDER "${IDE_FOLDER}" +) + +# +# Include directories +# + +target_include_directories(${target} + PRIVATE + ${DEFAULT_INCLUDE_DIRECTORIES} + ${PROJECT_BINARY_DIR}/source/include +) + +# +# Libraries +# + +target_link_libraries(${target} + PRIVATE + ${DEFAULT_LIBRARIES} + + GTest + + ${META_PROJECT_NAME}::metacall +) + +# +# Compile definitions +# + +target_compile_definitions(${target} + PRIVATE + ${DEFAULT_COMPILE_DEFINITIONS} +) + +# +# Compile options +# + +target_compile_options(${target} + PRIVATE + ${DEFAULT_COMPILE_OPTIONS} +) + +# +# Linker options +# + +target_link_libraries(${target} + PRIVATE + ${DEFAULT_LINKER_OPTIONS} +) + +# +# Define test +# + +add_test(NAME ${target} + COMMAND $ +) + +# +# Define dependencies +# + +add_dependencies(${target} + ext_loader + plugin_extension +) + +# +# Define test properties +# + +set_property(TEST ${target} + PROPERTY LABELS ${target} +) + +include(TestEnvironmentVariables) + +test_environment_variables(${target} + "" + ${TESTS_ENVIRONMENT_VARIABLES} +) diff --git a/source/tests/metacall_plugin_extension_destroy_order_test/source/main.cpp b/source/tests/metacall_plugin_extension_destroy_order_test/source/main.cpp new file mode 100644 index 000000000..628e40890 --- /dev/null +++ b/source/tests/metacall_plugin_extension_destroy_order_test/source/main.cpp @@ -0,0 +1,28 @@ +/* + * MetaCall Library by Parra Studios + * A library for providing a foreign function interface calls. + * + * Copyright (C) 2016 - 2022 Vicente Eduardo Ferrer Garcia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/source/tests/metacall_plugin_extension_destroy_order_test/source/metacall_plugin_extension_destroy_order_test.cpp b/source/tests/metacall_plugin_extension_destroy_order_test/source/metacall_plugin_extension_destroy_order_test.cpp new file mode 100644 index 000000000..5272e15cd --- /dev/null +++ b/source/tests/metacall_plugin_extension_destroy_order_test/source/metacall_plugin_extension_destroy_order_test.cpp @@ -0,0 +1,68 @@ +/* + * MetaCall Library by Parra Studios + * A library for providing a foreign function interface calls. + * + * Copyright (C) 2016 - 2022 Vicente Eduardo Ferrer Garcia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include + +class metacall_plugin_destroy_order_test : public testing::Test +{ +public: +}; + +TEST_F(metacall_plugin_destroy_order_test, DefaultConstructor) +{ + metacall_print_info(); + + ASSERT_EQ((int)0, (int)metacall_initialize()); + + /* Extension */ + const char *ext_scripts[] = { + "plugin_extension" + }; + + void *handle = NULL; + + ASSERT_EQ((int)0, (int)metacall_load_from_file("ext", ext_scripts, sizeof(ext_scripts) / sizeof(ext_scripts[0]), &handle)); + + /* Print inspect information */ + { + size_t size = 0; + + struct metacall_allocator_std_type std_ctx = { &std::malloc, &std::realloc, &std::free }; + + void *allocator = metacall_allocator_create(METACALL_ALLOCATOR_STD, (void *)&std_ctx); + + char *inspect_str = metacall_inspect(&size, allocator); + + EXPECT_NE((char *)NULL, (char *)inspect_str); + + EXPECT_GT((size_t)size, (size_t)0); + + std::cout << inspect_str << std::endl; + + metacall_allocator_free(allocator, inspect_str); + + metacall_allocator_destroy(allocator); + } + + EXPECT_EQ((int)0, (int)metacall_destroy()); +}