aboutsummaryrefslogtreecommitdiff
path: root/test/ByteBufferTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/ByteBufferTest.cpp')
-rw-r--r--test/ByteBufferTest.cpp33
1 files changed, 18 insertions, 15 deletions
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 <boost/test/unit_test.hpp>
#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<uint8_t>(new uint8_t[size]);
- uint8_t *tmp = (uint8_t *) (((uint64_t) &_bytes.get()[0x100]) & 0xffffffffffffff00);
- bytes = shared_ptr<uint8_t>(tmp, ::do_nothing<uint8_t>());
+ 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<uint8_t>(tmp, [secret](uint8_t *) {
+ delete[]secret;
+ });
}
shared_ptr<uint8_t> bytes;
- shared_ptr<uint8_t> _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();