From 754f33448e54839cbf0128f83285337c4e6df516 Mon Sep 17 00:00:00 2001 From: Sebastian Zander Date: Tue, 4 Aug 2015 10:59:34 +0200 Subject: [PATCH] Added test that breaks when using PeekUInt64(int maxBits). There's a bug in this function, as well as in ReadUInt64(int maxBits), when trying to read more than 32 bits (and the value uses more than 32 bits). --- UnitTests/ReadWriteTests.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/UnitTests/ReadWriteTests.cs b/UnitTests/ReadWriteTests.cs index 8682ccf..0067580 100644 --- a/UnitTests/ReadWriteTests.cs +++ b/UnitTests/ReadWriteTests.cs @@ -43,6 +43,7 @@ namespace UnitTests msg.Write("duke of earl"); msg.Write((byte)43); msg.Write((ushort)44); + msg.Write(UInt64.MaxValue, 64); msg.Write(true); msg.WritePadBits(); @@ -83,8 +84,13 @@ namespace UnitTests throw new NetException("Read/write failure"); bdr.Append(inc.ReadUInt16()); + + if (inc.PeekUInt64(64) != UInt64.MaxValue) + throw new NetException("Read/write failure"); + + bdr.Append(inc.ReadUInt64()); bdr.Append(inc.ReadBoolean()); - + inc.SkipPadBits(); bdr.Append(inc.ReadSingle()); @@ -96,7 +102,7 @@ namespace UnitTests bdr.Append(inc.ReadVariableUInt32()); bdr.Append(inc.ReadVariableInt64()); - if (bdr.ToString().Equals("False-342duke of earl4344True56784521159980224614-4747000048-49")) + if (bdr.ToString().Equals("False-342duke of earl434418446744073709551615True56784521159980224614-4747000048-49")) Console.WriteLine("Read/write tests OK"); else throw new NetException("Read/write tests FAILED!");