Exemplo n.º 1
0
        public void Resetting()
        {
            var s = new ReusableStream(16);

            Assert.AreEqual(0, s.Position);
            Assert.AreEqual(0, s.Length);

            var written = long.MaxValue;

            s.Write(written);

            Assert.AreEqual(8, s.Position);
            Assert.AreEqual(8, s.Length);

            s.ResetForReading();

            Assert.AreEqual(0, s.Position);
            Assert.AreEqual(8, s.Length);

            var read = s.ReadInt64();

            Assert.AreEqual(written, read);
            Assert.AreEqual(8, s.Position);
            Assert.AreEqual(8, s.Length);

            s.ResetForWriting();

            Assert.AreEqual(0, s.Position);
            Assert.AreEqual(0, s.Length);

            written = 1;
            s.Write(written);

            Assert.AreEqual(8, s.Position);
            Assert.AreEqual(8, s.Length);

            s.ResetForReading();

            Assert.AreEqual(0, s.Position);
            Assert.AreEqual(8, s.Length);

            read = s.ReadInt64();

            Assert.AreEqual(written, read);
            Assert.AreEqual(8, s.Position);
            Assert.AreEqual(8, s.Length);
        }
Exemplo n.º 2
0
        public void StringEdgeCases()
        {
            // The purpose of this method is to trigger some edge cases in the string writing code where the max encoded size of given string length is greater
            // than the remaining bytes in the stream; however, the *actual* encoded string might still fit. If the real encoded size will fit, the stream
            // should not grow.

            var s = new ReusableStream(8);

            var sevenAscii   = "seven c"; // should fit
            var sevenUnicode = "seven 瀬"; // won't fit

            s.WriteString(sevenAscii, false);
            Assert.AreEqual(8, s.Length);
            Assert.AreEqual(8, s.Capacity);

            s.ResetForWriting();

            s.WriteString(sevenUnicode, false);
            Assert.AreEqual(10, s.Length);
            Assert.IsTrue(s.Capacity >= 10);
        }