Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 45 additions & 41 deletions tests-unity/UnityCompatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#pragma warning disable CEK005 // Collection expressions must be empty

// This project compiles every successful public wire shape against netstandard2.1; diagnostic failures remain test-project cases because they intentionally prevent compilation.
var fixedPacket = new FixedPacket
FixedPacket fixedPacket = new FixedPacket
{
BooleanValue = true,
ByteValue = 0xAB,
Expand All @@ -29,9 +29,9 @@
State = PacketState.Ready,
Position = new PackedPosition { X = 10, Y = 20 },
};
var fixedBuffer = new byte[FixedPacketView.RequiredByteLength];
byte[] fixedBuffer = new byte[FixedPacketView.RequiredByteLength];
int fixedWrittenByteCount = fixedPacket.Serialize(fixedBuffer);
var fixedView = new FixedPacketView(fixedBuffer);
FixedPacketView fixedView = new FixedPacketView(fixedBuffer);

RequireCondition(
fixedWrittenByteCount == FixedPacketView.RequiredByteLength
Expand Down Expand Up @@ -59,22 +59,22 @@
&& fixedSerializedMemory.Length == FixedPacketView.RequiredByteLength,
"Fixed-size View conversion did not expose its exact serialized region.");

var packedPacket = new PackedPacket
PackedPacket packedPacket = new PackedPacket
{
Identifier = 42,
Position = new PackedPosition { X = -10, Y = 20 },
};
var packedBuffer = new byte[PackedPacketView.RequiredByteLength];
byte[] packedBuffer = new byte[PackedPacketView.RequiredByteLength];
int packedWrittenByteCount = packedPacket.Serialize(packedBuffer);
var packedView = new PackedPacketView(packedBuffer);
PackedPacketView packedView = new PackedPacketView(packedBuffer);
RequireCondition(
packedWrittenByteCount == PackedPacketView.RequiredByteLength
&& packedView.Identifier == packedPacket.Identifier
&& packedView.Position.X == packedPacket.Position.X
&& packedView.Position.Y == packedPacket.Position.Y,
"Root Blittable Struct did not match its source.");

var variablePacket = new VariablePacket
VariablePacket variablePacket = new VariablePacket
{
Name = "unity",
EmptyName = string.Empty,
Expand All @@ -97,9 +97,9 @@
FloatValues = [1.5f, 2.5f, 3.5f],
DoubleValues = [1.25, 2.25, 3.25],
};
var variableBuffer = new byte[1024];
byte[] variableBuffer = new byte[1024];
int variableWrittenByteCount = variablePacket.Serialize(variableBuffer);
var variableView = new VariablePacketView(variableBuffer.AsMemory(0, variableWrittenByteCount));
VariablePacketView variableView = new VariablePacketView(variableBuffer.AsMemory(0, variableWrittenByteCount));

RequireCondition(
VariablePacketView.RequiredByteLength < 0
Expand Down Expand Up @@ -147,26 +147,26 @@
&& BinaryPrimitives.ReadInt32LittleEndian(variableSerializedData.Slice(17 * sizeof(int), sizeof(int))) == 0,
"Null payloads were not represented by zero property offsets.");

var ignoredMembersPacket = new IgnoredMembersPacket(7, 8, 9) { IgnoredField = 10 };
var ignoredMembersBuffer = new byte[IgnoredMembersPacketView.RequiredByteLength];
ignoredMembersPacket.Serialize(ignoredMembersBuffer);
var ignoredMembersView = new IgnoredMembersPacketView(ignoredMembersBuffer);
IgnoredMembersPacket ignoredMembersPacket = new IgnoredMembersPacket(7, 8, 9) { IgnoredField = 10 };
byte[] ignoredMembersBuffer = new byte[IgnoredMembersPacketView.RequiredByteLength];
int ignoredMembersWritten = ignoredMembersPacket.Serialize(ignoredMembersBuffer);
IgnoredMembersPacketView ignoredMembersView = new IgnoredMembersPacketView(ignoredMembersBuffer);
RequireCondition(
ignoredMembersView.Included == 7
ignoredMembersWritten == 16 && ignoredMembersView.Included == 7
&& ignoredMembersView.PrivateSetter == 8
&& typeof(IgnoredMembersPacketView).GetProperties().Length == 2
&& typeof(IgnoredMembersPacketView).GetProperty(nameof(IgnoredMembersPacket.Included)) is not null
&& typeof(IgnoredMembersPacketView).GetProperty(nameof(IgnoredMembersPacket.PrivateSetter)) is not null,
"Ignored properties, indexers, setters, or non-public getters changed the generated View.");

