Skip to content

Commit 261f236

Browse files
Adding tests for --with-packing output
1 parent 2218939 commit 261f236

File tree

14 files changed

+265
-26
lines changed

14 files changed

+265
-26
lines changed

tests/ClangSharp.PInvokeGenerator.UnitTests/Base/StructDeclarationTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ public abstract class StructDeclarationTest : PInvokeGeneratorTest
206206
[Test]
207207
public Task WithAccessSpecifierTest() => WithAccessSpecifierTestImpl();
208208

209+
[Test]
210+
public Task WithPackingTest() => WithPackingTestImpl();
211+
209212
[Test]
210213
public Task SourceLocationAttributeTest() => SourceLocationAttributeTestImpl();
211214

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

280283
protected abstract Task WithAccessSpecifierTestImpl();
281284

285+
protected abstract Task WithPackingTestImpl();
286+
282287
protected abstract Task SourceLocationAttributeTestImpl();
283288
}

tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/StructDeclarationTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,27 @@ public partial struct MyStruct3
17241724
return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers);
17251725
}
17261726

1727+
protected override Task WithPackingTestImpl()
1728+
{
1729+
const string InputContents = @"struct MyStruct {};";
1730+
1731+
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1732+
1733+
namespace ClangSharp.Test
1734+
{
1735+
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
1736+
public partial struct MyStruct
1737+
{
1738+
}
1739+
}
1740+
";
1741+
1742+
var withPackings = new Dictionary<string, string> {
1743+
["MyStruct"] = "CustomPackValue"
1744+
};
1745+
return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings);
1746+
}
1747+
17271748
protected override Task SourceLocationAttributeTestImpl()
17281749
{
17291750
const string InputContents = @"struct MyStruct

tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/StructDeclarationTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,27 @@ public partial struct MyStruct3
17281728
return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers);
17291729
}
17301730

1731+
protected override Task WithPackingTestImpl()
1732+
{
1733+
const string InputContents = @"struct MyStruct {};";
1734+
1735+
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1736+
1737+
namespace ClangSharp.Test
1738+
{
1739+
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
1740+
public partial struct MyStruct
1741+
{
1742+
}
1743+
}
1744+
";
1745+
1746+
var withPackings = new Dictionary<string, string> {
1747+
["MyStruct"] = "CustomPackValue"
1748+
};
1749+
return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings);
1750+
}
1751+
17311752
protected override Task SourceLocationAttributeTestImpl()
17321753
{
17331754
const string InputContents = @"struct MyStruct

tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/StructDeclarationTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,27 @@ public partial struct MyStruct3
17021702
return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers);
17031703
}
17041704

1705+
protected override Task WithPackingTestImpl()
1706+
{
1707+
const string InputContents = @"struct MyStruct {};";
1708+
1709+
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1710+
1711+
namespace ClangSharp.Test
1712+
{
1713+
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
1714+
public partial struct MyStruct
1715+
{
1716+
}
1717+
}
1718+
";
1719+
1720+
var withPackings = new Dictionary<string, string> {
1721+
["MyStruct"] = "CustomPackValue"
1722+
};
1723+
return ValidateGeneratedCSharpLatestUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings);
1724+
}
1725+
17051726
protected override Task SourceLocationAttributeTestImpl()
17061727
{
17071728
const string InputContents = @"struct MyStruct

tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/StructDeclarationTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,27 @@ public partial struct MyStruct3
17061706
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers);
17071707
}
17081708

1709+
protected override Task WithPackingTestImpl()
1710+
{
1711+
const string InputContents = @"struct MyStruct {};";
1712+
1713+
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1714+
1715+
namespace ClangSharp.Test
1716+
{
1717+
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
1718+
public partial struct MyStruct
1719+
{
1720+
}
1721+
}
1722+
";
1723+
1724+
var withPackings = new Dictionary<string, string> {
1725+
["MyStruct"] = "CustomPackValue"
1726+
};
1727+
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings);
1728+
}
1729+
17091730
protected override Task SourceLocationAttributeTestImpl()
17101731
{
17111732
const string InputContents = @"struct MyStruct

tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/StructDeclarationTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,27 @@ public partial struct MyStruct3
17281728
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers);
17291729
}
17301730

1731+
protected override Task WithPackingTestImpl()
1732+
{
1733+
const string InputContents = @"struct MyStruct {};";
1734+
1735+
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1736+
1737+
namespace ClangSharp.Test
1738+
{
1739+
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
1740+
public partial struct MyStruct
1741+
{
1742+
}
1743+
}
1744+
";
1745+
1746+
var withPackings = new Dictionary<string, string> {
1747+
["MyStruct"] = "CustomPackValue"
1748+
};
1749+
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings);
1750+
}
1751+
17311752
protected override Task SourceLocationAttributeTestImpl()
17321753
{
17331754
const string InputContents = @"struct MyStruct

tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/StructDeclarationTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,27 @@ public partial struct MyStruct3
17321732
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers);
17331733
}
17341734

1735+
protected override Task WithPackingTestImpl()
1736+
{
1737+
const string InputContents = @"struct MyStruct {};";
1738+
1739+
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1740+
1741+
namespace ClangSharp.Test
1742+
{
1743+
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
1744+
public partial struct MyStruct
1745+
{
1746+
}
1747+
}
1748+
";
1749+
1750+
var withPackings = new Dictionary<string, string> {
1751+
["MyStruct"] = "CustomPackValue"
1752+
};
1753+
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings);
1754+
}
1755+
17351756
protected override Task SourceLocationAttributeTestImpl()
17361757
{
17371758
const string InputContents = @"struct MyStruct

0 commit comments

Comments
 (0)