Remove old UnitTest++ tests

This commit is contained in:
FeRD (Frank Dana)
2021-04-09 05:27:18 -04:00
parent 893a7c4240
commit 1240aaa874
23 changed files with 31 additions and 4881 deletions

View File

@@ -76,8 +76,7 @@ option(DISABLE_BUNDLED_JSONCPP "Don't fall back to bundled JsonCpp" OFF)
option(ENABLE_IWYU "Enable 'Include What You Use' scanner (CMake 3.3+)" OFF)
option(ENABLE_TESTS "Build unit tests (requires Catch2 or UnitTest++)" ON)
option(USE_CATCH2 "Enable Catch2-based unit tests" ON)
option(ENABLE_TESTS "Build unit tests (requires Catch2)" ON)
option(ENABLE_PARALLEL_CTEST "Run CTest using multiple processors" ON)
option(ENABLE_COVERAGE "Scan test coverage using gcov and report" OFF)
@@ -93,7 +92,7 @@ if (DISABLE_TESTS)
endif()
if(DEFINED ENABLE_TESTS)
set(ENABLE_TESTS ${ENABLE_TESTS} CACHE BOOL "Build unit tests (requires Catch2 or UnitTest++)" FORCE)
set(ENABLE_TESTS ${ENABLE_TESTS} CACHE BOOL "Build unit tests (requires Catch2)" FORCE)
endif()
#### Work around a GCC < 9 bug with handling of _Pragma() in macros
@@ -176,58 +175,42 @@ endif()
############# PROCESS tests/ DIRECTORY ##############
if(ENABLE_TESTS)
set(TESTS_ENABLED TRUE) # May be overridden by tests/CMakeLists.txt
if (USE_CATCH2)
find_package(Catch2 REQUIRED)
if(ENABLE_PARALLEL_CTEST)
# Figure out the amount of parallelism for CTest
include(ProcessorCount)
ProcessorCount(CPU_COUNT)
if(NOT CPU_COUNT EQUAL 0)
message(STATUS "Setting up unit tests to use ${CPU_COUNT} processors")
set(CTEST_OPTIONS "-j${CPU_COUNT}")
endif()
find_package(Catch2 REQUIRED)
if(ENABLE_PARALLEL_CTEST)
# Figure out the amount of parallelism for CTest
include(ProcessorCount)
ProcessorCount(CPU_COUNT)
if(NOT CPU_COUNT EQUAL 0)
message(STATUS "Setting up unit tests to use ${CPU_COUNT} processors")
set(CTEST_OPTIONS "-j${CPU_COUNT}")
endif()
include(CTest)
include(Catch)
endif()
include(CTest)
include(Catch)
add_subdirectory(tests)
endif()
add_feature_info("Unit tests" TESTS_ENABLED "Compile unit tests for library functions")
############## COVERAGE REPORTING #################
if (ENABLE_COVERAGE)
if (DEFINED CATCH2_TEST_TARGETS)
setup_target_for_coverage_lcov(
NAME coverage
LCOV_ARGS "--no-external"
EXECUTABLE ctest
EXECUTABLE_ARGS ${CTEST_OPTIONS}
DEPENDENCIES openshot ${CATCH2_TEST_TARGETS}
EXCLUDE
"bindings/*"
"examples/*"
"${CMAKE_CURRENT_BINARY_DIR}/bindings/*"
"${CMAKE_CURRENT_BINARY_DIR}/src/*_autogen/*"
)
else()
setup_target_for_coverage_lcov(
NAME coverage
LCOV_ARGS "--no-external"
EXECUTABLE ${UNIT_TEST_TARGETS}
DEPENDENCIES openshot
EXCLUDE
"bindings/*"
"examples/*"
"${CMAKE_CURRENT_BINARY_DIR}/bindings/*"
"${CMAKE_CURRENT_BINARY_DIR}/src/*_autogen/*"
)
endif()
if (ENABLE_COVERAGE AND DEFINED UNIT_TEST_TARGETS)
setup_target_for_coverage_lcov(
NAME coverage
LCOV_ARGS "--no-external"
EXECUTABLE ctest
EXECUTABLE_ARGS ${CTEST_OPTIONS}
DEPENDENCIES openshot ${UNIT_TEST_TARGETS}
EXCLUDE
"bindings/*"
"examples/*"
"${CMAKE_CURRENT_BINARY_DIR}/bindings/*"
"${CMAKE_CURRENT_BINARY_DIR}/src/*_autogen/*"
)
endif()
if(TESTS_ENABLED AND NOT TARGET coverage)
add_custom_target(coverage
COMMAND ctest ${CTEST_OPTIONS}
DEPENDS openshot ${CATCH2_TEST_TARGETS} ${UNIT_TEST_TARGETS}
DEPENDS openshot ${UNIT_TEST_TARGETS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Running unit tests (coverage disabled)"
)

View File

@@ -42,6 +42,8 @@ endif()
### TEST SOURCE FILES
###
set(OPENSHOT_TESTS
CacheDisk
CacheMemory
Clip
Color
Coordinate
@@ -60,16 +62,6 @@ set(OPENSHOT_TESTS
Timeline
)
# Handle differences in test sets
if(USE_CATCH2)
list(APPEND OPENSHOT_TESTS
CacheDisk
CacheMemory
)
else()
list(APPEND OPENSHOT_TESTS Cache)
endif()
###
### OPENCV RELATED TEST FILES
###
@@ -82,9 +74,9 @@ if(ENABLE_OPENCV)
endif()
###
### Catch2 (new) unit tests
### Catch2 unit tests
###
if (TESTS_ENABLED AND USE_CATCH2)
if (TESTS_ENABLED)
message (STATUS "Tests enabled, test executables will be compiled")
include(Catch)
@@ -108,47 +100,6 @@ if (TESTS_ENABLED AND USE_CATCH2)
list(APPEND CATCH2_TEST_TARGETS openshot-${tname}-test)
endforeach()
# Export target list for coverage use
set(CATCH2_TEST_TARGETS ${CATCH2_TEST_TARGETS} PARENT_SCOPE)
set(UNIT_TEST_TARGETS ${CATCH2_TEST_TARGETS} PARENT_SCOPE)
endif()
###
### UNITTEST++ (old) unit tests
###
if (TESTS_ENABLED AND NOT USE_CATCH2)
# Find UnitTest++ libraries (used for unit testing)
find_package(UnitTest++)
if (NOT UnitTest++_FOUND)
set(TESTS_ENABLED OFF PARENT_SCOPE)
return()
endif()
# Include UnitTest++ headers (needed for compile)
include_directories(${UnitTest++_INCLUDE_DIRS})
set_package_properties(UnitTest++ PROPERTIES
TYPE RECOMMENDED
PURPOSE "Unit testing framework")
################ TESTER EXECUTABLE #################
# Create unit test executable (openshot-test)
message (STATUS "Tests enabled, test executable will be built as tests/openshot-test")
foreach(tname ${OPENSHOT_TESTS})
list(APPEND TEST_SOURCES cppunittest/${tname}_Tests.cpp)
endforeach()
add_executable(openshot-test
cppunittest/tests.cpp
${TEST_SOURCES}
)
target_compile_definitions(openshot-test PRIVATE
TEST_MEDIA_PATH="${TEST_MEDIA_PATH}"
)
# Link libraries to the new executable
target_link_libraries(openshot-test
openshot
${UnitTest++_LIBRARIES}
)
set(UNIT_TEST_TARGETS openshot-test PARENT_SCOPE)
endif()

View File

@@ -1,140 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::Frame
* @author Jonathan Thomas <jonathan@openshot.org>
* @author FeRD (Frank Dana) <ferdnyc@gmail.com>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <memory>
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "Clip.h"
#include "CVObjectDetection.h"
#include "ProcessingController.h"
#include "Json.h"
using namespace openshot;
std::string effectInfo =(" {\"protobuf_data_path\": \"objdetector.data\", "
" \"processing_device\": \"GPU\", "
" \"model_configuration\": \"~/yolo/yolov3.cfg\", "
" \"model_weights\": \"~/yolo/yolov3.weights\", "
" \"classes_file\": \"~/yolo/obj.names\"} ");
SUITE(CVObjectDetection_Tests)
{
// Just for the stabilizer constructor, it won't be used
ProcessingController processingController;
TEST(DetectObject_Video)
{
// Create a video clip
std::stringstream path;
path << TEST_MEDIA_PATH << "run.mp4";
// Open clip
openshot::Clip c1(path.str());
c1.Open();
//TODO remove hardcoded path
CVObjectDetection objectDetector(effectInfo, processingController);
objectDetector.detectObjectsClip(c1, 0, 20, true);
CVDetectionData dd = objectDetector.GetDetectionData(20);
float x1 = dd.boxes.at(20).x;
float y1 = dd.boxes.at(20).y;
float x2 = x1 + dd.boxes.at(20).width;
float y2 = y1 + dd.boxes.at(20).height;
float confidence = dd.confidences.at(20);
int classId = dd.classIds.at(20);
CHECK_EQUAL((int) (x1 * 720), 106);
CHECK_EQUAL((int) (y1 * 400), 21);
CHECK_EQUAL((int) (x2 * 720), 628);
CHECK_EQUAL((int) (y2 * 400), 429);
CHECK_EQUAL((int) (confidence * 1000), 554);
CHECK_EQUAL(classId, 0);
}
TEST(SaveLoad_Protobuf)
{
// Create a video clip
std::stringstream path;
path << TEST_MEDIA_PATH << "run.mp4";
// Open clip
openshot::Clip c1(path.str());
c1.Open();
//TODO remove hardcoded path
CVObjectDetection objectDetector_1(effectInfo ,processingController);
objectDetector_1.detectObjectsClip(c1, 0, 20, true);
CVDetectionData dd_1 = objectDetector_1.GetDetectionData(20);
float x1_1 = dd_1.boxes.at(20).x;
float y1_1 = dd_1.boxes.at(20).y;
float x2_1 = x1_1 + dd_1.boxes.at(20).width;
float y2_1 = y1_1 + dd_1.boxes.at(20).height;
float confidence_1 = dd_1.confidences.at(20);
int classId_1 = dd_1.classIds.at(20);
objectDetector_1.SaveObjDetectedData();
CVObjectDetection objectDetector_2(effectInfo, processingController);
objectDetector_2._LoadObjDetectdData();
CVDetectionData dd_2 = objectDetector_2.GetDetectionData(20);
float x1_2 = dd_2.boxes.at(20).x;
float y1_2 = dd_2.boxes.at(20).y;
float x2_2 = x1_2 + dd_2.boxes.at(20).width;
float y2_2 = y1_2 + dd_2.boxes.at(20).height;
float confidence_2 = dd_2.confidences.at(20);
int classId_2 = dd_2.classIds.at(20);
CHECK_EQUAL((int) (x1_1 * 720), (int) (x1_2 * 720));
CHECK_EQUAL((int) (y1_1 * 400), (int) (y1_2 * 400));
CHECK_EQUAL((int) (x2_1 * 720), (int) (x2_2 * 720));
CHECK_EQUAL((int) (y2_1 * 400), (int) (y2_2 * 400));
CHECK_EQUAL((int) (confidence_1 * 1000), (int) (confidence_2 * 1000));
CHECK_EQUAL(classId_1, classId_2);
}
} // SUITE(Frame_Tests)

View File

@@ -1,142 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::Frame
* @author Jonathan Thomas <jonathan@openshot.org>
* @author FeRD (Frank Dana) <ferdnyc@gmail.com>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <memory>
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "Clip.h"
#include "CVStabilization.h" // for TransformParam, CamTrajectory, CVStabilization
#include "ProcessingController.h"
using namespace openshot;
SUITE(CVStabilizer_Tests)
{
// Just for the stabilizer constructor, it won't be used
ProcessingController processingController;
TEST(Stabilize_Video)
{
// Create a video clip
std::stringstream path;
path << TEST_MEDIA_PATH << "test.avi";
// Open clip
openshot::Clip c1(path.str());
c1.Open();
std::string json_data = R"proto(
{
"protobuf_data_path": "stabilizer.data",
"smoothing-window": 30
} )proto";
// Create stabilizer
CVStabilization stabilizer(json_data, processingController);
// Stabilize clip for frames 0-21
stabilizer.stabilizeClip(c1, 0, 21, true);
// Get stabilized data
TransformParam tp = stabilizer.GetTransformParamData(20);
CamTrajectory ct = stabilizer.GetCamTrajectoryTrackedData(20);
// // Compare if stabilized data is equal to pre-tested ones
int dx = tp.dx*1000;
int dy = tp.dy*1000;
int da = tp.da*1000;
int x = ct.x*1000;
int y = ct.y*1000;
int a = ct.a*1000;
CHECK_EQUAL((int) (58), dx);
CHECK_EQUAL((int) (-88), dy);
CHECK_EQUAL((int) (7), da);
CHECK_EQUAL((int) (0), x);
CHECK_EQUAL((int) (-1), y);
CHECK_EQUAL((int) (0), a);
}
TEST(SaveLoad_Protobuf)
{
// Create a video clip
std::stringstream path;
path << TEST_MEDIA_PATH << "test.avi";
// Open clip
openshot::Clip c1(path.str());
c1.Open();
std::string json_data = R"proto(
{
"protobuf_data_path": "stabilizer.data",
"smoothing-window": 30
} )proto";
// Create first stabilizer
CVStabilization stabilizer_1(json_data, processingController);
// Stabilize clip for frames 0-20
stabilizer_1.stabilizeClip(c1, 0, 20+1, true);
// Get stabilized data
TransformParam tp_1 = stabilizer_1.GetTransformParamData(20);
CamTrajectory ct_1 = stabilizer_1.GetCamTrajectoryTrackedData(20);
// Save stabilized data
stabilizer_1.SaveStabilizedData();
// Create second stabilizer
CVStabilization stabilizer_2(json_data, processingController);
// Load stabilized data from first stabilizer protobuf data
stabilizer_2._LoadStabilizedData();
// Get stabilized data
TransformParam tp_2 = stabilizer_2.GetTransformParamData(20);
CamTrajectory ct_2 = stabilizer_2.GetCamTrajectoryTrackedData(20);
// Compare first stabilizer data with second stabilizer data
CHECK_EQUAL((int) (tp_1.dx * 10000), (int) (tp_2.dx *10000));
CHECK_EQUAL((int) (tp_1.dy * 10000), (int) (tp_2.dy * 10000));
CHECK_EQUAL((int) (tp_1.da * 10000), (int) (tp_2.da * 10000));
CHECK_EQUAL((int) (ct_1.x * 10000), (int) (ct_2.x * 10000));
CHECK_EQUAL((int) (ct_1.y * 10000), (int) (ct_2.y * 10000));
CHECK_EQUAL((int) (ct_1.a * 10000), (int) (ct_2.a * 10000));
}
} // SUITE(Frame_Tests)

