2013-09-12 23:41:49 -05:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @brief Unit tests for openshot::Coordinate
|
|
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
2019-06-09 08:31:04 -04:00
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-16 01:26:26 -04:00
|
|
|
// Copyright (c) 2008-2019 OpenShot Studios, LLC
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2013-09-12 23:41:49 -05:00
|
|
|
|
2022-06-17 15:07:16 -04:00
|
|
|
#include "openshot_catch.h"
|
2021-04-09 04:09:36 -04:00
|
|
|
|
2020-12-26 21:51:24 -05: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]" )
|
2020-12-04 11:27:18 -05:00
|
|
|
{
|
|
|
|
|
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));
|
2020-12-04 11:27:18 -05:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|