Skip to content

Commit db738ce

Browse files
committed
Point_Tests: Increase coverage
- Add blank constructor, JSON in/out tests More Point tests
1 parent 97cd270 commit db738ce

File tree

1 file changed

+84
-29
lines changed

1 file changed

+84
-29
lines changed

tests/Point_Tests.cpp

Lines changed: 84 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,86 +33,141 @@
3333
#define DONT_SET_USING_JUCE_NAMESPACE 1
3434
#include "OpenShot.h"
3535

36-
using namespace std;
37-
using namespace openshot;
36+
SUITE(POINT) {
3837

39-
TEST(Point_Default_Constructor)
38+
TEST(Default_Constructor)
39+
{
40+
openshot::Point p;
41+
42+
// Default values
43+
CHECK_EQUAL(1, p.co.X);
44+
CHECK_EQUAL(0, p.co.Y);
45+
CHECK_EQUAL(0.5, p.handle_left.X);
46+
CHECK_EQUAL(1.0, p.handle_left.Y);
47+
CHECK_EQUAL(0.5, p.handle_right.X);
48+
CHECK_EQUAL(0.0, p.handle_right.Y);
49+
CHECK_EQUAL(openshot::InterpolationType::BEZIER, p.interpolation);
50+
CHECK_EQUAL(openshot::HandleType::AUTO, p.handle_type);
51+
}
52+
TEST(XY_Constructor)
4053
{
4154
// Create a point with X and Y values
4255
openshot::Point p1(2,9);
4356

4457
CHECK_EQUAL(2, p1.co.X);
4558
CHECK_EQUAL(9, p1.co.Y);
46-
CHECK_EQUAL(BEZIER, p1.interpolation);
59+
CHECK_EQUAL(openshot::InterpolationType::BEZIER, p1.interpolation);
4760
}
4861

49-
TEST(Point_Constructor_With_Coordinate)
62+
TEST(Constructor_With_Coordinate)
5063
{
5164
// Create a point with a coordinate
52-
Coordinate c1(3,7);
65+
openshot::Coordinate c1(3,7);
5366
openshot::Point p1(c1);
5467

5568
CHECK_EQUAL(3, p1.co.X);
5669
CHECK_EQUAL(7, p1.co.Y);
57-
CHECK_EQUAL(BEZIER, p1.interpolation);
70+
CHECK_EQUAL(openshot::InterpolationType::BEZIER, p1.interpolation);
5871
}
5972

60-
TEST(Point_Constructor_With_Coordinate_And_LINEAR_Interpolation)
73+
TEST(Constructor_With_Coordinate_And_LINEAR_Interpolation)
6174
{
6275
// Create a point with a coordinate and interpolation
63-
Coordinate c1(3,9);
64-
InterpolationType interp = LINEAR;
76+
openshot::Coordinate c1(3,9);
77+
auto interp = openshot::InterpolationType::LINEAR;
6578
openshot::Point p1(c1, interp);
6679

6780
CHECK_EQUAL(3, c1.X);
6881
CHECK_EQUAL(9, c1.Y);
69-
CHECK_EQUAL(LINEAR, p1.interpolation);
82+
CHECK_EQUAL(openshot::InterpolationType::LINEAR, p1.interpolation);
7083
}
7184

72-
TEST(Point_Constructor_With_Coordinate_And_BEZIER_Interpolation)
85+
TEST(Constructor_With_Coordinate_And_BEZIER_Interpolation)
7386
{
7487
// Create a point with a coordinate and interpolation
75-
Coordinate c1(3,9);
76-
InterpolationType interp = BEZIER;
88+
openshot::Coordinate c1(3,9);
89+
auto interp = openshot::InterpolationType::BEZIER;
7790
openshot::Point p1(c1, interp);
7891

7992
CHECK_EQUAL(3, p1.co.X);
8093
CHECK_EQUAL(9, p1.co.Y);
81-
CHECK_EQUAL(BEZIER, p1.interpolation);
94+
CHECK_EQUAL(openshot::InterpolationType::BEZIER, p1.interpolation);
8295
}
8396

84-
TEST(Point_Constructor_With_Coordinate_And_CONSTANT_Interpolation)
97+
TEST(Constructor_With_Coordinate_And_CONSTANT_Interpolation)
8598
{
8699
// Create a point with a coordinate and interpolation
87-
Coordinate c1(2,8);
88-
InterpolationType interp = CONSTANT;
100+
openshot::Coordinate c1(2,8);
101+
auto interp = openshot::InterpolationType::CONSTANT;
89102
openshot::Point p1(c1, interp);
90103

91104
CHECK_EQUAL(2, p1.co.X);
92105
CHECK_EQUAL(8, p1.co.Y);
93-
CHECK_EQUAL(CONSTANT, p1.interpolation);
106+
CHECK_EQUAL(openshot::InterpolationType::CONSTANT, p1.interpolation);
94107
}
95108

96-
TEST(Point_Constructor_With_Coordinate_And_BEZIER_And_AUTO_Handle)
109+
TEST(Constructor_With_Coordinate_And_BEZIER_And_AUTO_Handle)
97110
{
98111
// Create a point with a coordinate and interpolation
99-
Coordinate c1(3,9);
100-
openshot::Point p1(c1, BEZIER, AUTO);
112+
openshot::Coordinate c1(3,9);
113+
openshot::Point p1(c1,
114+
openshot::InterpolationType::BEZIER,
115+
openshot::HandleType::AUTO);
101116

102117
CHECK_EQUAL(3, p1.co.X);
103118
CHECK_EQUAL(9, p1.co.Y);
104-
CHECK_EQUAL(BEZIER, p1.interpolation);
105-
CHECK_EQUAL(AUTO, p1.handle_type);
119+
CHECK_EQUAL(openshot::InterpolationType::BEZIER, p1.interpolation);
120+
CHECK_EQUAL(openshot::HandleType::AUTO, p1.handle_type);
106121
}
107122

108-
TEST(Point_Constructor_With_Coordinate_And_BEZIER_And_MANUAL_Handle)
123+
TEST(Constructor_With_Coordinate_And_BEZIER_And_MANUAL_Handle)
109124
{
110125
// Create a point with a coordinate and interpolation
111-
Coordinate c1(3,9);
112-
openshot::Point p1(c1, BEZIER, MANUAL);
126+
openshot::Coordinate c1(3,9);
127+
openshot::Point p1(c1,
128+
openshot::InterpolationType::BEZIER,
129+
openshot::HandleType::MANUAL);
113130

114131
CHECK_EQUAL(3, p1.co.X);
115132
CHECK_EQUAL(9, p1.co.Y);
116-
CHECK_EQUAL(BEZIER, p1.interpolation);
117-
CHECK_EQUAL(MANUAL, p1.handle_type);
133+
CHECK_EQUAL(openshot::InterpolationType::BEZIER, p1.interpolation);
134+
CHECK_EQUAL(openshot::HandleType::MANUAL, p1.handle_type);
135+
}
136+
137+
TEST(Json)
138+
{
139+
openshot::Point p1;
140+
openshot::Point p2(1, 0);
141+
auto json1 = p1.Json();
142+
auto json2 = p2.JsonValue();
143+
auto json_string2 = json2.toStyledString();
144+
CHECK_EQUAL(json1, json_string2);
118145
}
146+
147+
TEST(SetJson)
148+
{
149+
openshot::Point p1;
150+
std::stringstream json_stream;
151+
json_stream << R"json(
152+
{
153+
"co": { "X": 1.0, "Y": 0.0 },
154+
"handle_left": { "X": 2.0, "Y": 3.0 },
155+
"handle_right": { "X": 4.0, "Y": -2.0 },
156+
"handle_type": )json";
157+
json_stream << static_cast<float>(openshot::HandleType::MANUAL) << ",";
158+
json_stream << R"json(
159+
"interpolation": )json";
160+
json_stream << static_cast<float>(openshot::InterpolationType::CONSTANT);
161+
json_stream << R"json(
162+
}
163+
)json";
164+
p1.SetJson(json_stream.str());
165+
CHECK_EQUAL(2.0, p1.handle_left.X);
166+
CHECK_EQUAL(3.0, p1.handle_left.Y);
167+
CHECK_EQUAL(4.0, p1.handle_right.X);
168+
CHECK_EQUAL(-2.0, p1.handle_right.Y);
169+
CHECK_EQUAL(openshot::HandleType::MANUAL, p1.handle_type);
170+
CHECK_EQUAL(openshot::InterpolationType::CONSTANT, p1.interpolation);
171+
}
172+
173+
} // SUITE

0 commit comments

Comments
 (0)