From 5926b05afa21eaac36c185e7fc458710efa30b02 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 21 Feb 2015 23:58:39 +0100 Subject: o Support for reading and writing characteristics. --- test/ByteBufferTest.cpp | 33 ++++++++++++++++++--------------- test/CMakeLists.txt | 1 - 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/test/ByteBufferTest.cpp b/test/ByteBufferTest.cpp index 7ed75e1..bf18387 100644 --- a/test/ByteBufferTest.cpp +++ b/test/ByteBufferTest.cpp @@ -1,12 +1,13 @@ #include "ByteBuffer.h" +#include "log.h" #define BOOST_TEST_MODULE "ByteBuffer" #include #include "Bluetooth.h" -#define checkBuffer(buffer, size, capacity, cursor) \ - D << "size=" << buffer.getSize() << ", capacity=" << buffer.getCapacity() << ", cursor=" << buffer.getCursor(); \ +#define checkBuffer(buffer, capacity, size, cursor) \ + if(false) {D << "capacity=" << buffer.getCapacity() << ", size=" << buffer.getSize() << ", cursor=" << buffer.getCursor();} \ BOOST_CHECK_EQUAL(buffer.getSize(), size); \ BOOST_CHECK_EQUAL(buffer.getCapacity(), capacity); \ BOOST_CHECK_EQUAL(buffer.getCursor(), cursor) @@ -22,15 +23,17 @@ struct do_nothing { class Bytes { public: Bytes(size_t size) : capacity(size) { - _bytes = shared_ptr(new uint8_t[size]); - uint8_t *tmp = (uint8_t *) (((uint64_t) &_bytes.get()[0x100]) & 0xffffffffffffff00); - bytes = shared_ptr(tmp, ::do_nothing()); + uint8_t *secret = new uint8_t[size + 0x100]; + auto tmp = (uint8_t *) (((uint64_t) &secret[0x100]) & 0xffffffffffffff00); for (int i = 0; i < size; i++) { - bytes.get()[i] = (uint8_t) i; + tmp[i] = (uint8_t) i; } + + bytes = shared_ptr(tmp, [secret](uint8_t *) { + delete[]secret; + }); } shared_ptr bytes; - shared_ptr _bytes; size_t capacity; }; @@ -49,7 +52,7 @@ BOOST_AUTO_TEST_CASE(empty_buffer) { BOOST_AUTO_TEST_CASE(basic) { Bytes b(1000); - ByteBuffer buffer(b.bytes, 1000, 0, 1000); + ByteBuffer buffer(b.bytes, 1000, 1000); checkBuffer(buffer, 1000, 1000, 0); BOOST_CHECK_EQUAL(buffer.read8(), 0); @@ -62,25 +65,25 @@ BOOST_AUTO_TEST_CASE(basic) { BOOST_AUTO_TEST_CASE(setCursor) { Bytes b(1000); - ByteBuffer buffer(b.bytes, 1000, 0, 10); - checkBuffer(buffer, 10, 1000, 0); + ByteBuffer buffer(b.bytes, 1000, 10, 0); + checkBuffer(buffer, 1000, 10, 0); BOOST_CHECK_EQUAL(buffer.read8(), 0); - checkBuffer(buffer, 10, 1000, 1); + checkBuffer(buffer, 1000, 10, 1); buffer.setCursor(0); - checkBuffer(buffer, 10, 1000, 0); + checkBuffer(buffer, 1000, 10, 0); BOOST_CHECK_EQUAL(buffer.read8(), 0); - checkBuffer(buffer, 10, 1000, 1); + checkBuffer(buffer, 1000, 10, 1); buffer.setCursor(9); - checkBuffer(buffer, 10, 1000, 9); + checkBuffer(buffer, 1000, 10, 9); } BOOST_AUTO_TEST_CASE(view) { Bytes b(1000); - ByteBuffer buffer(b.bytes, b.capacity, 0, 10); + ByteBuffer buffer(b.bytes, b.capacity, 10, 0); BOOST_CHECK_EQUAL(buffer.read8(), 0); ByteBuffer view1 = buffer.view(); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 14dcdf7..a417d2b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,3 @@ -enable_testing() find_package(Boost COMPONENTS log unit_test_framework REQUIRED) # If we can change directory here add_definition and test-specific stuff could be moved to the test directory -- cgit v1.2.3