View File

@@ -1,151 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::Frame
* @author Jonathan Thomas <jonathan@openshot.org>
* @author FeRD (Frank Dana) <ferdnyc@gmail.com>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <memory>
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "Clip.h"
#include "CVTracker.h" // for FrameData, CVTracker
#include "ProcessingController.h"
using namespace openshot;
SUITE(CVTracker_Tests)
{
// Just for the tracker constructor, it won't be used
ProcessingController processingController;
TEST(Track_Video)
{
// Create a video clip
std::stringstream path;
path << TEST_MEDIA_PATH << "test.avi";
// Open clip
openshot::Clip c1(path.str());
c1.Open();
std::string json_data = R"proto(
{
"protobuf_data_path": "kcf_tracker.data",
"tracker-type": "KCF",
"region": {"x": 294, "y": 102, "width": 180, "height": 166, "first-frame": 0}
} )proto";
// Create tracker
CVTracker kcfTracker(json_data, processingController);
// Track clip for frames 0-20
kcfTracker.trackClip(c1, 0, 20, true);
// Get tracked data
FrameData fd = kcfTracker.GetTrackedData(20);
float x = fd.x1;
float y = fd.y1;
float width = fd.x2 - x;
float height = fd.y2 - y;
// Compare if tracked data is equal to pre-tested ones
CHECK_EQUAL(259, (int)(x * 640));
CHECK_EQUAL(131, (int)(y * 360));
CHECK_EQUAL(180, (int)(width * 640));
CHECK_EQUAL(166, (int)(height * 360));
}
TEST(SaveLoad_Protobuf)
{
// Create a video clip
std::stringstream path;
path << TEST_MEDIA_PATH << "test.avi";
// Open clip
openshot::Clip c1(path.str());
c1.Open();
std::string json_data = R"proto(
{
"protobuf_data_path": "kcf_tracker.data",
"tracker-type": "KCF",
"region": {"x": 294, "y": 102, "width": 180, "height": 166, "first-frame": 0}
} )proto";
// Create first tracker
CVTracker kcfTracker_1(json_data, processingController);
// Track clip for frames 0-20
kcfTracker_1.trackClip(c1, 0, 20, true);
// Get tracked data
FrameData fd_1 = kcfTracker_1.GetTrackedData(20);
float x_1 = fd_1.x1;
float y_1 = fd_1.y1;
float width_1 = fd_1.x2 - x_1;
float height_1 = fd_1.y2 - y_1;
// Save tracked data
kcfTracker_1.SaveTrackedData();
std::string proto_data_1 = R"proto(
{
"protobuf_data_path": "kcf_tracker.data",
"tracker_type": "",
"region": {"x": -1, "y": -1, "width": -1, "height": -1, "first-frame": 0}
} )proto";
// Create second tracker
CVTracker kcfTracker_2(proto_data_1, processingController);
// Load tracked data from first tracker protobuf data
kcfTracker_2._LoadTrackedData();
// Get tracked data
FrameData fd_2 = kcfTracker_2.GetTrackedData(20);
float x_2 = fd_2.x1;
float y_2 = fd_2.y1;
float width_2 = fd_2.x2 - x_2;
float height_2 = fd_2.y2 - y_2;
// Compare first tracker data with second tracker data
CHECK_EQUAL((int)(x_1 * 640), (int)(x_2 * 640));
CHECK_EQUAL((int)(y_1 * 360), (int)(y_2 * 360));
CHECK_EQUAL((int)(width_1 * 640), (int)(width_2 * 640));
CHECK_EQUAL((int)(height_1 * 360), (int)(height_2 * 360));
}
} // SUITE(Frame_Tests)

View File

