From f90dc888bb0c0bef05bd677024292af8ae309d83 Mon Sep 17 00:00:00 2001 From: Joshua Scott Date: Sat, 20 Oct 2018 20:08:39 +0100 Subject: [PATCH] util: Write further tests for BitStream::stream_pos coverage --- test/src/unit-bitstream.cpp | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/src/unit-bitstream.cpp b/test/src/unit-bitstream.cpp index 5d077a2..f3a8ac3 100644 --- a/test/src/unit-bitstream.cpp +++ b/test/src/unit-bitstream.cpp @@ -23,6 +23,59 @@ using namespace ki; +TEST_CASE("BitStream::stream_pos Functionality", "[bit-stream]") +{ + BitStream::stream_pos position(1, 4); + + SECTION("Increment single bit") + { + ++position; + if (position.get_byte() != 1 || position.get_bit() != 5) + FAIL(); + SUCCEED(); + } + + SECTION("Decrement single bit") + { + --position; + if (position.get_byte() != 1 || position.get_bit() != 3) + FAIL(); + SUCCEED(); + } + + SECTION("Increment bits and move to next byte") + { + position += 4; + if (position.get_byte() != 2 || position.get_bit() != 0) + FAIL(); + SUCCEED(); + } + + SECTION("Decrement bits and move to previous byte") + { + position -= 4; + if (position.get_byte() != 1 || position.get_bit() != 7) + FAIL(); + SUCCEED(); + } + + SECTION("Increment byte") + { + position += BitStream::stream_pos(1, 0); + if (position.get_byte() != 2 || position.get_bit() != 4) + FAIL(); + SUCCEED(); + } + + SECTION("Decrement byte") + { + position -= BitStream::stream_pos(1, 0); + if (position.get_byte() != 0 || position.get_bit() != 4) + FAIL(); + SUCCEED(); + } +} + TEST_CASE("BitStream Functionality", "[bit-stream]") { auto *bit_stream = new BitStream();