Adding tests covering `preview-codegen`
This commit is contained in:
Родитель
0d997e6fb9
Коммит
032a7dc2c3
|
@ -0,0 +1,920 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class CSharpPreviewUnix_CXXMethodDeclarationTest : CXXMethodDeclarationTest
|
||||
{
|
||||
protected override Task ConstructorTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int _value;
|
||||
|
||||
MyStruct(int value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int _value;
|
||||
|
||||
public MyStruct(int value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ConstructorWithInitializeTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int _x;
|
||||
int _y;
|
||||
int _z;
|
||||
|
||||
MyStruct(int x) : _x(x)
|
||||
{
|
||||
}
|
||||
|
||||
MyStruct(int x, int y) : _x(x), _y(y)
|
||||
{
|
||||
}
|
||||
|
||||
MyStruct(int x, int y, int z) : _x(x), _y(y), _z()
|
||||
{
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int _x;
|
||||
|
||||
public int _y;
|
||||
|
||||
public int _z;
|
||||
|
||||
public MyStruct(int x)
|
||||
{
|
||||
_x = x;
|
||||
}
|
||||
|
||||
public MyStruct(int x, int y)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
}
|
||||
|
||||
public MyStruct(int x, int y, int z)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ConversionTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int value;
|
||||
|
||||
operator int()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int value;
|
||||
|
||||
public int ToInt32()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task DestructorTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
~MyStruct()
|
||||
{
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task InstanceTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
void MyVoidMethod();
|
||||
|
||||
int MyInt32Method()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* MyVoidStarMethod()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
";
|
||||
var entryPoint = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "__ZN8MyStruct12MyVoidMethodEv" : "_ZN8MyStruct12MyVoidMethodEv";
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
if (!Environment.Is64BitProcess)
|
||||
{
|
||||
entryPoint = "?MyVoidMethod@MyStruct@@QAEXXZ";
|
||||
}
|
||||
else
|
||||
{
|
||||
entryPoint = "?MyVoidMethod@MyStruct@@QEAAXXZ";
|
||||
}
|
||||
}
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct
|
||||
{{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.ThisCall, EntryPoint = ""{entryPoint}"", ExactSpelling = true)]
|
||||
public static extern void MyVoidMethod(MyStruct* pThis);
|
||||
|
||||
public int MyInt32Method()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public void* MyVoidStarMethod()
|
||||
{{
|
||||
return null;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task MemberCallTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int value;
|
||||
|
||||
int MyFunction1()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
int MyFunction2()
|
||||
{
|
||||
return MyFunction1();
|
||||
}
|
||||
|
||||
int MyFunction3()
|
||||
{
|
||||
return this->MyFunction1();
|
||||
}
|
||||
};
|
||||
|
||||
int MyFunctionA(MyStruct x)
|
||||
{
|
||||
return x.MyFunction1();
|
||||
}
|
||||
|
||||
int MyFunctionB(MyStruct* x)
|
||||
{
|
||||
return x->MyFunction2();
|
||||
}
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int value;
|
||||
|
||||
public int MyFunction1()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public int MyFunction2()
|
||||
{
|
||||
return MyFunction1();
|
||||
}
|
||||
|
||||
public int MyFunction3()
|
||||
{
|
||||
return this.MyFunction1();
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe partial class Methods
|
||||
{
|
||||
public static int MyFunctionA(MyStruct x)
|
||||
{
|
||||
return x.MyFunction1();
|
||||
}
|
||||
|
||||
public static int MyFunctionB(MyStruct* x)
|
||||
{
|
||||
return x->MyFunction2();
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task MemberTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int value;
|
||||
|
||||
int MyFunction()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int value;
|
||||
|
||||
public int MyFunction()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NewKeywordTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int Equals() { return 0; }
|
||||
int Equals(int obj) { return 0; }
|
||||
int Dispose() { return 0; }
|
||||
int Dispose(int obj) { return 0; }
|
||||
int GetHashCode() { return 0; }
|
||||
int GetHashCode(int obj) { return 0; }
|
||||
int GetType() { return 0; }
|
||||
int GetType(int obj) { return 0; }
|
||||
int MemberwiseClone() { return 0; }
|
||||
int MemberwiseClone(int obj) { return 0; }
|
||||
int ReferenceEquals() { return 0; }
|
||||
int ReferenceEquals(int obj) { return 0; }
|
||||
int ToString() { return 0; }
|
||||
int ToString(int obj) { return 0; }
|
||||
};";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public partial struct MyStruct
|
||||
{{
|
||||
public int Equals()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int Equals(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int Dispose()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int Dispose(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public new int GetHashCode()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int GetHashCode(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public new int GetType()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int GetType(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public new int MemberwiseClone()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int MemberwiseClone(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int ReferenceEquals()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int ReferenceEquals(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public new int ToString()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int ToString(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NewKeywordVirtualTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
virtual int GetType(int obj) = 0;
|
||||
virtual int GetType() = 0;
|
||||
virtual int GetType(int objA, int objB) = 0;
|
||||
};";
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct
|
||||
{{
|
||||
public void** lpVtbl;
|
||||
|
||||
public int GetType(int objA, int objB)
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, int, int, int>)(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this), objA, objB);
|
||||
}}
|
||||
|
||||
public new int GetType()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, int>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
public int GetType(int obj)
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, int, int>)(lpVtbl[2]))((MyStruct*)Unsafe.AsPointer(ref this), obj);
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NewKeywordVirtualWithExplicitVtblTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
virtual int GetType(int obj) = 0;
|
||||
virtual int GetType() = 0;
|
||||
virtual int GetType(int objA, int objB) = 0;
|
||||
};";
|
||||
|
||||
var nativeCallConv = "";
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !Environment.Is64BitProcess)
|
||||
{
|
||||
nativeCallConv = " __attribute__((thiscall))";
|
||||
}
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct
|
||||
{{
|
||||
public Vtbl* lpVtbl;
|
||||
|
||||
public int GetType(int objA, int objB)
|
||||
{{
|
||||
return lpVtbl->GetType((MyStruct*)Unsafe.AsPointer(ref this), objA, objB);
|
||||
}}
|
||||
|
||||
public new int GetType()
|
||||
{{
|
||||
return lpVtbl->GetType1((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
public int GetType(int obj)
|
||||
{{
|
||||
return lpVtbl->GetType2((MyStruct*)Unsafe.AsPointer(ref this), obj);
|
||||
}}
|
||||
|
||||
public partial struct Vtbl
|
||||
{{
|
||||
[NativeTypeName(""int (int, int){nativeCallConv}"")]
|
||||
public new delegate* unmanaged[Thiscall]<MyStruct*, int, int, int> GetType;
|
||||
|
||||
[NativeTypeName(""int (){nativeCallConv}"")]
|
||||
public delegate* unmanaged[Thiscall]<MyStruct*, int> GetType1;
|
||||
|
||||
[NativeTypeName(""int (int){nativeCallConv}"")]
|
||||
public delegate* unmanaged[Thiscall]<MyStruct*, int, int> GetType2;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateExplicitVtbls);
|
||||
}
|
||||
|
||||
protected override Task NewKeywordVirtualWithExplicitVtblAndMarkerInterfaceTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
virtual int GetType(int obj) = 0;
|
||||
virtual int GetType() = 0;
|
||||
virtual int GetType(int objA, int objB) = 0;
|
||||
};";
|
||||
|
||||
var nativeCallConv = "";
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !Environment.Is64BitProcess)
|
||||
{
|
||||
nativeCallConv = " __attribute__((thiscall))";
|
||||
}
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct : MyStruct.Interface
|
||||
{{
|
||||
public Vtbl<MyStruct>* lpVtbl;
|
||||
|
||||
public int GetType(int objA, int objB)
|
||||
{{
|
||||
return lpVtbl->GetType((MyStruct*)Unsafe.AsPointer(ref this), objA, objB);
|
||||
}}
|
||||
|
||||
public new int GetType()
|
||||
{{
|
||||
return lpVtbl->GetType1((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
public int GetType(int obj)
|
||||
{{
|
||||
return lpVtbl->GetType2((MyStruct*)Unsafe.AsPointer(ref this), obj);
|
||||
}}
|
||||
|
||||
public interface Interface
|
||||
{{
|
||||
int GetType(int objA, int objB);
|
||||
|
||||
int GetType();
|
||||
|
||||
int GetType(int obj);
|
||||
}}
|
||||
|
||||
public partial struct Vtbl<TSelf>
|
||||
where TSelf : unmanaged, Interface
|
||||
{{
|
||||
[NativeTypeName(""int (int, int){nativeCallConv}"")]
|
||||
public new delegate* unmanaged[Thiscall]<TSelf*, int, int, int> GetType;
|
||||
|
||||
[NativeTypeName(""int (){nativeCallConv}"")]
|
||||
public delegate* unmanaged[Thiscall]<TSelf*, int> GetType1;
|
||||
|
||||
[NativeTypeName(""int (int){nativeCallConv}"")]
|
||||
public delegate* unmanaged[Thiscall]<TSelf*, int, int> GetType2;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateExplicitVtbls | PInvokeGeneratorConfigurationOptions.GenerateMarkerInterfaces);
|
||||
}
|
||||
|
||||
protected override Task OperatorTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int value;
|
||||
|
||||
MyStruct(int value) : value(value)
|
||||
{
|
||||
}
|
||||
|
||||
MyStruct operator+(MyStruct rhs)
|
||||
{
|
||||
return MyStruct(value + rhs.value);
|
||||
}
|
||||
};
|
||||
|
||||
MyStruct operator-(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return MyStruct(lhs.value - rhs.value);
|
||||
}
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int value;
|
||||
|
||||
public MyStruct(int value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public MyStruct Add(MyStruct rhs)
|
||||
{
|
||||
return new MyStruct(value + rhs.value);
|
||||
}
|
||||
}
|
||||
|
||||
public static partial class Methods
|
||||
{
|
||||
public static MyStruct Subtract(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return new MyStruct(lhs.value - rhs.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task OperatorCallTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int value;
|
||||
|
||||
MyStruct(int value) : value(value)
|
||||
{
|
||||
}
|
||||
|
||||
MyStruct operator+(MyStruct rhs)
|
||||
{
|
||||
return MyStruct(value + rhs.value);
|
||||
}
|
||||
};
|
||||
|
||||
MyStruct MyFunction1(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return lhs + rhs;
|
||||
}
|
||||
|
||||
MyStruct operator-(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return MyStruct(lhs.value - rhs.value);
|
||||
}
|
||||
|
||||
MyStruct MyFunction2(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return lhs - rhs;
|
||||
}
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int value;
|
||||
|
||||
public MyStruct(int value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public MyStruct Add(MyStruct rhs)
|
||||
{
|
||||
return new MyStruct(value + rhs.value);
|
||||
}
|
||||
}
|
||||
|
||||
public static partial class Methods
|
||||
{
|
||||
public static MyStruct MyFunction1(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return lhs.Add(rhs);
|
||||
}
|
||||
|
||||
public static MyStruct Subtract(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return new MyStruct(lhs.value - rhs.value);
|
||||
}
|
||||
|
||||
public static MyStruct MyFunction2(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return Subtract(lhs, rhs);
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task StaticTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
static void MyVoidMethod();
|
||||
|
||||
static int MyInt32Method()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void* MyVoidStarMethod()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var entryPoint = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "?MyVoidMethod@MyStruct@@SAXXZ" : "_ZN8MyStruct12MyVoidMethodEv";
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
entryPoint = $"_{entryPoint}";
|
||||
}
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct
|
||||
{{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, EntryPoint = ""{entryPoint}"", ExactSpelling = true)]
|
||||
public static extern void MyVoidMethod();
|
||||
|
||||
public static int MyInt32Method()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public static void* MyVoidStarMethod()
|
||||
{{
|
||||
return null;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ThisTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int value;
|
||||
|
||||
int MyFunction()
|
||||
{
|
||||
return this->value;
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int value;
|
||||
|
||||
public int MyFunction()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UnsafeDoesNotImpactDllImportTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
void* MyVoidStarMethod()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public unsafe partial struct MyStruct
|
||||
{
|
||||
public void* MyVoidStarMethod()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction();
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task VirtualTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
virtual void MyVoidMethod() = 0;
|
||||
|
||||
virtual char MyInt8Method()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int MyInt32Method();
|
||||
|
||||
virtual void* MyVoidStarMethod() = 0;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct
|
||||
{{
|
||||
public void** lpVtbl;
|
||||
|
||||
public void MyVoidMethod()
|
||||
{{
|
||||
((delegate* unmanaged[Thiscall]<MyStruct*, void>)(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
[return: NativeTypeName(""char"")]
|
||||
public sbyte MyInt8Method()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
public int MyInt32Method()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, int>)(lpVtbl[2]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
public void* MyVoidStarMethod()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, void*>)(lpVtbl[3]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task VirtualWithVtblIndexAttributeTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
virtual void MyVoidMethod() = 0;
|
||||
|
||||
virtual char MyInt8Method()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int MyInt32Method();
|
||||
|
||||
virtual void* MyVoidStarMethod() = 0;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct
|
||||
{{
|
||||
public void** lpVtbl;
|
||||
|
||||
[VtblIndex(0)]
|
||||
public void MyVoidMethod()
|
||||
{{
|
||||
((delegate* unmanaged[Thiscall]<MyStruct*, void>)(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName(""char"")]
|
||||
public sbyte MyInt8Method()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
[VtblIndex(2)]
|
||||
public int MyInt32Method()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, int>)(lpVtbl[2]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
[VtblIndex(3)]
|
||||
public void* MyVoidStarMethod()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, void*>)(lpVtbl[3]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute);
|
||||
}
|
||||
|
||||
protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,554 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class CSharpPreviewUnix_EnumDeclarationTest : EnumDeclarationTest
|
||||
{
|
||||
protected override Task BasicTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task BasicValueTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value1 = 1,
|
||||
MyEnum_Value2,
|
||||
MyEnum_Value3,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum
|
||||
{
|
||||
MyEnum_Value1 = 1,
|
||||
MyEnum_Value2,
|
||||
MyEnum_Value3,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ExcludeTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = string.Empty;
|
||||
|
||||
var excludedNames = new string[] { "MyEnum" };
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: excludedNames);
|
||||
}
|
||||
|
||||
protected override Task ExplicitTypedTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"enum MyEnum : {nativeType}
|
||||
{{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public enum MyEnum : {expectedManagedType}
|
||||
{{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ExplicitTypedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"enum MyEnum : {nativeType}
|
||||
{{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
[NativeTypeName(""{nativeType}"")]
|
||||
public enum MyEnum : {expectedManagedType}
|
||||
{{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task RemapTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef enum _MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1,
|
||||
MyEnum1_Value2,
|
||||
MyEnum1_Value3,
|
||||
} MyEnum1;
|
||||
|
||||
namespace Namespace1
|
||||
{
|
||||
namespace Namespace2
|
||||
{
|
||||
typedef enum _MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1,
|
||||
MyEnum2_Value2,
|
||||
MyEnum2_Value3,
|
||||
} MyEnum2;
|
||||
|
||||
typedef enum _MyEnum3 : int
|
||||
{
|
||||
MyEnum3_Value1,
|
||||
MyEnum3_Value2,
|
||||
MyEnum3_Value3,
|
||||
} MyEnum3;
|
||||
|
||||
typedef enum _MyEnum4 : int
|
||||
{
|
||||
MyEnum4_Value1,
|
||||
MyEnum4_Value2,
|
||||
MyEnum4_Value3,
|
||||
} MyEnum4;
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value1,
|
||||
MyEnum1_Value2,
|
||||
MyEnum1_Value3,
|
||||
}
|
||||
|
||||
public enum MyEnum2
|
||||
{
|
||||
MyEnum2_Value1,
|
||||
MyEnum2_Value2,
|
||||
MyEnum2_Value3,
|
||||
}
|
||||
|
||||
public enum MyEnum3
|
||||
{
|
||||
MyEnum3_Value1,
|
||||
MyEnum3_Value2,
|
||||
MyEnum3_Value3,
|
||||
}
|
||||
|
||||
public enum MyEnum4
|
||||
{
|
||||
MyEnum4_Value1,
|
||||
MyEnum4_Value2,
|
||||
MyEnum4_Value3,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var remappedNames = new Dictionary<string, string> { ["_MyEnum1"] = "MyEnum1", ["Namespace1.Namespace2._MyEnum2"] = "MyEnum2", ["_MyEnum3"] = "MyEnum3", ["Namespace1::Namespace2::_MyEnum4"] = "MyEnum4" };
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames);
|
||||
}
|
||||
|
||||
protected override Task WithAttributeTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = 1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"using System;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
[Flags]
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
}
|
||||
|
||||
public enum MyEnum2
|
||||
{
|
||||
MyEnum2_Value1 = 1,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withAttributes = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["MyEnum1"] = new List<string>() { "Flags" }
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withAttributes: withAttributes);
|
||||
}
|
||||
|
||||
protected override Task WithNamespaceTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"using static ClangSharp.Test.MyEnum1;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
}
|
||||
|
||||
public enum MyEnum2
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withNamespaces = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["MyEnum1"] = new List<string>() { "static ClangSharp.Test.MyEnum1" }
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withUsings: withNamespaces);
|
||||
}
|
||||
|
||||
protected override Task WithNamespaceStarTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"using static ClangSharp.Test.MyEnum1;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
}
|
||||
|
||||
public enum MyEnum2
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withNamespaces = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["*"] = new List<string>() { "static ClangSharp.Test.MyEnum1" }
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withUsings: withNamespaces);
|
||||
}
|
||||
|
||||
protected override Task WithNamespaceStarPlusTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"using System;
|
||||
using static ClangSharp.Test.MyEnum1;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
}
|
||||
|
||||
public enum MyEnum2
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withNamespaces = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["*"] = new List<string>() { "static ClangSharp.Test.MyEnum1" },
|
||||
["MyEnum2"] = new List<string>() { "System" }
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withUsings: withNamespaces);
|
||||
}
|
||||
|
||||
protected override Task WithCastToEnumTypeImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0 = (MyEnum) 10,
|
||||
MyEnum_Value1 = (MyEnum) MyEnum_Value0,
|
||||
MyEnum_Value2 = ((MyEnum) 10) + MyEnum_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum
|
||||
{
|
||||
MyEnum_Value0 = (int)(MyEnum)(10),
|
||||
MyEnum_Value1 = (int)(MyEnum)(MyEnum_Value0),
|
||||
MyEnum_Value2 = ((int)(MyEnum)(10)) + MyEnum_Value1,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithMultipleEnumsTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value0 = 10,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value0 = MyEnum1_Value0,
|
||||
MyEnum2_Value1 = MyEnum1_Value0 + (MyEnum1) 10,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"using static ClangSharp.Test.MyEnum1;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value0 = 10,
|
||||
}
|
||||
|
||||
public enum MyEnum2
|
||||
{
|
||||
MyEnum2_Value0 = MyEnum1_Value0,
|
||||
MyEnum2_Value1 = MyEnum1_Value0 + (int)(MyEnum1)(10),
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithImplicitConversionTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2 = 0x80000000,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2 = unchecked((int)(0x80000000)),
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithTypeTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
[NativeTypeName(""int"")]
|
||||
public enum MyEnum : uint
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string> {
|
||||
["MyEnum"] = "uint"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
|
||||
protected override Task WithTypeAndImplicitConversionTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2 = 0x80000000,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
[NativeTypeName(""int"")]
|
||||
public enum MyEnum : uint
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2 = 0x80000000,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string>
|
||||
{
|
||||
["MyEnum"] = "uint"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
|
||||
protected override Task WithTypeStarTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value0
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value0
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
[NativeTypeName(""int"")]
|
||||
public enum MyEnum1 : uint
|
||||
{
|
||||
MyEnum1_Value0,
|
||||
}
|
||||
|
||||
[NativeTypeName(""int"")]
|
||||
public enum MyEnum2 : uint
|
||||
{
|
||||
MyEnum2_Value0,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "uint"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
|
||||
protected override Task WithTypeStarOverrideTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value0
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value0
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value0,
|
||||
}
|
||||
|
||||
[NativeTypeName(""int"")]
|
||||
public enum MyEnum2 : uint
|
||||
{
|
||||
MyEnum2_Value0,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "uint",
|
||||
["MyEnum1"] = "int",
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,400 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class CSharpPreviewUnix_FunctionDeclarationDllImportTest : FunctionDeclarationDllImportTest
|
||||
{
|
||||
protected override Task BasicTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction();
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ArrayParameterTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction(const float color[4]);";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static unsafe partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction([NativeTypeName(""const float[4]"")] float* color);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task FunctionPointerParameterTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction(void (*callback)());";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static unsafe partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction([NativeTypeName(""void (*)()"")] delegate* unmanaged[Cdecl]<void> callback);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NamespaceTestImpl()
|
||||
{
|
||||
var inputContents = @"namespace MyNamespace
|
||||
{
|
||||
void MyFunction();
|
||||
}";
|
||||
|
||||
var entryPoint = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "__ZN11MyNamespace10MyFunctionEv" : "_ZN11MyNamespace10MyFunctionEv";
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
entryPoint = "?MyFunction@MyNamespace@@YAXXZ";
|
||||
}
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, EntryPoint = ""{entryPoint}"", ExactSpelling = true)]
|
||||
public static extern void MyFunction();
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task TemplateParameterTestImpl(string nativeType, bool expectedNativeTypeAttr, string expectedManagedType, string expectedUsingStatement)
|
||||
{
|
||||
var inputContents = @$"template <typename T> struct MyTemplate;
|
||||
|
||||
extern ""C"" void MyFunction(MyTemplate<{nativeType}> myStruct);";
|
||||
|
||||
var expectedOutputContents = $@"{expectedUsingStatement}using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction({(expectedNativeTypeAttr ? $@"[NativeTypeName(""MyTemplate<{nativeType}>"")] " : "")}MyTemplate<{expectedManagedType}> myStruct);
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: new[] { "MyTemplate" });
|
||||
}
|
||||
|
||||
protected override Task TemplateMemberTestImpl()
|
||||
{
|
||||
var inputContents = @$"template <typename T> struct MyTemplate
|
||||
{{
|
||||
}};
|
||||
|
||||
struct MyStruct
|
||||
{{
|
||||
MyTemplate<float*> a;
|
||||
}};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"using System;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public partial struct MyStruct
|
||||
{{
|
||||
[NativeTypeName(""MyTemplate<float *>"")]
|
||||
public MyTemplate<IntPtr> a;
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: new[] { "MyTemplate" });
|
||||
}
|
||||
|
||||
protected override Task NoLibraryPathTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport("""", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction();
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, libraryPath: string.Empty);
|
||||
}
|
||||
|
||||
protected override Task WithLibraryPathTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction();
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withLibraryPaths = new Dictionary<string, string>
|
||||
{
|
||||
["MyFunction"] = "ClangSharpPInvokeGenerator"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, libraryPath: string.Empty, withLibraryPaths: withLibraryPaths);
|
||||
}
|
||||
|
||||
protected override Task WithLibraryPathStarTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction();
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withLibraryPaths = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "ClangSharpPInvokeGenerator"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, libraryPath: string.Empty, withLibraryPaths: withLibraryPaths);
|
||||
}
|
||||
|
||||
protected override Task OptionalParameterTestImpl(string nativeType, string nativeInit, bool expectedNativeTypeNameAttr, string expectedManagedType, string expectedManagedInit)
|
||||
{
|
||||
var inputContents = $@"extern ""C"" void MyFunction({nativeType} value = {nativeInit});";
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction({(expectedNativeTypeNameAttr ? $@"[NativeTypeName(""{nativeType}"")] " : "")}{expectedManagedType} value = {expectedManagedInit});
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task OptionalParameterUnsafeTestImpl(string nativeType, string nativeInit, string expectedManagedType, string expectedManagedInit)
|
||||
{
|
||||
var inputContents = $@"extern ""C"" void MyFunction({nativeType} value = {nativeInit});";
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static unsafe partial class Methods
|
||||
{{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction({expectedManagedType} value = {expectedManagedInit});
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithCallConvTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", ExactSpelling = true)]
|
||||
public static extern void MyFunction1(int value);
|
||||
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction2(int value);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withCallConvs = new Dictionary<string, string> {
|
||||
["MyFunction1"] = "Winapi"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withCallConvs: withCallConvs);
|
||||
}
|
||||
|
||||
protected override Task WithCallConvStarTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", ExactSpelling = true)]
|
||||
public static extern void MyFunction1(int value);
|
||||
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", ExactSpelling = true)]
|
||||
public static extern void MyFunction2(int value);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withCallConvs = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "Winapi"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withCallConvs: withCallConvs);
|
||||
}
|
||||
|
||||
protected override Task WithCallConvStarOverrideTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", ExactSpelling = true)]
|
||||
public static extern void MyFunction1(int value);
|
||||
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
|
||||
public static extern void MyFunction2(int value);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withCallConvs = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "Winapi",
|
||||
["MyFunction2"] = "StdCall"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withCallConvs: withCallConvs);
|
||||
}
|
||||
|
||||
protected override Task WithSetLastErrorTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = true)]
|
||||
public static extern void MyFunction1(int value);
|
||||
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction2(int value);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withSetLastErrors = new string[]
|
||||
{
|
||||
"MyFunction1"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withSetLastErrors: withSetLastErrors);
|
||||
}
|
||||
|
||||
protected override Task WithSetLastErrorStarTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = true)]
|
||||
public static extern void MyFunction1(int value);
|
||||
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = true)]
|
||||
public static extern void MyFunction2(int value);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withSetLastErrors = new string[]
|
||||
{
|
||||
"*"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withSetLastErrors: withSetLastErrors);
|
||||
}
|
||||
|
||||
protected override Task SourceLocationTestImpl()
|
||||
{
|
||||
const string InputContents = @"extern ""C"" void MyFunction(float value);";
|
||||
|
||||
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
[SourceLocation(""ClangUnsavedFile.h"", 1, 17)]
|
||||
public static extern void MyFunction([SourceLocation(""ClangUnsavedFile.h"", 1, 34)] float value);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute);
|
||||
}
|
||||
|
||||
protected override Task VarargsTestImpl() => Task.CompletedTask;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class CSharpPreviewUnix_FunctionPointerDeclarationTest : FunctionPointerDeclarationTest
|
||||
{
|
||||
protected override Task BasicTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef void (*Callback)();
|
||||
|
||||
struct MyStruct {
|
||||
Callback _callback;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public unsafe partial struct MyStruct
|
||||
{
|
||||
[NativeTypeName(""Callback"")]
|
||||
public delegate* unmanaged[Cdecl]<void> _callback;
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task CallconvTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef void (*Callback)() __attribute__((stdcall));
|
||||
|
||||
struct MyStruct {
|
||||
Callback _callback;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public unsafe partial struct MyStruct
|
||||
{
|
||||
[NativeTypeName(""Callback"")]
|
||||
public delegate* unmanaged[Stdcall]<void> _callback;
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task PointerlessTypedefTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef void (Callback)();
|
||||
|
||||
struct MyStruct {
|
||||
Callback* _callback;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public unsafe partial struct MyStruct
|
||||
{
|
||||
[NativeTypeName(""Callback *"")]
|
||||
public delegate* unmanaged[Cdecl]<void> _callback;
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,399 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class CSharpPreviewUnix_VarDeclarationTest : VarDeclarationTest
|
||||
{
|
||||
protected override Task BasicTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"{nativeType} MyVariable = 0;";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
public static {expectedManagedType} MyVariable = 0;
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"{nativeType} MyVariable = 0;";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""{nativeType}"")]
|
||||
public static {expectedManagedType} MyVariable = 0;
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task GuidMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"struct GUID {{
|
||||
unsigned long Data1;
|
||||
unsigned short Data2;
|
||||
unsigned short Data3;
|
||||
unsigned char Data4[8];
|
||||
}};
|
||||
|
||||
const GUID IID_IUnknown = {{ 0x00000000, 0x0000, 0x0000, {{ 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 }} }};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"using System;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""const GUID"")]
|
||||
public static readonly Guid IID_IUnknown = new Guid(0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
|
||||
}}
|
||||
}}
|
||||
";
|
||||
var excludedNames = new string[] { "GUID" };
|
||||
var remappedNames = new Dictionary<string, string> { ["GUID"] = "Guid" };
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: excludedNames, remappedNames: remappedNames);
|
||||
}
|
||||
|
||||
protected override Task MacroTestImpl(string nativeValue, string expectedManagedType, string expectedManagedValue)
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 {nativeValue}
|
||||
#define MyMacro2 MyMacro1";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro1 {nativeValue}"")]
|
||||
public const {expectedManagedType} MyMacro1 = {expectedManagedValue};
|
||||
|
||||
[NativeTypeName(""#define MyMacro2 MyMacro1"")]
|
||||
public const {expectedManagedType} MyMacro2 = {expectedManagedValue};
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task MultilineMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 0 + \
|
||||
1";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro1 0 + \\\n1"")]
|
||||
public const int MyMacro1 = 0 + 1;
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NoInitializerTestImpl(string nativeType)
|
||||
{
|
||||
var inputContents = $@"{nativeType} MyVariable;";
|
||||
var expectedOutputContents = "";
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task Utf8StringLiteralMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 ""Test""";
|
||||
|
||||
var expectedOutputContents = $@"using System;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro1 \""Test\"""")]
|
||||
public static ReadOnlySpan<byte> MyMacro1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task Utf16StringLiteralMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 u""Test""";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro1 u\""Test\"""")]
|
||||
public const string MyMacro1 = ""Test"";
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WideStringLiteralConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"const wchar_t MyConst1[] = L""Test"";
|
||||
const wchar_t* MyConst2 = L""Test"";
|
||||
const wchar_t* const MyConst3 = L""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""const wchar_t[5]"")]
|
||||
public static readonly uint[] MyConst1 = new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000 }};
|
||||
|
||||
[NativeTypeName(""const wchar_t *"")]
|
||||
public static uint[] MyConst2 = new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000 }};
|
||||
|
||||
[NativeTypeName(""const wchar_t *const"")]
|
||||
public static readonly uint[] MyConst3 = new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000 }};
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task StringLiteralConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"const char MyConst1[] = ""Test"";
|
||||
const char* MyConst2 = ""Test"";
|
||||
const char* const MyConst3 = ""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"using System;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""const char[5]"")]
|
||||
public static ReadOnlySpan<byte> MyConst1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
|
||||
[NativeTypeName(""const char *"")]
|
||||
public static byte[] MyConst2 = new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
|
||||
[NativeTypeName(""const char *const"")]
|
||||
public static ReadOnlySpan<byte> MyConst3 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WideStringLiteralStaticConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"static const wchar_t MyConst1[] = L""Test"";
|
||||
static const wchar_t* MyConst2 = L""Test"";
|
||||
static const wchar_t* const MyConst3 = L""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""const wchar_t[5]"")]
|
||||
public static readonly uint[] MyConst1 = new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000 }};
|
||||
|
||||
[NativeTypeName(""const wchar_t *"")]
|
||||
public static uint[] MyConst2 = new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000 }};
|
||||
|
||||
[NativeTypeName(""const wchar_t *const"")]
|
||||
public static readonly uint[] MyConst3 = new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000 }};
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task StringLiteralStaticConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"static const char MyConst1[] = ""Test"";
|
||||
static const char* MyConst2 = ""Test"";
|
||||
static const char* const MyConst3 = ""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"using System;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""const char[5]"")]
|
||||
public static ReadOnlySpan<byte> MyConst1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
|
||||
[NativeTypeName(""const char *"")]
|
||||
public static byte[] MyConst2 = new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
|
||||
[NativeTypeName(""const char *const"")]
|
||||
public static ReadOnlySpan<byte> MyConst3 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedConversionMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 (long)0x80000000L
|
||||
#define MyMacro2 (int)0x80000000";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro1 (long)0x80000000L"")]
|
||||
public const nint MyMacro1 = unchecked((nint)(0x80000000));
|
||||
|
||||
[NativeTypeName(""#define MyMacro2 (int)0x80000000"")]
|
||||
public const int MyMacro2 = unchecked((int)(0x80000000));
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedFunctionLikeCastMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 unsigned(-1)";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro1 unsigned(-1)"")]
|
||||
public const uint MyMacro1 = unchecked((uint)(-1));
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedConversionMacroTest2Impl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1(x, y, z) ((int)(((unsigned long)(x)<<31) | ((unsigned long)(y)<<16) | ((unsigned long)(z))))
|
||||
#define MyMacro2(n) MyMacro1(1, 2, n)
|
||||
#define MyMacro3 MyMacro2(3)";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro3 MyMacro2(3)"")]
|
||||
public const int MyMacro3 = unchecked((int)(((nuint)(1) << 31) | ((nuint)(2) << 16) | ((nuint)(3))));
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
var excludedNames = new string[] { "MyMacro1", "MyMacro2" };
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: excludedNames);
|
||||
}
|
||||
|
||||
protected override Task UncheckedPointerMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define Macro1 ((int*) -1)";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static unsafe partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define Macro1 ((int*) -1)"")]
|
||||
public static readonly int* Macro1 = unchecked((int*)(-1));
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedReinterpretCastMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define Macro1 reinterpret_cast<int*>(-1)";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static unsafe partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define Macro1 reinterpret_cast<int*>(-1)"")]
|
||||
public static readonly int* Macro1 = unchecked((int*)(-1));
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task MultidimensionlArrayTestImpl()
|
||||
{
|
||||
var inputContents = $@"const int MyArray[2][2] = {{ {{ 0, 1 }}, {{ 2, 3 }} }};";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""const int[2][2]"")]
|
||||
public static readonly int[][] MyArray = new int[2][]
|
||||
{{
|
||||
new int[2]
|
||||
{{
|
||||
0,
|
||||
1,
|
||||
}},
|
||||
new int[2]
|
||||
{{
|
||||
2,
|
||||
3,
|
||||
}},
|
||||
}};
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ConditionalDefineConstTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef int TESTRESULT;
|
||||
#define TESTRESULT_FROM_WIN32(x) ((TESTRESULT)(x) <= 0 ? ((TESTRESULT)(x)) : ((TESTRESULT) (((x) & 0x0000FFFF) | (7 << 16) | 0x80000000)))
|
||||
#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)"")]
|
||||
public const int ADDRESS_IN_USE = unchecked((int)(10048) <= 0 ? ((int)(10048)) : ((int)(((10048) & 0x0000FFFF) | (7 << 16) | 0x80000000)));
|
||||
}}
|
||||
}}
|
||||
";
|
||||
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Function like macro definition records are not supported: 'TESTRESULT_FROM_WIN32'. Generated bindings may be incomplete.", "Line 2, Column 9 in ClangUnsavedFile.h") };
|
||||
|
||||
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,920 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class CSharpPreviewWindows_CXXMethodDeclarationTest : CXXMethodDeclarationTest
|
||||
{
|
||||
protected override Task ConstructorTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int _value;
|
||||
|
||||
MyStruct(int value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int _value;
|
||||
|
||||
public MyStruct(int value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ConstructorWithInitializeTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int _x;
|
||||
int _y;
|
||||
int _z;
|
||||
|
||||
MyStruct(int x) : _x(x)
|
||||
{
|
||||
}
|
||||
|
||||
MyStruct(int x, int y) : _x(x), _y(y)
|
||||
{
|
||||
}
|
||||
|
||||
MyStruct(int x, int y, int z) : _x(x), _y(y), _z()
|
||||
{
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int _x;
|
||||
|
||||
public int _y;
|
||||
|
||||
public int _z;
|
||||
|
||||
public MyStruct(int x)
|
||||
{
|
||||
_x = x;
|
||||
}
|
||||
|
||||
public MyStruct(int x, int y)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
}
|
||||
|
||||
public MyStruct(int x, int y, int z)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ConversionTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int value;
|
||||
|
||||
operator int()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int value;
|
||||
|
||||
public int ToInt32()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task DestructorTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
~MyStruct()
|
||||
{
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task InstanceTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
void MyVoidMethod();
|
||||
|
||||
int MyInt32Method()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* MyVoidStarMethod()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
";
|
||||
var entryPoint = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "__ZN8MyStruct12MyVoidMethodEv" : "_ZN8MyStruct12MyVoidMethodEv";
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
if (!Environment.Is64BitProcess)
|
||||
{
|
||||
entryPoint = "?MyVoidMethod@MyStruct@@QAEXXZ";
|
||||
}
|
||||
else
|
||||
{
|
||||
entryPoint = "?MyVoidMethod@MyStruct@@QEAAXXZ";
|
||||
}
|
||||
}
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct
|
||||
{{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.ThisCall, EntryPoint = ""{entryPoint}"", ExactSpelling = true)]
|
||||
public static extern void MyVoidMethod(MyStruct* pThis);
|
||||
|
||||
public int MyInt32Method()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public void* MyVoidStarMethod()
|
||||
{{
|
||||
return null;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task MemberCallTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int value;
|
||||
|
||||
int MyFunction1()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
int MyFunction2()
|
||||
{
|
||||
return MyFunction1();
|
||||
}
|
||||
|
||||
int MyFunction3()
|
||||
{
|
||||
return this->MyFunction1();
|
||||
}
|
||||
};
|
||||
|
||||
int MyFunctionA(MyStruct x)
|
||||
{
|
||||
return x.MyFunction1();
|
||||
}
|
||||
|
||||
int MyFunctionB(MyStruct* x)
|
||||
{
|
||||
return x->MyFunction2();
|
||||
}
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int value;
|
||||
|
||||
public int MyFunction1()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public int MyFunction2()
|
||||
{
|
||||
return MyFunction1();
|
||||
}
|
||||
|
||||
public int MyFunction3()
|
||||
{
|
||||
return this.MyFunction1();
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe partial class Methods
|
||||
{
|
||||
public static int MyFunctionA(MyStruct x)
|
||||
{
|
||||
return x.MyFunction1();
|
||||
}
|
||||
|
||||
public static int MyFunctionB(MyStruct* x)
|
||||
{
|
||||
return x->MyFunction2();
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task MemberTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int value;
|
||||
|
||||
int MyFunction()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int value;
|
||||
|
||||
public int MyFunction()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NewKeywordTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int Equals() { return 0; }
|
||||
int Equals(int obj) { return 0; }
|
||||
int Dispose() { return 0; }
|
||||
int Dispose(int obj) { return 0; }
|
||||
int GetHashCode() { return 0; }
|
||||
int GetHashCode(int obj) { return 0; }
|
||||
int GetType() { return 0; }
|
||||
int GetType(int obj) { return 0; }
|
||||
int MemberwiseClone() { return 0; }
|
||||
int MemberwiseClone(int obj) { return 0; }
|
||||
int ReferenceEquals() { return 0; }
|
||||
int ReferenceEquals(int obj) { return 0; }
|
||||
int ToString() { return 0; }
|
||||
int ToString(int obj) { return 0; }
|
||||
};";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public partial struct MyStruct
|
||||
{{
|
||||
public int Equals()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int Equals(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int Dispose()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int Dispose(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public new int GetHashCode()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int GetHashCode(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public new int GetType()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int GetType(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public new int MemberwiseClone()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int MemberwiseClone(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int ReferenceEquals()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int ReferenceEquals(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public new int ToString()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public int ToString(int obj)
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NewKeywordVirtualTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
virtual int GetType(int obj) = 0;
|
||||
virtual int GetType() = 0;
|
||||
virtual int GetType(int objA, int objB) = 0;
|
||||
};";
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct
|
||||
{{
|
||||
public void** lpVtbl;
|
||||
|
||||
public int GetType(int objA, int objB)
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, int, int, int>)(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this), objA, objB);
|
||||
}}
|
||||
|
||||
public new int GetType()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, int>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
public int GetType(int obj)
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, int, int>)(lpVtbl[2]))((MyStruct*)Unsafe.AsPointer(ref this), obj);
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NewKeywordVirtualWithExplicitVtblTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
virtual int GetType(int obj) = 0;
|
||||
virtual int GetType() = 0;
|
||||
virtual int GetType(int objA, int objB) = 0;
|
||||
};";
|
||||
|
||||
var nativeCallConv = "";
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !Environment.Is64BitProcess)
|
||||
{
|
||||
nativeCallConv = " __attribute__((thiscall))";
|
||||
}
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct
|
||||
{{
|
||||
public Vtbl* lpVtbl;
|
||||
|
||||
public int GetType(int objA, int objB)
|
||||
{{
|
||||
return lpVtbl->GetType((MyStruct*)Unsafe.AsPointer(ref this), objA, objB);
|
||||
}}
|
||||
|
||||
public new int GetType()
|
||||
{{
|
||||
return lpVtbl->GetType1((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
public int GetType(int obj)
|
||||
{{
|
||||
return lpVtbl->GetType2((MyStruct*)Unsafe.AsPointer(ref this), obj);
|
||||
}}
|
||||
|
||||
public partial struct Vtbl
|
||||
{{
|
||||
[NativeTypeName(""int (int, int){nativeCallConv}"")]
|
||||
public new delegate* unmanaged[Thiscall]<MyStruct*, int, int, int> GetType;
|
||||
|
||||
[NativeTypeName(""int (){nativeCallConv}"")]
|
||||
public delegate* unmanaged[Thiscall]<MyStruct*, int> GetType1;
|
||||
|
||||
[NativeTypeName(""int (int){nativeCallConv}"")]
|
||||
public delegate* unmanaged[Thiscall]<MyStruct*, int, int> GetType2;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateExplicitVtbls);
|
||||
}
|
||||
|
||||
protected override Task NewKeywordVirtualWithExplicitVtblAndMarkerInterfaceTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
virtual int GetType(int obj) = 0;
|
||||
virtual int GetType() = 0;
|
||||
virtual int GetType(int objA, int objB) = 0;
|
||||
};";
|
||||
|
||||
var nativeCallConv = "";
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !Environment.Is64BitProcess)
|
||||
{
|
||||
nativeCallConv = " __attribute__((thiscall))";
|
||||
}
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct : MyStruct.Interface
|
||||
{{
|
||||
public Vtbl<MyStruct>* lpVtbl;
|
||||
|
||||
public int GetType(int objA, int objB)
|
||||
{{
|
||||
return lpVtbl->GetType((MyStruct*)Unsafe.AsPointer(ref this), objA, objB);
|
||||
}}
|
||||
|
||||
public new int GetType()
|
||||
{{
|
||||
return lpVtbl->GetType1((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
public int GetType(int obj)
|
||||
{{
|
||||
return lpVtbl->GetType2((MyStruct*)Unsafe.AsPointer(ref this), obj);
|
||||
}}
|
||||
|
||||
public interface Interface
|
||||
{{
|
||||
int GetType(int objA, int objB);
|
||||
|
||||
int GetType();
|
||||
|
||||
int GetType(int obj);
|
||||
}}
|
||||
|
||||
public partial struct Vtbl<TSelf>
|
||||
where TSelf : unmanaged, Interface
|
||||
{{
|
||||
[NativeTypeName(""int (int, int){nativeCallConv}"")]
|
||||
public new delegate* unmanaged[Thiscall]<TSelf*, int, int, int> GetType;
|
||||
|
||||
[NativeTypeName(""int (){nativeCallConv}"")]
|
||||
public delegate* unmanaged[Thiscall]<TSelf*, int> GetType1;
|
||||
|
||||
[NativeTypeName(""int (int){nativeCallConv}"")]
|
||||
public delegate* unmanaged[Thiscall]<TSelf*, int, int> GetType2;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateExplicitVtbls | PInvokeGeneratorConfigurationOptions.GenerateMarkerInterfaces);
|
||||
}
|
||||
|
||||
protected override Task OperatorTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int value;
|
||||
|
||||
MyStruct(int value) : value(value)
|
||||
{
|
||||
}
|
||||
|
||||
MyStruct operator+(MyStruct rhs)
|
||||
{
|
||||
return MyStruct(value + rhs.value);
|
||||
}
|
||||
};
|
||||
|
||||
MyStruct operator-(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return MyStruct(lhs.value - rhs.value);
|
||||
}
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int value;
|
||||
|
||||
public MyStruct(int value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public MyStruct Add(MyStruct rhs)
|
||||
{
|
||||
return new MyStruct(value + rhs.value);
|
||||
}
|
||||
}
|
||||
|
||||
public static partial class Methods
|
||||
{
|
||||
public static MyStruct Subtract(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return new MyStruct(lhs.value - rhs.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task OperatorCallTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int value;
|
||||
|
||||
MyStruct(int value) : value(value)
|
||||
{
|
||||
}
|
||||
|
||||
MyStruct operator+(MyStruct rhs)
|
||||
{
|
||||
return MyStruct(value + rhs.value);
|
||||
}
|
||||
};
|
||||
|
||||
MyStruct MyFunction1(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return lhs + rhs;
|
||||
}
|
||||
|
||||
MyStruct operator-(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return MyStruct(lhs.value - rhs.value);
|
||||
}
|
||||
|
||||
MyStruct MyFunction2(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return lhs - rhs;
|
||||
}
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int value;
|
||||
|
||||
public MyStruct(int value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public MyStruct Add(MyStruct rhs)
|
||||
{
|
||||
return new MyStruct(value + rhs.value);
|
||||
}
|
||||
}
|
||||
|
||||
public static partial class Methods
|
||||
{
|
||||
public static MyStruct MyFunction1(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return lhs.Add(rhs);
|
||||
}
|
||||
|
||||
public static MyStruct Subtract(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return new MyStruct(lhs.value - rhs.value);
|
||||
}
|
||||
|
||||
public static MyStruct MyFunction2(MyStruct lhs, MyStruct rhs)
|
||||
{
|
||||
return Subtract(lhs, rhs);
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task StaticTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
static void MyVoidMethod();
|
||||
|
||||
static int MyInt32Method()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void* MyVoidStarMethod()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var entryPoint = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "?MyVoidMethod@MyStruct@@SAXXZ" : "_ZN8MyStruct12MyVoidMethodEv";
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
entryPoint = $"_{entryPoint}";
|
||||
}
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct
|
||||
{{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, EntryPoint = ""{entryPoint}"", ExactSpelling = true)]
|
||||
public static extern void MyVoidMethod();
|
||||
|
||||
public static int MyInt32Method()
|
||||
{{
|
||||
return 0;
|
||||
}}
|
||||
|
||||
public static void* MyVoidStarMethod()
|
||||
{{
|
||||
return null;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ThisTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
int value;
|
||||
|
||||
int MyFunction()
|
||||
{
|
||||
return this->value;
|
||||
}
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public partial struct MyStruct
|
||||
{
|
||||
public int value;
|
||||
|
||||
public int MyFunction()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UnsafeDoesNotImpactDllImportTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
void* MyVoidStarMethod()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public unsafe partial struct MyStruct
|
||||
{
|
||||
public void* MyVoidStarMethod()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction();
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task VirtualTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
virtual void MyVoidMethod() = 0;
|
||||
|
||||
virtual char MyInt8Method()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int MyInt32Method();
|
||||
|
||||
virtual void* MyVoidStarMethod() = 0;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct
|
||||
{{
|
||||
public void** lpVtbl;
|
||||
|
||||
public void MyVoidMethod()
|
||||
{{
|
||||
((delegate* unmanaged[Thiscall]<MyStruct*, void>)(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
[return: NativeTypeName(""char"")]
|
||||
public sbyte MyInt8Method()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
public int MyInt32Method()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, int>)(lpVtbl[2]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
public void* MyVoidStarMethod()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, void*>)(lpVtbl[3]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task VirtualWithVtblIndexAttributeTestImpl()
|
||||
{
|
||||
var inputContents = @"struct MyStruct
|
||||
{
|
||||
virtual void MyVoidMethod() = 0;
|
||||
|
||||
virtual char MyInt8Method()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int MyInt32Method();
|
||||
|
||||
virtual void* MyVoidStarMethod() = 0;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public unsafe partial struct MyStruct
|
||||
{{
|
||||
public void** lpVtbl;
|
||||
|
||||
[VtblIndex(0)]
|
||||
public void MyVoidMethod()
|
||||
{{
|
||||
((delegate* unmanaged[Thiscall]<MyStruct*, void>)(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName(""char"")]
|
||||
public sbyte MyInt8Method()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, sbyte>)(lpVtbl[1]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
[VtblIndex(2)]
|
||||
public int MyInt32Method()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, int>)(lpVtbl[2]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
|
||||
[VtblIndex(3)]
|
||||
public void* MyVoidStarMethod()
|
||||
{{
|
||||
return ((delegate* unmanaged[Thiscall]<MyStruct*, void*>)(lpVtbl[3]))((MyStruct*)Unsafe.AsPointer(ref this));
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute);
|
||||
}
|
||||
|
||||
protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,554 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class CSharpPreviewWindows_EnumDeclarationTest : EnumDeclarationTest
|
||||
{
|
||||
protected override Task BasicTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task BasicValueTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value1 = 1,
|
||||
MyEnum_Value2,
|
||||
MyEnum_Value3,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum
|
||||
{
|
||||
MyEnum_Value1 = 1,
|
||||
MyEnum_Value2,
|
||||
MyEnum_Value3,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ExcludeTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = string.Empty;
|
||||
|
||||
var excludedNames = new string[] { "MyEnum" };
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: excludedNames);
|
||||
}
|
||||
|
||||
protected override Task ExplicitTypedTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"enum MyEnum : {nativeType}
|
||||
{{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public enum MyEnum : {expectedManagedType}
|
||||
{{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ExplicitTypedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"enum MyEnum : {nativeType}
|
||||
{{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
[NativeTypeName(""{nativeType}"")]
|
||||
public enum MyEnum : {expectedManagedType}
|
||||
{{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task RemapTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef enum _MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1,
|
||||
MyEnum1_Value2,
|
||||
MyEnum1_Value3,
|
||||
} MyEnum1;
|
||||
|
||||
namespace Namespace1
|
||||
{
|
||||
namespace Namespace2
|
||||
{
|
||||
typedef enum _MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1,
|
||||
MyEnum2_Value2,
|
||||
MyEnum2_Value3,
|
||||
} MyEnum2;
|
||||
|
||||
typedef enum _MyEnum3 : int
|
||||
{
|
||||
MyEnum3_Value1,
|
||||
MyEnum3_Value2,
|
||||
MyEnum3_Value3,
|
||||
} MyEnum3;
|
||||
|
||||
typedef enum _MyEnum4 : int
|
||||
{
|
||||
MyEnum4_Value1,
|
||||
MyEnum4_Value2,
|
||||
MyEnum4_Value3,
|
||||
} MyEnum4;
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value1,
|
||||
MyEnum1_Value2,
|
||||
MyEnum1_Value3,
|
||||
}
|
||||
|
||||
public enum MyEnum2
|
||||
{
|
||||
MyEnum2_Value1,
|
||||
MyEnum2_Value2,
|
||||
MyEnum2_Value3,
|
||||
}
|
||||
|
||||
public enum MyEnum3
|
||||
{
|
||||
MyEnum3_Value1,
|
||||
MyEnum3_Value2,
|
||||
MyEnum3_Value3,
|
||||
}
|
||||
|
||||
public enum MyEnum4
|
||||
{
|
||||
MyEnum4_Value1,
|
||||
MyEnum4_Value2,
|
||||
MyEnum4_Value3,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var remappedNames = new Dictionary<string, string> { ["_MyEnum1"] = "MyEnum1", ["Namespace1.Namespace2._MyEnum2"] = "MyEnum2", ["_MyEnum3"] = "MyEnum3", ["Namespace1::Namespace2::_MyEnum4"] = "MyEnum4" };
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames);
|
||||
}
|
||||
|
||||
protected override Task WithAttributeTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = 1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"using System;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
[Flags]
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
}
|
||||
|
||||
public enum MyEnum2
|
||||
{
|
||||
MyEnum2_Value1 = 1,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withAttributes = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["MyEnum1"] = new List<string>() { "Flags" }
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withAttributes: withAttributes);
|
||||
}
|
||||
|
||||
protected override Task WithNamespaceTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"using static ClangSharp.Test.MyEnum1;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
}
|
||||
|
||||
public enum MyEnum2
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withNamespaces = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["MyEnum1"] = new List<string>() { "static ClangSharp.Test.MyEnum1" }
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withUsings: withNamespaces);
|
||||
}
|
||||
|
||||
protected override Task WithNamespaceStarTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"using static ClangSharp.Test.MyEnum1;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
}
|
||||
|
||||
public enum MyEnum2
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withNamespaces = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["*"] = new List<string>() { "static ClangSharp.Test.MyEnum1" }
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withUsings: withNamespaces);
|
||||
}
|
||||
|
||||
protected override Task WithNamespaceStarPlusTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"using System;
|
||||
using static ClangSharp.Test.MyEnum1;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
}
|
||||
|
||||
public enum MyEnum2
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withNamespaces = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["*"] = new List<string>() { "static ClangSharp.Test.MyEnum1" },
|
||||
["MyEnum2"] = new List<string>() { "System" }
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withUsings: withNamespaces);
|
||||
}
|
||||
|
||||
protected override Task WithCastToEnumTypeImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0 = (MyEnum) 10,
|
||||
MyEnum_Value1 = (MyEnum) MyEnum_Value0,
|
||||
MyEnum_Value2 = ((MyEnum) 10) + MyEnum_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum
|
||||
{
|
||||
MyEnum_Value0 = (int)(MyEnum)(10),
|
||||
MyEnum_Value1 = (int)(MyEnum)(MyEnum_Value0),
|
||||
MyEnum_Value2 = ((int)(MyEnum)(10)) + MyEnum_Value1,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithMultipleEnumsTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value0 = 10,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value0 = MyEnum1_Value0,
|
||||
MyEnum2_Value1 = MyEnum1_Value0 + (MyEnum1) 10,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"using static ClangSharp.Test.MyEnum1;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value0 = 10,
|
||||
}
|
||||
|
||||
public enum MyEnum2
|
||||
{
|
||||
MyEnum2_Value0 = MyEnum1_Value0,
|
||||
MyEnum2_Value1 = MyEnum1_Value0 + (int)(MyEnum1)(10),
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithImplicitConversionTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2 = 0x80000000,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2 = unchecked((int)(0x80000000)),
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithTypeTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
[NativeTypeName(""int"")]
|
||||
public enum MyEnum : uint
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string> {
|
||||
["MyEnum"] = "uint"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
|
||||
protected override Task WithTypeAndImplicitConversionTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2 = 0x80000000,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
[NativeTypeName(""int"")]
|
||||
public enum MyEnum : uint
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2 = 0x80000000,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string>
|
||||
{
|
||||
["MyEnum"] = "uint"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
|
||||
protected override Task WithTypeStarTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value0
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value0
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
[NativeTypeName(""int"")]
|
||||
public enum MyEnum1 : uint
|
||||
{
|
||||
MyEnum1_Value0,
|
||||
}
|
||||
|
||||
[NativeTypeName(""int"")]
|
||||
public enum MyEnum2 : uint
|
||||
{
|
||||
MyEnum2_Value0,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "uint"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
|
||||
protected override Task WithTypeStarOverrideTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value0
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value0
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public enum MyEnum1
|
||||
{
|
||||
MyEnum1_Value0,
|
||||
}
|
||||
|
||||
[NativeTypeName(""int"")]
|
||||
public enum MyEnum2 : uint
|
||||
{
|
||||
MyEnum2_Value0,
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "uint",
|
||||
["MyEnum1"] = "int",
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,417 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class CSharpPreviewWindows_FunctionDeclarationDllImportTest : FunctionDeclarationDllImportTest
|
||||
{
|
||||
protected override Task BasicTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction();
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ArrayParameterTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction(const float color[4]);";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static unsafe partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction([NativeTypeName(""const float[4]"")] float* color);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task FunctionPointerParameterTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction(void (*callback)());";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static unsafe partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction([NativeTypeName(""void (*)()"")] delegate* unmanaged[Cdecl]<void> callback);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NamespaceTestImpl()
|
||||
{
|
||||
var inputContents = @"namespace MyNamespace
|
||||
{
|
||||
void MyFunction();
|
||||
}";
|
||||
|
||||
var entryPoint = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "__ZN11MyNamespace10MyFunctionEv" : "_ZN11MyNamespace10MyFunctionEv";
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
entryPoint = "?MyFunction@MyNamespace@@YAXXZ";
|
||||
}
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, EntryPoint = ""{entryPoint}"", ExactSpelling = true)]
|
||||
public static extern void MyFunction();
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task TemplateParameterTestImpl(string nativeType, bool expectedNativeTypeAttr, string expectedManagedType, string expectedUsingStatement)
|
||||
{
|
||||
var inputContents = @$"template <typename T> struct MyTemplate;
|
||||
|
||||
extern ""C"" void MyFunction(MyTemplate<{nativeType}> myStruct);";
|
||||
|
||||
var expectedOutputContents = $@"{expectedUsingStatement}using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction({(expectedNativeTypeAttr ? $@"[NativeTypeName(""MyTemplate<{nativeType}>"")] " : "")}MyTemplate<{expectedManagedType}> myStruct);
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: new[] { "MyTemplate" });
|
||||
}
|
||||
|
||||
protected override Task TemplateMemberTestImpl()
|
||||
{
|
||||
var inputContents = @$"template <typename T> struct MyTemplate
|
||||
{{
|
||||
}};
|
||||
|
||||
struct MyStruct
|
||||
{{
|
||||
MyTemplate<float*> a;
|
||||
}};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"using System;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public partial struct MyStruct
|
||||
{{
|
||||
[NativeTypeName(""MyTemplate<float *>"")]
|
||||
public MyTemplate<IntPtr> a;
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: new[] { "MyTemplate" });
|
||||
}
|
||||
|
||||
protected override Task NoLibraryPathTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport("""", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction();
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, libraryPath: string.Empty);
|
||||
}
|
||||
|
||||
protected override Task WithLibraryPathTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction();
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withLibraryPaths = new Dictionary<string, string>
|
||||
{
|
||||
["MyFunction"] = "ClangSharpPInvokeGenerator"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, libraryPath: string.Empty, withLibraryPaths: withLibraryPaths);
|
||||
}
|
||||
|
||||
protected override Task WithLibraryPathStarTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction();
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withLibraryPaths = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "ClangSharpPInvokeGenerator"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, libraryPath: string.Empty, withLibraryPaths: withLibraryPaths);
|
||||
}
|
||||
|
||||
protected override Task OptionalParameterTestImpl(string nativeType, string nativeInit, bool expectedNativeTypeNameAttr, string expectedManagedType, string expectedManagedInit)
|
||||
{
|
||||
var inputContents = $@"extern ""C"" void MyFunction({nativeType} value = {nativeInit});";
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction({(expectedNativeTypeNameAttr ? $@"[NativeTypeName(""{nativeType}"")] " : "")}{expectedManagedType} value = {expectedManagedInit});
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task OptionalParameterUnsafeTestImpl(string nativeType, string nativeInit, string expectedManagedType, string expectedManagedInit)
|
||||
{
|
||||
var inputContents = $@"extern ""C"" void MyFunction({nativeType} value = {nativeInit});";
|
||||
|
||||
var expectedOutputContents = $@"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static unsafe partial class Methods
|
||||
{{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction({expectedManagedType} value = {expectedManagedInit});
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithCallConvTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", ExactSpelling = true)]
|
||||
public static extern void MyFunction1(int value);
|
||||
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction2(int value);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withCallConvs = new Dictionary<string, string> {
|
||||
["MyFunction1"] = "Winapi"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withCallConvs: withCallConvs);
|
||||
}
|
||||
|
||||
protected override Task WithCallConvStarTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", ExactSpelling = true)]
|
||||
public static extern void MyFunction1(int value);
|
||||
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", ExactSpelling = true)]
|
||||
public static extern void MyFunction2(int value);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withCallConvs = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "Winapi"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withCallConvs: withCallConvs);
|
||||
}
|
||||
|
||||
protected override Task WithCallConvStarOverrideTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", ExactSpelling = true)]
|
||||
public static extern void MyFunction1(int value);
|
||||
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
|
||||
public static extern void MyFunction2(int value);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withCallConvs = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "Winapi",
|
||||
["MyFunction2"] = "StdCall"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withCallConvs: withCallConvs);
|
||||
}
|
||||
|
||||
protected override Task WithSetLastErrorTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = true)]
|
||||
public static extern void MyFunction1(int value);
|
||||
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction2(int value);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withSetLastErrors = new string[]
|
||||
{
|
||||
"MyFunction1"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withSetLastErrors: withSetLastErrors);
|
||||
}
|
||||
|
||||
protected override Task WithSetLastErrorStarTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = true)]
|
||||
public static extern void MyFunction1(int value);
|
||||
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = true)]
|
||||
public static extern void MyFunction2(int value);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var withSetLastErrors = new string[]
|
||||
{
|
||||
"*"
|
||||
};
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withSetLastErrors: withSetLastErrors);
|
||||
}
|
||||
|
||||
protected override Task SourceLocationTestImpl()
|
||||
{
|
||||
const string InputContents = @"extern ""C"" void MyFunction(float value);";
|
||||
|
||||
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
[SourceLocation(""ClangUnsavedFile.h"", 1, 17)]
|
||||
public static extern void MyFunction([SourceLocation(""ClangUnsavedFile.h"", 1, 34)] float value);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute);
|
||||
}
|
||||
|
||||
protected override Task VarargsTestImpl()
|
||||
{
|
||||
const string InputContents = @"extern ""C"" void MyFunction(int value, ...);";
|
||||
|
||||
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
public static partial class Methods
|
||||
{
|
||||
[DllImport(""ClangSharpPInvokeGenerator"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void MyFunction(int value, __arglist);
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(InputContents, ExpectedOutputContents);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class CSharpPreviewWindows_FunctionPointerDeclarationTest : FunctionPointerDeclarationTest
|
||||
{
|
||||
protected override Task BasicTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef void (*Callback)();
|
||||
|
||||
struct MyStruct {
|
||||
Callback _callback;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public unsafe partial struct MyStruct
|
||||
{
|
||||
[NativeTypeName(""Callback"")]
|
||||
public delegate* unmanaged[Cdecl]<void> _callback;
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task CallconvTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef void (*Callback)() __attribute__((stdcall));
|
||||
|
||||
struct MyStruct {
|
||||
Callback _callback;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public unsafe partial struct MyStruct
|
||||
{
|
||||
[NativeTypeName(""Callback"")]
|
||||
public delegate* unmanaged[Stdcall]<void> _callback;
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task PointerlessTypedefTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef void (Callback)();
|
||||
|
||||
struct MyStruct {
|
||||
Callback* _callback;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"namespace ClangSharp.Test
|
||||
{
|
||||
public unsafe partial struct MyStruct
|
||||
{
|
||||
[NativeTypeName(""Callback *"")]
|
||||
public delegate* unmanaged[Cdecl]<void> _callback;
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,399 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class CSharpPreviewWindows_VarDeclarationTest : VarDeclarationTest
|
||||
{
|
||||
protected override Task BasicTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"{nativeType} MyVariable = 0;";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
public static {expectedManagedType} MyVariable = 0;
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"{nativeType} MyVariable = 0;";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""{nativeType}"")]
|
||||
public static {expectedManagedType} MyVariable = 0;
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task GuidMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"struct GUID {{
|
||||
unsigned long Data1;
|
||||
unsigned short Data2;
|
||||
unsigned short Data3;
|
||||
unsigned char Data4[8];
|
||||
}};
|
||||
|
||||
const GUID IID_IUnknown = {{ 0x00000000, 0x0000, 0x0000, {{ 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 }} }};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"using System;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""const GUID"")]
|
||||
public static readonly Guid IID_IUnknown = new Guid(0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
|
||||
}}
|
||||
}}
|
||||
";
|
||||
var excludedNames = new string[] { "GUID" };
|
||||
var remappedNames = new Dictionary<string, string> { ["GUID"] = "Guid" };
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: excludedNames, remappedNames: remappedNames);
|
||||
}
|
||||
|
||||
protected override Task MacroTestImpl(string nativeValue, string expectedManagedType, string expectedManagedValue)
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 {nativeValue}
|
||||
#define MyMacro2 MyMacro1";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro1 {nativeValue}"")]
|
||||
public const {expectedManagedType} MyMacro1 = {expectedManagedValue};
|
||||
|
||||
[NativeTypeName(""#define MyMacro2 MyMacro1"")]
|
||||
public const {expectedManagedType} MyMacro2 = {expectedManagedValue};
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task MultilineMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 0 + \
|
||||
1";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro1 0 + \\\n1"")]
|
||||
public const int MyMacro1 = 0 + 1;
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NoInitializerTestImpl(string nativeType)
|
||||
{
|
||||
var inputContents = $@"{nativeType} MyVariable;";
|
||||
var expectedOutputContents = "";
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task Utf8StringLiteralMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 ""Test""";
|
||||
|
||||
var expectedOutputContents = $@"using System;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro1 \""Test\"""")]
|
||||
public static ReadOnlySpan<byte> MyMacro1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task Utf16StringLiteralMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 u""Test""";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro1 u\""Test\"""")]
|
||||
public const string MyMacro1 = ""Test"";
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WideStringLiteralConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"const wchar_t MyConst1[] = L""Test"";
|
||||
const wchar_t* MyConst2 = L""Test"";
|
||||
const wchar_t* const MyConst3 = L""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""const wchar_t[5]"")]
|
||||
public const string MyConst1 = ""Test"";
|
||||
|
||||
[NativeTypeName(""const wchar_t *"")]
|
||||
public static string MyConst2 = ""Test"";
|
||||
|
||||
[NativeTypeName(""const wchar_t *const"")]
|
||||
public const string MyConst3 = ""Test"";
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task StringLiteralConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"const char MyConst1[] = ""Test"";
|
||||
const char* MyConst2 = ""Test"";
|
||||
const char* const MyConst3 = ""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"using System;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""const char[5]"")]
|
||||
public static ReadOnlySpan<byte> MyConst1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
|
||||
[NativeTypeName(""const char *"")]
|
||||
public static byte[] MyConst2 = new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
|
||||
[NativeTypeName(""const char *const"")]
|
||||
public static ReadOnlySpan<byte> MyConst3 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WideStringLiteralStaticConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"static const wchar_t MyConst1[] = L""Test"";
|
||||
static const wchar_t* MyConst2 = L""Test"";
|
||||
static const wchar_t* const MyConst3 = L""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""const wchar_t[5]"")]
|
||||
public const string MyConst1 = ""Test"";
|
||||
|
||||
[NativeTypeName(""const wchar_t *"")]
|
||||
public static string MyConst2 = ""Test"";
|
||||
|
||||
[NativeTypeName(""const wchar_t *const"")]
|
||||
public const string MyConst3 = ""Test"";
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task StringLiteralStaticConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"static const char MyConst1[] = ""Test"";
|
||||
static const char* MyConst2 = ""Test"";
|
||||
static const char* const MyConst3 = ""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"using System;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""const char[5]"")]
|
||||
public static ReadOnlySpan<byte> MyConst1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
|
||||
[NativeTypeName(""const char *"")]
|
||||
public static byte[] MyConst2 = new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
|
||||
[NativeTypeName(""const char *const"")]
|
||||
public static ReadOnlySpan<byte> MyConst3 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }};
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedConversionMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 (long)0x80000000L
|
||||
#define MyMacro2 (int)0x80000000";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro1 (long)0x80000000L"")]
|
||||
public const int MyMacro1 = unchecked((int)(0x80000000));
|
||||
|
||||
[NativeTypeName(""#define MyMacro2 (int)0x80000000"")]
|
||||
public const int MyMacro2 = unchecked((int)(0x80000000));
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedFunctionLikeCastMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 unsigned(-1)";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro1 unsigned(-1)"")]
|
||||
public const uint MyMacro1 = unchecked((uint)(-1));
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedConversionMacroTest2Impl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1(x, y, z) ((int)(((unsigned long)(x)<<31) | ((unsigned long)(y)<<16) | ((unsigned long)(z))))
|
||||
#define MyMacro2(n) MyMacro1(1, 2, n)
|
||||
#define MyMacro3 MyMacro2(3)";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define MyMacro3 MyMacro2(3)"")]
|
||||
public const int MyMacro3 = unchecked((int)(((uint)(1) << 31) | ((uint)(2) << 16) | ((uint)(3))));
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
var excludedNames = new string[] { "MyMacro1", "MyMacro2" };
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: excludedNames);
|
||||
}
|
||||
|
||||
protected override Task UncheckedPointerMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define Macro1 ((int*) -1)";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static unsafe partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define Macro1 ((int*) -1)"")]
|
||||
public static readonly int* Macro1 = unchecked((int*)(-1));
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedReinterpretCastMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define Macro1 reinterpret_cast<int*>(-1)";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static unsafe partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define Macro1 reinterpret_cast<int*>(-1)"")]
|
||||
public static readonly int* Macro1 = unchecked((int*)(-1));
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task MultidimensionlArrayTestImpl()
|
||||
{
|
||||
var inputContents = $@"const int MyArray[2][2] = {{ {{ 0, 1 }}, {{ 2, 3 }} }};";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""const int[2][2]"")]
|
||||
public static readonly int[][] MyArray = new int[2][]
|
||||
{{
|
||||
new int[2]
|
||||
{{
|
||||
0,
|
||||
1,
|
||||
}},
|
||||
new int[2]
|
||||
{{
|
||||
2,
|
||||
3,
|
||||
}},
|
||||
}};
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ConditionalDefineConstTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef int TESTRESULT;
|
||||
#define TESTRESULT_FROM_WIN32(x) ((TESTRESULT)(x) <= 0 ? ((TESTRESULT)(x)) : ((TESTRESULT) (((x) & 0x0000FFFF) | (7 << 16) | 0x80000000)))
|
||||
#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";
|
||||
|
||||
var expectedOutputContents = $@"namespace ClangSharp.Test
|
||||
{{
|
||||
public static partial class Methods
|
||||
{{
|
||||
[NativeTypeName(""#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)"")]
|
||||
public const int ADDRESS_IN_USE = unchecked((int)(10048) <= 0 ? ((int)(10048)) : ((int)(((10048) & 0x0000FFFF) | (7 << 16) | 0x80000000)));
|
||||
}}
|
||||
}}
|
||||
";
|
||||
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Function like macro definition records are not supported: 'TESTRESULT_FROM_WIN32'. Generated bindings may be incomplete.", "Line 2, Column 9 in ClangUnsavedFile.h") };
|
||||
|
||||
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,6 +37,12 @@ namespace ClangSharp.UnitTests
|
|||
|
||||
protected static string EscapeXml(string value) => new XText(value).ToString();
|
||||
|
||||
protected static Task ValidateGeneratedCSharpPreviewWindowsBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary<string, string> remappedNames = null, IReadOnlyDictionary<string, AccessSpecifier> withAccessSpecifiers = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withAttributes = null, IReadOnlyDictionary<string, string> withCallConvs = null, IReadOnlyDictionary<string, string> withClasses = null, IReadOnlyDictionary<string, string> withLibraryPaths = null, IReadOnlyDictionary<string, string> withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary<string, (string, PInvokeGeneratorTransparentStructKind)> withTransparentStructs = null, IReadOnlyDictionary<string, string> withTypes = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withUsings = null, IEnumerable<Diagnostic> expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null)
|
||||
=> ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions.GeneratePreviewCode | PInvokeGeneratorConfigurationOptions.None | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withClasses, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs);
|
||||
|
||||
protected static Task ValidateGeneratedCSharpPreviewUnixBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary<string, string> remappedNames = null, IReadOnlyDictionary<string, AccessSpecifier> withAccessSpecifiers = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withAttributes = null, IReadOnlyDictionary<string, string> withCallConvs = null, IReadOnlyDictionary<string, string> withClasses = null, IReadOnlyDictionary<string, string> withLibraryPaths = null, IReadOnlyDictionary<string, string> withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary<string, (string, PInvokeGeneratorTransparentStructKind)> withTransparentStructs = null, IReadOnlyDictionary<string, string> withTypes = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withUsings = null, IEnumerable<Diagnostic> expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null)
|
||||
=> ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions.GeneratePreviewCode | PInvokeGeneratorConfigurationOptions.GenerateUnixTypes | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withClasses, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs);
|
||||
|
||||
protected static Task ValidateGeneratedCSharpLatestWindowsBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary<string, string> remappedNames = null, IReadOnlyDictionary<string, AccessSpecifier> withAccessSpecifiers = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withAttributes = null, IReadOnlyDictionary<string, string> withCallConvs = null, IReadOnlyDictionary<string, string> withClasses = null, IReadOnlyDictionary<string, string> withLibraryPaths = null, IReadOnlyDictionary<string, string> withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary<string, (string, PInvokeGeneratorTransparentStructKind)> withTransparentStructs = null, IReadOnlyDictionary<string, string> withTypes = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withUsings = null, IEnumerable<Diagnostic> expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null)
|
||||
=> ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions.None | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withClasses, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs);
|
||||
|
||||
|
@ -49,6 +55,12 @@ namespace ClangSharp.UnitTests
|
|||
protected static Task ValidateGeneratedCSharpCompatibleUnixBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary<string, string> remappedNames = null, IReadOnlyDictionary<string, AccessSpecifier> withAccessSpecifiers = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withAttributes = null, IReadOnlyDictionary<string, string> withCallConvs = null, IReadOnlyDictionary<string, string> withClasses = null, IReadOnlyDictionary<string, string> withLibraryPaths = null, IReadOnlyDictionary<string, string> withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary<string, (string, PInvokeGeneratorTransparentStructKind)> withTransparentStructs = null, IReadOnlyDictionary<string, string> withTypes = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withUsings = null, IEnumerable<Diagnostic> expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null)
|
||||
=> ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode | PInvokeGeneratorConfigurationOptions.GenerateUnixTypes | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withClasses, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs);
|
||||
|
||||
protected static Task ValidateGeneratedXmlPreviewWindowsBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary<string, string> remappedNames = null, IReadOnlyDictionary<string, AccessSpecifier> withAccessSpecifiers = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withAttributes = null, IReadOnlyDictionary<string, string> withCallConvs = null, IReadOnlyDictionary<string, string> withClasses = null, IReadOnlyDictionary<string, string> withLibraryPaths = null, IReadOnlyDictionary<string, string> withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary<string, (string, PInvokeGeneratorTransparentStructKind)> withTransparentStructs = null, IReadOnlyDictionary<string, string> withTypes = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withUsings = null, IEnumerable<Diagnostic> expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null, [CallerFilePath] string filePath = "")
|
||||
=> ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.Xml, PInvokeGeneratorConfigurationOptions.GeneratePreviewCode | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withClasses, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs, filePath);
|
||||
|
||||
protected static Task ValidateGeneratedXmlPreviewUnixBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary<string, string> remappedNames = null, IReadOnlyDictionary<string, AccessSpecifier> withAccessSpecifiers = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withAttributes = null, IReadOnlyDictionary<string, string> withCallConvs = null, IReadOnlyDictionary<string, string> withClasses = null, IReadOnlyDictionary<string, string> withLibraryPaths = null, IReadOnlyDictionary<string, string> withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary<string, (string, PInvokeGeneratorTransparentStructKind)> withTransparentStructs = null, IReadOnlyDictionary<string, string> withTypes = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withUsings = null, IEnumerable<Diagnostic> expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null)
|
||||
=> ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.Xml, PInvokeGeneratorConfigurationOptions.GeneratePreviewCode | PInvokeGeneratorConfigurationOptions.GenerateUnixTypes | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withClasses, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs);
|
||||
|
||||
protected static Task ValidateGeneratedXmlLatestWindowsBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary<string, string> remappedNames = null, IReadOnlyDictionary<string, AccessSpecifier> withAccessSpecifiers = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withAttributes = null, IReadOnlyDictionary<string, string> withCallConvs = null, IReadOnlyDictionary<string, string> withClasses = null, IReadOnlyDictionary<string, string> withLibraryPaths = null, IReadOnlyDictionary<string, string> withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary<string, (string, PInvokeGeneratorTransparentStructKind)> withTransparentStructs = null, IReadOnlyDictionary<string, string> withTypes = null, IReadOnlyDictionary<string, IReadOnlyList<string>> withUsings = null, IEnumerable<Diagnostic> expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null, [CallerFilePath] string filePath = "")
|
||||
=> ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.Xml, PInvokeGeneratorConfigurationOptions.None | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withClasses, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs, filePath);
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,656 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class XmlPreviewUnix_EnumDeclarationTest : EnumDeclarationTest
|
||||
{
|
||||
protected override Task BasicTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task BasicValueTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value1 = 1,
|
||||
MyEnum_Value2,
|
||||
MyEnum_Value3,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value3"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ExcludeTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = string.Empty;
|
||||
|
||||
var excludedNames = new string[] { "MyEnum" };
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: excludedNames);
|
||||
}
|
||||
|
||||
protected override Task ExplicitTypedTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"enum MyEnum : {nativeType}
|
||||
{{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>{EscapeXml(expectedManagedType)}</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">{EscapeXml(expectedManagedType)}</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">{EscapeXml(expectedManagedType)}</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">{EscapeXml(expectedManagedType)}</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ExplicitTypedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"enum MyEnum : {nativeType}
|
||||
{{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>{EscapeXml(expectedManagedType)}</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">{EscapeXml(expectedManagedType)}</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">{EscapeXml(expectedManagedType)}</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">{EscapeXml(expectedManagedType)}</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task RemapTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef enum _MyEnum : int
|
||||
{
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
MyEnum_Value3,
|
||||
} MyEnum;
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value3"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var remappedNames = new Dictionary<string, string> { ["_MyEnum"] = "MyEnum" };
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames);
|
||||
}
|
||||
|
||||
protected override Task WithAttributeTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = 1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<attribute>Flags</attribute>
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum1_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum2_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withAttributes = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["MyEnum1"] = new List<string>() { "Flags" }
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withAttributes: withAttributes);
|
||||
}
|
||||
|
||||
protected override Task WithNamespaceTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum1_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum2_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>MyEnum1_Value1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withNamespaces = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["MyEnum1"] = new List<string>() { "static ClangSharp.Test.MyEnum1" }
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withUsings: withNamespaces);
|
||||
}
|
||||
|
||||
protected override Task WithNamespaceStarTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum1_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum2_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>MyEnum1_Value1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withNamespaces = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["*"] = new List<string>() { "static ClangSharp.Test.MyEnum1" }
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withUsings: withNamespaces);
|
||||
}
|
||||
|
||||
protected override Task WithNamespaceStarPlusTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum1_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum2_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>MyEnum1_Value1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withNamespaces = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["*"] = new List<string>() { "static ClangSharp.Test.MyEnum1" },
|
||||
["MyEnum2"] = new List<string>() { "System" }
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withUsings: withNamespaces);
|
||||
}
|
||||
|
||||
protected override Task WithCastToEnumTypeImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0 = (MyEnum) 10,
|
||||
MyEnum_Value1 = (MyEnum) MyEnum_Value0,
|
||||
MyEnum_Value2 = ((MyEnum) 10) + MyEnum_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>(int)(MyEnum)(<value>10</value>)</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>(int)(MyEnum)(<value>MyEnum_Value0</value>)</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>((int)(MyEnum)(<value>10</value>)) + MyEnum_Value1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithMultipleEnumsTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value0 = 10,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value0 = MyEnum1_Value0,
|
||||
MyEnum2_Value1 = MyEnum1_Value0 + (MyEnum1) 10,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum1_Value0"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>10</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum2_Value0"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>MyEnum1_Value0</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum2_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>MyEnum1_Value0 + (int)(MyEnum1)(<value>10</value>)</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithImplicitConversionTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2 = 0x80000000,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<value>
|
||||
<cast>int</cast>
|
||||
<value>
|
||||
<code>0x80000000</code>
|
||||
</value>
|
||||
</value>
|
||||
</unchecked>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithTypeTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>uint</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string> {
|
||||
["MyEnum"] = "uint"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
|
||||
protected override Task WithTypeAndImplicitConversionTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2 = 0x80000000,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>uint</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
<value>
|
||||
<code>0x80000000</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string>
|
||||
{
|
||||
["MyEnum"] = "uint"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
|
||||
protected override Task WithTypeStarTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value0
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value0
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<type>uint</type>
|
||||
<enumerator name=""MyEnum1_Value0"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>uint</type>
|
||||
<enumerator name=""MyEnum2_Value0"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "uint"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
|
||||
protected override Task WithTypeStarOverrideTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value0
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value0
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum1_Value0"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>uint</type>
|
||||
<enumerator name=""MyEnum2_Value0"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "uint",
|
||||
["MyEnum1"] = "int",
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,453 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class XmlPreviewUnix_FunctionDeclarationDllImportTest : FunctionDeclarationDllImportTest
|
||||
{
|
||||
protected override Task BasicTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ArrayParameterTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction(const float color[4]);";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"" unsafe=""true"">
|
||||
<type>void</type>
|
||||
<param name=""color"">
|
||||
<type>float*</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task FunctionPointerParameterTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction(void (*callback)());";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"" unsafe=""true"">
|
||||
<type>void</type>
|
||||
<param name=""callback"">
|
||||
<type>delegate* unmanaged[Cdecl]<void></type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NamespaceTestImpl()
|
||||
{
|
||||
var inputContents = @"namespace MyNamespace
|
||||
{
|
||||
void MyFunction();
|
||||
}";
|
||||
|
||||
var entryPoint = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "__ZN11MyNamespace10MyFunctionEv" : "_ZN11MyNamespace10MyFunctionEv";
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
entryPoint = "?MyFunction@MyNamespace@@YAXXZ";
|
||||
}
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" entrypoint=""{entryPoint}"" static=""true"">
|
||||
<type>void</type>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task TemplateParameterTestImpl(string nativeType, bool expectedNativeTypeAttr, string expectedManagedType, string expectedUsingStatement)
|
||||
{
|
||||
var inputContents = @$"template <typename T> struct MyTemplate;
|
||||
|
||||
extern ""C"" void MyFunction(MyTemplate<{nativeType}> myStruct);";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""myStruct"">
|
||||
<type>MyTemplate<{expectedManagedType}></type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: new[] { "MyTemplate" });
|
||||
}
|
||||
|
||||
protected override Task TemplateMemberTestImpl()
|
||||
{
|
||||
var inputContents = @$"template <typename T> struct MyTemplate
|
||||
{{
|
||||
}};
|
||||
|
||||
struct MyStruct
|
||||
{{
|
||||
MyTemplate<float*> a;
|
||||
}};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<struct name=""MyStruct"" access=""public"">
|
||||
<field name=""a"" access=""public"">
|
||||
<type native=""MyTemplate<float *>"">MyTemplate<IntPtr></type>
|
||||
</field>
|
||||
</struct>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: new[] { "MyTemplate" });
|
||||
}
|
||||
|
||||
protected override Task NoLibraryPathTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib="""" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, libraryPath: string.Empty);
|
||||
}
|
||||
|
||||
protected override Task WithLibraryPathTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withLibraryPaths = new Dictionary<string, string>
|
||||
{
|
||||
["MyFunction"] = "ClangSharpPInvokeGenerator"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, libraryPath: string.Empty, withLibraryPaths: withLibraryPaths);
|
||||
}
|
||||
|
||||
protected override Task WithLibraryPathStarTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withLibraryPaths = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "ClangSharpPInvokeGenerator"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, libraryPath: string.Empty, withLibraryPaths: withLibraryPaths);
|
||||
}
|
||||
|
||||
protected override Task OptionalParameterTestImpl(string nativeType, string nativeInit, bool expectedNativeTypeNameAttr, string expectedManagedType, string expectedManagedInit)
|
||||
{
|
||||
var inputContents = $@"extern ""C"" void MyFunction({nativeType} value = {nativeInit});";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>{expectedManagedType}</type>
|
||||
<init>
|
||||
<code>{expectedManagedInit}</code>
|
||||
</init>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task OptionalParameterUnsafeTestImpl(string nativeType, string nativeInit, string expectedManagedType, string expectedManagedInit)
|
||||
{
|
||||
var inputContents = $@"extern ""C"" void MyFunction({nativeType} value = {nativeInit});";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"" unsafe=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>{expectedManagedType}</type>
|
||||
<init>
|
||||
<code>{expectedManagedInit}</code>
|
||||
</init>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithCallConvTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction1"" access=""public"" lib=""ClangSharpPInvokeGenerator"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
<function name=""MyFunction2"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withCallConvs = new Dictionary<string, string> {
|
||||
["MyFunction1"] = "Winapi"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withCallConvs: withCallConvs);
|
||||
}
|
||||
|
||||
protected override Task WithCallConvStarTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction1"" access=""public"" lib=""ClangSharpPInvokeGenerator"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
<function name=""MyFunction2"" access=""public"" lib=""ClangSharpPInvokeGenerator"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withCallConvs = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "Winapi"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withCallConvs: withCallConvs);
|
||||
}
|
||||
|
||||
protected override Task WithCallConvStarOverrideTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction1"" access=""public"" lib=""ClangSharpPInvokeGenerator"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
<function name=""MyFunction2"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""StdCall"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withCallConvs = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "Winapi",
|
||||
["MyFunction2"] = "StdCall"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withCallConvs: withCallConvs);
|
||||
}
|
||||
|
||||
protected override Task WithSetLastErrorTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction1"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" setlasterror=""true"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
<function name=""MyFunction2"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withSetLastErrors = new string[]
|
||||
{
|
||||
"MyFunction1"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withSetLastErrors: withSetLastErrors);
|
||||
}
|
||||
|
||||
protected override Task WithSetLastErrorStarTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction1"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" setlasterror=""true"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
<function name=""MyFunction2"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" setlasterror=""true"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withSetLastErrors = new string[]
|
||||
{
|
||||
"*"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withSetLastErrors: withSetLastErrors);
|
||||
}
|
||||
|
||||
protected override Task SourceLocationTestImpl()
|
||||
{
|
||||
const string InputContents = @"extern ""C"" void MyFunction(float value);";
|
||||
|
||||
const string ExpectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>float</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute);
|
||||
}
|
||||
|
||||
protected override Task VarargsTestImpl() => Task.CompletedTask;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class XmlPreviewUnix_FunctionPointerDeclarationTest : FunctionPointerDeclarationTest
|
||||
{
|
||||
protected override Task BasicTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef void (*Callback)();
|
||||
|
||||
struct MyStruct {
|
||||
Callback _callback;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<struct name=""MyStruct"" access=""public"" unsafe=""true"">
|
||||
<field name=""_callback"" access=""public"">
|
||||
<type native=""Callback"">delegate* unmanaged[Cdecl]<void></type>
|
||||
</field>
|
||||
</struct>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task CallconvTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef void (*Callback)() __attribute__((stdcall));
|
||||
|
||||
struct MyStruct {
|
||||
Callback _callback;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<struct name=""MyStruct"" access=""public"" unsafe=""true"">
|
||||
<field name=""_callback"" access=""public"">
|
||||
<type native=""Callback"">delegate* unmanaged[Stdcall]<void></type>
|
||||
</field>
|
||||
</struct>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task PointerlessTypedefTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef void (Callback)();
|
||||
|
||||
struct MyStruct {
|
||||
Callback* _callback;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<struct name=""MyStruct"" access=""public"" unsafe=""true"">
|
||||
<field name=""_callback"" access=""public"">
|
||||
<type native=""Callback *"">delegate* unmanaged[Cdecl]<void></type>
|
||||
</field>
|
||||
</struct>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,534 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class XmlPreviewUnix_VarDeclarationTest : VarDeclarationTest
|
||||
{
|
||||
protected override Task BasicTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"{nativeType} MyVariable = 0;";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<field name=""MyVariable"" access=""public"">
|
||||
<type primitive=""True"">{expectedManagedType}</type>
|
||||
<value>
|
||||
<code>0</code>
|
||||
</value>
|
||||
</field>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"{nativeType} MyVariable = 0;";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<field name=""MyVariable"" access=""public"">
|
||||
<type primitive=""True"">{expectedManagedType}</type>
|
||||
<value>
|
||||
<code>0</code>
|
||||
</value>
|
||||
</field>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task GuidMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"struct GUID {{
|
||||
unsigned long Data1;
|
||||
unsigned short Data2;
|
||||
unsigned short Data3;
|
||||
unsigned char Data4[8];
|
||||
}};
|
||||
|
||||
const GUID IID_IUnknown = {{ 0x00000000, 0x0000, 0x0000, {{ 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 }} }};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""IID_IUnknown"" access=""public"">
|
||||
<type primitive=""False"">Guid</type>
|
||||
<value>
|
||||
<code>new Guid(0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
var excludedNames = new string[] { "GUID" };
|
||||
var remappedNames = new Dictionary<string, string> { ["GUID"] = "Guid" };
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: excludedNames, remappedNames: remappedNames);
|
||||
}
|
||||
|
||||
protected override Task MacroTestImpl(string nativeValue, string expectedManagedType, string expectedManagedValue)
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 {nativeValue}
|
||||
#define MyMacro2 MyMacro1";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro1"" access=""public"">
|
||||
<type primitive=""True"">{expectedManagedType}</type>
|
||||
<value>
|
||||
<code>{expectedManagedValue}</code>
|
||||
</value>
|
||||
</constant>
|
||||
<constant name=""MyMacro2"" access=""public"">
|
||||
<type primitive=""True"">{expectedManagedType}</type>
|
||||
<value>
|
||||
<code>{expectedManagedValue}</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task MultilineMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 0 + \
|
||||
1";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro1"" access=""public"">
|
||||
<type primitive=""True"">int</type>
|
||||
<value>
|
||||
<code>0 + 1</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NoInitializerTestImpl(string nativeType)
|
||||
{
|
||||
var inputContents = $@"{nativeType} MyVariable;";
|
||||
var expectedOutputContents = "";
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task Utf8StringLiteralMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 ""Test""";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro1"" access=""public"">
|
||||
<type primitive=""False"">ReadOnlySpan<byte></type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task Utf16StringLiteralMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 u""Test""";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro1"" access=""public"">
|
||||
<type primitive=""True"">string</type>
|
||||
<value>
|
||||
<code>""Test""</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WideStringLiteralConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"const wchar_t MyConst1[] = L""Test"";
|
||||
const wchar_t* MyConst2 = L""Test"";
|
||||
const wchar_t* const MyConst3 = L""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyConst1"" access=""public"">
|
||||
<type primitive=""False"">uint[]</type>
|
||||
<value>
|
||||
<code>new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
<field name=""MyConst2"" access=""public"">
|
||||
<type primitive=""False"">uint[]</type>
|
||||
<value>
|
||||
<code>new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000 }}</code>
|
||||
</value>
|
||||
</field>
|
||||
<constant name=""MyConst3"" access=""public"">
|
||||
<type primitive=""False"">uint[]</type>
|
||||
<value>
|
||||
<code>new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task StringLiteralConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"const char MyConst1[] = ""Test"";
|
||||
const char* MyConst2 = ""Test"";
|
||||
const char* const MyConst3 = ""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyConst1"" access=""public"">
|
||||
<type primitive=""False"">ReadOnlySpan<byte></type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
<field name=""MyConst2"" access=""public"">
|
||||
<type primitive=""False"">byte[]</type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</field>
|
||||
<constant name=""MyConst3"" access=""public"">
|
||||
<type primitive=""False"">ReadOnlySpan<byte></type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WideStringLiteralStaticConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"static const wchar_t MyConst1[] = L""Test"";
|
||||
static const wchar_t* MyConst2 = L""Test"";
|
||||
static const wchar_t* const MyConst3 = L""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyConst1"" access=""public"">
|
||||
<type primitive=""False"">uint[]</type>
|
||||
<value>
|
||||
<code>new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
<field name=""MyConst2"" access=""public"">
|
||||
<type primitive=""False"">uint[]</type>
|
||||
<value>
|
||||
<code>new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000 }}</code>
|
||||
</value>
|
||||
</field>
|
||||
<constant name=""MyConst3"" access=""public"">
|
||||
<type primitive=""False"">uint[]</type>
|
||||
<value>
|
||||
<code>new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task StringLiteralStaticConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"static const char MyConst1[] = ""Test"";
|
||||
static const char* MyConst2 = ""Test"";
|
||||
static const char* const MyConst3 = ""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyConst1"" access=""public"">
|
||||
<type primitive=""False"">ReadOnlySpan<byte></type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
<field name=""MyConst2"" access=""public"">
|
||||
<type primitive=""False"">byte[]</type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</field>
|
||||
<constant name=""MyConst3"" access=""public"">
|
||||
<type primitive=""False"">ReadOnlySpan<byte></type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedConversionMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 (long)0x80000000L
|
||||
#define MyMacro2 (int)0x80000000";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro1"" access=""public"">
|
||||
<type primitive=""True"">nint</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<value>
|
||||
<code>(nint)(<value>0x80000000</value>)</code>
|
||||
</value>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
<constant name=""MyMacro2"" access=""public"">
|
||||
<type primitive=""True"">int</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<value>
|
||||
<code>(int)(<value>0x80000000</value>)</code>
|
||||
</value>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedFunctionLikeCastMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 unsigned(-1)";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro1"" access=""public"">
|
||||
<type primitive=""True"">uint</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<value>
|
||||
<code>(uint)(<value>-1</value>)</code>
|
||||
</value>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedConversionMacroTest2Impl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1(x, y, z) ((int)(((unsigned long)(x)<<31) | ((unsigned long)(y)<<16) | ((unsigned long)(z))))
|
||||
#define MyMacro2(n) MyMacro1(1, 2, n)
|
||||
#define MyMacro3 MyMacro2(3)";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro3"" access=""public"">
|
||||
<type primitive=""True"">int</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<code>((int)(((nuint)(1) << 31) | ((nuint)(2) << 16) | ((nuint)(3))))</code>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var excludedNames = new string[] { "MyMacro1", "MyMacro2" };
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: excludedNames);
|
||||
}
|
||||
|
||||
protected override Task UncheckedPointerMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define Macro1 ((int*) -1)";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"" unsafe=""true"">
|
||||
<constant name=""Macro1"" access=""public"">
|
||||
<type primitive=""True"">int*</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<code>((int*)(<value>-1</value>))</code>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedReinterpretCastMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define Macro1 reinterpret_cast<int*>(-1)";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"" unsafe=""true"">
|
||||
<constant name=""Macro1"" access=""public"">
|
||||
<type primitive=""True"">int*</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<value>
|
||||
<code>(int*)(<value>-1</value>)</code>
|
||||
</value>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task MultidimensionlArrayTestImpl()
|
||||
{
|
||||
var inputContents = $@"const int MyArray[2][2] = {{ {{ 0, 1 }}, {{ 2, 3 }} }};";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyArray"" access=""public"">
|
||||
<type primitive=""False"">int[][]</type>
|
||||
<value>
|
||||
<code>new int[2][]
|
||||
{{
|
||||
new int[2]
|
||||
{{
|
||||
0,
|
||||
1,
|
||||
}},
|
||||
new int[2]
|
||||
{{
|
||||
2,
|
||||
3,
|
||||
}},
|
||||
}}</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ConditionalDefineConstTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef int TESTRESULT;
|
||||
#define TESTRESULT_FROM_WIN32(x) ((TESTRESULT)(x) <= 0 ? ((TESTRESULT)(x)) : ((TESTRESULT) (((x) & 0x0000FFFF) | (7 << 16) | 0x80000000)))
|
||||
#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""ADDRESS_IN_USE"" access=""public"">
|
||||
<type primitive=""True"">int</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<code>((int)(10048) <= 0 ? ((int)(10048)) : ((int)(((10048) & 0x0000FFFF) | (7 << 16) | 0x80000000)))</code>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Function like macro definition records are not supported: 'TESTRESULT_FROM_WIN32'. Generated bindings may be incomplete.", "Line 2, Column 9 in ClangUnsavedFile.h") };
|
||||
|
||||
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
|
||||
}
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,656 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class XmlPreviewWindows_EnumDeclarationTest : EnumDeclarationTest
|
||||
{
|
||||
protected override Task BasicTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task BasicValueTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value1 = 1,
|
||||
MyEnum_Value2,
|
||||
MyEnum_Value3,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value3"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ExcludeTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = string.Empty;
|
||||
|
||||
var excludedNames = new string[] { "MyEnum" };
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: excludedNames);
|
||||
}
|
||||
|
||||
protected override Task ExplicitTypedTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"enum MyEnum : {nativeType}
|
||||
{{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>{EscapeXml(expectedManagedType)}</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">{EscapeXml(expectedManagedType)}</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">{EscapeXml(expectedManagedType)}</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">{EscapeXml(expectedManagedType)}</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ExplicitTypedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"enum MyEnum : {nativeType}
|
||||
{{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
}};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>{EscapeXml(expectedManagedType)}</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">{EscapeXml(expectedManagedType)}</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">{EscapeXml(expectedManagedType)}</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">{EscapeXml(expectedManagedType)}</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task RemapTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef enum _MyEnum : int
|
||||
{
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
MyEnum_Value3,
|
||||
} MyEnum;
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value3"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var remappedNames = new Dictionary<string, string> { ["_MyEnum"] = "MyEnum" };
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames);
|
||||
}
|
||||
|
||||
protected override Task WithAttributeTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = 1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<attribute>Flags</attribute>
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum1_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum2_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withAttributes = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["MyEnum1"] = new List<string>() { "Flags" }
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withAttributes: withAttributes);
|
||||
}
|
||||
|
||||
protected override Task WithNamespaceTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum1_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum2_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>MyEnum1_Value1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withNamespaces = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["MyEnum1"] = new List<string>() { "static ClangSharp.Test.MyEnum1" }
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withUsings: withNamespaces);
|
||||
}
|
||||
|
||||
protected override Task WithNamespaceStarTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum1_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum2_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>MyEnum1_Value1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withNamespaces = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["*"] = new List<string>() { "static ClangSharp.Test.MyEnum1" }
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withUsings: withNamespaces);
|
||||
}
|
||||
|
||||
protected override Task WithNamespaceStarPlusTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value1 = 1,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value1 = MyEnum1_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum1_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum2_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>MyEnum1_Value1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withNamespaces = new Dictionary<string, IReadOnlyList<string>>
|
||||
{
|
||||
["*"] = new List<string>() { "static ClangSharp.Test.MyEnum1" },
|
||||
["MyEnum2"] = new List<string>() { "System" }
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withUsings: withNamespaces);
|
||||
}
|
||||
|
||||
protected override Task WithCastToEnumTypeImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0 = (MyEnum) 10,
|
||||
MyEnum_Value1 = (MyEnum) MyEnum_Value0,
|
||||
MyEnum_Value2 = ((MyEnum) 10) + MyEnum_Value1,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>(int)(MyEnum)(<value>10</value>)</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>(int)(MyEnum)(<value>MyEnum_Value0</value>)</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>((int)(MyEnum)(<value>10</value>)) + MyEnum_Value1</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithMultipleEnumsTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value0 = 10,
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value0 = MyEnum1_Value0,
|
||||
MyEnum2_Value1 = MyEnum1_Value0 + (MyEnum1) 10,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum1_Value0"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>10</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum2_Value0"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>MyEnum1_Value0</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum2_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<code>MyEnum1_Value0 + (int)(MyEnum1)(<value>10</value>)</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithImplicitConversionTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2 = 0x80000000,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<value>
|
||||
<cast>int</cast>
|
||||
<value>
|
||||
<code>0x80000000</code>
|
||||
</value>
|
||||
</value>
|
||||
</unchecked>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithTypeTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>uint</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string> {
|
||||
["MyEnum"] = "uint"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
|
||||
protected override Task WithTypeAndImplicitConversionTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum : int
|
||||
{
|
||||
MyEnum_Value0,
|
||||
MyEnum_Value1,
|
||||
MyEnum_Value2 = 0x80000000,
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum"" access=""public"">
|
||||
<type>uint</type>
|
||||
<enumerator name=""MyEnum_Value0"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value1"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
<enumerator name=""MyEnum_Value2"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
<value>
|
||||
<code>0x80000000</code>
|
||||
</value>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string>
|
||||
{
|
||||
["MyEnum"] = "uint"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
|
||||
protected override Task WithTypeStarTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value0
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value0
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<type>uint</type>
|
||||
<enumerator name=""MyEnum1_Value0"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>uint</type>
|
||||
<enumerator name=""MyEnum2_Value0"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "uint"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
|
||||
protected override Task WithTypeStarOverrideTestImpl()
|
||||
{
|
||||
var inputContents = @"enum MyEnum1 : int
|
||||
{
|
||||
MyEnum1_Value0
|
||||
};
|
||||
|
||||
enum MyEnum2 : int
|
||||
{
|
||||
MyEnum2_Value0
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<enumeration name=""MyEnum1"" access=""public"">
|
||||
<type>int</type>
|
||||
<enumerator name=""MyEnum1_Value0"" access=""public"">
|
||||
<type primitive=""False"">int</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
<enumeration name=""MyEnum2"" access=""public"">
|
||||
<type>uint</type>
|
||||
<enumerator name=""MyEnum2_Value0"" access=""public"">
|
||||
<type primitive=""False"">uint</type>
|
||||
</enumerator>
|
||||
</enumeration>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withTypes = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "uint",
|
||||
["MyEnum1"] = "int",
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes);
|
||||
}
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,453 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class XmlPreviewWindows_FunctionDeclarationDllImportTest : FunctionDeclarationDllImportTest
|
||||
{
|
||||
protected override Task BasicTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ArrayParameterTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction(const float color[4]);";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"" unsafe=""true"">
|
||||
<type>void</type>
|
||||
<param name=""color"">
|
||||
<type>float*</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task FunctionPointerParameterTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction(void (*callback)());";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"" unsafe=""true"">
|
||||
<type>void</type>
|
||||
<param name=""callback"">
|
||||
<type>delegate* unmanaged[Cdecl]<void></type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NamespaceTestImpl()
|
||||
{
|
||||
var inputContents = @"namespace MyNamespace
|
||||
{
|
||||
void MyFunction();
|
||||
}";
|
||||
|
||||
var entryPoint = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "__ZN11MyNamespace10MyFunctionEv" : "_ZN11MyNamespace10MyFunctionEv";
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
entryPoint = "?MyFunction@MyNamespace@@YAXXZ";
|
||||
}
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" entrypoint=""{entryPoint}"" static=""true"">
|
||||
<type>void</type>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task TemplateParameterTestImpl(string nativeType, bool expectedNativeTypeAttr, string expectedManagedType, string expectedUsingStatement)
|
||||
{
|
||||
var inputContents = @$"template <typename T> struct MyTemplate;
|
||||
|
||||
extern ""C"" void MyFunction(MyTemplate<{nativeType}> myStruct);";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""myStruct"">
|
||||
<type>MyTemplate<{expectedManagedType}></type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: new[] { "MyTemplate" });
|
||||
}
|
||||
|
||||
protected override Task TemplateMemberTestImpl()
|
||||
{
|
||||
var inputContents = @$"template <typename T> struct MyTemplate
|
||||
{{
|
||||
}};
|
||||
|
||||
struct MyStruct
|
||||
{{
|
||||
MyTemplate<float*> a;
|
||||
}};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<struct name=""MyStruct"" access=""public"">
|
||||
<field name=""a"" access=""public"">
|
||||
<type native=""MyTemplate<float *>"">MyTemplate<IntPtr></type>
|
||||
</field>
|
||||
</struct>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: new[] { "MyTemplate" });
|
||||
}
|
||||
|
||||
protected override Task NoLibraryPathTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib="""" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, libraryPath: string.Empty);
|
||||
}
|
||||
|
||||
protected override Task WithLibraryPathTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withLibraryPaths = new Dictionary<string, string>
|
||||
{
|
||||
["MyFunction"] = "ClangSharpPInvokeGenerator"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, libraryPath: string.Empty, withLibraryPaths: withLibraryPaths);
|
||||
}
|
||||
|
||||
protected override Task WithLibraryPathStarTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction();";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withLibraryPaths = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "ClangSharpPInvokeGenerator"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, libraryPath: string.Empty, withLibraryPaths: withLibraryPaths);
|
||||
}
|
||||
|
||||
protected override Task OptionalParameterTestImpl(string nativeType, string nativeInit, bool expectedNativeTypeNameAttr, string expectedManagedType, string expectedManagedInit)
|
||||
{
|
||||
var inputContents = $@"extern ""C"" void MyFunction({nativeType} value = {nativeInit});";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>{expectedManagedType}</type>
|
||||
<init>
|
||||
<code>{expectedManagedInit}</code>
|
||||
</init>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task OptionalParameterUnsafeTestImpl(string nativeType, string nativeInit, string expectedManagedType, string expectedManagedInit)
|
||||
{
|
||||
var inputContents = $@"extern ""C"" void MyFunction({nativeType} value = {nativeInit});";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"" unsafe=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>{expectedManagedType}</type>
|
||||
<init>
|
||||
<code>{expectedManagedInit}</code>
|
||||
</init>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WithCallConvTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction1"" access=""public"" lib=""ClangSharpPInvokeGenerator"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
<function name=""MyFunction2"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withCallConvs = new Dictionary<string, string> {
|
||||
["MyFunction1"] = "Winapi"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withCallConvs: withCallConvs);
|
||||
}
|
||||
|
||||
protected override Task WithCallConvStarTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction1"" access=""public"" lib=""ClangSharpPInvokeGenerator"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
<function name=""MyFunction2"" access=""public"" lib=""ClangSharpPInvokeGenerator"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withCallConvs = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "Winapi"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withCallConvs: withCallConvs);
|
||||
}
|
||||
|
||||
protected override Task WithCallConvStarOverrideTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction1"" access=""public"" lib=""ClangSharpPInvokeGenerator"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
<function name=""MyFunction2"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""StdCall"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withCallConvs = new Dictionary<string, string>
|
||||
{
|
||||
["*"] = "Winapi",
|
||||
["MyFunction2"] = "StdCall"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withCallConvs: withCallConvs);
|
||||
}
|
||||
|
||||
protected override Task WithSetLastErrorTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction1"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" setlasterror=""true"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
<function name=""MyFunction2"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withSetLastErrors = new string[]
|
||||
{
|
||||
"MyFunction1"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withSetLastErrors: withSetLastErrors);
|
||||
}
|
||||
|
||||
protected override Task WithSetLastErrorStarTestImpl()
|
||||
{
|
||||
var inputContents = @"extern ""C"" void MyFunction1(int value); extern ""C"" void MyFunction2(int value);";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction1"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" setlasterror=""true"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
<function name=""MyFunction2"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" setlasterror=""true"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>int</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var withSetLastErrors = new string[]
|
||||
{
|
||||
"*"
|
||||
};
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withSetLastErrors: withSetLastErrors);
|
||||
}
|
||||
|
||||
protected override Task SourceLocationTestImpl()
|
||||
{
|
||||
const string InputContents = @"extern ""C"" void MyFunction(float value);";
|
||||
|
||||
const string ExpectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<function name=""MyFunction"" access=""public"" lib=""ClangSharpPInvokeGenerator"" convention=""Cdecl"" static=""true"">
|
||||
<type>void</type>
|
||||
<param name=""value"">
|
||||
<type>float</type>
|
||||
</param>
|
||||
</function>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute);
|
||||
}
|
||||
|
||||
protected override Task VarargsTestImpl() => Task.CompletedTask;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class XmlPreviewWindows_FunctionPointerDeclarationTest : FunctionPointerDeclarationTest
|
||||
{
|
||||
protected override Task BasicTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef void (*Callback)();
|
||||
|
||||
struct MyStruct {
|
||||
Callback _callback;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<struct name=""MyStruct"" access=""public"" unsafe=""true"">
|
||||
<field name=""_callback"" access=""public"">
|
||||
<type native=""Callback"">delegate* unmanaged[Cdecl]<void></type>
|
||||
</field>
|
||||
</struct>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task CallconvTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef void (*Callback)() __attribute__((stdcall));
|
||||
|
||||
struct MyStruct {
|
||||
Callback _callback;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<struct name=""MyStruct"" access=""public"" unsafe=""true"">
|
||||
<field name=""_callback"" access=""public"">
|
||||
<type native=""Callback"">delegate* unmanaged[Stdcall]<void></type>
|
||||
</field>
|
||||
</struct>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task PointerlessTypedefTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef void (Callback)();
|
||||
|
||||
struct MyStruct {
|
||||
Callback* _callback;
|
||||
};
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<struct name=""MyStruct"" access=""public"" unsafe=""true"">
|
||||
<field name=""_callback"" access=""public"">
|
||||
<type native=""Callback *"">delegate* unmanaged[Cdecl]<void></type>
|
||||
</field>
|
||||
</struct>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,534 @@
|
|||
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClangSharp.UnitTests
|
||||
{
|
||||
public sealed class XmlPreviewWindows_VarDeclarationTest : VarDeclarationTest
|
||||
{
|
||||
protected override Task BasicTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"{nativeType} MyVariable = 0;";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<field name=""MyVariable"" access=""public"">
|
||||
<type primitive=""True"">{expectedManagedType}</type>
|
||||
<value>
|
||||
<code>0</code>
|
||||
</value>
|
||||
</field>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType)
|
||||
{
|
||||
var inputContents = $@"{nativeType} MyVariable = 0;";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<field name=""MyVariable"" access=""public"">
|
||||
<type primitive=""True"">{expectedManagedType}</type>
|
||||
<value>
|
||||
<code>0</code>
|
||||
</value>
|
||||
</field>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task GuidMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"struct GUID {{
|
||||
unsigned long Data1;
|
||||
unsigned short Data2;
|
||||
unsigned short Data3;
|
||||
unsigned char Data4[8];
|
||||
}};
|
||||
|
||||
const GUID IID_IUnknown = {{ 0x00000000, 0x0000, 0x0000, {{ 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 }} }};
|
||||
";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""IID_IUnknown"" access=""public"">
|
||||
<type primitive=""False"">Guid</type>
|
||||
<value>
|
||||
<code>new Guid(0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
var excludedNames = new string[] { "GUID" };
|
||||
var remappedNames = new Dictionary<string, string> { ["GUID"] = "Guid" };
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: excludedNames, remappedNames: remappedNames);
|
||||
}
|
||||
|
||||
protected override Task MacroTestImpl(string nativeValue, string expectedManagedType, string expectedManagedValue)
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 {nativeValue}
|
||||
#define MyMacro2 MyMacro1";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro1"" access=""public"">
|
||||
<type primitive=""True"">{expectedManagedType}</type>
|
||||
<value>
|
||||
<code>{expectedManagedValue}</code>
|
||||
</value>
|
||||
</constant>
|
||||
<constant name=""MyMacro2"" access=""public"">
|
||||
<type primitive=""True"">{expectedManagedType}</type>
|
||||
<value>
|
||||
<code>{expectedManagedValue}</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task MultilineMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 0 + \
|
||||
1";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro1"" access=""public"">
|
||||
<type primitive=""True"">int</type>
|
||||
<value>
|
||||
<code>0 + 1</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task NoInitializerTestImpl(string nativeType)
|
||||
{
|
||||
var inputContents = $@"{nativeType} MyVariable;";
|
||||
var expectedOutputContents = "";
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task Utf8StringLiteralMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 ""Test""";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro1"" access=""public"">
|
||||
<type primitive=""False"">ReadOnlySpan<byte></type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task Utf16StringLiteralMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 u""Test""";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro1"" access=""public"">
|
||||
<type primitive=""True"">string</type>
|
||||
<value>
|
||||
<code>""Test""</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WideStringLiteralConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"const wchar_t MyConst1[] = L""Test"";
|
||||
const wchar_t* MyConst2 = L""Test"";
|
||||
const wchar_t* const MyConst3 = L""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyConst1"" access=""public"">
|
||||
<type primitive=""True"">string</type>
|
||||
<value>
|
||||
<code>""Test""</code>
|
||||
</value>
|
||||
</constant>
|
||||
<field name=""MyConst2"" access=""public"">
|
||||
<type primitive=""True"">string</type>
|
||||
<value>
|
||||
<code>""Test""</code>
|
||||
</value>
|
||||
</field>
|
||||
<constant name=""MyConst3"" access=""public"">
|
||||
<type primitive=""True"">string</type>
|
||||
<value>
|
||||
<code>""Test""</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task StringLiteralConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"const char MyConst1[] = ""Test"";
|
||||
const char* MyConst2 = ""Test"";
|
||||
const char* const MyConst3 = ""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyConst1"" access=""public"">
|
||||
<type primitive=""False"">ReadOnlySpan<byte></type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
<field name=""MyConst2"" access=""public"">
|
||||
<type primitive=""False"">byte[]</type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</field>
|
||||
<constant name=""MyConst3"" access=""public"">
|
||||
<type primitive=""False"">ReadOnlySpan<byte></type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task WideStringLiteralStaticConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"static const wchar_t MyConst1[] = L""Test"";
|
||||
static const wchar_t* MyConst2 = L""Test"";
|
||||
static const wchar_t* const MyConst3 = L""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyConst1"" access=""public"">
|
||||
<type primitive=""True"">string</type>
|
||||
<value>
|
||||
<code>""Test""</code>
|
||||
</value>
|
||||
</constant>
|
||||
<field name=""MyConst2"" access=""public"">
|
||||
<type primitive=""True"">string</type>
|
||||
<value>
|
||||
<code>""Test""</code>
|
||||
</value>
|
||||
</field>
|
||||
<constant name=""MyConst3"" access=""public"">
|
||||
<type primitive=""True"">string</type>
|
||||
<value>
|
||||
<code>""Test""</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task StringLiteralStaticConstTestImpl()
|
||||
{
|
||||
var inputContents = $@"static const char MyConst1[] = ""Test"";
|
||||
static const char* MyConst2 = ""Test"";
|
||||
static const char* const MyConst3 = ""Test"";";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyConst1"" access=""public"">
|
||||
<type primitive=""False"">ReadOnlySpan<byte></type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
<field name=""MyConst2"" access=""public"">
|
||||
<type primitive=""False"">byte[]</type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</field>
|
||||
<constant name=""MyConst3"" access=""public"">
|
||||
<type primitive=""False"">ReadOnlySpan<byte></type>
|
||||
<value>
|
||||
<code>new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00 }}</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedConversionMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 (long)0x80000000L
|
||||
#define MyMacro2 (int)0x80000000";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro1"" access=""public"">
|
||||
<type primitive=""True"">int</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<value>
|
||||
<code>(int)(<value>0x80000000</value>)</code>
|
||||
</value>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
<constant name=""MyMacro2"" access=""public"">
|
||||
<type primitive=""True"">int</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<value>
|
||||
<code>(int)(<value>0x80000000</value>)</code>
|
||||
</value>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedFunctionLikeCastMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1 unsigned(-1)";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro1"" access=""public"">
|
||||
<type primitive=""True"">uint</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<value>
|
||||
<code>(uint)(<value>-1</value>)</code>
|
||||
</value>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedConversionMacroTest2Impl()
|
||||
{
|
||||
var inputContents = $@"#define MyMacro1(x, y, z) ((int)(((unsigned long)(x)<<31) | ((unsigned long)(y)<<16) | ((unsigned long)(z))))
|
||||
#define MyMacro2(n) MyMacro1(1, 2, n)
|
||||
#define MyMacro3 MyMacro2(3)";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyMacro3"" access=""public"">
|
||||
<type primitive=""True"">int</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<code>((int)(((uint)(1) << 31) | ((uint)(2) << 16) | ((uint)(3))))</code>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
var excludedNames = new string[] { "MyMacro1", "MyMacro2" };
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: excludedNames);
|
||||
}
|
||||
|
||||
protected override Task UncheckedPointerMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define Macro1 ((int*) -1)";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"" unsafe=""true"">
|
||||
<constant name=""Macro1"" access=""public"">
|
||||
<type primitive=""True"">int*</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<code>((int*)(<value>-1</value>))</code>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task UncheckedReinterpretCastMacroTestImpl()
|
||||
{
|
||||
var inputContents = $@"#define Macro1 reinterpret_cast<int*>(-1)";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"" unsafe=""true"">
|
||||
<constant name=""Macro1"" access=""public"">
|
||||
<type primitive=""True"">int*</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<value>
|
||||
<code>(int*)(<value>-1</value>)</code>
|
||||
</value>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task MultidimensionlArrayTestImpl()
|
||||
{
|
||||
var inputContents = $@"const int MyArray[2][2] = {{ {{ 0, 1 }}, {{ 2, 3 }} }};";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""MyArray"" access=""public"">
|
||||
<type primitive=""False"">int[][]</type>
|
||||
<value>
|
||||
<code>new int[2][]
|
||||
{{
|
||||
new int[2]
|
||||
{{
|
||||
0,
|
||||
1,
|
||||
}},
|
||||
new int[2]
|
||||
{{
|
||||
2,
|
||||
3,
|
||||
}},
|
||||
}}</code>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
protected override Task ConditionalDefineConstTestImpl()
|
||||
{
|
||||
var inputContents = @"typedef int TESTRESULT;
|
||||
#define TESTRESULT_FROM_WIN32(x) ((TESTRESULT)(x) <= 0 ? ((TESTRESULT)(x)) : ((TESTRESULT) (((x) & 0x0000FFFF) | (7 << 16) | 0x80000000)))
|
||||
#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";
|
||||
|
||||
var expectedOutputContents = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
|
||||
<bindings>
|
||||
<namespace name=""ClangSharp.Test"">
|
||||
<class name=""Methods"" access=""public"" static=""true"">
|
||||
<constant name=""ADDRESS_IN_USE"" access=""public"">
|
||||
<type primitive=""True"">int</type>
|
||||
<value>
|
||||
<unchecked>
|
||||
<code>((int)(10048) <= 0 ? ((int)(10048)) : ((int)(((10048) & 0x0000FFFF) | (7 << 16) | 0x80000000)))</code>
|
||||
</unchecked>
|
||||
</value>
|
||||
</constant>
|
||||
</class>
|
||||
</namespace>
|
||||
</bindings>
|
||||
";
|
||||
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Function like macro definition records are not supported: 'TESTRESULT_FROM_WIN32'. Generated bindings may be incomplete.", "Line 2, Column 9 in ClangUnsavedFile.h") };
|
||||
|
||||
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче