tests/comms: Add some basic tests for ZM::Pipe

This commit is contained in:
Peter Keresztes Schmidt 2021-04-06 23:41:56 +02:00
parent d7224261f7
commit a06d374292
2 changed files with 64 additions and 0 deletions

View File

@ -12,6 +12,7 @@
include(Catch)
set(TEST_SOURCES
zm_comms.cpp
zm_crypt.cpp
zm_utils.cpp)

63
tests/zm_comms.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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);
}
}