Viewing is open to everyone. Downloading and starring need a GitHub sign-in.
Sign in with GitHub
StructLayoutTests.cs
v0.1.0-build.85
Latest
Commit ede38f5
Sign in with GitHub to download. Each download is recorded with your GitHub username.
| 1 | using System; |
| 2 | using System.Runtime.InteropServices; |
| 3 | using OpenCKey.Interop; |
| 4 | using Xunit; |
| 5 | |
| 6 | namespace OpenCKey.Tests |
| 7 | { |
| 8 | // The expected numbers come from sdk/dotnet/native/tools/layout_probe.c |
| 9 | // (recorded in layout_expected.txt) on 64-bit ABIs. |
| 10 | public unsafe class StructLayoutTests |
| 11 | { |
| 12 | private static int Off<T>(string field) => (int)Marshal.OffsetOf<T>(field); |
| 13 | |
| 14 | [Fact] |
| 15 | public void RunsOn64Bit() => Assert.Equal(8, IntPtr.Size); |
| 16 | |
| 17 | [Fact] |
| 18 | public void Sizes() |
| 19 | { |
| 20 | Assert.Equal(112, Marshal.SizeOf<NativeDiagnostics>()); |
| 21 | Assert.Equal(8216, Marshal.SizeOf<NativeScalableSymbol>()); |
| 22 | Assert.Equal(3, Marshal.SizeOf<NativeRgb>()); |
| 23 | Assert.Equal(96, Marshal.SizeOf<NativeStyle>()); |
| 24 | Assert.Equal(24, Marshal.SizeOf<NativeLogoImage>()); |
| 25 | Assert.Equal(48, Marshal.SizeOf<NativeRasterOptions>()); |
| 26 | Assert.Equal(40, Marshal.SizeOf<NativeBackdrop>()); |
| 27 | Assert.Equal(48, Marshal.SizeOf<NativeScanModel>()); |
| 28 | Assert.Equal(304, Marshal.SizeOf<NativeCertification>()); |
| 29 | Assert.Equal(96, Marshal.SizeOf<NativeTelemetryHistogram>()); |
| 30 | Assert.Equal(264, Marshal.SizeOf<NativeTelemetryCounters>()); |
| 31 | // The blittable (unmanaged) size the P/Invokes actually use agrees. |
| 32 | Assert.Equal(112, sizeof(NativeDiagnostics)); |
| 33 | Assert.Equal(8216, sizeof(NativeScalableSymbol)); |
| 34 | Assert.Equal(96, sizeof(NativeStyle)); |
| 35 | Assert.Equal(48, sizeof(NativeRasterOptions)); |
| 36 | Assert.Equal(40, sizeof(NativeBackdrop)); |
| 37 | Assert.Equal(48, sizeof(NativeScanModel)); |
| 38 | Assert.Equal(304, sizeof(NativeCertification)); |
| 39 | Assert.Equal(264, sizeof(NativeTelemetryCounters)); |
| 40 | } |
| 41 | |
| 42 | [Fact] |
| 43 | public void DiagnosticsAndSymbolOffsets() |
| 44 | { |
| 45 | Assert.Equal(4, Off<NativeDiagnostics>(nameof(NativeDiagnostics.Status))); |
| 46 | Assert.Equal(16, Off<NativeDiagnostics>(nameof(NativeDiagnostics.Message))); |
| 47 | Assert.Equal(20, Off<NativeScalableSymbol>(nameof(NativeScalableSymbol.CodewordLength))); |
| 48 | Assert.Equal(24, Off<NativeScalableSymbol>(nameof(NativeScalableSymbol.Codeword))); |
| 49 | } |
| 50 | |
| 51 | [Fact] |
| 52 | public void StyleOffsets() |
| 53 | { |
| 54 | Assert.Equal(3, Off<NativeStyle>(nameof(NativeStyle.BackgroundEdge))); |
| 55 | Assert.Equal(6, Off<NativeStyle>(nameof(NativeStyle.Ink))); |
| 56 | Assert.Equal(9, Off<NativeStyle>(nameof(NativeStyle.InkShade))); |
| 57 | Assert.Equal(12, Off<NativeStyle>(nameof(NativeStyle.Accent0))); |
| 58 | Assert.Equal(21, Off<NativeStyle>(nameof(NativeStyle.Accent3))); |
| 59 | Assert.Equal(24, Off<NativeStyle>(nameof(NativeStyle.AccentCount))); |
| 60 | Assert.Equal(28, Off<NativeStyle>(nameof(NativeStyle.AccentPercent))); |
| 61 | Assert.Equal(32, Off<NativeStyle>(nameof(NativeStyle.Modules))); |
| 62 | Assert.Equal(36, Off<NativeStyle>(nameof(NativeStyle.Rings))); |
| 63 | Assert.Equal(40, Off<NativeStyle>(nameof(NativeStyle.Rays))); |
| 64 | Assert.Equal(48, Off<NativeStyle>(nameof(NativeStyle.Bevel))); |
| 65 | Assert.Equal(56, Off<NativeStyle>(nameof(NativeStyle.Shadow))); |
| 66 | Assert.Equal(64, Off<NativeStyle>(nameof(NativeStyle.Texture))); |
| 67 | Assert.Equal(72, Off<NativeStyle>(nameof(NativeStyle.LogoHref))); |
| 68 | Assert.Equal(80, Off<NativeStyle>(nameof(NativeStyle.LogoRadius))); |
| 69 | Assert.Equal(88, Off<NativeStyle>(nameof(NativeStyle.LogoPlate))); |
| 70 | Assert.Equal(92, Off<NativeStyle>(nameof(NativeStyle.Policy))); |
| 71 | } |
| 72 | |
| 73 | [Fact] |
| 74 | public void RasterBackdropModelCertificationOffsets() |
| 75 | { |
| 76 | Assert.Equal(16, Off<NativeLogoImage>(nameof(NativeLogoImage.Stride))); |
| 77 | Assert.Equal(20, Off<NativeRasterOptions>(nameof(NativeRasterOptions.Supersample))); |
| 78 | Assert.Equal(24, Off<NativeRasterOptions>(nameof(NativeRasterOptions.MinFeaturePx))); |
| 79 | Assert.Equal(32, Off<NativeRasterOptions>(nameof(NativeRasterOptions.Materials))); |
| 80 | Assert.Equal(40, Off<NativeRasterOptions>(nameof(NativeRasterOptions.Logo))); |
| 81 | Assert.Equal(8, Off<NativeBackdrop>(nameof(NativeBackdrop.ColourCount))); |
| 82 | Assert.Equal(16, Off<NativeBackdrop>(nameof(NativeBackdrop.Rgba))); |
| 83 | Assert.Equal(24, Off<NativeBackdrop>(nameof(NativeBackdrop.Width))); |
| 84 | Assert.Equal(32, Off<NativeBackdrop>(nameof(NativeBackdrop.Stride))); |
| 85 | Assert.Equal(8, Off<NativeScanModel>(nameof(NativeScanModel.PxPerModule))); |
| 86 | Assert.Equal(40, Off<NativeScanModel>(nameof(NativeScanModel.Trials))); |
| 87 | Assert.Equal(24, Off<NativeCertification>(nameof(NativeCertification.MinContrast))); |
| 88 | Assert.Equal(40, Off<NativeCertification>(nameof(NativeCertification.LogoLoad))); |
| 89 | Assert.Equal(48, Off<NativeCertification>(nameof(NativeCertification.Message))); |
| 90 | } |
| 91 | |
| 92 | [Fact] |
| 93 | public void TelemetryOffsets() |
| 94 | { |
| 95 | Assert.Equal(16, Off<NativeTelemetryHistogram>(nameof(NativeTelemetryHistogram.Buckets))); |
| 96 | Assert.Equal(32, Off<NativeTelemetryCounters>(nameof(NativeTelemetryCounters.Decoded))); |
| 97 | Assert.Equal(72, Off<NativeTelemetryCounters>(nameof(NativeTelemetryCounters.TimeToDecodeMs))); |
| 98 | Assert.Equal(168, Off<NativeTelemetryCounters>(nameof(NativeTelemetryCounters.FrameMs))); |
| 99 | } |
| 100 | |
| 101 | [Fact] |
| 102 | public void NativeAbiMatches() |
| 103 | { |
| 104 | Assert.Equal((int)NativeConstants.AbiVersion, CKey.AbiVersion); |
| 105 | } |
| 106 | } |
| 107 | } |