mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
[gtest] Create a shared include directory for gtest utilities.
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
This commit is contained in:
parent
14296a67da
commit
7470585f23
69
include/llvm/Testing/Support/Error.h
Normal file
69
include/llvm/Testing/Support/Error.h
Normal file
@ -0,0 +1,69 @@
|
||||
//===- llvm/Testing/Support/Error.h ---------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TESTING_SUPPORT_ERROR_H
|
||||
#define LLVM_TESTING_SUPPORT_ERROR_H
|
||||
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Testing/Support/SupportHelpers.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include <ostream>
|
||||
|
||||
namespace llvm {
|
||||
namespace detail {
|
||||
ErrorHolder TakeError(Error Err);
|
||||
|
||||
template <typename T> ExpectedHolder<T> TakeExpected(Expected<T> &Exp) {
|
||||
llvm::detail::ExpectedHolder<T> Result;
|
||||
auto &EH = static_cast<llvm::detail::ErrorHolder &>(Result);
|
||||
EH = TakeError(Exp.takeError());
|
||||
if (Result.Success)
|
||||
Result.Value = &(*Exp);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename T> ExpectedHolder<T> TakeExpected(const Expected<T> &Exp) {
|
||||
return TakeExpected(const_cast<Expected<T> &>(Exp));
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
#define EXPECT_THAT_ERROR(Err, Matcher) \
|
||||
EXPECT_THAT(llvm::detail::TakeError(Err), Matcher)
|
||||
#define ASSERT_THAT_ERROR(Err, Matcher) \
|
||||
ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
|
||||
|
||||
#define EXPECT_THAT_EXPECTED(Err, Matcher) \
|
||||
EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
|
||||
#define ASSERT_THAT_EXPECTED(Err, Matcher) \
|
||||
ASSERT_THAT(llvm::detail::TakeExpected(Err), Matcher)
|
||||
|
||||
MATCHER(Succeeded, "") { return arg.Success; }
|
||||
MATCHER(Failed, "") { return !arg.Success; }
|
||||
|
||||
MATCHER_P(HasValue, value,
|
||||
"succeeded with value " + testing::PrintToString(value)) {
|
||||
if (!arg.Success) {
|
||||
*result_listener << "operation failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(arg.Value.hasValue());
|
||||
if (**arg.Value != value) {
|
||||
*result_listener << "but \"" + testing::PrintToString(**arg.Value) +
|
||||
"\" != " + testing::PrintToString(value);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace llvm
|
||||
|
||||
#endif
|
46
include/llvm/Testing/Support/SupportHelpers.h
Normal file
46
include/llvm/Testing/Support/SupportHelpers.h
Normal file
@ -0,0 +1,46 @@
|
||||
//===- Testing/Support/SupportHelpers.h -----------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TESTING_SUPPORT_SUPPORTHELPERS_H
|
||||
#define LLVM_TESTING_SUPPORT_SUPPORTHELPERS_H
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
|
||||
namespace llvm {
|
||||
namespace detail {
|
||||
struct ErrorHolder {
|
||||
bool Success;
|
||||
std::string Message;
|
||||
};
|
||||
|
||||
template <typename T> struct ExpectedHolder : public ErrorHolder {
|
||||
Optional<T *> Value;
|
||||
};
|
||||
|
||||
inline void PrintTo(const ErrorHolder &Err, std::ostream *Out) {
|
||||
*Out << (Err.Success ? "succeeded" : "failed");
|
||||
if (!Err.Success) {
|
||||
*Out << " (" << StringRef(Err.Message).trim().str() << ")";
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void PrintTo(const ExpectedHolder<T> &Item, std::ostream *Out) {
|
||||
if (Item.Success) {
|
||||
*Out << "succeeded with value \"" << testing::PrintToString(**Item.Value)
|
||||
<< "\"";
|
||||
} else {
|
||||
PrintTo(static_cast<const ErrorHolder &>(Item), Out);
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace llvm
|
||||
|
||||
#endif
|
@ -24,3 +24,4 @@ add_subdirectory(Fuzzer)
|
||||
add_subdirectory(Passes)
|
||||
add_subdirectory(ToolDrivers)
|
||||
add_subdirectory(XRay)
|
||||
add_subdirectory(Testing)
|
||||
|
@ -39,6 +39,7 @@ subdirectories =
|
||||
Support
|
||||
TableGen
|
||||
Target
|
||||
Testing
|
||||
ToolDrivers
|
||||
Transforms
|
||||
|
||||
|
1
lib/Testing/CMakeLists.txt
Normal file
1
lib/Testing/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
add_subdirectory(Support)
|
19
lib/Testing/LLVMBuild.txt
Normal file
19
lib/Testing/LLVMBuild.txt
Normal file
@ -0,0 +1,19 @@
|
||||
;===- ./lib/Testing/LLVMBuild.txt ------------------------------*- Conf -*--===;
|
||||
;
|
||||
; The LLVM Compiler Infrastructure
|
||||
;
|
||||
; This file is distributed under the University of Illinois Open Source
|
||||
; License. See LICENSE.TXT for details.
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
;
|
||||
; This is an LLVMBuild description file for the components in this subdirectory.
|
||||
;
|
||||
; For more information on the LLVMBuild system, please see:
|
||||
;
|
||||
; http://llvm.org/docs/LLVMBuild.html
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
|
||||
[common]
|
||||
subdirectories = Support
|
12
lib/Testing/Support/CMakeLists.txt
Normal file
12
lib/Testing/Support/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
add_llvm_library(LLVMTestingSupport
|
||||
Error.cpp
|
||||
|
||||
BUILDTREE_ONLY
|
||||
|
||||
ADDITIONAL_HEADER_DIRS
|
||||
${LLVM_MAIN_INCLUDE_DIR}/llvm/Testing/Support
|
||||
)
|
||||
|
||||
include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
|
||||
include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)
|
||||
target_link_libraries(LLVMTestingSupport PRIVATE gtest)
|
22
lib/Testing/Support/Error.cpp
Normal file
22
lib/Testing/Support/Error.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
//===- llvm/Testing/Support/Error.cpp -------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Testing/Support/Error.h"
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
llvm::detail::ErrorHolder llvm::detail::TakeError(llvm::Error Err) {
|
||||
bool Succeeded = !static_cast<bool>(Err);
|
||||
std::string Message;
|
||||
if (!Succeeded)
|
||||
Message = toString(std::move(Err));
|
||||
return {Succeeded, Message};
|
||||
}
|
22
lib/Testing/Support/LLVMBuild.txt
Normal file
22
lib/Testing/Support/LLVMBuild.txt
Normal file
@ -0,0 +1,22 @@
|
||||
;===- ./Testing/Support/LLVMBuild.txt --------------------------*- Conf -*--===;
|
||||
;
|
||||
; The LLVM Compiler Infrastructure
|
||||
;
|
||||
; This file is distributed under the University of Illinois Open Source
|
||||
; License. See LICENSE.TXT for details.
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
;
|
||||
; This is an LLVMBuild description file for the components in this subdirectory.
|
||||
;
|
||||
; For more information on the LLVMBuild system, please see:
|
||||
;
|
||||
; http://llvm.org/docs/LLVMBuild.html
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
|
||||
[component_0]
|
||||
type = Library
|
||||
name = TestingSupport
|
||||
parent = Libraries
|
||||
required_libraries = Support
|
@ -1,5 +1,6 @@
|
||||
set(LLVM_LINK_COMPONENTS
|
||||
DebugInfoCodeView
|
||||
TestingSupport
|
||||
)
|
||||
|
||||
set(DebugInfoCodeViewSources
|
||||
|
@ -1,70 +0,0 @@
|
||||
//===- ErrorChecking.h - Helpers for verifying llvm::Errors -----*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_UNITTESTS_DEBUGINFO_CODEVIEW_ERRORCHECKING_H
|
||||
#define LLVM_UNITTESTS_DEBUGINFO_CODEVIEW_ERRORCHECKING_H
|
||||
|
||||
#define EXPECT_NO_ERROR(Err) \
|
||||
{ \
|
||||
auto E = Err; \
|
||||
EXPECT_FALSE(static_cast<bool>(E)); \
|
||||
if (E) \
|
||||
consumeError(std::move(E)); \
|
||||
}
|
||||
|
||||
#define EXPECT_ERROR(Err) \
|
||||
{ \
|
||||
auto E = Err; \
|
||||
EXPECT_TRUE(static_cast<bool>(E)); \
|
||||
if (E) \
|
||||
consumeError(std::move(E)); \
|
||||
}
|
||||
|
||||
#define ASSERT_EXPECTED(Exp) \
|
||||
{ \
|
||||
auto E = Exp.takeError(); \
|
||||
bool Success = static_cast<bool>(E); \
|
||||
if (!Success) \
|
||||
consumeError(std::move(E)); \
|
||||
ASSERT_FALSE(Success); \
|
||||
}
|
||||
|
||||
#define EXPECT_EXPECTED(Exp) \
|
||||
{ \
|
||||
auto E = Exp.takeError(); \
|
||||
EXPECT_FALSE(static_cast<bool>(E)); \
|
||||
if (E) { \
|
||||
consumeError(std::move(E)); \
|
||||
return; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define EXPECT_EXPECTED_EQ(Val, Exp) \
|
||||
{ \
|
||||
auto Result = Exp; \
|
||||
auto E = Result.takeError(); \
|
||||
EXPECT_FALSE(static_cast<bool>(E)); \
|
||||
if (E) { \
|
||||
consumeError(std::move(E)); \
|
||||
return; \
|
||||
} \
|
||||
EXPECT_EQ(Val, *Result); \
|
||||
}
|
||||
|
||||
#define EXPECT_UNEXPECTED(Exp) \
|
||||
{ \
|
||||
auto E = Exp.takeError(); \
|
||||
EXPECT_TRUE(static_cast<bool>(E)); \
|
||||
if (E) { \
|
||||
consumeError(std::move(E)); \
|
||||
return; \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif
|
@ -7,8 +7,6 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "ErrorChecking.h"
|
||||
|
||||
#include "llvm/ADT/SmallBitVector.h"
|
||||
#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
|
||||
#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
|
||||
@ -22,6 +20,7 @@
|
||||
#include "llvm/Support/Allocator.h"
|
||||
#include "llvm/Support/BinaryItemStream.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Testing/Support/Error.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -219,7 +218,8 @@ TEST_F(RandomAccessVisitorTest, MultipleVisits) {
|
||||
for (uint32_t I : IndicesToVisit) {
|
||||
TypeIndex TI = TypeIndex::fromArrayIndex(I);
|
||||
CVType T = Types.getType(TI);
|
||||
EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks));
|
||||
EXPECT_THAT_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks),
|
||||
Succeeded());
|
||||
}
|
||||
|
||||
// [0,8) should be present
|
||||
@ -247,7 +247,8 @@ TEST_F(RandomAccessVisitorTest, DescendingWithinChunk) {
|
||||
for (uint32_t I : IndicesToVisit) {
|
||||
TypeIndex TI = TypeIndex::fromArrayIndex(I);
|
||||
CVType T = Types.getType(TI);
|
||||
EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks));
|
||||
EXPECT_THAT_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks),
|
||||
Succeeded());
|
||||
}
|
||||
|
||||
// [0, 7]
|
||||
@ -275,7 +276,8 @@ TEST_F(RandomAccessVisitorTest, AscendingWithinChunk) {
|
||||
for (uint32_t I : IndicesToVisit) {
|
||||
TypeIndex TI = TypeIndex::fromArrayIndex(I);
|
||||
CVType T = Types.getType(TI);
|
||||
EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks));
|
||||
EXPECT_THAT_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks),
|
||||
Succeeded());
|
||||
}
|
||||
|
||||
// [0, 7]
|
||||
@ -305,7 +307,8 @@ TEST_F(RandomAccessVisitorTest, StopPrematurelyInChunk) {
|
||||
for (uint32_t I : IndicesToVisit) {
|
||||
TypeIndex TI = TypeIndex::fromArrayIndex(I);
|
||||
CVType T = Types.getType(TI);
|
||||
EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks));
|
||||
EXPECT_THAT_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks),
|
||||
Succeeded());
|
||||
}
|
||||
|
||||
// [0, 8) should be visited.
|
||||
@ -334,7 +337,8 @@ TEST_F(RandomAccessVisitorTest, InnerChunk) {
|
||||
for (uint32_t I : IndicesToVisit) {
|
||||
TypeIndex TI = TypeIndex::fromArrayIndex(I);
|
||||
CVType T = Types.getType(TI);
|
||||
EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks));
|
||||
EXPECT_THAT_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks),
|
||||
Succeeded());
|
||||
}
|
||||
|
||||
// [4, 9)
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
|
||||
|
||||
#include "ErrorChecking.h"
|
||||
#include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
|
||||
#include "llvm/Support/Allocator.h"
|
||||
|
||||
|
@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS
|
||||
DebugInfoCodeView
|
||||
DebugInfoMSF
|
||||
DebugInfoPDB
|
||||
TestingSupport
|
||||
)
|
||||
|
||||
set(DebugInfoPDBSources
|
||||
|
@ -1,61 +0,0 @@
|
||||
//===- ErrorChecking.h - Helpers for verifying llvm::Errors -----*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_UNITTESTS_DEBUGINFO_PDB_ERRORCHECKING_H
|
||||
#define LLVM_UNITTESTS_DEBUGINFO_PDB_ERRORCHECKING_H
|
||||
|
||||
#define EXPECT_NO_ERROR(Err) \
|
||||
{ \
|
||||
auto E = Err; \
|
||||
EXPECT_FALSE(static_cast<bool>(E)); \
|
||||
if (E) \
|
||||
consumeError(std::move(E)); \
|
||||
}
|
||||
|
||||
#define EXPECT_ERROR(Err) \
|
||||
{ \
|
||||
auto E = Err; \
|
||||
EXPECT_TRUE(static_cast<bool>(E)); \
|
||||
if (E) \
|
||||
consumeError(std::move(E)); \
|
||||
}
|
||||
|
||||
#define EXPECT_EXPECTED(Exp) \
|
||||
{ \
|
||||
auto E = Exp.takeError(); \
|
||||
EXPECT_FALSE(static_cast<bool>(E)); \
|
||||
if (E) { \
|
||||
consumeError(std::move(E)); \
|
||||
return; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define EXPECT_EXPECTED_EQ(Val, Exp) \
|
||||
{ \
|
||||
auto Result = Exp; \
|
||||
auto E = Result.takeError(); \
|
||||
EXPECT_FALSE(static_cast<bool>(E)); \
|
||||
if (E) { \
|
||||
consumeError(std::move(E)); \
|
||||
return; \
|
||||
} \
|
||||
EXPECT_EQ(Val, *Result); \
|
||||
}
|
||||
|
||||
#define EXPECT_UNEXPECTED(Exp) \
|
||||
{ \
|
||||
auto E = Exp.takeError(); \
|
||||
EXPECT_TRUE(static_cast<bool>(E)); \
|
||||
if (E) { \
|
||||
consumeError(std::move(E)); \
|
||||
return; \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif
|
@ -7,13 +7,13 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "ErrorChecking.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "llvm/DebugInfo/PDB/Native/HashTable.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"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -150,13 +150,13 @@ TEST(HashTableTest, Serialization) {
|
||||
std::vector<uint8_t> Buffer(Table.calculateSerializedLength());
|
||||
MutableBinaryByteStream Stream(Buffer, little);
|
||||
BinaryStreamWriter Writer(Stream);
|
||||
EXPECT_NO_ERROR(Table.commit(Writer));
|
||||
EXPECT_THAT_ERROR(Table.commit(Writer), Succeeded());
|
||||
// We should have written precisely the number of bytes we calculated earlier.
|
||||
EXPECT_EQ(Buffer.size(), Writer.getOffset());
|
||||
|
||||
HashTableInternals Table2;
|
||||
BinaryStreamReader Reader(Stream);
|
||||
EXPECT_NO_ERROR(Table2.load(Reader));
|
||||
EXPECT_THAT_ERROR(Table2.load(Reader), Succeeded());
|
||||
// We should have read precisely the number of bytes we calculated earlier.
|
||||
EXPECT_EQ(Buffer.size(), Reader.getOffset());
|
||||
|
||||
|
@ -7,10 +7,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "ErrorChecking.h"
|
||||
|
||||
#include "llvm/DebugInfo/MSF/MSFBuilder.h"
|
||||
#include "llvm/DebugInfo/MSF/MSFCommon.h"
|
||||
#include "llvm/Testing/Support/Error.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -46,7 +45,7 @@ TEST_F(MSFBuilderTest, ValidateSuperBlockAccept) {
|
||||
SuperBlock SB;
|
||||
initializeSuperBlock(SB);
|
||||
|
||||
EXPECT_NO_ERROR(msf::validateSuperBlock(SB));
|
||||
EXPECT_THAT_ERROR(msf::validateSuperBlock(SB), Succeeded());
|
||||
}
|
||||
|
||||
TEST_F(MSFBuilderTest, ValidateSuperBlockReject) {
|
||||
@ -56,24 +55,24 @@ TEST_F(MSFBuilderTest, ValidateSuperBlockReject) {
|
||||
|
||||
// Mismatched magic
|
||||
SB.MagicBytes[0] = 8;
|
||||
EXPECT_ERROR(msf::validateSuperBlock(SB));
|
||||
EXPECT_THAT_ERROR(msf::validateSuperBlock(SB), Failed());
|
||||
initializeSimpleSuperBlock(SB);
|
||||
|
||||
// Block 0 is reserved for super block, can't be occupied by the block map
|
||||
SB.BlockMapAddr = 0;
|
||||
EXPECT_ERROR(msf::validateSuperBlock(SB));
|
||||
EXPECT_THAT_ERROR(msf::validateSuperBlock(SB), Failed());
|
||||
initializeSimpleSuperBlock(SB);
|
||||
|
||||
// Block sizes have to be powers of 2.
|
||||
SB.BlockSize = 3120;
|
||||
EXPECT_ERROR(msf::validateSuperBlock(SB));
|
||||
EXPECT_THAT_ERROR(msf::validateSuperBlock(SB), Failed());
|
||||
initializeSimpleSuperBlock(SB);
|
||||
|
||||
// The directory itself has a maximum size.
|
||||
SB.NumDirectoryBytes = SB.BlockSize * SB.BlockSize / 4;
|
||||
EXPECT_NO_ERROR(msf::validateSuperBlock(SB));
|
||||
EXPECT_THAT_ERROR(msf::validateSuperBlock(SB), Succeeded());
|
||||
SB.NumDirectoryBytes = SB.NumDirectoryBytes + 4;
|
||||
EXPECT_ERROR(msf::validateSuperBlock(SB));
|
||||
EXPECT_THAT_ERROR(msf::validateSuperBlock(SB), Failed());
|
||||
}
|
||||
|
||||
TEST_F(MSFBuilderTest, TestUsedBlocksMarkedAsUsed) {
|
||||
@ -86,10 +85,11 @@ TEST_F(MSFBuilderTest, TestUsedBlocksMarkedAsUsed) {
|
||||
// after the initialization.
|
||||
uint32_t NumBlocks = msf::getMinimumBlockCount() + Blocks.size() + 10;
|
||||
auto ExpectedMsf = MSFBuilder::create(Allocator, 4096, NumBlocks);
|
||||
EXPECT_EXPECTED(ExpectedMsf);
|
||||
ASSERT_THAT_EXPECTED(ExpectedMsf, Succeeded());
|
||||
auto &Msf = *ExpectedMsf;
|
||||
|
||||
EXPECT_EXPECTED(Msf.addStream(Blocks.size() * 4096, Blocks));
|
||||
EXPECT_THAT_EXPECTED(Msf.addStream(Blocks.size() * 4096, Blocks),
|
||||
Succeeded());
|
||||
|
||||
for (auto B : Blocks) {
|
||||
EXPECT_FALSE(Msf.isBlockFree(B));
|
||||
@ -106,28 +106,28 @@ TEST_F(MSFBuilderTest, TestAddStreamNoDirectoryBlockIncrease) {
|
||||
// tests the case where the directory *DOES NOT* grow large enough that it
|
||||
// crosses a Block boundary.
|
||||
auto ExpectedMsf = MSFBuilder::create(Allocator, 4096);
|
||||
EXPECT_EXPECTED(ExpectedMsf);
|
||||
EXPECT_THAT_EXPECTED(ExpectedMsf, Succeeded());
|
||||
auto &Msf = *ExpectedMsf;
|
||||
|
||||
auto ExpectedL1 = Msf.build();
|
||||
EXPECT_EXPECTED(ExpectedL1);
|
||||
EXPECT_THAT_EXPECTED(ExpectedL1, Succeeded());
|
||||
MSFLayout &L1 = *ExpectedL1;
|
||||
|
||||
auto OldDirBlocks = L1.DirectoryBlocks;
|
||||
EXPECT_EQ(1U, OldDirBlocks.size());
|
||||
|
||||
auto ExpectedMsf2 = MSFBuilder::create(Allocator, 4096);
|
||||
EXPECT_EXPECTED(ExpectedMsf2);
|
||||
EXPECT_THAT_EXPECTED(ExpectedMsf2, Succeeded());
|
||||
auto &Msf2 = *ExpectedMsf2;
|
||||
|
||||
EXPECT_EXPECTED(Msf2.addStream(4000));
|
||||
EXPECT_THAT_EXPECTED(Msf2.addStream(4000), Succeeded());
|
||||
EXPECT_EQ(1U, Msf2.getNumStreams());
|
||||
EXPECT_EQ(4000U, Msf2.getStreamSize(0));
|
||||
auto Blocks = Msf2.getStreamBlocks(0);
|
||||
EXPECT_EQ(1U, Blocks.size());
|
||||
|
||||
auto ExpectedL2 = Msf2.build();
|
||||
EXPECT_EXPECTED(ExpectedL2);
|
||||
EXPECT_THAT_EXPECTED(ExpectedL2, Succeeded());
|
||||
MSFLayout &L2 = *ExpectedL2;
|
||||
auto NewDirBlocks = L2.DirectoryBlocks;
|
||||
EXPECT_EQ(1U, NewDirBlocks.size());
|
||||
@ -140,13 +140,14 @@ TEST_F(MSFBuilderTest, TestAddStreamWithDirectoryBlockIncrease) {
|
||||
// so many Blocks that need to be indexed in the directory that the directory
|
||||
// crosses a Block boundary.
|
||||
auto ExpectedMsf = MSFBuilder::create(Allocator, 4096);
|
||||
EXPECT_EXPECTED(ExpectedMsf);
|
||||
EXPECT_THAT_EXPECTED(ExpectedMsf, Succeeded());
|
||||
auto &Msf = *ExpectedMsf;
|
||||
|
||||
EXPECT_EXPECTED(Msf.addStream(4096 * 4096 / sizeof(uint32_t)));
|
||||
EXPECT_THAT_EXPECTED(Msf.addStream(4096 * 4096 / sizeof(uint32_t)),
|
||||
Succeeded());
|
||||
|
||||
auto ExpectedL1 = Msf.build();
|
||||
EXPECT_EXPECTED(ExpectedL1);
|
||||
EXPECT_THAT_EXPECTED(ExpectedL1, Succeeded());
|
||||
MSFLayout &L1 = *ExpectedL1;
|
||||
auto DirBlocks = L1.DirectoryBlocks;
|
||||
EXPECT_EQ(2U, DirBlocks.size());
|
||||
@ -156,15 +157,15 @@ TEST_F(MSFBuilderTest, TestGrowStreamNoBlockIncrease) {
|
||||
// Test growing an existing stream by a value that does not affect the number
|
||||
// of blocks it occupies.
|
||||
auto ExpectedMsf = MSFBuilder::create(Allocator, 4096);
|
||||
EXPECT_EXPECTED(ExpectedMsf);
|
||||
EXPECT_THAT_EXPECTED(ExpectedMsf, Succeeded());
|
||||
auto &Msf = *ExpectedMsf;
|
||||
|
||||
EXPECT_EXPECTED(Msf.addStream(1024));
|
||||
EXPECT_THAT_EXPECTED(Msf.addStream(1024), Succeeded());
|
||||
EXPECT_EQ(1024U, Msf.getStreamSize(0));
|
||||
auto OldStreamBlocks = Msf.getStreamBlocks(0);
|
||||
EXPECT_EQ(1U, OldStreamBlocks.size());
|
||||
|
||||
EXPECT_NO_ERROR(Msf.setStreamSize(0, 2048));
|
||||
EXPECT_THAT_ERROR(Msf.setStreamSize(0, 2048), Succeeded());
|
||||
EXPECT_EQ(2048U, Msf.getStreamSize(0));
|
||||
auto NewStreamBlocks = Msf.getStreamBlocks(0);
|
||||
EXPECT_EQ(1U, NewStreamBlocks.size());
|
||||
@ -178,15 +179,15 @@ TEST_F(MSFBuilderTest, TestGrowStreamWithBlockIncrease) {
|
||||
// stream's
|
||||
// block list.
|
||||
auto ExpectedMsf = MSFBuilder::create(Allocator, 4096);
|
||||
EXPECT_EXPECTED(ExpectedMsf);
|
||||
EXPECT_THAT_EXPECTED(ExpectedMsf, Succeeded());
|
||||
auto &Msf = *ExpectedMsf;
|
||||
|
||||
EXPECT_EXPECTED(Msf.addStream(2048));
|
||||
EXPECT_THAT_EXPECTED(Msf.addStream(2048), Succeeded());
|
||||
EXPECT_EQ(2048U, Msf.getStreamSize(0));
|
||||
std::vector<uint32_t> OldStreamBlocks = Msf.getStreamBlocks(0);
|
||||
EXPECT_EQ(1U, OldStreamBlocks.size());
|
||||
|
||||
EXPECT_NO_ERROR(Msf.setStreamSize(0, 6144));
|
||||
EXPECT_THAT_ERROR(Msf.setStreamSize(0, 6144), Succeeded());
|
||||
EXPECT_EQ(6144U, Msf.getStreamSize(0));
|
||||
std::vector<uint32_t> NewStreamBlocks = Msf.getStreamBlocks(0);
|
||||
EXPECT_EQ(2U, NewStreamBlocks.size());
|
||||
@ -199,15 +200,15 @@ TEST_F(MSFBuilderTest, TestShrinkStreamNoBlockDecrease) {
|
||||
// Test that shrinking an existing stream by a value that does not affect the
|
||||
// number of Blocks it occupies makes no changes to stream's block list.
|
||||
auto ExpectedMsf = MSFBuilder::create(Allocator, 4096);
|
||||
EXPECT_EXPECTED(ExpectedMsf);
|
||||
EXPECT_THAT_EXPECTED(ExpectedMsf, Succeeded());
|
||||
auto &Msf = *ExpectedMsf;
|
||||
|
||||
EXPECT_EXPECTED(Msf.addStream(2048));
|
||||
EXPECT_THAT_EXPECTED(Msf.addStream(2048), Succeeded());
|
||||
EXPECT_EQ(2048U, Msf.getStreamSize(0));
|
||||
std::vector<uint32_t> OldStreamBlocks = Msf.getStreamBlocks(0);
|
||||
EXPECT_EQ(1U, OldStreamBlocks.size());
|
||||
|
||||
EXPECT_NO_ERROR(Msf.setStreamSize(0, 1024));
|
||||
EXPECT_THAT_ERROR(Msf.setStreamSize(0, 1024), Succeeded());
|
||||
EXPECT_EQ(1024U, Msf.getStreamSize(0));
|
||||
std::vector<uint32_t> NewStreamBlocks = Msf.getStreamBlocks(0);
|
||||
EXPECT_EQ(1U, NewStreamBlocks.size());
|
||||
@ -220,15 +221,15 @@ TEST_F(MSFBuilderTest, TestShrinkStreamWithBlockDecrease) {
|
||||
// causes the need to deallocate new Blocks to the stream correctly updates
|
||||
// the stream's block list.
|
||||
auto ExpectedMsf = MSFBuilder::create(Allocator, 4096);
|
||||
EXPECT_EXPECTED(ExpectedMsf);
|
||||
EXPECT_THAT_EXPECTED(ExpectedMsf, Succeeded());
|
||||
auto &Msf = *ExpectedMsf;
|
||||
|
||||
EXPECT_EXPECTED(Msf.addStream(6144));
|
||||
EXPECT_THAT_EXPECTED(Msf.addStream(6144), Succeeded());
|
||||
EXPECT_EQ(6144U, Msf.getStreamSize(0));
|
||||
std::vector<uint32_t> OldStreamBlocks = Msf.getStreamBlocks(0);
|
||||
EXPECT_EQ(2U, OldStreamBlocks.size());
|
||||
|
||||
EXPECT_NO_ERROR(Msf.setStreamSize(0, 2048));
|
||||
EXPECT_THAT_ERROR(Msf.setStreamSize(0, 2048), Succeeded());
|
||||
EXPECT_EQ(2048U, Msf.getStreamSize(0));
|
||||
std::vector<uint32_t> NewStreamBlocks = Msf.getStreamBlocks(0);
|
||||
EXPECT_EQ(1U, NewStreamBlocks.size());
|
||||
@ -240,20 +241,20 @@ TEST_F(MSFBuilderTest, TestRejectReusedStreamBlock) {
|
||||
// Test that attempting to add a stream and assigning a block that is already
|
||||
// in use by another stream fails.
|
||||
auto ExpectedMsf = MSFBuilder::create(Allocator, 4096);
|
||||
EXPECT_EXPECTED(ExpectedMsf);
|
||||
EXPECT_THAT_EXPECTED(ExpectedMsf, Succeeded());
|
||||
auto &Msf = *ExpectedMsf;
|
||||
|
||||
EXPECT_EXPECTED(Msf.addStream(6144));
|
||||
EXPECT_THAT_EXPECTED(Msf.addStream(6144), Succeeded());
|
||||
|
||||
std::vector<uint32_t> Blocks = {2, 3};
|
||||
EXPECT_UNEXPECTED(Msf.addStream(6144, Blocks));
|
||||
EXPECT_THAT_EXPECTED(Msf.addStream(6144, Blocks), Failed());
|
||||
}
|
||||
|
||||
TEST_F(MSFBuilderTest, TestBlockCountsWhenAddingStreams) {
|
||||
// Test that when adding multiple streams, the number of used and free Blocks
|
||||
// allocated to the MSF file are as expected.
|
||||
auto ExpectedMsf = MSFBuilder::create(Allocator, 4096);
|
||||
EXPECT_EXPECTED(ExpectedMsf);
|
||||
EXPECT_THAT_EXPECTED(ExpectedMsf, Succeeded());
|
||||
auto &Msf = *ExpectedMsf;
|
||||
|
||||
// one for the super block, one for the directory block map
|
||||
@ -263,7 +264,7 @@ TEST_F(MSFBuilderTest, TestBlockCountsWhenAddingStreams) {
|
||||
|
||||
const uint32_t StreamSizes[] = {4000, 6193, 189723};
|
||||
for (int I = 0; I < 3; ++I) {
|
||||
EXPECT_EXPECTED(Msf.addStream(StreamSizes[I]));
|
||||
EXPECT_THAT_EXPECTED(Msf.addStream(StreamSizes[I]), Succeeded());
|
||||
NumUsedBlocks += bytesToBlocks(StreamSizes[I], 4096);
|
||||
EXPECT_EQ(NumUsedBlocks, Msf.getNumUsedBlocks());
|
||||
EXPECT_EQ(0U, Msf.getNumFreeBlocks());
|
||||
@ -274,19 +275,19 @@ TEST_F(MSFBuilderTest, BuildMsfLayout) {
|
||||
// Test that we can generate an MSFLayout structure from a valid layout
|
||||
// specification.
|
||||
auto ExpectedMsf = MSFBuilder::create(Allocator, 4096);
|
||||
EXPECT_EXPECTED(ExpectedMsf);
|
||||
EXPECT_THAT_EXPECTED(ExpectedMsf, Succeeded());
|
||||
auto &Msf = *ExpectedMsf;
|
||||
|
||||
const uint32_t StreamSizes[] = {4000, 6193, 189723};
|
||||
uint32_t ExpectedNumBlocks = msf::getMinimumBlockCount();
|
||||
for (int I = 0; I < 3; ++I) {
|
||||
EXPECT_EXPECTED(Msf.addStream(StreamSizes[I]));
|
||||
EXPECT_THAT_EXPECTED(Msf.addStream(StreamSizes[I]), Succeeded());
|
||||
ExpectedNumBlocks += bytesToBlocks(StreamSizes[I], 4096);
|
||||
}
|
||||
++ExpectedNumBlocks; // The directory itself should use 1 block
|
||||
|
||||
auto ExpectedLayout = Msf.build();
|
||||
EXPECT_EXPECTED(ExpectedLayout);
|
||||
EXPECT_THAT_EXPECTED(ExpectedLayout, Succeeded());
|
||||
MSFLayout &L = *ExpectedLayout;
|
||||
EXPECT_EQ(4096U, L.SB->BlockSize);
|
||||
EXPECT_EQ(ExpectedNumBlocks, L.SB->NumBlocks);
|
||||
@ -305,15 +306,15 @@ TEST_F(MSFBuilderTest, BuildMsfLayout) {
|
||||
TEST_F(MSFBuilderTest, UseDirectoryBlockHint) {
|
||||
Expected<MSFBuilder> ExpectedMsf = MSFBuilder::create(
|
||||
Allocator, 4096, msf::getMinimumBlockCount() + 1, false);
|
||||
EXPECT_EXPECTED(ExpectedMsf);
|
||||
EXPECT_THAT_EXPECTED(ExpectedMsf, Succeeded());
|
||||
auto &Msf = *ExpectedMsf;
|
||||
|
||||
uint32_t B = msf::getFirstUnreservedBlock();
|
||||
EXPECT_NO_ERROR(Msf.setDirectoryBlocksHint({B + 1}));
|
||||
EXPECT_EXPECTED(Msf.addStream(2048, {B + 2}));
|
||||
EXPECT_THAT_ERROR(Msf.setDirectoryBlocksHint({B + 1}), Succeeded());
|
||||
EXPECT_THAT_EXPECTED(Msf.addStream(2048, {B + 2}), Succeeded());
|
||||
|
||||
auto ExpectedLayout = Msf.build();
|
||||
EXPECT_EXPECTED(ExpectedLayout);
|
||||
EXPECT_THAT_EXPECTED(ExpectedLayout, Succeeded());
|
||||
MSFLayout &L = *ExpectedLayout;
|
||||
EXPECT_EQ(msf::getMinimumBlockCount() + 2, L.SB->NumBlocks);
|
||||
EXPECT_EQ(1U, L.DirectoryBlocks.size());
|
||||
@ -326,16 +327,16 @@ TEST_F(MSFBuilderTest, UseDirectoryBlockHint) {
|
||||
TEST_F(MSFBuilderTest, DirectoryBlockHintInsufficient) {
|
||||
Expected<MSFBuilder> ExpectedMsf =
|
||||
MSFBuilder::create(Allocator, 4096, msf::getMinimumBlockCount() + 2);
|
||||
EXPECT_EXPECTED(ExpectedMsf);
|
||||
EXPECT_THAT_EXPECTED(ExpectedMsf, Succeeded());
|
||||
auto &Msf = *ExpectedMsf;
|
||||
uint32_t B = msf::getFirstUnreservedBlock();
|
||||
EXPECT_NO_ERROR(Msf.setDirectoryBlocksHint({B + 1}));
|
||||
EXPECT_THAT_ERROR(Msf.setDirectoryBlocksHint({B + 1}), Succeeded());
|
||||
|
||||
uint32_t Size = 4096 * 4096 / 4;
|
||||
EXPECT_EXPECTED(Msf.addStream(Size));
|
||||
EXPECT_THAT_EXPECTED(Msf.addStream(Size), Succeeded());
|
||||
|
||||
auto ExpectedLayout = Msf.build();
|
||||
EXPECT_EXPECTED(ExpectedLayout);
|
||||
EXPECT_THAT_EXPECTED(ExpectedLayout, Succeeded());
|
||||
MSFLayout &L = *ExpectedLayout;
|
||||
EXPECT_EQ(2U, L.DirectoryBlocks.size());
|
||||
EXPECT_EQ(B + 1, L.DirectoryBlocks[0]);
|
||||
@ -344,16 +345,16 @@ TEST_F(MSFBuilderTest, DirectoryBlockHintInsufficient) {
|
||||
TEST_F(MSFBuilderTest, DirectoryBlockHintOverestimated) {
|
||||
Expected<MSFBuilder> ExpectedMsf =
|
||||
MSFBuilder::create(Allocator, 4096, msf::getMinimumBlockCount() + 2);
|
||||
EXPECT_EXPECTED(ExpectedMsf);
|
||||
EXPECT_THAT_EXPECTED(ExpectedMsf, Succeeded());
|
||||
auto &Msf = *ExpectedMsf;
|
||||
|
||||
uint32_t B = msf::getFirstUnreservedBlock();
|
||||
EXPECT_NO_ERROR(Msf.setDirectoryBlocksHint({B + 1, B + 2}));
|
||||
EXPECT_THAT_ERROR(Msf.setDirectoryBlocksHint({B + 1, B + 2}), Succeeded());
|
||||
|
||||
EXPECT_EXPECTED(Msf.addStream(2048));
|
||||
ASSERT_THAT_EXPECTED(Msf.addStream(2048), Succeeded());
|
||||
|
||||
auto ExpectedLayout = Msf.build();
|
||||
EXPECT_EXPECTED(ExpectedLayout);
|
||||
ASSERT_THAT_EXPECTED(ExpectedLayout, Succeeded());
|
||||
MSFLayout &L = *ExpectedLayout;
|
||||
EXPECT_EQ(1U, L.DirectoryBlocks.size());
|
||||
EXPECT_EQ(B + 1, L.DirectoryBlocks[0]);
|
||||
|
@ -7,16 +7,16 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "ErrorChecking.h"
|
||||
|
||||
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
|
||||
#include "llvm/DebugInfo/MSF/IMSFFile.h"
|
||||
#include "llvm/DebugInfo/MSF/MSFError.h"
|
||||
#include "llvm/DebugInfo/MSF/MSFStreamLayout.h"
|
||||
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
|
||||
#include "llvm/Support/BinaryByteStream.h"
|
||||
#include "llvm/Support/BinaryStreamReader.h"
|
||||
#include "llvm/Support/BinaryStreamRef.h"
|
||||
#include "llvm/Support/BinaryStreamWriter.h"
|
||||
#include "llvm/Testing/Support/Error.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <unordered_map>
|
||||
@ -95,11 +95,11 @@ TEST(MappedBlockStreamTest, ReadBeyondEndOfStreamRef) {
|
||||
|
||||
BinaryStreamReader R(*S);
|
||||
BinaryStreamRef SR;
|
||||
EXPECT_NO_ERROR(R.readStreamRef(SR, 0U));
|
||||
EXPECT_THAT_ERROR(R.readStreamRef(SR, 0U), Succeeded());
|
||||
ArrayRef<uint8_t> Buffer;
|
||||
EXPECT_ERROR(SR.readBytes(0U, 1U, Buffer));
|
||||
EXPECT_NO_ERROR(R.readStreamRef(SR, 1U));
|
||||
EXPECT_ERROR(SR.readBytes(1U, 1U, Buffer));
|
||||
EXPECT_THAT_ERROR(SR.readBytes(0U, 1U, Buffer), Failed());
|
||||
EXPECT_THAT_ERROR(R.readStreamRef(SR, 1U), Succeeded());
|
||||
EXPECT_THAT_ERROR(SR.readBytes(1U, 1U, Buffer), Failed());
|
||||
}
|
||||
|
||||
// Tests that a read which outputs into a full destination buffer works and
|
||||
@ -111,7 +111,7 @@ TEST(MappedBlockStreamTest, ReadOntoNonEmptyBuffer) {
|
||||
|
||||
BinaryStreamReader R(*S);
|
||||
StringRef Str = "ZYXWVUTSRQPONMLKJIHGFEDCBA";
|
||||
EXPECT_NO_ERROR(R.readFixedString(Str, 1));
|
||||
EXPECT_THAT_ERROR(R.readFixedString(Str, 1), Succeeded());
|
||||
EXPECT_EQ(Str, StringRef("A"));
|
||||
EXPECT_EQ(0U, F.Allocator.getBytesAllocated());
|
||||
}
|
||||
@ -125,12 +125,12 @@ TEST(MappedBlockStreamTest, ZeroCopyReadContiguousBreak) {
|
||||
F.Allocator);
|
||||
BinaryStreamReader R(*S);
|
||||
StringRef Str;
|
||||
EXPECT_NO_ERROR(R.readFixedString(Str, 2));
|
||||
EXPECT_THAT_ERROR(R.readFixedString(Str, 2), Succeeded());
|
||||
EXPECT_EQ(Str, StringRef("AB"));
|
||||
EXPECT_EQ(0U, F.Allocator.getBytesAllocated());
|
||||
|
||||
R.setOffset(6);
|
||||
EXPECT_NO_ERROR(R.readFixedString(Str, 4));
|
||||
EXPECT_THAT_ERROR(R.readFixedString(Str, 4), Succeeded());
|
||||
EXPECT_EQ(Str, StringRef("GHIJ"));
|
||||
EXPECT_EQ(0U, F.Allocator.getBytesAllocated());
|
||||
}
|
||||
@ -144,7 +144,7 @@ TEST(MappedBlockStreamTest, CopyReadNonContiguousBreak) {
|
||||
F.Allocator);
|
||||
BinaryStreamReader R(*S);
|
||||
StringRef Str;
|
||||
EXPECT_NO_ERROR(R.readFixedString(Str, 10));
|
||||
EXPECT_THAT_ERROR(R.readFixedString(Str, 10), Succeeded());
|
||||
EXPECT_EQ(Str, StringRef("ABCDEFGHIJ"));
|
||||
EXPECT_EQ(10U, F.Allocator.getBytesAllocated());
|
||||
}
|
||||
@ -159,7 +159,7 @@ TEST(MappedBlockStreamTest, InvalidReadSizeNoBreak) {
|
||||
StringRef Str;
|
||||
|
||||
R.setOffset(10);
|
||||
EXPECT_ERROR(R.readFixedString(Str, 1));
|
||||
EXPECT_THAT_ERROR(R.readFixedString(Str, 1), Failed());
|
||||
EXPECT_EQ(0U, F.Allocator.getBytesAllocated());
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ TEST(MappedBlockStreamTest, InvalidReadSizeContiguousBreak) {
|
||||
StringRef Str;
|
||||
|
||||
R.setOffset(6);
|
||||
EXPECT_ERROR(R.readFixedString(Str, 5));
|
||||
EXPECT_THAT_ERROR(R.readFixedString(Str, 5), Failed());
|
||||
EXPECT_EQ(0U, F.Allocator.getBytesAllocated());
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ TEST(MappedBlockStreamTest, InvalidReadSizeNonContiguousBreak) {
|
||||
BinaryStreamReader R(*S);
|
||||
StringRef Str;
|
||||
|
||||
EXPECT_ERROR(R.readFixedString(Str, 11));
|
||||
EXPECT_THAT_ERROR(R.readFixedString(Str, 11), Failed());
|
||||
EXPECT_EQ(0U, F.Allocator.getBytesAllocated());
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ TEST(MappedBlockStreamTest, ZeroCopyReadNoBreak) {
|
||||
F.Allocator);
|
||||
BinaryStreamReader R(*S);
|
||||
StringRef Str;
|
||||
EXPECT_NO_ERROR(R.readFixedString(Str, 1));
|
||||
EXPECT_THAT_ERROR(R.readFixedString(Str, 1), Succeeded());
|
||||
EXPECT_EQ(Str, StringRef("A"));
|
||||
EXPECT_EQ(0U, F.Allocator.getBytesAllocated());
|
||||
}
|
||||
@ -213,12 +213,12 @@ TEST(MappedBlockStreamTest, UnalignedOverlappingRead) {
|
||||
BinaryStreamReader R(*S);
|
||||
StringRef Str1;
|
||||
StringRef Str2;
|
||||
EXPECT_NO_ERROR(R.readFixedString(Str1, 7));
|
||||
EXPECT_THAT_ERROR(R.readFixedString(Str1, 7), Succeeded());
|
||||
EXPECT_EQ(Str1, StringRef("ABCDEFG"));
|
||||
EXPECT_EQ(7U, F.Allocator.getBytesAllocated());
|
||||
|
||||
R.setOffset(2);
|
||||
EXPECT_NO_ERROR(R.readFixedString(Str2, 3));
|
||||
EXPECT_THAT_ERROR(R.readFixedString(Str2, 3), Succeeded());
|
||||
EXPECT_EQ(Str2, StringRef("CDE"));
|
||||
EXPECT_EQ(Str1.data() + 2, Str2.data());
|
||||
EXPECT_EQ(7U, F.Allocator.getBytesAllocated());
|
||||
@ -234,12 +234,12 @@ TEST(MappedBlockStreamTest, UnalignedOverlappingReadFail) {
|
||||
BinaryStreamReader R(*S);
|
||||
StringRef Str1;
|
||||
StringRef Str2;
|
||||
EXPECT_NO_ERROR(R.readFixedString(Str1, 6));
|
||||
EXPECT_THAT_ERROR(R.readFixedString(Str1, 6), Succeeded());
|
||||
EXPECT_EQ(Str1, StringRef("ABCDEF"));
|
||||
EXPECT_EQ(6U, F.Allocator.getBytesAllocated());
|
||||
|
||||
R.setOffset(4);
|
||||
EXPECT_NO_ERROR(R.readFixedString(Str2, 4));
|
||||
EXPECT_THAT_ERROR(R.readFixedString(Str2, 4), Succeeded());
|
||||
EXPECT_EQ(Str2, StringRef("EFGH"));
|
||||
EXPECT_EQ(10U, F.Allocator.getBytesAllocated());
|
||||
}
|
||||
@ -257,10 +257,12 @@ TEST(MappedBlockStreamTest, WriteBeyondEndOfStream) {
|
||||
F, F.Allocator);
|
||||
ArrayRef<uint8_t> Buffer;
|
||||
|
||||
EXPECT_ERROR(S->writeBytes(0, ArrayRef<uint8_t>(LargeBuffer)));
|
||||
EXPECT_NO_ERROR(S->writeBytes(0, ArrayRef<uint8_t>(SmallBuffer)));
|
||||
EXPECT_NO_ERROR(S->writeBytes(7, ArrayRef<uint8_t>(SmallBuffer)));
|
||||
EXPECT_ERROR(S->writeBytes(8, ArrayRef<uint8_t>(SmallBuffer)));
|
||||
EXPECT_THAT_ERROR(S->writeBytes(0, ArrayRef<uint8_t>(LargeBuffer)), Failed());
|
||||
EXPECT_THAT_ERROR(S->writeBytes(0, ArrayRef<uint8_t>(SmallBuffer)),
|
||||
Succeeded());
|
||||
EXPECT_THAT_ERROR(S->writeBytes(7, ArrayRef<uint8_t>(SmallBuffer)),
|
||||
Succeeded());
|
||||
EXPECT_THAT_ERROR(S->writeBytes(8, ArrayRef<uint8_t>(SmallBuffer)), Failed());
|
||||
}
|
||||
|
||||
TEST(MappedBlockStreamTest, TestWriteBytesNoBreakBoundary) {
|
||||
@ -270,25 +272,25 @@ TEST(MappedBlockStreamTest, TestWriteBytesNoBreakBoundary) {
|
||||
F, F.Allocator);
|
||||
ArrayRef<uint8_t> Buffer;
|
||||
|
||||
EXPECT_NO_ERROR(S->readBytes(0, 1, Buffer));
|
||||
EXPECT_THAT_ERROR(S->readBytes(0, 1, Buffer), Succeeded());
|
||||
EXPECT_EQ(Buffer, ArrayRef<uint8_t>('A'));
|
||||
EXPECT_NO_ERROR(S->readBytes(9, 1, Buffer));
|
||||
EXPECT_THAT_ERROR(S->readBytes(9, 1, Buffer), Succeeded());
|
||||
EXPECT_EQ(Buffer, ArrayRef<uint8_t>('J'));
|
||||
|
||||
EXPECT_NO_ERROR(S->writeBytes(0, ArrayRef<uint8_t>('J')));
|
||||
EXPECT_NO_ERROR(S->writeBytes(9, ArrayRef<uint8_t>('A')));
|
||||
EXPECT_THAT_ERROR(S->writeBytes(0, ArrayRef<uint8_t>('J')), Succeeded());
|
||||
EXPECT_THAT_ERROR(S->writeBytes(9, ArrayRef<uint8_t>('A')), Succeeded());
|
||||
|
||||
EXPECT_NO_ERROR(S->readBytes(0, 1, Buffer));
|
||||
EXPECT_THAT_ERROR(S->readBytes(0, 1, Buffer), Succeeded());
|
||||
EXPECT_EQ(Buffer, ArrayRef<uint8_t>('J'));
|
||||
EXPECT_NO_ERROR(S->readBytes(9, 1, Buffer));
|
||||
EXPECT_THAT_ERROR(S->readBytes(9, 1, Buffer), Succeeded());
|
||||
EXPECT_EQ(Buffer, ArrayRef<uint8_t>('A'));
|
||||
|
||||
EXPECT_NO_ERROR(S->writeBytes(0, ArrayRef<uint8_t>('A')));
|
||||
EXPECT_NO_ERROR(S->writeBytes(9, ArrayRef<uint8_t>('J')));
|
||||
EXPECT_THAT_ERROR(S->writeBytes(0, ArrayRef<uint8_t>('A')), Succeeded());
|
||||
EXPECT_THAT_ERROR(S->writeBytes(9, ArrayRef<uint8_t>('J')), Succeeded());
|
||||
|
||||
EXPECT_NO_ERROR(S->readBytes(0, 1, Buffer));
|
||||
EXPECT_THAT_ERROR(S->readBytes(0, 1, Buffer), Succeeded());
|
||||
EXPECT_EQ(Buffer, ArrayRef<uint8_t>('A'));
|
||||
EXPECT_NO_ERROR(S->readBytes(9, 1, Buffer));
|
||||
EXPECT_THAT_ERROR(S->readBytes(9, 1, Buffer), Succeeded());
|
||||
EXPECT_EQ(Buffer, ArrayRef<uint8_t>('J'));
|
||||
}
|
||||
|
||||
@ -303,12 +305,12 @@ TEST(MappedBlockStreamTest, TestWriteBytesBreakBoundary) {
|
||||
F, F.Allocator);
|
||||
ArrayRef<uint8_t> Buffer;
|
||||
|
||||
EXPECT_NO_ERROR(S->writeBytes(0, TestData));
|
||||
EXPECT_THAT_ERROR(S->writeBytes(0, TestData), Succeeded());
|
||||
// First just compare the memory, then compare the result of reading the
|
||||
// string out.
|
||||
EXPECT_EQ(ArrayRef<uint8_t>(Data), ArrayRef<uint8_t>(Expected));
|
||||
|
||||
EXPECT_NO_ERROR(S->readBytes(0, 8, Buffer));
|
||||
EXPECT_THAT_ERROR(S->readBytes(0, 8, Buffer), Succeeded());
|
||||
EXPECT_EQ(Buffer, ArrayRef<uint8_t>(TestData));
|
||||
}
|
||||
|
||||
@ -340,8 +342,8 @@ TEST(MappedBlockStreamTest, TestWriteThenRead) {
|
||||
|
||||
BinaryStreamReader Reader(*S);
|
||||
BinaryStreamWriter Writer(*S);
|
||||
EXPECT_NO_ERROR(Writer.writeInteger(u16[0]));
|
||||
EXPECT_NO_ERROR(Reader.readInteger(u16[1]));
|
||||
EXPECT_THAT_ERROR(Writer.writeInteger(u16[0]), Succeeded());
|
||||
EXPECT_THAT_ERROR(Reader.readInteger(u16[1]), Succeeded());
|
||||
EXPECT_EQ(u16[0], u16[1]);
|
||||
EXPECT_EQ(std::vector<uint8_t>({0, 0x7A, 0xEC, 0, 0, 0, 0, 0, 0, 0}),
|
||||
DataBytes);
|
||||
@ -349,8 +351,8 @@ TEST(MappedBlockStreamTest, TestWriteThenRead) {
|
||||
Reader.setOffset(0);
|
||||
Writer.setOffset(0);
|
||||
::memset(DataBytes.data(), 0, 10);
|
||||
EXPECT_NO_ERROR(Writer.writeInteger(u32[0]));
|
||||
EXPECT_NO_ERROR(Reader.readInteger(u32[1]));
|
||||
EXPECT_THAT_ERROR(Writer.writeInteger(u32[0]), Succeeded());
|
||||
EXPECT_THAT_ERROR(Reader.readInteger(u32[1]), Succeeded());
|
||||
EXPECT_EQ(u32[0], u32[1]);
|
||||
EXPECT_EQ(std::vector<uint8_t>({0x17, 0x5C, 0x50, 0, 0, 0, 0x35, 0, 0, 0}),
|
||||
DataBytes);
|
||||
@ -358,8 +360,8 @@ TEST(MappedBlockStreamTest, TestWriteThenRead) {
|
||||
Reader.setOffset(0);
|
||||
Writer.setOffset(0);
|
||||
::memset(DataBytes.data(), 0, 10);
|
||||
EXPECT_NO_ERROR(Writer.writeEnum(Enum[0]));
|
||||
EXPECT_NO_ERROR(Reader.readEnum(Enum[1]));
|
||||
EXPECT_THAT_ERROR(Writer.writeEnum(Enum[0]), Succeeded());
|
||||
EXPECT_THAT_ERROR(Reader.readEnum(Enum[1]), Succeeded());
|
||||
EXPECT_EQ(Enum[0], Enum[1]);
|
||||
EXPECT_EQ(std::vector<uint8_t>({0x2C, 0x60, 0x4A, 0, 0, 0, 0, 0, 0, 0}),
|
||||
DataBytes);
|
||||
@ -367,8 +369,8 @@ TEST(MappedBlockStreamTest, TestWriteThenRead) {
|
||||
Reader.setOffset(0);
|
||||
Writer.setOffset(0);
|
||||
::memset(DataBytes.data(), 0, 10);
|
||||
EXPECT_NO_ERROR(Writer.writeCString(ZStr[0]));
|
||||
EXPECT_NO_ERROR(Reader.readCString(ZStr[1]));
|
||||
EXPECT_THAT_ERROR(Writer.writeCString(ZStr[0]), Succeeded());
|
||||
EXPECT_THAT_ERROR(Reader.readCString(ZStr[1]), Succeeded());
|
||||
EXPECT_EQ(ZStr[0], ZStr[1]);
|
||||
EXPECT_EQ(
|
||||
std::vector<uint8_t>({'r', 'e', 'Z', ' ', 'S', 't', 'o', 'r', 0, 0}),
|
||||
@ -377,8 +379,9 @@ TEST(MappedBlockStreamTest, TestWriteThenRead) {
|
||||
Reader.setOffset(0);
|
||||
Writer.setOffset(0);
|
||||
::memset(DataBytes.data(), 0, 10);
|
||||
EXPECT_NO_ERROR(Writer.writeFixedString(FStr[0]));
|
||||
EXPECT_NO_ERROR(Reader.readFixedString(FStr[1], FStr[0].size()));
|
||||
EXPECT_THAT_ERROR(Writer.writeFixedString(FStr[0]), Succeeded());
|
||||
EXPECT_THAT_ERROR(Reader.readFixedString(FStr[1], FStr[0].size()),
|
||||
Succeeded());
|
||||
EXPECT_EQ(FStr[0], FStr[1]);
|
||||
EXPECT_EQ(
|
||||
std::vector<uint8_t>({'x', 'i', 'F', 'd', ' ', 'S', 'e', 't', 0, 'r'}),
|
||||
@ -387,8 +390,9 @@ TEST(MappedBlockStreamTest, TestWriteThenRead) {
|
||||
Reader.setOffset(0);
|
||||
Writer.setOffset(0);
|
||||
::memset(DataBytes.data(), 0, 10);
|
||||
EXPECT_NO_ERROR(Writer.writeArray(byteArray[0]));
|
||||
EXPECT_NO_ERROR(Reader.readArray(byteArray[1], byteArray[0].size()));
|
||||
EXPECT_THAT_ERROR(Writer.writeArray(byteArray[0]), Succeeded());
|
||||
EXPECT_THAT_ERROR(Reader.readArray(byteArray[1], byteArray[0].size()),
|
||||
Succeeded());
|
||||
EXPECT_EQ(byteArray[0], byteArray[1]);
|
||||
EXPECT_EQ(std::vector<uint8_t>({0, 0x32, 0x31, 0, 0, 0, 0, 0, 0, 0}),
|
||||
DataBytes);
|
||||
@ -396,8 +400,9 @@ TEST(MappedBlockStreamTest, TestWriteThenRead) {
|
||||
Reader.setOffset(0);
|
||||
Writer.setOffset(0);
|
||||
::memset(DataBytes.data(), 0, 10);
|
||||
EXPECT_NO_ERROR(Writer.writeArray(intArray[0]));
|
||||
EXPECT_NO_ERROR(Reader.readArray(intArray[1], intArray[0].size()));
|
||||
EXPECT_THAT_ERROR(Writer.writeArray(intArray[0]), Succeeded());
|
||||
EXPECT_THAT_ERROR(Reader.readArray(intArray[1], intArray[0].size()),
|
||||
Succeeded());
|
||||
EXPECT_EQ(intArray[0], intArray[1]);
|
||||
}
|
||||
|
||||
@ -416,20 +421,20 @@ TEST(MappedBlockStreamTest, TestWriteContiguousStreamRef) {
|
||||
// First write "Test Str" into the source stream.
|
||||
MutableBinaryByteStream SourceStream(SrcData, little);
|
||||
BinaryStreamWriter SourceWriter(SourceStream);
|
||||
EXPECT_NO_ERROR(SourceWriter.writeCString("Test Str"));
|
||||
EXPECT_THAT_ERROR(SourceWriter.writeCString("Test Str"), Succeeded());
|
||||
EXPECT_EQ(SrcDataBytes, std::vector<uint8_t>(
|
||||
{'T', 'e', 's', 't', ' ', 'S', 't', 'r', 0, 0}));
|
||||
|
||||
// Then write the source stream into the dest stream.
|
||||
BinaryStreamWriter DestWriter(*DestStream);
|
||||
EXPECT_NO_ERROR(DestWriter.writeStreamRef(SourceStream));
|
||||
EXPECT_THAT_ERROR(DestWriter.writeStreamRef(SourceStream), Succeeded());
|
||||
EXPECT_EQ(DestDataBytes, std::vector<uint8_t>(
|
||||
{'s', 'e', 'T', ' ', 'S', 't', 't', 'r', 0, 0}));
|
||||
|
||||
// Then read the string back out of the dest stream.
|
||||
StringRef Result;
|
||||
BinaryStreamReader DestReader(*DestStream);
|
||||
EXPECT_NO_ERROR(DestReader.readCString(Result));
|
||||
EXPECT_THAT_ERROR(DestReader.readCString(Result), Succeeded());
|
||||
EXPECT_EQ(Result, "Test Str");
|
||||
}
|
||||
|
||||
@ -452,20 +457,20 @@ TEST(MappedBlockStreamTest, TestWriteDiscontiguousStreamRef) {
|
||||
|
||||
// First write "Test Str" into the source stream.
|
||||
BinaryStreamWriter SourceWriter(*Src);
|
||||
EXPECT_NO_ERROR(SourceWriter.writeCString("Test Str"));
|
||||
EXPECT_THAT_ERROR(SourceWriter.writeCString("Test Str"), Succeeded());
|
||||
EXPECT_EQ(SrcDataBytes, std::vector<uint8_t>(
|
||||
{'e', 'T', 't', 't', ' ', 'S', 's', 'r', 0, 0}));
|
||||
|
||||
// Then write the source stream into the dest stream.
|
||||
BinaryStreamWriter DestWriter(*Dest);
|
||||
EXPECT_NO_ERROR(DestWriter.writeStreamRef(*Src));
|
||||
EXPECT_THAT_ERROR(DestWriter.writeStreamRef(*Src), Succeeded());
|
||||
EXPECT_EQ(DestDataBytes, std::vector<uint8_t>(
|
||||
{'s', 'e', 'T', ' ', 'S', 't', 't', 'r', 0, 0}));
|
||||
|
||||
// Then read the string back out of the dest stream.
|
||||
StringRef Result;
|
||||
BinaryStreamReader DestReader(*Dest);
|
||||
EXPECT_NO_ERROR(DestReader.readCString(Result));
|
||||
EXPECT_THAT_ERROR(DestReader.readCString(Result), Succeeded());
|
||||
EXPECT_EQ(Result, "Test Str");
|
||||
}
|
||||
|
||||
@ -484,8 +489,8 @@ TEST(MappedBlockStreamTest, DataLivesAfterStreamDestruction) {
|
||||
BinaryStreamReader Reader(*S);
|
||||
BinaryStreamWriter Writer(*S);
|
||||
::memset(DataBytes.data(), 0, 10);
|
||||
EXPECT_NO_ERROR(Writer.writeCString(Str[0]));
|
||||
EXPECT_NO_ERROR(Reader.readCString(Str[1]));
|
||||
EXPECT_THAT_ERROR(Writer.writeCString(Str[0]), Succeeded());
|
||||
EXPECT_THAT_ERROR(Reader.readCString(Str[1]), Succeeded());
|
||||
EXPECT_EQ(Str[0], Str[1]);
|
||||
}
|
||||
|
||||
|
@ -7,13 +7,12 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "ErrorChecking.h"
|
||||
|
||||
#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"
|
||||
|
||||
@ -36,21 +35,21 @@ TEST_F(StringTableBuilderTest, Simple) {
|
||||
std::vector<uint8_t> Buffer(Builder.calculateSerializedSize());
|
||||
MutableBinaryByteStream OutStream(Buffer, little);
|
||||
BinaryStreamWriter Writer(OutStream);
|
||||
EXPECT_NO_ERROR(Builder.commit(Writer));
|
||||
EXPECT_THAT_ERROR(Builder.commit(Writer), Succeeded());
|
||||
|
||||
// Reads the contents back.
|
||||
BinaryByteStream InStream(Buffer, little);
|
||||
BinaryStreamReader Reader(InStream);
|
||||
PDBStringTable Table;
|
||||
EXPECT_NO_ERROR(Table.reload(Reader));
|
||||
EXPECT_THAT_ERROR(Table.reload(Reader), Succeeded());
|
||||
|
||||
EXPECT_EQ(3U, Table.getNameCount());
|
||||
EXPECT_EQ(1U, Table.getHashVersion());
|
||||
|
||||
EXPECT_EXPECTED_EQ("foo", Table.getStringForID(1));
|
||||
EXPECT_EXPECTED_EQ("bar", Table.getStringForID(5));
|
||||
EXPECT_EXPECTED_EQ("baz", Table.getStringForID(9));
|
||||
EXPECT_EXPECTED_EQ(1U, Table.getIDForString("foo"));
|
||||
EXPECT_EXPECTED_EQ(5U, Table.getIDForString("bar"));
|
||||
EXPECT_EXPECTED_EQ(9U, Table.getIDForString("baz"));
|
||||
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));
|
||||
}
|
||||
|
@ -7,19 +7,18 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "ErrorChecking.h"
|
||||
|
||||
#include "llvm/DebugInfo/CodeView/TypeServerHandler.h"
|
||||
#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
|
||||
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
|
||||
#include "llvm/DebugInfo/CodeView/TypeRecordMapping.h"
|
||||
#include "llvm/DebugInfo/CodeView/TypeSerializer.h"
|
||||
#include "llvm/DebugInfo/CodeView/TypeServerHandler.h"
|
||||
#include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
|
||||
#include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h"
|
||||
#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
|
||||
#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
|
||||
#include "llvm/Support/Allocator.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Testing/Support/Error.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -127,7 +126,8 @@ TEST_F(TypeServerHandlerTest, VisitRecordNoTypeServer) {
|
||||
Pipeline.addCallbackToPipeline(C1);
|
||||
Pipeline.addCallbackToPipeline(C2);
|
||||
|
||||
EXPECT_NO_ERROR(codeview::visitTypeRecord(TypeServerRecord, Pipeline));
|
||||
EXPECT_THAT_ERROR(codeview::visitTypeRecord(TypeServerRecord, Pipeline),
|
||||
Succeeded());
|
||||
|
||||
EXPECT_EQ(MockTypeVisitorCallbacks::State::VisitTypeEnd, C1.S);
|
||||
EXPECT_EQ(MockTypeVisitorCallbacks::State::VisitTypeEnd, C2.S);
|
||||
@ -141,14 +141,18 @@ TEST_F(TypeServerHandlerTest, VisitRecordWithTypeServerOnce) {
|
||||
MockTypeVisitorCallbacks C1;
|
||||
|
||||
// Our mock server returns true the first time.
|
||||
EXPECT_NO_ERROR(codeview::visitTypeRecord(
|
||||
TypeServerRecord, C1, codeview::VDS_BytesExternal, &Handler));
|
||||
EXPECT_THAT_ERROR(codeview::visitTypeRecord(TypeServerRecord, C1,
|
||||
codeview::VDS_BytesExternal,
|
||||
&Handler),
|
||||
Succeeded());
|
||||
EXPECT_TRUE(Handler.Handled);
|
||||
EXPECT_EQ(MockTypeVisitorCallbacks::State::Ready, C1.S);
|
||||
|
||||
// And false the second time.
|
||||
EXPECT_NO_ERROR(codeview::visitTypeRecord(
|
||||
TypeServerRecord, C1, codeview::VDS_BytesExternal, &Handler));
|
||||
EXPECT_THAT_ERROR(codeview::visitTypeRecord(TypeServerRecord, C1,
|
||||
codeview::VDS_BytesExternal,
|
||||
&Handler),
|
||||
Succeeded());
|
||||
EXPECT_TRUE(Handler.Handled);
|
||||
EXPECT_EQ(MockTypeVisitorCallbacks::State::VisitTypeEnd, C1.S);
|
||||
}
|
||||
@ -161,13 +165,17 @@ TEST_F(TypeServerHandlerTest, VisitRecordWithTypeServerAlways) {
|
||||
|
||||
MockTypeVisitorCallbacks C1;
|
||||
|
||||
EXPECT_NO_ERROR(codeview::visitTypeRecord(
|
||||
TypeServerRecord, C1, codeview::VDS_BytesExternal, &Handler));
|
||||
EXPECT_THAT_ERROR(codeview::visitTypeRecord(TypeServerRecord, C1,
|
||||
codeview::VDS_BytesExternal,
|
||||
&Handler),
|
||||
Succeeded());
|
||||
EXPECT_TRUE(Handler.Handled);
|
||||
EXPECT_EQ(MockTypeVisitorCallbacks::State::Ready, C1.S);
|
||||
|
||||
EXPECT_NO_ERROR(codeview::visitTypeRecord(
|
||||
TypeServerRecord, C1, codeview::VDS_BytesExternal, &Handler));
|
||||
EXPECT_THAT_ERROR(codeview::visitTypeRecord(TypeServerRecord, C1,
|
||||
codeview::VDS_BytesExternal,
|
||||
&Handler),
|
||||
Succeeded());
|
||||
EXPECT_TRUE(Handler.Handled);
|
||||
EXPECT_EQ(MockTypeVisitorCallbacks::State::Ready, C1.S);
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
#include "llvm/Support/BinaryStreamReader.h"
|
||||
#include "llvm/Support/BinaryStreamRef.h"
|
||||
#include "llvm/Support/BinaryStreamWriter.h"
|
||||
#include "llvm/Testing/Support/Error.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <unordered_map>
|
||||
@ -21,30 +23,6 @@
|
||||
using namespace llvm;
|
||||
using namespace llvm::support;
|
||||
|
||||
#define EXPECT_NO_ERROR(Err) \
|
||||
{ \
|
||||
auto E = Err; \
|
||||
EXPECT_FALSE(static_cast<bool>(E)); \
|
||||
if (E) \
|
||||
consumeError(std::move(E)); \
|
||||
}
|
||||
|
||||
#define ASSERT_NO_ERROR(Err) \
|
||||
{ \
|
||||
auto E = Err; \
|
||||
ASSERT_FALSE(static_cast<bool>(E)); \
|
||||
if (E) \
|
||||
consumeError(std::move(E)); \
|
||||
}
|
||||
|
||||
#define EXPECT_ERROR(Err) \
|
||||
{ \
|
||||
auto E = Err; \
|
||||
EXPECT_TRUE(static_cast<bool>(E)); \
|
||||
if (E) \
|
||||
consumeError(std::move(E)); \
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class BrokenStream : public WritableBinaryStream {
|
||||
@ -227,13 +205,13 @@ TEST_F(BinaryStreamTest, BinaryByteStreamBounds) {
|
||||
|
||||
// 1. If the read fits it should work.
|
||||
ASSERT_EQ(InputData.size(), Stream.Input->getLength());
|
||||
ASSERT_NO_ERROR(Stream.Input->readBytes(2, 1, Buffer));
|
||||
ASSERT_THAT_ERROR(Stream.Input->readBytes(2, 1, Buffer), Succeeded());
|
||||
EXPECT_EQ(makeArrayRef(InputData).slice(2, 1), Buffer);
|
||||
ASSERT_NO_ERROR(Stream.Input->readBytes(0, 4, Buffer));
|
||||
ASSERT_THAT_ERROR(Stream.Input->readBytes(0, 4, Buffer), Succeeded());
|
||||
EXPECT_EQ(makeArrayRef(InputData).slice(0, 4), Buffer);
|
||||
|
||||
// 2. Reading past the bounds of the input should fail.
|
||||
EXPECT_ERROR(Stream.Input->readBytes(4, 2, Buffer));
|
||||
EXPECT_THAT_ERROR(Stream.Input->readBytes(4, 2, Buffer), Failed());
|
||||
}
|
||||
}
|
||||
|
||||
@ -247,31 +225,31 @@ TEST_F(BinaryStreamTest, StreamRefBounds) {
|
||||
|
||||
// Read 1 byte from offset 2 should work
|
||||
ASSERT_EQ(InputData.size(), Ref.getLength());
|
||||
ASSERT_NO_ERROR(Ref.readBytes(2, 1, Buffer));
|
||||
ASSERT_THAT_ERROR(Ref.readBytes(2, 1, Buffer), Succeeded());
|
||||
EXPECT_EQ(makeArrayRef(InputData).slice(2, 1), Buffer);
|
||||
|
||||
// Reading everything from offset 2 on.
|
||||
ASSERT_NO_ERROR(Ref.readLongestContiguousChunk(2, Buffer));
|
||||
ASSERT_THAT_ERROR(Ref.readLongestContiguousChunk(2, Buffer), Succeeded());
|
||||
if (Stream.IsContiguous)
|
||||
EXPECT_EQ(makeArrayRef(InputData).slice(2), Buffer);
|
||||
else
|
||||
EXPECT_FALSE(Buffer.empty());
|
||||
|
||||
// Reading 6 bytes from offset 0 is too big.
|
||||
EXPECT_ERROR(Ref.readBytes(0, 6, Buffer));
|
||||
EXPECT_ERROR(Ref.readLongestContiguousChunk(6, Buffer));
|
||||
EXPECT_THAT_ERROR(Ref.readBytes(0, 6, Buffer), Failed());
|
||||
EXPECT_THAT_ERROR(Ref.readLongestContiguousChunk(6, Buffer), Failed());
|
||||
|
||||
// Reading 1 byte from offset 2 after dropping 1 byte is the same as reading
|
||||
// 1 byte from offset 3.
|
||||
Ref = Ref.drop_front(1);
|
||||
ASSERT_NO_ERROR(Ref.readBytes(2, 1, Buffer));
|
||||
ASSERT_THAT_ERROR(Ref.readBytes(2, 1, Buffer), Succeeded());
|
||||
if (Stream.IsContiguous)
|
||||
EXPECT_EQ(makeArrayRef(InputData).slice(3, 1), Buffer);
|
||||
else
|
||||
EXPECT_FALSE(Buffer.empty());
|
||||
|
||||
// Reading everything from offset 2 on after dropping 1 byte.
|
||||
ASSERT_NO_ERROR(Ref.readLongestContiguousChunk(2, Buffer));
|
||||
ASSERT_THAT_ERROR(Ref.readLongestContiguousChunk(2, Buffer), Succeeded());
|
||||
if (Stream.IsContiguous)
|
||||
EXPECT_EQ(makeArrayRef(InputData).slice(3), Buffer);
|
||||
else
|
||||
@ -280,11 +258,11 @@ TEST_F(BinaryStreamTest, StreamRefBounds) {
|
||||
// Reading 2 bytes from offset 2 after dropping 2 bytes is the same as
|
||||
// reading 2 bytes from offset 4, and should fail.
|
||||
Ref = Ref.drop_front(1);
|
||||
EXPECT_ERROR(Ref.readBytes(2, 2, Buffer));
|
||||
EXPECT_THAT_ERROR(Ref.readBytes(2, 2, Buffer), Failed());
|
||||
|
||||
// But if we read the longest contiguous chunk instead, we should still
|
||||
// get the 1 byte at the end.
|
||||
ASSERT_NO_ERROR(Ref.readLongestContiguousChunk(2, Buffer));
|
||||
ASSERT_THAT_ERROR(Ref.readLongestContiguousChunk(2, Buffer), Succeeded());
|
||||
EXPECT_EQ(makeArrayRef(InputData).take_back(), Buffer);
|
||||
}
|
||||
}
|
||||
@ -298,27 +276,33 @@ TEST_F(BinaryStreamTest, DropOperations) {
|
||||
BinaryStreamRef Original(InputData, support::little);
|
||||
ASSERT_EQ(InputData.size(), Original.getLength());
|
||||
|
||||
EXPECT_NO_ERROR(Original.readBytes(0, InputData.size(), Result));
|
||||
EXPECT_THAT_ERROR(Original.readBytes(0, InputData.size(), Result),
|
||||
Succeeded());
|
||||
EXPECT_EQ(RefData, Result);
|
||||
|
||||
auto Dropped = Original.drop_front(2);
|
||||
EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
|
||||
EXPECT_THAT_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result),
|
||||
Succeeded());
|
||||
EXPECT_EQ(RefData.drop_front(2), Result);
|
||||
|
||||
Dropped = Original.drop_back(2);
|
||||
EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
|
||||
EXPECT_THAT_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result),
|
||||
Succeeded());
|
||||
EXPECT_EQ(RefData.drop_back(2), Result);
|
||||
|
||||
Dropped = Original.keep_front(2);
|
||||
EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
|
||||
EXPECT_THAT_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result),
|
||||
Succeeded());
|
||||
EXPECT_EQ(RefData.take_front(2), Result);
|
||||
|
||||
Dropped = Original.keep_back(2);
|
||||
EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
|
||||
EXPECT_THAT_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result),
|
||||
Succeeded());
|
||||
EXPECT_EQ(RefData.take_back(2), Result);
|
||||
|
||||
Dropped = Original.drop_symmetric(2);
|
||||
EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
|
||||
EXPECT_THAT_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result),
|
||||
Succeeded());
|
||||
EXPECT_EQ(RefData.drop_front(2).drop_back(2), Result);
|
||||
}
|
||||
|
||||
@ -341,22 +325,24 @@ TEST_F(BinaryStreamTest, MutableBinaryByteStreamBounds) {
|
||||
|
||||
// Read everything from Offset until the end of the input data.
|
||||
ArrayRef<uint8_t> Data;
|
||||
ASSERT_NO_ERROR(Stream.Input->readBytes(Offset, ExpectedSize, Data));
|
||||
ASSERT_THAT_ERROR(Stream.Input->readBytes(Offset, ExpectedSize, Data),
|
||||
Succeeded());
|
||||
ASSERT_EQ(ExpectedSize, Data.size());
|
||||
|
||||
// Then write it to the destination.
|
||||
ASSERT_NO_ERROR(Stream.Output->writeBytes(0, Data));
|
||||
ASSERT_THAT_ERROR(Stream.Output->writeBytes(0, Data), Succeeded());
|
||||
|
||||
// Then we read back what we wrote, it should match the corresponding
|
||||
// slice of the original input data.
|
||||
ArrayRef<uint8_t> Data2;
|
||||
ASSERT_NO_ERROR(Stream.Output->readBytes(Offset, ExpectedSize, Data2));
|
||||
ASSERT_THAT_ERROR(Stream.Output->readBytes(Offset, ExpectedSize, Data2),
|
||||
Succeeded());
|
||||
EXPECT_EQ(makeArrayRef(InputData).drop_front(Offset), Data2);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> BigData = {0, 1, 2, 3, 4};
|
||||
// 2. If the write is too big, it should fail.
|
||||
EXPECT_ERROR(Stream.Output->writeBytes(3, BigData));
|
||||
EXPECT_THAT_ERROR(Stream.Output->writeBytes(3, BigData), Failed());
|
||||
}
|
||||
}
|
||||
|
||||
@ -456,7 +442,7 @@ TEST_F(BinaryStreamTest, StreamReaderBounds) {
|
||||
StringRef S;
|
||||
BinaryStreamReader Reader(*Stream.Input);
|
||||
EXPECT_EQ(0U, Reader.bytesRemaining());
|
||||
EXPECT_ERROR(Reader.readFixedString(S, 1));
|
||||
EXPECT_THAT_ERROR(Reader.readFixedString(S, 1), Failed());
|
||||
}
|
||||
|
||||
Bytes.resize(5);
|
||||
@ -465,8 +451,8 @@ TEST_F(BinaryStreamTest, StreamReaderBounds) {
|
||||
StringRef S;
|
||||
BinaryStreamReader Reader(*Stream.Input);
|
||||
EXPECT_EQ(Bytes.size(), Reader.bytesRemaining());
|
||||
EXPECT_NO_ERROR(Reader.readFixedString(S, 5));
|
||||
EXPECT_ERROR(Reader.readFixedString(S, 6));
|
||||
EXPECT_THAT_ERROR(Reader.readFixedString(S, 5), Succeeded());
|
||||
EXPECT_THAT_ERROR(Reader.readFixedString(S, 6), Failed());
|
||||
}
|
||||
}
|
||||
|
||||
@ -484,11 +470,11 @@ TEST_F(BinaryStreamTest, StreamReaderIntegers) {
|
||||
|
||||
for (auto &Stream : Streams) {
|
||||
BinaryStreamWriter Writer(*Stream.Output);
|
||||
ASSERT_NO_ERROR(Writer.writeObject(Little));
|
||||
ASSERT_NO_ERROR(Writer.writeObject(Big));
|
||||
ASSERT_NO_ERROR(Writer.writeInteger(NS));
|
||||
ASSERT_NO_ERROR(Writer.writeInteger(NI));
|
||||
ASSERT_NO_ERROR(Writer.writeInteger(NUL));
|
||||
ASSERT_THAT_ERROR(Writer.writeObject(Little), Succeeded());
|
||||
ASSERT_THAT_ERROR(Writer.writeObject(Big), Succeeded());
|
||||
ASSERT_THAT_ERROR(Writer.writeInteger(NS), Succeeded());
|
||||
ASSERT_THAT_ERROR(Writer.writeInteger(NI), Succeeded());
|
||||
ASSERT_THAT_ERROR(Writer.writeInteger(NUL), Succeeded());
|
||||
|
||||
const support::ulittle64_t *Little2;
|
||||
const support::ubig32_t *Big2;
|
||||
@ -498,11 +484,11 @@ TEST_F(BinaryStreamTest, StreamReaderIntegers) {
|
||||
|
||||
// 1. Reading fields individually.
|
||||
BinaryStreamReader Reader(*Stream.Input);
|
||||
ASSERT_NO_ERROR(Reader.readObject(Little2));
|
||||
ASSERT_NO_ERROR(Reader.readObject(Big2));
|
||||
ASSERT_NO_ERROR(Reader.readInteger(NS2));
|
||||
ASSERT_NO_ERROR(Reader.readInteger(NI2));
|
||||
ASSERT_NO_ERROR(Reader.readInteger(NUL2));
|
||||
ASSERT_THAT_ERROR(Reader.readObject(Little2), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.readObject(Big2), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.readInteger(NS2), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.readInteger(NI2), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.readInteger(NUL2), Succeeded());
|
||||
ASSERT_EQ(0U, Reader.bytesRemaining());
|
||||
|
||||
EXPECT_EQ(Little, *Little2);
|
||||
@ -523,13 +509,13 @@ TEST_F(BinaryStreamTest, StreamReaderIntegerArray) {
|
||||
for (auto &Stream : Streams) {
|
||||
BinaryStreamReader Reader(*Stream.Input);
|
||||
ArrayRef<int> IntsRef;
|
||||
ASSERT_NO_ERROR(Reader.readArray(IntsRef, Ints.size()));
|
||||
ASSERT_THAT_ERROR(Reader.readArray(IntsRef, Ints.size()), Succeeded());
|
||||
ASSERT_EQ(0U, Reader.bytesRemaining());
|
||||
EXPECT_EQ(makeArrayRef(Ints), IntsRef);
|
||||
|
||||
Reader.setOffset(0);
|
||||
FixedStreamArray<int> FixedIntsRef;
|
||||
ASSERT_NO_ERROR(Reader.readArray(FixedIntsRef, Ints.size()));
|
||||
ASSERT_THAT_ERROR(Reader.readArray(FixedIntsRef, Ints.size()), Succeeded());
|
||||
ASSERT_EQ(0U, Reader.bytesRemaining());
|
||||
ASSERT_EQ(Ints, std::vector<int>(FixedIntsRef.begin(), FixedIntsRef.end()));
|
||||
}
|
||||
@ -545,7 +531,7 @@ TEST_F(BinaryStreamTest, StreamReaderEnum) {
|
||||
for (auto &Stream : Streams) {
|
||||
BinaryStreamWriter Writer(*Stream.Output);
|
||||
for (auto Value : Enums)
|
||||
ASSERT_NO_ERROR(Writer.writeEnum(Value));
|
||||
ASSERT_THAT_ERROR(Writer.writeEnum(Value), Succeeded());
|
||||
|
||||
BinaryStreamReader Reader(*Stream.Input);
|
||||
|
||||
@ -554,7 +540,7 @@ TEST_F(BinaryStreamTest, StreamReaderEnum) {
|
||||
|
||||
for (size_t I = 0; I < Enums.size(); ++I) {
|
||||
MyEnum Value;
|
||||
ASSERT_NO_ERROR(Reader.readEnum(Value));
|
||||
ASSERT_THAT_ERROR(Reader.readEnum(Value), Succeeded());
|
||||
EXPECT_EQ(Enums[I], Value);
|
||||
}
|
||||
ASSERT_EQ(0U, Reader.bytesRemaining());
|
||||
@ -587,9 +573,9 @@ TEST_F(BinaryStreamTest, StreamReaderObject) {
|
||||
const Foo *FPtrOut = nullptr;
|
||||
const Foo *GPtrOut = nullptr;
|
||||
const Foo *HPtrOut = nullptr;
|
||||
ASSERT_NO_ERROR(Reader.readObject(FPtrOut));
|
||||
ASSERT_NO_ERROR(Reader.readObject(GPtrOut));
|
||||
ASSERT_NO_ERROR(Reader.readObject(HPtrOut));
|
||||
ASSERT_THAT_ERROR(Reader.readObject(FPtrOut), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.readObject(GPtrOut), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.readObject(HPtrOut), Succeeded());
|
||||
EXPECT_EQ(0U, Reader.bytesRemaining());
|
||||
EXPECT_EQ(Foos[0], *FPtrOut);
|
||||
EXPECT_EQ(Foos[1], *GPtrOut);
|
||||
@ -610,10 +596,10 @@ TEST_F(BinaryStreamTest, StreamReaderStrings) {
|
||||
StringRef S2;
|
||||
StringRef S3;
|
||||
StringRef S4;
|
||||
ASSERT_NO_ERROR(Reader.readCString(S1));
|
||||
ASSERT_NO_ERROR(Reader.readCString(S2));
|
||||
ASSERT_NO_ERROR(Reader.readCString(S3));
|
||||
ASSERT_NO_ERROR(Reader.readCString(S4));
|
||||
ASSERT_THAT_ERROR(Reader.readCString(S1), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.readCString(S2), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.readCString(S3), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.readCString(S4), Succeeded());
|
||||
ASSERT_EQ(0U, Reader.bytesRemaining());
|
||||
|
||||
EXPECT_EQ("One", S1);
|
||||
@ -623,14 +609,14 @@ TEST_F(BinaryStreamTest, StreamReaderStrings) {
|
||||
|
||||
S1 = S2 = S3 = S4 = "";
|
||||
Reader.setOffset(0);
|
||||
ASSERT_NO_ERROR(Reader.readFixedString(S1, 3));
|
||||
ASSERT_NO_ERROR(Reader.skip(1));
|
||||
ASSERT_NO_ERROR(Reader.readFixedString(S2, 3));
|
||||
ASSERT_NO_ERROR(Reader.skip(1));
|
||||
ASSERT_NO_ERROR(Reader.readFixedString(S3, 5));
|
||||
ASSERT_NO_ERROR(Reader.skip(1));
|
||||
ASSERT_NO_ERROR(Reader.readFixedString(S4, 4));
|
||||
ASSERT_NO_ERROR(Reader.skip(1));
|
||||
ASSERT_THAT_ERROR(Reader.readFixedString(S1, 3), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.skip(1), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.readFixedString(S2, 3), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.skip(1), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.readFixedString(S3, 5), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.skip(1), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.readFixedString(S4, 4), Succeeded());
|
||||
ASSERT_THAT_ERROR(Reader.skip(1), Succeeded());
|
||||
ASSERT_EQ(0U, Reader.bytesRemaining());
|
||||
|
||||
EXPECT_EQ("One", S1);
|
||||
@ -648,16 +634,16 @@ TEST_F(BinaryStreamTest, StreamWriterBounds) {
|
||||
|
||||
// 1. Can write a string that exactly fills the buffer.
|
||||
EXPECT_EQ(5U, Writer.bytesRemaining());
|
||||
EXPECT_NO_ERROR(Writer.writeFixedString("abcde"));
|
||||
EXPECT_THAT_ERROR(Writer.writeFixedString("abcde"), Succeeded());
|
||||
EXPECT_EQ(0U, Writer.bytesRemaining());
|
||||
|
||||
// 2. Can write an empty string even when you're full
|
||||
EXPECT_NO_ERROR(Writer.writeFixedString(""));
|
||||
EXPECT_ERROR(Writer.writeFixedString("a"));
|
||||
EXPECT_THAT_ERROR(Writer.writeFixedString(""), Succeeded());
|
||||
EXPECT_THAT_ERROR(Writer.writeFixedString("a"), Failed());
|
||||
|
||||
// 3. Can't write a string that is one character too long.
|
||||
Writer.setOffset(0);
|
||||
EXPECT_ERROR(Writer.writeFixedString("abcdef"));
|
||||
EXPECT_THAT_ERROR(Writer.writeFixedString("abcdef"), Failed());
|
||||
}
|
||||
}
|
||||
|
||||
@ -676,11 +662,12 @@ TEST_F(BinaryStreamTest, StreamWriterIntegerArrays) {
|
||||
ArrayRef<int> Ints;
|
||||
ArrayRef<int> Ints2;
|
||||
// First read them, then write them, then read them back.
|
||||
ASSERT_NO_ERROR(Reader.readArray(Ints, SourceInts.size()));
|
||||
ASSERT_NO_ERROR(Writer.writeArray(Ints));
|
||||
ASSERT_THAT_ERROR(Reader.readArray(Ints, SourceInts.size()), Succeeded());
|
||||
ASSERT_THAT_ERROR(Writer.writeArray(Ints), Succeeded());
|
||||
|
||||
BinaryStreamReader ReaderBacker(*Stream.Output);
|
||||
ASSERT_NO_ERROR(ReaderBacker.readArray(Ints2, SourceInts.size()));
|
||||
ASSERT_THAT_ERROR(ReaderBacker.readArray(Ints2, SourceInts.size()),
|
||||
Succeeded());
|
||||
|
||||
EXPECT_EQ(makeArrayRef(SourceInts), Ints2);
|
||||
}
|
||||
@ -698,12 +685,12 @@ TEST_F(BinaryStreamTest, StringWriterStrings) {
|
||||
for (auto &Stream : Streams) {
|
||||
BinaryStreamWriter Writer(*Stream.Output);
|
||||
for (auto S : Strings)
|
||||
ASSERT_NO_ERROR(Writer.writeCString(S));
|
||||
ASSERT_THAT_ERROR(Writer.writeCString(S), Succeeded());
|
||||
std::vector<StringRef> InStrings;
|
||||
BinaryStreamReader Reader(*Stream.Input);
|
||||
while (!Reader.empty()) {
|
||||
StringRef S;
|
||||
ASSERT_NO_ERROR(Reader.readCString(S));
|
||||
ASSERT_THAT_ERROR(Reader.readCString(S), Succeeded());
|
||||
InStrings.push_back(S);
|
||||
}
|
||||
EXPECT_EQ(makeArrayRef(Strings), makeArrayRef(InStrings));
|
||||
@ -748,7 +735,7 @@ TEST_F(BinaryStreamTest, BinaryItemStream) {
|
||||
MutableArrayRef<uint8_t> Buffer(Ptr, sizeof(Foo));
|
||||
MutableBinaryByteStream Stream(Buffer, llvm::support::big);
|
||||
BinaryStreamWriter Writer(Stream);
|
||||
ASSERT_NO_ERROR(Writer.writeObject(F));
|
||||
ASSERT_THAT_ERROR(Writer.writeObject(F), Succeeded());
|
||||
Objects.push_back(BinaryItemStreamObject(Buffer));
|
||||
}
|
||||
|
||||
@ -758,7 +745,7 @@ TEST_F(BinaryStreamTest, BinaryItemStream) {
|
||||
|
||||
for (const auto &F : Foos) {
|
||||
const Foo *F2;
|
||||
ASSERT_NO_ERROR(Reader.readObject(F2));
|
||||
ASSERT_THAT_ERROR(Reader.readObject(F2), Succeeded());
|
||||
|
||||
EXPECT_EQ(F.X, F2->X);
|
||||
EXPECT_DOUBLE_EQ(F.Y, F2->Y);
|
||||
|
@ -1,5 +1,6 @@
|
||||
set(LLVM_LINK_COMPONENTS
|
||||
Support
|
||||
TestingSupport
|
||||
)
|
||||
|
||||
add_llvm_unittest(SupportTests
|
||||
|
Loading…
Reference in New Issue
Block a user