Merge branch 'bugfix/616-csharp-bool-array'
* bugfix/616-csharp-bool-array: Add changes entry to fix C# bool[] Quieten failing bool[] testcase message Skip failing bool[] test cases when running under mono Change C# bool[] typemaps to marshall as 1-byte
This commit is contained in:
commit
53b425b638
5 changed files with 215 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 \
|
||||
|
|
@ -48,6 +49,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
|
||||
|
|
|
|||
90
Examples/test-suite/csharp/csharp_lib_arrays_bool_runme.cs
Normal file
90
Examples/test-suite/csharp/csharp_lib_arrays_bool_runme.cs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
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");
|
||||
}
|
||||
|
||||
if( runtimeIsMono() )
|
||||
{
|
||||
// Console.Error.WriteLine("Tests are running on mono, failing bool[] tests skipped");
|
||||
// See Mono bug report https://github.com/mono/mono/issues/15592
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
static bool runtimeIsMono()
|
||||
{
|
||||
return Type.GetType ("Mono.Runtime") != null;
|
||||
}
|
||||
}
|
||||
|
||||
78
Examples/test-suite/csharp_lib_arrays_bool.i
Normal file
78
Examples/test-suite/csharp_lib_arrays_bool.i
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
%module csharp_lib_arrays_bool
|
||||
|
||||
%include "arrays_csharp.i"
|
||||
|
||||
%apply bool INPUT[] { bool* sourceArray }
|
||||
%apply bool OUTPUT[] { bool* targetArray }
|
||||
|
||||
%apply bool INOUT[] { bool* array1 }
|
||||
%apply bool INOUT[] { bool* array2 }
|
||||
|
||||
%inline %{
|
||||
#include <iostream>
|
||||
|
||||
/* copy the contents of the first array to the second */
|
||||
void myArrayCopyBool( bool* sourceArray, bool* targetArray, int nitems ) {
|
||||
int i;
|
||||
for ( i = 0; i < nitems; i++ ) {
|
||||
targetArray[ i ] = sourceArray[ i ];
|
||||
}
|
||||
}
|
||||
|
||||
/* swap the contents of the two arrays */
|
||||
void myArraySwapBool( bool* array1, bool* array2, int nitems ) {
|
||||
int i;
|
||||
bool temp;
|
||||
for ( i = 0; i < nitems; i++ ) {
|
||||
temp = array1[ i ];
|
||||
array1[ i ] = array2[ i ];
|
||||
array2[ i ] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
bool checkBoolArrayCorrect( bool* sourceArray, int sourceArraySize ) {
|
||||
if( sourceArraySize != 8 ) {
|
||||
std::cout << "checkBoolArrayCorrect: Expected array with 8 elements" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return sourceArray[0] == true &&
|
||||
sourceArray[1] == false &&
|
||||
sourceArray[2] == false &&
|
||||
sourceArray[3] == true &&
|
||||
sourceArray[4] == false &&
|
||||
sourceArray[5] == true &&
|
||||
sourceArray[6] == true &&
|
||||
sourceArray[7] == false;
|
||||
}
|
||||
%}
|
||||
|
||||
%clear bool* sourceArray;
|
||||
%clear bool* targetArray;
|
||||
|
||||
%clear bool* array1;
|
||||
%clear bool* array2;
|
||||
|
||||
// Below replicates the above array handling but this time using the pinned (fixed) array typemaps
|
||||
%csmethodmodifiers myArrayCopyUsingFixedArraysBool "public unsafe";
|
||||
%csmethodmodifiers myArraySwapUsingFixedArraysBool "public unsafe";
|
||||
|
||||
%apply bool FIXED[] { bool* sourceArray }
|
||||
%apply bool FIXED[] { bool* targetArray }
|
||||
|
||||
%inline %{
|
||||
void myArrayCopyUsingFixedArraysBool( bool *sourceArray, bool* targetArray, int nitems ) {
|
||||
myArrayCopyBool(sourceArray, targetArray, nitems);
|
||||
}
|
||||
%}
|
||||
|
||||
%apply bool FIXED[] { bool* array1 }
|
||||
%apply bool FIXED[] { bool* array2 }
|
||||
|
||||
%inline %{
|
||||
void myArraySwapUsingFixedArraysBool( bool* array1, bool* array2, int nitems ) {
|
||||
myArraySwapBool(array1, array2, nitems);
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue