prepare tvg v0.8 release
[platform/core/graphics/tizenvg.git] / test / testSavers.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("Saver Creation", "[tvgSavers]")
29 {
30     auto saver = Saver::gen();
31     REQUIRE(saver);
32 }
33
34 TEST_CASE("Save empty shape", "[tvgSavers]")
35 {
36     auto shape = Shape::gen();
37     REQUIRE(shape);
38
39     auto saver = Saver::gen();
40     REQUIRE(saver);
41
42     REQUIRE(saver->save(move(shape), TEST_DIR"/test.tvg") == Result::Unknown);
43 }
44
45 TEST_CASE("Save svg into tvg", "[tvgSavers]")
46 {
47     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
48
49     auto picture = Picture::gen();
50     REQUIRE(picture);
51     REQUIRE(picture->load(TEST_DIR"/tag.svg") == Result::Success);
52
53     auto saver = Saver::gen();
54     REQUIRE(saver);
55
56     REQUIRE(saver->save(move(picture), TEST_DIR"/tag.tvg") == Result::Success);
57     REQUIRE(saver->sync() == Result::Success);
58
59     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
60 }
61
62 TEST_CASE("Save scene into tvg", "[tvgSavers]")
63 {
64     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
65
66     auto picture = tvg::Picture::gen();
67     REQUIRE(picture);
68     REQUIRE(picture->load(TEST_DIR"/test.png") == Result::Success);
69     REQUIRE(picture->translate(50, 0) == Result::Success);
70     REQUIRE(picture->scale(2) == Result::Success);
71
72     auto mask = tvg::Shape::gen();
73     REQUIRE(mask);
74     REQUIRE(mask->appendCircle(400, 400, 15, 15) == Result::Success);
75     REQUIRE(mask->fill(0, 0, 0, 255) == Result::Success);
76     REQUIRE(picture->composite(move(mask), tvg::CompositeMethod::InvAlphaMask) == Result::Success);
77
78     auto saver = Saver::gen();
79     REQUIRE(saver);
80     REQUIRE(saver->save(move(picture), TEST_DIR"/test.tvg") == Result::Success);
81     REQUIRE(saver->sync() == Result::Success);
82
83     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
84 }