1 //===-- MemoryMatcher.cpp ---------------------------------------*- 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 //===----------------------------------------------------------------------===//
8 
9 #include "MemoryMatcher.h"
10 
11 namespace __llvm_libc {
12 namespace memory {
13 namespace testing {
14 
match(MemoryView actualValue)15 bool MemoryMatcher::match(MemoryView actualValue) {
16   actual = actualValue;
17   return expected.equals(actual);
18 }
19 
display(testutils::StreamWrapper & Stream,char C)20 void display(testutils::StreamWrapper &Stream, char C) {
21   const auto print = [&Stream](unsigned char I) {
22     Stream << static_cast<char>(I < 10 ? '0' + I : 'A' + I - 10);
23   };
24   print(static_cast<unsigned char>(C) / 16);
25   print(static_cast<unsigned char>(C) & 15);
26 }
27 
display(testutils::StreamWrapper & Stream,MemoryView View)28 void display(testutils::StreamWrapper &Stream, MemoryView View) {
29   for (auto C : View) {
30     Stream << ' ';
31     display(Stream, C);
32   }
33 }
34 
explainError(testutils::StreamWrapper & Stream)35 void MemoryMatcher::explainError(testutils::StreamWrapper &Stream) {
36   Stream << "expected :";
37   display(Stream, expected);
38   Stream << '\n';
39   Stream << "actual   :";
40   display(Stream, actual);
41   Stream << '\n';
42 }
43 
44 } // namespace testing
45 } // namespace memory
46 } // namespace __llvm_libc
47