TestByteBuffer.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibTest/TestCase.h>
  7. #include <AK/ByteBuffer.h>
  8. TEST_CASE(equality_operator)
  9. {
  10. ByteBuffer a = ByteBuffer::copy("Hello, world", 7).release_value();
  11. ByteBuffer b = ByteBuffer::copy("Hello, friend", 7).release_value();
  12. // `a` and `b` are both "Hello, ".
  13. ByteBuffer c = ByteBuffer::copy("asdf", 4).release_value();
  14. ByteBuffer d;
  15. EXPECT_EQ(a == a, true);
  16. EXPECT_EQ(a == b, true);
  17. EXPECT_EQ(a == c, false);
  18. EXPECT_EQ(a == d, false);
  19. EXPECT_EQ(b == a, true);
  20. EXPECT_EQ(b == b, true);
  21. EXPECT_EQ(b == c, false);
  22. EXPECT_EQ(b == d, false);
  23. EXPECT_EQ(c == a, false);
  24. EXPECT_EQ(c == b, false);
  25. EXPECT_EQ(c == c, true);
  26. EXPECT_EQ(c == d, false);
  27. EXPECT_EQ(d == a, false);
  28. EXPECT_EQ(d == b, false);
  29. EXPECT_EQ(d == c, false);
  30. EXPECT_EQ(d == d, true);
  31. }
  32. /*
  33. * FIXME: These `negative_*` tests should cause precisely one compilation error
  34. * each, and always for the specified reason. Currently we do not have a harness
  35. * for that, so in order to run the test you need to set the #define to 1, compile
  36. * it, and check the error messages manually.
  37. */
  38. #define COMPILE_NEGATIVE_TESTS 0
  39. #if COMPILE_NEGATIVE_TESTS
  40. TEST_CASE(negative_operator_lt)
  41. {
  42. ByteBuffer a = ByteBuffer::copy("Hello, world", 10);
  43. ByteBuffer b = ByteBuffer::copy("Hello, friend", 10);
  44. [[maybe_unused]] auto res = a < b;
  45. // error: error: use of deleted function ‘bool AK::ByteBuffer::operator<(const AK::ByteBuffer&) const’
  46. }
  47. #endif /* COMPILE_NEGATIVE_TESTS */