2013-09-12 23:41:49 -05:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @brief Unit tests for openshot::ReaderBase
|
|
|
|
|
* @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
|
|
|
|
2020-12-26 21:51:24 -05:00
|
|
|
#include <memory>
|
2021-04-09 04:09:36 -04:00
|
|
|
#include <string>
|
|
|
|
|
|
2022-06-17 15:07:16 -04:00
|
|
|
#include "openshot_catch.h"
|
2020-12-26 21:51:24 -05:00
|
|
|
|
|
|
|
|
#include "ReaderBase.h"
|
|
|
|
|
#include "CacheBase.h"
|
|
|
|
|
#include "Frame.h"
|
|
|
|
|
#include "Json.h"
|
2011-10-11 08:44:27 -05:00
|
|
|
|
|
|
|
|
using namespace openshot;
|
|
|
|
|
|
|
|
|
|
// Since it is not possible to instantiate an abstract class, this test creates
|
|
|
|
|
// a new derived class, in order to test the base class file info struct.
|
2021-04-19 20:38:03 -04:00
|
|
|
TEST_CASE( "derived class", "[libopenshot][readerbase]" )
|
2011-10-11 08:44:27 -05:00
|
|
|
{
|
2013-09-08 16:40:57 -05:00
|
|
|
// Create a new derived class from type ReaderBase
|
|
|
|
|
class TestReader : public ReaderBase
|
2011-10-11 08:44:27 -05:00
|
|
|
{
|
|
|
|
|
public:
|
2015-02-05 00:12:34 -06:00
|
|
|
TestReader() { };
|
2021-04-09 04:09:36 -04:00
|
|
|
CacheBase* GetCache() { return nullptr; };
|
2017-09-28 16:03:01 -05:00
|
|
|
std::shared_ptr<Frame> GetFrame(int64_t number) { std::shared_ptr<Frame> f(new Frame()); return f; }
|
2012-10-08 16:22:18 -05:00
|
|
|
void Close() { };
|
|
|
|
|
void Open() { };
|
2021-04-09 04:09:36 -04:00
|
|
|
std::string Json() const { return ""; };
|
|
|
|
|
void SetJson(std::string value) { };
|
2020-03-10 23:56:27 -04:00
|
|
|
Json::Value JsonValue() const { return Json::Value("{}"); };
|
2013-12-18 21:55:43 -06:00
|
|
|
void SetJsonValue(Json::Value root) { };
|
|
|
|
|
bool IsOpen() { return true; };
|
2021-04-09 04:09:36 -04:00
|
|
|
std::string Name() { return "TestReader"; };
|
2011-10-11 08:44:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Create an instance of the derived class
|
|
|
|
|
TestReader t1;
|
|
|
|
|
|
2020-03-10 23:56:27 -04:00
|
|
|
// Validate the new class
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(t1.Name() == "TestReader");
|
2020-03-10 23:56:27 -04:00
|
|
|
|
|
|
|
|
t1.Close();
|
|
|
|
|
t1.Open();
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(t1.IsOpen() == true);
|
2020-03-10 23:56:27 -04:00
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(t1.GetCache() == nullptr);
|
2020-03-10 23:56:27 -04:00
|
|
|
|
|
|
|
|
t1.SetJson("{ }");
|
|
|
|
|
t1.SetJsonValue(Json::Value("{}"));
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(t1.Json() == "");
|
2020-03-10 23:56:27 -04:00
|
|
|
auto json = t1.JsonValue();
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(Json::Value("{}") == json);
|
2020-03-10 23:56:27 -04:00
|
|
|
|
|
|
|
|
auto f = t1.GetFrame(1);
|
|
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
REQUIRE(f != nullptr);
|
|
|
|
|
CHECK(f->number == 1);
|
|
|
|
|
|
2011-10-11 08:44:27 -05:00
|
|
|
// Check some of the default values of the FileInfo struct on the base class
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK_FALSE(t1.info.has_audio);
|
|
|
|
|
CHECK_FALSE(t1.info.has_audio);
|
|
|
|
|
CHECK(t1.info.duration == Approx(0.0f).margin(0.00001));
|
|
|
|
|
CHECK(t1.info.height == 0);
|
|
|
|
|
CHECK(t1.info.width == 0);
|
|
|
|
|
CHECK(t1.info.fps.num == 1);
|
|
|
|
|
CHECK(t1.info.fps.den == 1);
|
2011-10-11 08:44:27 -05:00
|
|
|
}
|