llvm-project/llvm/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp
Zachary Turner 695ed56ba5 [PDB] Make streams carry their own endianness.
Before the endianness was specified on each call to read
or write of the StreamReader / StreamWriter, but in practice
it's extremely rare for streams to have data encoded in
multiple different endiannesses, so we should optimize for the
99% use case.

This makes the code cleaner and more general, but otherwise
has NFC.

llvm-svn: 296415
2017-02-28 00:04:07 +00:00

56 lines
1.8 KiB
C++

//===- StringTableBuilderTest.cpp -----------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "ErrorChecking.h"
#include "llvm/DebugInfo/MSF/BinaryByteStream.h"
#include "llvm/DebugInfo/MSF/BinaryStreamReader.h"
#include "llvm/DebugInfo/MSF/BinaryStreamWriter.h"
#include "llvm/DebugInfo/PDB/Native/StringTable.h"
#include "llvm/DebugInfo/PDB/Native/StringTableBuilder.h"
#include "gtest/gtest.h"
using namespace llvm;
using namespace llvm::pdb;
using namespace llvm::support;
namespace {
class StringTableBuilderTest : public ::testing::Test {};
}
TEST_F(StringTableBuilderTest, Simple) {
// Create /names table contents.
StringTableBuilder Builder;
EXPECT_EQ(1U, Builder.insert("foo"));
EXPECT_EQ(5U, Builder.insert("bar"));
EXPECT_EQ(1U, Builder.insert("foo"));
EXPECT_EQ(9U, Builder.insert("baz"));
std::vector<uint8_t> Buffer(Builder.finalize());
MutableBinaryByteStream OutStream(Buffer, little);
BinaryStreamWriter Writer(OutStream);
EXPECT_NO_ERROR(Builder.commit(Writer));
// Reads the contents back.
BinaryByteStream InStream(Buffer, little);
BinaryStreamReader Reader(InStream);
StringTable Table;
EXPECT_NO_ERROR(Table.load(Reader));
EXPECT_EQ(3U, Table.getNameCount());
EXPECT_EQ(1U, Table.getHashVersion());
EXPECT_EQ("foo", Table.getStringForID(1));
EXPECT_EQ("bar", Table.getStringForID(5));
EXPECT_EQ("baz", Table.getStringForID(9));
EXPECT_EQ(1U, Table.getIDForString("foo"));
EXPECT_EQ(5U, Table.getIDForString("bar"));
EXPECT_EQ(9U, Table.getIDForString("baz"));
}