tests/comms: Add read/write tests for ZM::Pipe
This commit is contained in:
parent
a06d374292
commit
5aa508bc74
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue