diff --git a/tests/LibHac.Tests/Common/Layout.cs b/tests/LibHac.Tests/Common/Layout.cs index 1a0cb743..dc1842ac 100644 --- a/tests/LibHac.Tests/Common/Layout.cs +++ b/tests/LibHac.Tests/Common/Layout.cs @@ -16,4 +16,17 @@ public class Layout return offset; } + + public static int AlignOf() where T : unmanaged + { + return Unsafe.SizeOf>() - Unsafe.SizeOf(); + } + + private readonly struct AlignOfHelper where T : unmanaged + { +#pragma warning disable CS0169 // Field is never used + private readonly byte _padding; + private readonly T _value; +#pragma warning restore CS0169 + } } \ No newline at end of file diff --git a/tests/LibHac.Tests/Fs/TypeLayoutTests.cs b/tests/LibHac.Tests/Fs/TypeLayoutTests.cs index 4a6ef886..5ac2ee69 100644 --- a/tests/LibHac.Tests/Fs/TypeLayoutTests.cs +++ b/tests/LibHac.Tests/Fs/TypeLayoutTests.cs @@ -1,5 +1,4 @@ using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using LibHac.Fs; using LibHac.Fs.Impl; using Xunit; @@ -476,21 +475,10 @@ public class TypeLayoutTests Assert.Equal(0, GetOffset(in s, in s.Value)); } - [StructLayout(LayoutKind.Sequential)] - private struct Int64AlignmentTest - { - public byte A; - public Int64 B; - } - [Fact] - public static void Int64Test_Layout() + public static void Int64_Layout() { - var s = new Int64AlignmentTest(); - - Assert.Equal(12, Unsafe.SizeOf()); - - Assert.Equal(0, GetOffset(in s, in s.A)); - Assert.Equal(4, GetOffset(in s, in s.B)); + Assert.Equal(8, Unsafe.SizeOf()); + Assert.Equal(4, AlignOf()); } } \ No newline at end of file diff --git a/tests/LibHac.Tests/FsSystem/TypeLayoutTests.cs b/tests/LibHac.Tests/FsSystem/TypeLayoutTests.cs index c344430e..1ff05b94 100644 --- a/tests/LibHac.Tests/FsSystem/TypeLayoutTests.cs +++ b/tests/LibHac.Tests/FsSystem/TypeLayoutTests.cs @@ -1,5 +1,4 @@ using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using LibHac.FsSystem; using Xunit; using static LibHac.Tests.Common.Layout; @@ -287,6 +286,7 @@ public class TypeLayoutTests HierarchicalIntegrityVerificationLevelInformation s = default; Assert.Equal(0x18, Unsafe.SizeOf()); + Assert.Equal(0x04, AlignOf()); Assert.Equal(0x00, GetOffset(in s, in s.Offset)); Assert.Equal(0x08, GetOffset(in s, in s.Size)); @@ -294,24 +294,6 @@ public class TypeLayoutTests Assert.Equal(0x14, GetOffset(in s, in s.Reserved)); } - [StructLayout(LayoutKind.Sequential)] - private struct HierarchicalIntegrityVerificationLevelInformationAlignmentTest - { - public byte A; - public HierarchicalIntegrityVerificationLevelInformation B; - } - - [Fact] - public static void HierarchicalIntegrityVerificationLevelInformation_Alignment() - { - var s = new HierarchicalIntegrityVerificationLevelInformationAlignmentTest(); - - Assert.Equal(0x1C, Unsafe.SizeOf()); - - Assert.Equal(0, GetOffset(in s, in s.A)); - Assert.Equal(4, GetOffset(in s, in s.B)); - } - [Fact] public static void HierarchicalIntegrityVerificationInformation_Layout() {