Browse Source

Fix typo and move alignment offsets to cpp file

pull/1535/head
josetr 5 years ago
parent
commit
f474a7327b
  1. 6
      tests/CSharp/CSharp.Tests.cs
  2. 22
      tests/CSharp/CSharp.cpp
  3. 25
      tests/CSharp/CSharp.h

6
tests/CSharp/CSharp.Tests.cs

@ -750,9 +750,9 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -750,9 +750,9 @@ public unsafe class CSharpTests : GeneratorTestFixture
Assert.That(Marshal.SizeOf(internalType), Is.EqualTo(internalType.StructLayoutAttribute.Size));
}
foreach (var (type, offsets) in new (Type, int[])[] {
foreach (var (type, offsets) in new (Type, uint[])[] {
(typeof(ClassCustomTypeAlignment), CSharp.CSharp.ClassCustomTypeAlignmentOffsets),
(typeof(ClassCustomObjectAligment), CSharp.CSharp.ClassCustomObjectAligmentOffsets),
(typeof(ClassCustomObjectAlignment), CSharp.CSharp.ClassCustomObjectAlignmentOffsets),
(typeof(ClassMicrosoftObjectAlignment), CSharp.CSharp.ClassMicrosoftObjectAlignmentOffsets),
})
{
@ -761,7 +761,7 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -761,7 +761,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
.SkipWhile(x => x.FieldType == typeof(IntPtr))
.Where(x => !x.Name.EndsWith("Padding"))
.Select(field => (int)Marshal.OffsetOf(internalType, field.Name));
.Select(field => (uint)Marshal.OffsetOf(internalType, field.Name));
Assert.That(managedOffsets, Is.EqualTo(offsets));
Assert.That(Marshal.SizeOf(internalType), Is.EqualTo(internalType.StructLayoutAttribute.Size));

22
tests/CSharp/CSharp.cpp

@ -1866,3 +1866,25 @@ ConversionFunctions::operator short() { return field; } @@ -1866,3 +1866,25 @@ ConversionFunctions::operator short() { return field; }
ConversionFunctions::operator const short*() const { return &field; }
ConversionFunctions::operator const short&() const { return field; }
ConversionFunctions::operator const short() const { return field; }
const unsigned ClassCustomTypeAlignmentOffsets[5]
{
offsetof(ClassCustomTypeAlignment, boolean),
offsetof(ClassCustomTypeAlignment, align16),
offsetof(ClassCustomTypeAlignment, align1),
offsetof(ClassCustomTypeAlignment, dbl),
offsetof(ClassCustomTypeAlignment, align8),
};
const unsigned ClassCustomObjectAlignmentOffsets[2] {
offsetof(ClassCustomObjectAlignment, boolean),
offsetof(ClassCustomObjectAlignment, charAligned8),
};
const unsigned ClassMicrosoftObjectAlignmentOffsets[4]
{
offsetof(ClassMicrosoftObjectAlignment, u8),
offsetof(ClassMicrosoftObjectAlignment, dbl),
offsetof(ClassMicrosoftObjectAlignment, i16),
offsetof(ClassMicrosoftObjectAlignment, boolean),
};

25
tests/CSharp/CSharp.h

@ -1482,25 +1482,12 @@ struct DLL_API ClassCustomTypeAlignment @@ -1482,25 +1482,12 @@ struct DLL_API ClassCustomTypeAlignment
Align8 align8;
};
static constexpr const int ClassCustomTypeAlignmentOffsets[] {
offsetof(ClassCustomTypeAlignment, boolean),
offsetof(ClassCustomTypeAlignment, align16),
offsetof(ClassCustomTypeAlignment, align1),
offsetof(ClassCustomTypeAlignment, dbl),
offsetof(ClassCustomTypeAlignment, align8),
};
struct DLL_API ClassCustomObjectAligment
struct DLL_API ClassCustomObjectAlignment
{
bool boolean;
alignas(alignof(ClassCustomTypeAlignment)) char charAligned8;
};
static constexpr const int ClassCustomObjectAligmentOffsets[] {
offsetof(ClassCustomObjectAligment, boolean),
offsetof(ClassCustomObjectAligment, charAligned8),
};
struct DLL_API ClassMicrosoftObjectAlignmentBase
{
uint8_t u8;
@ -1514,13 +1501,9 @@ struct DLL_API ClassMicrosoftObjectAlignment : ClassMicrosoftObjectAlignmentBase @@ -1514,13 +1501,9 @@ struct DLL_API ClassMicrosoftObjectAlignment : ClassMicrosoftObjectAlignmentBase
bool boolean;
};
static constexpr const int ClassMicrosoftObjectAlignmentOffsets[]
{
offsetof(ClassMicrosoftObjectAlignment, u8),
offsetof(ClassMicrosoftObjectAlignment, dbl),
offsetof(ClassMicrosoftObjectAlignment, i16),
offsetof(ClassMicrosoftObjectAlignment, boolean),
};
DLL_API extern const unsigned ClassCustomTypeAlignmentOffsets[5];
DLL_API extern const unsigned ClassCustomObjectAlignmentOffsets[2];
DLL_API extern const unsigned ClassMicrosoftObjectAlignmentOffsets[4];
DLL_API const char* TestCSharpString(const char* in, CS_OUT const char** out);
DLL_API const wchar_t* TestCSharpStringWide(const wchar_t* in, CS_OUT const wchar_t** out);

Loading…
Cancel
Save