tests/Box: Add unit tests

This commit is contained in:
Peter Keresztes Schmidt 2021-05-02 23:04:26 +02:00
parent f85e3765db
commit c2a7f7b593
8 changed files with 91 additions and 10 deletions

View File

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

55
tests/zm_box.cpp Normal file
View File

@ -0,0 +1,55 @@
/*
* 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 "zm_catch2.h"
#include "zm_box.h"
TEST_CASE("Box: default constructor") {
Box b;
REQUIRE(b.Lo() == Vector2(0, 0));
REQUIRE(b.Hi() == Vector2(0, 0));
REQUIRE(b.Size() == Vector2(0, 0));
REQUIRE(b.Area() == 0);
}
TEST_CASE("Box: construct from lo and hi") {
Box b({1, 1}, {5, 5});
SECTION("basic properties") {
REQUIRE(b.Lo() == Vector2(1, 1));
REQUIRE(b.Hi() == Vector2(5, 5));
// Should be:
// REQUIRE(b.Size() == Vector2(4 ,4));
REQUIRE(b.Size() == Vector2(5, 5));
// Should be:
// REQUIRE(b.Area() == 16);
REQUIRE(b.Area() == 25);
// Should be:
// REQUIRE(b.Centre() == Vector2(3, 3));
REQUIRE(b.Centre() == Vector2(4, 4));
}
SECTION("contains") {
REQUIRE(b.Contains({0, 0}) == false);
REQUIRE(b.Contains({1, 1}) == true);
REQUIRE(b.Contains({3, 3}) == true);
REQUIRE(b.Contains({5, 5}) == true);
REQUIRE(b.Contains({6, 6}) == false);
}
}

30
tests/zm_catch2.h Normal file
View File

@ -0,0 +1,30 @@
/*
* 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/>.
*/
#ifndef ZONEMINDER_TESTS_ZM_CATCH2_H_
#define ZONEMINDER_TESTS_ZM_CATCH2_H_
#include "catch2/catch.hpp"
#include "zm_vector2.h"
inline std::ostream &operator<<(std::ostream &os, Vector2 const &value) {
os << "{ X: " << value.x_ << ", Y: " << value.y_ << " }";
return os;
}
#endif //ZONEMINDER_TESTS_ZM_CATCH2_H_

View File

@ -15,7 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catch2/catch.hpp"
#include "zm_catch2.h"
#include "zm_comms.h"
#include <array>

View File

@ -15,7 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catch2/catch.hpp"
#include "zm_catch2.h"
#include "zm_crypt.h"

View File

@ -15,7 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catch2/catch.hpp"
#include "zm_catch2.h"
#include "zm_font.h"

View File

@ -15,7 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catch2/catch.hpp"
#include "zm_catch2.h"
#include "zm_utils.h"
#include <sstream>

View File

@ -15,15 +15,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catch2/catch.hpp"
#include "zm_catch2.h"
#include "zm_vector2.h"
std::ostream &operator<<(std::ostream &os, Vector2 const &value) {
os << "{ X: " << value.x_ << ", Y: " << value.y_ << " }";
return os;
}
TEST_CASE("Vector2: default constructor") {
Vector2 c;
REQUIRE(c.x_ == 0);