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"
26 TEST_CASE("Create a Scene", "[capiScene]")
28 Tvg_Paint* scene = tvg_scene_new();
31 REQUIRE(tvg_paint_del(scene) == TVG_RESULT_SUCCESS);
34 TEST_CASE("Paints Into a Scene", "[capiScene]")
36 Tvg_Paint* scene = tvg_scene_new();
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);
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);
48 REQUIRE(tvg_paint_del(scene) == TVG_RESULT_SUCCESS);
51 TEST_CASE("Scene Reservation", "[capiScene]")
53 Tvg_Paint* scene = tvg_scene_new();
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);
63 REQUIRE(tvg_scene_reserve(NULL, 1) == TVG_RESULT_INVALID_ARGUMENT);
65 REQUIRE(tvg_paint_del(scene) == TVG_RESULT_SUCCESS);
68 TEST_CASE("Clear the Scene", "[capiScene]")
70 Tvg_Paint* scene = tvg_scene_new();
73 REQUIRE(tvg_scene_push(scene, tvg_shape_new()) == TVG_RESULT_SUCCESS);
74 REQUIRE(tvg_scene_clear(scene, true) == TVG_RESULT_SUCCESS);
77 REQUIRE(tvg_scene_clear(NULL, false) == TVG_RESULT_INVALID_ARGUMENT);
79 REQUIRE(tvg_paint_del(scene) == TVG_RESULT_SUCCESS);
82 TEST_CASE("Scene reusing paints", "[capiScene]")
84 REQUIRE(tvg_engine_init(TVG_ENGINE_SW, 0) == TVG_RESULT_SUCCESS);
86 Tvg_Canvas* canvas = tvg_swcanvas_create();
89 uint32_t* buffer = (uint32_t*) malloc(sizeof(uint32_t) * 200 * 200);
92 REQUIRE(tvg_swcanvas_set_target(canvas, buffer, 200, 200, 200, TVG_COLORSPACE_ARGB8888) == TVG_RESULT_SUCCESS);
94 Tvg_Paint* scene = tvg_scene_new();
97 Tvg_Paint* shape = tvg_shape_new();
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);
104 //No deallocate shape.
105 REQUIRE(tvg_scene_clear(scene, false) == TVG_RESULT_SUCCESS);
108 REQUIRE(tvg_scene_push(scene, shape) == TVG_RESULT_SUCCESS);
110 REQUIRE(tvg_canvas_destroy(canvas) == TVG_RESULT_SUCCESS);
112 REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS);