From 6d15318560648a5c3d0161967348849ac1198270 Mon Sep 17 00:00:00 2001 From: asynts Date: Wed, 12 Aug 2020 11:17:02 +0200 Subject: [PATCH] AK: Remove fatal() from InputStream. Fatal errors can not be handeled and lead to an assertion error when the stream is destroyed. It makes no sense to delay the assertion failure, instead of setting m_fatal, an assertion should be done directly. --- AK/Stream.h | 4 +--- AK/Tests/TestStream.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/AK/Stream.h b/AK/Stream.h index ff6d32d979..daa0c11227 100644 --- a/AK/Stream.h +++ b/AK/Stream.h @@ -37,17 +37,15 @@ class Stream { public: virtual ~Stream() { - ASSERT(!error() && !fatal()); + ASSERT(!error()); } bool error() const { return m_error; } - bool fatal() const { return m_fatal; } bool handle_error() { return exchange(m_error, false); } protected: mutable bool m_error { false }; - mutable bool m_fatal { false }; }; } diff --git a/AK/Tests/TestStream.cpp b/AK/Tests/TestStream.cpp index a8b581e988..09cc1ea259 100644 --- a/AK/Tests/TestStream.cpp +++ b/AK/Tests/TestStream.cpp @@ -48,7 +48,7 @@ TEST_CASE(read_an_integer) InputMemoryStream stream { { &expected, sizeof(expected) } }; stream >> actual; - EXPECT(!stream.error() && !stream.fatal() && stream.eof()); + EXPECT(!stream.error() && stream.eof()); EXPECT_EQ(expected, actual); } @@ -59,15 +59,15 @@ TEST_CASE(recoverable_error) InputMemoryStream stream { { &expected, sizeof(expected) } }; - EXPECT(!stream.error() && !stream.fatal() && !stream.eof()); + EXPECT(!stream.error() && !stream.eof()); stream >> to_large_value; - EXPECT(stream.error() && !stream.fatal() && !stream.eof()); + EXPECT(stream.error() && !stream.eof()); EXPECT(stream.handle_error()); - EXPECT(!stream.error() && !stream.fatal() && !stream.eof()); + EXPECT(!stream.error() && !stream.eof()); stream >> actual; - EXPECT(!stream.error() && !stream.fatal() && stream.eof()); + EXPECT(!stream.error() && stream.eof()); EXPECT_EQ(expected, actual); } @@ -78,7 +78,7 @@ TEST_CASE(chain_stream_operator) InputMemoryStream stream { { expected, sizeof(expected) } }; stream >> actual[0] >> actual[1] >> actual[2] >> actual[3]; - EXPECT(!stream.error() && !stream.fatal() && stream.eof()); + EXPECT(!stream.error() && stream.eof()); EXPECT(compare({ expected, sizeof(expected) }, { actual, sizeof(actual) })); } @@ -94,17 +94,17 @@ TEST_CASE(seeking_slicing_offset) InputMemoryStream stream { { input, sizeof(input) } }; stream >> Bytes { actual0, sizeof(actual0) }; - EXPECT(!stream.error() && !stream.fatal() && !stream.eof()); + EXPECT(!stream.error() && !stream.eof()); EXPECT(compare({ expected0, sizeof(expected0) }, { actual0, sizeof(actual0) })); stream.seek(4); stream >> Bytes { actual1, sizeof(actual1) }; - EXPECT(!stream.error() && !stream.fatal() && stream.eof()); + EXPECT(!stream.error() && stream.eof()); EXPECT(compare({ expected1, sizeof(expected1) }, { actual1, sizeof(actual1) })); stream.seek(1); stream >> Bytes { actual2, sizeof(actual2) }; - EXPECT(!stream.error() && !stream.fatal() && !stream.eof()); + EXPECT(!stream.error() && !stream.eof()); EXPECT(compare({ expected2, sizeof(expected2) }, { actual2, sizeof(actual2) })); }