ae4be5fbf90f88e824807a7bf1673eeead4d28fe
[platform/core/graphics/tizenvg.git] / test / testScene.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.h>
24 #include "catch.hpp"
25
26 using namespace tvg;
27
28 TEST_CASE("Scene Creation", "[tvgScene]")
29 {
30     auto scene = Scene::gen();
31     REQUIRE(scene);
32
33     REQUIRE(scene->identifier() == Scene::identifier());
34     REQUIRE(scene->identifier() != Shape::identifier());
35     REQUIRE(scene->identifier() != Picture::identifier());
36 }
37
38 TEST_CASE("Pushing Paints Into Scene", "[tvgScene]")
39 {
40     auto scene = Scene::gen();
41     REQUIRE(scene);
42
43     //Pushing Paints
44     REQUIRE(scene->push(move(Shape::gen())) == Result::Success);
45     REQUIRE(scene->push(move(Picture::gen())) == Result::Success);
46     REQUIRE(scene->push(move(Scene::gen())) == Result::Success);
47
48     //Pushing Null Pointer
49     REQUIRE(scene->push(nullptr) == Result::MemoryCorruption);
50
51     //Pushing Invalid Paint
52     std::unique_ptr<Shape> shape = nullptr;
53     REQUIRE(scene->push(move(shape)) == Result::MemoryCorruption);
54 }
55
56 TEST_CASE("Scene Memory Reservation", "[tvgScene]")
57 {
58     auto scene = Scene::gen();
59     REQUIRE(scene);
60
61     //Check Growth / Reduction
62     REQUIRE(scene->reserve(10) == Result::Success);
63     REQUIRE(scene->reserve(1000) == Result::Success);
64     REQUIRE(scene->reserve(100) == Result::Success);
65     REQUIRE(scene->reserve(0) == Result::Success);
66 }
67
68 TEST_CASE("Scene Clear", "[tvgScene]")
69 {
70     auto scene = Scene::gen();
71     REQUIRE(scene);
72
73     REQUIRE(scene->push(move(Shape::gen())) == Result::Success);
74     REQUIRE(scene->clear() == Result::Success);
75 }
76
77 TEST_CASE("Scene Clear And Reuse Shape", "[tvgScene]")
78 {
79     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
80
81     auto canvas = SwCanvas::gen();
82     REQUIRE(canvas);
83
84     auto scene = Scene::gen();
85     REQUIRE(scene);
86     Scene *pScene = scene.get();
87
88     auto shape = Shape::gen();
89     REQUIRE(shape);
90     Shape* pShape = shape.get();
91
92     REQUIRE(scene->push(move(shape)) == Result::Success);
93     REQUIRE(canvas->push(move(scene)) == Result::Success);
94     REQUIRE(canvas->update() == Result::Success);
95
96     //No deallocate shape.
97     REQUIRE(pScene->clear(false) == Result::Success);
98
99     //Reuse shape.
100     REQUIRE(pScene->push(std::unique_ptr<Shape>(pShape)) == Result::Success);
101
102     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
103 }