Skip to content

Commit ecc7f8d

Browse files
committed
Add base for complex test with multiple ports and callbacks between languages.
1 parent 8d5ee1c commit ecc7f8d

File tree

7 files changed

+498
-0
lines changed

7 files changed

+498
-0
lines changed

source/tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ add_subdirectory(metacall_node_inline_test)
133133
add_subdirectory(metacall_node_async_test)
134134
add_subdirectory(metacall_node_reentrant_test)
135135
add_subdirectory(metacall_node_port_test)
136+
#add_subdirectory(metacall_node_python_port_mock_test) # TODO
137+
#add_subdirectory(metacall_node_python_port_ruby_test) # TODO
136138
add_subdirectory(metacall_distributable_test)
137139
add_subdirectory(metacall_cast_test)
138140
add_subdirectory(metacall_init_fini_test)
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Check if this loader is enabled
2+
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_NODE OR NOT OPTION_BUILD_LOADERS_PY OR NOT OPTION_BUILD_LOADERS_MOCK OR NOT OPTION_BUILD_PORTS OR NOT OPTION_BUILD_PORTS_NODE OR NOT OPTION_BUILD_PORTS_PY)
3+
return()
4+
endif()
5+
6+
#
7+
# Executable name and options
8+
#
9+
10+
# Target name
11+
set(target metacall-node-python-port-mock-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_node_python_port_mock_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_distributable
89+
)
90+
91+
#
92+
# Compile definitions
93+
#
94+
95+
target_compile_definitions(${target}
96+
PRIVATE
97+
${DEFAULT_COMPILE_DEFINITIONS}
98+
99+
# NodeJS Port path
100+
METACALL_NODE_PORT_PATH="${CMAKE_SOURCE_DIR}/source/ports/node_port/index.js"
101+
102+
# Python Port path
103+
METACALL_PYTHON_PORT_PATH="${CMAKE_SOURCE_DIR}/source/ports/py_port"
104+
)
105+
106+
#
107+
# Compile options
108+
#
109+
110+
target_compile_options(${target}
111+
PRIVATE
112+
${DEFAULT_COMPILE_OPTIONS}
113+
)
114+
115+
#
116+
# Linker options
117+
#
118+
119+
target_link_libraries(${target}
120+
PRIVATE
121+
${DEFAULT_LINKER_OPTIONS}
122+
)
123+
124+
#
125+
# Define test
126+
#
127+
128+
add_test(NAME ${target}
129+
COMMAND $<TARGET_FILE:${target}>
130+
)
131+
132+
#
133+
# Define dependencies
134+
#
135+
136+
add_dependencies(${target}
137+
node_loader
138+
py_loader
139+
mock_loader
140+
)
141+
142+
#
143+
# Define test properties
144+
#
145+
146+
set_property(TEST ${target}
147+
PROPERTY LABELS ${target}
148+
)
149+
150+
include(TestEnvironmentVariables)
151+
152+
test_environment_variables(${target}
153+
""
154+
${TESTS_ENVIRONMENT_VARIABLES}
155+
)
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 - 2020 Vicente Eduardo Ferrer Garcia <[email protected]>
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 <gmock/gmock.h>
22+
23+
int main(int argc, char * argv[])
24+
{
25+
::testing::InitGoogleMock(&argc, argv);
26+
27+
return RUN_ALL_TESTS();
28+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* MetaCall Library by Parra Studios
3+
* A library for providing a foreign function interface calls.
4+
*
5+
* Copyright (C) 2016 - 2020 Vicente Eduardo Ferrer Garcia <[email protected]>
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 <gmock/gmock.h>
22+
23+
#include <metacall/metacall.h>
24+
#include <metacall/metacall_value.h>
25+
#include <metacall/metacall_loaders.h>
26+
27+
class metacall_node_python_port_mock_test : public testing::Test
28+
{
29+
public:
30+
};
31+
32+
TEST_F(metacall_node_python_port_mock_test, DefaultConstructor)
33+
{
34+
metacall_print_info();
35+
36+
metacall_log_null();
37+
38+
ASSERT_EQ((int) 0, (int) metacall_initialize());
39+
40+
/* NodeJS & Python & Mock */
41+
#if defined(OPTION_BUILD_LOADERS_NODE) && defined(OPTION_BUILD_LOADERS_PY) && defined(OPTION_BUILD_LOADERS_MOCK)
42+
{
43+
static const char buffer[] =
44+
/* NodeJS */
45+
"const { metacall, metacall_load_from_memory } = require('" METACALL_NODE_PORT_PATH "');\n"
46+
"metacall_load_from_memory('py', `"
47+
/* Python */
48+
"import sys\n"
49+
"sys.path.insert(0, '" METACALL_PYTHON_PORT_PATH "')\n"
50+
"import metacall\n"
51+
/* Mock */
52+
"from asd.mock import two_doubles\n"
53+
"def py_func(js_func):\n"
54+
" return js_func(two_doubles)\n"
55+
"`);\n"
56+
"const result = metacall('py_func', (mock_func) => mock_func(3, 4));\n"
57+
"console.log('Result:', result);\n"
58+
"if (result !== 3.1416) process.exit(1);\n";
59+
60+
ASSERT_EQ((int) 0, (int) metacall_load_from_memory("node", buffer, sizeof(buffer), NULL));
61+
}
62+
#endif /* OPTION_BUILD_LOADERS_NODE && OPTION_BUILD_LOADERS_PY && OPTION_BUILD_LOADERS_MOCK */
63+
64+
EXPECT_EQ((int) 0, (int) metacall_destroy());
65+
}

0 commit comments

Comments
 (0)