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

Protected Member Functions

void SetUp () override
 
void runSimpleTest (const DataHolder &dh)
 

Protected Attributes

std::unique_ptr< Codeccodec_
 

Detailed Description

Definition at line 381 of file CompressionTest.cpp.

Member Function Documentation

void folly::io::test::CompressionCorruptionTest::runSimpleTest ( const DataHolder dh)
protected

Definition at line 392 of file CompressionTest.cpp.

References codec_, folly::io::test::DataHolder::data(), EXPECT_EQ, EXPECT_THROW, folly::io::test::DataHolder::hash(), folly::io::test::hashIOBuf(), uint64_t, and folly::IOBuf::wrapBuffer().

392  {
393  constexpr uint64_t uncompressedLength = 42;
394  auto original = IOBuf::wrapBuffer(dh.data(uncompressedLength));
395  auto compressed = codec_->compress(original.get());
396 
397  if (!codec_->needsUncompressedLength()) {
398  auto uncompressed = codec_->uncompress(compressed.get());
399  EXPECT_EQ(uncompressedLength, uncompressed->computeChainDataLength());
400  EXPECT_EQ(dh.hash(uncompressedLength), hashIOBuf(uncompressed.get()));
401  }
402  {
403  auto uncompressed =
404  codec_->uncompress(compressed.get(), uncompressedLength);
405  EXPECT_EQ(uncompressedLength, uncompressed->computeChainDataLength());
406  EXPECT_EQ(dh.hash(uncompressedLength), hashIOBuf(uncompressed.get()));
407  }
408 
409  EXPECT_THROW(
410  codec_->uncompress(compressed.get(), uncompressedLength + 1),
411  std::runtime_error);
412 
413  auto corrupted = compressed->clone();
414  corrupted->unshare();
415  // Truncate the last character
416  corrupted->prev()->trimEnd(1);
417  if (!codec_->needsUncompressedLength()) {
418  EXPECT_THROW(codec_->uncompress(corrupted.get()), std::runtime_error);
419  }
420 
421  EXPECT_THROW(
422  codec_->uncompress(corrupted.get(), uncompressedLength),
423  std::runtime_error);
424 
425  corrupted = compressed->clone();
426  corrupted->unshare();
427  // Corrupt the first character
428  ++(corrupted->writableData()[0]);
429 
430  if (!codec_->needsUncompressedLength()) {
431  EXPECT_THROW(codec_->uncompress(corrupted.get()), std::runtime_error);
432  }
433 
434  EXPECT_THROW(
435  codec_->uncompress(corrupted.get(), uncompressedLength),
436  std::runtime_error);
437 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
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
uint64_t hashIOBuf(const IOBuf *buf)
void folly::io::test::CompressionCorruptionTest::SetUp ( )
inlineoverrideprotected

Definition at line 383 of file CompressionTest.cpp.

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

383  {
384  codec_ = getCodec(GetParam());
385  }
std::unique_ptr< Codec > getCodec(CodecType type, int level)

Member Data Documentation

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

Definition at line 389 of file CompressionTest.cpp.


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