aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-15 23:29:17 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-15 23:35:36 +0100
commit0d0543e4daeb1c6b01d4799736026b6f3aef9779 (patch)
tree0f14cac6264710700c70f18c79e41a8aaa6a8cfd /test
parent60d5440dd3514e71b87948ff5ed30ee38445b8a5 (diff)
downloadble-toys-0d0543e4daeb1c6b01d4799736026b6f3aef9779.tar.gz
ble-toys-0d0543e4daeb1c6b01d4799736026b6f3aef9779.tar.bz2
ble-toys-0d0543e4daeb1c6b01d4799736026b6f3aef9779.tar.xz
ble-toys-0d0543e4daeb1c6b01d4799736026b6f3aef9779.zip
valgrind tests
Diffstat (limited to 'test')
-rw-r--r--test/ByteBufferTest.cpp37
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();