示例#1
0
            public void SimplePeekCharMultipleBytesMbcsUtf32()
            {
                CircularBuffer <byte> buffer = new CircularBuffer <byte>(new byte[] { 0xF3, 0xA0, 0x82, 0x84, 0x30 });
                ReadToCache           rtc    = new ReadToCache();

                Assert.That(rtc.PeekChar(buffer), Is.True);
                Assert.That(rtc.PeekChar(buffer), Is.True);
                Assert.That(rtc.PeekChar(buffer), Is.False);
            }
示例#2
0
            public void SimplePeekCharMultipleBytes()
            {
                CircularBuffer <byte> buffer = new CircularBuffer <byte>(new byte[] { 0x65, 0x66, 0x67 });
                ReadToCache           rtc    = new ReadToCache();

                Assert.That(rtc.PeekChar(buffer), Is.True);
                Assert.That(rtc.PeekChar(buffer), Is.True);
                Assert.That(rtc.PeekChar(buffer), Is.True);
                Assert.That(rtc.PeekChar(buffer), Is.False);
            }
示例#3
0
            public void SimplePeekChar()
            {
                CircularBuffer <byte> buffer = new CircularBuffer <byte>(new byte[] { 0x65 });
                ReadToCache           rtc    = new ReadToCache();

                Assert.That(rtc.PeekChar(buffer), Is.True);
            }
示例#4
0
            public void OverflowWithUtf32AtEnd()
            {
                ReadToCache rtc = new ReadToCache();

                Random r = new Random();

                byte[] bbuffer = new byte[2048];

                // Ensure that each byte is ASCII for simplicity
                for (int i = 0; i < 1022; i++)
                {
                    bbuffer[i] = (byte)r.Next(48, 126);
                }
                bbuffer[1023] = 0xF3;
                bbuffer[1024] = 0xA0;
                bbuffer[1025] = 0x82;
                bbuffer[1026] = 0x84;
                for (int i = 1027; i < bbuffer.Length; i++)
                {
                    bbuffer[i] = (byte)r.Next(48, 126);
                }

                CircularBuffer <byte> buffer = new CircularBuffer <byte>(4096);

                buffer.Append(bbuffer);

                // We now peek 1023 times, which we shouldn't have an overflow
                for (int i = 0; i < 1023; i++)
                {
                    Assert.That(rtc.PeekChar(buffer), Is.True);
                }

                // Shouldn't overflow, but we've now got 1025 characters
                Assert.That(rtc.PeekChar(buffer), Is.True);

                // With this one we should overflow.
                //  m_ReadOverflow = 1
                //  m_ReadOverflowChar[0] is the first character
                //  m_ReadOverflowUtf32 = false
                Assert.That(rtc.PeekChar(buffer), Is.True);

                // Check that the next overflow is still correct
                //  m_ReadOverflow, m_ReadOverflowChar, m_ReadOverflowUtf32 shouldn't change
                Assert.That(rtc.PeekChar(buffer), Is.True);

                rtc.Reset(true);
            }
示例#5
0
            public void SimplePeekCharMultipleBytesMbcsUtf32ByteByByte()
            {
                byte[] bbuffer = { 0xF3, 0xA0, 0x82, 0x84, 0x30 };
                CircularBuffer <byte> buffer = new CircularBuffer <byte>(256);
                ReadToCache           rtc    = new ReadToCache();

                Assert.That(rtc.PeekChar(buffer), Is.False);

                buffer.Append(bbuffer[0]);
                Assert.That(rtc.PeekChar(buffer), Is.False);

                buffer.Append(bbuffer[1]);
                Assert.That(rtc.PeekChar(buffer), Is.False);

                buffer.Append(bbuffer[2]);
                Assert.That(rtc.PeekChar(buffer), Is.False);

                buffer.Append(bbuffer[3]);
                Assert.That(rtc.PeekChar(buffer), Is.True);

                buffer.Append(bbuffer[4]);
                Assert.That(rtc.PeekChar(buffer), Is.True);

                Assert.That(rtc.PeekChar(buffer), Is.False);
            }
示例#6
0
            public void OverflowWithUtf32AtBeginning()
            {
                ReadToCache rtc = new ReadToCache();

                Random r = new Random();

                byte[] bbuffer = new byte[2048];

                bbuffer[0] = 0xF3;
                bbuffer[1] = 0xA0;
                bbuffer[2] = 0x82;
                bbuffer[3] = 0x84;
                // Ensure that each byte is ASCII for simplicity
                for (int i = 4; i < bbuffer.Length; i++)
                {
                    bbuffer[i] = (byte)r.Next(48, 126);
                }

                CircularBuffer <byte> buffer = new CircularBuffer <byte>(4096);

                buffer.Append(bbuffer);

                // We now peek 1023 times, which we shouldn't have an overflow
                for (int i = 0; i < 1023; i++)
                {
                    Assert.That(rtc.PeekChar(buffer), Is.True);
                }

                // 1024 times, fills the buffer. No overflow expected here.
                Assert.That(rtc.PeekChar(buffer), Is.True);

                // With this one we should overflow.
                //  m_ReadOverflow = 4
                //  m_ReadOverflowChar[0] and [1] is the first character
                //  m_ReadOverflowUtf32 = true
                Assert.That(rtc.PeekChar(buffer), Is.True);

                // Check that the next overflow is still correct
                //  m_ReadOverflow, m_ReadOverflowChar, m_ReadOverflowUtf32 shouldn't change
                Assert.That(rtc.PeekChar(buffer), Is.True);

                rtc.Reset(true);
            }