diff options
Diffstat (limited to 'test/ByteBufferTest.cpp')
-rw-r--r-- | test/ByteBufferTest.cpp | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/test/ByteBufferTest.cpp b/test/ByteBufferTest.cpp index f98a770..70a98ab 100644 --- a/test/ByteBufferTest.cpp +++ b/test/ByteBufferTest.cpp @@ -1,12 +1,20 @@ #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> +class Utils { +public: + uint8_t bytes[1000]; + + Utils() { + for (int i = 0; i < sizeof(bytes); i++) { + bytes[i] = (uint8_t) i; + } + } +}; + void checkBuffer(ByteBuffer& buffer, size_t size, size_t capacity, size_t cursor) { BOOST_CHECK(buffer.getSize() == size); BOOST_CHECK(buffer.getCapacity() == capacity); @@ -14,13 +22,8 @@ void checkBuffer(ByteBuffer& buffer, size_t size, size_t capacity, size_t 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); + Utils u; + ByteBuffer buffer(u.bytes, sizeof(u.bytes), 0, 0); checkBuffer(buffer, 0, 1000, 0); @@ -32,13 +35,17 @@ BOOST_AUTO_TEST_CASE(empty_buffer) { } BOOST_AUTO_TEST_CASE(basic) { - uint8_t bytes[1000]; + Utils u; + ByteBuffer buffer(u.bytes, sizeof(u.bytes), 10, 0); + checkBuffer(buffer, 10, 1000, 0); - for (int i = 0; i < sizeof(bytes); i++) { - bytes[i] = (uint8_t) i; - } + buffer.get8(); + checkBuffer(buffer, 10, 1000, 1); +} - ByteBuffer buffer(bytes, sizeof(bytes), 10, 0); +BOOST_AUTO_TEST_CASE(view) { + Utils u; + ByteBuffer buffer(u.bytes, sizeof(u.bytes), 10, 0); checkBuffer(buffer, 10, 1000, 0); buffer.get8(); |