From 2470dd3bb5f437658ec2f95ff3e7f0bb2e0b5448 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Wed, 25 Jan 2023 20:06:16 +0100 Subject: AK: Move bit streams from `LibCore` --- Tests/LibCore/TestLibCoreStream.cpp | 115 ------------------------------------ 1 file changed, 115 deletions(-) (limited to 'Tests/LibCore/TestLibCoreStream.cpp') diff --git a/Tests/LibCore/TestLibCoreStream.cpp b/Tests/LibCore/TestLibCoreStream.cpp index 0549a35518..c7c87aff85 100644 --- a/Tests/LibCore/TestLibCoreStream.cpp +++ b/Tests/LibCore/TestLibCoreStream.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -717,117 +716,3 @@ TEST_CASE(allocating_memory_stream_10kb) offset += file_span.size(); } } - -// Bit stream tests - -// Note: This does not do any checks on the internal representation, it just ensures that the behavior of the input and output streams match. -TEST_CASE(little_endian_bit_stream_input_output_match) -{ - auto memory_stream = make(); - - // Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks, - // so testing with sizes that will not trigger a write will yield unexpected results. - auto bit_write_stream = MUST(Core::Stream::LittleEndianOutputBitStream::construct(MaybeOwned(*memory_stream))); - auto bit_read_stream = MUST(Core::Stream::LittleEndianInputBitStream::construct(MaybeOwned(*memory_stream))); - - // Test two mirrored chunks of a fully mirrored pattern to check that we are not dropping bits. - { - MUST(bit_write_stream->write_bits(0b1111u, 4)); - MUST(bit_write_stream->write_bits(0b1111u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1111u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1111u, result); - } - { - MUST(bit_write_stream->write_bits(0b0000u, 4)); - MUST(bit_write_stream->write_bits(0b0000u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b0000u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b0000u, result); - } - - // Test two mirrored chunks of a non-mirrored pattern to check that we are writing bits within a pattern in the correct order. - { - MUST(bit_write_stream->write_bits(0b1000u, 4)); - MUST(bit_write_stream->write_bits(0b1000u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1000u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1000u, result); - } - - // Test two different chunks to check that we are not confusing their order. - { - MUST(bit_write_stream->write_bits(0b1000u, 4)); - MUST(bit_write_stream->write_bits(0b0100u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1000u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b0100u, result); - } - - // Test a pattern that spans multiple bytes. - { - MUST(bit_write_stream->write_bits(0b1101001000100001u, 16)); - auto result = MUST(bit_read_stream->read_bits(16)); - EXPECT_EQ(0b1101001000100001u, result); - } -} - -// Note: This does not do any checks on the internal representation, it just ensures that the behavior of the input and output streams match. -TEST_CASE(big_endian_bit_stream_input_output_match) -{ - auto memory_stream = make(); - - // Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks, - // so testing with sizes that will not trigger a write will yield unexpected results. - auto bit_write_stream = MUST(Core::Stream::BigEndianOutputBitStream::construct(MaybeOwned(*memory_stream))); - auto bit_read_stream = MUST(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned(*memory_stream))); - - // Test two mirrored chunks of a fully mirrored pattern to check that we are not dropping bits. - { - MUST(bit_write_stream->write_bits(0b1111u, 4)); - MUST(bit_write_stream->write_bits(0b1111u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1111u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1111u, result); - } - { - MUST(bit_write_stream->write_bits(0b0000u, 4)); - MUST(bit_write_stream->write_bits(0b0000u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b0000u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b0000u, result); - } - - // Test two mirrored chunks of a non-mirrored pattern to check that we are writing bits within a pattern in the correct order. - { - MUST(bit_write_stream->write_bits(0b1000u, 4)); - MUST(bit_write_stream->write_bits(0b1000u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1000u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1000u, result); - } - - // Test two different chunks to check that we are not confusing their order. - { - MUST(bit_write_stream->write_bits(0b1000u, 4)); - MUST(bit_write_stream->write_bits(0b0100u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1000u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b0100u, result); - } - - // Test a pattern that spans multiple bytes. - { - MUST(bit_write_stream->write_bits(0b1101001000100001u, 16)); - auto result = MUST(bit_read_stream->read_bits(16)); - EXPECT_EQ(0b1101001000100001u, result); - } -} -- cgit v1.2.3