Tests for the circular buffer library

Dependencies:   CircularBuffer TestSupportLite mbed

Uses TestSupportLite and implements tests for CircularBuffer library. Output looks something like:

[001] {X} Empty buffer: getSize()
[002] {X} Empty buffer: read()
[003] {X} Empty buffer: peek()
[004] {X} Empty buffer: isEmpty()
[005] {X} Empty buffer: isFull()
[006] {X} Empty buffer: capacity()
[007] {X} Empty buffer: write() single byte
[008] {X} Single-byte buffer: getSize()
[009] {X} Single-byte buffer: peek()
[010] {X} Single-byte buffer: isEmpty()
[011] {X} Single-byte buffer: isFull()
[012] {X} Single-byte buffer: capacity()
[013] {X} Single-byte buffer: read()
[014] {X} Empty buffer: getSize()
[015] {X} Empty buffer: read()
[016] {X} Empty buffer: peek()
[017] {X} Empty buffer: isEmpty()
[018] {X} Empty buffer: isFull()
[019] {X} Empty buffer: capacity()
----- [19 tests run, 19 passed]
Committer:
johnb
Date:
Sun Jan 19 17:18:55 2014 +0000
Revision:
0:6383f958c806
Child:
1:0b6bc5c2c913
Tests for the CircularBuffer library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnb 0:6383f958c806 1 #include "mbed.h"
johnb 0:6383f958c806 2 #include "CircularBuffer.h"
johnb 0:6383f958c806 3 #include "TestSupportSimple.hpp"
johnb 0:6383f958c806 4
johnb 0:6383f958c806 5 #define TEST_BUFFER_SIZE 16
johnb 0:6383f958c806 6
johnb 0:6383f958c806 7 CircularBuffer<TEST_BUFFER_SIZE> buffer;
johnb 0:6383f958c806 8 uint8_t temp_buffer[ TEST_BUFFER_SIZE ];
johnb 0:6383f958c806 9
johnb 0:6383f958c806 10 void check_empty( void )
johnb 0:6383f958c806 11 {
johnb 0:6383f958c806 12 /* A buffer which is empty should pass all of these tests */
johnb 0:6383f958c806 13
johnb 0:6383f958c806 14 TST_EQ( buffer.getSize(), 0, "Empty buffer: getSize()" );
johnb 0:6383f958c806 15 TST_EQ( buffer.read( temp_buffer, TEST_BUFFER_SIZE ), 0, "Empty buffer: read()" );
johnb 0:6383f958c806 16 TST_EQ( buffer.peek( temp_buffer, TEST_BUFFER_SIZE ), 0, "Empty buffer: peek()" );
johnb 0:6383f958c806 17 TST_TRUE( buffer.isEmpty(), "Empty buffer: isEmpty()" );
johnb 0:6383f958c806 18 TST_FALSE( buffer.isFull(), "Empty buffer: isFull()" );
johnb 0:6383f958c806 19 TST_EQ( buffer.getCapacity(), TEST_BUFFER_SIZE, "Empty buffer: capacity()" );
johnb 0:6383f958c806 20 }
johnb 0:6383f958c806 21
johnb 0:6383f958c806 22 int main()
johnb 0:6383f958c806 23 {
johnb 0:6383f958c806 24 check_empty();
johnb 0:6383f958c806 25 temp_buffer[ 0 ] = 0x55;
johnb 0:6383f958c806 26
johnb 0:6383f958c806 27 /* Write a single byte into the buffer then call various methods */
johnb 0:6383f958c806 28 TST_EQ( buffer.write( temp_buffer, 1 ), 1, "Empty buffer: write() single byte" );
johnb 0:6383f958c806 29 TST_EQ( buffer.getSize(), 1, "Single-byte buffer: getSize()" );
johnb 0:6383f958c806 30 TST_EQ( buffer.peek( temp_buffer, TEST_BUFFER_SIZE ), 1, "Single-byte buffer: peek()" );
johnb 0:6383f958c806 31 TST_FALSE( buffer.isEmpty(), "Single-byte buffer: isEmpty()" );
johnb 0:6383f958c806 32 TST_FALSE( buffer.isFull(), "Single-byte buffer: isFull()" );
johnb 0:6383f958c806 33 TST_EQ( buffer.getCapacity(), TEST_BUFFER_SIZE, "Single-byte buffer: capacity()" );
johnb 0:6383f958c806 34 // This test is last as it will empty the buffer again
johnb 0:6383f958c806 35 TST_EQ( buffer.read( temp_buffer, TEST_BUFFER_SIZE ), 1, "Single-byte buffer: read()" );
johnb 0:6383f958c806 36
johnb 0:6383f958c806 37 /* Now that the buffer is empty again, run the tests to make sure that method returns
johnb 0:6383f958c806 38 are again consistent with this */
johnb 0:6383f958c806 39 check_empty();
johnb 0:6383f958c806 40
johnb 0:6383f958c806 41 /* TODO: Finish off writing tests! */
johnb 0:6383f958c806 42
johnb 0:6383f958c806 43 TST_DONE();
johnb 0:6383f958c806 44 return 0;
johnb 0:6383f958c806 45 }