@@ -1,470 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::Cache
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory>
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "CacheDisk.h"
#include "CacheMemory.h"
#include "Json.h"
#include <QDir>
using namespace openshot;
TEST(Cache_Default_Constructor)
{
// Create cache object
CacheMemory c;
// Loop 50 times
for (int i = 0; i < 50; i++)
{
// Add blank frame to the cache
std::shared_ptr<Frame> f(new Frame());
f->number = i;
c.Add(f);
}
CHECK_EQUAL(50, c.Count()); // Cache should have all frames, with no limit
CHECK_EQUAL(0, c.GetMaxBytes()); // Max frames should default to 0
}
TEST(Cache_Max_Bytes_Constructor)
{
// Create cache object (with a max of 5 previous items)
CacheMemory c(250 * 1024);
// Loop 20 times
for (int i = 30; i > 0; i--)
{
// Add blank frame to the cache
std::shared_ptr<Frame> f(new Frame(i, 320, 240, "#000000"));
f->AddColor(320, 240, "#000000");
c.Add(f);
}
// Cache should have all 20
CHECK_EQUAL(20, c.Count());
// Add 10 frames again
for (int i = 10; i > 0; i--)
{
// Add blank frame to the cache
std::shared_ptr<Frame> f(new Frame(i, 320, 240, "#000000"));
f->AddColor(320, 240, "#000000");
c.Add(f);
}
// Count should be 20, since we're more frames than can be cached.
CHECK_EQUAL(20, c.Count());
// Check which items the cache kept
CHECK_EQUAL(true, c.GetFrame(1) != NULL);
CHECK_EQUAL(true, c.GetFrame(10) != NULL);
CHECK_EQUAL(true, c.GetFrame(11) != NULL);
CHECK_EQUAL(true, c.GetFrame(19) != NULL);
CHECK_EQUAL(true, c.GetFrame(20) != NULL);
CHECK_EQUAL(false, c.GetFrame(21) != NULL);
CHECK_EQUAL(false, c.GetFrame(30) != NULL);
}
TEST(Cache_Clear)
{
// Create cache object
CacheMemory c(250 * 1024);
// Loop 10 times
for (int i = 0; i < 10; i++)
{
// Add blank frame to the cache
std::shared_ptr<Frame> f(new Frame());
f->number = i;
c.Add(f);
}
// Cache should only have 10 items
CHECK_EQUAL(10, c.Count());
// Clear Cache
c.Clear();
// Cache should now have 0 items
CHECK_EQUAL(0, c.Count());
}
TEST(Cache_Add_Duplicate_Frames)
{
// Create cache object
CacheMemory c(250 * 1024);
// Loop 10 times
for (int i = 0; i < 10; i++)
{
// Add blank frame to the cache (each frame is #1)
std::shared_ptr<Frame> f(new Frame());
c.Add(f);
}
// Cache should only have 1 items (since all frames were frame #1)
CHECK_EQUAL(1, c.Count());
}
TEST(Cache_Check_If_Frame_Exists)
{
// Create cache object
CacheMemory c(250 * 1024);
// Loop 5 times
for (int i = 1; i < 6; i++)
{
// Add blank frame to the cache
std::shared_ptr<Frame> f(new Frame());
f->number = i;
c.Add(f);
}
// Check if certain frames exists (only 1-5 exist)
CHECK_EQUAL(false, c.GetFrame(0) != NULL);
CHECK_EQUAL(true, c.GetFrame(1) != NULL);
CHECK_EQUAL(true, c.GetFrame(2) != NULL);
CHECK_EQUAL(true, c.GetFrame(3) != NULL);
CHECK_EQUAL(true, c.GetFrame(4) != NULL);
CHECK_EQUAL(true, c.GetFrame(5) != NULL);
CHECK_EQUAL(false, c.GetFrame(6) != NULL);
}
TEST(Cache_GetFrame)
{
// Create cache object
CacheMemory c(250 * 1024);
// Create 3 frames
Frame *red = new Frame(1, 300, 300, "red");
Frame *blue = new Frame(2, 400, 400, "blue");
Frame *green = new Frame(3, 500, 500, "green");
// Add frames to cache
c.Add(std::shared_ptr<Frame>(red));
c.Add(std::shared_ptr<Frame>(blue));
c.Add(std::shared_ptr<Frame>(green));
// Get frames
CHECK_EQUAL(true, c.GetFrame(0) == NULL);
CHECK_EQUAL(true, c.GetFrame(4) == NULL);
// Check if certain frames exists (only 1-5 exist)
CHECK_EQUAL(1, c.GetFrame(1)->number);
CHECK_EQUAL(2, c.GetFrame(2)->number);
CHECK_EQUAL(3, c.GetFrame(3)->number);
}
TEST(Cache_GetSmallest)
{
// Create cache object (with a max of 10 items)
CacheMemory c(250 * 1024);
// Create 3 frames
Frame *red = new Frame(1, 300, 300, "red");
Frame *blue = new Frame(2, 400, 400, "blue");
Frame *green = new Frame(3, 500, 500, "green");
// Add frames to cache
c.Add(std::shared_ptr<Frame>(red));
c.Add(std::shared_ptr<Frame>(blue));
c.Add(std::shared_ptr<Frame>(green));
// Check if frame 1 is the front
CHECK_EQUAL(1, c.GetSmallestFrame()->number);
// Check if frame 1 is STILL the front
CHECK_EQUAL(1, c.GetSmallestFrame()->number);
// Erase frame 1
c.Remove(1);
// Check if frame 2 is the front
CHECK_EQUAL(2, c.GetSmallestFrame()->number);
}
TEST(Cache_Remove)
{
// Create cache object (with a max of 10 items)
CacheMemory c(250 * 1024);
// Create 3 frames
Frame *red = new Frame(1, 300, 300, "red");
Frame *blue = new Frame(2, 400, 400, "blue");
Frame *green = new Frame(3, 500, 500, "green");
// Add frames to cache
c.Add(std::shared_ptr<Frame>(red));
c.Add(std::shared_ptr<Frame>(blue));
c.Add(std::shared_ptr<Frame>(green));
// Check if count is 3
CHECK_EQUAL(3, c.Count());
// Check if frame 2 exists
CHECK_EQUAL(true, c.GetFrame(2) != NULL);
// Remove frame 2
c.Remove(2);
// Check if frame 2 exists
CHECK_EQUAL(false, c.GetFrame(2) != NULL);
// Check if count is 2
CHECK_EQUAL(2, c.Count());
// Remove frame 1
c.Remove(1);
// Check if frame 1 exists
CHECK_EQUAL(false, c.GetFrame(1) != NULL);
// Check if count is 1
CHECK_EQUAL(1, c.Count());
}
TEST(Cache_Set_Max_Bytes)
{
// Create cache object
CacheMemory c;
// Loop 20 times
for (int i = 0; i < 20; i++)
{
// Add blank frame to the cache
std::shared_ptr<Frame> f(new Frame());
f->number = i;
c.Add(f);
}
CHECK_EQUAL(0, c.GetMaxBytes()); // Cache defaults max frames to -1, unlimited frames
// Set max frames
c.SetMaxBytes(8 * 1024);
CHECK_EQUAL(8 * 1024, c.GetMaxBytes());
// Set max frames
c.SetMaxBytes(4 * 1024);
CHECK_EQUAL(4 * 1024, c.GetMaxBytes());
}
TEST(Cache_Multiple_Remove)
{
// Create cache object (using platform /temp/ directory)
CacheMemory c;
// Add frames to disk cache
for (int i = 1; i <= 20; i++)
{
// Add blank frame to the cache
std::shared_ptr<Frame> f(new Frame());
f->number = i;
// Add some picture data
f->AddColor(1280, 720, "Blue");
f->ResizeAudio(2, 500, 44100, LAYOUT_STEREO);
f->AddAudioSilence(500);
c.Add(f);
}
// Should have 20 frames
CHECK_EQUAL(20, c.Count());
// Remove all 20 frames
c.Remove(1, 20);
// Should have 20 frames
CHECK_EQUAL(0, c.Count());
}
TEST(CacheDisk_Set_Max_Bytes)
{
// Create cache object (using platform /temp/ directory)
CacheDisk c("", "PPM", 1.0, 0.25);
// Add frames to disk cache
for (int i = 0; i < 20; i++)
{
// Add blank frame to the cache
std::shared_ptr<Frame> f(new Frame());
f->number = i;
// Add some picture data
f->AddColor(1280, 720, "Blue");
f->ResizeAudio(2, 500, 44100, LAYOUT_STEREO);
f->AddAudioSilence(500);
c.Add(f);
}
CHECK_EQUAL(0, c.GetMaxBytes()); // Cache defaults max frames to -1, unlimited frames
// Set max frames
c.SetMaxBytes(8 * 1024);
CHECK_EQUAL(8 * 1024, c.GetMaxBytes());
// Set max frames
c.SetMaxBytes(4 * 1024);
CHECK_EQUAL(4 * 1024, c.GetMaxBytes());
// Read frames from disk cache
std::shared_ptr<Frame> f = c.GetFrame(5);
CHECK_EQUAL(320, f->GetWidth());
CHECK_EQUAL(180, f->GetHeight());
CHECK_EQUAL(2, f->GetAudioChannelsCount());
CHECK_EQUAL(500, f->GetAudioSamplesCount());
CHECK_EQUAL(LAYOUT_STEREO, f->ChannelsLayout());
CHECK_EQUAL(44100, f->SampleRate());
// Check count of cache
CHECK_EQUAL(20, c.Count());
// Clear cache
c.Clear();
// Check count of cache
CHECK_EQUAL(0, c.Count());
// Delete cache directory
QDir path = QDir::tempPath() + QString("/preview-cache/");
path.removeRecursively();
}
TEST(CacheDisk_Multiple_Remove)
{
// Create cache object (using platform /temp/ directory)
CacheDisk c("", "PPM", 1.0, 0.25);
// Add frames to disk cache
for (int i = 1; i <= 20; i++)
{
// Add blank frame to the cache
std::shared_ptr<Frame> f(new Frame());
f->number = i;
// Add some picture data
f->AddColor(1280, 720, "Blue");
f->ResizeAudio(2, 500, 44100, LAYOUT_STEREO);
f->AddAudioSilence(500);
c.Add(f);
}
// Should have 20 frames
CHECK_EQUAL(20, c.Count());
// Remove all 20 frames
c.Remove(1, 20);
// Should have 20 frames
CHECK_EQUAL(0, c.Count());
// Delete cache directory
QDir path = QDir::tempPath() + QString("/preview-cache/");
path.removeRecursively();
}
TEST(CacheDisk_JSON)
{
// Create cache object (using platform /temp/ directory)
CacheDisk c("", "PPM", 1.0, 0.25);
// Add some frames (out of order)
std::shared_ptr<Frame> f3(new Frame(3, 1280, 720, "Blue", 500, 2));
c.Add(f3);
CHECK_EQUAL(1, (int)c.JsonValue()["ranges"].size());
CHECK_EQUAL("1", c.JsonValue()["version"].asString());
// Add some frames (out of order)
std::shared_ptr<Frame> f1(new Frame(1, 1280, 720, "Blue", 500, 2));
c.Add(f1);
CHECK_EQUAL(2, (int)c.JsonValue()["ranges"].size());
CHECK_EQUAL("2", c.JsonValue()["version"].asString());
// Add some frames (out of order)
std::shared_ptr<Frame> f2(new Frame(2, 1280, 720, "Blue", 500, 2));
c.Add(f2);
CHECK_EQUAL(1, (int)c.JsonValue()["ranges"].size());
CHECK_EQUAL("3", c.JsonValue()["version"].asString());
// Add some frames (out of order)
std::shared_ptr<Frame> f5(new Frame(5, 1280, 720, "Blue", 500, 2));
c.Add(f5);
CHECK_EQUAL(2, (int)c.JsonValue()["ranges"].size());
CHECK_EQUAL("4", c.JsonValue()["version"].asString());
// Add some frames (out of order)
std::shared_ptr<Frame> f4(new Frame(4, 1280, 720, "Blue", 500, 2));
c.Add(f4);
CHECK_EQUAL(1, (int)c.JsonValue()["ranges"].size());
CHECK_EQUAL("5", c.JsonValue()["version"].asString());
// Delete cache directory
QDir path = QDir::tempPath() + QString("/preview-cache/");
path.removeRecursively();
}
TEST(CacheMemory_JSON)
{
// Create memory cache object
CacheMemory c;
// Add some frames (out of order)
std::shared_ptr<Frame> f3(new Frame(3, 1280, 720, "Blue", 500, 2));
c.Add(f3);
CHECK_EQUAL(1, (int)c.JsonValue()["ranges"].size());
CHECK_EQUAL("1", c.JsonValue()["version"].asString());
// Add some frames (out of order)
std::shared_ptr<Frame> f1(new Frame(1, 1280, 720, "Blue", 500, 2));
c.Add(f1);
CHECK_EQUAL(2, (int)c.JsonValue()["ranges"].size());
CHECK_EQUAL("2", c.JsonValue()["version"].asString());
// Add some frames (out of order)
std::shared_ptr<Frame> f2(new Frame(2, 1280, 720, "Blue", 500, 2));
c.Add(f2);
CHECK_EQUAL(1, (int)c.JsonValue()["ranges"].size());
CHECK_EQUAL("3", c.JsonValue()["version"].asString());
// Add some frames (out of order)
std::shared_ptr<Frame> f5(new Frame(5, 1280, 720, "Blue", 500, 2));
c.Add(f5);
CHECK_EQUAL(2, (int)c.JsonValue()["ranges"].size());
CHECK_EQUAL("4", c.JsonValue()["version"].asString());
// Add some frames (out of order)
std::shared_ptr<Frame> f4(new Frame(4, 1280, 720, "Blue", 500, 2));
c.Add(f4);
CHECK_EQUAL(1, (int)c.JsonValue()["ranges"].size());
CHECK_EQUAL("5", c.JsonValue()["version"].asString());
}

