xref: /llvm-project/lldb/unittests/TestingSupport/TestUtilities.h (revision 388548359f5049b88a9738d8a9e67691503fbdef)
1 //===- TestUtilities.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 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_UNITTESTS_TESTINGSUPPORT_TESTUTILITIES_H
10 #define LLDB_UNITTESTS_TESTINGSUPPORT_TESTUTILITIES_H
11 
12 #include "lldb/Core/ModuleSpec.h"
13 #include "lldb/Utility/DataBuffer.h"
14 #include "llvm/ADT/SmallString.h"
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/Support/Error.h"
17 #include "llvm/Support/FileUtilities.h"
18 #include <string>
19 
20 #define ASSERT_NO_ERROR(x)                                                     \
21   if (std::error_code ASSERT_NO_ERROR_ec = x) {                                \
22     llvm::SmallString<128> MessageStorage;                                     \
23     llvm::raw_svector_ostream Message(MessageStorage);                         \
24     Message << #x ": did not return errc::success.\n"                          \
25             << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n"          \
26             << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n";      \
27     GTEST_FATAL_FAILURE_(MessageStorage.c_str());                              \
28   } else {                                                                     \
29   }
30 
31 namespace lldb_private {
32 std::string GetInputFilePath(const llvm::Twine &name);
33 
34 class TestUtilities {
35 public:
36   static std::once_flag g_debugger_initialize_flag;
37 };
38 
39 class TestFile {
40 public:
41   static llvm::Expected<TestFile> fromYaml(llvm::StringRef Yaml);
42   static llvm::Expected<TestFile> fromYamlFile(const llvm::Twine &Name);
43 
moduleSpec()44   ModuleSpec moduleSpec() {
45     return ModuleSpec(FileSpec(), UUID(), dataBuffer());
46   }
47 
48 private:
TestFile(std::string && Buffer)49   TestFile(std::string &&Buffer) : Buffer(std::move(Buffer)) {}
50 
dataBuffer()51   lldb::DataBufferSP dataBuffer() {
52     auto *Data = reinterpret_cast<const uint8_t *>(Buffer.data());
53     return std::make_shared<DataBufferUnowned>(const_cast<uint8_t *>(Data),
54                                                Buffer.size());
55   }
56 
57   std::string Buffer;
58 };
59 } // namespace lldb_private
60 
61 #endif
62