1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:27:45 +00:00

AK: Deprecate the old AK::Stream

This also removes a few cases where the respective header wasn't
actually required to be included.
This commit is contained in:
Tim Schumacher 2023-01-20 14:07:24 +01:00 committed by Andrew Kaster
parent 230cb3b0cb
commit ae64b68717
38 changed files with 116 additions and 120 deletions

View file

@ -18,6 +18,7 @@ set(AK_TEST_SOURCES
TestCircularDeque.cpp
TestCircularQueue.cpp
TestComplex.cpp
TestDeprecatedMemoryStream.cpp
TestDeprecatedString.cpp
TestDisjointChunks.cpp
TestDistinctNumeric.cpp
@ -48,7 +49,6 @@ set(AK_TEST_SOURCES
TestLexicalPath.cpp
TestMACAddress.cpp
TestMemory.cpp
TestMemoryStream.cpp
TestNeverDestroyed.cpp
TestNonnullRefPtr.cpp
TestNumberFormat.cpp

View file

@ -7,13 +7,13 @@
#include <LibTest/TestCase.h>
#include <AK/Array.h>
#include <AK/MemoryStream.h>
#include <AK/DeprecatedMemoryStream.h>
TEST_CASE(read_an_integer)
{
u32 expected = 0x01020304, actual;
InputMemoryStream stream { { &expected, sizeof(expected) } };
DeprecatedInputMemoryStream stream { { &expected, sizeof(expected) } };
stream >> actual;
EXPECT(!stream.has_any_error() && stream.eof());
@ -24,7 +24,7 @@ TEST_CASE(read_a_bool)
{
bool expected = true, actual;
InputMemoryStream stream { { &expected, sizeof(expected) } };
DeprecatedInputMemoryStream stream { { &expected, sizeof(expected) } };
stream >> actual;
EXPECT(!stream.has_any_error() && stream.eof());
@ -35,7 +35,7 @@ TEST_CASE(read_a_double)
{
double expected = 3.141592653589793, actual;
InputMemoryStream stream { { &expected, sizeof(expected) } };
DeprecatedInputMemoryStream stream { { &expected, sizeof(expected) } };
stream >> actual;
EXPECT(!stream.has_any_error() && stream.eof());
@ -47,7 +47,7 @@ TEST_CASE(recoverable_error)
u32 expected = 0x01020304, actual = 0;
u64 to_large_value = 0;
InputMemoryStream stream { { &expected, sizeof(expected) } };
DeprecatedInputMemoryStream stream { { &expected, sizeof(expected) } };
EXPECT(!stream.has_any_error() && !stream.eof());
stream >> to_large_value;
@ -66,7 +66,7 @@ TEST_CASE(chain_stream_operator)
Array<u8, 4> const expected { 0, 1, 2, 3 };
Array<u8, 4> actual;
InputMemoryStream stream { expected };
DeprecatedInputMemoryStream stream { expected };
stream >> actual[0] >> actual[1] >> actual[2] >> actual[3];
EXPECT(!stream.has_any_error() && stream.eof());
@ -83,7 +83,7 @@ TEST_CASE(seeking_slicing_offset)
Array<u8, 4> actual0 {}, actual1 {}, actual2 {};
InputMemoryStream stream { input };
DeprecatedInputMemoryStream stream { input };
stream >> actual0;
EXPECT(!stream.has_any_error() && !stream.eof());
@ -103,7 +103,7 @@ TEST_CASE(seeking_slicing_offset)
TEST_CASE(read_endian_values)
{
Array<u8, 8> const input { 0, 1, 2, 3, 4, 5, 6, 7 };
InputMemoryStream stream { input };
DeprecatedInputMemoryStream stream { input };
LittleEndian<u32> value1;
BigEndian<u32> value2;
@ -116,7 +116,7 @@ TEST_CASE(read_endian_values)
TEST_CASE(new_output_memory_stream)
{
Array<u8, 16> buffer;
OutputMemoryStream stream { buffer };
DeprecatedOutputMemoryStream stream { buffer };
EXPECT_EQ(stream.size(), 0u);
EXPECT_EQ(stream.remaining(), 16u);

View file

@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedMemoryStream.h>
#include <AK/LEB128.h>
#include <AK/MemoryStream.h>
#include <AK/NumericLimits.h>
#include <LibTest/TestCase.h>
@ -14,7 +14,7 @@ TEST_CASE(single_byte)
u32 output = {};
i32 output_signed = {};
u8 buf[] = { 0x00 };
InputMemoryStream stream({ buf, sizeof(buf) });
DeprecatedInputMemoryStream stream({ buf, sizeof(buf) });
// less than/eq 0b0011_1111, signed == unsigned == raw byte
for (u8 i = 0u; i <= 0x3F; ++i) {
@ -64,7 +64,7 @@ TEST_CASE(two_bytes)
u32 output = {};
i32 output_signed = {};
u8 buf[] = { 0x00, 0x1 };
InputMemoryStream stream({ buf, sizeof(buf) });
DeprecatedInputMemoryStream stream({ buf, sizeof(buf) });
// Only test with first byte expecting more, otherwise equivalent to single byte case
for (u16 i = 0x80; i <= 0xFF; ++i) {
@ -120,7 +120,7 @@ TEST_CASE(overflow_sizeof_output_unsigned)
u8 u32_max_plus_one[] = { 0x80, 0x80, 0x80, 0x80, 0x10 };
{
u32 out = 0;
InputMemoryStream stream({ u32_max_plus_one, sizeof(u32_max_plus_one) });
DeprecatedInputMemoryStream stream({ u32_max_plus_one, sizeof(u32_max_plus_one) });
EXPECT(!LEB128::read_unsigned(stream, out));
EXPECT_EQ(out, 0u);
EXPECT(!stream.handle_any_error());
@ -135,7 +135,7 @@ TEST_CASE(overflow_sizeof_output_unsigned)
u8 u32_max[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x0F };
{
u32 out = 0;
InputMemoryStream stream({ u32_max, sizeof(u32_max) });
DeprecatedInputMemoryStream stream({ u32_max, sizeof(u32_max) });
EXPECT(LEB128::read_unsigned(stream, out));
EXPECT_EQ(out, NumericLimits<u32>::max());
EXPECT(!stream.handle_any_error());
@ -153,7 +153,7 @@ TEST_CASE(overflow_sizeof_output_signed)
u8 i32_max_plus_one[] = { 0x80, 0x80, 0x80, 0x80, 0x08 };
{
i32 out = 0;
InputMemoryStream stream({ i32_max_plus_one, sizeof(i32_max_plus_one) });
DeprecatedInputMemoryStream stream({ i32_max_plus_one, sizeof(i32_max_plus_one) });
EXPECT(!LEB128::read_signed(stream, out));
EXPECT_EQ(out, 0);
EXPECT(!stream.handle_any_error());
@ -168,7 +168,7 @@ TEST_CASE(overflow_sizeof_output_signed)
u8 i32_max[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x07 };
{
i32 out = 0;
InputMemoryStream stream({ i32_max, sizeof(i32_max) });
DeprecatedInputMemoryStream stream({ i32_max, sizeof(i32_max) });
EXPECT(LEB128::read_signed(stream, out));
EXPECT_EQ(out, NumericLimits<i32>::max());
EXPECT(!stream.handle_any_error());
@ -183,7 +183,7 @@ TEST_CASE(overflow_sizeof_output_signed)
u8 i32_min_minus_one[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x77 };
{
i32 out = 0;
InputMemoryStream stream({ i32_min_minus_one, sizeof(i32_min_minus_one) });
DeprecatedInputMemoryStream stream({ i32_min_minus_one, sizeof(i32_min_minus_one) });
EXPECT(!LEB128::read_signed(stream, out));
EXPECT_EQ(out, 0);
EXPECT(!stream.handle_any_error());
@ -198,7 +198,7 @@ TEST_CASE(overflow_sizeof_output_signed)
u8 i32_min[] = { 0x80, 0x80, 0x80, 0x80, 0x78 };
{
i32 out = 0;
InputMemoryStream stream({ i32_min, sizeof(i32_min) });
DeprecatedInputMemoryStream stream({ i32_min, sizeof(i32_min) });
EXPECT(LEB128::read_signed(stream, out));
EXPECT_EQ(out, NumericLimits<i32>::min());
EXPECT(!stream.handle_any_error());

View file

@ -7,7 +7,6 @@
#include <LibTest/TestCase.h>
#include <AK/Array.h>
#include <AK/MemoryStream.h>
#include <AK/Random.h>
#include <LibCompress/Deflate.h>
#include <LibCore/BitStream.h>