View File

@@ -1,264 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::Clip
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <memory>
#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 "Clip.h"
#include "Frame.h"
#include "Fraction.h"
#include "Timeline.h"
#include "Json.h"
using namespace openshot;
SUITE(Clip)
{
TEST(Default_Constructor)
{
// Create a empty clip
Clip c1;
// Check basic settings
CHECK_EQUAL(ANCHOR_CANVAS, c1.anchor);
CHECK_EQUAL(GRAVITY_CENTER, c1.gravity);
CHECK_EQUAL(SCALE_FIT, c1.scale);
CHECK_EQUAL(0, c1.Layer());
CHECK_CLOSE(0.0f, c1.Position(), 0.00001);
CHECK_CLOSE(0.0f, c1.Start(), 0.00001);
CHECK_CLOSE(0.0f, c1.End(), 0.00001);
}
TEST(Clip_Constructor)
{
// Create a empty clip
std::stringstream path;
path << TEST_MEDIA_PATH << "piano.wav";
Clip c1(path.str());
c1.Open();
// Check basic settings
CHECK_EQUAL(ANCHOR_CANVAS, c1.anchor);
CHECK_EQUAL(GRAVITY_CENTER, c1.gravity);
CHECK_EQUAL(SCALE_FIT, c1.scale);
CHECK_EQUAL(0, c1.Layer());
CHECK_CLOSE(0.0f, c1.Position(), 0.00001);
CHECK_CLOSE(0.0f, c1.Start(), 0.00001);
CHECK_CLOSE(4.39937f, c1.End(), 0.00001);
}
TEST(Basic_Gettings_and_Setters)
{
// Create a empty clip
Clip c1;
// Check basic settings
CHECK_THROW(c1.Open(), ReaderClosed);
CHECK_EQUAL(ANCHOR_CANVAS, c1.anchor);
CHECK_EQUAL(GRAVITY_CENTER, c1.gravity);
CHECK_EQUAL(SCALE_FIT, c1.scale);
CHECK_EQUAL(0, c1.Layer());
CHECK_CLOSE(0.0f, c1.Position(), 0.00001);
CHECK_CLOSE(0.0f, c1.Start(), 0.00001);
CHECK_CLOSE(0.0f, c1.End(), 0.00001);
// Change some properties
c1.Layer(1);
c1.Position(5.0);
c1.Start(3.5);
c1.End(10.5);
CHECK_EQUAL(1, c1.Layer());
CHECK_CLOSE(5.0f, c1.Position(), 0.00001);
CHECK_CLOSE(3.5f, c1.Start(), 0.00001);
CHECK_CLOSE(10.5f, c1.End(), 0.00001);
}
TEST(Properties)
{
// Create a empty clip
Clip c1;
// Change some properties
c1.Layer(1);
c1.Position(5.0);
c1.Start(3.5);
c1.End(10.5);
c1.alpha.AddPoint(1, 1.0);
c1.alpha.AddPoint(500, 0.0);
// Get properties JSON string at frame 1
std::string properties = c1.PropertiesJSON(1);
// Parse JSON string into JSON objects
Json::Value root;
Json::CharReaderBuilder rbuilder;
Json::CharReader* reader(rbuilder.newCharReader());
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 );
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);
// Parse JSON string into JSON objects
root.clear();
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 );
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(Effects)
{
// Load clip with video
std::stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
Clip c10(path.str());
c10.Open();
Negate n;
c10.AddEffect(&n);
// Get frame 1
std::shared_ptr<Frame> f = c10.GetFrame(500);
// Get the image data
const unsigned char* pixels = f->GetPixels(10);
int pixel_index = 112 * 4; // pixel 112 (4 bytes per pixel)
// Check image properties on scanline 10, pixel 112
CHECK_EQUAL(255, (int)pixels[pixel_index]);
CHECK_EQUAL(255, (int)pixels[pixel_index + 1]);
CHECK_EQUAL(255, (int)pixels[pixel_index + 2]);
CHECK_EQUAL(255, (int)pixels[pixel_index + 3]);
// Check the # of Effects
CHECK_EQUAL(1, (int)c10.Effects().size());
// Add a 2nd negate effect
Negate n1;
c10.AddEffect(&n1);
// Get frame 1
f = c10.GetFrame(500);
// Get the image data
pixels = f->GetPixels(10);
pixel_index = 112 * 4; // pixel 112 (4 bytes per pixel)
// Check image properties on scanline 10, pixel 112
CHECK_EQUAL(0, (int)pixels[pixel_index]);
CHECK_EQUAL(0, (int)pixels[pixel_index + 1]);
CHECK_EQUAL(0, (int)pixels[pixel_index + 2]);
CHECK_EQUAL(255, (int)pixels[pixel_index + 3]);
// Check the # of Effects
CHECK_EQUAL(2, (int)c10.Effects().size());
}
TEST(Verify_Parent_Timeline)
{
Timeline t1(640, 480, Fraction(30,1), 44100, 2, LAYOUT_STEREO);
// Load clip with video
std::stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
Clip c1(path.str());
c1.Open();
// Check size of frame image
CHECK_EQUAL(c1.GetFrame(1)->GetImage()->width(), 1280);
CHECK_EQUAL(c1.GetFrame(1)->GetImage()->height(), 720);
// Add clip to timeline
t1.AddClip(&c1);
// Check size of frame image (with an associated timeline)
CHECK_EQUAL(c1.GetFrame(1)->GetImage()->width(), 640);
CHECK_EQUAL(c1.GetFrame(1)->GetImage()->height(), 360);
}
} // SUITE

View File

@@ -1,186 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::Color
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string>
#include <vector>
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "Color.h"
#include "Exceptions.h"
#include "KeyFrame.h"
#include "Json.h"
SUITE(Color) {
TEST(Default_Constructor)
{
// Create an empty color
openshot::Color c1;
CHECK_CLOSE(0.0f, c1.red.GetValue(0), 0.00001);
CHECK_CLOSE(0.0f, c1.green.GetValue(0), 0.00001);
CHECK_CLOSE(0.0f, c1.blue.GetValue(0), 0.00001);
}
TEST(Keyframe_constructor)
{
std::vector<openshot::Keyframe> kfs{0, 0, 0, 0};
int64_t i(0);
for (auto& kf : kfs) {
kf.AddPoint(100, ++i * 20);
}
auto c = openshot::Color(kfs[0], kfs[1], kfs[2], kfs[3]);
CHECK_CLOSE(20, c.red.GetLong(100), 0.01);
CHECK_CLOSE(40, c.green.GetLong(100), 0.01);
CHECK_CLOSE(60, c.blue.GetLong(100), 0.01);
CHECK_CLOSE(80, c.alpha.GetLong(100), 0.01);
}
TEST(Animate_Colors)
{
// Create an empty color
openshot::Color c1;
// Set starting color (on frame 0)
c1.red.AddPoint(1, 0);
c1.green.AddPoint(1, 120);
c1.blue.AddPoint(1, 255);
// Set ending color (on frame 1000)
c1.red.AddPoint(1000, 0);
c1.green.AddPoint(1000, 255);
c1.blue.AddPoint(1000, 65);
// Check the color at frame 500
CHECK_CLOSE(0, c1.red.GetLong(500), 0.01);
CHECK_CLOSE(187, c1.green.GetLong(500), 0.01);
CHECK_CLOSE(160, c1.blue.GetLong(500), 0.01);
}
TEST(HEX_Value)
{
// Color
openshot::Color c;
c.red = openshot::Keyframe(0);
c.red.AddPoint(100, 255);
c.green = openshot::Keyframe(0);
c.green.AddPoint(100, 255);
c.blue = openshot::Keyframe(0);
c.blue.AddPoint(100, 255);
CHECK_EQUAL("#000000", c.GetColorHex(1));
CHECK_EQUAL("#7d7d7d", c.GetColorHex(50));
CHECK_EQUAL("#ffffff", c.GetColorHex(100));
}
TEST(HEX_Constructor)
{
// Color
openshot::Color c("#4586db");
c.red.AddPoint(100, 255);
c.green.AddPoint(100, 255);
c.blue.AddPoint(100, 255);
CHECK_EQUAL("#4586db", c.GetColorHex(1));
CHECK_EQUAL("#a0c1ed", c.GetColorHex(50));
CHECK_EQUAL("#ffffff", c.GetColorHex(100));
}
TEST(Distance)
{
// Color
openshot::Color c1("#040a0c");
openshot::Color c2("#0c0c04");
openshot::Color c3("#000000");
openshot::Color c4("#ffffff");
CHECK_CLOSE(19.0f, openshot::Color::GetDistance(c1.red.GetInt(1), c1.blue.GetInt(1), c1.green.GetInt(1), c2.red.GetInt(1), c2.blue.GetInt(1), c2.green.GetInt(1)), 0.001);
CHECK_CLOSE(764.0f, openshot::Color::GetDistance(c3.red.GetInt(1), c3.blue.GetInt(1), c3.green.GetInt(1), c4.red.GetInt(1), c4.blue.GetInt(1), c4.green.GetInt(1)), 0.001);
}
TEST(RGBA_Constructor)
{
// Color
openshot::Color c(69, 134, 219, 255);
c.red.AddPoint(100, 255);
c.green.AddPoint(100, 255);
c.blue.AddPoint(100, 255);
CHECK_EQUAL("#4586db", c.GetColorHex(1));
CHECK_EQUAL("#a0c1ed", c.GetColorHex(50));
CHECK_EQUAL("#ffffff", c.GetColorHex(100));
// Color with alpha
openshot::Color c1(69, 134, 219, 128);
CHECK_EQUAL("#4586db", c1.GetColorHex(1));
CHECK_EQUAL(128, c1.alpha.GetInt(1));
}
TEST(Json)
{
openshot::Color c(128, 128, 128, 0);
openshot::Color c1;
c1.red.AddPoint(1, 128);
c1.green.AddPoint(1, 128);
c1.blue.AddPoint(1, 128);
c1.alpha.AddPoint(1, 0);
// Check that JSON produced is identical
auto j = c.Json();
auto j1 = c1.Json();
CHECK_EQUAL(j, j1);
// Check Json::Value representation
auto jv = c.JsonValue();
auto jv_string = jv.toStyledString();
CHECK_EQUAL(jv_string, j1);
}
TEST(SetJson) {
const std::string json_input = R"json(
{
"red": { "Points": [ { "co": { "X": 1.0, "Y": 0.0 }, "interpolation": 0 } ] },
"green": { "Points": [ { "co": { "X": 1.0, "Y": 128.0 }, "interpolation": 0 } ] },
"blue": { "Points": [ { "co": { "X": 1.0, "Y": 64.0 }, "interpolation": 0 } ] },
"alpha": { "Points": [ { "co": { "X": 1.0, "Y": 192.0 }, "interpolation": 0 } ] }
}
)json";
openshot::Color c;
CHECK_THROW(c.SetJson("}{"), openshot::InvalidJSON);
c.SetJson(json_input);
CHECK_CLOSE(0, c.red.GetLong(10), 0.01);
CHECK_CLOSE(128, c.green.GetLong(10), 0.01);
CHECK_CLOSE(64, c.blue.GetLong(10), 0.01);
CHECK_CLOSE(192, c.alpha.GetLong(10), 0.01);
}
} // SUITE

