aboutsummaryrefslogtreecommitdiff
path: root/test/ByteBufferTest.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-18 23:03:57 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-18 23:11:43 +0100
commit4d2339c65548cf553891b049200e6a845de293e9 (patch)
tree296acd302b61ca1e4ff673d102283485a3b4c9fe /test/ByteBufferTest.cpp
parent67478ec6b3f09c14195b8aea1099afb9bcaf9532 (diff)
downloadble-toys-4d2339c65548cf553891b049200e6a845de293e9.tar.gz
ble-toys-4d2339c65548cf553891b049200e6a845de293e9.tar.bz2
ble-toys-4d2339c65548cf553891b049200e6a845de293e9.tar.xz
ble-toys-4d2339c65548cf553891b049200e6a845de293e9.zip
o Successfully decoding GATT services.
Diffstat (limited to 'test/ByteBufferTest.cpp')
-rw-r--r--test/ByteBufferTest.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/test/ByteBufferTest.cpp b/test/ByteBufferTest.cpp
index 2a9bb8c..7ed75e1 100644
--- a/test/ByteBufferTest.cpp
+++ b/test/ByteBufferTest.cpp
@@ -13,22 +13,24 @@
using namespace std;
+template<typename T>
+struct do_nothing {
+ void operator()(T *) {
+ }
+};
+
class Bytes {
public:
Bytes(size_t size) : capacity(size) {
- _bytes = new uint8_t[size + 0x100];
-
- bytes = (uint8_t *) (((uint64_t) &_bytes[0x100]) & 0xffffffffffffff00);
-
+ _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>());
for (int i = 0; i < size; i++) {
- bytes[i] = (uint8_t) i;
+ bytes.get()[i] = (uint8_t) i;
}
}
- ~Bytes() {
- delete _bytes;
- }
- uint8_t *bytes;
- uint8_t *_bytes;
+ shared_ptr<uint8_t> bytes;
+ shared_ptr<uint8_t> _bytes;
size_t capacity;
};
@@ -39,7 +41,7 @@ BOOST_AUTO_TEST_CASE(empty_buffer) {
checkBuffer(buffer, 0, 0, 0);
try {
- buffer.get8();
+ buffer.read8();
BOOST_FAIL("Expected exception");
} catch (ByteBufferException e) {
}
@@ -50,11 +52,11 @@ BOOST_AUTO_TEST_CASE(basic) {
ByteBuffer buffer(b.bytes, 1000, 0, 1000);
checkBuffer(buffer, 1000, 1000, 0);
- BOOST_CHECK_EQUAL(buffer.get8(), 0);
+ BOOST_CHECK_EQUAL(buffer.read8(), 0);
checkBuffer(buffer, 1000, 1000, 1);
for (int i = 1; i < b.capacity; i++) {
- BOOST_CHECK_EQUAL(buffer.get8(), b.bytes[i]);
+ BOOST_CHECK_EQUAL(buffer.read8(), b.bytes.get()[i]);
}
}
@@ -63,13 +65,13 @@ BOOST_AUTO_TEST_CASE(setCursor) {
ByteBuffer buffer(b.bytes, 1000, 0, 10);
checkBuffer(buffer, 10, 1000, 0);
- BOOST_CHECK_EQUAL(buffer.get8(), 0);
+ BOOST_CHECK_EQUAL(buffer.read8(), 0);
checkBuffer(buffer, 10, 1000, 1);
buffer.setCursor(0);
checkBuffer(buffer, 10, 1000, 0);
- BOOST_CHECK_EQUAL(buffer.get8(), 0);
+ BOOST_CHECK_EQUAL(buffer.read8(), 0);
checkBuffer(buffer, 10, 1000, 1);
buffer.setCursor(9);
@@ -80,15 +82,15 @@ BOOST_AUTO_TEST_CASE(view) {
Bytes b(1000);
ByteBuffer buffer(b.bytes, b.capacity, 0, 10);
- BOOST_CHECK_EQUAL(buffer.get8(), 0);
+ BOOST_CHECK_EQUAL(buffer.read8(), 0);
ByteBuffer view1 = buffer.view();
checkBuffer(view1, 9, 9, 0);
- BOOST_CHECK_EQUAL(view1.get8(), 1);
- BOOST_CHECK_EQUAL(view1.get8(), 2);
+ BOOST_CHECK_EQUAL(view1.read8(), 1);
+ BOOST_CHECK_EQUAL(view1.read8(), 2);
ByteBuffer view2 = view1.view();
checkBuffer(view2, 7, 7, 0);
- BOOST_CHECK_EQUAL(view1.get8(), 3);
+ BOOST_CHECK_EQUAL(view1.read8(), 3);
}