diff options
author | Rui Ueyama <ruiu@google.com> | 2017-01-15 00:36:02 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2017-01-15 00:36:02 +0000 |
commit | dcd32937dc396d6da334fbdcc930e268d12a28d4 (patch) | |
tree | b13c21510a7c5d464844ffabd9a1fcae3d97306e /llvm/unittests/DebugInfo/PDB | |
parent | 2f19a324cb07c893ece46a45521c0a0bbd28a74a (diff) | |
download | bcm5719-llvm-dcd32937dc396d6da334fbdcc930e268d12a28d4.tar.gz bcm5719-llvm-dcd32937dc396d6da334fbdcc930e268d12a28d4.zip |
PDB: Add a class to create the /names stream contents.
This patch adds a new class NameHashTableBuilder which creates /names streams.
This patch contains a test to confirm that a stream created by
NameHashTableBuilder can be read by NameHashTable reader class.
Differential Revision: https://reviews.llvm.org/D28707
llvm-svn: 292040
Diffstat (limited to 'llvm/unittests/DebugInfo/PDB')
-rw-r--r-- | llvm/unittests/DebugInfo/PDB/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/unittests/DebugInfo/PDB/NameHashTableBuilderTest.cpp | 54 |
2 files changed, 55 insertions, 0 deletions
diff --git a/llvm/unittests/DebugInfo/PDB/CMakeLists.txt b/llvm/unittests/DebugInfo/PDB/CMakeLists.txt index 406b487e7a1..16a69edd81c 100644 --- a/llvm/unittests/DebugInfo/PDB/CMakeLists.txt +++ b/llvm/unittests/DebugInfo/PDB/CMakeLists.txt @@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS set(DebugInfoPDBSources MappedBlockStreamTest.cpp + NameHashTableBuilderTest.cpp MSFBuilderTest.cpp PDBApiTest.cpp ) diff --git a/llvm/unittests/DebugInfo/PDB/NameHashTableBuilderTest.cpp b/llvm/unittests/DebugInfo/PDB/NameHashTableBuilderTest.cpp new file mode 100644 index 00000000000..4ae0e67fa20 --- /dev/null +++ b/llvm/unittests/DebugInfo/PDB/NameHashTableBuilderTest.cpp @@ -0,0 +1,54 @@ +//===- NameHashTableBuilderTest.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/ByteStream.h" +#include "llvm/DebugInfo/MSF/StreamReader.h" +#include "llvm/DebugInfo/MSF/StreamWriter.h" +#include "llvm/DebugInfo/PDB/Raw/NameHashTable.h" +#include "llvm/DebugInfo/PDB/Raw/NameHashTableBuilder.h" + +#include "gtest/gtest.h" + +using namespace llvm; +using namespace llvm::pdb; + +namespace { +class NameHashTableBuilderTest : public ::testing::Test {}; +} + +TEST_F(NameHashTableBuilderTest, Simple) { + // Create /names table contents. + NameHashTableBuilder 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.calculateSerializedLength()); + msf::MutableByteStream OutStream(Buffer); + msf::StreamWriter Writer(OutStream); + EXPECT_NO_ERROR(Builder.commit(Writer)); + + // Reads the contents back. + msf::ByteStream InStream(Buffer); + msf::StreamReader Reader(InStream); + NameHashTable 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")); +} |