proxygen
folly::io::test::AutomaticCodecTest Class Reference
Inheritance diagram for folly::io::test::AutomaticCodecTest:

Protected Member Functions

void SetUp () override
 
void runSimpleTest (const DataHolder &dh)
 
std::unique_ptr< CodecgetTerminalCodec ()
 

Protected Attributes

std::unique_ptr< Codeccodec_
 
std::unique_ptr< Codecauto_
 
CodecType codecType_
 
bool autoType_
 

Detailed Description

Definition at line 1010 of file CompressionTest.cpp.

Member Function Documentation

std::unique_ptr<Codec> folly::io::test::AutomaticCodecTest::getTerminalCodec ( )
inlineprotected

Definition at line 1026 of file CompressionTest.cpp.

References folly::io::getCodec().

1026  {
1027  return (autoType_ ? nullptr : getCodec(codecType_));
1028  }
std::unique_ptr< Codec > getCodec(CodecType type, int level)
void folly::io::test::AutomaticCodecTest::runSimpleTest ( const DataHolder dh)
protected

Definition at line 1037 of file CompressionTest.cpp.

References ASSERT_GE, codec_, folly::io::test::DataHolder::data(), EXPECT_EQ, folly::io::test::DataHolder::hash(), folly::io::test::hashIOBuf(), i, folly::gen::move, folly::split(), uint64_t, and folly::IOBuf::wrapBuffer().

1037  {
1038  constexpr uint64_t uncompressedLength = 1000;
1039  auto original = IOBuf::wrapBuffer(dh.data(uncompressedLength));
1040  auto compressed = codec_->compress(original.get());
1041 
1042  if (!codec_->needsUncompressedLength()) {
1043  auto uncompressed = auto_->uncompress(compressed.get());
1044  EXPECT_EQ(uncompressedLength, uncompressed->computeChainDataLength());
1045  EXPECT_EQ(dh.hash(uncompressedLength), hashIOBuf(uncompressed.get()));
1046  }
1047  {
1048  auto uncompressed = auto_->uncompress(compressed.get(), uncompressedLength);
1049  EXPECT_EQ(uncompressedLength, uncompressed->computeChainDataLength());
1050  EXPECT_EQ(dh.hash(uncompressedLength), hashIOBuf(uncompressed.get()));
1051  }
1052  ASSERT_GE(compressed->computeChainDataLength(), 8);
1053  for (size_t i = 0; i < 8; ++i) {
1054  auto split = compressed->clone();
1055  auto rest = compressed->clone();
1056  split->trimEnd(split->length() - i);
1057  rest->trimStart(i);
1058  split->appendChain(std::move(rest));
1059  auto uncompressed = auto_->uncompress(split.get(), uncompressedLength);
1060  EXPECT_EQ(uncompressedLength, uncompressed->computeChainDataLength());
1061  EXPECT_EQ(dh.hash(uncompressedLength), hashIOBuf(uncompressed.get()));
1062  }
1063 }
#define ASSERT_GE(val1, val2)
Definition: gtest.h:1972
static std::unique_ptr< IOBuf > wrapBuffer(const void *buf, std::size_t capacity)
Definition: IOBuf.cpp:353
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void split(const Delim &delimiter, const String &input, std::vector< OutputType > &out, bool ignoreEmpty)
Definition: String-inl.h:382
uint64_t hashIOBuf(const IOBuf *buf)
void folly::io::test::AutomaticCodecTest::SetUp ( )
inlineoverrideprotected

Definition at line 1012 of file CompressionTest.cpp.

References codec_, folly::io::getAutoUncompressionCodec(), and folly::io::getCodec().

1012  {
1013  codecType_ = GetParam();
1015  autoType_ = std::any_of(
1016  autoUncompressionCodecTypes.begin(),
1017  autoUncompressionCodecTypes.end(),
1018  [&](CodecType o) { return codecType_ == o; });
1019  // Add the codec with type codecType_ as the terminal codec if it is not in
1020  // autoUncompressionCodecTypes.
1022  }
std::unique_ptr< Codec > getTerminalCodec()
std::unique_ptr< Codec > getAutoUncompressionCodec(std::vector< std::unique_ptr< Codec >> customCodecs, std::unique_ptr< Codec > terminalCodec)
std::unique_ptr< Codec > getCodec(CodecType type, int level)

Member Data Documentation

std::unique_ptr<Codec> folly::io::test::AutomaticCodecTest::auto_
protected

Definition at line 1031 of file CompressionTest.cpp.

bool folly::io::test::AutomaticCodecTest::autoType_
protected

Definition at line 1034 of file CompressionTest.cpp.

std::unique_ptr<Codec> folly::io::test::AutomaticCodecTest::codec_
protected

Definition at line 1030 of file CompressionTest.cpp.

CodecType folly::io::test::AutomaticCodecTest::codecType_
protected

Definition at line 1032 of file CompressionTest.cpp.


The documentation for this class was generated from the following file: