Exemplo n.º 1
0
        public void IsTextWithInvalidIndexAndLength()
        {
            var buffer = Unpooled.Buffer();

            try
            {
                buffer.WriteBytes(new byte[4]);
                int[][] validIndexLengthPairs = new[] {
                    new [] { 4, 0 },
                    new [] { 0, 4 },
                    new [] { 1, 3 },
                };
                foreach (var pair in validIndexLengthPairs)
                {
                    Assert.True(ByteBufferUtil.IsText(buffer, pair[0], pair[1], Encoding.ASCII));
                }
                int[][] invalidIndexLengthPairs = new[] {
                    new [] { 4, 1 },
                    new [] { -1, 2 },
                    new [] { 3, -1 },
                    new [] { 3, -2 },
                    new [] { 5, 0 },
                    new [] { 1, 5 },
                };
                foreach (var pair in invalidIndexLengthPairs)
                {
                    Assert.Throws <IndexOutOfRangeException>(() => ByteBufferUtil.IsText(buffer, pair[0], pair[1], Encoding.ASCII));
                }
            }
            finally
            {
                buffer.Release();
            }
        }
Exemplo n.º 2
0
        private static void AssertIsText(byte[] bytes, bool expected, Encoding charset)
        {
            var buffer = Unpooled.Buffer();

            try
            {
                buffer.WriteBytes(bytes);
                Assert.Equal(expected, ByteBufferUtil.IsText(buffer, charset));
            }
            finally
            {
                buffer.Release();
            }
        }