Skip to content

Commit 0e2f483

Browse files
committed
Add reproducible test (from ctest) of pull request #303
1 parent a2761e0 commit 0e2f483

File tree

7 files changed

+248
-6
lines changed

7 files changed

+248
-6
lines changed

source/cli/plugins/core_plugin/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Check if this loader is enabled
2-
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_EXTENSIONS OR NOT OPTION_BUILD_EXTENSIONS_LOAD)
2+
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_EXTENSIONS)
33
return()
44
endif()
55

source/extensions/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@ if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_
33
return()
44
endif()
55

6-
# Extension options
7-
option(OPTION_BUILD_EXTENSIONS_PLUGIN "Build plugin extension." ON)
8-
96
# Extension sub-projects
107
add_subdirectory(plugin_extension)

source/extensions/plugin_extension/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Check if this loader is enabled
2-
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_EXTENSIONS OR NOT OPTION_BUILD_EXTENSIONS_PLUGIN)
2+
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_EXTENSIONS)
33
return()
44
endif()
55

source/tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,5 @@ add_subdirectory(metacall_library_path_without_env_vars_test)
230230
add_subdirectory(metacall_ext_test)
231231
add_subdirectory(metacall_plugin_extension_test)
232232
add_subdirectory(metacall_plugin_extension_local_test)
233-
add_subdirectory(metacall_core_plugin_test)
233+
add_subdirectory(metacall_plugin_extension_destroy_order_test)
234+
add_subdirectory(metacall_core_plugin_test)
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Check if this loader is enabled
2+
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_EXTENSIONS)
3+
return()
4+
endif()
5+
6+
#
7+
# Executable name and options
8+
#
9+
10+
# Target name
11+
set(target metacall-plugin-extension-destroy-order-test)
12+
message(STATUS "Test ${target}")
13+
14+
#
15+
# Compiler warnings
16+
#
17+
18+
include(Warnings)
19+
20+
#
21+
# Compiler security
22+
#
23+
24+
include(SecurityFlags)
25+
26+
#
27+
# Sources
28+
#
29+
30+
set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}")
31+
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")
32+
33+
set(sources
34+
${source_path}/main.cpp
35+
${source_path}/metacall_plugin_extension_destroy_order_test.cpp
36+
)
37+
38+
# Group source files
39+
set(header_group "Header Files (API)")
40+
set(source_group "Source Files")
41+
source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$"
42+
${header_group} ${headers})
43+
source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$"
44+
${source_group} ${sources})
45+
46+
#
47+
# Create executable
48+
#
49+
50+
# Build executable
51+
add_executable(${target}
52+
${sources}
53+
)
54+
55+
# Create namespaced alias
56+
add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target})
57+
58+
#
59+
# Project options
60+
#
61+
62+
set_target_properties(${target}
63+
PROPERTIES
64+
${DEFAULT_PROJECT_OPTIONS}
65+
FOLDER "${IDE_FOLDER}"
66+
)
67+
68+
#
69+
# Include directories
70+
#
71+
72+
target_include_directories(${target}
73+
PRIVATE
74+
${DEFAULT_INCLUDE_DIRECTORIES}
75+
${PROJECT_BINARY_DIR}/source/include
76+
)
77+
78+
#
79+
# Libraries
80+
#
81+
82+
target_link_libraries(${target}
83+
PRIVATE
84+
${DEFAULT_LIBRARIES}
85+
86+
GTest
87+
88+
${META_PROJECT_NAME}::metacall
89+
)
90+
91+
#
92+
# Compile definitions
93+
#
94+
95+
target_compile_definitions(${target}
96+
PRIVATE
97+
${DEFAULT_COMPILE_DEFINITIONS}
98+
)
99+
100+
#
101+
# Compile options
102+
#
103+
104+
target_compile_options(${target}
105+
PRIVATE
106+
${DEFAULT_COMPILE_OPTIONS}
107+
)
108+
109+
#
110+
# Linker options
111+
#
112+
113+
target_link_libraries(${target}
114+
PRIVATE
115+
${DEFAULT_LINKER_OPTIONS}
116+
)
117+
118+
#
119+
# Define test
120+
#
121+
122+
add_test(NAME ${target}
123+
COMMAND $<TARGET_FILE:${target}>
124+
)
125+
126+
#
127+
# Define dependencies
128+
#
129+
130+
add_dependencies(${target}
131+
ext_loader
132+
plugin_extension
133+
)
134+
135+
#
136+
# Define test properties
137+
#
138+
139+
set_property(TEST ${target}
140+
PROPERTY LABELS ${target}
141+
)
142+
143+
include(TestEnvironmentVariables)
144+
145+
test_environment_variables(${target}
146+
""
147+
${TESTS_ENVIRONMENT_VARIABLES}
148+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* MetaCall Library by Parra Studios
3+
* A library for providing a foreign function interface calls.
4+
*
5+
* Copyright (C) 2016 - 2022 Vicente Eduardo Ferrer Garcia <vic798@gmail.com>
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#include <gtest/gtest.h>
22+
23+
int main(int argc, char *argv[])
24+
{
25+
::testing::InitGoogleTest(&argc, argv);
26+
27+
return RUN_ALL_TESTS();
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* MetaCall Library by Parra Studios
3+
* A library for providing a foreign function interface calls.
4+
*
5+
* Copyright (C) 2016 - 2022 Vicente Eduardo Ferrer Garcia <vic798@gmail.com>
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#include <gtest/gtest.h>
22+
23+
#include <metacall/metacall.h>
24+
#include <metacall/metacall_loaders.h>
25+
26+
class metacall_plugin_destroy_order_test : public testing::Test
27+
{
28+
public:
29+
};
30+
31+
TEST_F(metacall_plugin_destroy_order_test, DefaultConstructor)
32+
{
33+
metacall_print_info();
34+
35+
ASSERT_EQ((int)0, (int)metacall_initialize());
36+
37+
/* Extension */
38+
const char *ext_scripts[] = {
39+
"plugin_extension"
40+
};
41+
42+
void *handle = NULL;
43+
44+
ASSERT_EQ((int)0, (int)metacall_load_from_file("ext", ext_scripts, sizeof(ext_scripts) / sizeof(ext_scripts[0]), &handle));
45+
46+
/* Print inspect information */
47+
{
48+
size_t size = 0;
49+
50+
struct metacall_allocator_std_type std_ctx = { &std::malloc, &std::realloc, &std::free };
51+
52+
void *allocator = metacall_allocator_create(METACALL_ALLOCATOR_STD, (void *)&std_ctx);
53+
54+
char *inspect_str = metacall_inspect(&size, allocator);
55+
56+
EXPECT_NE((char *)NULL, (char *)inspect_str);
57+
58+
EXPECT_GT((size_t)size, (size_t)0);
59+
60+
std::cout << inspect_str << std::endl;
61+
62+
metacall_allocator_free(allocator, inspect_str);
63+
64+
metacall_allocator_destroy(allocator);
65+
}
66+
67+
EXPECT_EQ((int)0, (int)metacall_destroy());
68+
}

0 commit comments

Comments
 (0)