Bump version to 19.1.0-rc3
[llvm-project.git] / llvm / unittests / Support / ELFAttributeParserTest.cpp
blob38e7b09cc3c7d593ce11157af2407e6444328fbc
1 //===----- unittests/ELFAttributeParserTest.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/Support/ELFAttributeParser.h"
10 #include "llvm/Support/ELFAttributes.h"
11 #include "gtest/gtest.h"
12 #include <string>
14 using namespace llvm;
16 static const TagNameMap emptyTagNameMap;
18 // This class is used to test the common part of the ELF attribute section.
19 class AttributeHeaderParser : public ELFAttributeParser {
20 Error handler(uint64_t tag, bool &handled) override {
21 // Treat all attributes as handled.
22 handled = true;
23 return Error::success();
26 public:
27 AttributeHeaderParser(ScopedPrinter *printer)
28 : ELFAttributeParser(printer, emptyTagNameMap, "test") {}
29 AttributeHeaderParser() : ELFAttributeParser(emptyTagNameMap, "test") {}
32 static void testParseError(ArrayRef<uint8_t> bytes, const char *msg) {
33 AttributeHeaderParser parser;
34 Error e = parser.parse(bytes, llvm::endianness::little);
35 EXPECT_STREQ(toString(std::move(e)).c_str(), msg);
38 TEST(AttributeHeaderParser, UnrecognizedFormatVersion) {
39 static const uint8_t bytes[] = {1};
40 testParseError(bytes, "unrecognized format-version: 0x1");
43 TEST(AttributeHeaderParser, InvalidSectionLength) {
44 static const uint8_t bytes[] = {'A', 3, 0, 0, 0};
45 testParseError(bytes, "invalid section length 3 at offset 0x1");
48 TEST(AttributeHeaderParser, UnrecognizedTag) {
49 static const uint8_t bytes[] = {'A', 14, 0, 0, 0, 't', 'e', 's',
50 't', 0, 4, 5, 0, 0, 0};
51 testParseError(bytes, "unrecognized tag 0x4 at offset 0xa");
54 TEST(AttributeHeaderParser, InvalidAttributeSize) {
55 static const uint8_t bytes[] = {'A', 14, 0, 0, 0, 't', 'e', 's',
56 't', 0, 1, 4, 0, 0, 0};
57 testParseError(bytes, "invalid attribute size 4 at offset 0xa");