Ejemplo n.º 1
0
        public void Encode_WithRandomData_ShouldNotFail(int length)
        {
            Random r = new Random((int)DateTime.Now.Ticks);

            byte[] buffer  = new byte[length];
            byte[] buffer2 = new byte[PayloadEncoding.EncodedPayloadLength(length)];
            r.NextBytes(buffer);
            fixed(byte *src = buffer)
            fixed(byte *dst = buffer2)
            {
                PayloadEncoding.Encode(src, length, dst, out int bufferLength);
                Assert.AreEqual(buffer2.Length, bufferLength);
                Assert.IsTrue(buffer2.All(b => b != 0));
            }
        }
Ejemplo n.º 2
0
        public void Decode_WithEncodedRandomData_ShouldNotFail(int length)
        {
            Random r = new Random((int)DateTime.Now.Ticks);

            byte[] buffer  = new byte[length];
            byte[] buffer2 = new byte[PayloadEncoding.EncodedPayloadLength(length)];

            r.NextBytes(buffer);
            fixed(byte *src = buffer)
            fixed(byte *dst = buffer2)
            {
                ushort checksum1 = PayloadEncoding.Encode(src, length, dst, out int bufferLength);

                byte[] buffer3 = new byte[bufferLength];
                fixed(byte *dcp = buffer3)
                {
                    ushort checksum2 = PayloadEncoding.Decode(dst, bufferLength, dcp, out int dstLength);

                    Assert.AreEqual(length, dstLength);
                    Assert.AreEqual(checksum1, checksum2);
                    Assert.IsTrue(buffer3.Take(dstLength).SequenceEqual(buffer));
                }
            }
        }