diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-02-15 11:01:46 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-02-15 11:01:46 +0100 |
commit | 60d5440dd3514e71b87948ff5ed30ee38445b8a5 (patch) | |
tree | 0d983caed47449c875c5188e604e81da29e1b82c /test | |
parent | 041bbe24b39190ac0b624b2709fc38dea17ad0a7 (diff) | |
download | ble-toys-60d5440dd3514e71b87948ff5ed30ee38445b8a5.tar.gz ble-toys-60d5440dd3514e71b87948ff5ed30ee38445b8a5.tar.bz2 ble-toys-60d5440dd3514e71b87948ff5ed30ee38445b8a5.tar.xz ble-toys-60d5440dd3514e71b87948ff5ed30ee38445b8a5.zip |
o wip. Test cases!
Diffstat (limited to 'test')
-rw-r--r-- | test/ByteBufferTest.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/ByteBufferTest.cpp b/test/ByteBufferTest.cpp new file mode 100644 index 0000000..f98a770 --- /dev/null +++ b/test/ByteBufferTest.cpp @@ -0,0 +1,46 @@ +#include "ByteBuffer.h" + +#define BOOST_TEST_DYN_LINK + +//Define our Module name (prints at testing) +#define BOOST_TEST_MODULE "ByteBuffer" + +#include <boost/test/unit_test.hpp> + +void checkBuffer(ByteBuffer& buffer, size_t size, size_t capacity, size_t cursor) { + BOOST_CHECK(buffer.getSize() == size); + BOOST_CHECK(buffer.getCapacity() == capacity); + BOOST_CHECK(buffer.getCursor() == cursor); +} + +BOOST_AUTO_TEST_CASE(empty_buffer) { + uint8_t bytes[1000]; + + for (int i = 0; i < sizeof(bytes); i++) { + bytes[i] = (uint8_t) i; + } + + ByteBuffer buffer(bytes, sizeof(bytes), 0, 0); + + checkBuffer(buffer, 0, 1000, 0); + + try { + buffer.get8(); + BOOST_FAIL("Expected exception"); + } catch (ByteBufferException e) { + } +} + +BOOST_AUTO_TEST_CASE(basic) { + uint8_t bytes[1000]; + + for (int i = 0; i < sizeof(bytes); i++) { + bytes[i] = (uint8_t) i; + } + + ByteBuffer buffer(bytes, sizeof(bytes), 10, 0); + checkBuffer(buffer, 10, 1000, 0); + + buffer.get8(); + checkBuffer(buffer, 10, 1000, 1); +} |