1 //===- YAML2ObjTest.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 "llvm/ObjectYAML/yaml2obj.h"
10 #include "llvm/ADT/SmallString.h"
11 #include "llvm/Object/ObjectFile.h"
12 #include "llvm/Support/Error.h"
13 #include "llvm/Testing/Support/Error.h"
14 #include "gtest/gtest.h"
15 
16 using namespace llvm;
17 using namespace object;
18 using namespace yaml;
19 
20 TEST(yaml2ObjectFile, ELF) {
21   SmallString<0> Storage;
22   Expected<std::unique_ptr<ObjectFile>> ErrOrObj = yaml2ObjectFile(Storage, R"(
23 --- !ELF
24 FileHeader:
25   Class:    ELFCLASS64
26   Data:     ELFDATA2LSB
27   Type:     ET_REL
28   Machine:  EM_X86_64)");
29 
30   ASSERT_THAT_EXPECTED(ErrOrObj, Succeeded());
31 
32   std::unique_ptr<ObjectFile> ObjFile = std::move(ErrOrObj.get());
33 
34   ASSERT_TRUE(ObjFile->isELF());
35   ASSERT_TRUE(ObjFile->isRelocatableObject());
36 }
37