From e759101a47365319886986ff97f6cb5cd17fda2d Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Thu, 23 May 2019 23:38:35 +0100 Subject: [PATCH] Provide tests for ViewCamera --- tests/CMakeLists.txt | 1 + tests/main.cpp | 2 +- tests/test_Globals.hpp | 6 ++++++ tests/test_ViewCamera.cpp | 26 ++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/test_ViewCamera.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 23438431..b2aae0a1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,6 +34,7 @@ set(TESTS Text TrafficDirector Vehicle + ViewCamera VisualFX Weapon World diff --git a/tests/main.cpp b/tests/main.cpp index 07607815..a11ed160 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -3,6 +3,6 @@ #include "test_Globals.hpp" std::ostream& operator<<(std::ostream& stream, const glm::vec3& v) { - stream << v.x << " " << v.y << " " << v.z; + stream << glm::to_string(v); return stream; } diff --git a/tests/test_Globals.hpp b/tests/test_Globals.hpp index 760e0680..bba2f939 100644 --- a/tests/test_Globals.hpp +++ b/tests/test_Globals.hpp @@ -45,6 +45,12 @@ struct print_log_value { s << glm::to_string(v); } }; +template <> +struct print_log_value { + void operator()(std::ostream& s, glm::vec4 const& v) { + s << glm::to_string(v); + } +}; BOOST_NS_MAGIC_CLOSING } } diff --git a/tests/test_ViewCamera.cpp b/tests/test_ViewCamera.cpp new file mode 100644 index 00000000..056f411b --- /dev/null +++ b/tests/test_ViewCamera.cpp @@ -0,0 +1,26 @@ +#include +#include "test_Globals.hpp" +#include + +namespace { + +struct CameraFixture { + ViewCamera camera_ { + {1.f, 2.f, 3.f} + }; +}; +} + +BOOST_AUTO_TEST_SUITE(ViewCameraTests) + +BOOST_FIXTURE_TEST_CASE(test_creation, CameraFixture) { + BOOST_CHECK_EQUAL(camera_.position, glm::vec3(1.f, 2.f, 3.f)); +} + +BOOST_FIXTURE_TEST_CASE(test_view_matrix, CameraFixture) { + const auto& view = camera_.getView(); + BOOST_CHECK_EQUAL(view[3], glm::vec4(2.f, -3.f, 1.f, 1.f)); +} + + +BOOST_AUTO_TEST_SUITE_END()