View File

@@ -1,99 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::Coordinate
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "Coordinate.h"
#include "Exceptions.h"
using namespace openshot;
SUITE(Coordinate)
{
TEST(Default_Constructor)
{
// Create an empty coordinate
Coordinate c1;
CHECK_CLOSE(0.0f, c1.X, 0.00001);
CHECK_CLOSE(0.0f, c1.Y, 0.00001);
}
TEST(X_Y_Constructor)
{
// Create an empty coordinate
Coordinate c1(2,8);
CHECK_CLOSE(2.0f, c1.X, 0.00001);
CHECK_CLOSE(8.0f, c1.Y, 0.00001);
}
TEST(Pair_Constructor)
{
Coordinate c1(std::pair<double,double>(12, 10));
CHECK_CLOSE(12.0f, c1.X, 0.00001);
CHECK_CLOSE(10.0f, c1.Y, 0.00001);
}
TEST(Json)
{
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();
CHECK_EQUAL(j, j1);
// Check Json::Value representation
auto jv = c.JsonValue();
auto jv_string = jv.toStyledString();
CHECK_EQUAL(jv_string, j1);
}
TEST(SetJson) {
// Construct our input Json representation
const std::string json_input = R"json(
{
"X": 100.0,
"Y": 50.0
}
)json";
openshot::Coordinate c;
CHECK_THROW(c.SetJson("}{"), openshot::InvalidJSON);
// Check that values set via SetJson() are correct
c.SetJson(json_input);
CHECK_CLOSE(100.0, c.X, 0.01);
CHECK_CLOSE(50.0, c.Y, 0.01);
}
} // SUITE

View File

@@ -1,192 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::DummyReader
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory>
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "DummyReader.h"
#include "Exceptions.h"
#include "CacheMemory.h"
#include "Fraction.h"
#include "Frame.h"
SUITE (DummyReader) {
TEST (Default_Constructor) {
openshot::DummyReader r;
CHECK_EQUAL(false, r.IsOpen());
CHECK_THROW(r.GetFrame(1), openshot::ReaderClosed);
r.Open();
// Default values
CHECK_EQUAL(1280, r.info.width);
CHECK_EQUAL(768, r.info.height);
CHECK_EQUAL(24, r.info.fps.num);
CHECK_EQUAL(1, r.info.fps.den);
CHECK_EQUAL(44100, r.info.sample_rate);
CHECK_EQUAL(2, r.info.channels);
CHECK_EQUAL(30.0, r.info.duration);
CHECK_EQUAL("DummyReader", r.Name());
auto cache = r.GetCache();
CHECK_EQUAL(true, cache == nullptr);
}
TEST (Constructor) {
openshot::DummyReader r(openshot::Fraction(30, 1), 1920, 1080, 48000, 2, 60.0);
r.Open();
// Check values
CHECK_EQUAL(1920, r.info.width);
CHECK_EQUAL(1080, r.info.height);
CHECK_EQUAL(30, r.info.fps.num);
CHECK_EQUAL(1, r.info.fps.den);
CHECK_EQUAL(48000, r.info.sample_rate);
CHECK_EQUAL(2, r.info.channels);
CHECK_EQUAL(60.0, r.info.duration);
}
TEST (Blank_Frame) {
openshot::DummyReader r(openshot::Fraction(30, 1), 1920, 1080, 44100, 2, 30.0);
r.Open();
// Get a blank frame (because we have not passed a Cache object (full of Frame objects) to the constructor
// Check values
CHECK_EQUAL(1, r.GetFrame(1)->number);
CHECK_EQUAL(1, r.GetFrame(1)->GetPixels(700)[700] == 0); // black pixel
CHECK_EQUAL(1, r.GetFrame(1)->GetPixels(701)[701] == 0); // black pixel
}
TEST (Fake_Frame) {
// Create cache object to hold test frames
openshot::CacheMemory cache;
// Let's create some test frames
for (int64_t frame_number = 1; frame_number <= 30; frame_number++) {
// Create blank frame (with specific frame #, samples, and channels)
// Sample count should be 44100 / 30 fps = 1470 samples per frame
int sample_count = 1470;
auto f = std::make_shared<openshot::Frame>(frame_number, sample_count, 2);
// Create test samples with incrementing value
float *audio_buffer = new float[sample_count];
for (int64_t sample_number = 0; sample_number < sample_count; sample_number++) {
// Generate an incrementing audio sample value (just as an example)
audio_buffer[sample_number] = float(frame_number) + (float(sample_number) / float(sample_count));
}
// Add custom audio samples to Frame (bool replaceSamples, int destChannel, int destStartSample, const float* source,
f->AddAudio(true, 0, 0, audio_buffer, sample_count, 1.0); // add channel 1
f->AddAudio(true, 1, 0, audio_buffer, sample_count, 1.0); // add channel 2
// Add test frame to dummy reader
cache.Add(f);
}
openshot::DummyReader r(openshot::Fraction(30, 1), 1920, 1080, 44100, 2, 30.0, &cache);
r.Open();
// Verify our artificial audio sample data is correct
CHECK_EQUAL(1, r.GetFrame(1)->number);
CHECK_EQUAL(1, r.GetFrame(1)->GetAudioSamples(0)[0]);
CHECK_CLOSE(1.00068033, r.GetFrame(1)->GetAudioSamples(0)[1], 0.00001);
CHECK_CLOSE(1.00136054, r.GetFrame(1)->GetAudioSamples(0)[2], 0.00001);
CHECK_EQUAL(2, r.GetFrame(2)->GetAudioSamples(0)[0]);
CHECK_CLOSE(2.00068033, r.GetFrame(2)->GetAudioSamples(0)[1], 0.00001);
CHECK_CLOSE(2.00136054, r.GetFrame(2)->GetAudioSamples(0)[2], 0.00001);
// Clean up
cache.Clear();
r.Close();
}
TEST (Invalid_Fake_Frame) {
// Create fake frames (with specific frame #, samples, and channels)
auto f1 = std::make_shared<openshot::Frame>(1, 1470, 2);
auto f2 = std::make_shared<openshot::Frame>(2, 1470, 2);
// Add test frames to cache object
openshot::CacheMemory cache;
cache.Add(f1);
cache.Add(f2);
openshot::DummyReader r(openshot::Fraction(30, 1), 1920, 1080, 44100, 2, 30.0, &cache);
r.Open();
// Verify exception
CHECK_EQUAL(1, r.GetFrame(1)->number);
CHECK_EQUAL(2, r.GetFrame(2)->number);
CHECK_THROW(r.GetFrame(3)->number, openshot::InvalidFile);
// Clean up
cache.Clear();
r.Close();
}
TEST(Json)
{
openshot::DummyReader r1;
openshot::DummyReader r2(openshot::Fraction(24, 1), 1280, 768, 44100, 2, 30.0);
auto json1 = r1.Json();
auto json2 = r2.JsonValue();
auto json_string2 = json2.toStyledString();
CHECK_EQUAL(json1, json_string2);
}
TEST(SetJson)
{
openshot::DummyReader r1;
std::stringstream json_stream;
json_stream << R"json(
{
"width": 1920,
"height": 1080,
"fps": { "num": 15, "den": 1 },
"duration": 15.0
}
)json";
r1.SetJson(json_stream.str());
CHECK_EQUAL(1920, r1.info.width);
CHECK_EQUAL(1080, r1.info.height);
CHECK_EQUAL(15, r1.info.fps.num);
CHECK_EQUAL(1, r1.info.fps.den);
CHECK_EQUAL(15.0, r1.info.duration);
}
} // SUITE

View File

@@ -1,281 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::FFmpegReader
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <memory>
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "FFmpegReader.h"
#include "Exceptions.h"
#include "Frame.h"
#include "Timeline.h"
#include "Json.h"
using namespace std;
using namespace openshot;
SUITE(FFmpegReader)
{
TEST(Invalid_Path)
{
// Check invalid path
CHECK_THROW(FFmpegReader(""), InvalidFile);
}
TEST(GetFrame_Before_Opening)
{
// Create a reader
stringstream path;
path << TEST_MEDIA_PATH << "piano.wav";
FFmpegReader r(path.str());
// Check invalid path
CHECK_THROW(r.GetFrame(1), ReaderClosed);
}
TEST(Check_Audio_File)
{
// Create a reader
stringstream path;
path << TEST_MEDIA_PATH << "piano.wav";
FFmpegReader r(path.str());
r.Open();
// Get frame 1
std::shared_ptr<Frame> f = r.GetFrame(1);
// Get the number of channels and samples
float *samples = f->GetAudioSamples(0);
// Check audio properties
CHECK_EQUAL(2, f->GetAudioChannelsCount());
CHECK_EQUAL(332, f->GetAudioSamplesCount());
// Check actual sample values (to be sure the waveform is correct)
CHECK_CLOSE(0.0f, samples[0], 0.00001);
CHECK_CLOSE(0.0f, samples[50], 0.00001);
CHECK_CLOSE(0.0f, samples[100], 0.00001);
CHECK_CLOSE(0.0f, samples[200], 0.00001);
CHECK_CLOSE(0.16406f, samples[230], 0.00001);
CHECK_CLOSE(-0.06250f, samples[300], 0.00001);
// Close reader
r.Close();
}
TEST(Check_Video_File)
{
// Create a reader
stringstream path;
path << TEST_MEDIA_PATH << "test.mp4";
FFmpegReader r(path.str());
r.Open();
// Get frame 1
std::shared_ptr<Frame> f = r.GetFrame(1);
// Get the image data
const unsigned char* pixels = f->GetPixels(10);
int pixel_index = 112 * 4; // pixel 112 (4 bytes per pixel)
// Check image properties on scanline 10, pixel 112
CHECK_CLOSE(21, (int)pixels[pixel_index], 5);
CHECK_CLOSE(191, (int)pixels[pixel_index + 1], 5);
CHECK_CLOSE(0, (int)pixels[pixel_index + 2], 5);
CHECK_CLOSE(255, (int)pixels[pixel_index + 3], 5);
// Check pixel function
CHECK_EQUAL(true, f->CheckPixel(10, 112, 21, 191, 0, 255, 5));
CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0, 5));
// Get frame 1
f = r.GetFrame(2);
// Get the next frame
pixels = f->GetPixels(10);
pixel_index = 112 * 4; // pixel 112 (4 bytes per pixel)
// Check image properties on scanline 10, pixel 112
CHECK_CLOSE(0, (int)pixels[pixel_index], 5);
CHECK_CLOSE(96, (int)pixels[pixel_index + 1], 5);
CHECK_CLOSE(188, (int)pixels[pixel_index + 2], 5);
CHECK_CLOSE(255, (int)pixels[pixel_index + 3], 5);
// Check pixel function
CHECK_EQUAL(true, f->CheckPixel(10, 112, 0, 96, 188, 255, 5));
CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0, 5));
// Close reader
r.Close();
}
TEST(Seek)
{
// Create a reader
stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
FFmpegReader r(path.str());
r.Open();
// Get frame
std::shared_ptr<Frame> f = r.GetFrame(1);
CHECK_EQUAL(1, f->number);
// Get frame
f = r.GetFrame(300);
CHECK_EQUAL(300, f->number);
// Get frame
f = r.GetFrame(301);
CHECK_EQUAL(301, f->number);
// Get frame
f = r.GetFrame(315);
CHECK_EQUAL(315, f->number);
// Get frame
f = r.GetFrame(275);
CHECK_EQUAL(275, f->number);
// Get frame
f = r.GetFrame(270);
CHECK_EQUAL(270, f->number);
// Get frame
f = r.GetFrame(500);
CHECK_EQUAL(500, f->number);
// Get frame
f = r.GetFrame(100);
CHECK_EQUAL(100, f->number);
// Get frame
f = r.GetFrame(600);
CHECK_EQUAL(600, f->number);
// Get frame
f = r.GetFrame(1);
CHECK_EQUAL(1, f->number);
// Get frame
f = r.GetFrame(700);
CHECK_EQUAL(700, f->number);
// Close reader
r.Close();
}
TEST(Frame_Rate)
{
// Create a reader
stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
FFmpegReader r(path.str());
r.Open();
// Verify detected frame rate
openshot::Fraction rate = r.info.fps;
CHECK_EQUAL(24, rate.num);
CHECK_EQUAL(1, rate.den);
r.Close();
}
TEST(Multiple_Open_and_Close)
{
// Create a reader
stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
FFmpegReader r(path.str());
r.Open();
// Get frame that requires a seek
std::shared_ptr<Frame> f = r.GetFrame(1200);
CHECK_EQUAL(1200, f->number);
// Close and Re-open the reader
r.Close();
r.Open();
// Get frame
f = r.GetFrame(1);
CHECK_EQUAL(1, f->number);
f = r.GetFrame(250);
CHECK_EQUAL(250, f->number);
// Close and Re-open the reader
r.Close();
r.Open();
// Get frame
f = r.GetFrame(750);
CHECK_EQUAL(750, f->number);
f = r.GetFrame(1000);
CHECK_EQUAL(1000, f->number);
// Close reader
r.Close();
}
TEST(Verify_Parent_Timeline)
{
// Create a reader
stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
FFmpegReader r(path.str());
r.Open();
// Check size of frame image
CHECK_EQUAL(r.GetFrame(1)->GetImage()->width(), 1280);
CHECK_EQUAL(r.GetFrame(1)->GetImage()->height(), 720);
r.GetFrame(1)->GetImage()->save("reader-1.png", "PNG");
// Create a Clip associated with this reader
Clip c1(&r);
c1.Open();
// Check size of frame image (should still be the same)
CHECK_EQUAL(r.GetFrame(1)->GetImage()->width(), 1280);
CHECK_EQUAL(r.GetFrame(1)->GetImage()->height(), 720);
// Create Timeline
Timeline t1(640, 480, Fraction(30,1), 44100, 2, LAYOUT_STEREO);
t1.AddClip(&c1);
// Check size of frame image (it should now match the parent timeline)
CHECK_EQUAL(r.GetFrame(1)->GetImage()->width(), 640);
CHECK_EQUAL(r.GetFrame(1)->GetImage()->height(), 360);
}
} // SUITE(FFmpegReader)

View File

@@ -1,135 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::FFmpegWriter
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <memory>
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "FFmpegWriter.h"
#include "Exceptions.h"
#include "FFmpegReader.h"
#include "Fraction.h"
#include "Frame.h"
using namespace std;
using namespace openshot;
SUITE(FFMpegWriter) {
TEST(Webm)
{
// Reader
stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
FFmpegReader r(path.str());
r.Open();
/* WRITER ---------------- */
FFmpegWriter w("output1.webm");
// Set options
w.SetAudioOptions(true, "libvorbis", 44100, 2, LAYOUT_STEREO, 188000);
w.SetVideoOptions(true, "libvpx", Fraction(24,1), 1280, 720, Fraction(1,1), false, false, 30000000);
// Open writer
w.Open();
// Write some frames
w.WriteFrame(&r, 24, 50);
// Close writer & reader
w.Close();
r.Close();
FFmpegReader r1("output1.webm");
r1.Open();
// Verify various settings on new MP4
CHECK_EQUAL(2, r1.GetFrame(1)->GetAudioChannelsCount());
CHECK_EQUAL(24, r1.info.fps.num);
CHECK_EQUAL(1, r1.info.fps.den);
// Get a specific frame
std::shared_ptr<Frame> f = r1.GetFrame(8);
// Get the image data for row 500
const unsigned char* pixels = f->GetPixels(500);
int pixel_index = 112 * 4; // pixel 112 (4 bytes per pixel)
// Check image properties on scanline 10, pixel 112
CHECK_CLOSE(23, (int)pixels[pixel_index], 5);
CHECK_CLOSE(23, (int)pixels[pixel_index + 1], 5);
CHECK_CLOSE(23, (int)pixels[pixel_index + 2], 5);
CHECK_CLOSE(255, (int)pixels[pixel_index + 3], 5);
}
TEST(Options_Overloads)
{
// Reader
stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
FFmpegReader r(path.str());
r.Open();
/* WRITER ---------------- */
FFmpegWriter w("output1.mp4");
// Set options
w.SetAudioOptions("aac", 48000, 192000);
w.SetVideoOptions("libx264", 1280, 720, Fraction(30,1), 5000000);
// Open writer
w.Open();
// Write some frames
w.WriteFrame(&r, 24, 50);
// Close writer & reader
w.Close();
r.Close();
FFmpegReader r1("output1.mp4");
r1.Open();
// Verify implied settings
CHECK_EQUAL(true, r1.info.has_audio);
CHECK_EQUAL(true, r1.info.has_video);
CHECK_EQUAL(2, r1.GetFrame(1)->GetAudioChannelsCount());
CHECK_EQUAL(LAYOUT_STEREO, r1.info.channel_layout);
CHECK_EQUAL(1, r1.info.pixel_ratio.num);
CHECK_EQUAL(1, r1.info.pixel_ratio.den);
CHECK_EQUAL(false, r1.info.interlaced_frame);
CHECK_EQUAL(true, r1.info.top_field_first);
}
} // SUITE()

View File

