2020-08-17 01:33:50 +03:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-17 01:33:50 +03:00
|
|
|
|
*/
|
|
|
|
|
|
2021-04-25 08:53:23 +03:00
|
|
|
|
#include <LibTest/TestCase.h>
|
2020-08-17 01:33:50 +03:00
|
|
|
|
|
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
|
|
|
|
|
|
TEST_CASE(equality_operator)
|
|
|
|
|
{
|
2021-09-06 01:59:52 +03:00
|
|
|
|
ByteBuffer a = ByteBuffer::copy("Hello, world", 7).release_value();
|
|
|
|
|
ByteBuffer b = ByteBuffer::copy("Hello, friend", 7).release_value();
|
2020-08-17 01:33:50 +03:00
|
|
|
|
// `a` and `b` are both "Hello, ".
|
2021-09-06 01:59:52 +03:00
|
|
|
|
ByteBuffer c = ByteBuffer::copy("asdf", 4).release_value();
|
2020-08-17 01:33:50 +03:00
|
|
|
|
ByteBuffer d;
|
|
|
|
|
EXPECT_EQ(a == a, true);
|
|
|
|
|
EXPECT_EQ(a == b, true);
|
|
|
|
|
EXPECT_EQ(a == c, false);
|
|
|
|
|
EXPECT_EQ(a == d, false);
|
|
|
|
|
EXPECT_EQ(b == a, true);
|
|
|
|
|
EXPECT_EQ(b == b, true);
|
|
|
|
|
EXPECT_EQ(b == c, false);
|
|
|
|
|
EXPECT_EQ(b == d, false);
|
|
|
|
|
EXPECT_EQ(c == a, false);
|
|
|
|
|
EXPECT_EQ(c == b, false);
|
|
|
|
|
EXPECT_EQ(c == c, true);
|
|
|
|
|
EXPECT_EQ(c == d, false);
|
|
|
|
|
EXPECT_EQ(d == a, false);
|
|
|
|
|
EXPECT_EQ(d == b, false);
|
|
|
|
|
EXPECT_EQ(d == c, false);
|
|
|
|
|
EXPECT_EQ(d == d, true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-22 17:10:19 +03:00
|
|
|
|
/*
|
|
|
|
|
* FIXME: These `negative_*` tests should cause precisely one compilation error
|
|
|
|
|
* each, and always for the specified reason. Currently we do not have a harness
|
|
|
|
|
* for that, so in order to run the test you need to set the #define to 1, compile
|
|
|
|
|
* it, and check the error messages manually.
|
|
|
|
|
*/
|
|
|
|
|
#define COMPILE_NEGATIVE_TESTS 0
|
|
|
|
|
#if COMPILE_NEGATIVE_TESTS
|
|
|
|
|
TEST_CASE(negative_operator_lt)
|
2020-08-17 01:33:50 +03:00
|
|
|
|
{
|
2020-08-22 17:10:19 +03:00
|
|
|
|
ByteBuffer a = ByteBuffer::copy("Hello, world", 10);
|
|
|
|
|
ByteBuffer b = ByteBuffer::copy("Hello, friend", 10);
|
2020-12-21 02:09:48 +03:00
|
|
|
|
[[maybe_unused]] auto res = a < b;
|
2020-08-22 17:10:19 +03:00
|
|
|
|
// error: error: use of deleted function ‘bool AK::ByteBuffer::operator<(const AK::ByteBuffer&) const’
|
2020-08-17 01:33:50 +03:00
|
|
|
|
}
|
2020-08-22 17:10:19 +03:00
|
|
|
|
#endif /* COMPILE_NEGATIVE_TESTS */
|