Skip to content

Commit

Permalink
Add test for unpacked boolean arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Davipb committed Mar 18, 2017
1 parent f2af2ac commit ff1e13c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
21 changes: 21 additions & 0 deletions BinarySerializer.Test/PackedBoolean/PackedBooleanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ public void AddsNewItemsOnFixedSize()
CheckSequence(expectedLength, result.ConstantLengthArray);
}

[TestMethod]
public void DoesntAffectUnpackedBooleanArrays()
{
var original = new UnpackedBooleanClass
{
UnpackedArray = new[] { true, true, false, false, true, true }
};

var expected = new byte[] { 6, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 };
var actual = Serialize(original);

CheckSequence(expected, actual);

var deserialized = Deserialize<UnpackedBooleanClass>(actual);

Assert.AreEqual(original.UnpackedArray.Length, deserialized.UnpackedArrayLength, "Invalid length binding on unpacked boolean array.");
Assert.AreEqual(original.UnpackedArray.Length, deserialized.UnpackedArrayCount, "Invalid count binding on unpacked boolean array.");

CheckSequence(original.UnpackedArray, deserialized.UnpackedArray);
}

private void CheckSequence<T>(IEnumerable<T> expected, IEnumerable<T> actual)
{
Assert.AreEqual(expected.Count(), actual.Count(), "Incorrect length");
Expand Down
16 changes: 16 additions & 0 deletions BinarySerializer.Test/PackedBoolean/UnpackedBooleanClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace BinarySerialization.Test.PackedBoolean
{
public class UnpackedBooleanClass
{
[FieldOrder(0)] public long UnpackedArrayCount { get; set; }
[FieldOrder(1)] public long UnpackedArrayLength { get; set; }

[FieldCount(nameof(UnpackedArrayCount)), FieldLength(nameof(UnpackedArrayLength))]
[FieldOrder(2)]
public bool[] UnpackedArray { get; set; }
}
}

0 comments on commit ff1e13c

Please sign in to comment.