Skip to content

Commit

Permalink
Merge pull request #406 from DaZombieKiller/with-packing-tests
Browse files Browse the repository at this point in the history
Adding tests for --with-packing output
  • Loading branch information
tannergooding authored Nov 7, 2022
2 parents 69391f1 + abc629a commit bbf343f
Showing 14 changed files with 571 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -206,6 +206,9 @@ public abstract class StructDeclarationTest : PInvokeGeneratorTest
[Test]
public Task WithAccessSpecifierTest() => WithAccessSpecifierTestImpl();

[Test]
public Task WithPackingTest() => WithPackingTestImpl();

[Test]
public Task SourceLocationAttributeTest() => SourceLocationAttributeTestImpl();

@@ -279,5 +282,7 @@ public abstract class StructDeclarationTest : PInvokeGeneratorTest

protected abstract Task WithAccessSpecifierTestImpl();

protected abstract Task WithPackingTestImpl();

protected abstract Task SourceLocationAttributeTestImpl();
}
Original file line number Diff line number Diff line change
@@ -1724,6 +1724,50 @@ public partial struct MyStruct3
return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers);
}

protected override Task WithPackingTestImpl()
{
const string InputContents = @"struct MyStruct
{
size_t FixedBuffer[1];
};
";

const string ExpectedOutputContents = @"using System;
using System.Runtime.InteropServices;
namespace ClangSharp.Test
{
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
public partial struct MyStruct
{
[NativeTypeName(""size_t[1]"")]
public _FixedBuffer_e__FixedBuffer FixedBuffer;
public partial struct _FixedBuffer_e__FixedBuffer
{
public UIntPtr e0;
public unsafe ref UIntPtr this[int index]
{
get
{
fixed (UIntPtr* pThis = &e0)
{
return ref pThis[index];
}
}
}
}
}
}
";

var withPackings = new Dictionary<string, string> {
["MyStruct"] = "CustomPackValue"
};
return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings);
}

protected override Task SourceLocationAttributeTestImpl()
{
const string InputContents = @"struct MyStruct
Original file line number Diff line number Diff line change
@@ -1728,6 +1728,50 @@ public partial struct MyStruct3
return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers);
}

protected override Task WithPackingTestImpl()
{
const string InputContents = @"struct MyStruct
{
size_t FixedBuffer[1];
};
";

const string ExpectedOutputContents = @"using System;
using System.Runtime.InteropServices;
namespace ClangSharp.Test
{
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
public partial struct MyStruct
{
[NativeTypeName(""size_t[1]"")]
public _FixedBuffer_e__FixedBuffer FixedBuffer;
public partial struct _FixedBuffer_e__FixedBuffer
{
public UIntPtr e0;
public unsafe ref UIntPtr this[int index]
{
get
{
fixed (UIntPtr* pThis = &e0)
{
return ref pThis[index];
}
}
}
}
}
}
";

var withPackings = new Dictionary<string, string> {
["MyStruct"] = "CustomPackValue"
};
return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings);
}

protected override Task SourceLocationAttributeTestImpl()
{
const string InputContents = @"struct MyStruct
Original file line number Diff line number Diff line change
@@ -1702,6 +1702,49 @@ public partial struct MyStruct3
return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers);
}

protected override Task WithPackingTestImpl()
{
const string InputContents = @"struct MyStruct
{
size_t FixedBuffer[1];
};
";

const string ExpectedOutputContents = @"using System;
using System.Runtime.InteropServices;
namespace ClangSharp.Test
{
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
public partial struct MyStruct
{
[NativeTypeName(""size_t[1]"")]
public _FixedBuffer_e__FixedBuffer FixedBuffer;
public partial struct _FixedBuffer_e__FixedBuffer
{
public nuint e0;
public ref nuint this[int index]
{
get
{
return ref AsSpan(int.MaxValue)[index];
}
}
public Span<nuint> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
}
}
}
";

var withPackings = new Dictionary<string, string> {
["MyStruct"] = "CustomPackValue"
};
return ValidateGeneratedCSharpLatestUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings);
}

protected override Task SourceLocationAttributeTestImpl()
{
const string InputContents = @"struct MyStruct
Original file line number Diff line number Diff line change
@@ -1706,6 +1706,49 @@ public partial struct MyStruct3
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers);
}

protected override Task WithPackingTestImpl()
{
const string InputContents = @"struct MyStruct
{
size_t FixedBuffer[1];
};
";

const string ExpectedOutputContents = @"using System;
using System.Runtime.InteropServices;
namespace ClangSharp.Test
{
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
public partial struct MyStruct
{
[NativeTypeName(""size_t[1]"")]
public _FixedBuffer_e__FixedBuffer FixedBuffer;
public partial struct _FixedBuffer_e__FixedBuffer
{
public nuint e0;
public ref nuint this[int index]
{
get
{
return ref AsSpan(int.MaxValue)[index];
}
}
public Span<nuint> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
}
}
}
";

var withPackings = new Dictionary<string, string> {
["MyStruct"] = "CustomPackValue"
};
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings);
}

protected override Task SourceLocationAttributeTestImpl()
{
const string InputContents = @"struct MyStruct
Original file line number Diff line number Diff line change
@@ -1728,6 +1728,52 @@ public partial struct MyStruct3
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers);
}

protected override Task WithPackingTestImpl()
{
const string InputContents = @"struct MyStruct
{
size_t FixedBuffer[1];
};
";

const string ExpectedOutputContents = @"using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
namespace ClangSharp.Test
{
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
public partial struct MyStruct
{
[NativeTypeName(""size_t[1]"")]
public _FixedBuffer_e__FixedBuffer FixedBuffer;
public partial struct _FixedBuffer_e__FixedBuffer
{
public nuint e0;
[UnscopedRef]
public ref nuint this[int index]
{
get
{
return ref AsSpan(int.MaxValue)[index];
}
}
[UnscopedRef]
public Span<nuint> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
}
}
}
";

var withPackings = new Dictionary<string, string> {
["MyStruct"] = "CustomPackValue"
};
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings);
}

protected override Task SourceLocationAttributeTestImpl()
{
const string InputContents = @"struct MyStruct
Original file line number Diff line number Diff line change
@@ -1732,6 +1732,52 @@ public partial struct MyStruct3
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers);
}

protected override Task WithPackingTestImpl()
{
const string InputContents = @"struct MyStruct
{
size_t FixedBuffer[1];
};
";

const string ExpectedOutputContents = @"using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
namespace ClangSharp.Test
{
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
public partial struct MyStruct
{
[NativeTypeName(""size_t[1]"")]
public _FixedBuffer_e__FixedBuffer FixedBuffer;
public partial struct _FixedBuffer_e__FixedBuffer
{
public nuint e0;
[UnscopedRef]
public ref nuint this[int index]
{
get
{
return ref AsSpan(int.MaxValue)[index];
}
}
[UnscopedRef]
public Span<nuint> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
}
}
}
";

var withPackings = new Dictionary<string, string> {
["MyStruct"] = "CustomPackValue"
};
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings);
}

protected override Task SourceLocationAttributeTestImpl()
{
const string InputContents = @"struct MyStruct
Loading

0 comments on commit bbf343f

Please sign in to comment.