CppSharp icon indicating copy to clipboard operation
CppSharp copied to clipboard

Lack of tests with `MarshalCharAsManagedChar = false` is causing issues now and will in the future

Open josetr opened this issue 5 years ago • 1 comments

CSharp test projects wont build

// A value of type 'char' cannot be used as a default parameter because there are no standard 
public void DefaultChar(sbyte c = 'a')

public sbyte** Names {
    get {
      // Cannot take the address of, get the size of, or declare a conversions to type 'sbyte'
        return (string*) ((global::CSharp.TestPointers.__Internal*) __Instance)->Names;
    }
}
// error CS1503: Argument 1: cannot convert from 'char' to 'sbyte'
Assert.That(*CSharp.CSharp.TakeConstCharRef(z), Is.EqualTo(z));

// error CS1503: Argument 1: cannot convert from 'char*' to 'sbyte*'
Assert.That(*CSharp.CSharp.TakeCharPointer(&c), Is.EqualTo(c));

These other bugs would have been found much sooner with MarshalCharAsManagedChar set to false

https://github.com/mono/CppSharp/issues/1417 https://github.com/mono/CppSharp/issues/1420 https://github.com/mono/CppSharp/issues/1409

josetr avatar Oct 16 '20 15:10 josetr

@ddobrev We should definitely add a new CI test configuration to keep this tested.

As for the testing assertion errors, perhaps the best way to fix them would be add an #ifdef MARSHAL_AS_MANAGED_CHAR option I guess to conditionally use a different type.

tritao avatar Oct 16 '20 18:10 tritao