mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
AK: Remove the fallbile constructor from BigEndianOutputBitStream
This commit is contained in:
parent
261d62438f
commit
0fee97916b
2 changed files with 12 additions and 17 deletions
|
@ -225,9 +225,9 @@ private:
|
||||||
/// in big-endian order to another stream.
|
/// in big-endian order to another stream.
|
||||||
class BigEndianOutputBitStream : public Stream {
|
class BigEndianOutputBitStream : public Stream {
|
||||||
public:
|
public:
|
||||||
static ErrorOr<NonnullOwnPtr<BigEndianOutputBitStream>> construct(MaybeOwned<Stream> stream)
|
explicit BigEndianOutputBitStream(MaybeOwned<Stream> stream)
|
||||||
|
: m_stream(move(stream))
|
||||||
{
|
{
|
||||||
return adopt_nonnull_own_or_enomem<BigEndianOutputBitStream>(new BigEndianOutputBitStream(move(stream)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ErrorOr<Bytes> read(Bytes) override
|
virtual ErrorOr<Bytes> read(Bytes) override
|
||||||
|
@ -294,11 +294,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BigEndianOutputBitStream(MaybeOwned<Stream> stream)
|
|
||||||
: m_stream(move(stream))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
MaybeOwned<Stream> m_stream;
|
MaybeOwned<Stream> m_stream;
|
||||||
u8 m_current_byte { 0 };
|
u8 m_current_byte { 0 };
|
||||||
size_t m_bit_offset { 0 };
|
size_t m_bit_offset { 0 };
|
||||||
|
|
|
@ -71,21 +71,21 @@ TEST_CASE(big_endian_bit_stream_input_output_match)
|
||||||
|
|
||||||
// Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks,
|
// 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.
|
// so testing with sizes that will not trigger a write will yield unexpected results.
|
||||||
auto bit_write_stream = MUST(BigEndianOutputBitStream::construct(MaybeOwned<AK::Stream>(*memory_stream)));
|
BigEndianOutputBitStream bit_write_stream { MaybeOwned<AK::Stream>(*memory_stream) };
|
||||||
BigEndianInputBitStream bit_read_stream { MaybeOwned<AK::Stream>(*memory_stream) };
|
BigEndianInputBitStream bit_read_stream { MaybeOwned<AK::Stream>(*memory_stream) };
|
||||||
|
|
||||||
// Test two mirrored chunks of a fully mirrored pattern to check that we are not dropping bits.
|
// 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));
|
||||||
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));
|
auto result = MUST(bit_read_stream.read_bits(4));
|
||||||
EXPECT_EQ(0b1111u, result);
|
EXPECT_EQ(0b1111u, result);
|
||||||
result = MUST(bit_read_stream.read_bits(4));
|
result = MUST(bit_read_stream.read_bits(4));
|
||||||
EXPECT_EQ(0b1111u, result);
|
EXPECT_EQ(0b1111u, result);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
MUST(bit_write_stream->write_bits(0b0000u, 4));
|
MUST(bit_write_stream.write_bits(0b0000u, 4));
|
||||||
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));
|
auto result = MUST(bit_read_stream.read_bits(4));
|
||||||
EXPECT_EQ(0b0000u, result);
|
EXPECT_EQ(0b0000u, result);
|
||||||
result = MUST(bit_read_stream.read_bits(4));
|
result = MUST(bit_read_stream.read_bits(4));
|
||||||
|
@ -94,8 +94,8 @@ TEST_CASE(big_endian_bit_stream_input_output_match)
|
||||||
|
|
||||||
// Test two mirrored chunks of a non-mirrored pattern to check that we are writing bits within a pattern in the correct order.
|
// 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));
|
||||||
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));
|
auto result = MUST(bit_read_stream.read_bits(4));
|
||||||
EXPECT_EQ(0b1000u, result);
|
EXPECT_EQ(0b1000u, result);
|
||||||
result = MUST(bit_read_stream.read_bits(4));
|
result = MUST(bit_read_stream.read_bits(4));
|
||||||
|
@ -104,8 +104,8 @@ TEST_CASE(big_endian_bit_stream_input_output_match)
|
||||||
|
|
||||||
// Test two different chunks to check that we are not confusing their order.
|
// 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(0b1000u, 4));
|
||||||
MUST(bit_write_stream->write_bits(0b0100u, 4));
|
MUST(bit_write_stream.write_bits(0b0100u, 4));
|
||||||
auto result = MUST(bit_read_stream.read_bits(4));
|
auto result = MUST(bit_read_stream.read_bits(4));
|
||||||
EXPECT_EQ(0b1000u, result);
|
EXPECT_EQ(0b1000u, result);
|
||||||
result = MUST(bit_read_stream.read_bits(4));
|
result = MUST(bit_read_stream.read_bits(4));
|
||||||
|
@ -114,7 +114,7 @@ TEST_CASE(big_endian_bit_stream_input_output_match)
|
||||||
|
|
||||||
// Test a pattern that spans multiple bytes.
|
// Test a pattern that spans multiple bytes.
|
||||||
{
|
{
|
||||||
MUST(bit_write_stream->write_bits(0b1101001000100001u, 16));
|
MUST(bit_write_stream.write_bits(0b1101001000100001u, 16));
|
||||||
auto result = MUST(bit_read_stream.read_bits(16));
|
auto result = MUST(bit_read_stream.read_bits(16));
|
||||||
EXPECT_EQ(0b1101001000100001u, result);
|
EXPECT_EQ(0b1101001000100001u, result);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue