tests/comms: Add read/write tests for ZM::Pipe

This commit is contained in:
Peter Keresztes Schmidt 2021-04-09 09:44:55 +02:00
parent a06d374292
commit 5aa508bc74
1 changed files with 30 additions and 0 deletions

View File

@ -18,6 +18,7 @@
#include "catch2/catch.hpp"
#include "zm_comms.h"
#include <array>
TEST_CASE("ZM::Pipe basics") {
ZM::Pipe pipe;
@ -61,3 +62,32 @@ TEST_CASE("ZM::Pipe basics") {
REQUIRE(pipe.setBlocking(false) == true);
}
}
TEST_CASE("ZM::Pipe read/write") {
ZM::Pipe pipe;
std::array<char, 3> msg = {'a', 'b', 'c'};
std::array<char, msg.size()> rcv{};
SECTION("read/write on non-opened pipe") {
REQUIRE(pipe.write(msg.data(), msg.size()) == -1);
REQUIRE(pipe.read(rcv.data(), rcv.size()) == -1);
}
SECTION("read/write on opened pipe") {
REQUIRE(pipe.open() == true);
REQUIRE(pipe.write(msg.data(), msg.size()) == msg.size());
REQUIRE(pipe.read(rcv.data(), rcv.size()) == msg.size());
REQUIRE(rcv == msg);
}
SECTION("read/write on closed pipe") {
REQUIRE(pipe.open() == true);
REQUIRE(pipe.close() == true);
REQUIRE(pipe.write(msg.data(), msg.size()) == -1);
REQUIRE(pipe.read(rcv.data(), rcv.size()) == -1);
}
}