コード例 #1
0
        public void TestPutPrefixedStringWithPrefixLength()
        {
            Encoding encoding = Encoding.GetEncoding("ISO-8859-1");
            IoBuffer buf      = IoBuffer.Allocate(16).Sweep();

            buf.AutoExpand = true;

            buf.PutPrefixedString("A", 1, encoding);
            Assert.AreEqual(2, buf.Position);
            Assert.AreEqual(1, buf.Get(0));
            Assert.AreEqual((byte)'A', buf.Get(1));

            buf.Sweep();
            buf.PutPrefixedString("A", 2, encoding);
            Assert.AreEqual(3, buf.Position);
            Assert.AreEqual(0, buf.Get(0));
            Assert.AreEqual(1, buf.Get(1));
            Assert.AreEqual((byte)'A', buf.Get(2));

            buf.Sweep();
            buf.PutPrefixedString("A", 4, encoding);
            Assert.AreEqual(5, buf.Position);
            Assert.AreEqual(0, buf.Get(0));
            Assert.AreEqual(0, buf.Get(1));
            Assert.AreEqual(0, buf.Get(2));
            Assert.AreEqual(1, buf.Get(3));
            Assert.AreEqual((byte)'A', buf.Get(4));
        }
コード例 #2
0
        public void TestPutPrefixedString()
        {
            Encoding encoding = Encoding.GetEncoding("ISO-8859-1");
            IoBuffer buf      = IoBuffer.Allocate(16);

            buf.FillAndReset(buf.Remaining);

            // Without autoExpand
            buf.PutPrefixedString("ABC", encoding);
            Assert.AreEqual(5, buf.Position);
            Assert.AreEqual(0, buf.Get(0));
            Assert.AreEqual(3, buf.Get(1));
            Assert.AreEqual((byte)'A', buf.Get(2));
            Assert.AreEqual((byte)'B', buf.Get(3));
            Assert.AreEqual((byte)'C', buf.Get(4));

            buf.Clear();
            try
            {
                buf.PutPrefixedString("123456789012345", encoding);
                Assert.Fail();
            }
            catch (OverflowException)
            {
                // Expected an Exception, signifies test success
                Assert.IsTrue(true);
            }

            // With autoExpand
            buf.Clear();
            buf.AutoExpand = true;
            buf.PutPrefixedString("123456789012345", encoding);
            Assert.AreEqual(17, buf.Position);
            Assert.AreEqual(0, buf.Get(0));
            Assert.AreEqual(15, buf.Get(1));
            Assert.AreEqual((byte)'1', buf.Get(2));
            Assert.AreEqual((byte)'2', buf.Get(3));
            Assert.AreEqual((byte)'3', buf.Get(4));
            Assert.AreEqual((byte)'4', buf.Get(5));
            Assert.AreEqual((byte)'5', buf.Get(6));
            Assert.AreEqual((byte)'6', buf.Get(7));
            Assert.AreEqual((byte)'7', buf.Get(8));
            Assert.AreEqual((byte)'8', buf.Get(9));
            Assert.AreEqual((byte)'9', buf.Get(10));
            Assert.AreEqual((byte)'0', buf.Get(11));
            Assert.AreEqual((byte)'1', buf.Get(12));
            Assert.AreEqual((byte)'2', buf.Get(13));
            Assert.AreEqual((byte)'3', buf.Get(14));
            Assert.AreEqual((byte)'4', buf.Get(15));
            Assert.AreEqual((byte)'5', buf.Get(16));
        }
コード例 #3
0
ファイル: IoBufferWrapper.cs プロジェクト: eltonfan/Mina.NET
 /// <inheritdoc/>
 public override IoBuffer PutPrefixedString(String value, Encoding encoding)
 {
     return(_buf.PutPrefixedString(value, encoding));
 }