From 503e4cf3c790e0b2f7e2de1fc977e5d237eed5fc Mon Sep 17 00:00:00 2001 From: Martchus Date: Wed, 27 Jan 2016 01:13:49 +0100 Subject: [PATCH] added test for BitReader --- tests/iotests.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/iotests.cpp b/tests/iotests.cpp index 5e321ff..9422b38 100644 --- a/tests/iotests.cpp +++ b/tests/iotests.cpp @@ -1,5 +1,6 @@ #include "../io/binaryreader.h" #include "../io/binarywriter.h" +#include "../io/bitreader.h" #include #include @@ -22,6 +23,7 @@ class IoTests : public TestFixture CPPUNIT_TEST(testFailure); CPPUNIT_TEST(testBinaryReader); CPPUNIT_TEST(testBinaryWriter); + CPPUNIT_TEST(testBitReader); CPPUNIT_TEST_SUITE_END(); public: @@ -31,6 +33,7 @@ public: void testFailure(); void testBinaryReader(); void testBinaryWriter(); + void testBitReader(); }; CPPUNIT_TEST_SUITE_REGISTRATION(IoTests); @@ -165,3 +168,20 @@ void IoTests::testBinaryWriter() CPPUNIT_ASSERT(c == static_cast(testFile.get())); } } + +/*! + * \brief Tests the BitReader. + */ +void IoTests::testBitReader() +{ + byte testData[] = {0x81, 0x90, 0x3C, 0x44, 0x28, 0x00, 0x44}; + BitReader reader(reinterpret_cast(testData), sizeof(testData)); + CPPUNIT_ASSERT(reader.readBit() == 1); + reader.skipBits(6); + CPPUNIT_ASSERT(reader.showBits(2) == 3); + CPPUNIT_ASSERT(reader.readBits(2) == 3); + CPPUNIT_ASSERT(reader.readBits(32) == (0x103C4428 << 1)); + reader.align(); + CPPUNIT_ASSERT(reader.readBits(8) == 0x44); + CPPUNIT_ASSERT_THROW(reader.readBit(), std::ios_base::failure); +}