[AArch64] Fix SDNode type mismatches between *.td files and ISel (#116523)
[llvm-project.git] / llvm / unittests / Object / ArchiveTest.cpp
blobb4f2192ad31ac4594303acbf0b5caee53144ce67
1 //===- ArchiveTest.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 //===----------------------------------------------------------------------===//
9 #include "llvm/Object/Archive.h"
10 #include "llvm/Testing/Support/Error.h"
11 #include "gtest/gtest.h"
13 using namespace llvm;
14 using namespace object;
15 using namespace testing;
17 static const char ArchiveWithMember[] = "!<arch>\n" // Global header
18 "test/ " // Member name
19 "0 " // Timestamp
20 "0 " // Owner ID
21 "0 " // Group ID
22 "0 " // File mode
23 "9999999999" // Size
24 "`\n";
26 static const char ThinArchiveWithMember[] = "!<thin>\n" // Global header
27 "test/ " // Member name
28 "0 " // Timestamp
29 "0 " // Owner ID
30 "0 " // Group ID
31 "0 " // File mode
32 "9999999999" // Size
33 "`\n";
35 static const uint64_t MemberSize = 9999999999ull;
37 struct ArchiveTestsFixture : Test {
38 Expected<Archive::child_iterator> createChild(StringRef Src) {
39 MemoryBufferRef Source(Src, "archive");
40 Expected<std::unique_ptr<Archive>> AOrErr = Archive::create(Source);
41 if (!AOrErr)
42 return AOrErr.takeError();
43 A = std::move(*AOrErr);
45 Error ChildErr = Error::success();
46 auto Child = A->child_begin(ChildErr);
47 if (ChildErr)
48 return std::move(ChildErr);
49 return Child;
52 std::unique_ptr<Archive> A;
55 TEST_F(ArchiveTestsFixture, ArchiveChildGetSizeRegularArchive) {
56 // This test relies on a StringRef being able to hold the appropriate amount
57 // of data.
58 if (std::numeric_limits<StringRef::size_type>::max() < MemberSize)
59 GTEST_SKIP();
61 auto Child = createChild(ArchiveWithMember);
62 ASSERT_THAT_EXPECTED(Child, Succeeded());
64 Expected<uint64_t> Size = (*Child)->getSize();
65 ASSERT_THAT_EXPECTED(Size, Succeeded());
66 EXPECT_EQ(MemberSize, *Size);
69 TEST_F(ArchiveTestsFixture, ArchiveChildGetSizeThinArchive) {
70 auto Child = createChild(ThinArchiveWithMember);
71 ASSERT_THAT_EXPECTED(Child, Succeeded());
73 Expected<uint64_t> Size = (*Child)->getSize();
74 ASSERT_THAT_EXPECTED(Size, Succeeded());
75 EXPECT_EQ(MemberSize, *Size);
78 TEST_F(ArchiveTestsFixture, ArchiveChildGetBuffer) {
79 // This test relies on a StringRef being able to hold the appropriate amount
80 // of data.
81 if (std::numeric_limits<StringRef::size_type>::max() < MemberSize)
82 GTEST_SKIP();
84 auto Child = createChild(ArchiveWithMember);
85 ASSERT_THAT_EXPECTED(Child, Succeeded());
87 Expected<StringRef> Buffer = (*Child)->getBuffer();
88 // Cannot use ASSERT_THAT_EXPECTED, as that will attempt to print the
89 // StringRef (which has an invalid size).
90 ASSERT_TRUE((bool)Buffer);
91 EXPECT_EQ(MemberSize, Buffer->size());
92 EXPECT_EQ(ArchiveWithMember + sizeof(ArchiveWithMember) - 1, Buffer->data());