[RDF] Add RegisterRef::idx and make toUnitId constexpr
[llvm-project.git] / libc / test / UnitTest / MemoryMatcher.h
blobe3df4c09315c9f336f4d01e633242a24a0a09599
1 //===-- MemoryMatcher.h -----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_UTILS_UNITTEST_MEMORY_MATCHER_H
10 #define LLVM_LIBC_UTILS_UNITTEST_MEMORY_MATCHER_H
12 #include "src/__support/CPP/span.h"
14 #include "test/UnitTest/Test.h"
16 namespace __llvm_libc {
17 namespace testing {
19 using MemoryView = __llvm_libc::cpp::span<const char>;
21 } // namespace testing
22 } // namespace __llvm_libc
24 #ifdef LIBC_COPT_TEST_USE_FUCHSIA
26 #define EXPECT_MEM_EQ(expected, actual) \
27 do { \
28 __llvm_libc::testing::MemoryView e = (expected); \
29 __llvm_libc::testing::MemoryView a = (actual); \
30 ASSERT_EQ(e.size(), a.size()); \
31 EXPECT_BYTES_EQ(e.data(), a.data(), e.size()); \
32 } while (0)
34 #define ASSERT_MEM_EQ(expected, actual) \
35 do { \
36 __llvm_libc::testing::MemoryView e = (expected); \
37 __llvm_libc::testing::MemoryView a = (actual); \
38 ASSERT_EQ(e.size(), a.size()); \
39 ASSERT_BYTES_EQ(e.data(), a.data(), e.size()); \
40 } while (0)
42 #else
44 namespace __llvm_libc::testing {
46 class MemoryMatcher : public Matcher<MemoryView> {
47 MemoryView expected;
48 MemoryView actual;
49 bool mismatch_size = false;
50 size_t mismatch_index = -1;
52 public:
53 MemoryMatcher(MemoryView expectedValue) : expected(expectedValue) {}
55 bool match(MemoryView actualValue);
57 void explainError() override;
60 } // namespace __llvm_libc::testing
62 #define EXPECT_MEM_EQ(expected, actual) \
63 EXPECT_THAT(actual, __llvm_libc::testing::MemoryMatcher(expected))
64 #define ASSERT_MEM_EQ(expected, actual) \
65 ASSERT_THAT(actual, __llvm_libc::testing::MemoryMatcher(expected))
67 #endif
69 #endif // LLVM_LIBC_UTILS_UNITTEST_MEMORY_MATCHER_H