Esempio n. 1
0
 public void RejectsWhenExactlyFull()
 {
     CircularBuffer circularBuffer = new CircularBuffer(100);
     byte[] buffer = new byte[200];
     circularBuffer.Write(buffer, 0, 100);
     int written = circularBuffer.Write(buffer, 0, 50);
     Assert.AreEqual(0, written, "Wrote the wrong amount");
 }
Esempio n. 2
0
 public void CanWriteToBuffer()
 {
     CircularBuffer circularBuffer = new CircularBuffer(1024);
     byte[] buffer = new byte[100];
     circularBuffer.Write(buffer, 0, 100);
     Assert.AreEqual(100, circularBuffer.Count);
     circularBuffer.Write(buffer, 0, 50);
     Assert.AreEqual(150, circularBuffer.Count);
 }
Esempio n. 3
0
 public void RejectsWhenFull()
 {
     CircularBuffer circularBuffer = new CircularBuffer(100);
     byte[] buffer = new byte[200];
     circularBuffer.Write(buffer, 0, 75);
     try
     {
         circularBuffer.Write(buffer, 0, 50);
         Assert.Fail("Should have thrown an argument exception");
     }
     catch (ArgumentException)
     {
         // expected exception
     }
 }
Esempio n. 4
0
 public void RejectsTooMuchData()
 {
     CircularBuffer circularBuffer = new CircularBuffer(100);
     byte[] buffer = new byte[200];
         
     int written = circularBuffer.Write(buffer, 0, 200);
     Assert.AreEqual(100, written, "Wrote the wrong amount");
 }
Esempio n. 5
0
 public void CanWritePastEnd()
 {
     CircularBuffer circularBuffer = new CircularBuffer(100);
     byte[] buffer = new byte[200];
     circularBuffer.Write(buffer, 0, 75);
     Assert.AreEqual(75, circularBuffer.Count, "Initial count");
     int read = circularBuffer.Read(buffer, 0, 75);
     Assert.AreEqual(0, circularBuffer.Count, "Count after read");
     Assert.AreEqual(75, read, "Bytes read");
     // write wraps round
     circularBuffer.Write(buffer, 0, 50);
     Assert.AreEqual(50, circularBuffer.Count, "Count after wrap round");
     // read wraps round
     read = circularBuffer.Read(buffer, 0, 75);
     Assert.AreEqual(50, read, "Bytes Read 2");
     Assert.AreEqual(0, circularBuffer.Count, "Final Count");
 }
Esempio n. 6
0
 public void BufferReturnsAsMuchAsIsAvailable()
 {
     CircularBuffer circularBuffer = new CircularBuffer(1024);
     byte[] buffer = new byte[100];
     circularBuffer.Write(buffer, 0, 100);
     Assert.AreEqual(100, circularBuffer.Count);
     byte[] readBuffer = new byte[1000];
     int read = circularBuffer.Read(readBuffer, 0, 1000);
     Assert.AreEqual(100, read);
 }
Esempio n. 7
0
        public void DataIntegrityTest()
        {
            byte[] numbers = new byte[256];
            byte[] readBuffer = new byte[256];
            for (int n = 0; n < 256; n++)
            {
                numbers[n] = (byte)n;
            }

            CircularBuffer circularBuffer = new CircularBuffer(300);
            circularBuffer.Write(numbers, 0, 200);
            Array.Clear(readBuffer, 0, readBuffer.Length);
            int read = circularBuffer.Read(readBuffer, 0, 200);
            Assert.AreEqual(200, read);
            CheckBuffer(readBuffer, 0, read);

            // now write past the end
            circularBuffer.Write(numbers, 0, 200);
            Array.Clear(readBuffer, 0, readBuffer.Length);
            // now read past the end
            read = circularBuffer.Read(readBuffer, 0, 200);
            Assert.AreEqual(200, read);
            CheckBuffer(readBuffer, 0, read);
        }