Change C# bool[] typemaps to marshall as 1-byte
Default marshalling for bool[] now uses 1-byte entries in the array, to ensure array contents is as expected in C++. When running under mono csharp_lib_arrays_bool testcase will fail due to an apparent bug in mono. Works correctly under Microsoft's runtime. See https://github.com/mono/mono/issues/15592
This commit is contained in:
parent
d9cac176f6
commit
58863bba59
4 changed files with 202 additions and 1 deletions
|
|
@ -19,6 +19,7 @@ CPP_TEST_CASES = \
|
|||
csharp_exceptions \
|
||||
csharp_features \
|
||||
csharp_lib_arrays \
|
||||
csharp_lib_arrays_bool \
|
||||
csharp_namespace_system_collision \
|
||||
csharp_prepost \
|
||||
csharp_typemaps \
|
||||
|
|
@ -36,6 +37,9 @@ CPP11_TEST_CASES = \
|
|||
cpp11_shared_ptr_upcast \
|
||||
cpp11_strongly_typed_enumerations_simple \
|
||||
|
||||
# bool[] typemaps don't work correctly when running under mono
|
||||
FAILING_CPP_TESTS = csharp_lib_arrays_bool
|
||||
|
||||
include $(srcdir)/../common.mk
|
||||
|
||||
# Overridden variables here
|
||||
|
|
@ -48,6 +52,7 @@ CSHARPFLAGSSPECIAL =
|
|||
intermediary_classname.cpptest: SWIGOPT += -dllimport intermediary_classname
|
||||
complextest.cpptest: CSHARPFLAGSSPECIAL = -r:System.Numerics.dll
|
||||
csharp_lib_arrays.cpptest: CSHARPFLAGSSPECIAL = -unsafe
|
||||
csharp_lib_arrays_bool.cpptest: CSHARPFLAGSSPECIAL = -unsafe
|
||||
csharp_swig2_compatibility.cpptest: SWIGOPT += -DSWIG2_CSHARP
|
||||
|
||||
# Rules for the different types of tests
|
||||
|
|
|
|||
78
Examples/test-suite/csharp/csharp_lib_arrays_bool_runme.cs
Normal file
78
Examples/test-suite/csharp/csharp_lib_arrays_bool_runme.cs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
using System;
|
||||
using csharp_lib_arrays_boolNamespace;
|
||||
|
||||
public class runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
{
|
||||
bool[] source = { true, false, false, true, false, true, true, false };
|
||||
bool[] target = new bool[ source.Length ];
|
||||
|
||||
csharp_lib_arrays_bool.myArrayCopyUsingFixedArraysBool( source, target, target.Length );
|
||||
CompareArrays(source, target, "bool[] INPUT/OUTPUT Fixed");
|
||||
}
|
||||
|
||||
{
|
||||
bool[] source = { true, false, false, true, false, true, true, false };
|
||||
bool[] target = { false, true, true, false, true, false, false, true };
|
||||
|
||||
csharp_lib_arrays_bool.myArraySwapUsingFixedArraysBool( source, target, target.Length );
|
||||
|
||||
for (int i=0; i<target.Length; ++i)
|
||||
target[i] = !target[i];
|
||||
|
||||
CompareArrays(source, target, "bool[] INOUT");
|
||||
}
|
||||
|
||||
{
|
||||
bool[] source = { true, false, false, true, false, true, true, false };
|
||||
bool[] target = new bool[ source.Length ];
|
||||
|
||||
if( !csharp_lib_arrays_bool.checkBoolArrayCorrect( source, source.Length ) )
|
||||
{
|
||||
throw new Exception("bool[] INPUT incorrect");
|
||||
}
|
||||
|
||||
csharp_lib_arrays_bool.myArrayCopyBool( source, target, target.Length );
|
||||
CompareArrays(source, target, "bool[] INPUT/OUTPUT");
|
||||
}
|
||||
|
||||
{
|
||||
bool[] source = { true, false, false, true, false, true, true, false };
|
||||
bool[] target = { false, true, true, false, true, false, false, true };
|
||||
|
||||
csharp_lib_arrays_bool.myArraySwapBool( source, target, target.Length );
|
||||
|
||||
for (int i=0; i<target.Length; ++i)
|
||||
target[i] = !target[i];
|
||||
|
||||
CompareArrays(source, target, "bool[] INOUT");
|
||||
}
|
||||
}
|
||||
|
||||
static void CompareArrays<T>( T[] a, T[] b, string testName )
|
||||
{
|
||||
if (a.Length != b.Length)
|
||||
throw new Exception("size mismatch");
|
||||
|
||||
for(int i=0; i<a.Length; ++i) {
|
||||
if (a[i].Equals(b[i]) == false) {
|
||||
Console.Error.WriteLine("C# Array mismatch: " + testName);
|
||||
Console.Error.WriteLine("a:");
|
||||
PrintArray(a);
|
||||
Console.Error.WriteLine("b:");
|
||||
PrintArray(b);
|
||||
throw new Exception("element mismatch");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintArray<T>( T[] a )
|
||||
{
|
||||
foreach ( T i in a )
|
||||
Console.Error.Write( "{0} ", i );
|
||||
Console.Error.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue