#include "ByteBuffer.h" #define BOOST_TEST_MODULE "ByteBuffer" #include 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); BOOST_CHECK(buffer.getCursor() == cursor); } BOOST_AUTO_TEST_CASE(empty_buffer) { Utils u; ByteBuffer buffer(u.bytes, sizeof(u.bytes), 0, 0); checkBuffer(buffer, 0, 1000, 0); try { buffer.get8(); BOOST_FAIL("Expected exception"); } catch (ByteBufferException e) { } } BOOST_AUTO_TEST_CASE(basic) { Utils u; ByteBuffer buffer(u.bytes, sizeof(u.bytes), 10, 0); checkBuffer(buffer, 10, 1000, 0); buffer.get8(); checkBuffer(buffer, 10, 1000, 1); } BOOST_AUTO_TEST_CASE(view) { Utils u; ByteBuffer buffer(u.bytes, sizeof(u.bytes), 10, 0); checkBuffer(buffer, 10, 1000, 0); buffer.get8(); checkBuffer(buffer, 10, 1000, 1); }