@@ -1,156 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::Fraction
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "Fraction.h"
using namespace std;
using namespace openshot;
SUITE(Fraction)
{
TEST(Constructors)
{
// Create a default fraction (should be 1/1)
Fraction f1;
// Check default fraction
CHECK_EQUAL(1, f1.num);
CHECK_EQUAL(1, f1.den);
CHECK_CLOSE(1.0f, f1.ToFloat(), 0.00001);
CHECK_CLOSE(1.0f, f1.ToDouble(), 0.00001);
// reduce fraction
f1.Reduce();
// Check the reduced fraction
CHECK_EQUAL(1, f1.num);
CHECK_EQUAL(1, f1.den);
CHECK_CLOSE(1.0f, f1.ToFloat(), 0.00001);
CHECK_CLOSE(1.0f, f1.ToDouble(), 0.00001);
}
TEST(Alt_Constructors)
{
// Use the delegating constructor for std::pair
std::pair<int, int> args{24, 1};
Fraction f1(args);
CHECK_EQUAL(24, f1.num);
CHECK_EQUAL(1, f1.den);
CHECK_CLOSE(24.0f, f1.ToFloat(), 0.00001);
// Use the delegating constructor for std::vector
std::vector<int> v{30000, 1001};
Fraction f2(v);
CHECK_CLOSE(30000.0/1001.0, f2.ToFloat(), 0.00001);
// Use the delegating constructor for std::map<std::string, int>
std::map<std::string, int> dict;
dict.insert({"num", 24000});
dict.insert({"den", 1001});
Fraction f3(dict);
CHECK_EQUAL(1001, f3.den);
CHECK_EQUAL(24000, f3.num);
CHECK_CLOSE(1001.0/24000.0, f3.Reciprocal().ToFloat(), 0.00001);
}
TEST(WxH_640_480)
{
// Create fraction
Fraction f1(640, 480);
// Check fraction
CHECK_EQUAL(640, f1.num);
CHECK_EQUAL(480, f1.den);
CHECK_CLOSE(1.33333f, f1.ToFloat(), 0.00001);
CHECK_CLOSE(1.33333f, f1.ToDouble(), 0.00001);
// reduce fraction
f1.Reduce();
// Check the reduced fraction
CHECK_EQUAL(4, f1.num);
CHECK_EQUAL(3, f1.den);
CHECK_CLOSE(1.33333f, f1.ToFloat(), 0.00001);
CHECK_CLOSE(1.33333f, f1.ToDouble(), 0.00001);
}
TEST(WxH_1280_720)
{
// Create fraction
Fraction f1(1280, 720);
// Check fraction
CHECK_EQUAL(1280, f1.num);
CHECK_EQUAL(720, f1.den);
CHECK_CLOSE(1.77777f, f1.ToFloat(), 0.00001);
CHECK_CLOSE(1.77777f, f1.ToDouble(), 0.00001);
// reduce fraction
f1.Reduce();
// Check the reduced fraction
CHECK_EQUAL(16, f1.num);
CHECK_EQUAL(9, f1.den);
CHECK_CLOSE(1.77777f, f1.ToFloat(), 0.00001);
CHECK_CLOSE(1.77777f, f1.ToDouble(), 0.00001);
}
TEST(Reciprocal)
{
// Create fraction
Fraction f1(1280, 720);
// Check fraction
CHECK_EQUAL(1280, f1.num);
CHECK_EQUAL(720, f1.den);
CHECK_CLOSE(1.77777f, f1.ToFloat(), 0.00001);
CHECK_CLOSE(1.77777f, f1.ToDouble(), 0.00001);
// Get the reciprocal of the fraction (i.e. flip the fraction)
Fraction f2 = f1.Reciprocal();
// Check the reduced fraction
CHECK_EQUAL(720, f2.num);
CHECK_EQUAL(1280, f2.den);
CHECK_CLOSE(0.5625f, f2.ToFloat(), 0.00001);
CHECK_CLOSE(0.5625f, f2.ToDouble(), 0.00001);
// Re-Check the original fraction (to be sure it hasn't changed)
CHECK_EQUAL(1280, f1.num);
CHECK_EQUAL(720, f1.den);
CHECK_CLOSE(1.77777f, f1.ToFloat(), 0.00001);
CHECK_CLOSE(1.77777f, f1.ToDouble(), 0.00001);
}
} // SUITE

File diff suppressed because it is too large Load Diff

View File

@@ -1,183 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::Frame
* @author Jonathan Thomas <jonathan@openshot.org>
* @author FeRD (Frank Dana) <ferdnyc@gmail.com>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <memory>
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "Frame.h"
#include "Clip.h"
#include "Fraction.h"
#include <QImage>
#ifdef USE_OPENCV
#include <opencv2/core.hpp>
#endif
using namespace openshot;
SUITE(Frame_Tests)
{
TEST(Default_Constructor)
{
// Create a "blank" default Frame
std::shared_ptr<Frame> f1(new Frame());
CHECK(f1 != nullptr); // Test aborts here if we didn't get a Frame
// Check basic default parameters
CHECK_EQUAL(1, f1->GetHeight());
CHECK_EQUAL(1, f1->GetWidth());
CHECK_EQUAL(44100, f1->SampleRate());
CHECK_EQUAL(2, f1->GetAudioChannelsCount());
// Should be false until we load or create contents
CHECK_EQUAL(false, f1->has_image_data);
CHECK_EQUAL(false, f1->has_audio_data);
// Calling GetImage() paints a blank frame, by default
std::shared_ptr<QImage> i1 = f1->GetImage();
CHECK(i1 != nullptr);
CHECK_EQUAL(true,f1->has_image_data);
CHECK_EQUAL(false,f1->has_audio_data);
}
TEST(Data_Access)
{
// Create a video clip
std::stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
Clip c1(path.str());
c1.Open();
// Get first frame
std::shared_ptr<Frame> f1 = c1.GetFrame(1);
CHECK(f1 != nullptr);
CHECK_EQUAL(1, f1->number);
CHECK_EQUAL(1280, f1->GetWidth());
CHECK_EQUAL(720, f1->GetHeight());
}
TEST(AddImage_QImage)
{
// Create a "blank" default Frame
std::shared_ptr<Frame> f1(new Frame());
// Load an image
std::stringstream path;
path << TEST_MEDIA_PATH << "front.png";
std::shared_ptr<QImage> i1(new QImage(QString::fromStdString(path.str()))) ;
CHECK(f1 != nullptr); // Test aborts here if we didn't get a Frame
CHECK_EQUAL(false, i1->isNull());
f1->AddImage(i1);
// Check loaded image parameters
CHECK_EQUAL(i1->height(), f1->GetHeight());
CHECK_EQUAL(i1->width(), f1->GetWidth());
CHECK_EQUAL(true, f1->has_image_data);
}
TEST(Copy_Constructor)
{
// Create a dummy Frame
openshot::Frame f1(1, 800, 600, "#000000");
// Load an image
std::stringstream path;
path << TEST_MEDIA_PATH << "front.png";
std::shared_ptr<QImage> i1( new QImage(QString::fromStdString(path.str())) );
CHECK_EQUAL(false, i1->isNull());
// Add image to f1, then copy f1 to f2
f1.AddImage(i1);
Frame f2 = f1;
CHECK_EQUAL(f1.GetHeight(), f2.GetHeight());
CHECK_EQUAL(f1.GetWidth(), f2.GetWidth());
CHECK_EQUAL(f1.has_image_data, f2.has_image_data);
CHECK_EQUAL(f1.has_audio_data, f2.has_audio_data);
Fraction par1 = f1.GetPixelRatio();
Fraction par2 = f2.GetPixelRatio();
CHECK_EQUAL(par1.num, par2.num);
CHECK_EQUAL(par1.den, par2.den);
CHECK_EQUAL(f1.SampleRate(), f2.SampleRate());
CHECK_EQUAL(f1.GetAudioChannelsCount(), f2.GetAudioChannelsCount());
CHECK_EQUAL(f1.ChannelsLayout(), f2.ChannelsLayout());
CHECK_EQUAL(f1.GetBytes(), f2.GetBytes());
CHECK_EQUAL(f1.GetAudioSamplesCount(), f2.GetAudioSamplesCount());
}
#ifdef USE_OPENCV
TEST(Convert_Image)
{
// Create a video clip
std::stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
Clip c1(path.str());
c1.Open();
// Get first frame
auto f1 = c1.GetFrame(1);
// Get first Mat image
cv::Mat cvimage = f1->GetImageCV();
CHECK(!cvimage.empty());
CHECK_EQUAL(1, f1->number);
CHECK_EQUAL(f1->GetWidth(), cvimage.cols);
CHECK_EQUAL(f1->GetHeight(), cvimage.rows);
CHECK_EQUAL(3, cvimage.channels());
}
#endif
} // SUITE(Frame_Tests)

View File

