From 98d6e667b0114d2fe4705b963f2e88394f0edc79 Mon Sep 17 00:00:00 2001 From: Rodol Phito Date: Mon, 8 Apr 2019 11:20:19 -0700 Subject: [PATCH] Added string binary compat test --- Assets/Mirror/Tests/NetworkWriterTest.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Assets/Mirror/Tests/NetworkWriterTest.cs b/Assets/Mirror/Tests/NetworkWriterTest.cs index e6d48d45d..e1520f784 100644 --- a/Assets/Mirror/Tests/NetworkWriterTest.cs +++ b/Assets/Mirror/Tests/NetworkWriterTest.cs @@ -486,6 +486,22 @@ public void TestReadingTruncatedString() Assert.Throws(() => reader.ReadString()); } + [Test] + public void TestStringBinaryCompat() + { + NetworkWriter writer = new NetworkWriter(); + writer.Write(""); + writer.Write("short string"); + writer.Write(string.Join("0", new string[100000])); + byte[] data = writer.ToArray(); + byte[] expect = new byte[]{1,0,1,12,115,104,111,114,116,32,115,116,114,105,110,103,1,159,141,6}; + Assert.That(data.Length, Is.EqualTo(100019)); + for (int i = 0; i < expect.Length; i++) + Assert.That(data[i], Is.EqualTo(expect[i]), $"index {i}"); + for (int i = expect.Length; i < data.Length; i++) + Assert.That(data[i], Is.EqualTo(48), $"index {i}"); + } + [Test] public void TestToArray() {