#include "ByteBuffer.h" #define BOOST_TEST_DYN_LINK //Define our Module name (prints at testing) #define BOOST_TEST_MODULE "ByteBuffer" #include 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); }