Files
libopenshot/tests/Coordinate.cpp

76 lines
1.7 KiB
C++
Raw Permalink Normal View History

/**
* @file
* @brief Unit tests for openshot::Coordinate
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
// Copyright (c) 2008-2019 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "openshot_catch.h"
2021-04-09 04:09:36 -04:00
#include "Coordinate.h"
2021-01-27 05:48:53 -05:00
#include "Exceptions.h"
2011-10-11 08:44:27 -05:00
using namespace openshot;
2021-04-09 04:09:36 -04:00
TEST_CASE( "default constructor", "[libopenshot][coordinate]" )
2011-10-11 08:44:27 -05:00
{
// Create an empty coordinate
Coordinate c1;
2021-04-09 04:09:36 -04:00
CHECK(c1.X == Approx(0.0f).margin(0.00001));
CHECK(c1.Y == Approx(0.0f).margin(0.00001));
2011-10-11 08:44:27 -05:00
}
2021-04-09 04:09:36 -04:00
TEST_CASE( "XY constructor", "[libopenshot][coordinate]" )
2011-10-11 08:44:27 -05:00
{
// Create an empty coordinate
Coordinate c1(2,8);
2021-04-09 04:09:36 -04:00
CHECK(c1.X == Approx(2.0f).margin(0.00001));
CHECK(c1.Y == Approx(8.0f).margin(0.00001));
2011-10-11 08:44:27 -05:00
}
2020-11-21 16:07:27 -05:00
2021-04-09 04:09:36 -04:00
TEST_CASE( "std::pair constructor", "[libopenshot][coordinate]" )
{
Coordinate c1(std::pair<double,double>(12, 10));
2021-04-09 04:09:36 -04:00
CHECK(c1.X == Approx(12.0f).margin(0.00001));
CHECK(c1.Y == Approx(10.0f).margin(0.00001));
}
2021-04-09 04:09:36 -04:00
TEST_CASE( "Json", "[libopenshot][coordinate]" )
2020-11-21 16:07:27 -05:00
{
openshot::Coordinate c(100, 200);
openshot::Coordinate c1;
c1.X = 100;
c1.Y = 200;
// Check that JSON produced is identical
auto j = c.Json();
auto j1 = c1.Json();
2021-04-09 04:09:36 -04:00
CHECK(j1 == j);
2020-11-21 16:07:27 -05:00
// Check Json::Value representation
auto jv = c.JsonValue();
auto jv_string = jv.toStyledString();
2021-04-09 04:09:36 -04:00
CHECK(j1 == jv_string);
2020-11-21 16:07:27 -05:00
}
2021-04-09 04:09:36 -04:00
TEST_CASE( "SetJson", "[libopenshot][coordinate]" ) {
2020-11-21 16:07:27 -05:00
// Construct our input Json representation
const std::string json_input = R"json(
{
"X": 100.0,
"Y": 50.0
}
)json";
openshot::Coordinate c;
2021-04-09 04:09:36 -04:00
CHECK_THROWS_AS(c.SetJson("}{"), openshot::InvalidJSON);
2020-11-21 16:07:27 -05:00
// Check that values set via SetJson() are correct
c.SetJson(json_input);
2021-04-09 04:09:36 -04:00
CHECK(c.X == Approx(100.0).margin(0.01));
CHECK(c.Y == Approx(50.0).margin(0.01));
2020-11-21 16:07:27 -05:00
}