@@ -1,122 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::ImageWriter
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <memory>
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#ifdef USE_IMAGEMAGICK
#include "ImageWriter.h"
#include "Exceptions.h"
#include "ImageReader.h"
#include "FFmpegReader.h"
#include "Frame.h"
using namespace std;
using namespace openshot;
SUITE(ImageWriter)
{
TEST(Gif)
{
// Reader ---------------
// Bad path
FFmpegReader bad_r("/tmp/bleeblorp.xls", false);
CHECK_THROW(bad_r.Open(), InvalidFile);
// Good path
stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
FFmpegReader r(path.str());
// Read-before-open error
CHECK_THROW(r.GetFrame(1), ReaderClosed);
r.Open();
/* WRITER ---------------- */
ImageWriter w("output1.gif");
CHECK_EQUAL(false, w.IsOpen());
// Check for exception on write-before-open
CHECK_THROW(w.WriteFrame(&r, 500, 504), WriterClosed);
// Set the image output settings (format, fps, width, height, quality, loops, combine)
w.SetVideoOptions("GIF", r.info.fps, r.info.width, r.info.height, 70, 1, true);
// Open writer
w.Open();
// Write some frames (start on frame 500 and go to frame 510)
w.WriteFrame(&r, 500, 504);
// Close writer & reader
w.Close();
r.Close();
// Open up the 5th frame from the newly created GIF
ImageReader r1("output1.gif[4]");
// Basic Reader state queries
CHECK_EQUAL("ImageReader", r1.Name());
CacheBase* c = r1.GetCache();
CHECK_EQUAL(true, c == nullptr);
CHECK_EQUAL(false, r1.IsOpen());
r1.Open();
CHECK_EQUAL(true, r1.IsOpen());
// Verify various settings
CHECK_EQUAL(r.info.width, r1.info.width);
CHECK_EQUAL(r.info.height, r1.info.height);
// Get a specific frame
std::shared_ptr<Frame> f = r1.GetFrame(8);
// Get the image data for row 500
const unsigned char* pixels = f->GetPixels(500);
int pixel_index = 230 * 4; // pixel 230 (4 bytes per pixel)
// Check image properties
CHECK_CLOSE(20, (int)pixels[pixel_index], 5);
CHECK_CLOSE(18, (int)pixels[pixel_index + 1], 5);
CHECK_CLOSE(11, (int)pixels[pixel_index + 2], 5);
CHECK_CLOSE(255, (int)pixels[pixel_index + 3], 5);
}
} // SUITE
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,186 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::Point
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "Point.h"
#include "Enums.h"
#include "Coordinate.h"
#include "Json.h"
SUITE(POINT) {
TEST(Default_Constructor)
{
openshot::Point p;
// Default values
CHECK_EQUAL(1, p.co.X);
CHECK_EQUAL(0, p.co.Y);
CHECK_EQUAL(0.5, p.handle_left.X);
CHECK_EQUAL(1.0, p.handle_left.Y);
CHECK_EQUAL(0.5, p.handle_right.X);
CHECK_EQUAL(0.0, p.handle_right.Y);
CHECK_EQUAL(openshot::InterpolationType::BEZIER, p.interpolation);
CHECK_EQUAL(openshot::HandleType::AUTO, p.handle_type);
}
TEST(XY_Constructor)
{
// Create a point with X and Y values
openshot::Point p1(2,9);
CHECK_EQUAL(2, p1.co.X);
CHECK_EQUAL(9, p1.co.Y);
CHECK_EQUAL(openshot::InterpolationType::BEZIER, p1.interpolation);
}
TEST(Pair_Constructor)
{
// Create a point from a std::pair
std::pair<double, double> coordinates(22, 5);
openshot::Point p1(coordinates);
CHECK_CLOSE(22.0f, p1.co.X, 0.00001);
CHECK_CLOSE(5.0f, p1.co.Y, 0.00001);
}
TEST(Constructor_With_Coordinate)
{
// Create a point with a coordinate
openshot::Coordinate c1(3,7);
openshot::Point p1(c1);
CHECK_CLOSE(3.0f, p1.co.X, 0.00001);
CHECK_CLOSE(7.0f, p1.co.Y, 0.00001);
CHECK_EQUAL(openshot::InterpolationType::BEZIER, p1.interpolation);
}
TEST(Constructor_With_Coordinate_And_LINEAR_Interpolation)
{
// Create a point with a coordinate and interpolation
openshot::Coordinate c1(3,9);
auto interp = openshot::InterpolationType::LINEAR;
openshot::Point p1(c1, interp);
CHECK_EQUAL(3, c1.X);
CHECK_EQUAL(9, c1.Y);
CHECK_EQUAL(openshot::InterpolationType::LINEAR, p1.interpolation);
}
TEST(Constructor_With_Coordinate_And_BEZIER_Interpolation)
{
// Create a point with a coordinate and interpolation
openshot::Coordinate c1(3,9);
auto interp = openshot::InterpolationType::BEZIER;
openshot::Point p1(c1, interp);
CHECK_EQUAL(3, p1.co.X);
CHECK_EQUAL(9, p1.co.Y);
CHECK_EQUAL(openshot::InterpolationType::BEZIER, p1.interpolation);
}
TEST(Constructor_With_Coordinate_And_CONSTANT_Interpolation)
{
// Create a point with a coordinate and interpolation
openshot::Coordinate c1(2,8);
auto interp = openshot::InterpolationType::CONSTANT;
openshot::Point p1(c1, interp);
CHECK_EQUAL(2, p1.co.X);
CHECK_EQUAL(8, p1.co.Y);
CHECK_EQUAL(openshot::InterpolationType::CONSTANT, p1.interpolation);
}
TEST(Constructor_With_Coordinate_And_BEZIER_And_AUTO_Handle)
{
// Create a point with a coordinate and interpolation
openshot::Coordinate c1(3,9);
openshot::Point p1(c1,
openshot::InterpolationType::BEZIER,
openshot::HandleType::AUTO);
CHECK_EQUAL(3, p1.co.X);
CHECK_EQUAL(9, p1.co.Y);
CHECK_EQUAL(openshot::InterpolationType::BEZIER, p1.interpolation);
CHECK_EQUAL(openshot::HandleType::AUTO, p1.handle_type);
}
TEST(Constructor_With_Coordinate_And_BEZIER_And_MANUAL_Handle)
{
// Create a point with a coordinate and interpolation
openshot::Coordinate c1(3,9);
openshot::Point p1(c1,
openshot::InterpolationType::BEZIER,
openshot::HandleType::MANUAL);
CHECK_EQUAL(3, p1.co.X);
CHECK_EQUAL(9, p1.co.Y);
CHECK_EQUAL(openshot::InterpolationType::BEZIER, p1.interpolation);
CHECK_EQUAL(openshot::HandleType::MANUAL, p1.handle_type);
}
TEST(Json)
{
openshot::Point p1;
openshot::Point p2(1, 0);
auto json1 = p1.Json();
auto json2 = p2.JsonValue();
auto json_string2 = json2.toStyledString();
CHECK_EQUAL(json1, json_string2);
}
TEST(SetJson)
{
openshot::Point p1;
std::stringstream json_stream;
json_stream << R"json(
{
"co": { "X": 1.0, "Y": 0.0 },
"handle_left": { "X": 2.0, "Y": 3.0 },
"handle_right": { "X": 4.0, "Y": -2.0 },
"handle_type": )json";
json_stream << static_cast<float>(openshot::HandleType::MANUAL) << ",";
json_stream << R"json(
"interpolation": )json";
json_stream << static_cast<float>(openshot::InterpolationType::CONSTANT);
json_stream << R"json(
}
)json";
p1.SetJson(json_stream.str());
CHECK_EQUAL(2.0, p1.handle_left.X);
CHECK_EQUAL(3.0, p1.handle_left.Y);
CHECK_EQUAL(4.0, p1.handle_right.X);
CHECK_EQUAL(-2.0, p1.handle_right.Y);
CHECK_EQUAL(openshot::HandleType::MANUAL, p1.handle_type);
CHECK_EQUAL(openshot::InterpolationType::CONSTANT, p1.interpolation);
}
} // SUITE

View File

@@ -1,107 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::QtImageReader
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "QGuiApplication"
#include "OpenShot.h"
using namespace std;
using namespace openshot;
SUITE(QtImageReader)
{
TEST(Default_Constructor)
{
// Check invalid path
CHECK_THROW(QtImageReader(""), InvalidFile);
}
TEST(GetFrame_Before_Opening)
{
// Create a reader
stringstream path;
path << TEST_MEDIA_PATH << "front.png";
QtImageReader r(path.str());
// Check invalid path
CHECK_THROW(r.GetFrame(1), ReaderClosed);
}
TEST(Check_SVG_Loading)
{
// Create a reader
stringstream path;
path << TEST_MEDIA_PATH << "1F0CF.svg";
QtImageReader r(path.str());
r.Open();
// Get frame, with no Timeline or Clip
// Default SVG scaling sizes things to 1920x1080
std::shared_ptr<Frame> f = r.GetFrame(1);
CHECK_EQUAL(1080, f->GetImage()->width());
CHECK_EQUAL(1080, f->GetImage()->height());
Fraction fps(30000,1000);
Timeline t1(640, 480, fps, 44100, 2, LAYOUT_STEREO);
Clip clip1(path.str());
clip1.Layer(1);
clip1.Position(0.0); // Delay the overlay by 0.05 seconds
clip1.End(10.0); // Make the duration of the overlay 1/2 second
// Add clips
t1.AddClip(&clip1);
t1.Open();
// Get frame, with 640x480 Timeline
// Should scale to 480
clip1.Reader()->Open();
f = clip1.Reader()->GetFrame(2);
CHECK_EQUAL(480, f->GetImage()->width());
CHECK_EQUAL(480, f->GetImage()->height());
// Add scale_x and scale_y. Should scale the square SVG
// by the largest scale keyframe (i.e. 4)
clip1.scale_x.AddPoint(1.0, 2.0, openshot::LINEAR);
clip1.scale_y.AddPoint(1.0, 2.0, openshot::LINEAR);
f = clip1.Reader()->GetFrame(3);
CHECK_EQUAL(480 * 2, f->GetImage()->width());
CHECK_EQUAL(480 * 2, f->GetImage()->height());
// Close reader
t1.Close();
r.Close();
}
} // SUITE(QtImageReader)

View File

@@ -1,93 +0,0 @@
/**
* @file
* @brief Unit tests for openshot::ReaderBase
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory>
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "ReaderBase.h"
#include "CacheBase.h"
#include "Frame.h"
#include "Json.h"
using namespace std;
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.
TEST(ReaderBase_Derived_Class)
{
// Create a new derived class from type ReaderBase
class TestReader : public ReaderBase
{
public:
TestReader() { };
CacheBase* GetCache() { return NULL; };
std::shared_ptr<Frame> GetFrame(int64_t number) { std::shared_ptr<Frame> f(new Frame()); return f; }
void Close() { };
void Open() { };
string Json() const { return ""; };
void SetJson(string value) { };
Json::Value JsonValue() const { return Json::Value("{}"); };
void SetJsonValue(Json::Value root) { };
bool IsOpen() { return true; };
string Name() { return "TestReader"; };
};
// Create an instance of the derived class
TestReader t1;
// Validate the new class
CHECK_EQUAL("TestReader", t1.Name());
t1.Close();
t1.Open();
CHECK_EQUAL(true, t1.IsOpen());
CHECK_EQUAL(true, t1.GetCache() == NULL);
t1.SetJson("{ }");
t1.SetJsonValue(Json::Value("{}"));
CHECK_EQUAL("", t1.Json());
auto json = t1.JsonValue();
CHECK_EQUAL(json, Json::Value("{}"));
auto f = t1.GetFrame(1);
// Check some of the default values of the FileInfo struct on the base class
CHECK_EQUAL(false, t1.info.has_audio);
CHECK_EQUAL(false, t1.info.has_audio);
CHECK_CLOSE(0.0f, t1.info.duration, 0.00001);
CHECK_EQUAL(0, t1.info.height);
CHECK_EQUAL(0, t1.info.width);
CHECK_EQUAL(1, t1.info.fps.num);
CHECK_EQUAL(1, t1.info.fps.den);
}

Some files were not shown because too many files have changed in this diff Show More