diff options
author | crupest <crupest@outlook.com> | 2022-05-24 23:14:45 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-05-24 23:14:45 +0800 |
commit | ad4f06c133dc0475ef6a98cac0fa97f6e0527bf1 (patch) | |
tree | 63b07dc8674afd7ec99380e121eca0f1762ae11e /test/platform/graphics/cairo | |
parent | ae0694c91602fa1cd278394132bc1320c00deba8 (diff) | |
download | cru-ad4f06c133dc0475ef6a98cac0fa97f6e0527bf1.tar.gz cru-ad4f06c133dc0475ef6a98cac0fa97f6e0527bf1.tar.bz2 cru-ad4f06c133dc0475ef6a98cac0fa97f6e0527bf1.zip |
...
Diffstat (limited to 'test/platform/graphics/cairo')
-rw-r--r-- | test/platform/graphics/cairo/BaseTest.cpp | 40 | ||||
-rw-r--r-- | test/platform/graphics/cairo/CMakeLists.txt | 6 |
2 files changed, 46 insertions, 0 deletions
diff --git a/test/platform/graphics/cairo/BaseTest.cpp b/test/platform/graphics/cairo/BaseTest.cpp new file mode 100644 index 00000000..29e53ff0 --- /dev/null +++ b/test/platform/graphics/cairo/BaseTest.cpp @@ -0,0 +1,40 @@ +#include "cru/platform/graphics/cairo/Base.h" + +#include <cairo/cairo.h> +#include <catch2/catch_test_macros.hpp> +#include "catch2/catch_approx.hpp" + +using Catch::Approx; + +TEST_CASE("Cairo Matrix Convert", "[matrix]") { + using namespace cru::platform; + using namespace cru::platform::graphics; + using namespace cru::platform::graphics::cairo; + + SECTION("Cairo to cru should work") { + cairo_matrix_t cairo_matrix; + cairo_matrix_init_identity(&cairo_matrix); + cairo_matrix_scale(&cairo_matrix, 2, 2); + cairo_matrix_rotate(&cairo_matrix, 1); + cairo_matrix_translate(&cairo_matrix, 10, 10); + auto cru_matrix = Convert(cairo_matrix); + Point original_point(3, 5); + double cairo_point_x = original_point.x, cairo_point_y = original_point.y; + cairo_matrix_transform_point(&cairo_matrix, &cairo_point_x, &cairo_point_y); + Point cru_point = cru_matrix.TransformPoint(original_point); + REQUIRE(Approx(cru_point.x) == cairo_point_x); + REQUIRE(Approx(cru_point.y) == cairo_point_y); + } + + SECTION("Cru to cairo should work") { + auto cru_matrix = Matrix::Identity() * Matrix::Scale(2, 2) * + Matrix::Rotation(60) * Matrix::Translation(10, 10); + cairo_matrix_t cairo_matrix = Convert(cru_matrix); + Point original_point(3, 5); + double cairo_point_x = original_point.x, cairo_point_y = original_point.y; + cairo_matrix_transform_point(&cairo_matrix, &cairo_point_x, &cairo_point_y); + Point cru_point = cru_matrix.TransformPoint(original_point); + REQUIRE(Approx(cru_point.x) == cairo_point_x); + REQUIRE(Approx(cru_point.y) == cairo_point_y); + } +} diff --git a/test/platform/graphics/cairo/CMakeLists.txt b/test/platform/graphics/cairo/CMakeLists.txt new file mode 100644 index 00000000..5d055aa2 --- /dev/null +++ b/test/platform/graphics/cairo/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(CruPlatformGraphicsCairoTest + BaseTest.cpp +) +target_link_libraries(CruPlatformGraphicsCairoTest PRIVATE CruPlatformGraphicsCairo CruTestBase) + +catch_discover_tests(CruPlatformGraphicsCairoTest) |