1 //===-- MemoryMatcher.cpp ---------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "MemoryMatcher.h"
11 #include "test/UnitTest/Test.h"
13 using LIBC_NAMESPACE::testing::tlog
;
15 namespace LIBC_NAMESPACE
{
19 bool equals(const cpp::span
<T
> &Span1
, const cpp::span
<T
> &Span2
,
20 bool &mismatch_size
, size_t &mismatch_index
) {
21 if (Span1
.size() != Span2
.size()) {
25 for (size_t Index
= 0; Index
< Span1
.size(); ++Index
)
26 if (Span1
[Index
] != Span2
[Index
]) {
27 mismatch_index
= Index
;
33 bool MemoryMatcher::match(MemoryView actualValue
) {
35 return equals(expected
, actual
, mismatch_size
, mismatch_index
);
38 static void display(char C
) {
39 const auto print
= [](unsigned char I
) {
40 tlog
<< static_cast<char>(I
< 10 ? '0' + I
: 'A' + I
- 10);
42 print(static_cast<unsigned char>(C
) / 16);
43 print(static_cast<unsigned char>(C
) & 15);
46 static void display(MemoryView View
) {
53 void MemoryMatcher::explainError() {
55 tlog
<< "Size mismatch :";
56 tlog
<< "expected : ";
57 tlog
<< expected
.size();
60 tlog
<< actual
.size();
63 tlog
<< "Mismatch at position : ";
64 tlog
<< mismatch_index
;
66 tlog
<< expected
.size();
77 } // namespace testing
78 } // namespace LIBC_NAMESPACE