aboutsummaryrefslogtreecommitdiff
path: root/test/ByteBufferTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/ByteBufferTest.cpp')
-rw-r--r--test/ByteBufferTest.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/ByteBufferTest.cpp b/test/ByteBufferTest.cpp
new file mode 100644
index 0000000..f98a770
--- /dev/null
+++ b/test/ByteBufferTest.cpp
@@ -0,0 +1,46 @@
+#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>
+
+void checkBuffer(ByteBuffer& buffer, size_t size, size_t capacity, size_t cursor) {
+ BOOST_CHECK(buffer.getSize() == size);
+ BOOST_CHECK(buffer.getCapacity() == capacity);
+ BOOST_CHECK(buffer.getCursor() == 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);
+
+ checkBuffer(buffer, 0, 1000, 0);
+
+ try {
+ buffer.get8();
+ BOOST_FAIL("Expected exception");
+ } catch (ByteBufferException e) {
+ }
+}
+
+BOOST_AUTO_TEST_CASE(basic) {
+ uint8_t bytes[1000];
+
+ for (int i = 0; i < sizeof(bytes); i++) {
+ bytes[i] = (uint8_t) i;
+ }
+
+ ByteBuffer buffer(bytes, sizeof(bytes), 10, 0);
+ checkBuffer(buffer, 10, 1000, 0);
+
+ buffer.get8();
+ checkBuffer(buffer, 10, 1000, 1);
+}