var namespacedPacket = new UnityCompatibilityModels.NamespacedPacket { Identifier = 11 };
var namespacedBuffer = new byte[UnityCompatibilityModels.NamespacedPacketView.RequiredByteLength];
namespacedPacket.Serialize(namespacedBuffer);
var namespacedView = new UnityCompatibilityModels.NamespacedPacketView(namespacedBuffer);
RequireCondition(namespacedView.Identifier == namespacedPacket.Identifier, "Namespace-local generation failed.");
UnityCompatibilityModels.NamespacedPacket namespacedPacket = new UnityCompatibilityModels.NamespacedPacket { Identifier = 11 };
byte[] namespacedBuffer = new byte[UnityCompatibilityModels.NamespacedPacketView.RequiredByteLength];
int namespacedWritten = namespacedPacket.Serialize(namespacedBuffer);
UnityCompatibilityModels.NamespacedPacketView namespacedView = new UnityCompatibilityModels.NamespacedPacketView(namespacedBuffer);
RequireCondition(namespacedWritten == 8 && namespacedView.Identifier == namespacedPacket.Identifier, "Namespace-local generation failed.");

var emptyClassBuffer = Span<byte>.Empty;
var emptyStructBuffer = Span<byte>.Empty;
Span<byte> emptyClassBuffer = Span<byte>.Empty;
Span<byte> emptyStructBuffer = Span<byte>.Empty;
RequireCondition(
new EmptyClassPacket().Serialize(emptyClassBuffer) == 0
&& new EmptyStructPacket().Serialize(emptyStructBuffer) == 0
Expand All @@ -175,32 +175,34 @@
"Empty serializable types did not remain zero length.");

// Record class roundtrip verification
var recordObj = new UnitySimpleCsharpRecord { IntValue = 55, DoubleValue = 99.9 };
var recordBuffer = new byte[128];
UnitySimpleCsharpRecord recordObj = new UnitySimpleCsharpRecord { IntValue = 55, DoubleValue = 99.9 };
byte[] recordBuffer = new byte[128];
int recordWritten = recordObj.Serialize(recordBuffer);
var recordView = new UnitySimpleCsharpRecordView(recordBuffer);
UnitySimpleCsharpRecordView recordView = new UnitySimpleCsharpRecordView(recordBuffer);
RequireCondition(
recordView.IntValue == 55
recordWritten == 20
&& recordView.IntValue == 55
&& recordView.DoubleValue == 99.9
&& !UnitySimpleCsharpRecordView.IsBlittable,
"UnitySimpleCsharpRecord did not match its source or IsBlittable was incorrect.");

// Record struct roundtrip verification
var recordStructObj = new UnitySimpleRecordStruct { IntValue = 66, DoubleValue = 88.8 };
var recordStructBuffer = new byte[128];
UnitySimpleRecordStruct recordStructObj = new UnitySimpleRecordStruct { IntValue = 66, DoubleValue = 88.8 };
byte[] recordStructBuffer = new byte[128];
int recordStructWritten = recordStructObj.Serialize(recordStructBuffer);
var recordStructView = new UnitySimpleRecordStructView(recordStructBuffer);
UnitySimpleRecordStructView recordStructView = new UnitySimpleRecordStructView(recordStructBuffer);
RequireCondition(
recordStructView.IntValue == 66
recordStructWritten == 20
&& recordStructView.IntValue == 66
&& recordStructView.DoubleValue == 88.8
&& !UnitySimpleRecordStructView.IsBlittable,
"UnitySimpleRecordStruct did not match its source or IsBlittable was incorrect.");

