Exemplo n.º 1
0
        public static void DecoderExceptionFallbackBufferTest()
        {
            Decoder decoder = Encoding.GetEncoding("us-ascii", new EncoderExceptionFallback(), new DecoderExceptionFallback()).GetDecoder();

            byte [] bytes = new byte [] { 0xFF, 0xFF };
            char [] chars = new char [bytes.Length];

            Assert.Throws <DecoderFallbackException>(() => decoder.GetChars(bytes, 0, 2, chars, 2));

            DecoderFallbackBuffer fallbackBuffer = decoder.FallbackBuffer;

            Assert.True(fallbackBuffer is DecoderExceptionFallbackBuffer, "Expected to get DecoderExceptionFallbackBuffer type");
            Assert.Throws <DecoderFallbackException>(() => fallbackBuffer.Fallback(bytes, 0));
            Assert.Throws <DecoderFallbackException>(() => fallbackBuffer.Fallback(new byte [] { 0x40, 0x60 }, 0));

            Assert.Equal(0, fallbackBuffer.Remaining);
            Assert.Equal('\u0000', fallbackBuffer.GetNextChar());

            Assert.False(fallbackBuffer.MovePrevious(), "MovePrevious expected to always return false");

            fallbackBuffer.Reset();

            Assert.Equal(0, fallbackBuffer.Remaining);
            Assert.Equal('\u0000', fallbackBuffer.GetNextChar());
        }
Exemplo n.º 2
0
        public static void DecoderReplacementFallbackBufferTest()
        {
            Decoder decoder = Encoding.GetEncoding("us-ascii", new EncoderReplacementFallback(), new DecoderReplacementFallback()).GetDecoder();

            byte [] bytes = new byte [] { 0xFF, 0xFF };
            char [] chars = new char [bytes.Length];

            DecoderFallbackBuffer fallbackBuffer = decoder.FallbackBuffer;

            Assert.True(fallbackBuffer is DecoderReplacementFallbackBuffer, "Expected to get DecoderReplacementFallbackBuffer type");
            Assert.True(fallbackBuffer.Fallback(bytes, 0), "Expected we fallback on the given buffer");
            Assert.Equal(1, fallbackBuffer.Remaining);
            Assert.False(fallbackBuffer.MovePrevious(), "Expected we cannot move back on the replacement buffer as we are at the Beginning of the buffer");
            Assert.Equal('?', fallbackBuffer.GetNextChar());
            Assert.True(fallbackBuffer.MovePrevious(), "Expected we can move back on the replacement buffer");
            Assert.Equal('?', fallbackBuffer.GetNextChar());

            fallbackBuffer.Reset();
            Assert.Equal(0, fallbackBuffer.Remaining);
            Assert.Equal('\u0000', fallbackBuffer.GetNextChar());
            Assert.False(fallbackBuffer.MovePrevious(), "Expected we cannot move back on the replacement buffer as we are rest the buffer");
        }
Exemplo n.º 3
0
 public override bool MovePrevious()
 {
     return(_parentBuffer == null ? false : _parentBuffer.MovePrevious());
 }
Exemplo n.º 4
0
 public override bool MovePrevious()
 {
     return(buffer.MovePrevious());
 }