1 | //===-- DataBufferTest.cpp ------------------------------------------------===// |
---|---|
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 "gtest/gtest.h" |
10 | |
11 | #include "lldb/Utility/DataBuffer.h" |
12 | #include "lldb/Utility/DataBufferHeap.h" |
13 | #include "lldb/Utility/DataBufferLLVM.h" |
14 | |
15 | #include "llvm/Support/Casting.h" |
16 | #include "llvm/Support/MemoryBuffer.h" |
17 | |
18 | using namespace lldb_private; |
19 | using namespace lldb; |
20 | |
21 | TEST(DataBufferTest, RTTI) { |
22 | { |
23 | DataBufferSP data_buffer_sp = std::make_shared<DataBufferHeap>(); |
24 | DataBuffer *data_buffer = data_buffer_sp.get(); |
25 | |
26 | EXPECT_TRUE(llvm::isa<DataBuffer>(data_buffer)); |
27 | EXPECT_TRUE(llvm::isa<WritableDataBuffer>(data_buffer)); |
28 | EXPECT_TRUE(llvm::isa<DataBufferHeap>(data_buffer)); |
29 | EXPECT_FALSE(llvm::isa<DataBufferLLVM>(data_buffer)); |
30 | } |
31 | |
32 | { |
33 | llvm::StringRef data; |
34 | DataBufferSP data_buffer_sp = std::make_shared<DataBufferLLVM>( |
35 | args: llvm::MemoryBuffer::getMemBufferCopy(InputData: data)); |
36 | DataBuffer *data_buffer = data_buffer_sp.get(); |
37 | |
38 | EXPECT_TRUE(llvm::isa<DataBuffer>(data_buffer)); |
39 | EXPECT_TRUE(llvm::isa<DataBufferLLVM>(data_buffer)); |
40 | EXPECT_FALSE(llvm::isa<WritableDataBuffer>(data_buffer)); |
41 | EXPECT_FALSE(llvm::isa<WritableDataBufferLLVM>(data_buffer)); |
42 | EXPECT_FALSE(llvm::isa<DataBufferHeap>(data_buffer)); |
43 | } |
44 | |
45 | { |
46 | DataBufferSP data_buffer_sp = std::make_shared<WritableDataBufferLLVM>( |
47 | args: llvm::WritableMemoryBuffer::getNewMemBuffer(Size: 1)); |
48 | DataBuffer *data_buffer = data_buffer_sp.get(); |
49 | |
50 | EXPECT_TRUE(llvm::isa<DataBuffer>(data_buffer)); |
51 | EXPECT_TRUE(llvm::isa<WritableDataBuffer>(data_buffer)); |
52 | EXPECT_TRUE(llvm::isa<WritableDataBufferLLVM>(data_buffer)); |
53 | EXPECT_FALSE(llvm::isa<DataBufferLLVM>(data_buffer)); |
54 | EXPECT_FALSE(llvm::isa<DataBufferHeap>(data_buffer)); |
55 | } |
56 | } |
57 |