aboutsummaryrefslogtreecommitdiff
path: root/test/platform
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-05-24 23:14:45 +0800
committercrupest <crupest@outlook.com>2022-05-24 23:14:45 +0800
commitad4f06c133dc0475ef6a98cac0fa97f6e0527bf1 (patch)
tree63b07dc8674afd7ec99380e121eca0f1762ae11e /test/platform
parentae0694c91602fa1cd278394132bc1320c00deba8 (diff)
downloadcru-ad4f06c133dc0475ef6a98cac0fa97f6e0527bf1.tar.gz
cru-ad4f06c133dc0475ef6a98cac0fa97f6e0527bf1.tar.bz2
cru-ad4f06c133dc0475ef6a98cac0fa97f6e0527bf1.zip
...
Diffstat (limited to 'test/platform')
-rw-r--r--test/platform/CMakeLists.txt4
-rw-r--r--test/platform/graphics/cairo/BaseTest.cpp40
-rw-r--r--test/platform/graphics/cairo/CMakeLists.txt6
3 files changed, 50 insertions, 0 deletions
diff --git a/test/platform/CMakeLists.txt b/test/platform/CMakeLists.txt
index 5116d54d..01f6966b 100644
--- a/test/platform/CMakeLists.txt
+++ b/test/platform/CMakeLists.txt
@@ -8,4 +8,8 @@ if (WIN32)
add_subdirectory(graphics/direct2d)
endif()
+if (UNIX)
+ add_subdirectory(graphics/cairo)
+endif()
+
catch_discover_tests(CruPlatformBaseTest)
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)