![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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]
main.cpp@1:0b6bc5c2c913, 2014-01-30 (annotated)
- Committer:
- johnb
- Date:
- Thu Jan 30 20:26:17 2014 +0000
- Revision:
- 1:0b6bc5c2c913
- Parent:
- 0:6383f958c806
Add a couple of tests for [] operator
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:0b6bc5c2c913 | 22 | #define FIRST_TEST_BYTE 0x55U |
johnb | 1:0b6bc5c2c913 | 23 | |
johnb | 0:6383f958c806 | 24 | int main() |
johnb | 0:6383f958c806 | 25 | { |
johnb | 0:6383f958c806 | 26 | check_empty(); |
johnb | 1:0b6bc5c2c913 | 27 | temp_buffer[ 0 ] = FIRST_TEST_BYTE; |
johnb | 0:6383f958c806 | 28 | |
johnb | 0:6383f958c806 | 29 | /* Write a single byte into the buffer then call various methods */ |
johnb | 0:6383f958c806 | 30 | TST_EQ( buffer.write( temp_buffer, 1 ), 1, "Empty buffer: write() single byte" ); |
johnb | 1:0b6bc5c2c913 | 31 | TST_EQ( buffer[0], FIRST_TEST_BYTE, "Single byte buffer: [] operator to read first byte" ); |
johnb | 0:6383f958c806 | 32 | TST_EQ( buffer.getSize(), 1, "Single-byte buffer: getSize()" ); |
johnb | 1:0b6bc5c2c913 | 33 | temp_buffer[0]++; |
johnb | 0:6383f958c806 | 34 | TST_EQ( buffer.peek( temp_buffer, TEST_BUFFER_SIZE ), 1, "Single-byte buffer: peek()" ); |
johnb | 1:0b6bc5c2c913 | 35 | TST_EQ( temp_buffer[0], FIRST_TEST_BYTE, "Single-byte buffer: peek() yielded correct value" ); |
johnb | 0:6383f958c806 | 36 | TST_FALSE( buffer.isEmpty(), "Single-byte buffer: isEmpty()" ); |
johnb | 0:6383f958c806 | 37 | TST_FALSE( buffer.isFull(), "Single-byte buffer: isFull()" ); |
johnb | 0:6383f958c806 | 38 | TST_EQ( buffer.getCapacity(), TEST_BUFFER_SIZE, "Single-byte buffer: capacity()" ); |
johnb | 0:6383f958c806 | 39 | // This test is last as it will empty the buffer again |
johnb | 0:6383f958c806 | 40 | TST_EQ( buffer.read( temp_buffer, TEST_BUFFER_SIZE ), 1, "Single-byte buffer: read()" ); |
johnb | 0:6383f958c806 | 41 | |
johnb | 0:6383f958c806 | 42 | /* Now that the buffer is empty again, run the tests to make sure that method returns |
johnb | 0:6383f958c806 | 43 | are again consistent with this */ |
johnb | 0:6383f958c806 | 44 | check_empty(); |
johnb | 0:6383f958c806 | 45 | |
johnb | 0:6383f958c806 | 46 | /* TODO: Finish off writing tests! */ |
johnb | 0:6383f958c806 | 47 | |
johnb | 0:6383f958c806 | 48 | TST_DONE(); |
johnb | 0:6383f958c806 | 49 | return 0; |
johnb | 0:6383f958c806 | 50 | } |