Skip to content

Commit

Permalink
fix/test IndicatorComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
akopetsch committed Jun 17, 2024
1 parent 5695da4 commit ef976e0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class IndicatorAttributeTest(ITestOutputHelper testOutputHelper) :
{
#region Fields

private static readonly byte[] TestBytes =
private static readonly byte[] Indicated_TestBytes =
HexStringConverter.ToByteArray("41 58747261 42 43"); // 'A', 'Xtra', 'B', C'

private static readonly IndicatorTestClass TestObject = new()
private static readonly IndicatorTestClass Indicated_TestObject = new()
{
Byte0 = (byte)'A',
Bar = new IndicatorTestClass2()
Expand All @@ -25,19 +25,38 @@ public class IndicatorAttributeTest(ITestOutputHelper testOutputHelper) :
},
};

private static readonly byte[] NotIndicated_TestBytes =
HexStringConverter.ToByteArray("41"); // 'A'

private static readonly IndicatorTestClass NotIndicated_TestObject = new()
{
Byte0 = (byte)'A',
Bar = null,
};

#endregion

#region Methods

[Fact]
public void Test_Deserialization() =>
public void Test_Indicated_Deserialization() =>
AssertDeserializedObject(
Indicated_TestObject, Indicated_TestBytes, Endianness.BigEndian);

[Fact]
public void Test_Indicated_Serialization() =>
AssertSerializedObject(
Indicated_TestBytes, Indicated_TestObject, Endianness.BigEndian);

[Fact]
public void Test_NotIndicated_Deserialization() =>
AssertDeserializedObject(
TestObject, TestBytes, Endianness.BigEndian);
NotIndicated_TestObject, [ 0x41, 0, 0, 0, 0], Endianness.BigEndian); // FIXME: testBytes

[Fact]
public void Test_Serialization() =>
public void Test_NotIndicated_Serialization() =>
AssertSerializedObject(
TestBytes, TestObject, Endianness.BigEndian);
NotIndicated_TestBytes, NotIndicated_TestObject, Endianness.BigEndian);

#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ public class IndicatorComponent : AttributeComponent<IndicatorAttribute>, ICondi
protected override void OnInitialized()
{
base.OnInitialized();
Node.OnSerializing += WriteIndicator;
Node.OnSerializing += WriteIndicatorIfNotNull;
}

private void WriteIndicator() =>
Writer.Write(Attribute.Value);
private void WriteIndicatorIfNotNull()
{
if (Node.Value != null)
Writer.Write(Attribute.Value);
}

public bool IsSerialized(Node node) =>
Reader.TryRead(Attribute.Value);
Expand Down
1 change: 0 additions & 1 deletion ByteSerialization/IO/EndianBinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ByteSerialization.IO
{
Expand Down

0 comments on commit ef976e0

Please sign in to comment.