From 5615b9843472b4a564de7686692ba1391d1dadee Mon Sep 17 00:00:00 2001 From: Harsh-dev023 Date: Mon, 8 Jun 2026 11:46:48 +0530 Subject: [PATCH 1/3] feat: add Python type conversion test --- source/tests/CMakeLists.txt | 1 + .../CMakeLists.txt | 156 ++++++++++++++++++ .../source/main.cpp | 28 ++++ .../source/metacall_py_conversion_test.cpp | 79 +++++++++ 4 files changed, 264 insertions(+) create mode 100644 source/tests/metacall_py_conversion_test/CMakeLists.txt create mode 100644 source/tests/metacall_py_conversion_test/source/main.cpp create mode 100644 source/tests/metacall_py_conversion_test/source/metacall_py_conversion_test.cpp diff --git a/source/tests/CMakeLists.txt b/source/tests/CMakeLists.txt index 55ddb2b41a..813631c043 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_py_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_py_conversion_test/CMakeLists.txt b/source/tests/metacall_py_conversion_test/CMakeLists.txt new file mode 100644 index 0000000000..c61367bebc --- /dev/null +++ b/source/tests/metacall_py_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-py-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_py_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_py_conversion_test/source/main.cpp b/source/tests/metacall_py_conversion_test/source/main.cpp new file mode 100644 index 0000000000..fb41f44af8 --- /dev/null +++ b/source/tests/metacall_py_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_py_conversion_test/source/metacall_py_conversion_test.cpp b/source/tests/metacall_py_conversion_test/source/metacall_py_conversion_test.cpp new file mode 100644 index 0000000000..1551416fbe --- /dev/null +++ b/source/tests/metacall_py_conversion_test/source/metacall_py_conversion_test.cpp @@ -0,0 +1,79 @@ +/* + * 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_py_conversion_test : public testing::Test +{ +public: +}; + +TEST_F(metacall_py_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)); + + { + void *args[1] = { metacall_value_create(METACALL_INT) }; + + ret = metacallhv(handle, "identity", args); + + EXPECT_NE((void *)NULL, (void *)ret); + + EXPECT_EQ((enum metacall_value_id)METACALL_LONG, (enum metacall_value_id)metacall_value_id(ret)); + + metacall_value_destroy(ret); + metacall_value_destroy(args[0]); + } + + // TODO: + /* + 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); + + EXPECT_NE((void *)NULL, (void *)ret); + + 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(); +} From 4515b660a47776e0459edc2540886dcd844706db Mon Sep 17 00:00:00 2001 From: Harsh-dev023 Date: Thu, 11 Jun 2026 22:48:54 +0530 Subject: [PATCH 2/3] refactor: rename py to python in conversion test --- source/tests/CMakeLists.txt | 2 +- .../CMakeLists.txt | 4 ++-- .../source/main.cpp | 0 .../source/metacall_python_conversion_test.cpp} | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) rename source/tests/{metacall_py_conversion_test => metacall_python_conversion_test}/CMakeLists.txt (95%) rename source/tests/{metacall_py_conversion_test => metacall_python_conversion_test}/source/main.cpp (100%) rename source/tests/{metacall_py_conversion_test/source/metacall_py_conversion_test.cpp => metacall_python_conversion_test/source/metacall_python_conversion_test.cpp} (94%) diff --git a/source/tests/CMakeLists.txt b/source/tests/CMakeLists.txt index 813631c043..f73038953c 100644 --- a/source/tests/CMakeLists.txt +++ b/source/tests/CMakeLists.txt @@ -179,7 +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_py_conversion_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_py_conversion_test/CMakeLists.txt b/source/tests/metacall_python_conversion_test/CMakeLists.txt similarity index 95% rename from source/tests/metacall_py_conversion_test/CMakeLists.txt rename to source/tests/metacall_python_conversion_test/CMakeLists.txt index c61367bebc..8a49e79028 100644 --- a/source/tests/metacall_py_conversion_test/CMakeLists.txt +++ b/source/tests/metacall_python_conversion_test/CMakeLists.txt @@ -8,7 +8,7 @@ endif() # # Target name -set(target metacall-py-conversion-test) +set(target metacall-python-conversion-test) message(STATUS "Test ${target}") # @@ -32,7 +32,7 @@ set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source") set(sources ${source_path}/main.cpp - ${source_path}/metacall_py_conversion_test.cpp + ${source_path}/metacall_python_conversion_test.cpp ) # Group source files diff --git a/source/tests/metacall_py_conversion_test/source/main.cpp b/source/tests/metacall_python_conversion_test/source/main.cpp similarity index 100% rename from source/tests/metacall_py_conversion_test/source/main.cpp rename to source/tests/metacall_python_conversion_test/source/main.cpp diff --git a/source/tests/metacall_py_conversion_test/source/metacall_py_conversion_test.cpp b/source/tests/metacall_python_conversion_test/source/metacall_python_conversion_test.cpp similarity index 94% rename from source/tests/metacall_py_conversion_test/source/metacall_py_conversion_test.cpp rename to source/tests/metacall_python_conversion_test/source/metacall_python_conversion_test.cpp index 1551416fbe..9ff7ac0a43 100644 --- a/source/tests/metacall_py_conversion_test/source/metacall_py_conversion_test.cpp +++ b/source/tests/metacall_python_conversion_test/source/metacall_python_conversion_test.cpp @@ -24,12 +24,12 @@ #include #include -class metacall_py_conversion_test : public testing::Test +class metacall_python_conversion_test : public testing::Test { public: }; -TEST_F(metacall_py_conversion_test, DefaultConstructor) +TEST_F(metacall_python_conversion_test, DefaultConstructor) { metacall_print_info(); From fbbf912e341dfffe04d28e6fb29840e5fa8fc839 Mon Sep 17 00:00:00 2001 From: Harsh-dev023 Date: Fri, 12 Jun 2026 17:31:10 +0530 Subject: [PATCH 3/3] test: iterate over all metacall types in python conversion test --- .../metacall_python_conversion_test.cpp | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) 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 index 9ff7ac0a43..aec1e95d95 100644 --- 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 @@ -44,35 +44,24 @@ TEST_F(metacall_python_conversion_test, DefaultConstructor) ASSERT_EQ((int)0, (int)metacall_load_from_memory("py", script, sizeof(script), &handle)); - { - void *args[1] = { metacall_value_create(METACALL_INT) }; - - ret = metacallhv(handle, "identity", args); - - EXPECT_NE((void *)NULL, (void *)ret); - - EXPECT_EQ((enum metacall_value_id)METACALL_LONG, (enum metacall_value_id)metacall_value_id(ret)); - - metacall_value_destroy(ret); - metacall_value_destroy(args[0]); - } - - // TODO: - /* 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); - EXPECT_NE((void *)NULL, (void *)ret); + 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();