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) {
- EXPECT_FALSE(getCodec(CodecType::NO_COMPRESSION)->needsUncompressedLength());
- EXPECT_TRUE(getCodec(CodecType::LZ4)->needsUncompressedLength());
- EXPECT_FALSE(getCodec(CodecType::SNAPPY)->needsUncompressedLength());
- EXPECT_FALSE(getCodec(CodecType::ZLIB)->needsUncompressedLength());
- EXPECT_FALSE(getCodec(CodecType::LZ4_VARINT_SIZE)->needsUncompressedLength());
- EXPECT_TRUE(getCodec(CodecType::LZMA2)->needsUncompressedLength());
- EXPECT_FALSE(getCodec(CodecType::LZMA2_VARINT_SIZE)
- ->needsUncompressedLength());
- EXPECT_FALSE(getCodec(CodecType::ZSTD)->needsUncompressedLength());
- EXPECT_FALSE(getCodec(CodecType::GZIP)->needsUncompressedLength());
+ 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 },
+ };
+
+ for (auto const& test : expectations) {
+ if (hasCodec(test.type)) {
+ EXPECT_EQ(getCodec(test.type)->needsUncompressedLength(),
+ test.needsUncompressedLength);
+ }
+ }
}
class CompressionTest
testing::Combine(
testing::Values(0, 1, 12, 22, 25, 27),
testing::Values(1, 2, 3, 8, 65),
- testing::Values(
- CodecType::NO_COMPRESSION,
- CodecType::LZ4,
- CodecType::SNAPPY,
- CodecType::ZLIB,
- CodecType::LZ4_VARINT_SIZE,
- CodecType::LZMA2,
- CodecType::LZMA2_VARINT_SIZE,
- CodecType::ZSTD,
- CodecType::GZIP)));
+ testing::ValuesIn(availableCodecs())));
class CompressionVarintTest
: public testing::TestWithParam<std::tr1::tuple<int, CodecType>> {
CompressionVarintTest,
testing::Combine(
testing::Values(0, 1, 12, 22, 25, 27),
- testing::Values(
+ testing::ValuesIn(supportedCodecs({
CodecType::LZ4_VARINT_SIZE,
- CodecType::LZMA2_VARINT_SIZE)));
+ CodecType::LZMA2_VARINT_SIZE,
+ }))));
class CompressionCorruptionTest : public testing::TestWithParam<CodecType> {
protected:
INSTANTIATE_TEST_CASE_P(
CompressionCorruptionTest,
CompressionCorruptionTest,
- testing::Values(
+ testing::ValuesIn(
// NO_COMPRESSION can't detect corruption
// LZ4 can't detect corruption reliably (sigh)
- CodecType::SNAPPY,
- CodecType::ZLIB));
+ supportedCodecs({
+ CodecType::SNAPPY,
+ CodecType::ZLIB,
+ })));
}}} // namespaces
--- /dev/null
+ACLOCAL_AMFLAGS = -I m4
+
+CPPFLAGS = -I$(top_srcdir)/test/gtest/googletest/include
+ldadd = $(top_builddir)/test/libfollytestmain.la
+
+# compression_test takes several minutes, so it's not run automatically.
+TESTS = \
+ iobuf_test \
+ iobuf_cursor_test \
+ iobuf_queue_test \
+ record_io_test \
+ shutdown_socket_set_test
+
+check_PROGRAMS = $(TESTS) \
+ compression_test
+
+iobuf_test_SOURCES = IOBufTest.cpp
+iobuf_test_LDADD = $(ldadd)
+
+iobuf_cursor_test_SOURCES = IOBufCursorTest.cpp
+iobuf_cursor_test_LDADD = $(ldadd)
+
+compression_test_SOURCES = CompressionTest.cpp
+compression_test_LDADD = $(top_builddir)/libfolly.la \
+ $(top_builddir)/test/libgtest.la \
+ $(top_builddir)/libfollybenchmark.la
+
+iobuf_queue_test_SOURCES = IOBufQueueTest.cpp
+iobuf_queue_test_LDADD = $(ldadd)
+
+record_io_test_SOURCES = RecordIOTest.cpp
+record_io_test_LDADD = $(ldadd)
+
+shutdown_socket_set_test_SOURCES = ShutdownSocketSetTest.cpp
+shutdown_socket_set_test_LDADD = $(ldadd)