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
28 TEST_CASE("Shape Creation", "[tvgShape]")
30 auto shape = Shape::gen();
33 REQUIRE(shape->identifier() == Shape::identifier());
34 REQUIRE(shape->identifier() != Picture::identifier());
35 REQUIRE(shape->identifier() != Scene::identifier());
38 TEST_CASE("Appending Commands", "[tvgShape]")
40 auto shape = Shape::gen();
43 REQUIRE(shape->close() == Result::Success);
45 REQUIRE(shape->moveTo(100, 100) == Result::Success);
46 REQUIRE(shape->moveTo(99999999.0f, -99999999.0f) == Result::Success);
47 REQUIRE(shape->moveTo(0, 0) == Result::Success);
49 REQUIRE(shape->lineTo(120, 140) == Result::Success);
50 REQUIRE(shape->lineTo(99999999.0f, -99999999.0f) == Result::Success);
51 REQUIRE(shape->lineTo(0, 0) == Result::Success);
53 REQUIRE(shape->cubicTo(0, 0, 0, 0, 0, 0) == Result::Success);
54 REQUIRE(shape->cubicTo(0, 0, 99999999.0f, -99999999.0f, 0, 0) == Result::Success);
55 REQUIRE(shape->cubicTo(0, 0, 99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f) == Result::Success);
56 REQUIRE(shape->cubicTo(99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f) == Result::Success);
58 REQUIRE(shape->close() == Result::Success);
60 REQUIRE(shape->reset() == Result::Success);
61 REQUIRE(shape->reset() == Result::Success);
64 TEST_CASE("Appending Shapes", "[tvgShape]")
66 auto shape = Shape::gen();
69 REQUIRE(shape->moveTo(100, 100) == Result::Success);
70 REQUIRE(shape->lineTo(120, 140) == Result::Success);
72 REQUIRE(shape->appendRect(0, 0, 0, 0, 0, 0) == Result::Success);
73 REQUIRE(shape->appendRect(0, 0,99999999.0f, -99999999.0f, 0, 0) == Result::Success);
74 REQUIRE(shape->appendRect(0, 0, 0, 0, -99999999.0f, 99999999.0f) == Result::Success);
75 REQUIRE(shape->appendRect(99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f) == Result::Success);
77 REQUIRE(shape->appendCircle(0, 0, 0, 0) == Result::Success);
78 REQUIRE(shape->appendCircle(-99999999.0f, 99999999.0f, 0, 0) == Result::Success);
79 REQUIRE(shape->appendCircle(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f) == Result::Success);
81 REQUIRE(shape->appendArc(0, 0, 0, 0, 0, false) == Result::Success);
82 REQUIRE(shape->appendArc(0, 0, 0, 0, 0, true) == Result::Success);
83 REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, 0, 0, 0, false) == Result::Success);
84 REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, 0, 0, 0, true) == Result::Success);
85 REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, 0, false) == Result::Success);
86 REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, 0, true) == Result::Success);
87 REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, -400, false) == Result::Success);
88 REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, 400, true) == Result::Success);
91 TEST_CASE("Appending Pathes", "[tvgShape]")
93 auto shape = Shape::gen();
97 REQUIRE(shape->appendPath(nullptr, 0, nullptr, 0) == Result::InvalidArguments);
98 REQUIRE(shape->appendPath(nullptr, 100, nullptr, 0) == Result::InvalidArguments);
99 REQUIRE(shape->appendPath(nullptr, 0, nullptr, 100) == Result::InvalidArguments);
101 PathCommand cmds[5] = {
105 PathCommand::CubicTo,
117 REQUIRE(shape->appendPath(cmds, 0, pts, 5) == Result::InvalidArguments);
118 REQUIRE(shape->appendPath(cmds, 5, pts, 0) == Result::InvalidArguments);
119 REQUIRE(shape->appendPath(cmds, 5, pts, 5) == Result::Success);
121 const PathCommand* cmds2;
122 REQUIRE(shape->pathCommands(&cmds2) == 5);
125 REQUIRE(shape->pathCoords(&pts2) == 5);
127 for (int i = 0; i < 5; ++i) {
128 REQUIRE(cmds2[i] == cmds[i]);
129 REQUIRE(pts[i].x == pts2[i].x);
130 REQUIRE(pts[i].y == pts2[i].y);
134 REQUIRE(shape->pathCommands(nullptr) == 0);
135 REQUIRE(shape->pathCoords(nullptr) == 0);
138 TEST_CASE("Stroking", "[tvgShape]")
140 auto shape = Shape::gen();
144 REQUIRE(shape->stroke(0) == Result::Success);
145 REQUIRE(shape->strokeWidth() == 0);
146 REQUIRE(shape->stroke(300) == Result::Success);
147 REQUIRE(shape->strokeWidth() == 300);
151 REQUIRE(shape->stroke(0, 50, 100, 200) == Result::Success);
152 REQUIRE(shape->strokeColor(nullptr, nullptr, &b, nullptr) == Result::Success);
154 REQUIRE(shape->strokeColor(&r, &g, &b, &a) == Result::Success);
159 REQUIRE(shape->strokeColor(nullptr, nullptr, nullptr, nullptr) == Result::Success);
162 float dashPattern[3] = {0, 1.5f, 2.22f};
163 REQUIRE(shape->stroke(dashPattern, 3) == Result::InvalidArguments);
165 float dashPattern2[3] = {1.0f, 1.5f, 2.22f};
166 REQUIRE(shape->stroke(dashPattern2, 3) == Result::Success);
168 const float* dashPattern3;
169 REQUIRE(shape->strokeDash(nullptr) == 3);
170 REQUIRE(shape->strokeDash(&dashPattern3) == 3);
171 REQUIRE(dashPattern3[0] == 1.0f);
172 REQUIRE(dashPattern3[1] == 1.5f);
173 REQUIRE(dashPattern3[2] == 2.22f);
175 REQUIRE(shape->stroke(nullptr, 0) == Result::Success);
178 REQUIRE(shape->strokeCap() == StrokeCap::Square);
179 REQUIRE(shape->stroke(StrokeCap::Round) == Result::Success);
180 REQUIRE(shape->stroke(StrokeCap::Butt) == Result::Success);
181 REQUIRE(shape->strokeCap() == StrokeCap::Butt);
184 REQUIRE(shape->strokeJoin() == StrokeJoin::Bevel);
185 REQUIRE(shape->stroke(StrokeJoin::Miter) == Result::Success);
186 REQUIRE(shape->stroke(StrokeJoin::Round) == Result::Success);
187 REQUIRE(shape->strokeJoin() == StrokeJoin::Round);
190 TEST_CASE("Shape Filling", "[tvgShape]")
192 auto shape = Shape::gen();
197 REQUIRE(shape->fill(255, 100, 50, 5) == Result::Success);
198 REQUIRE(shape->fillColor(&r, nullptr, &b, nullptr) == Result::Success);
201 REQUIRE(shape->fillColor(&r, &g, &b, &a) == Result::Success);
206 REQUIRE(shape->fillRule() == FillRule::Winding);
207 REQUIRE(shape->fill(FillRule::EvenOdd) == Result::Success);
208 REQUIRE(shape->fillRule() == FillRule::EvenOdd);