mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
Tests: Add a test to codify BitStream behavior beyond stream limits
This commit is contained in:
parent
de49413bdf
commit
270b1176de
Notes:
sideshowbarker
2024-07-17 04:01:41 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/270b1176de Pull-request: https://github.com/SerenityOS/serenity/pull/21890 Issue: https://github.com/SerenityOS/serenity/issues/21869 Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/LucasChollet Reviewed-by: https://github.com/trflynn89
1 changed files with 47 additions and 0 deletions
|
@ -132,6 +132,53 @@ TEST_CASE(big_endian_bit_stream_input_output_match)
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE(bit_reads_beyond_stream_limits)
|
||||
{
|
||||
Array<u8, 1> const test_data { 0xFF };
|
||||
|
||||
{
|
||||
// LittleEndianInputBitStream allows reading null bits beyond the original data
|
||||
// for compatibility purposes.
|
||||
auto memory_stream = make<FixedMemoryStream>(test_data);
|
||||
auto bit_stream = make<LittleEndianInputBitStream>(move(memory_stream));
|
||||
|
||||
{
|
||||
auto result = TRY_OR_FAIL(bit_stream->read_bits<u8>(6));
|
||||
EXPECT_EQ(result, 0b111111);
|
||||
}
|
||||
|
||||
{
|
||||
auto result = TRY_OR_FAIL(bit_stream->read_bits<u8>(6));
|
||||
EXPECT_EQ(result, 0b000011);
|
||||
}
|
||||
|
||||
{
|
||||
auto result = TRY_OR_FAIL(bit_stream->read_bits<u8>(6));
|
||||
EXPECT_EQ(result, 0b000000);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto memory_stream = make<FixedMemoryStream>(test_data);
|
||||
auto bit_stream = make<BigEndianInputBitStream>(move(memory_stream));
|
||||
|
||||
{
|
||||
auto result = TRY_OR_FAIL(bit_stream->read_bits<u8>(6));
|
||||
EXPECT_EQ(result, 0b111111);
|
||||
}
|
||||
|
||||
{
|
||||
auto result = bit_stream->read_bits<u8>(6);
|
||||
EXPECT(result.is_error());
|
||||
}
|
||||
|
||||
{
|
||||
auto result = bit_stream->read_bits<u8>(6);
|
||||
EXPECT(result.is_error());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RANDOMIZED_TEST_CASE(roundtrip_u8_little_endian)
|
||||
{
|
||||
GEN(n, Gen::unsigned_int(NumericLimits<u8>::max()));
|
||||
|
|
Loading…
Add table
Reference in a new issue