2929 */
3030
3131#include " UnitTest++.h"
32+
33+ // Work around older versions of UnitTest++ without REQUIRE
34+ #ifndef REQUIRE
35+ #define REQUIRE
36+ #endif
37+
3238// Prevent name clashes with juce::UnitTest
3339#define DONT_SET_USING_JUCE_NAMESPACE 1
3440#include " ../include/OpenShot.h"
3541
36- using namespace std ;
3742using namespace openshot ;
3843
39- TEST (Clip_Default_Constructor)
44+ SUITE (Clip)
45+ {
46+
47+ TEST (Default_Constructor)
4048{
4149 // Create a empty clip
4250 Clip c1;
@@ -54,7 +62,7 @@ TEST(Clip_Default_Constructor)
5462TEST (Clip_Constructor)
5563{
5664 // Create a empty clip
57- stringstream path;
65+ std:: stringstream path;
5866 path << TEST_MEDIA_PATH << " piano.wav" ;
5967 Clip c1 (path.str ());
6068 c1.Open ();
@@ -69,7 +77,7 @@ TEST(Clip_Constructor)
6977 CHECK_CLOSE (4 .39937f , c1.End (), 0.00001 );
7078}
7179
72- TEST (Clip_Basic_Gettings_and_Setters )
80+ TEST (Basic_Gettings_and_Setters )
7381{
7482 // Create a empty clip
7583 Clip c1;
@@ -96,7 +104,7 @@ TEST(Clip_Basic_Gettings_and_Setters)
96104 CHECK_CLOSE (10 .5f , c1.End (), 0.00001 );
97105}
98106
99- TEST (Clip_Properties )
107+ TEST (Properties )
100108{
101109 // Create a empty clip
102110 Clip c1;
@@ -110,116 +118,75 @@ TEST(Clip_Properties)
110118 c1.alpha .AddPoint (500 , 0.0 );
111119
112120 // Get properties JSON string at frame 1
113- string properties = c1.PropertiesJSON (1 );
121+ std:: string properties = c1.PropertiesJSON (1 );
114122
115123 // Parse JSON string into JSON objects
116124 Json::Value root;
117125 Json::CharReaderBuilder rbuilder;
118126 Json::CharReader* reader (rbuilder.newCharReader ());
119- string errors;
120- bool success = reader->parse ( properties.c_str (),
121- properties.c_str () + properties.size (), &root, &errors );
122-
123- if (!success)
124- // Raise exception
125- throw InvalidJSON (" JSON could not be parsed (or is invalid)" );
126-
127- try
128- {
129- // Check for specific things
130- CHECK_CLOSE (1 .0f , root[" alpha" ][" value" ].asDouble (), 0.01 );
131- CHECK_EQUAL (true , root[" alpha" ][" keyframe" ].asBool ());
132-
133- }
134- catch (const std::exception& e)
135- {
136- // Error parsing JSON (or missing keys)
137- throw InvalidJSON (" JSON is invalid (missing keys or invalid data types)" );
138- }
127+ std::string errors;
128+ bool success = reader->parse (
129+ properties.c_str (),
130+ properties.c_str () + properties.size (),
131+ &root, &errors );
132+ CHECK_EQUAL (true , success);
139133
134+ // Check for specific things
135+ CHECK_CLOSE (1 .0f , root[" alpha" ][" value" ].asDouble (), 0.01 );
136+ CHECK_EQUAL (true , root[" alpha" ][" keyframe" ].asBool ());
140137
141138 // Get properties JSON string at frame 250
142139 properties = c1.PropertiesJSON (250 );
143140
144141 // Parse JSON string into JSON objects
145142 root.clear ();
146- success = reader->parse ( properties.c_str (),
147- properties.c_str () + properties.size (), &root, &errors );
148- if (!success)
149- // Raise exception
150- throw InvalidJSON (" JSON could not be parsed (or is invalid)" );
151-
152- try
153- {
154- // Check for specific things
155- CHECK_CLOSE (0 .5f , root[" alpha" ][" value" ].asDouble (), 0.01 );
156- CHECK_EQUAL (false , root[" alpha" ][" keyframe" ].asBool ());
157-
158- }
159- catch (const std::exception& e)
160- {
161- // Error parsing JSON (or missing keys)
162- throw InvalidJSON (" JSON is invalid (missing keys or invalid data types)" );
163- }
143+ success = reader->parse (
144+ properties.c_str (),
145+ properties.c_str () + properties.size (),
146+ &root, &errors );
147+ REQUIRE CHECK_EQUAL (true , success);
164148
149+ // Check for specific things
150+ CHECK_CLOSE (0 .5f , root[" alpha" ][" value" ].asDouble (), 0.01 );
151+ CHECK_EQUAL (false , root[" alpha" ][" keyframe" ].asBool ());
165152
166153 // Get properties JSON string at frame 250 (again)
167- properties = c1.PropertiesJSON (250 ); // again
154+ properties = c1.PropertiesJSON (250 );
168155
169156 // Parse JSON string into JSON objects
170157 root.clear ();
171- success = reader->parse ( properties.c_str (),
172- properties.c_str () + properties.size (), &root, &errors );
173- if (!success)
174- // Raise exception
175- throw InvalidJSON (" JSON could not be parsed (or is invalid)" );
176-
177- try
178- {
179- // Check for specific things
180- CHECK_EQUAL (false , root[" alpha" ][" keyframe" ].asBool ());
181-
182- }
183- catch (const std::exception& e)
184- {
185- // Error parsing JSON (or missing keys)
186- throw InvalidJSON (" JSON is invalid (missing keys or invalid data types)" );
187- }
158+ success = reader->parse (
159+ properties.c_str (),
160+ properties.c_str () + properties.size (),
161+ &root, &errors );
162+ REQUIRE CHECK_EQUAL (true , success);
188163
164+ // Check for specific things
165+ CHECK_EQUAL (false , root[" alpha" ][" keyframe" ].asBool ());
189166
190167 // Get properties JSON string at frame 500
191168 properties = c1.PropertiesJSON (500 );
192169
193170 // Parse JSON string into JSON objects
194171 root.clear ();
195- success = reader->parse ( properties.c_str (),
196- properties.c_str () + properties.size (), &root, &errors );
197- if (!success)
198- // Raise exception
199- throw InvalidJSON (" JSON could not be parsed (or is invalid)" );
200-
201- try
202- {
203- // Check for specific things
204- CHECK_CLOSE (0 .0f , root[" alpha" ][" value" ].asDouble (), 0.00001 );
205- CHECK_EQUAL (true , root[" alpha" ][" keyframe" ].asBool ());
206-
207- }
208- catch (const std::exception& e)
209- {
210- // Error parsing JSON (or missing keys)
211- throw InvalidJSON (" JSON is invalid (missing keys or invalid data types)" );
212- }
172+ success = reader->parse (
173+ properties.c_str (),
174+ properties.c_str () + properties.size (),
175+ &root, &errors );
176+ REQUIRE CHECK_EQUAL (true , success);
213177
178+ // Check for specific things
179+ CHECK_CLOSE (0 .0f , root[" alpha" ][" value" ].asDouble (), 0.00001 );
180+ CHECK_EQUAL (true , root[" alpha" ][" keyframe" ].asBool ());
214181
215182 // Free up the reader we allocated
216183 delete reader;
217184}
218185
219- TEST (Clip_Effects )
186+ TEST (Effects )
220187{
221188 // Load clip with video
222- stringstream path;
189+ std:: stringstream path;
223190 path << TEST_MEDIA_PATH << " sintel_trailer-720p.mp4" ;
224191 Clip c10 (path.str ());
225192 c10.Open ();
@@ -264,3 +231,6 @@ TEST(Clip_Effects)
264231 // Check the # of Effects
265232 CHECK_EQUAL (2 , (int )c10.Effects ().size ());
266233}
234+
235+ } // SUITE
236+
0 commit comments