diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 9 | ||||
-rw-r--r-- | test/common/HandlerRegistryTest.cpp | 36 | ||||
-rw-r--r-- | test/platform/CMakeLists.txt | 6 | ||||
-rw-r--r-- | test/platform/MatrixTest.cpp | 37 | ||||
-rw-r--r-- | test/win/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/win/graphics/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/win/graphics/direct/CMakeLists.txt | 6 | ||||
-rw-r--r-- | test/win/graphics/direct/ConvertTest.cpp | 29 |
8 files changed, 123 insertions, 2 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c534b909..3b9567cd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,7 +2,12 @@ find_package(GTest CONFIG REQUIRED) include(GoogleTest) -add_subdirectory(common) - add_library(cru_test_base INTERFACE) target_link_libraries(cru_test_base INTERFACE GTest::gtest GTest::gtest_main) + +add_subdirectory(common) +add_subdirectory(platform) + +if(WIN32) + add_subdirectory(win) +endif() diff --git a/test/common/HandlerRegistryTest.cpp b/test/common/HandlerRegistryTest.cpp new file mode 100644 index 00000000..d1792c7c --- /dev/null +++ b/test/common/HandlerRegistryTest.cpp @@ -0,0 +1,36 @@ +#include "cru/common/HandlerRegistry.hpp" + +#include <gtest/gtest.h> +#include <algorithm> + +TEST(HandlerRegistry, Work) { + using namespace cru; + HandlerRegistry<void()> registry; + + int counter = 1; + + auto tag1 = registry.AddHandler([&counter] { counter++; }); + auto tag2 = registry.AddHandler([&counter] { counter++; }); + + for (const auto& handler : registry) { + handler(); + } + + ASSERT_EQ(counter, 3); + + registry.RemoveHandler(tag1); + + for (const auto& handler : registry) { + handler(); + } + + ASSERT_EQ(counter, 4); + + registry.RemoveHandler(tag2); + + for (const auto& handler : registry) { + handler(); + } + + ASSERT_EQ(counter, 4); +} diff --git a/test/platform/CMakeLists.txt b/test/platform/CMakeLists.txt new file mode 100644 index 00000000..9ad8fb51 --- /dev/null +++ b/test/platform/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(cru_platform_base_test + MatrixTest.cpp +) +target_link_libraries(cru_platform_base_test PRIVATE cru_platform_base cru_test_base) + +gtest_discover_tests(cru_platform_base_test) diff --git a/test/platform/MatrixTest.cpp b/test/platform/MatrixTest.cpp new file mode 100644 index 00000000..3b8aab27 --- /dev/null +++ b/test/platform/MatrixTest.cpp @@ -0,0 +1,37 @@ +#include "cru/platform/GraphBase.hpp" +#include "cru/platform/Matrix.hpp" + +#include <gtest/gtest.h> + +using cru::platform::Matrix; +using cru::platform::Point; + +TEST(Matrix, Rotation) { + Point p(1, 1); + + Point p90 = Matrix::Rotation(90).TransformPoint(p); + ASSERT_FLOAT_EQ(p90.x, -1); + ASSERT_FLOAT_EQ(p90.y, 1); + + Point p180 = Matrix::Rotation(180).TransformPoint(p); + ASSERT_FLOAT_EQ(p180.x, -1); + ASSERT_FLOAT_EQ(p180.y, -1); + + Point p270 = Matrix::Rotation(270).TransformPoint(p); + ASSERT_FLOAT_EQ(p270.x, 1); + ASSERT_FLOAT_EQ(p270.y, -1); +} + +TEST(Matrix, TranslationAndRotation) { + Point p = + (Matrix::Translation(1, 1) * Matrix::Rotation(90)).TransformPoint({1, 1}); + ASSERT_FLOAT_EQ(p.x, -2); + ASSERT_FLOAT_EQ(p.y, 2); +} + +TEST(Matrix, RotationAndTranslation) { + Point p = + (Matrix::Rotation(90) * Matrix::Translation(1, 1)).TransformPoint({1, 1}); + ASSERT_FLOAT_EQ(p.x, 0); + ASSERT_FLOAT_EQ(p.y, 2); +} diff --git a/test/win/CMakeLists.txt b/test/win/CMakeLists.txt new file mode 100644 index 00000000..0ebdd7fe --- /dev/null +++ b/test/win/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(graphics) diff --git a/test/win/graphics/CMakeLists.txt b/test/win/graphics/CMakeLists.txt new file mode 100644 index 00000000..c90537ac --- /dev/null +++ b/test/win/graphics/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(direct) diff --git a/test/win/graphics/direct/CMakeLists.txt b/test/win/graphics/direct/CMakeLists.txt new file mode 100644 index 00000000..69e22ef7 --- /dev/null +++ b/test/win/graphics/direct/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(cru_win_graphics_direct_test + ConvertTest.cpp +) +target_link_libraries(cru_win_graphics_direct_test PRIVATE cru_win_graphics_direct cru_test_base) + +gtest_discover_tests(cru_win_graphics_direct_test) diff --git a/test/win/graphics/direct/ConvertTest.cpp b/test/win/graphics/direct/ConvertTest.cpp new file mode 100644 index 00000000..f8f95dac --- /dev/null +++ b/test/win/graphics/direct/ConvertTest.cpp @@ -0,0 +1,29 @@ +#include "cru/platform/Matrix.hpp" +#include "cru/win/graphics/direct/ConvertUtil.hpp" + +#include <gtest/gtest.h> + +using cru::platform::Matrix; +using cru::platform::graphics::win::direct::Convert; + +TEST(MatrixConvert, Rotation) { + auto matrix = Convert(Matrix::Rotation(90)); + + auto m = *D2D1::Matrix3x2F::ReinterpretBaseType(&matrix); + + auto p = m.TransformPoint({1, 1}); + + ASSERT_FLOAT_EQ(p.x, -1); + ASSERT_FLOAT_EQ(p.y, 1); +} + +TEST(MatrixConvert, RotationAndTranslation) { + auto matrix = Convert(Matrix::Rotation(90) * Matrix::Translation(1, 1)); + + auto m = *D2D1::Matrix3x2F::ReinterpretBaseType(&matrix); + + auto p = m.TransformPoint({1, 1}); + + ASSERT_FLOAT_EQ(p.x, 0); + ASSERT_FLOAT_EQ(p.y, 2); +} |