Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: CircularBuffer TestSupportLite mbed
Revision 0:6383f958c806, committed 2014-01-19
- Comitter:
- johnb
- Date:
- Sun Jan 19 17:18:55 2014 +0000
- Child:
- 1:0b6bc5c2c913
- Commit message:
- Tests for the CircularBuffer library
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CircularBuffer.lib Sun Jan 19 17:18:55 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/johnb/code/CircularBuffer/#e2d532183250
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TestSupportLite.lib Sun Jan 19 17:18:55 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/johnb/code/TestSupportLite/#62a10b8392a4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sun Jan 19 17:18:55 2014 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+#include "CircularBuffer.h"
+#include "TestSupportSimple.hpp"
+
+#define TEST_BUFFER_SIZE 16
+
+CircularBuffer<TEST_BUFFER_SIZE> buffer;
+uint8_t temp_buffer[ TEST_BUFFER_SIZE ];
+
+void check_empty( void )
+{
+ /* A buffer which is empty should pass all of these tests */
+
+ TST_EQ( buffer.getSize(), 0, "Empty buffer: getSize()" );
+ TST_EQ( buffer.read( temp_buffer, TEST_BUFFER_SIZE ), 0, "Empty buffer: read()" );
+ TST_EQ( buffer.peek( temp_buffer, TEST_BUFFER_SIZE ), 0, "Empty buffer: peek()" );
+ TST_TRUE( buffer.isEmpty(), "Empty buffer: isEmpty()" );
+ TST_FALSE( buffer.isFull(), "Empty buffer: isFull()" );
+ TST_EQ( buffer.getCapacity(), TEST_BUFFER_SIZE, "Empty buffer: capacity()" );
+}
+
+int main()
+{
+ check_empty();
+ temp_buffer[ 0 ] = 0x55;
+
+ /* Write a single byte into the buffer then call various methods */
+ TST_EQ( buffer.write( temp_buffer, 1 ), 1, "Empty buffer: write() single byte" );
+ TST_EQ( buffer.getSize(), 1, "Single-byte buffer: getSize()" );
+ TST_EQ( buffer.peek( temp_buffer, TEST_BUFFER_SIZE ), 1, "Single-byte buffer: peek()" );
+ TST_FALSE( buffer.isEmpty(), "Single-byte buffer: isEmpty()" );
+ TST_FALSE( buffer.isFull(), "Single-byte buffer: isFull()" );
+ TST_EQ( buffer.getCapacity(), TEST_BUFFER_SIZE, "Single-byte buffer: capacity()" );
+ // This test is last as it will empty the buffer again
+ TST_EQ( buffer.read( temp_buffer, TEST_BUFFER_SIZE ), 1, "Single-byte buffer: read()" );
+
+ /* Now that the buffer is empty again, run the tests to make sure that method returns
+ are again consistent with this */
+ check_empty();
+
+ /* TODO: Finish off writing tests! */
+
+ TST_DONE();
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Jan 19 17:18:55 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/824293ae5e43 \ No newline at end of file