1 //===----------- StringTableBuilderTest.cpp -------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/StringTableBuilder.h"
11 #include "llvm/Support/Endian.h"
12 #include "gtest/gtest.h"
19 TEST(StringTableBuilderTest, BasicELF) {
20 StringTableBuilder B(StringTableBuilder::ELF);
35 EXPECT_EQ(Expected, B.data());
36 EXPECT_EQ(1U, B.getOffset("foobar"));
37 EXPECT_EQ(4U, B.getOffset("bar"));
38 EXPECT_EQ(8U, B.getOffset("foo"));
41 TEST(StringTableBuilderTest, BasicWinCOFF) {
42 StringTableBuilder B(StringTableBuilder::WinCOFF);
44 // Strings must be 9 chars or longer to go in the table.
45 B.add("hippopotamus");
46 B.add("pygmy hippopotamus");
51 // size_field + "pygmy hippopotamus\0" + "river horse\0"
52 uint32_t ExpectedSize = 4 + 19 + 12;
53 EXPECT_EQ(ExpectedSize, B.data().size());
58 support::endian::byte_swap<uint32_t, support::little>(ExpectedSize);
59 Expected.append((const char*)&ExpectedSize, 4);
60 Expected += "pygmy hippopotamus";
62 Expected += "river horse";
65 EXPECT_EQ(Expected, B.data());
66 EXPECT_EQ(4U, B.getOffset("pygmy hippopotamus"));
67 EXPECT_EQ(10U, B.getOffset("hippopotamus"));
68 EXPECT_EQ(23U, B.getOffset("river horse"));