1 //===- YAML2ObjTest.cpp --------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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/Support/YAMLTraits.h"
14 #include "llvm/Testing/Support/Error.h"
15 #include "gtest/gtest.h"
18 using namespace object
;
21 TEST(yaml2ObjectFile
, ELF
) {
22 bool ErrorReported
= false;
23 auto ErrHandler
= [&](const Twine
&Msg
) { ErrorReported
= true; };
25 SmallString
<0> Storage
;
26 std::unique_ptr
<ObjectFile
> Obj
= yaml2ObjectFile(Storage
, R
"(
32 Machine: EM_X86_64)", ErrHandler
);
34 ASSERT_FALSE(ErrorReported
);
36 ASSERT_TRUE(Obj
->isELF());
37 ASSERT_TRUE(Obj
->isRelocatableObject());
40 TEST(yaml2ObjectFile
, Errors
) {
41 std::vector
<std::string
> Errors
;
42 auto ErrHandler
= [&](const Twine
&Msg
) {
43 Errors
.push_back("ObjectYAML: " + Msg
.str());
46 SmallString
<0> Storage
;
60 // 1. Test yaml2ObjectFile().
62 std::unique_ptr
<ObjectFile
> Obj
= yaml2ObjectFile(Storage
, Yaml
, ErrHandler
);
65 ASSERT_TRUE(Errors
.size() == 2);
66 ASSERT_TRUE(Errors
[0] == "ObjectYAML: repeated symbol name: 'foo'");
67 ASSERT_TRUE(Errors
[1] == Errors
[0]);
69 // 2. Test convertYAML().
73 raw_svector_ostream
OS(Storage
);
75 yaml::Input
YIn(Yaml
);
76 bool Res
= convertYAML(YIn
, OS
, ErrHandler
);
78 ASSERT_TRUE(Errors
.size() == 2);
79 ASSERT_TRUE(Errors
[0] == "ObjectYAML: repeated symbol name: 'foo'");
80 ASSERT_TRUE(Errors
[1] == Errors
[0]);