[InstCombine] Signed saturation tests. NFC
[llvm-complete.git] / unittests / ObjectYAML / YAML2ObjTest.cpp
blob8fafca4f908f80cc931d9ef26f47c7cff92aae86
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 //===----------------------------------------------------------------------===//
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"
17 using namespace llvm;
18 using namespace object;
19 using namespace yaml;
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"(
27 --- !ELF
28 FileHeader:
29 Class: ELFCLASS64
30 Data: ELFDATA2LSB
31 Type: ET_REL
32 Machine: EM_X86_64)", ErrHandler);
34 ASSERT_FALSE(ErrorReported);
35 ASSERT_TRUE(Obj);
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;
47 StringRef Yaml = R"(
48 --- !ELF
49 FileHeader:
50 Class: ELFCLASS64
51 Data: ELFDATA2LSB
52 Type: ET_REL
53 Machine: EM_X86_64
54 Symbols:
55 - Name: foo
56 - Name: foo
57 - Name: foo
58 )";
60 // 1. Test yaml2ObjectFile().
62 std::unique_ptr<ObjectFile> Obj = yaml2ObjectFile(Storage, Yaml, ErrHandler);
64 ASSERT_FALSE(Obj);
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().
71 Errors.clear();
72 Storage.clear();
73 raw_svector_ostream OS(Storage);
75 yaml::Input YIn(Yaml);
76 bool Res = convertYAML(YIn, OS, ErrHandler);
77 ASSERT_FALSE(Res);
78 ASSERT_TRUE(Errors.size() == 2);
79 ASSERT_TRUE(Errors[0] == "ObjectYAML: repeated symbol name: 'foo'");
80 ASSERT_TRUE(Errors[1] == Errors[0]);