38235d4d686280e26ebd2e462ca10e3398898f6f
[platform/core/graphics/tizenvg.git] / test / capi / capiScene.cpp
1 /*
2  * Copyright (c) 2021 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
3
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:
10
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13
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
20  * SOFTWARE.
21  */
22
23 #include <thorvg_capi.h>
24 #include "../catch.hpp"
25
26 TEST_CASE("Create a Scene", "[capiScene]")
27 {
28     Tvg_Paint* scene = tvg_scene_new();
29     REQUIRE(scene);
30
31     REQUIRE(tvg_paint_del(scene) == TVG_RESULT_SUCCESS);
32 }
33
34 TEST_CASE("Paints Into a Scene", "[capiScene]")
35 {
36     Tvg_Paint* scene = tvg_scene_new();
37     REQUIRE(scene);
38
39     //Pushing Paints
40     REQUIRE(tvg_scene_push(scene, tvg_shape_new()) == TVG_RESULT_SUCCESS);
41     REQUIRE(tvg_scene_push(scene, tvg_picture_new()) == TVG_RESULT_SUCCESS);
42     REQUIRE(tvg_scene_push(scene, tvg_scene_new()) == TVG_RESULT_SUCCESS);
43
44     //Pushing Null Pointer
45     REQUIRE(tvg_scene_push(scene, NULL) == TVG_RESULT_INVALID_ARGUMENT);
46     REQUIRE(tvg_scene_push(NULL, NULL) == TVG_RESULT_INVALID_ARGUMENT);
47
48     REQUIRE(tvg_paint_del(scene) == TVG_RESULT_SUCCESS);
49 }
50
51 TEST_CASE("Scene Reservation", "[capiScene]")
52 {
53     Tvg_Paint* scene = tvg_scene_new();
54     REQUIRE(scene);
55
56     //Check Growth / Reduction
57     REQUIRE(tvg_scene_reserve(scene, 100) == TVG_RESULT_SUCCESS);
58     REQUIRE(tvg_scene_reserve(scene, 1000) == TVG_RESULT_SUCCESS);
59     REQUIRE(tvg_scene_reserve(scene, 100) == TVG_RESULT_SUCCESS);
60     REQUIRE(tvg_scene_reserve(scene, 0) == TVG_RESULT_SUCCESS);
61
62     //Invalid scene
63     REQUIRE(tvg_scene_reserve(NULL, 1) == TVG_RESULT_INVALID_ARGUMENT);
64
65     REQUIRE(tvg_paint_del(scene) == TVG_RESULT_SUCCESS);
66 }
67
68 TEST_CASE("Clear the Scene", "[capiScene]")
69 {
70     Tvg_Paint* scene = tvg_scene_new();
71     REQUIRE(scene);
72
73     REQUIRE(tvg_scene_push(scene, tvg_shape_new()) == TVG_RESULT_SUCCESS);
74     REQUIRE(tvg_scene_clear(scene, true) == TVG_RESULT_SUCCESS);
75
76     //Invalid scene
77     REQUIRE(tvg_scene_clear(NULL, false) == TVG_RESULT_INVALID_ARGUMENT);
78
79     REQUIRE(tvg_paint_del(scene) == TVG_RESULT_SUCCESS);
80 }
81
82 TEST_CASE("Scene reusing paints", "[capiScene]")
83 {
84     REQUIRE(tvg_engine_init(TVG_ENGINE_SW, 0) == TVG_RESULT_SUCCESS);
85
86     Tvg_Canvas* canvas = tvg_swcanvas_create();
87     REQUIRE(canvas);
88
89     uint32_t* buffer = (uint32_t*) malloc(sizeof(uint32_t) * 200 * 200);
90     REQUIRE(buffer);
91
92     REQUIRE(tvg_swcanvas_set_target(canvas, buffer, 200, 200, 200, TVG_COLORSPACE_ARGB8888) == TVG_RESULT_SUCCESS);
93
94     Tvg_Paint* scene = tvg_scene_new();
95     REQUIRE(scene);
96
97     Tvg_Paint* shape = tvg_shape_new();
98     REQUIRE(shape);
99
100     REQUIRE(tvg_scene_push(scene, shape) == TVG_RESULT_SUCCESS);
101     REQUIRE(tvg_canvas_push(canvas, scene) == TVG_RESULT_SUCCESS);
102     REQUIRE(tvg_canvas_update(canvas) == TVG_RESULT_SUCCESS);
103
104     //No deallocate shape.
105     REQUIRE(tvg_scene_clear(scene, false) == TVG_RESULT_SUCCESS);
106
107     //Reuse shape.
108     REQUIRE(tvg_scene_push(scene, shape) == TVG_RESULT_SUCCESS);
109
110     REQUIRE(tvg_canvas_destroy(canvas) == TVG_RESULT_SUCCESS);
111
112     REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS);
113
114     free(buffer);
115 }