+class ConstantDataHolder : public DataHolder {
+ public:
+ explicit ConstantDataHolder(size_t sizeLog2);
+};
+
+ConstantDataHolder::ConstantDataHolder(size_t sizeLog2)
+ : DataHolder(sizeLog2) {
+ memset(data_.get(), 'a', size_);
+}
+
+constexpr size_t dataSizeLog2 = 27; // 128MiB
+RandomDataHolder randomDataHolder(dataSizeLog2);
+ConstantDataHolder constantDataHolder(dataSizeLog2);
+
+// The intersection of the provided codecs & those that are compiled in.
+static std::vector<CodecType> supportedCodecs(std::vector<CodecType> const& v) {
+ std::vector<CodecType> supported;
+
+ std::copy_if(
+ std::begin(v),
+ std::end(v),
+ std::back_inserter(supported),
+ hasCodec);
+
+ return supported;
+}
+
+// All compiled-in compression codecs.
+static std::vector<CodecType> availableCodecs() {
+ std::vector<CodecType> codecs;
+
+ for (size_t i = 0; i < static_cast<size_t>(CodecType::NUM_CODEC_TYPES); ++i) {
+ auto type = static_cast<CodecType>(i);
+ if (hasCodec(type)) {
+ codecs.push_back(type);
+ }
+ }
+
+ return codecs;
+}
+
+TEST(CompressionTestNeedsUncompressedLength, Simple) {
+ static const struct { CodecType type; bool needsUncompressedLength; }
+ expectations[] = {
+ { CodecType::NO_COMPRESSION, false },
+ { CodecType::LZ4, true },
+ { CodecType::SNAPPY, false },
+ { CodecType::ZLIB, false },
+ { CodecType::LZ4_VARINT_SIZE, false },
+ { CodecType::LZMA2, true },
+ { CodecType::LZMA2_VARINT_SIZE, false },
+ { CodecType::ZSTD, false },
+ { CodecType::GZIP, false },
+ { CodecType::LZ4_FRAME, false },
+ };
+
+ for (auto const& test : expectations) {
+ if (hasCodec(test.type)) {
+ EXPECT_EQ(getCodec(test.type)->needsUncompressedLength(),
+ test.needsUncompressedLength);
+ }
+ }
+}
+
+class CompressionTest
+ : public testing::TestWithParam<std::tr1::tuple<int, int, CodecType>> {
+ protected:
+ void SetUp() override {
+ auto tup = GetParam();
+ uncompressedLength_ = uint64_t(1) << std::tr1::get<0>(tup);
+ chunks_ = std::tr1::get<1>(tup);
+ codec_ = getCodec(std::tr1::get<2>(tup));
+ }
+
+ void runSimpleIOBufTest(const DataHolder& dh);