Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
156 changes: 156 additions & 0 deletions source/tests/metacall_python_conversion_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 $<TARGET_FILE:${target}>
)

#
# 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}
)
28 changes: 28 additions & 0 deletions source/tests/metacall_python_conversion_test/source/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <vic798@gmail.com>
*
* 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 <gtest/gtest.h>

int main(int argc, char *argv[])
{
::testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS();
}
Original file line number Diff line number Diff line change
@@ -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 <vic798@gmail.com>
*
* 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 <gtest/gtest.h>

#include <metacall/metacall.h>
#include <metacall/metacall_loaders.h>
#include <metacall/metacall_value.h>

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();
}
Loading