From a06d3742924856ec077f8eace3b993c3d75ad0a1 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Tue, 6 Apr 2021 23:41:56 +0200 Subject: [PATCH] tests/comms: Add some basic tests for ZM::Pipe --- tests/CMakeLists.txt | 1 + tests/zm_comms.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/zm_comms.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d40af81ab..c863c7cbb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,6 +12,7 @@ include(Catch) set(TEST_SOURCES + zm_comms.cpp zm_crypt.cpp zm_utils.cpp) diff --git a/tests/zm_comms.cpp b/tests/zm_comms.cpp new file mode 100644 index 000000000..ccb2a6c88 --- /dev/null +++ b/tests/zm_comms.cpp @@ -0,0 +1,63 @@ +/* + * This file is part of the ZoneMinder Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "catch2/catch.hpp" + +#include "zm_comms.h" + +TEST_CASE("ZM::Pipe basics") { + ZM::Pipe pipe; + + SECTION("setBlocking on non-opened") { + REQUIRE(pipe.setBlocking(true) == false); + REQUIRE(pipe.setBlocking(false) == false); + } + + REQUIRE(pipe.open() == true); + + REQUIRE(pipe.isOpen() == true); + REQUIRE(pipe.isClosed() == false); + REQUIRE(pipe.getReadDesc() != -1); + REQUIRE(pipe.getWriteDesc() != -1); + + SECTION("double open") { + REQUIRE(pipe.open() == true); // is this expected? + } + + SECTION("close") { + REQUIRE(pipe.close() == true); + + REQUIRE(pipe.isOpen() == false); + REQUIRE(pipe.isClosed() == true); + REQUIRE(pipe.getReadDesc() == -1); + REQUIRE(pipe.getWriteDesc() == -1); + + SECTION("double close") { + REQUIRE(pipe.close() == true); + } + + SECTION("setBlocking on closed") { + REQUIRE(pipe.setBlocking(true) == false); + REQUIRE(pipe.setBlocking(false) == false); + } + } + + SECTION("setBlocking") { + REQUIRE(pipe.setBlocking(true) == true); + REQUIRE(pipe.setBlocking(false) == true); + } +}