From 0d0543e4daeb1c6b01d4799736026b6f3aef9779 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 15 Feb 2015 23:29:17 +0100 Subject: valgrind tests --- test/ByteBufferTest.cpp | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'test') 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 +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(); -- cgit v1.2.3