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
2 changes: 2 additions & 0 deletions source/scripts/csharp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ include(CSharpProject)

add_subdirectory(hello)
add_subdirectory(static)
add_subdirectory(class)
add_subdirectory(function)

20 changes: 20 additions & 0 deletions source/scripts/csharp/class/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# External dependencies
#

find_package(DotNET)

if(NOT DOTNET_FOUND)
message(SEND_ERROR "DotNET command not found")
return()
endif()

if(DOTNET_VERSION VERSION_LESS "5.0")
return()
endif()

#
# Configure csharp project
#

cs_project(class 0.1.0)
21 changes: 21 additions & 0 deletions source/scripts/csharp/class/source/class.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class Counter
{
public int count; // attribute
public static int total; // static attribute

public Counter(int start) // constructor
{
this.count = start;
}

public int Add(int value) // instance method
{
this.count += value;
return this.count;
}

public static int Twice(int value) // static method
{
return value * 2;
}
}
1 change: 1 addition & 0 deletions source/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ add_subdirectory(metacall_llvm_test)
add_subdirectory(metacall_ruby_test)
add_subdirectory(metacall_cs_test)
add_subdirectory(metacall_csharp_static_class_test)
add_subdirectory(metacall_csharp_class_test)
add_subdirectory(metacall_csharp_function_test)
add_subdirectory(metacall_csharp_empty_configuration_test)
add_subdirectory(metacall_csharp_invalid_configuration_test)
Expand Down
192 changes: 192 additions & 0 deletions source/tests/metacall_csharp_class_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
# Check if this loader is enabled
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_CS OR NOT OPTION_BUILD_SCRIPTS OR NOT OPTION_BUILD_SCRIPTS_CS)
return()
endif()

#
# External dependencies
#

find_package(DotNET)

if(NOT DOTNET_FOUND)
message(SEND_ERROR "DotNET command not found")
return()
endif()

if(DOTNET_VERSION VERSION_LESS "5.0")
return()
endif()

#
# Executable name and options
#

# Target name
set(target metacall-csharp-class-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_csharp_class_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
#

if(OPTION_BUILD_THREAD_SANITIZER)
find_package(DotNET)
check_tsan_executable("${DOTNET_CORE_LIBRARY}" DotNET_TSAN)
if(NOT DotNET_TSAN)
# This test fails when run with thread sanitizer due to C# when CoreCLR is not compiled with TSAN:
# coreclr_initialize status (0x8007ff0b)
# For solving this, we should enable C# support for sanitizers and debug it properly
return()
endif()
endif()

if(OPTION_TEST_MEMORYCHECK)
# C# NetCore instrumentation for Valgrind is not supported right now on MetaCall
# and we do not have a way to check if is instrumented or not checking the library
# so we skip directly the test to avoid false positives
return()
endif()

add_test(NAME ${target}
COMMAND $<TARGET_FILE:${target}>
)

#
# Define dependencies
#

add_dependencies(${target}
cs_loader
)

#
# Define test properties
#

set_property(TEST ${target}
PROPERTY LABELS ${target}

# TODO: Valgrind also fails with C#
MEMCHECK_IGNORE
)

include(TestEnvironmentVariables)

test_environment_variables(${target}
""
${TESTS_ENVIRONMENT_VARIABLES}
)
28 changes: 28 additions & 0 deletions source/tests/metacall_csharp_class_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();
}
Loading