Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clip_Tests: Remove try/catch blocks #468

Merged
merged 2 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ coverage:
ignore:
- "/src/examples"
- "/src/Qt/demo"
- "/thirdparty"
- "/thirdparty/jsoncpp/*.cpp"
- "/thirdparty/jsoncpp/json/*.h"
- "/doc"
- "/cmake"
- "/*.md"
134 changes: 52 additions & 82 deletions tests/Clip_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@
*/

#include "UnitTest++.h"

// Work around older versions of UnitTest++ without REQUIRE
#ifndef REQUIRE
#define REQUIRE
#endif

// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "../include/OpenShot.h"

using namespace std;
using namespace openshot;

TEST(Clip_Default_Constructor)
SUITE(Clip)
{

TEST(Default_Constructor)
{
// Create a empty clip
Clip c1;
Expand All @@ -54,7 +62,7 @@ TEST(Clip_Default_Constructor)
TEST(Clip_Constructor)
{
// Create a empty clip
stringstream path;
std::stringstream path;
path << TEST_MEDIA_PATH << "piano.wav";
Clip c1(path.str());
c1.Open();
Expand All @@ -69,7 +77,7 @@ TEST(Clip_Constructor)
CHECK_CLOSE(4.39937f, c1.End(), 0.00001);
}

TEST(Clip_Basic_Gettings_and_Setters)
TEST(Basic_Gettings_and_Setters)
{
// Create a empty clip
Clip c1;
Expand All @@ -96,7 +104,7 @@ TEST(Clip_Basic_Gettings_and_Setters)
CHECK_CLOSE(10.5f, c1.End(), 0.00001);
}

TEST(Clip_Properties)
TEST(Properties)
{
// Create a empty clip
Clip c1;
Expand All @@ -110,116 +118,75 @@ TEST(Clip_Properties)
c1.alpha.AddPoint(500, 0.0);

// Get properties JSON string at frame 1
string properties = c1.PropertiesJSON(1);
std::string properties = c1.PropertiesJSON(1);

// Parse JSON string into JSON objects
Json::Value root;
Json::CharReaderBuilder rbuilder;
Json::CharReader* reader(rbuilder.newCharReader());
string errors;
bool success = reader->parse( properties.c_str(),
properties.c_str() + properties.size(), &root, &errors );

if (!success)
// Raise exception
throw InvalidJSON("JSON could not be parsed (or is invalid)");

try
{
// Check for specific things
CHECK_CLOSE(1.0f, root["alpha"]["value"].asDouble(), 0.01);
CHECK_EQUAL(true, root["alpha"]["keyframe"].asBool());

}
catch (const std::exception& e)
{
// Error parsing JSON (or missing keys)
throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
}
std::string errors;
bool success = reader->parse(
properties.c_str(),
properties.c_str() + properties.size(),
&root, &errors );
CHECK_EQUAL(true, success);

// Check for specific things
CHECK_CLOSE(1.0f, root["alpha"]["value"].asDouble(), 0.01);
CHECK_EQUAL(true, root["alpha"]["keyframe"].asBool());

// Get properties JSON string at frame 250
properties = c1.PropertiesJSON(250);

// Parse JSON string into JSON objects
root.clear();
success = reader->parse( properties.c_str(),
properties.c_str() + properties.size(), &root, &errors );
if (!success)
// Raise exception
throw InvalidJSON("JSON could not be parsed (or is invalid)");

try
{
// Check for specific things
CHECK_CLOSE(0.5f, root["alpha"]["value"].asDouble(), 0.01);
CHECK_EQUAL(false, root["alpha"]["keyframe"].asBool());

}
catch (const std::exception& e)
{
// Error parsing JSON (or missing keys)
throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
}
success = reader->parse(
properties.c_str(),
properties.c_str() + properties.size(),
&root, &errors );
REQUIRE CHECK_EQUAL(true, success);

// Check for specific things
CHECK_CLOSE(0.5f, root["alpha"]["value"].asDouble(), 0.01);
CHECK_EQUAL(false, root["alpha"]["keyframe"].asBool());

// Get properties JSON string at frame 250 (again)
properties = c1.PropertiesJSON(250); // again
properties = c1.PropertiesJSON(250);

// Parse JSON string into JSON objects
root.clear();
success = reader->parse( properties.c_str(),
properties.c_str() + properties.size(), &root, &errors );
if (!success)
// Raise exception
throw InvalidJSON("JSON could not be parsed (or is invalid)");

try
{
// Check for specific things
CHECK_EQUAL(false, root["alpha"]["keyframe"].asBool());

}
catch (const std::exception& e)
{
// Error parsing JSON (or missing keys)
throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
}
success = reader->parse(
properties.c_str(),
properties.c_str() + properties.size(),
&root, &errors );
REQUIRE CHECK_EQUAL(true, success);

// Check for specific things
CHECK_EQUAL(false, root["alpha"]["keyframe"].asBool());

// Get properties JSON string at frame 500
properties = c1.PropertiesJSON(500);

// Parse JSON string into JSON objects
root.clear();
success = reader->parse( properties.c_str(),
properties.c_str() + properties.size(), &root, &errors );
if (!success)
// Raise exception
throw InvalidJSON("JSON could not be parsed (or is invalid)");

try
{
// Check for specific things
CHECK_CLOSE(0.0f, root["alpha"]["value"].asDouble(), 0.00001);
CHECK_EQUAL(true, root["alpha"]["keyframe"].asBool());

}
catch (const std::exception& e)
{
// Error parsing JSON (or missing keys)
throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
}
success = reader->parse(
properties.c_str(),
properties.c_str() + properties.size(),
&root, &errors );
REQUIRE CHECK_EQUAL(true, success);

// Check for specific things
CHECK_CLOSE(0.0f, root["alpha"]["value"].asDouble(), 0.00001);
CHECK_EQUAL(true, root["alpha"]["keyframe"].asBool());

// Free up the reader we allocated
delete reader;
}

TEST(Clip_Effects)
TEST(Effects)
{
// Load clip with video
stringstream path;
std::stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
Clip c10(path.str());
c10.Open();
Expand Down Expand Up @@ -264,3 +231,6 @@ TEST(Clip_Effects)
// Check the # of Effects
CHECK_EQUAL(2, (int)c10.Effects().size());
}

} // SUITE