tests/Box: Add unit tests
This commit is contained in:
parent
f85e3765db
commit
c2a7f7b593
|
@ -12,6 +12,7 @@
|
|||
include(Catch)
|
||||
|
||||
set(TEST_SOURCES
|
||||
zm_box.cpp
|
||||
zm_comms.cpp
|
||||
zm_crypt.cpp
|
||||
zm_font.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 <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);
|
||||
}
|
||||
}
|
|
@ -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_
|
|
@ -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>
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue