Beispiel #1
0
        public unsafe void OneValueTest([Values(unchecked ((long)0xFFFFFFFFFF000000UL))] long value)
        {
            using (var codec = new CodecWriter(10))
            {
                codec.Count = 0;
                codec.WriteSignedValue(value);

                fixed(byte *pbuf = codec.Buffer)
                {
                    int  pos = 0;
                    long v   = CodecReader.ReadSignedValueUnsafe(pbuf, ref pos);

                    if (value != v)
                    {
                        Assert.Fail("Failed signed long {0:X}", value);
                    }
                }

                using (var codecRdr = new CodecReader(codec.AsArraySegment()))
                {
                    long v = codecRdr.ReadSignedValue();

                    if (value != v)
                    {
                        Assert.Fail("Failed signed long {0:X}", value);
                    }
                }
            }
        }
Beispiel #2
0
        public unsafe void ErrorValuesTests()
        {
            var buf = new byte[10];

            for (int i = 0; i < buf.Length; i++)
            {
                buf[i] = 0xFF;
            }

            int pos = 0;

            // ReSharper disable AccessToModifiedClosure
            Assert.Throws <SerializerException>(
                () =>
            {
                fixed(byte *pbuf = buf)
                CodecReader.ReadSignedValueUnsafe(pbuf, ref pos);
            });
            // ReSharper restore AccessToModifiedClosure

            Assert.AreEqual(0, pos, "ReadSignedValueUnsafe pos shifted");

            Assert.Throws <SerializerException>(
                () =>
            {
                fixed(byte *pbuf = buf)
                CodecReader.ReadUnsignedValueUnsafe(pbuf, ref pos);
            });

            Assert.AreEqual(0, pos, "ReadSignedValueUnsafe pos shifted");


            using (var codecRdr = new CodecReader(new ArraySegment <byte>(buf)))
            {
                // ReSharper disable AccessToDisposedClosure
                Assert.Throws <SerializerException>(() => codecRdr.ReadSignedValue());
                // ReSharper restore AccessToDisposedClosure
                Assert.AreEqual(0, codecRdr.BufferPos, "ReadSignedValue pos shifted");

                // ReSharper disable AccessToDisposedClosure
                Assert.Throws <SerializerException>(() => codecRdr.ReadUnsignedValue());
                // ReSharper restore AccessToDisposedClosure
                Assert.AreEqual(0, codecRdr.BufferPos, "ReadUnsignedValue pos shifted");
            }
        }