Skip to content

Commit

Permalink
add zstd test
Browse files Browse the repository at this point in the history
  • Loading branch information
james-rms committed Nov 14, 2023
1 parent 408f0b6 commit 04d9ca4
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions cpp/test/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,13 +627,62 @@ TEST_CASE("LZ4 compression", "[reader][writer]") {

reader.close();
}
}
#endif

#ifndef MCAP_COMPRESSION_NO_LZ4
TEST_CASE("zstd compression", "[reader][writer]") {
SECTION("Roundtrip") {
Buffer buffer;

mcap::McapWriter writer;
mcap::McapWriterOptions opts("test");
opts.compression = mcap::Compression::Zstd;
opts.forceCompression = true;
writer.open(buffer, opts);
mcap::Schema schema("schema", "schemaEncoding", "ab");
writer.addSchema(schema);
mcap::Channel channel("topic", "messageEncoding", schema.id);
writer.addChannel(channel);

mcap::Message msg;
std::vector<std::byte> data = {std::byte(1), std::byte(2), std::byte(3)};
WriteMsg(writer, channel.id, 0, 2, 1, data);

writer.close();

mcap::McapReader reader;
auto status = reader.open(buffer);
requireOk(status);

size_t messageCount = 0;
const auto onProblem = [](const mcap::Status& status) {
FAIL("Status " + std::to_string((int)status.code) + ": " + status.message);
};
for (const auto& msgView : reader.readMessages(onProblem)) {
++messageCount;
REQUIRE(msgView.message.sequence == 0);
REQUIRE(msgView.message.channelId == channel.id);
REQUIRE(msgView.message.logTime == 2);
REQUIRE(msgView.message.publishTime == 1);
REQUIRE(msgView.message.dataSize == data.size());
REQUIRE(std::vector(msgView.message.data, msgView.message.data + msgView.message.dataSize) ==
data);
}
REQUIRE(messageCount == 1);

reader.close();
}
}
#endif

TEST_CASE("Read Order", "[reader][writer]") {
SECTION("Roundtrip two topics") {
Buffer buffer;

mcap::McapWriter writer;
mcap::McapWriterOptions opts("test");
opts.compression = mcap::Compression::Lz4;
opts.compression = mcap::Compression::None;
opts.forceCompression = true;
writer.open(buffer, opts);
mcap::Schema schema1("schema1", "schemaEncoding", "ab");
Expand Down Expand Up @@ -677,15 +726,12 @@ TEST_CASE("LZ4 compression", "[reader][writer]") {

reader.close();
}
}

TEST_CASE("Read Order", "[reader][writer]") {
SECTION("Roundtrip unordered") {
Buffer buffer;

mcap::McapWriter writer;
mcap::McapWriterOptions opts("test");
opts.compression = mcap::Compression::Lz4;
opts.compression = mcap::Compression::None;
opts.forceCompression = true;
writer.open(buffer, opts);
mcap::Schema schema("schema", "schemaEncoding", "ab");
Expand Down Expand Up @@ -782,7 +828,6 @@ TEST_CASE("Read Order", "[reader][writer]") {
REQUIRE(count == reverse_order_expected.size());
}
}
#endif

TEST_CASE("ReadJobQueue order", "[reader]") {
SECTION("successive chunks with out-of-order timestamps") {
Expand Down

0 comments on commit 04d9ca4

Please sign in to comment.