#include "llvm/Support/DataExtractor.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
usingnamespacellvm;
namespace {
const char numberData[] = …;
const char leb128data[] = …;
const char bigleb128data[] = …;
TEST(DataExtractorTest, OffsetOverflow) { … }
TEST(DataExtractorTest, UnsignedNumbers) { … }
TEST(DataExtractorTest, SignedNumbers) { … }
TEST(DataExtractorTest, Strings) { … }
TEST(DataExtractorTest, LEB128) { … }
TEST(DataExtractorTest, LEB128_error) { … }
TEST(DataExtractorTest, Cursor_tell) { … }
TEST(DataExtractorTest, Cursor_seek) { … }
TEST(DataExtractorTest, Cursor_takeError) { … }
TEST(DataExtractorTest, Cursor_chaining) { … }
#if defined(GTEST_HAS_DEATH_TEST) && defined(_DEBUG) && \
LLVM_ENABLE_ABI_BREAKING_CHECKS
TEST(DataExtractorDeathTest, Cursor) {
DataExtractor DE(StringRef("AB"), false, 8);
EXPECT_DEATH(DataExtractor::Cursor(0),
"Success values must still be checked prior to being destroyed");
{
auto C = std::make_unique<DataExtractor::Cursor>(0);
EXPECT_EQ(0u, DE.getU32(*C));
EXPECT_DEATH(C.reset(), "unexpected end of data");
EXPECT_THAT_ERROR(C->takeError(), Failed());
}
{
auto C = std::make_unique<DataExtractor::Cursor>(0);
EXPECT_EQ('A', DE.getU8(*C));
EXPECT_DEATH(
C.reset(),
"Success values must still be checked prior to being destroyed");
EXPECT_THAT_ERROR(C->takeError(), Succeeded());
}
{
auto C = std::make_unique<DataExtractor::Cursor>(0);
EXPECT_EQ('A', DE.getU8(*C));
EXPECT_EQ(0u, DE.getU32(*C));
EXPECT_DEATH(C.reset(), "unexpected end of data");
EXPECT_THAT_ERROR(C->takeError(), Failed());
}
{
auto C = std::make_unique<DataExtractor::Cursor>(0);
EXPECT_EQ(0u, DE.getU32(*C));
EXPECT_EQ(0, DE.getU8(*C));
EXPECT_DEATH(C.reset(), "unexpected end of data");
EXPECT_THAT_ERROR(C->takeError(), Failed());
}
}
#endif
TEST(DataExtractorTest, getU8_vector) { … }
TEST(DataExtractorTest, getU24) { … }
TEST(DataExtractorTest, skip) { … }
TEST(DataExtractorTest, eof) { … }
TEST(DataExtractorTest, size) { … }
TEST(DataExtractorTest, FixedLengthString) { … }
TEST(DataExtractorTest, GetBytes) { … }
}