Skip to content

Commit 8e88663

Browse files
committed
Add test for unpacked boolean arrays
1 parent 21dba68 commit 8e88663

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

BinarySerializer.Test/PackedBoolean/PackedBooleanTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,27 @@ public void AddsNewItemsOnFixedSize()
108108
CheckSequence(expectedLength, result.ConstantLengthArray);
109109
}
110110

111+
[TestMethod]
112+
public void DoesntAffectUnpackedBooleanArrays()
113+
{
114+
var original = new UnpackedBooleanClass
115+
{
116+
UnpackedArray = new[] { true, true, false, false, true, true }
117+
};
118+
119+
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 };
120+
var actual = Serialize(original);
121+
122+
CheckSequence(expected, actual);
123+
124+
var deserialized = Deserialize<UnpackedBooleanClass>(actual);
125+
126+
Assert.AreEqual(original.UnpackedArray.Length, deserialized.UnpackedArrayLength, "Invalid length binding on unpacked boolean array.");
127+
Assert.AreEqual(original.UnpackedArray.Length, deserialized.UnpackedArrayCount, "Invalid count binding on unpacked boolean array.");
128+
129+
CheckSequence(original.UnpackedArray, deserialized.UnpackedArray);
130+
}
131+
111132
private void CheckSequence<T>(IEnumerable<T> expected, IEnumerable<T> actual)
112133
{
113134
Assert.AreEqual(expected.Count(), actual.Count(), "Incorrect length");
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace BinarySerialization.Test.PackedBoolean
6+
{
7+
public class UnpackedBooleanClass
8+
{
9+
[FieldOrder(0)] public long UnpackedArrayCount { get; set; }
10+
[FieldOrder(1)] public long UnpackedArrayLength { get; set; }
11+
12+
[FieldCount(nameof(UnpackedArrayCount)), FieldLength(nameof(UnpackedArrayLength))]
13+
[FieldOrder(2)]
14+
public bool[] UnpackedArray { get; set; }
15+
}
16+
}

0 commit comments

Comments
 (0)