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); }
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); }