2 * Copyright (c) 2021 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include <thorvg_capi.h>
24 #include "../catch.hpp"
27 TEST_CASE("Paint Transform", "[capiPaint]")
29 Tvg_Paint* paint = tvg_shape_new();
32 Tvg_Matrix matrix_set = {1, 0, 0, 0, 1, 0, 0, 0, 1}, matrix_get;
34 REQUIRE(tvg_paint_set_transform(paint, &matrix_set) == TVG_RESULT_SUCCESS);
35 REQUIRE(tvg_paint_get_transform(paint, &matrix_get) == TVG_RESULT_SUCCESS);
36 REQUIRE(matrix_get.e11 == Approx(matrix_set.e11).margin(0.000001));
37 REQUIRE(matrix_get.e12 == Approx(matrix_set.e12).margin(0.000001));
38 REQUIRE(matrix_get.e13 == Approx(matrix_set.e13).margin(0.000001));
39 REQUIRE(matrix_get.e21 == Approx(matrix_set.e21).margin(0.000001));
40 REQUIRE(matrix_get.e22 == Approx(matrix_set.e22).margin(0.000001));
41 REQUIRE(matrix_get.e23 == Approx(matrix_set.e23).margin(0.000001));
42 REQUIRE(matrix_get.e31 == Approx(matrix_set.e31).margin(0.000001));
43 REQUIRE(matrix_get.e32 == Approx(matrix_set.e32).margin(0.000001));
44 REQUIRE(matrix_get.e33 == Approx(matrix_set.e33).margin(0.000001));
46 REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS);
49 TEST_CASE("Paint Translate", "[capiPaint]")
51 Tvg_Paint* paint = tvg_shape_new();
56 REQUIRE(tvg_paint_translate(paint, 20, 30) == TVG_RESULT_SUCCESS);
57 REQUIRE(tvg_paint_get_transform(paint, &matrix) == TVG_RESULT_SUCCESS);
58 REQUIRE(matrix.e11 == Approx(1).margin(0.000001));
59 REQUIRE(matrix.e12 == Approx(0).margin(0.000001));
60 REQUIRE(matrix.e13 == Approx(20).margin(0.000001));
61 REQUIRE(matrix.e21 == Approx(0).margin(0.000001));
62 REQUIRE(matrix.e22 == Approx(1).margin(0.000001));
63 REQUIRE(matrix.e23 == Approx(30).margin(0.000001));
64 REQUIRE(matrix.e31 == Approx(0).margin(0.000001));
65 REQUIRE(matrix.e32 == Approx(0).margin(0.000001));
66 REQUIRE(matrix.e33 == Approx(1).margin(0.000001));
68 REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS);
71 TEST_CASE("Paint Scale", "[capiPaint]")
73 Tvg_Paint* paint = tvg_shape_new();
78 REQUIRE(tvg_paint_scale(paint, 2.5f) == TVG_RESULT_SUCCESS);
79 REQUIRE(tvg_paint_get_transform(paint, &matrix) == TVG_RESULT_SUCCESS);
80 REQUIRE(matrix.e11 == Approx(2.5).margin(0.000001));
81 REQUIRE(matrix.e12 == Approx(0).margin(0.000001));
82 REQUIRE(matrix.e13 == Approx(0).margin(0.000001));
83 REQUIRE(matrix.e21 == Approx(0).margin(0.000001));
84 REQUIRE(matrix.e22 == Approx(2.5).margin(0.000001));
85 REQUIRE(matrix.e23 == Approx(0).margin(0.000001));
86 REQUIRE(matrix.e31 == Approx(0).margin(0.000001));
87 REQUIRE(matrix.e32 == Approx(0).margin(0.000001));
88 REQUIRE(matrix.e33 == Approx(1).margin(0.000001));
90 REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS);
93 TEST_CASE("Paint Rotate", "[capiPaint]")
95 Tvg_Paint* paint = tvg_shape_new();
100 REQUIRE(tvg_paint_rotate(paint, 180.0f) == TVG_RESULT_SUCCESS);
101 REQUIRE(tvg_paint_get_transform(paint, &matrix) == TVG_RESULT_SUCCESS);
102 REQUIRE(matrix.e11 == Approx(-1).margin(0.000001));
103 REQUIRE(matrix.e12 == Approx(0).margin(0.000001));
104 REQUIRE(matrix.e13 == Approx(0).margin(0.000001));
105 REQUIRE(matrix.e21 == Approx(-0).margin(0.000001));
106 REQUIRE(matrix.e22 == Approx(-1).margin(0.000001));
107 REQUIRE(matrix.e23 == Approx(0).margin(0.000001));
108 REQUIRE(matrix.e31 == Approx(0).margin(0.000001));
109 REQUIRE(matrix.e32 == Approx(0).margin(0.000001));
110 REQUIRE(matrix.e33 == Approx(1).margin(0.000001));
112 REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS);
115 TEST_CASE("Paint Opacity", "[capiPaint]")
117 Tvg_Paint* paint = tvg_shape_new();
122 REQUIRE(tvg_paint_set_opacity(paint, 0) == TVG_RESULT_SUCCESS);
123 REQUIRE(tvg_paint_get_opacity(paint, &opacity) == TVG_RESULT_SUCCESS);
124 REQUIRE(0 == opacity);
126 REQUIRE(tvg_paint_set_opacity(paint, 128) == TVG_RESULT_SUCCESS);
127 REQUIRE(tvg_paint_get_opacity(paint, &opacity) == TVG_RESULT_SUCCESS);
128 REQUIRE(128 == opacity);
130 REQUIRE(tvg_paint_set_opacity(paint, 255) == TVG_RESULT_SUCCESS);
131 REQUIRE(tvg_paint_get_opacity(paint, &opacity) == TVG_RESULT_SUCCESS);
132 REQUIRE(255 == opacity);
134 REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS);
137 TEST_CASE("Paint Bounds", "[capiPaint]")
139 Tvg_Paint* paint = tvg_shape_new();
144 REQUIRE(tvg_shape_append_rect(paint, 0, 10, 20, 100, 0, 0) == TVG_RESULT_SUCCESS);
145 REQUIRE(tvg_paint_get_bounds(paint, &x, &y, &w, &h, true) == TVG_RESULT_SUCCESS);
152 REQUIRE(tvg_shape_reset(paint) == TVG_RESULT_SUCCESS);
154 REQUIRE(tvg_paint_translate(paint, 100, 100) == TVG_RESULT_SUCCESS);
155 REQUIRE(tvg_paint_scale(paint, 2) == TVG_RESULT_SUCCESS);
157 REQUIRE(tvg_shape_move_to(paint, 0, 10) == TVG_RESULT_SUCCESS);
158 REQUIRE(tvg_shape_line_to(paint, 20, 110) == TVG_RESULT_SUCCESS);
159 REQUIRE(tvg_paint_get_bounds(paint, &x, &y, &w, &h, false) == TVG_RESULT_SUCCESS);
166 REQUIRE(tvg_paint_get_bounds(paint, &x, &y, &w, &h, true) == TVG_RESULT_SUCCESS);
168 REQUIRE(x == Approx(100.0f).margin(0.000001));
169 REQUIRE(y == Approx(120.0f).margin(0.000001));
170 REQUIRE(w == Approx(40.0f).margin(0.000001));
171 REQUIRE(h == Approx(200.0f).margin(0.000001));
173 REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS);
176 TEST_CASE("Paint Dupliction", "[capiPaint]")
178 Tvg_Paint* paint = tvg_shape_new();
181 REQUIRE(tvg_paint_set_opacity(paint, 0) == TVG_RESULT_SUCCESS);
183 REQUIRE(tvg_paint_translate(paint, 200, 100) == TVG_RESULT_SUCCESS);
184 REQUIRE(tvg_paint_scale(paint, 2.2f) == TVG_RESULT_SUCCESS);
185 REQUIRE(tvg_paint_rotate(paint, 90.0f) == TVG_RESULT_SUCCESS);
187 Tvg_Paint* paint_copy = tvg_paint_duplicate(paint);
191 REQUIRE(tvg_paint_get_opacity(paint_copy, &opacity) == TVG_RESULT_SUCCESS);
192 REQUIRE(0 == opacity);
195 REQUIRE(tvg_paint_get_transform(paint, &matrix) == TVG_RESULT_SUCCESS);
196 REQUIRE(matrix.e11 == Approx(0.0f).margin(0.000001));
197 REQUIRE(matrix.e12 == Approx(-2.2f).margin(0.000001));
198 REQUIRE(matrix.e13 == Approx(200.0f).margin(0.000001));
199 REQUIRE(matrix.e21 == Approx(2.2f).margin(0.000001));
200 REQUIRE(matrix.e22 == Approx(0.0f).margin(0.000001));
201 REQUIRE(matrix.e23 == Approx(100.0f).margin(0.000001));
202 REQUIRE(matrix.e31 == Approx(0.0f).margin(0.000001));
203 REQUIRE(matrix.e32 == Approx(0.0f).margin(0.000001));
204 REQUIRE(matrix.e33 == Approx(1.0f).margin(0.000001));
206 REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS);
207 REQUIRE(tvg_paint_del(paint_copy) == TVG_RESULT_SUCCESS);
210 TEST_CASE("Paint Clip Path Composite Method", "[capiPaint]")
212 Tvg_Paint* paint = tvg_shape_new();
215 Tvg_Paint* target = tvg_shape_new();
218 REQUIRE(tvg_paint_set_composite_method(paint, NULL, TVG_COMPOSITE_METHOD_NONE) == TVG_RESULT_SUCCESS);
219 REQUIRE(tvg_paint_set_composite_method(paint, target, TVG_COMPOSITE_METHOD_NONE) == TVG_RESULT_INVALID_ARGUMENT);
220 REQUIRE(tvg_paint_set_composite_method(paint, NULL, TVG_COMPOSITE_METHOD_CLIP_PATH) == TVG_RESULT_INVALID_ARGUMENT);
222 Tvg_Paint* target2 = tvg_shape_new();
224 REQUIRE(tvg_paint_set_composite_method(paint, target2, TVG_COMPOSITE_METHOD_CLIP_PATH) == TVG_RESULT_SUCCESS);
226 const Tvg_Paint* target3 = nullptr;
227 Tvg_Composite_Method method = TVG_COMPOSITE_METHOD_NONE;
228 REQUIRE(tvg_paint_get_composite_method(paint, NULL, &method) == TVG_RESULT_INVALID_ARGUMENT);
229 REQUIRE(tvg_paint_get_composite_method(paint, &target3, NULL) == TVG_RESULT_INVALID_ARGUMENT);
230 REQUIRE(tvg_paint_get_composite_method(paint, &target3, &method) == TVG_RESULT_SUCCESS);
231 REQUIRE(method == TVG_COMPOSITE_METHOD_CLIP_PATH);
232 REQUIRE(target2 == target3);
234 REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS);