From 5aa508bc742f1d9bc276220a6ec80d2869c10a03 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Fri, 9 Apr 2021 09:44:55 +0200 Subject: [PATCH] tests/comms: Add read/write tests for ZM::Pipe --- tests/zm_comms.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/zm_comms.cpp b/tests/zm_comms.cpp index ccb2a6c88..bb05e7097 100644 --- a/tests/zm_comms.cpp +++ b/tests/zm_comms.cpp @@ -18,6 +18,7 @@ #include "catch2/catch.hpp" #include "zm_comms.h" +#include 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 msg = {'a', 'b', 'c'}; + std::array 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); + } +}