// Blittable record struct layout verification
var blittableRecordStructObj = new UnitySimpleBlittableRecordStruct { IntValue = 77, DoubleValue = 77.7 };
var blittableRecordStructBuffer = new byte[UnitySimpleBlittableRecordStructView.RequiredByteLength];
UnitySimpleBlittableRecordStruct blittableRecordStructObj = new UnitySimpleBlittableRecordStruct { IntValue = 77, DoubleValue = 77.7 };
byte[] blittableRecordStructBuffer = new byte[UnitySimpleBlittableRecordStructView.RequiredByteLength];
int blittableRecordStructWritten = blittableRecordStructObj.Serialize(blittableRecordStructBuffer);
var blittableRecordStructView = new UnitySimpleBlittableRecordStructView(blittableRecordStructBuffer);
UnitySimpleBlittableRecordStructView blittableRecordStructView = new UnitySimpleBlittableRecordStructView(blittableRecordStructBuffer);
RequireCondition(
blittableRecordStructView.IntValue == 77
&& blittableRecordStructView.DoubleValue == 77.7
Expand All @@ -210,19 +212,20 @@
"UnitySimpleBlittableRecordStruct did not match its source or IsBlittable was incorrect.");

// Nested blittable record struct container verification
var firstRecord = new UnitySimpleBlittableRecordStruct { IntValue = 88, DoubleValue = 88.88 };
var secondRecord = new UnitySimpleBlittableRecordStruct { IntValue = 99, DoubleValue = 99.99 };
var nestedBlittableRecordContainer = new UnityBlittableRecordStructContainer
UnitySimpleBlittableRecordStruct firstRecord = new UnitySimpleBlittableRecordStruct { IntValue = 88, DoubleValue = 88.88 };
UnitySimpleBlittableRecordStruct secondRecord = new UnitySimpleBlittableRecordStruct { IntValue = 99, DoubleValue = 99.99 };
UnityBlittableRecordStructContainer nestedBlittableRecordContainer = new UnityBlittableRecordStructContainer
{
Value = firstRecord,
OptionalValue = secondRecord,
Values = [firstRecord, secondRecord],
};
var nestedBlittableRecordBuffer = new byte[256];
byte[] nestedBlittableRecordBuffer = new byte[256];
int nestedBlittableRecordWritten = nestedBlittableRecordContainer.Serialize(nestedBlittableRecordBuffer);
var nestedBlittableRecordView = new UnityBlittableRecordStructContainerView(nestedBlittableRecordBuffer.AsMemory(0, nestedBlittableRecordWritten));
UnityBlittableRecordStructContainerView nestedBlittableRecordView = new UnityBlittableRecordStructContainerView(nestedBlittableRecordBuffer.AsMemory(0, nestedBlittableRecordWritten));
RequireCondition(
nestedBlittableRecordView.Value.IntValue == 88
nestedBlittableRecordWritten == 64
&& nestedBlittableRecordView.Value.IntValue == 88
&& nestedBlittableRecordView.Value.DoubleValue == 88.88
&& nestedBlittableRecordView.OptionalValue!.Value.IntValue == 99
&& nestedBlittableRecordView.OptionalValue!.Value.DoubleValue == 99.99
Expand All @@ -234,16 +237,17 @@
&& nestedBlittableRecordView.GetByteLength() == nestedBlittableRecordWritten,
"UnityBlittableRecordStructContainer non-null roundtrip failed.");

var nestedBlittableRecordNullsContainer = new UnityBlittableRecordStructContainer
UnityBlittableRecordStructContainer nestedBlittableRecordNullsContainer = new UnityBlittableRecordStructContainer
{
Value = firstRecord,
OptionalValue = null,
Values = null,
};
int nestedBlittableRecordNullsWritten = nestedBlittableRecordNullsContainer.Serialize(nestedBlittableRecordBuffer);
var nestedBlittableRecordNullsView = new UnityBlittableRecordStructContainerView(nestedBlittableRecordBuffer.AsMemory(0, nestedBlittableRecordNullsWritten));
UnityBlittableRecordStructContainerView nestedBlittableRecordNullsView = new UnityBlittableRecordStructContainerView(nestedBlittableRecordBuffer.AsMemory(0, nestedBlittableRecordNullsWritten));
RequireCondition(
nestedBlittableRecordNullsView.Value.IntValue == 88
nestedBlittableRecordNullsWritten == 24
&& nestedBlittableRecordNullsView.Value.IntValue == 88
&& nestedBlittableRecordNullsView.Value.DoubleValue == 88.88
&& nestedBlittableRecordNullsView.OptionalValue is null
&& nestedBlittableRecordNullsView.Values.IsEmpty
Expand Down Expand Up @@ -271,7 +275,7 @@
{
public bool BooleanValue { get; init; }

public byte ByteValue { get; init; }

Check warning on line 278 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

Struct 'FixedPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 278 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Release)

Struct 'FixedPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 278 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

Struct 'FixedPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 278 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

Struct 'FixedPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 278 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

Struct 'FixedPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 278 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

Struct 'FixedPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

public sbyte SignedByteValue { get; init; }

Expand Down Expand Up @@ -406,13 +410,13 @@
}

[ZeroSerializer(EmitShapeTag = true)]
public struct EmptyStructPacket

Check warning on line 413 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 413 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Release)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 413 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 413 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 413 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 413 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'
{
}

namespace UnityCompatibilityModels
{

Check warning on line 418 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 418 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Release)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 418 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 418 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 418 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 418 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'
[ZeroSerializer]

Check warning on line 419 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

Struct 'EmptyStructPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 419 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Release)

Struct 'EmptyStructPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 419 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

Struct 'EmptyStructPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 419 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

Struct 'EmptyStructPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 419 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

Struct 'EmptyStructPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 419 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

Struct 'EmptyStructPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization
public sealed class NamespacedPacket
{
public int Identifier { get; init; }
Expand Down Expand Up @@ -449,7 +453,7 @@
public double DoubleValue { get; init; }
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]

Check warning on line 456 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

Struct 'UnitySimpleRecordStruct' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 456 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Release)

Struct 'UnitySimpleRecordStruct' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 456 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

Struct 'UnitySimpleRecordStruct' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 456 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

Struct 'UnitySimpleRecordStruct' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 456 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

Struct 'UnitySimpleRecordStruct' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 456 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

Struct 'UnitySimpleRecordStruct' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization
[ZeroSerializer]
public record struct UnitySimpleBlittableRecordStruct
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Diagnostics/CSharpSourceGeneratorVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class CSharpSourceGeneratorVerifier<TGenerator>
{
public static async Task VerifySourceGeneratorAsync(string source, params DiagnosticResult[] expected)
{
var test = new Test
Test test = new Test
{
TestState =
{
Expand Down
20 changes: 12 additions & 8 deletions tests/EnumTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}

[ZeroSerializer]
public readonly struct EnumStructContainer

Check warning on line 44 in tests/EnumTypeTests.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

Struct 'EnumStructContainer' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 44 in tests/EnumTypeTests.cs

View workflow job for this annotation

GitHub Actions / test (Release)

Struct 'EnumStructContainer' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization
{
public EnumStructContainer(
ByteBackedState byteState,
Expand Down Expand Up @@ -70,16 +70,18 @@
[Fact]
public void ClassViewPreservesDeclaredEnumTypes()
{
var source = new EnumClassContainer
EnumClassContainer source = new EnumClassContainer
{
ByteState = ByteBackedState.Complete,
IntMode = IntBackedMode.Passive,
UlongOptions = UlongBackedOptions.First | UlongBackedOptions.Audit,
};
var serializedData = new byte[EnumClassContainerView.RequiredByteLength];
byte[] serializedData = new byte[EnumClassContainerView.RequiredByteLength];

source.Serialize(serializedData);
var view = new EnumClassContainerView(serializedData);
int classWritten = source.Serialize(serializedData);
EnumClassContainerView view = new EnumClassContainerView(serializedData);

TestAssert.Equal(25, classWritten, nameof(classWritten));

// Direct assignments intentionally prevent generated getters from regressing to underlying integer types.
ByteBackedState byteState = view.ByteState;
Expand All @@ -94,14 +96,16 @@
[Fact]
public void StructViewPreservesDeclaredEnumTypes()
{
var source = new EnumStructContainer(
EnumStructContainer source = new EnumStructContainer(
ByteBackedState.Ready,
IntBackedMode.Active,
UlongBackedOptions.Second | UlongBackedOptions.Audit);
var serializedData = new byte[EnumStructContainerView.RequiredByteLength];
byte[] serializedData = new byte[EnumStructContainerView.RequiredByteLength];

int structWritten = source.Serialize(serializedData);
EnumStructContainerView view = new EnumStructContainerView(serializedData);

source.Serialize(serializedData);
var view = new EnumStructContainerView(serializedData);
TestAssert.Equal(25, structWritten, nameof(structWritten));

// Direct assignments intentionally prevent generated getters from regressing to underlying integer types.
ByteBackedState byteState = view.ByteState;
Expand Down
Loading
Loading