mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-04 19:26:30 +00:00
7470585f23
Many times unit tests for different libraries would like to use the same helper functions for checking common types of errors. This patch adds a common library with helpers for testing things in Support, and introduces helpers in here for integrating the llvm::Error and llvm::Expected<T> classes with gtest and gmock. Normally, we would just be able to write: EXPECT_THAT(someFunction(), succeeded()); but due to some quirks in llvm::Error's move semantics, gmock doesn't make this easy, so two macros EXPECT_THAT_ERROR() and EXPECT_THAT_EXPECTED() are introduced to gloss over the difficulties. Consider this an exception, and possibly only temporary as we look for ways to improve this. Differential Revision: https://reviews.llvm.org/D33059 llvm-svn: 305395
56 lines
1.9 KiB
C++
56 lines
1.9 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 "llvm/DebugInfo/PDB/Native/PDBStringTable.h"
|
|
#include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
|
|
#include "llvm/Support/BinaryByteStream.h"
|
|
#include "llvm/Support/BinaryStreamReader.h"
|
|
#include "llvm/Support/BinaryStreamWriter.h"
|
|
#include "llvm/Testing/Support/Error.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.
|
|
PDBStringTableBuilder 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.calculateSerializedSize());
|
|
MutableBinaryByteStream OutStream(Buffer, little);
|
|
BinaryStreamWriter Writer(OutStream);
|
|
EXPECT_THAT_ERROR(Builder.commit(Writer), Succeeded());
|
|
|
|
// Reads the contents back.
|
|
BinaryByteStream InStream(Buffer, little);
|
|
BinaryStreamReader Reader(InStream);
|
|
PDBStringTable Table;
|
|
EXPECT_THAT_ERROR(Table.reload(Reader), Succeeded());
|
|
|
|
EXPECT_EQ(3U, Table.getNameCount());
|
|
EXPECT_EQ(1U, Table.getHashVersion());
|
|
|
|
EXPECT_THAT_EXPECTED(Table.getStringForID(1), HasValue("foo"));
|
|
EXPECT_THAT_EXPECTED(Table.getStringForID(5), HasValue("bar"));
|
|
EXPECT_THAT_EXPECTED(Table.getStringForID(9), HasValue("baz"));
|
|
EXPECT_THAT_EXPECTED(Table.getIDForString("foo"), HasValue(1U));
|
|
EXPECT_THAT_EXPECTED(Table.getIDForString("bar"), HasValue(5U));
|
|
EXPECT_THAT_EXPECTED(Table.getIDForString("baz"), HasValue(9U));
|
|
}
|