diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 426f03766..ea5c24aa5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,6 +12,7 @@ include(Catch) set(TEST_SOURCES + zm_box.cpp zm_comms.cpp zm_crypt.cpp zm_font.cpp diff --git a/tests/zm_box.cpp b/tests/zm_box.cpp new file mode 100644 index 000000000..bd47c0bfb --- /dev/null +++ b/tests/zm_box.cpp @@ -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 . + */ + +#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); + } +} diff --git a/tests/zm_catch2.h b/tests/zm_catch2.h new file mode 100644 index 000000000..5f92277ea --- /dev/null +++ b/tests/zm_catch2.h @@ -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 . + */ + +#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_ diff --git a/tests/zm_comms.cpp b/tests/zm_comms.cpp index dfe98e1bf..1146e69a5 100644 --- a/tests/zm_comms.cpp +++ b/tests/zm_comms.cpp @@ -15,7 +15,7 @@ * with this program. If not, see . */ -#include "catch2/catch.hpp" +#include "zm_catch2.h" #include "zm_comms.h" #include diff --git a/tests/zm_crypt.cpp b/tests/zm_crypt.cpp index d3a315ef4..0d68c1e3c 100644 --- a/tests/zm_crypt.cpp +++ b/tests/zm_crypt.cpp @@ -15,7 +15,7 @@ * with this program. If not, see . */ -#include "catch2/catch.hpp" +#include "zm_catch2.h" #include "zm_crypt.h" diff --git a/tests/zm_font.cpp b/tests/zm_font.cpp index d862c3291..9ddb79a0e 100644 --- a/tests/zm_font.cpp +++ b/tests/zm_font.cpp @@ -15,7 +15,7 @@ * with this program. If not, see . */ -#include "catch2/catch.hpp" +#include "zm_catch2.h" #include "zm_font.h" diff --git a/tests/zm_utils.cpp b/tests/zm_utils.cpp index 408b9f43e..4745ad60b 100644 --- a/tests/zm_utils.cpp +++ b/tests/zm_utils.cpp @@ -15,7 +15,7 @@ * with this program. If not, see . */ -#include "catch2/catch.hpp" +#include "zm_catch2.h" #include "zm_utils.h" #include diff --git a/tests/zm_vector2.cpp b/tests/zm_vector2.cpp index 75b25350d..23930f41a 100644 --- a/tests/zm_vector2.cpp +++ b/tests/zm_vector2.cpp @@ -15,15 +15,10 @@ * with this program. If not, see . */ -#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);