Skip to content

Commit e162c16

Browse files
Changing --with-packing tests to account for nested fixed buffer types
1 parent 261f236 commit e162c16

File tree

12 files changed

+330
-24
lines changed

12 files changed

+330
-24
lines changed

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

+25-2
Original file line numberDiff line numberDiff line change
@@ -1726,15 +1726,38 @@ public partial struct MyStruct3
17261726

17271727
protected override Task WithPackingTestImpl()
17281728
{
1729-
const string InputContents = @"struct MyStruct {};";
1729+
const string InputContents = @"struct MyStruct
1730+
{
1731+
size_t FixedBuffer[1];
1732+
};
1733+
";
17301734

1731-
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1735+
const string ExpectedOutputContents = @"using System;
1736+
using System.Runtime.InteropServices;
17321737
17331738
namespace ClangSharp.Test
17341739
{
17351740
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
17361741
public partial struct MyStruct
17371742
{
1743+
[NativeTypeName(""size_t[1]"")]
1744+
public _FixedBuffer_e__FixedBuffer FixedBuffer;
1745+
1746+
public partial struct _FixedBuffer_e__FixedBuffer
1747+
{
1748+
public UIntPtr e0;
1749+
1750+
public unsafe ref UIntPtr this[int index]
1751+
{
1752+
get
1753+
{
1754+
fixed (UIntPtr* pThis = &e0)
1755+
{
1756+
return ref pThis[index];
1757+
}
1758+
}
1759+
}
1760+
}
17381761
}
17391762
}
17401763
";

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

+25-2
Original file line numberDiff line numberDiff line change
@@ -1730,15 +1730,38 @@ public partial struct MyStruct3
17301730

17311731
protected override Task WithPackingTestImpl()
17321732
{
1733-
const string InputContents = @"struct MyStruct {};";
1733+
const string InputContents = @"struct MyStruct
1734+
{
1735+
size_t FixedBuffer[1];
1736+
};
1737+
";
17341738

1735-
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1739+
const string ExpectedOutputContents = @"using System;
1740+
using System.Runtime.InteropServices;
17361741
17371742
namespace ClangSharp.Test
17381743
{
17391744
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
17401745
public partial struct MyStruct
17411746
{
1747+
[NativeTypeName(""size_t[1]"")]
1748+
public _FixedBuffer_e__FixedBuffer FixedBuffer;
1749+
1750+
public partial struct _FixedBuffer_e__FixedBuffer
1751+
{
1752+
public UIntPtr e0;
1753+
1754+
public unsafe ref UIntPtr this[int index]
1755+
{
1756+
get
1757+
{
1758+
fixed (UIntPtr* pThis = &e0)
1759+
{
1760+
return ref pThis[index];
1761+
}
1762+
}
1763+
}
1764+
}
17421765
}
17431766
}
17441767
";

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

+24-2
Original file line numberDiff line numberDiff line change
@@ -1704,15 +1704,37 @@ public partial struct MyStruct3
17041704

17051705
protected override Task WithPackingTestImpl()
17061706
{
1707-
const string InputContents = @"struct MyStruct {};";
1707+
const string InputContents = @"struct MyStruct
1708+
{
1709+
size_t FixedBuffer[1];
1710+
};
1711+
";
17081712

1709-
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1713+
const string ExpectedOutputContents = @"using System;
1714+
using System.Runtime.InteropServices;
17101715
17111716
namespace ClangSharp.Test
17121717
{
17131718
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
17141719
public partial struct MyStruct
17151720
{
1721+
[NativeTypeName(""size_t[1]"")]
1722+
public _FixedBuffer_e__FixedBuffer FixedBuffer;
1723+
1724+
public partial struct _FixedBuffer_e__FixedBuffer
1725+
{
1726+
public nuint e0;
1727+
1728+
public ref nuint this[int index]
1729+
{
1730+
get
1731+
{
1732+
return ref AsSpan(int.MaxValue)[index];
1733+
}
1734+
}
1735+
1736+
public Span<nuint> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
1737+
}
17161738
}
17171739
}
17181740
";

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

+24-2
Original file line numberDiff line numberDiff line change
@@ -1708,15 +1708,37 @@ public partial struct MyStruct3
17081708

17091709
protected override Task WithPackingTestImpl()
17101710
{
1711-
const string InputContents = @"struct MyStruct {};";
1711+
const string InputContents = @"struct MyStruct
1712+
{
1713+
size_t FixedBuffer[1];
1714+
};
1715+
";
17121716

1713-
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1717+
const string ExpectedOutputContents = @"using System;
1718+
using System.Runtime.InteropServices;
17141719
17151720
namespace ClangSharp.Test
17161721
{
17171722
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
17181723
public partial struct MyStruct
17191724
{
1725+
[NativeTypeName(""size_t[1]"")]
1726+
public _FixedBuffer_e__FixedBuffer FixedBuffer;
1727+
1728+
public partial struct _FixedBuffer_e__FixedBuffer
1729+
{
1730+
public nuint e0;
1731+
1732+
public ref nuint this[int index]
1733+
{
1734+
get
1735+
{
1736+
return ref AsSpan(int.MaxValue)[index];
1737+
}
1738+
}
1739+
1740+
public Span<nuint> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
1741+
}
17201742
}
17211743
}
17221744
";

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

+27-2
Original file line numberDiff line numberDiff line change
@@ -1730,15 +1730,40 @@ public partial struct MyStruct3
17301730

17311731
protected override Task WithPackingTestImpl()
17321732
{
1733-
const string InputContents = @"struct MyStruct {};";
1733+
const string InputContents = @"struct MyStruct
1734+
{
1735+
size_t FixedBuffer[1];
1736+
};
1737+
";
17341738

1735-
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1739+
const string ExpectedOutputContents = @"using System;
1740+
using System.Diagnostics.CodeAnalysis;
1741+
using System.Runtime.InteropServices;
17361742
17371743
namespace ClangSharp.Test
17381744
{
17391745
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
17401746
public partial struct MyStruct
17411747
{
1748+
[NativeTypeName(""size_t[1]"")]
1749+
public _FixedBuffer_e__FixedBuffer FixedBuffer;
1750+
1751+
public partial struct _FixedBuffer_e__FixedBuffer
1752+
{
1753+
public nuint e0;
1754+
1755+
[UnscopedRef]
1756+
public ref nuint this[int index]
1757+
{
1758+
get
1759+
{
1760+
return ref AsSpan(int.MaxValue)[index];
1761+
}
1762+
}
1763+
1764+
[UnscopedRef]
1765+
public Span<nuint> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
1766+
}
17421767
}
17431768
}
17441769
";

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

+27-2
Original file line numberDiff line numberDiff line change
@@ -1734,15 +1734,40 @@ public partial struct MyStruct3
17341734

17351735
protected override Task WithPackingTestImpl()
17361736
{
1737-
const string InputContents = @"struct MyStruct {};";
1737+
const string InputContents = @"struct MyStruct
1738+
{
1739+
size_t FixedBuffer[1];
1740+
};
1741+
";
17381742

1739-
const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1743+
const string ExpectedOutputContents = @"using System;
1744+
using System.Diagnostics.CodeAnalysis;
1745+
using System.Runtime.InteropServices;
17401746
17411747
namespace ClangSharp.Test
17421748
{
17431749
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
17441750
public partial struct MyStruct
17451751
{
1752+
[NativeTypeName(""size_t[1]"")]
1753+
public _FixedBuffer_e__FixedBuffer FixedBuffer;
1754+
1755+
public partial struct _FixedBuffer_e__FixedBuffer
1756+
{
1757+
public nuint e0;
1758+
1759+
[UnscopedRef]
1760+
public ref nuint this[int index]
1761+
{
1762+
get
1763+
{
1764+
return ref AsSpan(int.MaxValue)[index];
1765+
}
1766+
}
1767+
1768+
[UnscopedRef]
1769+
public Span<nuint> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
1770+
}
17461771
}
17471772
}
17481773
";

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

+27-2
Original file line numberDiff line numberDiff line change
@@ -1727,12 +1727,37 @@ struct MyStruct3
17271727

17281728
protected override Task WithPackingTestImpl()
17291729
{
1730-
const string InputContents = @"struct MyStruct {};";
1730+
const string InputContents = @"struct MyStruct
1731+
{
1732+
size_t FixedBuffer[1];
1733+
};
1734+
";
17311735

17321736
const string ExpectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
17331737
<bindings>
17341738
<namespace name=""ClangSharp.Test"">
1735-
<struct name=""MyStruct"" access=""public"" layout=""Sequential"" pack=""CustomPackValue""></struct>
1739+
<struct name=""MyStruct"" access=""public"" layout=""Sequential"" pack=""CustomPackValue"">
1740+
<field name=""FixedBuffer"" access=""public"">
1741+
<type native=""size_t[1]"" count=""1"" fixed=""_FixedBuffer_e__FixedBuffer"">UIntPtr</type>
1742+
</field>
1743+
<struct name=""_FixedBuffer_e__FixedBuffer"" access=""public"">
1744+
<field name=""e0"" access=""public"">
1745+
<type>UIntPtr</type>
1746+
</field>
1747+
<indexer access=""public"" unsafe=""true"">
1748+
<type>ref UIntPtr</type>
1749+
<param name=""index"">
1750+
<type>int</type>
1751+
</param>
1752+
<get>
1753+
<code>fixed (UIntPtr* pThis = &amp;e0)
1754+
{
1755+
return ref pThis[index];
1756+
}</code>
1757+
</get>
1758+
</indexer>
1759+
</struct>
1760+
</struct>
17361761
</namespace>
17371762
</bindings>
17381763
";

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

+27-2
Original file line numberDiff line numberDiff line change
@@ -1732,12 +1732,37 @@ struct MyStruct3
17321732

17331733
protected override Task WithPackingTestImpl()
17341734
{
1735-
const string InputContents = @"struct MyStruct {};";
1735+
const string InputContents = @"struct MyStruct
1736+
{
1737+
size_t FixedBuffer[1];
1738+
};
1739+
";
17361740

17371741
const string ExpectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
17381742
<bindings>
17391743
<namespace name=""ClangSharp.Test"">
1740-
<struct name=""MyStruct"" access=""public"" layout=""Sequential"" pack=""CustomPackValue""></struct>
1744+
<struct name=""MyStruct"" access=""public"" layout=""Sequential"" pack=""CustomPackValue"">
1745+
<field name=""FixedBuffer"" access=""public"">
1746+
<type native=""size_t[1]"" count=""1"" fixed=""_FixedBuffer_e__FixedBuffer"">UIntPtr</type>
1747+
</field>
1748+
<struct name=""_FixedBuffer_e__FixedBuffer"" access=""public"">
1749+
<field name=""e0"" access=""public"">
1750+
<type>UIntPtr</type>
1751+
</field>
1752+
<indexer access=""public"" unsafe=""true"">
1753+
<type>ref UIntPtr</type>
1754+
<param name=""index"">
1755+
<type>int</type>
1756+
</param>
1757+
<get>
1758+
<code>fixed (UIntPtr* pThis = &amp;e0)
1759+
{
1760+
return ref pThis[index];
1761+
}</code>
1762+
</get>
1763+
</indexer>
1764+
</struct>
1765+
</struct>
17411766
</namespace>
17421767
</bindings>
17431768
";

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

+31-2
Original file line numberDiff line numberDiff line change
@@ -1707,12 +1707,41 @@ struct MyStruct3
17071707

17081708
protected override Task WithPackingTestImpl()
17091709
{
1710-
const string InputContents = @"struct MyStruct {};";
1710+
const string InputContents = @"struct MyStruct
1711+
{
1712+
size_t FixedBuffer[1];
1713+
};
1714+
";
17111715

17121716
const string ExpectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
17131717
<bindings>
17141718
<namespace name=""ClangSharp.Test"">
1715-
<struct name=""MyStruct"" access=""public"" layout=""Sequential"" pack=""CustomPackValue""></struct>
1719+
<struct name=""MyStruct"" access=""public"" layout=""Sequential"" pack=""CustomPackValue"">
1720+
<field name=""FixedBuffer"" access=""public"">
1721+
<type native=""size_t[1]"" count=""1"" fixed=""_FixedBuffer_e__FixedBuffer"">nuint</type>
1722+
</field>
1723+
<struct name=""_FixedBuffer_e__FixedBuffer"" access=""public"">
1724+
<field name=""e0"" access=""public"">
1725+
<type>nuint</type>
1726+
</field>
1727+
<indexer access=""public"">
1728+
<type>ref nuint</type>
1729+
<param name=""index"">
1730+
<type>int</type>
1731+
</param>
1732+
<get>
1733+
<code>return ref AsSpan(int.MaxValue)[index];</code>
1734+
</get>
1735+
</indexer>
1736+
<function name=""AsSpan"" access=""public"">
1737+
<type>Span&lt;nuint&gt;</type>
1738+
<param name=""length"">
1739+
<type>int</type>
1740+
</param>
1741+
<code>MemoryMarshal.CreateSpan(ref e0, length);</code>
1742+
</function>
1743+
</struct>
1744+
</struct>
17161745
</namespace>
17171746
</bindings>
17181747
";

0 commit comments

Comments
 (0)