diff --git a/source/tests/CMakeLists.txt b/source/tests/CMakeLists.txt index 55ddb2b41..f73038953 100644 --- a/source/tests/CMakeLists.txt +++ b/source/tests/CMakeLists.txt @@ -179,6 +179,7 @@ add_subdirectory(metacall_python_builtins_test) add_subdirectory(metacall_python_async_test) # TODO: add_subdirectory(metacall_python_await_test) # TODO: Implement metacall_await in Python Port add_subdirectory(metacall_python_exception_test) +add_subdirectory(metacall_python_conversion_test) # TODO: add_subdirectory(metacall_python_node_await_test) # TODO: Implement metacall_await in Python Port add_subdirectory(metacall_python_without_env_vars_test) add_subdirectory(metacall_map_test) diff --git a/source/tests/metacall_python_conversion_test/CMakeLists.txt b/source/tests/metacall_python_conversion_test/CMakeLists.txt new file mode 100644 index 000000000..8a49e7902 --- /dev/null +++ b/source/tests/metacall_python_conversion_test/CMakeLists.txt @@ -0,0 +1,156 @@ +# Check if this loader is enabled +if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_PY) + return() +endif() + +# +# Executable name and options +# + +# Target name +set(target metacall-python-conversion-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_python_conversion_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} +) + +# +# Compile features +# + +target_compile_features(${target} + PRIVATE + cxx_std_17 +) + +# +# Linker options +# + +target_link_options(${target} + PRIVATE + ${DEFAULT_LINKER_OPTIONS} +) + +# +# Define test +# + +add_test(NAME ${target} + COMMAND $ +) + +# +# Define dependencies +# + +add_dependencies(${target} + py_loader +) + +# +# 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_python_conversion_test/source/main.cpp b/source/tests/metacall_python_conversion_test/source/main.cpp new file mode 100644 index 000000000..fb41f44af --- /dev/null +++ b/source/tests/metacall_python_conversion_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 - 2026 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_python_conversion_test/source/metacall_python_conversion_test.cpp b/source/tests/metacall_python_conversion_test/source/metacall_python_conversion_test.cpp new file mode 100644 index 000000000..aec1e95d9 --- /dev/null +++ b/source/tests/metacall_python_conversion_test/source/metacall_python_conversion_test.cpp @@ -0,0 +1,68 @@ +/* + * MetaCall Library by Parra Studios + * A library for providing a foreign function interface calls. + * + * Copyright (C) 2016 - 2026 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 +#include + +class metacall_python_conversion_test : public testing::Test +{ +public: +}; + +TEST_F(metacall_python_conversion_test, DefaultConstructor) +{ + metacall_print_info(); + + metacall_log_null(); + + ASSERT_EQ((int)0, (int)metacall_initialize()); + + { + static const char script[] = "def identity(x):\n\treturn x\n"; + void *handle = NULL; + void *ret; + + ASSERT_EQ((int)0, (int)metacall_load_from_memory("py", script, sizeof(script), &handle)); + + for (size_t id = 0; id < METACALL_SIZE; ++id) + { + void *args[1] = { metacall_value_create((enum metacall_value_id)id) }; + + ret = metacallhv(handle, "identity", args); + + if (ret == NULL) + { + std::cout << metacall_value_id_name((enum metacall_value_id)id) << " => NULL (unsupported)" << std::endl; + metacall_value_destroy(args[0]); + continue; + } + + std::cout << metacall_value_id_name((enum metacall_value_id)id) << " => " << metacall_value_id_name(metacall_value_id(ret)) << std::endl; + + metacall_value_destroy(ret); + metacall_value_destroy(args[0]); + } + } + + metacall_destroy(); +}