From d9775d4a5e9b011e31a45526767c783d7b201040 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Fri, 9 Apr 2021 04:09:36 -0400 Subject: [PATCH] Port unit tests to Catch2 --- CMakeLists.txt | 122 +++++++--- tests/CMakeLists.txt | 163 ++++++++----- tests/CVObjectDetection.cpp | 135 +++++------ tests/CVStabilizer.cpp | 168 +++++++------ tests/CVTracker.cpp | 188 +++++++-------- tests/Cache.cpp | 470 ------------------------------------ tests/CacheDisk.cpp | 261 ++++++++++++++++++++ tests/CacheMemory.cpp | 351 +++++++++++++++++++++++++++ tests/Clip.cpp | 128 +++++----- tests/Color.cpp | 95 ++++---- tests/Coordinate.cpp | 42 ++-- tests/DummyReader.cpp | 116 +++++---- tests/FFmpegReader.cpp | 118 +++++---- tests/FFmpegWriter.cpp | 42 ++-- tests/Fraction.cpp | 106 ++++---- tests/Frame.cpp | 110 +++++---- tests/FrameMapper.cpp | 157 ++++++------ tests/ImageWriter.cpp | 47 ++-- tests/KeyFrame.cpp | 399 +++++++++++++++--------------- tests/Point.cpp | 118 ++++----- tests/QtImageReader.cpp | 46 ++-- tests/ReaderBase.cpp | 44 ++-- tests/Settings.cpp | 22 +- tests/Timeline.cpp | 341 +++++++++++--------------- tests/catch_main.cpp | 33 +++ 25 files changed, 1974 insertions(+), 1848 deletions(-) delete mode 100644 tests/Cache.cpp create mode 100644 tests/CacheDisk.cpp create mode 100644 tests/CacheMemory.cpp create mode 100644 tests/catch_main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 85aa26409..efcbaf787 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,10 +73,16 @@ include(FeatureSummary) # Optional build settings for libopenshot option(USE_SYSTEM_JSONCPP "Use system installed JsonCpp, if found" ON) 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 UnitTest++)" ON) + +option(ENABLE_TESTS "Build unit tests (requires Catch2 or UnitTest++)" ON) +option(USE_CATCH2 "Enable Catch2-based unit tests" ON) +option(ENABLE_PARALLEL_CTEST "Run CTest using multiple processors" ON) option(ENABLE_COVERAGE "Scan test coverage using gcov and report" OFF) + option(ENABLE_DOCS "Build API documentation (requires Doxygen)" ON) + option(APPIMAGE_BUILD "Build to install in an AppImage (Linux only)" OFF) option(ENABLE_MAGICK "Use ImageMagick, if available" ON) option(ENABLE_OPENCV "Build with OpenCV algorithms (requires Boost, Protobuf 3)" ON) @@ -87,7 +93,7 @@ if (DISABLE_TESTS) endif() if(DEFINED ENABLE_TESTS) - set(ENABLE_TESTS ${ENABLE_TESTS} CACHE BOOL "Build unit tests (requires UnitTest++)" FORCE) + set(ENABLE_TESTS ${ENABLE_TESTS} CACHE BOOL "Build unit tests (requires Catch2 or UnitTest++)" FORCE) endif() #### Work around a GCC < 9 bug with handling of _Pragma() in macros @@ -109,7 +115,7 @@ ENDIF(WIN32) ############## Code Coverage ######################### if (ENABLE_COVERAGE AND NOT ENABLE_TESTS) message(WARNING "ENABLE_COVERAGE requires unit tests, forcing ENABLE_TESTS") - set(ENABLE_TESTS ON CACHE BOOL "Don't build unit tests" FORCE) + set(ENABLE_TESTS ON CACHE BOOL "Build unit tests (requires Catch2 or UnitTest++)" FORCE) endif() if (ENABLE_COVERAGE) @@ -166,55 +172,103 @@ if (ENABLE_DOCS) OPTIONAL ) # No error if the docs aren't found endif() endif() -add_feature_info("Documentation" DOCS_ENABLED "Build API documentation with 'make doc'") ############# 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() + endif() + include(CTest) + include(Catch) + endif() add_subdirectory(tests) endif() add_feature_info("Unit tests" TESTS_ENABLED "Compile unit tests for library functions") ############## COVERAGE REPORTING ################# if (ENABLE_COVERAGE) - setup_target_for_coverage_lcov( - NAME coverage - LCOV_ARGS "--no-external" - EXECUTABLE openshot-test - DEPENDENCIES openshot openshot-test - EXCLUDE - "bindings/*" - "examples/*" - "${CMAKE_CURRENT_BINARY_DIR}/bindings/*" - "${CMAKE_CURRENT_BINARY_DIR}/src/*_autogen/*" - ) - if(NOT TARGET os_test) - add_custom_target(os_test) - add_dependencies(os_test 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() endif() -# Also hook up 'test' as an alias for the 'os_test' target, if possible -# This requires CMake 3.11+, where the CMP0037 policy -# configured to 'NEW' mode will not reserve target names -# unless the corresponding feature is actually used -if (POLICY CMP0037) - cmake_policy(SET CMP0037 NEW) +if(TESTS_ENABLED AND NOT TARGET coverage) + add_custom_target(coverage + COMMAND ctest ${CTEST_OPTIONS} + DEPENDS openshot ${CATCH2_TEST_TARGETS} ${UNIT_TEST_TARGETS} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Running unit tests (coverage disabled)" + ) endif() -if(TARGET os_test) - if (CMAKE_VERSION VERSION_GREATER 3.11) - message(STATUS "Cmake 3.11+ detected, enabling 'test' target") - add_custom_target(test) - add_dependencies(test os_test) - set(TEST_TARGET_NAME "test") - else() - set(TEST_TARGET_NAME "os_test") + +if(TARGET test AND NOT TARGET os_test) + add_custom_target(os_test) + add_dependencies(os_test coverage) +endif() + +if(TARGET os_test AND NOT TARGET test AND CMAKE_VERSION VERSION_GREATER 3.11) + # Also hook up 'test' as an alias for the 'os_test' target, if possible + # This requires CMake 3.11+, where the CMP0037 policy + # configured to 'NEW' mode will not reserve target names + # unless the corresponding feature is actually used + if (POLICY CMP0037) + cmake_policy(SET CMP0037 NEW) endif() - add_feature_info("Testrunner" ENABLE_TESTS "Run unit tests with 'make ${TEST_TARGET_NAME}'") + message(STATUS "Cmake 3.11+ detected, enabling 'test' target") + add_custom_target(test) + add_dependencies(test os_test) endif() +### +### Add feature-summary details on non-default built targets +### +set(optional_targets test os_test coverage doc) +set(target_test_description "Build and execute unit tests") +set(target_os_test_description "Build and execute unit tests (legacy target)") +set(target_coverage_description "Run unit tests and (if enabled) collect coverage data") +set(target_doc_description "Build formatted API documentation (HTML+SVG)") +foreach(_tname IN LISTS optional_targets) + if(TARGET ${_tname}) + add_feature_info("Non-default target '${_tname}'" TRUE ${target_${_tname}_description}) + else() + message(DEBUG "No target ${_tname}") + endif() +endforeach() + ########### PRINT FEATURE SUMMARY ############## feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES - DESCRIPTION "Displaying feature summary\n\nBuild configuration:") + DESCRIPTION "Build configuration:") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c649db9e9..cb36c6921 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,24 +26,6 @@ # Test media path, used by unit tests for input data file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/examples/" TEST_MEDIA_PATH) -add_definitions( -DTEST_MEDIA_PATH="${TEST_MEDIA_PATH}" ) - -################### UNITTEST++ ##################### -# 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") - ################# BLACKMAGIC DECKLINK ################### if(ENABLE_BLACKMAGIC) @@ -56,53 +38,108 @@ if(ENABLE_BLACKMAGIC) endif() endif() -############### SET TEST SOURCE FILES ################# -set(OPENSHOT_TEST_FILES - Cache_Tests.cpp - Clip_Tests.cpp - Color_Tests.cpp - Coordinate_Tests.cpp - DummyReader_Tests.cpp - ReaderBase_Tests.cpp - ImageWriter_Tests.cpp - FFmpegReader_Tests.cpp - FFmpegWriter_Tests.cpp - Fraction_Tests.cpp - Frame_Tests.cpp - FrameMapper_Tests.cpp - KeyFrame_Tests.cpp - Point_Tests.cpp - QtImageReader_Tests.cpp - Settings_Tests.cpp - Timeline_Tests.cpp) - -########## SET OPENCV RELATED TEST FILES ############### +### +### TEST SOURCE FILES +### +set(OPENSHOT_TESTS + CacheDisk + CacheMemory + Clip + Color + Coordinate + DummyReader + ReaderBase + ImageWriter + FFmpegReader + FFmpegWriter + Fraction + Frame + FrameMapper + KeyFrame + Point + QtImageReader + Settings + Timeline) + +### +### OPENCV RELATED TEST FILES +### if(ENABLE_OPENCV) - list(APPEND OPENSHOT_TEST_FILES - CVTracker_Tests.cpp - CVStabilizer_Tests.cpp - # CVObjectDetection_Tests.cpp + list(APPEND OPENSHOT_TESTS + CVTracker + CVStabilizer + # CVObjectDetection ) endif() -################ TESTER EXECUTABLE ################# -# Create unit test executable (openshot-test) -message (STATUS "Tests enabled, test executable will be built as tests/openshot-test") - -add_executable(openshot-test - tests.cpp - ${OPENSHOT_TEST_FILES} -) - -# Link libraries to the new executable -target_link_libraries(openshot-test - openshot - ${UnitTest++_LIBRARIES} -) - -##### RUNNING TESTS (make os_test / make test) ##### -# Hook up the 'make os_test' target to the 'openshot-test' executable, -# if we aren't defining it as the coverage target -if(NOT ENABLE_COVERAGE) - add_custom_target(os_test COMMAND openshot-test) +### +### Catch2 (new) unit tests +### +if (TESTS_ENABLED AND USE_CATCH2) + message (STATUS "Tests enabled, test executables will be compiled") + include(Catch) + + include(CTest) + + # Create object library for test executable main(), + # to avoid recompiling for every test + add_library(catch-main OBJECT catch_main.cpp) + + foreach(tname ${OPENSHOT_TESTS}) + add_executable(openshot-${tname}-test ${tname}.cpp $) + target_compile_definitions(openshot-${tname}-test PRIVATE + TEST_MEDIA_PATH="${TEST_MEDIA_PATH}" + ) + target_link_libraries(openshot-${tname}-test Catch2::Catch2 openshot) + # Automatically configure CTest targets from Catch2 test cases + catch_discover_tests( + openshot-${tname}-test + TEST_PREFIX ${tname}: + ) + list(APPEND CATCH2_TEST_TARGETS openshot-${tname}-test) + endforeach() + # Export target list for coverage use + set(CATCH2_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() diff --git a/tests/CVObjectDetection.cpp b/tests/CVObjectDetection.cpp index e6c997a00..96e4328a6 100644 --- a/tests/CVObjectDetection.cpp +++ b/tests/CVObjectDetection.cpp @@ -32,9 +32,8 @@ #include #include -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include + #include "Clip.h" #include "CVObjectDetection.h" #include "ProcessingController.h" @@ -48,93 +47,87 @@ std::string effectInfo =(" {\"protobuf_data_path\": \"objdetector.data\", " " \"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"; +// Just for the stabilizer constructor, it won't be used +ProcessingController processingController; - // Open clip - openshot::Clip c1(path.str()); - c1.Open(); - - //TODO remove hardcoded path - CVObjectDetection objectDetector(effectInfo, processingController); +TEST_CASE( "DetectObject_Video", "[libopenshot][opencv][objectdetection]" ) +{ + // Create a video clip + std::stringstream path; + path << TEST_MEDIA_PATH << "run.mp4"; - objectDetector.detectObjectsClip(c1, 0, 20, true); + // Open clip + openshot::Clip c1(path.str()); + c1.Open(); - CVDetectionData dd = objectDetector.GetDetectionData(20); + //TODO remove hardcoded path + CVObjectDetection objectDetector(effectInfo, processingController); - 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); + objectDetector.detectObjectsClip(c1, 0, 20, true); - 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); + 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((int) (x1 * 720) == 106); + CHECK((int) (y1 * 400) == 21); + CHECK((int) (x2 * 720) == 628); + CHECK((int) (y2 * 400) == 429); + CHECK((int) (confidence * 1000) == 554); + CHECK(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(); +TEST_CASE( "SaveLoad_Protobuf", "[libopenshot][opencv][objectdetection]" ) +{ - //TODO remove hardcoded path - CVObjectDetection objectDetector_1(effectInfo ,processingController); + // Create a video clip + std::stringstream path; + path << TEST_MEDIA_PATH << "run.mp4"; - objectDetector_1.detectObjectsClip(c1, 0, 20, true); + // Open clip + openshot::Clip c1(path.str()); + c1.Open(); - CVDetectionData dd_1 = objectDetector_1.GetDetectionData(20); + //TODO remove hardcoded path + CVObjectDetection objectDetector_1(effectInfo ,processingController); - 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.detectObjectsClip(c1, 0, 20, true); - objectDetector_1.SaveObjDetectedData(); + CVDetectionData dd_1 = objectDetector_1.GetDetectionData(20); - CVObjectDetection objectDetector_2(effectInfo, processingController); + 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_2._LoadObjDetectdData(); + objectDetector_1.SaveObjDetectedData(); - CVDetectionData dd_2 = objectDetector_2.GetDetectionData(20); + CVObjectDetection objectDetector_2(effectInfo, processingController); - 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); + objectDetector_2._LoadObjDetectdData(); - 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); + 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); -} // SUITE(Frame_Tests) + CHECK((int) (x1_1 * 720) == (int) (x1_2 * 720)); + CHECK((int) (y1_1 * 400) == (int) (y1_2 * 400)); + CHECK((int) (x2_1 * 720) == (int) (x2_2 * 720)); + CHECK((int) (y2_1 * 400) == (int) (y2_2 * 400)); + CHECK((int) (confidence_1 * 1000) == (int) (confidence_2 * 1000)); + CHECK(classId_1 == classId_2); +} diff --git a/tests/CVStabilizer.cpp b/tests/CVStabilizer.cpp index 4d1f9305c..0065584e7 100644 --- a/tests/CVStabilizer.cpp +++ b/tests/CVStabilizer.cpp @@ -32,111 +32,105 @@ #include #include -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include + #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 stabilizer_pc; + +TEST_CASE( "Stabilize_Video", "[libopenshot][opencv][stabilizer]" ) { + // Create a video clip + std::stringstream path; + path << TEST_MEDIA_PATH << "test.avi"; - // Just for the stabilizer constructor, it won't be used - ProcessingController processingController; + // Open clip + openshot::Clip c1(path.str()); + c1.Open(); - 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) + std::string json_data = R"proto( { + "protobuf_data_path": "stabilizer.data", + "smoothing-window": 30 + } )proto"; + + // Create stabilizer + CVStabilization stabilizer(json_data, stabilizer_pc); + + // 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(dx == (int) (58)); + CHECK(dy == (int) (-88)); + CHECK(da == (int) (7)); + CHECK(x == (int) (0)); + CHECK(y == (int) (-1)); + CHECK(a == (int) (0)); +} + + +TEST_CASE( "SaveLoad_Protobuf", "[libopenshot][opencv][stabilizer]" ) +{ - // Create a video clip - std::stringstream path; - path << TEST_MEDIA_PATH << "test.avi"; - - // Open clip - openshot::Clip c1(path.str()); - c1.Open(); + // Create a video clip + std::stringstream path; + path << TEST_MEDIA_PATH << "test.avi"; - std::string json_data = R"proto( - { - "protobuf_data_path": "stabilizer.data", - "smoothing-window": 30 - } )proto"; + // Open clip + openshot::Clip c1(path.str()); + c1.Open(); - // Create first stabilizer - CVStabilization stabilizer_1(json_data, processingController); + std::string json_data = R"proto( + { + "protobuf_data_path": "stabilizer.data", + "smoothing-window": 30 + } )proto"; - // Stabilize clip for frames 0-20 - stabilizer_1.stabilizeClip(c1, 0, 20+1, true); + // Create first stabilizer + CVStabilization stabilizer_1(json_data, stabilizer_pc); - // Get stabilized data - TransformParam tp_1 = stabilizer_1.GetTransformParamData(20); - CamTrajectory ct_1 = stabilizer_1.GetCamTrajectoryTrackedData(20); + // Stabilize clip for frames 0-20 + stabilizer_1.stabilizeClip(c1, 0, 20+1, true); - // Save stabilized data - stabilizer_1.SaveStabilizedData(); + // Get stabilized data + TransformParam tp_1 = stabilizer_1.GetTransformParamData(20); + CamTrajectory ct_1 = stabilizer_1.GetCamTrajectoryTrackedData(20); - // Create second stabilizer - CVStabilization stabilizer_2(json_data, processingController); + // Save stabilized data + stabilizer_1.SaveStabilizedData(); - // Load stabilized data from first stabilizer protobuf data - stabilizer_2._LoadStabilizedData(); + // Create second stabilizer + CVStabilization stabilizer_2(json_data, stabilizer_pc); - // Get stabilized data - TransformParam tp_2 = stabilizer_2.GetTransformParamData(20); - CamTrajectory ct_2 = stabilizer_2.GetCamTrajectoryTrackedData(20); + // Load stabilized data from first stabilizer protobuf data + stabilizer_2._LoadStabilizedData(); - // 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)); - } + // Get stabilized data + TransformParam tp_2 = stabilizer_2.GetTransformParamData(20); + CamTrajectory ct_2 = stabilizer_2.GetCamTrajectoryTrackedData(20); -} // SUITE(Frame_Tests) + // Compare first stabilizer data with second stabilizer data + CHECK((int) (tp_1.dx * 10000) == (int) (tp_2.dx *10000)); + CHECK((int) (tp_1.dy * 10000) == (int) (tp_2.dy * 10000)); + CHECK((int) (tp_1.da * 10000) == (int) (tp_2.da * 10000)); + CHECK((int) (ct_1.x * 10000) == (int) (ct_2.x * 10000)); + CHECK((int) (ct_1.y * 10000) == (int) (ct_2.y * 10000)); + CHECK((int) (ct_1.a * 10000) == (int) (ct_2.a * 10000)); +} diff --git a/tests/CVTracker.cpp b/tests/CVTracker.cpp index 3229d1ca9..dcb162859 100644 --- a/tests/CVTracker.cpp +++ b/tests/CVTracker.cpp @@ -32,120 +32,114 @@ #include #include -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include + #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 tracker_pc; + +TEST_CASE( "Track_Video", "[libopenshot][opencv][tracker]" ) { + // Create a video clip + std::stringstream path; + path << TEST_MEDIA_PATH << "test.avi"; - // Just for the tracker constructor, it won't be used - ProcessingController processingController; + // Open clip + openshot::Clip c1(path.str()); + c1.Open(); - 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) + 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, tracker_pc); + + // 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((int)(x * 640) == 259); + CHECK((int)(y * 360) == 131); + CHECK((int)(width * 640) == 180); + CHECK((int)(height * 360) == 166); +} + + +TEST_CASE( "SaveLoad_Protobuf", "[libopenshot][opencv][tracker]" ) +{ - // 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); + // Create a video clip + std::stringstream path; + path << TEST_MEDIA_PATH << "test.avi"; - 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; + // Open clip + openshot::Clip c1(path.str()); + c1.Open(); - // Save tracked data - kcfTracker_1.SaveTrackedData(); + 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"; - 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); + // Create first tracker + CVTracker kcfTracker_1(json_data, tracker_pc); - // Load tracked data from first tracker protobuf data - kcfTracker_2._LoadTrackedData(); + // Track clip for frames 0-20 + kcfTracker_1.trackClip(c1, 0, 20, true); - // Get tracked data - FrameData fd_2 = kcfTracker_2.GetTrackedData(20); + // Get tracked data + FrameData fd_1 = kcfTracker_1.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; + 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; - // 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)); - } + // Save tracked data + kcfTracker_1.SaveTrackedData(); -} // SUITE(Frame_Tests) + 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, tracker_pc); + + // 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((int)(x_1 * 640) == (int)(x_2 * 640)); + CHECK((int)(y_1 * 360) == (int)(y_2 * 360)); + CHECK((int)(width_1 * 640) == (int)(width_2 * 640)); + CHECK((int)(height_1 * 360) == (int)(height_2 * 360)); +} diff --git a/tests/Cache.cpp b/tests/Cache.cpp deleted file mode 100644 index 1220cf14b..000000000 --- a/tests/Cache.cpp +++ /dev/null @@ -1,470 +0,0 @@ -/** - * @file - * @brief Unit tests for openshot::Cache - * @author Jonathan Thomas - * - * @ref License - */ - -/* LICENSE - * - * Copyright (c) 2008-2019 OpenShot Studios, LLC - * . 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 . - * - * 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 . - */ - -#include - -#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 - -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 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 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 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 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 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 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(red)); - c.Add(std::shared_ptr(blue)); - c.Add(std::shared_ptr(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(red)); - c.Add(std::shared_ptr(blue)); - c.Add(std::shared_ptr(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(red)); - c.Add(std::shared_ptr(blue)); - c.Add(std::shared_ptr(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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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()); - -} diff --git a/tests/CacheDisk.cpp b/tests/CacheDisk.cpp new file mode 100644 index 000000000..25c1cf671 --- /dev/null +++ b/tests/CacheDisk.cpp @@ -0,0 +1,261 @@ +/** + * @file + * @brief Unit tests for openshot::Cache + * @author Jonathan Thomas + * + * @ref License + */ + +/* LICENSE + * + * Copyright (c) 2008-2019 OpenShot Studios, LLC + * . 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 . + * + * 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 . + */ + +#include +#include + +#include + +#include "CacheDisk.h" +#include "Json.h" + +using namespace openshot; + +TEST_CASE( "constructor", "[libopenshot][cachedisk]" ) +{ + QDir temp_path = QDir::tempPath() + QString("/constructor/"); + + // Create cache object + CacheDisk c(temp_path.path().toStdString(), "PPM", 1.0, 0.25); + + for (int i = 0; i < 20; i++) + { + // Add blank frame to the cache + auto f = std::make_shared(); + f->number = i; + c.Add(f); + } + + CHECK(c.Count() == 20); // Cache should have all frames, with no limit + CHECK(c.GetMaxBytes() == 0); // Max frames should default to 0 + + // Clean up + c.Clear(); + temp_path.removeRecursively(); +} + +TEST_CASE( "MaxBytes constructor", "[libopenshot][cachedisk]" ) +{ + QDir temp_path = QDir::tempPath() + QString("/maxbytes-constructor/"); + + // Create cache object + CacheDisk c(temp_path.path().toStdString(), "PPM", 1.0, 0.25, 20 * 1024); + + CHECK(c.GetMaxBytes() == 20 * 1024); + + for (int i = 0; i < 20; i++) + { + // Add blank frame to the cache + auto f = std::make_shared(); + f->number = i; + c.Add(f); + } + + CHECK(c.Count() == 20); + CHECK(c.GetMaxBytes() == 20 * 1024); + + // Clean up + c.Clear(); + temp_path.removeRecursively(); +} + +TEST_CASE( "SetMaxBytes", "[libopenshot][cachedisk]" ) +{ + QDir temp_path = QDir::tempPath() + QString("/set_max_bytes/"); + + // Create cache object + CacheDisk c(temp_path.path().toStdString(), "PPM", 1.0, 0.25); + + // Add frames to disk cache + for (int i = 0; i < 20; i++) + { + // Add blank frame to the cache + auto f = std::make_shared(); + 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(c.GetMaxBytes() == 0); // Cache defaults max frames to -1, unlimited frames + + // Set max frames + c.SetMaxBytes(8 * 1024); + CHECK(c.GetMaxBytes() == 8 * 1024); + + // Set max frames + c.SetMaxBytes(4 * 1024); + CHECK(c.GetMaxBytes() == 4 * 1024); + + // Read frames from disk cache + auto f = c.GetFrame(5); + CHECK(f->GetWidth() == 320); + CHECK(f->GetHeight() == 180); + CHECK(f->GetAudioChannelsCount() == 2); + CHECK(f->GetAudioSamplesCount() == 500); + CHECK(f->ChannelsLayout() == LAYOUT_STEREO); + CHECK(f->SampleRate() == 44100); + + // Check count of cache + CHECK(c.Count() == 20); + + // Clear cache + c.Clear(); + + // Check count of cache + CHECK(c.Count() == 0); + + // Delete cache directory + temp_path.removeRecursively(); +} + +TEST_CASE( "freshen frames", "[libopensoht][cachedisk]" ) +{ + QDir temp_path = QDir::tempPath() + QString("/freshen-frames/"); + + // Create cache object + CacheDisk c(temp_path.path().toStdString(), "PPM", 1.0, 0.25); + + auto f1 = std::make_shared(1, 1280, 1024, "#FRIST!"); + + c.Add(f1); + + for(int i = 2; i <= 20; i++) + { + // Add blank frame to the cache + auto f = std::make_shared(); + 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(c.Count() == 20); + + // Capture current size of cache + auto start_bytes = c.GetBytes(); + + // Re-add existing frame a few times + for (int x = 0; x < 5; x++) + { + c.Add(f1); + } + + // Check that size hasn't changed + CHECK(c.Count() == 20); + CHECK(c.GetBytes() == start_bytes); + + // Clean up + c.Clear(); + temp_path.removeRecursively(); +} + +TEST_CASE( "multiple remove", "[libopenshot][cachedisk]" ) +{ + // Create cache object in default temp_path()/preview-cache location + 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 + auto f = std::make_shared(); + 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(c.Count() == 20); + + // Remove a single frame + c.Remove(5); + CHECK(c.Count() == 19); + + // Remove a range of frames + c.Remove(4, 20); + CHECK(c.Count() == 3); + + // Remove the rest + c.Remove(1, 3); + CHECK(c.Count() == 0); + + // Delete cache directory + QDir temp_path = QDir::tempPath() + "/preview-cache/"; + temp_path.removeRecursively(); +} + +TEST_CASE( "JSON", "[libopenshot][cachedisk]" ) +{ + QDir temp_path = QDir::tempPath() + QString("/cache_json/"); + + // Create cache object + CacheDisk c(temp_path.path().toStdString(), "PPM", 1.0, 0.25); + + // Add some frames (out of order) + auto f3 = std::make_shared(3, 1280, 720, "Blue", 500, 2); + c.Add(f3); + CHECK((int)c.JsonValue()["ranges"].size() == 1); + CHECK(c.JsonValue()["version"].asString() == "1"); + + // Add some frames (out of order) + auto f1 = std::make_shared(1, 1280, 720, "Blue", 500, 2); + c.Add(f1); + CHECK((int)c.JsonValue()["ranges"].size() == 2); + CHECK(c.JsonValue()["version"].asString() == "2"); + + // Add some frames (out of order) + auto f2 = std::make_shared(2, 1280, 720, "Blue", 500, 2); + c.Add(f2); + CHECK((int)c.JsonValue()["ranges"].size() == 1); + CHECK(c.JsonValue()["version"].asString() == "3"); + + // Add some frames (out of order) + auto f5 = std::make_shared(5, 1280, 720, "Blue", 500, 2); + c.Add(f5); + CHECK((int)c.JsonValue()["ranges"].size() == 2); + CHECK(c.JsonValue()["version"].asString() == "4"); + + // Add some frames (out of order) + auto f4 = std::make_shared(4, 1280, 720, "Blue", 500, 2); + c.Add(f4); + CHECK((int)c.JsonValue()["ranges"].size() == 1); + CHECK(c.JsonValue()["version"].asString() == "5"); + + // Delete cache directory + c.Clear(); + temp_path.removeRecursively(); +} diff --git a/tests/CacheMemory.cpp b/tests/CacheMemory.cpp new file mode 100644 index 000000000..9b8e54421 --- /dev/null +++ b/tests/CacheMemory.cpp @@ -0,0 +1,351 @@ +/** + * @file + * @brief Unit tests for openshot::CacheMemory + * @author Jonathan Thomas + * + * @ref License + */ + +/* LICENSE + * + * Copyright (c) 2008-2019 OpenShot Studios, LLC + * . 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 . + * + * 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 . + */ + +#include +#include + +#include + +#include "CacheMemory.h" +#include "Json.h" + +using namespace openshot; + +TEST_CASE( "default constructor", "[libopenshot][cachememory]" ) +{ + // Create cache object + CacheMemory c; + + // Loop 50 times + for (int i = 0; i < 50; i++) + { + // Add blank frame to the cache + auto f = std::make_shared(); + f->number = i; + c.Add(f); + } + + CHECK(c.Count() == 50); // Cache should have all frames, with no limit + CHECK(c.GetMaxBytes() == 0); // Max frames should default to 0 +} + +TEST_CASE( "MaxBytes constructor", "[libopenshot][cachememory]" ) +{ + // 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 + auto f = std::make_shared(i, 320, 240, "#000000"); + f->AddColor(320, 240, "#000000"); + c.Add(f); + } + + // Cache should have all 20 + CHECK(c.Count() == 20); + + // Add 10 frames again + for (int i = 10; i > 0; i--) + { + // Add blank frame to the cache + auto f = std::make_shared(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(c.Count() == 20); + + // Check which items the cache kept + CHECK(c.GetFrame(1) != nullptr); + CHECK(c.GetFrame(10) != nullptr); + CHECK(c.GetFrame(11) != nullptr); + CHECK(c.GetFrame(19) != nullptr); + CHECK(c.GetFrame(20) != nullptr); + CHECK(c.GetFrame(21) == nullptr); + CHECK(c.GetFrame(30) == nullptr); +} + +TEST_CASE( "Clear", "[libopenshot][cachememory]" ) +{ + // Create cache object + CacheMemory c(250 * 1024); + + // Loop 10 times + for (int i = 0; i < 10; i++) + { + // Add blank frame to the cache + auto f = std::make_shared(); + f->number = i; + c.Add(f); + } + + // Cache should only have 10 items + CHECK(c.Count() == 10); + + // Clear Cache + c.Clear(); + + // Cache should now have 0 items + CHECK(c.Count() == 0); +} + +TEST_CASE( "add duplicate Frames", "[libopenshot][cachememory]" ) +{ + // 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) + auto f = std::make_shared(); + c.Add(f); + } + + // Cache should only have 1 items (since all frames were frame #1) + CHECK(c.Count() == 1); +} + +TEST_CASE( "check if Frame exists", "[libopenshot][cachememory]" ) +{ + // Create cache object + CacheMemory c(250 * 1024); + + // Loop 5 times + for (int i = 1; i < 6; i++) + { + // Add blank frame to the cache + auto f = std::make_shared(); + f->number = i; + c.Add(f); + } + + // Check if certain frames exists (only 1-5 exist) + CHECK(c.GetFrame(0) == nullptr); + CHECK(c.GetFrame(1) != nullptr); + CHECK(c.GetFrame(2) != nullptr); + CHECK(c.GetFrame(3) != nullptr); + CHECK(c.GetFrame(4) != nullptr); + CHECK(c.GetFrame(5) != nullptr); + CHECK(c.GetFrame(6) == nullptr); +} + +TEST_CASE( "GetFrame", "[libopenshot][cachememory]" ) +{ + // 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(red)); + c.Add(std::shared_ptr(blue)); + c.Add(std::shared_ptr(green)); + + // Get frames + CHECK(c.GetFrame(0) == nullptr); + CHECK(c.GetFrame(4) == nullptr); + + // Check if certain frames exists (only 1-5 exist) + CHECK(c.GetFrame(1)->number == 1); + CHECK(c.GetFrame(2)->number == 2); + CHECK(c.GetFrame(3)->number == 3); +} + +TEST_CASE( "GetSmallest", "[libopenshot][cachememory]" ) +{ + // Create cache object (with a max of 10 items) + CacheMemory c(250 * 1024); + + // Create 3 frames + auto red = std::make_shared(1, 300, 300, "red"); + auto blue = std::make_shared(2, 400, 400, "blue"); + auto green = std::make_shared(3, 500, 500, "green"); + + // Add frames to cache + c.Add(red); + c.Add(blue); + + // Check if frame 1 is the front + CHECK(c.GetSmallestFrame()->number == 1); + + c.Add(green); + + // Check if frame 1 is STILL the front + CHECK(c.GetSmallestFrame()->number == 1); + + c.Remove(1); + + // Check if frame 2 is now the front + CHECK(c.GetSmallestFrame()->number == 2); +} + +TEST_CASE( "Remove", "[libopenshot][cachememory]" ) +{ + // Create cache object (with a max of 10 items) + CacheMemory c(250 * 1024); + + // Create 3 frames + auto red = std::make_shared(1, 300, 300, "red"); + auto blue = std::make_shared(2, 400, 400, "blue"); + auto green = std::make_shared(3, 500, 500, "green"); + + // Add frames to cache + c.Add(red); + c.Add(blue); + c.Add(green); + + // Check if count is 3 + CHECK(c.Count() == 3); + + // Check if frame 2 exists + CHECK(c.GetFrame(2) != nullptr); + + // Remove frame 2 + c.Remove(2); + + // Check if frame 2 exists + CHECK(c.GetFrame(2) == nullptr); + + // Check if count is 2 + CHECK(c.Count() == 2); + + // Remove frame 1 + c.Remove(1); + + // Check if frame 1 exists + CHECK(c.GetFrame(1) == nullptr); + + // Check if count is 1 + CHECK(c.Count() == 1); +} + +TEST_CASE( "SetMaxBytes", "[libopenshot][cachememory]" ) +{ + // Create cache object + CacheMemory c; + + // Loop 20 times + for (int i = 0; i < 20; i++) + { + // Add blank frame to the cache + auto f = std::make_shared(); + f->number = i; + c.Add(f); + } + + CHECK(c.GetMaxBytes() == 0); // Cache defaults max frames to -1, unlimited frames + + // Set max frames + c.SetMaxBytes(8 * 1024); + CHECK(c.GetMaxBytes() == 8 * 1024); + + // Set max frames + c.SetMaxBytes(4 * 1024); + CHECK(c.GetMaxBytes() == 4 * 1024); +} + +TEST_CASE( "multiple remove", "[libopenshot][cachememory]" ) +{ + // 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 + auto f = std::make_shared(); + 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(c.Count() == 20); + + // Remove a single frame + c.Remove(17); + CHECK(c.Count() == 19); + + // Remove a range of frames + c.Remove(16, 18); + CHECK(c.Count() == 17); + + // Remove all remaining frames + c.Remove(1, 20); + CHECK(c.Count() == 0); +} + + + +TEST_CASE( "JSON", "[libopenshot][cachememory]" ) +{ + // Create memory cache object + CacheMemory c; + + // Add some frames (out of order) + auto f3 = std::make_shared(3, 1280, 720, "Blue", 500, 2); + c.Add(f3); + CHECK((int)c.JsonValue()["ranges"].size() == 1); + CHECK(c.JsonValue()["version"].asString() == "1"); + + // Add some frames (out of order) + auto f1 = std::make_shared(1, 1280, 720, "Blue", 500, 2); + c.Add(f1); + CHECK((int)c.JsonValue()["ranges"].size() == 2); + CHECK(c.JsonValue()["version"].asString() == "2"); + + // Add some frames (out of order) + auto f2 = std::make_shared(2, 1280, 720, "Blue", 500, 2); + c.Add(f2); + CHECK((int)c.JsonValue()["ranges"].size() == 1); + CHECK(c.JsonValue()["version"].asString() == "3"); + + // Add some frames (out of order) + auto f5 = std::make_shared(5, 1280, 720, "Blue", 500, 2); + c.Add(f5); + CHECK((int)c.JsonValue()["ranges"].size() == 2); + CHECK(c.JsonValue()["version"].asString() == "4"); + + // Add some frames (out of order) + auto f4 = std::make_shared(4, 1280, 720, "Blue", 500, 2); + c.Add(f4); + CHECK((int)c.JsonValue()["ranges"].size() == 1); + CHECK(c.JsonValue()["version"].asString() == "5"); + +} diff --git a/tests/Clip.cpp b/tests/Clip.cpp index 5d8ab43ce..31842eb3d 100644 --- a/tests/Clip.cpp +++ b/tests/Clip.cpp @@ -31,15 +31,8 @@ #include #include -#include "UnitTest++.h" +#include -// 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" @@ -48,25 +41,22 @@ using namespace openshot; -SUITE(Clip) -{ - -TEST(Default_Constructor) +TEST_CASE( "default constructor", "[libopenshot][clip]" ) { // 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); + CHECK(c1.anchor == ANCHOR_CANVAS); + CHECK(c1.gravity == GRAVITY_CENTER); + CHECK(c1.scale == SCALE_FIT); + CHECK(c1.Layer() == 0); + CHECK(c1.Position() == Approx(0.0f).margin(0.00001)); + CHECK(c1.Start() == Approx(0.0f).margin(0.00001)); + CHECK(c1.End() == Approx(0.0f).margin(0.00001)); } -TEST(Clip_Constructor) +TEST_CASE( "path string constructor", "[libopenshot][clip]" ) { // Create a empty clip std::stringstream path; @@ -75,29 +65,29 @@ TEST(Clip_Constructor) 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); + CHECK(c1.anchor == ANCHOR_CANVAS); + CHECK(c1.gravity == GRAVITY_CENTER); + CHECK(c1.scale == SCALE_FIT); + CHECK(c1.Layer() == 0); + CHECK(c1.Position() == Approx(0.0f).margin(0.00001)); + CHECK(c1.Start() == Approx(0.0f).margin(0.00001)); + CHECK(c1.End() == Approx(4.39937f).margin(0.00001)); } -TEST(Basic_Gettings_and_Setters) +TEST_CASE( "basic getters and setters", "[libopenshot][clip]" ) { // 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); + CHECK_THROWS_AS(c1.Open(), ReaderClosed); + CHECK(c1.anchor == ANCHOR_CANVAS); + CHECK(c1.gravity == GRAVITY_CENTER); + CHECK(c1.scale == SCALE_FIT); + CHECK(c1.Layer() == 0); + CHECK(c1.Position() == Approx(0.0f).margin(0.00001)); + CHECK(c1.Start() == Approx(0.0f).margin(0.00001)); + CHECK(c1.End() == Approx(0.0f).margin(0.00001)); // Change some properties c1.Layer(1); @@ -105,13 +95,13 @@ TEST(Basic_Gettings_and_Setters) 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); + CHECK(c1.Layer() == 1); + CHECK(c1.Position() == Approx(5.0f).margin(0.00001)); + CHECK(c1.Start() == Approx(3.5f).margin(0.00001)); + CHECK(c1.End() == Approx(10.5f).margin(0.00001)); } -TEST(Properties) +TEST_CASE( "properties", "[libopenshot][clip]" ) { // Create a empty clip Clip c1; @@ -136,11 +126,11 @@ TEST(Properties) properties.c_str(), properties.c_str() + properties.size(), &root, &errors ); - CHECK_EQUAL(true, success); + CHECK(success == true); // Check for specific things - CHECK_CLOSE(1.0f, root["alpha"]["value"].asDouble(), 0.01); - CHECK_EQUAL(true, root["alpha"]["keyframe"].asBool()); + CHECK(root["alpha"]["value"].asDouble() == Approx(1.0f).margin(0.01)); + CHECK(root["alpha"]["keyframe"].asBool() == true); // Get properties JSON string at frame 250 properties = c1.PropertiesJSON(250); @@ -151,11 +141,11 @@ TEST(Properties) properties.c_str(), properties.c_str() + properties.size(), &root, &errors ); - REQUIRE CHECK_EQUAL(true, success); + CHECK(success == true); // Check for specific things - CHECK_CLOSE(0.5f, root["alpha"]["value"].asDouble(), 0.01); - CHECK_EQUAL(false, root["alpha"]["keyframe"].asBool()); + CHECK(root["alpha"]["value"].asDouble() == Approx(0.5f).margin(0.01)); + CHECK_FALSE(root["alpha"]["keyframe"].asBool()); // Get properties JSON string at frame 250 (again) properties = c1.PropertiesJSON(250); @@ -166,10 +156,10 @@ TEST(Properties) properties.c_str(), properties.c_str() + properties.size(), &root, &errors ); - REQUIRE CHECK_EQUAL(true, success); + CHECK(success == true); // Check for specific things - CHECK_EQUAL(false, root["alpha"]["keyframe"].asBool()); + CHECK_FALSE(root["alpha"]["keyframe"].asBool()); // Get properties JSON string at frame 500 properties = c1.PropertiesJSON(500); @@ -180,17 +170,17 @@ TEST(Properties) properties.c_str(), properties.c_str() + properties.size(), &root, &errors ); - REQUIRE CHECK_EQUAL(true, success); + CHECK(success == true); // Check for specific things - CHECK_CLOSE(0.0f, root["alpha"]["value"].asDouble(), 0.00001); - CHECK_EQUAL(true, root["alpha"]["keyframe"].asBool()); + CHECK(root["alpha"]["value"].asDouble() == Approx(0.0f).margin(0.00001)); + CHECK(root["alpha"]["keyframe"].asBool() == true); // Free up the reader we allocated delete reader; } -TEST(Effects) +TEST_CASE( "effects", "[libopenshot][clip]" ) { // Load clip with video std::stringstream path; @@ -209,13 +199,13 @@ TEST(Effects) 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((int)pixels[pixel_index] == 255); + CHECK((int)pixels[pixel_index + 1] == 255); + CHECK((int)pixels[pixel_index + 2] == 255); + CHECK((int)pixels[pixel_index + 3] == 255); // Check the # of Effects - CHECK_EQUAL(1, (int)c10.Effects().size()); + CHECK((int)c10.Effects().size() == 1); // Add a 2nd negate effect @@ -230,16 +220,16 @@ TEST(Effects) 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((int)pixels[pixel_index] == 0); + CHECK((int)pixels[pixel_index + 1] == 0); + CHECK((int)pixels[pixel_index + 2] == 0); + CHECK((int)pixels[pixel_index + 3] == 255); // Check the # of Effects - CHECK_EQUAL(2, (int)c10.Effects().size()); + CHECK((int)c10.Effects().size() == 2); } -TEST(Verify_Parent_Timeline) +TEST_CASE( "verify parent Timeline", "[libopenshot][clip]" ) { Timeline t1(640, 480, Fraction(30,1), 44100, 2, LAYOUT_STEREO); @@ -250,15 +240,13 @@ TEST(Verify_Parent_Timeline) c1.Open(); // Check size of frame image - CHECK_EQUAL(c1.GetFrame(1)->GetImage()->width(), 1280); - CHECK_EQUAL(c1.GetFrame(1)->GetImage()->height(), 720); + CHECK(1280 == c1.GetFrame(1)->GetImage()->width()); + CHECK(720 == c1.GetFrame(1)->GetImage()->height()); // 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); + CHECK(640 == c1.GetFrame(1)->GetImage()->width()); + CHECK(360 == c1.GetFrame(1)->GetImage()->height()); } - -} // SUITE diff --git a/tests/Color.cpp b/tests/Color.cpp index 8b110f9e1..dcd4b1d6b 100644 --- a/tests/Color.cpp +++ b/tests/Color.cpp @@ -31,27 +31,24 @@ #include #include -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include + #include "Color.h" #include "Exceptions.h" #include "KeyFrame.h" #include "Json.h" -SUITE(Color) { - -TEST(Default_Constructor) +TEST_CASE( "default constructor", "[libopenshot][color]" ) { // 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); + CHECK(c1.red.GetValue(0) == Approx(0.0f).margin(0.00001)); + CHECK(c1.green.GetValue(0) == Approx(0.0f).margin(0.00001)); + CHECK(c1.blue.GetValue(0) == Approx(0.0f).margin(0.00001)); } -TEST(Keyframe_constructor) +TEST_CASE( "Keyframe constructor", "[libopenshot][color]" ) { std::vector kfs{0, 0, 0, 0}; int64_t i(0); @@ -60,13 +57,13 @@ TEST(Keyframe_constructor) } 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); + CHECK(c.red.GetLong(100) == Approx(20).margin(0.01)); + CHECK(c.green.GetLong(100) == Approx(40).margin(0.01)); + CHECK(c.blue.GetLong(100) == Approx(60).margin(0.01)); + CHECK(c.alpha.GetLong(100) == Approx(80).margin(0.01)); } -TEST(Animate_Colors) +TEST_CASE( "Animate_Colors", "[libopenshot][color]" ) { // Create an empty color openshot::Color c1; @@ -82,12 +79,12 @@ TEST(Animate_Colors) 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); + CHECK(c1.red.GetLong(500) == Approx(0).margin(0.01)); + CHECK(c1.green.GetLong(500) == Approx(187).margin(0.01)); + CHECK(c1.blue.GetLong(500) == Approx(160).margin(0.01)); } -TEST(HEX_Value) +TEST_CASE( "HEX_Value", "[libopenshot][color]" ) { // Color openshot::Color c; @@ -98,13 +95,13 @@ TEST(HEX_Value) 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)); + CHECK(c.GetColorHex(1) == "#000000"); + CHECK(c.GetColorHex(50) == "#7d7d7d"); + CHECK(c.GetColorHex(100) == "#ffffff"); } -TEST(HEX_Constructor) +TEST_CASE( "HEX_Constructor", "[libopenshot][color]" ) { // Color openshot::Color c("#4586db"); @@ -112,12 +109,12 @@ TEST(HEX_Constructor) 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)); + CHECK(c.GetColorHex(1) == "#4586db"); + CHECK(c.GetColorHex(50) == "#a0c1ed"); + CHECK(c.GetColorHex(100) == "#ffffff"); } -TEST(Distance) +TEST_CASE( "Distance", "[libopenshot][color]" ) { // Color openshot::Color c1("#040a0c"); @@ -125,11 +122,19 @@ TEST(Distance) 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); + CHECK( + 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) + ) == Approx(19.0f).margin(0.001)); + CHECK( + 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) + ) == Approx(764.0f).margin(0.001)); } -TEST(RGBA_Constructor) +TEST_CASE( "RGBA_Constructor", "[libopenshot][color]" ) { // Color openshot::Color c(69, 134, 219, 255); @@ -137,17 +142,17 @@ TEST(RGBA_Constructor) 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)); + CHECK(c.GetColorHex(1) == "#4586db"); + CHECK(c.GetColorHex(50) == "#a0c1ed"); + CHECK(c.GetColorHex(100) == "#ffffff"); // Color with alpha openshot::Color c1(69, 134, 219, 128); - CHECK_EQUAL("#4586db", c1.GetColorHex(1)); - CHECK_EQUAL(128, c1.alpha.GetInt(1)); + CHECK(c1.GetColorHex(1) == "#4586db"); + CHECK(c1.alpha.GetInt(1) == 128); } -TEST(Json) +TEST_CASE( "Json", "[libopenshot][color]" ) { openshot::Color c(128, 128, 128, 0); openshot::Color c1; @@ -158,14 +163,14 @@ TEST(Json) // Check that JSON produced is identical auto j = c.Json(); auto j1 = c1.Json(); - CHECK_EQUAL(j, j1); + CHECK(j1 == j); // Check Json::Value representation auto jv = c.JsonValue(); auto jv_string = jv.toStyledString(); - CHECK_EQUAL(jv_string, j1); + CHECK(j1 == jv_string); } -TEST(SetJson) { +TEST_CASE( "SetJson", "[libopenshot][color]" ) { const std::string json_input = R"json( { "red": { "Points": [ { "co": { "X": 1.0, "Y": 0.0 }, "interpolation": 0 } ] }, @@ -175,12 +180,10 @@ TEST(SetJson) { } )json"; openshot::Color c; - CHECK_THROW(c.SetJson("}{"), openshot::InvalidJSON); + CHECK_THROWS_AS(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); + CHECK(c.red.GetLong(10) == Approx(0).margin(0.01)); + CHECK(c.green.GetLong(10) == Approx(128).margin(0.01)); + CHECK(c.blue.GetLong(10) == Approx(64).margin(0.01)); + CHECK(c.alpha.GetLong(10) == Approx(192).margin(0.01)); } - -} // SUITE diff --git a/tests/Coordinate.cpp b/tests/Coordinate.cpp index 7dd5886c1..8fe075750 100644 --- a/tests/Coordinate.cpp +++ b/tests/Coordinate.cpp @@ -28,43 +28,39 @@ * along with OpenShot Library. If not, see . */ -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include + #include "Coordinate.h" #include "Exceptions.h" using namespace openshot; -SUITE(Coordinate) -{ - -TEST(Default_Constructor) +TEST_CASE( "default constructor", "[libopenshot][coordinate]" ) { // Create an empty coordinate Coordinate c1; - CHECK_CLOSE(0.0f, c1.X, 0.00001); - CHECK_CLOSE(0.0f, c1.Y, 0.00001); + CHECK(c1.X == Approx(0.0f).margin(0.00001)); + CHECK(c1.Y == Approx(0.0f).margin(0.00001)); } -TEST(X_Y_Constructor) +TEST_CASE( "XY constructor", "[libopenshot][coordinate]" ) { // Create an empty coordinate Coordinate c1(2,8); - CHECK_CLOSE(2.0f, c1.X, 0.00001); - CHECK_CLOSE(8.0f, c1.Y, 0.00001); + CHECK(c1.X == Approx(2.0f).margin(0.00001)); + CHECK(c1.Y == Approx(8.0f).margin(0.00001)); } -TEST(Pair_Constructor) +TEST_CASE( "std::pair constructor", "[libopenshot][coordinate]" ) { Coordinate c1(std::pair(12, 10)); - CHECK_CLOSE(12.0f, c1.X, 0.00001); - CHECK_CLOSE(10.0f, c1.Y, 0.00001); + CHECK(c1.X == Approx(12.0f).margin(0.00001)); + CHECK(c1.Y == Approx(10.0f).margin(0.00001)); } -TEST(Json) +TEST_CASE( "Json", "[libopenshot][coordinate]" ) { openshot::Coordinate c(100, 200); openshot::Coordinate c1; @@ -73,14 +69,14 @@ TEST(Json) // Check that JSON produced is identical auto j = c.Json(); auto j1 = c1.Json(); - CHECK_EQUAL(j, j1); + CHECK(j1 == j); // Check Json::Value representation auto jv = c.JsonValue(); auto jv_string = jv.toStyledString(); - CHECK_EQUAL(jv_string, j1); + CHECK(j1 == jv_string); } -TEST(SetJson) { +TEST_CASE( "SetJson", "[libopenshot][coordinate]" ) { // Construct our input Json representation const std::string json_input = R"json( { @@ -89,11 +85,9 @@ TEST(SetJson) { } )json"; openshot::Coordinate c; - CHECK_THROW(c.SetJson("}{"), openshot::InvalidJSON); + CHECK_THROWS_AS(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); + CHECK(c.X == Approx(100.0).margin(0.01)); + CHECK(c.Y == Approx(50.0).margin(0.01)); } - -} // SUITE diff --git a/tests/DummyReader.cpp b/tests/DummyReader.cpp index 806bd281e..e54e889ce 100644 --- a/tests/DummyReader.cpp +++ b/tests/DummyReader.cpp @@ -30,9 +30,7 @@ #include -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include #include "DummyReader.h" #include "Exceptions.h" @@ -40,57 +38,54 @@ #include "Fraction.h" #include "Frame.h" -SUITE (DummyReader) { - -TEST (Default_Constructor) { +TEST_CASE( "Default constructor", "[libopenshot][dummyreader]" ) { + // Create a default fraction (should be 1/1) openshot::DummyReader r; + r.Open(); // Open the reader - 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 values + CHECK(r.info.width == 1280); + CHECK(r.info.height == 768); + CHECK(r.info.fps.num == 24); + CHECK(r.info.fps.den == 1); + CHECK(r.info.sample_rate == 44100); + CHECK(r.info.channels == 2); + CHECK(r.info.duration == 30.0); - CHECK_EQUAL("DummyReader", r.Name()); + CHECK(r.Name() == "DummyReader"); auto cache = r.GetCache(); - CHECK_EQUAL(true, cache == nullptr); + CHECK(cache == nullptr); } -TEST (Constructor) { - openshot::DummyReader r(openshot::Fraction(30, 1), 1920, 1080, 48000, 2, 60.0); - r.Open(); +TEST_CASE( "Constructor", "[libopenshot][dummyreader]" ) { + // Create a default fraction (should be 1/1) + openshot::DummyReader r(openshot::Fraction(30, 1), 1920, 1080, 44100, 2, 60.0); + r.Open(); // Open the reader // 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); + CHECK(r.info.width == 1920); + CHECK(r.info.height == 1080); + CHECK(r.info.fps.num == 30); + CHECK(r.info.fps.den == 1); + CHECK(r.info.sample_rate == 44100); + CHECK(r.info.channels == 2); + CHECK(r.info.duration == 60.0); } -TEST (Blank_Frame) { +TEST_CASE( "Blank_Frame", "[libopenshot][dummyreader]" ) { + // Create a default fraction (should be 1/1) openshot::DummyReader r(openshot::Fraction(30, 1), 1920, 1080, 44100, 2, 30.0); - r.Open(); + r.Open(); // Open the reader // 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 + CHECK(r.GetFrame(1)->number == 1); + CHECK(r.GetFrame(1)->GetPixels(700)[700] == 0); // black pixel + CHECK(r.GetFrame(1)->GetPixels(701)[701] == 0); // black pixel } -TEST (Fake_Frame) { +TEST_CASE( "Fake_Frame", "[libopenshot][dummyreader]" ) { // Create cache object to hold test frames openshot::CacheMemory cache; @@ -117,24 +112,25 @@ TEST (Fake_Frame) { cache.Add(f); } + // Create a default fraction (should be 1/1) openshot::DummyReader r(openshot::Fraction(30, 1), 1920, 1080, 44100, 2, 30.0, &cache); - r.Open(); + r.Open(); // Open the reader // 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); + CHECK(r.GetFrame(1)->number == 1); + CHECK(r.GetFrame(1)->GetAudioSamples(0)[0] == 1); + CHECK(r.GetFrame(1)->GetAudioSamples(0)[1] == Approx(1.00068033).margin(0.00001)); + CHECK(r.GetFrame(1)->GetAudioSamples(0)[2] == Approx(1.00136054).margin(0.00001)); + CHECK(r.GetFrame(2)->GetAudioSamples(0)[0] == 2); + CHECK(r.GetFrame(2)->GetAudioSamples(0)[1] == Approx(2.00068033).margin(0.00001)); + CHECK(r.GetFrame(2)->GetAudioSamples(0)[2] == Approx(2.00136054).margin(0.00001)); // Clean up cache.Clear(); r.Close(); } -TEST (Invalid_Fake_Frame) { +TEST_CASE( "Invalid_Fake_Frame", "[libopenshot][dummyreader]" ) { // Create fake frames (with specific frame #, samples, and channels) auto f1 = std::make_shared(1, 1470, 2); auto f2 = std::make_shared(2, 1470, 2); @@ -144,32 +140,30 @@ TEST (Invalid_Fake_Frame) { cache.Add(f1); cache.Add(f2); + // Create a default fraction (should be 1/1) 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); + CHECK(r.GetFrame(1)->number == 1); + CHECK(r.GetFrame(2)->number == 2); + CHECK_THROWS_AS(r.GetFrame(3)->number, openshot::InvalidFile); // Clean up cache.Clear(); r.Close(); } - -TEST(Json) -{ +TEST_CASE( "Json", "[libopenshot][dummyreader]") { 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); + CHECK(json_string2 == json1); } -TEST(SetJson) -{ +TEST_CASE( "SetJson", "[libopenshot][dummyreader]") { openshot::DummyReader r1; std::stringstream json_stream; json_stream << R"json( @@ -182,11 +176,9 @@ TEST(SetJson) )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); + CHECK(r1.info.width == 1920); + CHECK(r1.info.height == 1080); + CHECK(r1.info.fps.num == 15); + CHECK(r1.info.fps.den == 1); + CHECK(r1.info.duration == 15.0); } - -} // SUITE diff --git a/tests/FFmpegReader.cpp b/tests/FFmpegReader.cpp index f5dc44350..217d601ca 100644 --- a/tests/FFmpegReader.cpp +++ b/tests/FFmpegReader.cpp @@ -31,9 +31,8 @@ #include #include -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include + #include "FFmpegReader.h" #include "Exceptions.h" #include "Frame.h" @@ -43,16 +42,13 @@ using namespace std; using namespace openshot; -SUITE(FFmpegReader) -{ - -TEST(Invalid_Path) +TEST_CASE( "Invalid_Path", "[libopenshot][ffmpegreader]" ) { // Check invalid path - CHECK_THROW(FFmpegReader(""), InvalidFile); + CHECK_THROWS_AS(FFmpegReader(""), InvalidFile); } -TEST(GetFrame_Before_Opening) +TEST_CASE( "GetFrame_Before_Opening", "[libopenshot][ffmpegreader]" ) { // Create a reader stringstream path; @@ -60,10 +56,10 @@ TEST(GetFrame_Before_Opening) FFmpegReader r(path.str()); // Check invalid path - CHECK_THROW(r.GetFrame(1), ReaderClosed); + CHECK_THROWS_AS(r.GetFrame(1), ReaderClosed); } -TEST(Check_Audio_File) +TEST_CASE( "Check_Audio_File", "[libopenshot][ffmpegreader]" ) { // Create a reader stringstream path; @@ -78,22 +74,22 @@ TEST(Check_Audio_File) float *samples = f->GetAudioSamples(0); // Check audio properties - CHECK_EQUAL(2, f->GetAudioChannelsCount()); - CHECK_EQUAL(332, f->GetAudioSamplesCount()); + CHECK(f->GetAudioChannelsCount() == 2); + CHECK(f->GetAudioSamplesCount() == 332); // 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); + CHECK(samples[0] == Approx(0.0f).margin(0.00001)); + CHECK(samples[50] == Approx(0.0f).margin(0.00001)); + CHECK(samples[100] == Approx(0.0f).margin(0.00001)); + CHECK(samples[200] == Approx(0.0f).margin(0.00001)); + CHECK(samples[230] == Approx(0.16406f).margin(0.00001)); + CHECK(samples[300] == Approx(-0.06250f).margin(0.00001)); // Close reader r.Close(); } -TEST(Check_Video_File) +TEST_CASE( "Check_Video_File", "[libopenshot][ffmpegreader]" ) { // Create a reader stringstream path; @@ -109,14 +105,14 @@ TEST(Check_Video_File) 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((int)pixels[pixel_index] == Approx(21).margin(5)); + CHECK((int)pixels[pixel_index + 1] == Approx(191).margin(5)); + CHECK((int)pixels[pixel_index + 2] == Approx(0).margin(5)); + CHECK((int)pixels[pixel_index + 3] == Approx(255).margin(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)); + CHECK(f->CheckPixel(10, 112, 21, 191, 0, 255, 5) == true); + CHECK_FALSE(f->CheckPixel(10, 112, 0, 0, 0, 0, 5)); // Get frame 1 f = r.GetFrame(2); @@ -126,20 +122,20 @@ TEST(Check_Video_File) 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((int)pixels[pixel_index] == Approx(0).margin(5)); + CHECK((int)pixels[pixel_index + 1] == Approx(96).margin(5)); + CHECK((int)pixels[pixel_index + 2] == Approx(188).margin(5)); + CHECK((int)pixels[pixel_index + 3] == Approx(255).margin(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)); + CHECK(f->CheckPixel(10, 112, 0, 96, 188, 255, 5) == true); + CHECK_FALSE(f->CheckPixel(10, 112, 0, 0, 0, 0, 5)); // Close reader r.Close(); } -TEST(Seek) +TEST_CASE( "Seek", "[libopenshot][ffmpegreader]" ) { // Create a reader stringstream path; @@ -149,54 +145,54 @@ TEST(Seek) // Get frame std::shared_ptr f = r.GetFrame(1); - CHECK_EQUAL(1, f->number); + CHECK(f->number == 1); // Get frame f = r.GetFrame(300); - CHECK_EQUAL(300, f->number); + CHECK(f->number == 300); // Get frame f = r.GetFrame(301); - CHECK_EQUAL(301, f->number); + CHECK(f->number == 301); // Get frame f = r.GetFrame(315); - CHECK_EQUAL(315, f->number); + CHECK(f->number == 315); // Get frame f = r.GetFrame(275); - CHECK_EQUAL(275, f->number); + CHECK(f->number == 275); // Get frame f = r.GetFrame(270); - CHECK_EQUAL(270, f->number); + CHECK(f->number == 270); // Get frame f = r.GetFrame(500); - CHECK_EQUAL(500, f->number); + CHECK(f->number == 500); // Get frame f = r.GetFrame(100); - CHECK_EQUAL(100, f->number); + CHECK(f->number == 100); // Get frame f = r.GetFrame(600); - CHECK_EQUAL(600, f->number); + CHECK(f->number == 600); // Get frame f = r.GetFrame(1); - CHECK_EQUAL(1, f->number); + CHECK(f->number == 1); // Get frame f = r.GetFrame(700); - CHECK_EQUAL(700, f->number); + CHECK(f->number == 700); // Close reader r.Close(); } -TEST(Frame_Rate) +TEST_CASE( "Frame_Rate", "[libopenshot][ffmpegreader]" ) { // Create a reader stringstream path; @@ -206,13 +202,13 @@ TEST(Frame_Rate) // Verify detected frame rate openshot::Fraction rate = r.info.fps; - CHECK_EQUAL(24, rate.num); - CHECK_EQUAL(1, rate.den); + CHECK(rate.num == 24); + CHECK(rate.den == 1); r.Close(); } -TEST(Multiple_Open_and_Close) +TEST_CASE( "Multiple_Open_and_Close", "[libopenshot][ffmpegreader]" ) { // Create a reader stringstream path; @@ -222,7 +218,7 @@ TEST(Multiple_Open_and_Close) // Get frame that requires a seek std::shared_ptr f = r.GetFrame(1200); - CHECK_EQUAL(1200, f->number); + CHECK(f->number == 1200); // Close and Re-open the reader r.Close(); @@ -230,9 +226,9 @@ TEST(Multiple_Open_and_Close) // Get frame f = r.GetFrame(1); - CHECK_EQUAL(1, f->number); + CHECK(f->number == 1); f = r.GetFrame(250); - CHECK_EQUAL(250, f->number); + CHECK(f->number == 250); // Close and Re-open the reader r.Close(); @@ -240,15 +236,15 @@ TEST(Multiple_Open_and_Close) // Get frame f = r.GetFrame(750); - CHECK_EQUAL(750, f->number); + CHECK(f->number == 750); f = r.GetFrame(1000); - CHECK_EQUAL(1000, f->number); + CHECK(f->number == 1000); // Close reader r.Close(); } -TEST(Verify_Parent_Timeline) +TEST_CASE( "verify parent Timeline", "[libopenshot][ffmpegreader]" ) { // Create a reader stringstream path; @@ -257,8 +253,8 @@ TEST(Verify_Parent_Timeline) r.Open(); // Check size of frame image - CHECK_EQUAL(r.GetFrame(1)->GetImage()->width(), 1280); - CHECK_EQUAL(r.GetFrame(1)->GetImage()->height(), 720); + CHECK(r.GetFrame(1)->GetImage()->width() == 1280); + CHECK(r.GetFrame(1)->GetImage()->height() == 720); r.GetFrame(1)->GetImage()->save("reader-1.png", "PNG"); // Create a Clip associated with this reader @@ -266,16 +262,14 @@ TEST(Verify_Parent_Timeline) 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); + CHECK(r.GetFrame(1)->GetImage()->width() == 1280); + CHECK(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); + CHECK(r.GetFrame(1)->GetImage()->width() == 640); + CHECK(r.GetFrame(1)->GetImage()->height() == 360); } - -} // SUITE(FFmpegReader) diff --git a/tests/FFmpegWriter.cpp b/tests/FFmpegWriter.cpp index 0160ac929..059bbb4de 100644 --- a/tests/FFmpegWriter.cpp +++ b/tests/FFmpegWriter.cpp @@ -31,9 +31,8 @@ #include #include -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include + #include "FFmpegWriter.h" #include "Exceptions.h" #include "FFmpegReader.h" @@ -43,8 +42,7 @@ using namespace std; using namespace openshot; -SUITE(FFMpegWriter) { -TEST(Webm) +TEST_CASE( "Webm", "[libopenshot][ffmpegwriter]" ) { // Reader stringstream path; @@ -73,9 +71,9 @@ TEST(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); + CHECK(r1.GetFrame(1)->GetAudioChannelsCount() == 2); + CHECK(r1.info.fps.num == 24); + CHECK(r1.info.fps.den == 1); // Get a specific frame std::shared_ptr f = r1.GetFrame(8); @@ -85,13 +83,13 @@ TEST(Webm) 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); + CHECK((int)pixels[pixel_index] == Approx(23).margin(5)); + CHECK((int)pixels[pixel_index + 1] == Approx(23).margin(5)); + CHECK((int)pixels[pixel_index + 2] == Approx(23).margin(5)); + CHECK((int)pixels[pixel_index + 3] == Approx(255).margin(5)); } -TEST(Options_Overloads) +TEST_CASE( "Options_Overloads", "[libopenshot][ffmpegwriter]" ) { // Reader stringstream path; @@ -120,16 +118,14 @@ TEST(Options_Overloads) r1.Open(); // Verify implied settings - CHECK_EQUAL(true, r1.info.has_audio); - CHECK_EQUAL(true, r1.info.has_video); + CHECK(r1.info.has_audio == true); + CHECK(r1.info.has_video == true); - CHECK_EQUAL(2, r1.GetFrame(1)->GetAudioChannelsCount()); - CHECK_EQUAL(LAYOUT_STEREO, r1.info.channel_layout); + CHECK(r1.GetFrame(1)->GetAudioChannelsCount() == 2); + CHECK(r1.info.channel_layout == LAYOUT_STEREO); - 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); + CHECK(r1.info.pixel_ratio.num == 1); + CHECK(r1.info.pixel_ratio.den == 1); + CHECK_FALSE(r1.info.interlaced_frame); + CHECK(r1.info.top_field_first == true); } - -} // SUITE() diff --git a/tests/Fraction.cpp b/tests/Fraction.cpp index 760a83807..8736abaf8 100644 --- a/tests/Fraction.cpp +++ b/tests/Fraction.cpp @@ -28,129 +28,123 @@ * along with OpenShot Library. If not, see . */ -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include + #include "Fraction.h" using namespace std; using namespace openshot; -SUITE(Fraction) -{ - -TEST(Constructors) +TEST_CASE( "Constructors", "[libopenshot][fraction]" ) { // 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); + CHECK(f1.num == 1); + CHECK(f1.den == 1); + CHECK(f1.ToFloat() == Approx(1.0f).margin(0.00001)); + CHECK(f1.ToDouble() == Approx(1.0f).margin(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); + CHECK(f1.num == 1); + CHECK(f1.den == 1); + CHECK(f1.ToFloat() == Approx(1.0f).margin(0.00001)); + CHECK(f1.ToDouble() == Approx(1.0f).margin(0.00001)); } -TEST(Alt_Constructors) +TEST_CASE( "Alt_Constructors", "[libopenshot][fraction]" ) { // Use the delegating constructor for std::pair std::pair args{24, 1}; Fraction f1(args); - CHECK_EQUAL(24, f1.num); - CHECK_EQUAL(1, f1.den); - CHECK_CLOSE(24.0f, f1.ToFloat(), 0.00001); + CHECK(f1.num == 24); + CHECK(f1.den == 1); + CHECK(f1.ToFloat() == Approx(24.0f).margin(0.00001)); // Use the delegating constructor for std::vector std::vector v{30000, 1001}; Fraction f2(v); - CHECK_CLOSE(30000.0/1001.0, f2.ToFloat(), 0.00001); + CHECK(f2.ToFloat() == Approx(30000.0/1001.0).margin(0.00001)); // Use the delegating constructor for std::map std::map 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); + CHECK(f3.den == 1001); + CHECK(f3.num == 24000); + CHECK(f3.Reciprocal().ToFloat() == Approx(1001.0/24000.0).margin(0.00001)); } -TEST(WxH_640_480) +TEST_CASE( "WxH_640_480", "[libopenshot][fraction]" ) { // 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); + CHECK(f1.num == 640); + CHECK(f1.den == 480); + CHECK(f1.ToFloat() == Approx(1.33333f).margin(0.00001)); + CHECK(f1.ToDouble() == Approx(1.33333f).margin(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); + CHECK(f1.num == 4); + CHECK(f1.den == 3); + CHECK(f1.ToFloat() == Approx(1.33333f).margin(0.00001)); + CHECK(f1.ToDouble() == Approx(1.33333f).margin(0.00001)); } -TEST(WxH_1280_720) +TEST_CASE( "WxH_1280_720", "[libopenshot][fraction]" ) { // 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); + CHECK(f1.num == 1280); + CHECK(f1.den == 720); + CHECK(f1.ToFloat() == Approx(1.77777f).margin(0.00001)); + CHECK(f1.ToDouble() == Approx(1.77777f).margin(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); + CHECK(f1.num == 16); + CHECK(f1.den == 9); + CHECK(f1.ToFloat() == Approx(1.77777f).margin(0.00001)); + CHECK(f1.ToDouble() == Approx(1.77777f).margin(0.00001)); } -TEST(Reciprocal) +TEST_CASE( "Reciprocal", "[libopenshot][fraction]" ) { // 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); + CHECK(f1.num == 1280); + CHECK(f1.den == 720); + CHECK(f1.ToFloat() == Approx(1.77777f).margin(0.00001)); + CHECK(f1.ToDouble() == Approx(1.77777f).margin(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); + CHECK(f2.num == 720); + CHECK(f2.den == 1280); + CHECK(f2.ToFloat() == Approx(0.5625f).margin(0.00001)); + CHECK(f2.ToDouble() == Approx(0.5625f).margin(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); + CHECK(f1.num == 1280); + CHECK(f1.den == 720); + CHECK(f1.ToFloat() == Approx(1.77777f).margin(0.00001)); + CHECK(f1.ToDouble() == Approx(1.77777f).margin(0.00001)); } - -} // SUITE diff --git a/tests/Frame.cpp b/tests/Frame.cpp index 9038f8b85..0a780a323 100644 --- a/tests/Frame.cpp +++ b/tests/Frame.cpp @@ -32,52 +32,52 @@ #include #include -#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 #ifdef USE_OPENCV -#include +#define int64 opencv_broken_int +#define uint64 opencv_broken_uint +#include +#undef int64 +#undef uint64 #endif -using namespace openshot; +#include -SUITE(Frame_Tests) -{ +#include "Clip.h" +#include "Fraction.h" +#include "Frame.h" -TEST(Default_Constructor) +using namespace openshot; + +TEST_CASE( "Default_Constructor", "[libopenshot][frame]" ) { // Create a "blank" default Frame std::shared_ptr f1(new Frame()); - CHECK(f1 != nullptr); // Test aborts here if we didn't get a Frame + REQUIRE(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()); + CHECK(f1->GetHeight() == 1); + CHECK(f1->GetWidth() == 1); + CHECK(f1->SampleRate() == 44100); + CHECK(f1->GetAudioChannelsCount() == 2); // Should be false until we load or create contents - CHECK_EQUAL(false, f1->has_image_data); - CHECK_EQUAL(false, f1->has_audio_data); + CHECK(f1->has_image_data == false); + CHECK(f1->has_audio_data == false); // Calling GetImage() paints a blank frame, by default std::shared_ptr i1 = f1->GetImage(); - CHECK(i1 != nullptr); + REQUIRE(i1 != nullptr); - CHECK_EQUAL(true,f1->has_image_data); - CHECK_EQUAL(false,f1->has_audio_data); + CHECK(f1->has_image_data == true); + CHECK(f1->has_audio_data == false); } -TEST(Data_Access) +TEST_CASE( "Data_Access", "[libopenshot][frame]" ) { // Create a video clip std::stringstream path; @@ -88,15 +88,15 @@ TEST(Data_Access) // Get first frame std::shared_ptr f1 = c1.GetFrame(1); - CHECK(f1 != nullptr); + REQUIRE(f1 != nullptr); - CHECK_EQUAL(1, f1->number); - CHECK_EQUAL(1280, f1->GetWidth()); - CHECK_EQUAL(720, f1->GetHeight()); + CHECK(f1->number == 1); + CHECK(f1->GetWidth() == 1280); + CHECK(f1->GetHeight() == 720); } -TEST(AddImage_QImage) +TEST_CASE( "AddImage_QImage", "[libopenshot][frame]" ) { // Create a "blank" default Frame std::shared_ptr f1(new Frame()); @@ -104,21 +104,21 @@ TEST(AddImage_QImage) // Load an image std::stringstream path; path << TEST_MEDIA_PATH << "front.png"; - std::shared_ptr i1(new QImage(QString::fromStdString(path.str()))) ; + auto i1 = std::make_shared(QString::fromStdString(path.str())); - CHECK(f1 != nullptr); // Test aborts here if we didn't get a Frame - CHECK_EQUAL(false, i1->isNull()); + REQUIRE(f1 != nullptr); // Test aborts here if we didn't get a Frame + CHECK(i1->isNull() == false); 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); + CHECK(f1->GetHeight() == i1->height()); + CHECK(f1->GetWidth() == i1->width()); + CHECK(f1->has_image_data == true); } -TEST(Copy_Constructor) +TEST_CASE( "Copy_Constructor", "[libopenshot][frame]" ) { // Create a dummy Frame openshot::Frame f1(1, 800, 600, "#000000"); @@ -126,38 +126,38 @@ TEST(Copy_Constructor) // Load an image std::stringstream path; path << TEST_MEDIA_PATH << "front.png"; - std::shared_ptr i1( new QImage(QString::fromStdString(path.str())) ); + auto i1 = std::make_shared(QString::fromStdString(path.str())); - CHECK_EQUAL(false, i1->isNull()); + CHECK(i1->isNull() == false); // 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(f1.GetHeight() == f2.GetHeight()); + CHECK(f1.GetWidth() == f2.GetWidth()); - CHECK_EQUAL(f1.has_image_data, f2.has_image_data); - CHECK_EQUAL(f1.has_audio_data, f2.has_audio_data); + CHECK(f1.has_image_data == f2.has_image_data); + CHECK(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(par1.num == par2.num); + CHECK(par1.den == par2.den); - CHECK_EQUAL(f1.SampleRate(), f2.SampleRate()); - CHECK_EQUAL(f1.GetAudioChannelsCount(), f2.GetAudioChannelsCount()); - CHECK_EQUAL(f1.ChannelsLayout(), f2.ChannelsLayout()); + CHECK(f1.SampleRate() == f2.SampleRate()); + CHECK(f1.GetAudioChannelsCount() == f2.GetAudioChannelsCount()); + CHECK(f1.ChannelsLayout() == f2.ChannelsLayout()); - CHECK_EQUAL(f1.GetBytes(), f2.GetBytes()); - CHECK_EQUAL(f1.GetAudioSamplesCount(), f2.GetAudioSamplesCount()); + CHECK(f1.GetBytes() == f2.GetBytes()); + CHECK(f1.GetAudioSamplesCount() == f2.GetAudioSamplesCount()); } #ifdef USE_OPENCV -TEST(Convert_Image) +TEST_CASE( "Convert_Image", "[libopenshot][opencv][frame]" ) { // Create a video clip std::stringstream path; @@ -171,13 +171,11 @@ TEST(Convert_Image) // Get first Mat image cv::Mat cvimage = f1->GetImageCV(); - CHECK(!cvimage.empty()); + CHECK_FALSE(cvimage.empty()); - CHECK_EQUAL(1, f1->number); - CHECK_EQUAL(f1->GetWidth(), cvimage.cols); - CHECK_EQUAL(f1->GetHeight(), cvimage.rows); - CHECK_EQUAL(3, cvimage.channels()); + CHECK(f1->number == 1); + CHECK(f1->GetWidth() == cvimage.cols); + CHECK(f1->GetHeight() == cvimage.rows); + CHECK(cvimage.channels() == 3); } #endif - -} // SUITE(Frame_Tests) diff --git a/tests/FrameMapper.cpp b/tests/FrameMapper.cpp index d586c30c2..2636016e0 100644 --- a/tests/FrameMapper.cpp +++ b/tests/FrameMapper.cpp @@ -28,9 +28,8 @@ * along with OpenShot Library. If not, see . */ -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include + #include "CacheMemory.h" #include "Clip.h" #include "DummyReader.h" @@ -40,36 +39,33 @@ #include "FrameMapper.h" #include "Timeline.h" -using namespace std; using namespace openshot; -SUITE(FrameMapper) { - -TEST(NoOp_GetMappedFrame) +TEST_CASE( "NoOp_GetMappedFrame", "[libopenshot][framemapper]" ) { // Create a reader DummyReader r(Fraction(24,1), 720, 480, 22000, 2, 5.0); // Create mapping between 24 fps and 24 fps without pulldown FrameMapper mapping(&r, Fraction(24, 1), PULLDOWN_NONE, 22000, 2, LAYOUT_STEREO); - CHECK_EQUAL("FrameMapper", mapping.Name()); + CHECK(mapping.Name() == "FrameMapper"); // Should find this frame MappedFrame f = mapping.GetMappedFrame(100); - CHECK_EQUAL(100, f.Odd.Frame); - CHECK_EQUAL(100, f.Even.Frame); + CHECK(f.Odd.Frame == 100); + CHECK(f.Even.Frame == 100); // Should return end frame f = mapping.GetMappedFrame(150); - CHECK_EQUAL(120, f.Odd.Frame); - CHECK_EQUAL(120, f.Even.Frame); + CHECK(f.Odd.Frame == 120); + CHECK(f.Even.Frame == 120); mapping.Close(); mapping.Reader(nullptr); - CHECK_THROW(mapping.Reader(), ReaderClosed); + CHECK_THROWS_AS(mapping.Reader(), ReaderClosed); } -TEST(Invalid_Frame_Too_Small) +TEST_CASE( "Invalid_Frame_Too_Small", "[libopenshot][framemapper]" ) { // Create a reader DummyReader r(Fraction(24,1), 720, 480, 22000, 2, 5.0); @@ -78,11 +74,11 @@ TEST(Invalid_Frame_Too_Small) FrameMapper mapping(&r, Fraction(30000, 1001), PULLDOWN_CLASSIC, 22000, 2, LAYOUT_STEREO); // Check invalid frame number - CHECK_THROW(mapping.GetMappedFrame(0), OutOfBoundsFrame); + CHECK_THROWS_AS(mapping.GetMappedFrame(0), OutOfBoundsFrame); } -TEST(24_fps_to_30_fps_Pulldown_Classic) +TEST_CASE( "24_fps_to_30_fps_Pulldown_Classic", "[libopenshot][framemapper]" ) { // Create a reader DummyReader r(Fraction(24,1), 720, 480, 22000, 2, 5.0); @@ -93,13 +89,13 @@ TEST(24_fps_to_30_fps_Pulldown_Classic) MappedFrame frame3 = mapping.GetMappedFrame(3); // Check for 3 fields of frame 2 - CHECK_EQUAL(2, frame2.Odd.Frame); - CHECK_EQUAL(2, frame2.Even.Frame); - CHECK_EQUAL(2, frame3.Odd.Frame); - CHECK_EQUAL(3, frame3.Even.Frame); + CHECK(frame2.Odd.Frame == 2); + CHECK(frame2.Even.Frame == 2); + CHECK(frame3.Odd.Frame == 2); + CHECK(frame3.Even.Frame == 3); } -TEST(24_fps_to_30_fps_Pulldown_Advanced) +TEST_CASE( "24_fps_to_30_fps_Pulldown_Advanced", "[libopenshot][framemapper]" ) { // Create a reader DummyReader r(Fraction(24,1), 720, 480, 22000, 2, 5.0); @@ -111,15 +107,15 @@ TEST(24_fps_to_30_fps_Pulldown_Advanced) MappedFrame frame4 = mapping.GetMappedFrame(4); // Check for advanced pulldown (only 1 fake frame) - CHECK_EQUAL(2, frame2.Odd.Frame); - CHECK_EQUAL(2, frame2.Even.Frame); - CHECK_EQUAL(2, frame3.Odd.Frame); - CHECK_EQUAL(3, frame3.Even.Frame); - CHECK_EQUAL(3, frame4.Odd.Frame); - CHECK_EQUAL(3, frame4.Even.Frame); + CHECK(frame2.Odd.Frame == 2); + CHECK(frame2.Even.Frame == 2); + CHECK(frame3.Odd.Frame == 2); + CHECK(frame3.Even.Frame == 3); + CHECK(frame4.Odd.Frame == 3); + CHECK(frame4.Even.Frame == 3); } -TEST(24_fps_to_30_fps_Pulldown_None) +TEST_CASE( "24_fps_to_30_fps_Pulldown_None", "[libopenshot][framemapper]" ) { // Create a reader DummyReader r(Fraction(24,1), 720, 480, 22000, 2, 5.0); @@ -130,13 +126,13 @@ TEST(24_fps_to_30_fps_Pulldown_None) MappedFrame frame5 = mapping.GetMappedFrame(5); // Check for advanced pulldown (only 1 fake frame) - CHECK_EQUAL(4, frame4.Odd.Frame); - CHECK_EQUAL(4, frame4.Even.Frame); - CHECK_EQUAL(4, frame5.Odd.Frame); - CHECK_EQUAL(4, frame5.Even.Frame); + CHECK(frame4.Odd.Frame == 4); + CHECK(frame4.Even.Frame == 4); + CHECK(frame5.Odd.Frame == 4); + CHECK(frame5.Even.Frame == 4); } -TEST(30_fps_to_24_fps_Pulldown_Classic) +TEST_CASE( "30_fps_to_24_fps_Pulldown_Classic", "[libopenshot][framemapper]" ) { // Create a reader DummyReader r(Fraction(30, 1), 720, 480, 22000, 2, 5.0); @@ -148,15 +144,15 @@ TEST(30_fps_to_24_fps_Pulldown_Classic) MappedFrame frame5 = mapping.GetMappedFrame(5); // Check for advanced pulldown (only 1 fake frame) - CHECK_EQUAL(4, frame3.Odd.Frame); - CHECK_EQUAL(3, frame3.Even.Frame); - CHECK_EQUAL(5, frame4.Odd.Frame); - CHECK_EQUAL(4, frame4.Even.Frame); - CHECK_EQUAL(6, frame5.Odd.Frame); - CHECK_EQUAL(6, frame5.Even.Frame); + CHECK(frame3.Odd.Frame == 4); + CHECK(frame3.Even.Frame == 3); + CHECK(frame4.Odd.Frame == 5); + CHECK(frame4.Even.Frame == 4); + CHECK(frame5.Odd.Frame == 6); + CHECK(frame5.Even.Frame == 6); } -TEST(30_fps_to_24_fps_Pulldown_Advanced) +TEST_CASE( "30_fps_to_24_fps_Pulldown_Advanced", "[libopenshot][framemapper]" ) { // Create a reader DummyReader r(Fraction(30, 1), 720, 480, 22000, 2, 5.0); @@ -168,15 +164,15 @@ TEST(30_fps_to_24_fps_Pulldown_Advanced) MappedFrame frame4 = mapping.GetMappedFrame(4); // Check for advanced pulldown (only 1 fake frame) - CHECK_EQUAL(2, frame2.Odd.Frame); - CHECK_EQUAL(2, frame2.Even.Frame); - CHECK_EQUAL(4, frame3.Odd.Frame); - CHECK_EQUAL(4, frame3.Even.Frame); - CHECK_EQUAL(5, frame4.Odd.Frame); - CHECK_EQUAL(5, frame4.Even.Frame); + CHECK(frame2.Odd.Frame == 2); + CHECK(frame2.Even.Frame == 2); + CHECK(frame3.Odd.Frame == 4); + CHECK(frame3.Even.Frame == 4); + CHECK(frame4.Odd.Frame == 5); + CHECK(frame4.Even.Frame == 5); } -TEST(30_fps_to_24_fps_Pulldown_None) +TEST_CASE( "30_fps_to_24_fps_Pulldown_None", "[libopenshot][framemapper]" ) { // Create a reader DummyReader r(Fraction(30, 1), 720, 480, 22000, 2, 5.0); @@ -187,16 +183,16 @@ TEST(30_fps_to_24_fps_Pulldown_None) MappedFrame frame5 = mapping.GetMappedFrame(5); // Check for advanced pulldown (only 1 fake frame) - CHECK_EQUAL(4, frame4.Odd.Frame); - CHECK_EQUAL(4, frame4.Even.Frame); - CHECK_EQUAL(6, frame5.Odd.Frame); - CHECK_EQUAL(6, frame5.Even.Frame); + CHECK(frame4.Odd.Frame == 4); + CHECK(frame4.Even.Frame == 4); + CHECK(frame5.Odd.Frame == 6); + CHECK(frame5.Even.Frame == 6); } -TEST(resample_audio_48000_to_41000) +TEST_CASE( "resample_audio_48000_to_41000", "[libopenshot][framemapper]" ) { // Create a reader: 24 fps, 2 channels, 48000 sample rate - stringstream path; + std::stringstream path; path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4"; FFmpegReader r(path.str()); @@ -205,25 +201,25 @@ TEST(resample_audio_48000_to_41000) map.Open(); // Check details - CHECK_EQUAL(3, map.GetFrame(1)->GetAudioChannelsCount()); - CHECK_EQUAL(1470, map.GetFrame(1)->GetAudioSamplesCount()); - CHECK_EQUAL(1470, map.GetFrame(2)->GetAudioSamplesCount()); - CHECK_EQUAL(1470, map.GetFrame(50)->GetAudioSamplesCount()); + CHECK(map.GetFrame(1)->GetAudioChannelsCount() == 3); + CHECK(map.GetFrame(1)->GetAudioSamplesCount() == 1470); + CHECK(map.GetFrame(2)->GetAudioSamplesCount() == 1470); + CHECK(map.GetFrame(50)->GetAudioSamplesCount() == 1470); // Change mapping data map.ChangeMapping(Fraction(25,1), PULLDOWN_NONE, 22050, 1, LAYOUT_MONO); // Check details - CHECK_EQUAL(1, map.GetFrame(1)->GetAudioChannelsCount()); - CHECK_CLOSE(882, map.GetFrame(1)->GetAudioSamplesCount(), 10.0); - CHECK_CLOSE(882, map.GetFrame(2)->GetAudioSamplesCount(), 10.0); - CHECK_CLOSE(882, map.GetFrame(50)->GetAudioSamplesCount(), 10.0); + CHECK(map.GetFrame(1)->GetAudioChannelsCount() == 1); + CHECK(map.GetFrame(1)->GetAudioSamplesCount() == Approx(882).margin(10.0)); + CHECK(map.GetFrame(2)->GetAudioSamplesCount() == Approx(882).margin(10.0)); + CHECK(map.GetFrame(50)->GetAudioSamplesCount() == Approx(882).margin(10.0)); // Close mapper map.Close(); } -TEST(resample_audio_mapper) { +TEST_CASE( "resample_audio_mapper", "[libopenshot][framemapper]" ) { // This test verifies that audio data can be resampled on FrameMapper // instances, even on frame rates that do not divide evenly, and that no audio data is misplaced // or duplicated. We verify this by creating a SIN wave, add those data points to a DummyReader, @@ -263,11 +259,11 @@ TEST(resample_audio_mapper) { } // Create a default fraction (should be 1/1) - openshot::DummyReader r(openshot::Fraction(30, 1), 1920, 1080, 44100, 2, 30.0, &cache); + openshot::DummyReader r(openshot::Fraction(30, 1), 1, 1, 44100, 2, 30.0, &cache); r.Open(); // Open the reader // Sample rates - vector arr = { 44100, 16000 }; + std::vector arr = { 44100, 16000 }; for (auto& rate : arr) { // Reset SIN wave ANGLE = 0.0; @@ -294,14 +290,14 @@ TEST(resample_audio_mapper) { float resampled_value = map.GetFrame(frame_index)->GetAudioSample(0, sample_index, 1.0); // TODO: 0.1 is much to broad to accurately test this, but without this, all the resampled values are too far away from expected - CHECK_CLOSE(sample_value, resampled_value, 0.1); + CHECK(resampled_value == Approx(sample_value).margin(0.1)); } // Increment sample value num_samples += map.GetFrame(frame_index)->GetAudioSamplesCount(); } // Verify samples per second is correct (i.e. 44100) - CHECK_EQUAL(num_samples, map.info.sample_rate); + CHECK(map.info.sample_rate == num_samples); // Create Timeline (same specs as reader) Timeline t1(map.info.width, map.info.height, map.info.fps, rate, map.info.channels, map.info.channel_layout); @@ -334,19 +330,20 @@ TEST(resample_audio_mapper) { ANGLE = 0.0; for (int frame_index = 1; frame_index < 24; frame_index++) { - t1.GetFrame(frame_index); - for (int sample_index = 0; sample_index < t1.GetFrame(frame_index)->GetAudioSamplesCount(); sample_index++) { + auto f = t1.GetFrame(frame_index); + auto sample_count = f->GetAudioSamplesCount(); + for (int i = 0; i < sample_count; i++) { // Calculate sin wave float sample_value = abs(float(AMPLITUDE * sin(ANGLE) + OFFSET)); ANGLE += (2 * M_PI) / (NUM_SAMPLES * resample_multiplier); // Verify each mapped sample value is correct (after being redistributed by the FrameMapper) - float resampled_value = t1.GetFrame(frame_index)->GetAudioSample(0, sample_index, 1.0); + float resampled_value = f->GetAudioSample(0, i, 1.0); // TODO: 0.1 is much to broad to accurately test this, but without this, all the resampled values are too far away from expected // Testing wave value X 2, since we have 2 overlapping clips - CHECK_CLOSE(sample_value * 2.0, resampled_value, 0.1); + CHECK(resampled_value == Approx(sample_value * 2.0).margin(0.1)); } } @@ -362,7 +359,7 @@ TEST(resample_audio_mapper) { r.Close(); } -TEST(redistribute_samples_per_frame) { +TEST_CASE( "redistribute_samples_per_frame", "[libopenshot][framemapper]" ) { // This test verifies that audio data is correctly aligned on // FrameMapper instances. We do this by creating 2 Clips based on the same parent reader // (i.e. same exact audio sample data). We use a Timeline to overlap these clips @@ -404,7 +401,7 @@ TEST(redistribute_samples_per_frame) { r.Open(); // Open the reader // Sample rates - vector arr = { 24, 30, 60 }; + std::vector arr = { 24, 30, 60 }; for (auto& fps : arr) { // Map to 24 fps, which should create a variable # of samples per frame FrameMapper map(&r, Fraction(fps,1), PULLDOWN_NONE, 44100, 2, LAYOUT_STEREO); @@ -414,16 +411,16 @@ TEST(redistribute_samples_per_frame) { // Loop through samples, and verify FrameMapper didn't mess up individual sample values sample_value = 0; for (int frame_index = 1; frame_index <= map.info.fps.ToInt(); frame_index++) { - for (int sample_index = 0; sample_index < map.GetFrame(frame_index)->GetAudioSamplesCount(); sample_index++) { + for (int i = 0; i < map.GetFrame(frame_index)->GetAudioSamplesCount(); i++) { // Verify each mapped sample value is correct (after being redistributed by the FrameMapper) - CHECK_EQUAL(sample_value + sample_index, map.GetFrame(frame_index)->GetAudioSample(0, sample_index, 1.0)); + CHECK(map.GetFrame(frame_index)->GetAudioSample(0, i, 1.0) == sample_value + i); } // Increment sample value sample_value += map.GetFrame(frame_index)->GetAudioSamplesCount(); } // Verify samples per second is correct (i.e. 44100) - CHECK_EQUAL(sample_value, map.info.sample_rate); + CHECK(map.info.sample_rate == sample_value); // Create Timeline (same specs as reader) Timeline t1(map.info.width, map.info.height, map.info.fps, 44100, map.info.channels, map.info.channel_layout); @@ -467,7 +464,7 @@ TEST(redistribute_samples_per_frame) { // Check if sample_value - previous_value == 2 // This should be true, because the DummyReader is added twice to the Timeline, and is overlapping // This should be an ever increasing linear curve, increasing by 2 each sample on the Timeline - CHECK_EQUAL(2, sample_diff); + CHECK(sample_diff == 2); // Set previous sample value previous_sample_value = t1.GetFrame(frame_index)->GetAudioSample(0, sample_index, 1.0); @@ -485,7 +482,7 @@ TEST(redistribute_samples_per_frame) { r.Close(); } -TEST(Json) +TEST_CASE( "Json", "[libopenshot][framemapper]" ) { DummyReader r(Fraction(30,1), 1280, 720, 48000, 2, 5.0); FrameMapper map(&r, Fraction(30, 1), PULLDOWN_NONE, 48000, 2, LAYOUT_STEREO); @@ -494,8 +491,6 @@ TEST(Json) const std::string map_config = map.Json(); map.SetJson(map_config); - CHECK_EQUAL(48000, map.info.sample_rate); - CHECK_EQUAL(30, map.info.fps.num); + CHECK(map.info.sample_rate == 48000); + CHECK(map.info.fps.num == 30); } - -} // SUITE diff --git a/tests/ImageWriter.cpp b/tests/ImageWriter.cpp index c4afaee00..d50d73c5b 100644 --- a/tests/ImageWriter.cpp +++ b/tests/ImageWriter.cpp @@ -28,51 +28,46 @@ * along with OpenShot Library. If not, see . */ +#ifdef USE_IMAGEMAGICK + #include #include -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include -#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) +TEST_CASE( "Gif", "[libopenshot][imagewriter]" ) { // Reader --------------- // Bad path FFmpegReader bad_r("/tmp/bleeblorp.xls", false); - CHECK_THROW(bad_r.Open(), InvalidFile); + CHECK_THROWS_AS(bad_r.Open(), InvalidFile); // Good path - stringstream path; + std::stringstream path; path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4"; FFmpegReader r(path.str()); // Read-before-open error - CHECK_THROW(r.GetFrame(1), ReaderClosed); + CHECK_THROWS_AS(r.GetFrame(1), ReaderClosed); r.Open(); /* WRITER ---------------- */ ImageWriter w("output1.gif"); - CHECK_EQUAL(false, w.IsOpen()); + CHECK_FALSE(w.IsOpen()); // Check for exception on write-before-open - CHECK_THROW(w.WriteFrame(&r, 500, 504), WriterClosed); + CHECK_THROWS_AS(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); @@ -91,18 +86,18 @@ TEST(Gif) ImageReader r1("output1.gif[4]"); // Basic Reader state queries - CHECK_EQUAL("ImageReader", r1.Name()); + CHECK(r1.Name() == "ImageReader"); CacheBase* c = r1.GetCache(); - CHECK_EQUAL(true, c == nullptr); + CHECK(c == nullptr); - CHECK_EQUAL(false, r1.IsOpen()); + CHECK_FALSE(r1.IsOpen()); r1.Open(); - CHECK_EQUAL(true, r1.IsOpen()); + CHECK(r1.IsOpen() == true); // Verify various settings - CHECK_EQUAL(r.info.width, r1.info.width); - CHECK_EQUAL(r.info.height, r1.info.height); + CHECK(r1.info.width == r.info.width); + CHECK(r1.info.height == r.info.height); // Get a specific frame std::shared_ptr f = r1.GetFrame(8); @@ -112,11 +107,9 @@ TEST(Gif) 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); + CHECK((int)pixels[pixel_index] == Approx(20).margin(5)); + CHECK((int)pixels[pixel_index + 1] == Approx(18).margin(5)); + CHECK((int)pixels[pixel_index + 2] == Approx(11).margin(5)); + CHECK((int)pixels[pixel_index + 3] == Approx(255).margin(5)); } - -} // SUITE -#endif +#endif // USE_IMAGEMAGICK diff --git a/tests/KeyFrame.cpp b/tests/KeyFrame.cpp index f4718dccb..b919e8a5f 100644 --- a/tests/KeyFrame.cpp +++ b/tests/KeyFrame.cpp @@ -28,67 +28,63 @@ * along with OpenShot Library. If not, see . */ -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include + #include "KeyFrame.h" #include "Exceptions.h" #include "Coordinate.h" #include "Fraction.h" #include "Point.h" -using namespace std; using namespace openshot; -SUITE(Keyframe) { - -TEST(GetPoint_With_No_Points) +TEST_CASE( "GetPoint_With_No_Points", "[libopenshot][keyframe]" ) { // Create an empty keyframe Keyframe k1; - CHECK_THROW(k1.GetPoint(0), OutOfBoundsPoint); + CHECK_THROWS_AS(k1.GetPoint(0), OutOfBoundsPoint); } -TEST(GetPoint_With_1_Points) +TEST_CASE( "GetPoint_With_1_Points", "[libopenshot][keyframe]" ) { // Create an empty keyframe Keyframe k1; k1.AddPoint(openshot::Point(2,3)); - CHECK_THROW(k1.GetPoint(-1), OutOfBoundsPoint); - CHECK_EQUAL(1, k1.GetCount()); - CHECK_CLOSE(2.0f, k1.GetPoint(0).co.X, 0.00001); - CHECK_CLOSE(3.0f, k1.GetPoint(0).co.Y, 0.00001); - CHECK_THROW(k1.GetPoint(1), OutOfBoundsPoint); + CHECK_THROWS_AS(k1.GetPoint(-1), OutOfBoundsPoint); + CHECK(k1.GetCount() == 1); + CHECK(k1.GetPoint(0).co.X == Approx(2.0f).margin(0.00001)); + CHECK(k1.GetPoint(0).co.Y == Approx(3.0f).margin(0.00001)); + CHECK_THROWS_AS(k1.GetPoint(1), OutOfBoundsPoint); } -TEST(AddPoint_With_1_Point) +TEST_CASE( "AddPoint_With_1_Point", "[libopenshot][keyframe]" ) { // Create an empty keyframe Keyframe k1; k1.AddPoint(openshot::Point(2,9)); - CHECK_CLOSE(2.0f, k1.GetPoint(0).co.X, 0.00001); - CHECK_THROW(k1.GetPoint(-1), OutOfBoundsPoint); - CHECK_THROW(k1.GetPoint(1), OutOfBoundsPoint); + CHECK(k1.GetPoint(0).co.X == Approx(2.0f).margin(0.00001)); + CHECK_THROWS_AS(k1.GetPoint(-1), OutOfBoundsPoint); + CHECK_THROWS_AS(k1.GetPoint(1), OutOfBoundsPoint); } -TEST(AddPoint_With_2_Points) +TEST_CASE( "AddPoint_With_2_Points", "[libopenshot][keyframe]" ) { // Create an empty keyframe Keyframe k1; k1.AddPoint(openshot::Point(2,9)); k1.AddPoint(openshot::Point(5,20)); - CHECK_CLOSE(2.0f, k1.GetPoint(0).co.X, 0.00001); - CHECK_CLOSE(5.0f, k1.GetPoint(1).co.X, 0.00001); - CHECK_THROW(k1.GetPoint(-1), OutOfBoundsPoint); - CHECK_THROW(k1.GetPoint(2), OutOfBoundsPoint); + CHECK(k1.GetPoint(0).co.X == Approx(2.0f).margin(0.00001)); + CHECK(k1.GetPoint(1).co.X == Approx(5.0f).margin(0.00001)); + CHECK_THROWS_AS(k1.GetPoint(-1), OutOfBoundsPoint); + CHECK_THROWS_AS(k1.GetPoint(2), OutOfBoundsPoint); } -TEST(GetValue_For_Bezier_Curve_2_Points) +TEST_CASE( "GetValue_For_Bezier_Curve_2_Points", "[libopenshot][keyframe]" ) { // Create a keyframe curve with 2 points Keyframe kf; @@ -96,18 +92,18 @@ TEST(GetValue_For_Bezier_Curve_2_Points) kf.AddPoint(openshot::Point(Coordinate(50, 4), BEZIER)); // Spot check values from the curve - CHECK_CLOSE(1.0f, kf.GetValue(-1), 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(0), 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(1), 0.0001); - CHECK_CLOSE(1.12414f, kf.GetValue(9), 0.0001); - CHECK_CLOSE(1.86370f, kf.GetValue(20), 0.0001); - CHECK_CLOSE(3.79733f, kf.GetValue(40), 0.0001); - CHECK_CLOSE(4.0f, kf.GetValue(50), 0.0001); + CHECK(kf.GetValue(-1) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(0) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(1) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(9) == Approx(1.12414f).margin(0.0001)); + CHECK(kf.GetValue(20) == Approx(1.86370f).margin(0.0001)); + CHECK(kf.GetValue(40) == Approx(3.79733f).margin(0.0001)); + CHECK(kf.GetValue(50) == Approx(4.0f).margin(0.0001)); // Check the expected number of values - CHECK_EQUAL(51, kf.GetLength()); + CHECK(kf.GetLength() == 51); } -TEST(GetValue_For_Bezier_Curve_5_Points_40_Percent_Handle) +TEST_CASE( "GetValue_For_Bezier_Curve_5_Points_40_Percent_Handle", "[libopenshot][keyframe]" ) { // Create a keyframe curve with 2 points Keyframe kf; @@ -118,19 +114,19 @@ TEST(GetValue_For_Bezier_Curve_5_Points_40_Percent_Handle) kf.AddPoint(openshot::Point(Coordinate(200, 3), BEZIER)); // Spot check values from the curve - CHECK_CLOSE(kf.GetValue(-1), 1.0f, 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(0), 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(1), 0.0001); - CHECK_CLOSE(2.68197f, kf.GetValue(27), 0.0001); - CHECK_CLOSE(7.47719f, kf.GetValue(77), 0.0001); - CHECK_CLOSE(4.20468f, kf.GetValue(127), 0.0001); - CHECK_CLOSE(1.73860f, kf.GetValue(177), 0.0001); - CHECK_CLOSE(3.0f, kf.GetValue(200), 0.0001); + CHECK(1.0f == Approx(kf.GetValue(-1)).margin(0.0001)); + CHECK(kf.GetValue(0) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(1) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(27) == Approx(2.68197f).margin(0.0001)); + CHECK(kf.GetValue(77) == Approx(7.47719f).margin(0.0001)); + CHECK(kf.GetValue(127) == Approx(4.20468f).margin(0.0001)); + CHECK(kf.GetValue(177) == Approx(1.73860f).margin(0.0001)); + CHECK(kf.GetValue(200) == Approx(3.0f).margin(0.0001)); // Check the expected number of values - CHECK_EQUAL(201, kf.GetLength()); + CHECK(kf.GetLength() == 201); } -TEST(GetValue_For_Bezier_Curve_5_Points_25_Percent_Handle) +TEST_CASE( "GetValue_For_Bezier_Curve_5_Points_25_Percent_Handle", "[libopenshot][keyframe]" ) { // Create a keyframe curve with 2 points Keyframe kf; @@ -141,19 +137,19 @@ TEST(GetValue_For_Bezier_Curve_5_Points_25_Percent_Handle) kf.AddPoint(openshot::Point(Coordinate(200, 3), BEZIER)); // Spot check values from the curve - CHECK_CLOSE(1.0f, kf.GetValue(-1), 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(0), 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(1), 0.0001); - CHECK_CLOSE(2.68197f, kf.GetValue(27), 0.0001); - CHECK_CLOSE(7.47719f, kf.GetValue(77), 0.0001); - CHECK_CLOSE(4.20468f, kf.GetValue(127), 0.0001); - CHECK_CLOSE(1.73860f, kf.GetValue(177), 0.0001); - CHECK_CLOSE(3.0f, kf.GetValue(200), 0.0001); + CHECK(kf.GetValue(-1) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(0) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(1) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(27) == Approx(2.68197f).margin(0.0001)); + CHECK(kf.GetValue(77) == Approx(7.47719f).margin(0.0001)); + CHECK(kf.GetValue(127) == Approx(4.20468f).margin(0.0001)); + CHECK(kf.GetValue(177) == Approx(1.73860f).margin(0.0001)); + CHECK(kf.GetValue(200) == Approx(3.0f).margin(0.0001)); // Check the expected number of values - CHECK_EQUAL(201, kf.GetLength()); + CHECK(kf.GetLength() == 201); } -TEST(GetValue_For_Linear_Curve_3_Points) +TEST_CASE( "GetValue_For_Linear_Curve_3_Points", "[libopenshot][keyframe]" ) { // Create a keyframe curve with 2 points Keyframe kf; @@ -162,18 +158,18 @@ TEST(GetValue_For_Linear_Curve_3_Points) kf.AddPoint(openshot::Point(Coordinate(50, 2), LINEAR)); // Spot check values from the curve - CHECK_CLOSE(1.0f, kf.GetValue(-1), 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(0), 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(1), 0.0001); - CHECK_CLOSE(3.33333f, kf.GetValue(9), 0.0001); - CHECK_CLOSE(6.54167f, kf.GetValue(20), 0.0001); - CHECK_CLOSE(4.4f, kf.GetValue(40), 0.0001); - CHECK_CLOSE(2.0f, kf.GetValue(50), 0.0001); + CHECK(kf.GetValue(-1) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(0) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(1) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(9) == Approx(3.33333f).margin(0.0001)); + CHECK(kf.GetValue(20) == Approx(6.54167f).margin(0.0001)); + CHECK(kf.GetValue(40) == Approx(4.4f).margin(0.0001)); + CHECK(kf.GetValue(50) == Approx(2.0f).margin(0.0001)); // Check the expected number of values - CHECK_EQUAL(51, kf.GetLength()); + CHECK(kf.GetLength() == 51); } -TEST(GetValue_For_Constant_Curve_3_Points) +TEST_CASE( "GetValue_For_Constant_Curve_3_Points", "[libopenshot][keyframe]" ) { // Create a keyframe curve with 2 points Keyframe kf; @@ -182,19 +178,19 @@ TEST(GetValue_For_Constant_Curve_3_Points) kf.AddPoint(openshot::Point(Coordinate(50, 2), CONSTANT)); // Spot check values from the curve - CHECK_CLOSE(1.0f, kf.GetValue(-1), 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(0), 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(1), 0.0001); - CHECK_CLOSE(1.0f, kf.GetValue(24), 0.0001); - CHECK_CLOSE(8.0f, kf.GetValue(25), 0.0001); - CHECK_CLOSE(8.0f, kf.GetValue(40), 0.0001); - CHECK_CLOSE(8.0f, kf.GetValue(49), 0.0001); - CHECK_CLOSE(2.0f, kf.GetValue(50), 0.0001); + CHECK(kf.GetValue(-1) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(0) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(1) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(24) == Approx(1.0f).margin(0.0001)); + CHECK(kf.GetValue(25) == Approx(8.0f).margin(0.0001)); + CHECK(kf.GetValue(40) == Approx(8.0f).margin(0.0001)); + CHECK(kf.GetValue(49) == Approx(8.0f).margin(0.0001)); + CHECK(kf.GetValue(50) == Approx(2.0f).margin(0.0001)); // Check the expected number of values - CHECK_EQUAL(51, kf.GetLength()); + CHECK(kf.GetLength() == 51); } -TEST(Check_Direction_and_Repeat_Fractions) +TEST_CASE( "Check_Direction_and_Repeat_Fractions", "[libopenshot][keyframe]" ) { // Create a keyframe curve with 2 points Keyframe kf; @@ -203,33 +199,33 @@ TEST(Check_Direction_and_Repeat_Fractions) kf.AddPoint(500, 500); // Spot check values from the curve - CHECK_EQUAL(500, kf.GetInt(1)); - CHECK_EQUAL(false, kf.IsIncreasing(1)); - CHECK_EQUAL(1, kf.GetRepeatFraction(1).num); - CHECK_EQUAL(13, kf.GetRepeatFraction(1).den); - CHECK_EQUAL(500, kf.GetDelta(1)); - - CHECK_EQUAL(498, kf.GetInt(24)); - CHECK_EQUAL(false, kf.IsIncreasing(24)); - CHECK_EQUAL(3, kf.GetRepeatFraction(24).num); - CHECK_EQUAL(6, kf.GetRepeatFraction(24).den); - CHECK_EQUAL(0, kf.GetDelta(24)); - - CHECK_EQUAL(100, kf.GetLong(390)); - CHECK_EQUAL(true, kf.IsIncreasing(390)); - CHECK_EQUAL(3, kf.GetRepeatFraction(390).num); - CHECK_EQUAL(16, kf.GetRepeatFraction(390).den); - CHECK_EQUAL(0, kf.GetDelta(390)); - - CHECK_EQUAL(100, kf.GetLong(391)); - CHECK_EQUAL(true, kf.IsIncreasing(391)); - CHECK_EQUAL(4, kf.GetRepeatFraction(391).num); - CHECK_EQUAL(16, kf.GetRepeatFraction(391).den); - CHECK_EQUAL(-1, kf.GetDelta(388)); + CHECK(kf.GetInt(1) == 500); + CHECK_FALSE(kf.IsIncreasing(1)); + CHECK(kf.GetRepeatFraction(1).num == 1); + CHECK(kf.GetRepeatFraction(1).den == 13); + CHECK(kf.GetDelta(1) == 500); + + CHECK(kf.GetInt(24) == 498); + CHECK_FALSE(kf.IsIncreasing(24)); + CHECK(kf.GetRepeatFraction(24).num == 3); + CHECK(kf.GetRepeatFraction(24).den == 6); + CHECK(kf.GetDelta(24) == 0); + + CHECK(kf.GetLong(390) == 100); + CHECK(kf.IsIncreasing(390) == true); + CHECK(kf.GetRepeatFraction(390).num == 3); + CHECK(kf.GetRepeatFraction(390).den == 16); + CHECK(kf.GetDelta(390) == 0); + + CHECK(kf.GetLong(391) == 100); + CHECK(kf.IsIncreasing(391) == true); + CHECK(kf.GetRepeatFraction(391).num == 4); + CHECK(kf.GetRepeatFraction(391).den == 16); + CHECK(kf.GetDelta(388) == -1); } -TEST(Get_Closest_Point) +TEST_CASE( "Get_Closest_Point", "[libopenshot][keyframe]" ) { // Create a keyframe curve with 2 points Keyframe kf; @@ -238,26 +234,26 @@ TEST(Get_Closest_Point) kf.AddPoint(2500, 0.0); // Spot check values from the curve (to the right) - CHECK_EQUAL(1000, kf.GetClosestPoint(openshot::Point(900, 900)).co.X); - CHECK_EQUAL(1, kf.GetClosestPoint(openshot::Point(1, 1)).co.X); - CHECK_EQUAL(1000, kf.GetClosestPoint(openshot::Point(5, 5)).co.X); - CHECK_EQUAL(1000, kf.GetClosestPoint(openshot::Point(1000, 1000)).co.X); - CHECK_EQUAL(2500, kf.GetClosestPoint(openshot::Point(1001, 1001)).co.X); - CHECK_EQUAL(2500, kf.GetClosestPoint(openshot::Point(2500, 2500)).co.X); - CHECK_EQUAL(2500, kf.GetClosestPoint(openshot::Point(3000, 3000)).co.X); + CHECK(kf.GetClosestPoint(openshot::Point(900, 900)).co.X == 1000); + CHECK(kf.GetClosestPoint(openshot::Point(1, 1)).co.X == 1); + CHECK(kf.GetClosestPoint(openshot::Point(5, 5)).co.X == 1000); + CHECK(kf.GetClosestPoint(openshot::Point(1000, 1000)).co.X == 1000); + CHECK(kf.GetClosestPoint(openshot::Point(1001, 1001)).co.X == 2500); + CHECK(kf.GetClosestPoint(openshot::Point(2500, 2500)).co.X == 2500); + CHECK(kf.GetClosestPoint(openshot::Point(3000, 3000)).co.X == 2500); // Spot check values from the curve (to the left) - CHECK_EQUAL(1, kf.GetClosestPoint(openshot::Point(900, 900), true).co.X); - CHECK_EQUAL(1, kf.GetClosestPoint(openshot::Point(1, 1), true).co.X); - CHECK_EQUAL(1, kf.GetClosestPoint(openshot::Point(5, 5), true).co.X); - CHECK_EQUAL(1, kf.GetClosestPoint(openshot::Point(1000, 1000), true).co.X); - CHECK_EQUAL(1000, kf.GetClosestPoint(openshot::Point(1001, 1001), true).co.X); - CHECK_EQUAL(1000, kf.GetClosestPoint(openshot::Point(2500, 2500), true).co.X); - CHECK_EQUAL(2500, kf.GetClosestPoint(openshot::Point(3000, 3000), true).co.X); + CHECK(kf.GetClosestPoint(openshot::Point(900, 900), true).co.X == 1); + CHECK(kf.GetClosestPoint(openshot::Point(1, 1), true).co.X == 1); + CHECK(kf.GetClosestPoint(openshot::Point(5, 5), true).co.X == 1); + CHECK(kf.GetClosestPoint(openshot::Point(1000, 1000), true).co.X == 1); + CHECK(kf.GetClosestPoint(openshot::Point(1001, 1001), true).co.X == 1000); + CHECK(kf.GetClosestPoint(openshot::Point(2500, 2500), true).co.X == 1000); + CHECK(kf.GetClosestPoint(openshot::Point(3000, 3000), true).co.X == 2500); } -TEST(Get_Previous_Point) +TEST_CASE( "Get_Previous_Point", "[libopenshot][keyframe]" ) { // Create a keyframe curve with 2 points Keyframe kf; @@ -266,42 +262,42 @@ TEST(Get_Previous_Point) kf.AddPoint(2500, 0.0); // Spot check values from the curve - CHECK_EQUAL(1, kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(900, 900))).co.X); - CHECK_EQUAL(1, kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(1, 1))).co.X); - CHECK_EQUAL(1, kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(5, 5))).co.X); - CHECK_EQUAL(1, kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(1000, 1000))).co.X); - CHECK_EQUAL(1000, kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(1001, 1001))).co.X); - CHECK_EQUAL(1000, kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(2500, 2500))).co.X); - CHECK_EQUAL(1000, kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(3000, 3000))).co.X); + CHECK(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(900, 900))).co.X == 1); + CHECK(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(1, 1))).co.X == 1); + CHECK(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(5, 5))).co.X == 1); + CHECK(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(1000, 1000))).co.X == 1); + CHECK(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(1001, 1001))).co.X == 1000); + CHECK(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(2500, 2500))).co.X == 1000); + CHECK(kf.GetPreviousPoint(kf.GetClosestPoint(openshot::Point(3000, 3000))).co.X == 1000); } -TEST(Get_Max_Point) +TEST_CASE( "Get_Max_Point", "[libopenshot][keyframe]" ) { // Create a keyframe curve Keyframe kf; kf.AddPoint(1, 1.0); // Spot check values from the curve - CHECK_EQUAL(1.0, kf.GetMaxPoint().co.Y); + CHECK(kf.GetMaxPoint().co.Y == 1.0); kf.AddPoint(2, 0.0); // Spot check values from the curve - CHECK_EQUAL(1.0, kf.GetMaxPoint().co.Y); + CHECK(kf.GetMaxPoint().co.Y == 1.0); kf.AddPoint(3, 2.0); // Spot check values from the curve - CHECK_EQUAL(2.0, kf.GetMaxPoint().co.Y); + CHECK(kf.GetMaxPoint().co.Y == 2.0); kf.AddPoint(4, 1.0); // Spot check values from the curve - CHECK_EQUAL(2.0, kf.GetMaxPoint().co.Y); + CHECK(kf.GetMaxPoint().co.Y == 2.0); } -TEST(Scale_Keyframe) +TEST_CASE( "Scale_Keyframe", "[libopenshot][keyframe]" ) { // Create a keyframe curve with 2 points Keyframe kf; @@ -310,40 +306,40 @@ TEST(Scale_Keyframe) kf.AddPoint(openshot::Point(Coordinate(50, 2), BEZIER)); // Spot check values from the curve - CHECK_CLOSE(1.0f, kf.GetValue(1), 0.01); - CHECK_CLOSE(7.99f, kf.GetValue(24), 0.01); - CHECK_CLOSE(8.0f, kf.GetValue(25), 0.01); - CHECK_CLOSE(3.85f, kf.GetValue(40), 0.01); - CHECK_CLOSE(2.01f, kf.GetValue(49), 0.01); - CHECK_CLOSE(2.0f, kf.GetValue(50), 0.01); + CHECK(kf.GetValue(1) == Approx(1.0f).margin(0.01)); + CHECK(kf.GetValue(24) == Approx(7.99f).margin(0.01)); + CHECK(kf.GetValue(25) == Approx(8.0f).margin(0.01)); + CHECK(kf.GetValue(40) == Approx(3.85f).margin(0.01)); + CHECK(kf.GetValue(49) == Approx(2.01f).margin(0.01)); + CHECK(kf.GetValue(50) == Approx(2.0f).margin(0.01)); // Resize / Scale the keyframe kf.ScalePoints(2.0); // 100% larger // Spot check values from the curve - CHECK_CLOSE(1.0f, kf.GetValue(1), 0.01); - CHECK_CLOSE(4.08f, kf.GetValue(24), 0.01); - CHECK_CLOSE(4.36f, kf.GetValue(25), 0.01); - CHECK_CLOSE(7.53f, kf.GetValue(40), 0.01); - CHECK_CLOSE(7.99f, kf.GetValue(49), 0.01); - CHECK_CLOSE(8.0f, kf.GetValue(50), 0.01); - CHECK_CLOSE(2.39f, kf.GetValue(90), 0.01); - CHECK_CLOSE(2.0f, kf.GetValue(100), 0.01); + CHECK(kf.GetValue(1) == Approx(1.0f).margin(0.01)); + CHECK(kf.GetValue(24) == Approx(4.08f).margin(0.01)); + CHECK(kf.GetValue(25) == Approx(4.36f).margin(0.01)); + CHECK(kf.GetValue(40) == Approx(7.53f).margin(0.01)); + CHECK(kf.GetValue(49) == Approx(7.99f).margin(0.01)); + CHECK(kf.GetValue(50) == Approx(8.0f).margin(0.01)); + CHECK(kf.GetValue(90) == Approx(2.39f).margin(0.01)); + CHECK(kf.GetValue(100) == Approx(2.0f).margin(0.01)); // Resize / Scale the keyframe kf.ScalePoints(0.5); // 50% smaller, which should match the original size // Spot check values from the curve - CHECK_CLOSE(1.0f, kf.GetValue(1), 0.01); - CHECK_CLOSE(7.99f, kf.GetValue(24), 0.01); - CHECK_CLOSE(8.0f, kf.GetValue(25), 0.01); - CHECK_CLOSE(3.85f, kf.GetValue(40), 0.01); - CHECK_CLOSE(2.01f, kf.GetValue(49), 0.01); - CHECK_CLOSE(2.0f, kf.GetValue(50), 0.01); + CHECK(kf.GetValue(1) == Approx(1.0f).margin(0.01)); + CHECK(kf.GetValue(24) == Approx(7.99f).margin(0.01)); + CHECK(kf.GetValue(25) == Approx(8.0f).margin(0.01)); + CHECK(kf.GetValue(40) == Approx(3.85f).margin(0.01)); + CHECK(kf.GetValue(49) == Approx(2.01f).margin(0.01)); + CHECK(kf.GetValue(50) == Approx(2.0f).margin(0.01)); } -TEST(Flip_Keyframe) +TEST_CASE( "Flip_Keyframe", "[libopenshot][keyframe]" ) { // Create a keyframe curve with 2 points Keyframe kf; @@ -353,31 +349,31 @@ TEST(Flip_Keyframe) kf.AddPoint(openshot::Point(Coordinate(100, 10), LINEAR)); // Spot check values from the curve - CHECK_CLOSE(1.0f, kf.GetValue(1), 0.01); - CHECK_CLOSE(8.0f, kf.GetValue(25), 0.01); - CHECK_CLOSE(2.0f, kf.GetValue(50), 0.01); - CHECK_CLOSE(10.0f, kf.GetValue(100), 0.01); + CHECK(kf.GetValue(1) == Approx(1.0f).margin(0.01)); + CHECK(kf.GetValue(25) == Approx(8.0f).margin(0.01)); + CHECK(kf.GetValue(50) == Approx(2.0f).margin(0.01)); + CHECK(kf.GetValue(100) == Approx(10.0f).margin(0.01)); // Flip the points kf.FlipPoints(); // Spot check values from the curve - CHECK_CLOSE(10.0f, kf.GetValue(1), 0.01); - CHECK_CLOSE(2.0f, kf.GetValue(25), 0.01); - CHECK_CLOSE(8.0f, kf.GetValue(50), 0.01); - CHECK_CLOSE(1.0f, kf.GetValue(100), 0.01); + CHECK(kf.GetValue(1) == Approx(10.0f).margin(0.01)); + CHECK(kf.GetValue(25) == Approx(2.0f).margin(0.01)); + CHECK(kf.GetValue(50) == Approx(8.0f).margin(0.01)); + CHECK(kf.GetValue(100) == Approx(1.0f).margin(0.01)); // Flip the points again (back to the original) kf.FlipPoints(); // Spot check values from the curve - CHECK_CLOSE(1.0f, kf.GetValue(1), 0.01); - CHECK_CLOSE(8.0f, kf.GetValue(25), 0.01); - CHECK_CLOSE(2.0f, kf.GetValue(50), 0.01); - CHECK_CLOSE(10.0f, kf.GetValue(100), 0.01); + CHECK(kf.GetValue(1) == Approx(1.0f).margin(0.01)); + CHECK(kf.GetValue(25) == Approx(8.0f).margin(0.01)); + CHECK(kf.GetValue(50) == Approx(2.0f).margin(0.01)); + CHECK(kf.GetValue(100) == Approx(10.0f).margin(0.01)); } -TEST(Remove_Duplicate_Point) +TEST_CASE( "Remove_Duplicate_Point", "[libopenshot][keyframe]" ) { // Create a keyframe curve with 2 points Keyframe kf; @@ -386,11 +382,11 @@ TEST(Remove_Duplicate_Point) kf.AddPoint(1, 2.0); // Spot check values from the curve - CHECK_EQUAL(1, kf.GetLength()); - CHECK_CLOSE(2.0, kf.GetPoint(0).co.Y, 0.01); + CHECK(kf.GetLength() == 1); + CHECK(kf.GetPoint(0).co.Y == Approx(2.0).margin(0.01)); } -TEST(Large_Number_Values) +TEST_CASE( "Large_Number_Values", "[libopenshot][keyframe]" ) { // Large value int64_t const large_value = 30 * 60 * 90; @@ -401,38 +397,38 @@ TEST(Large_Number_Values) kf.AddPoint(large_value, 100.0); // 90 minutes long // Spot check values from the curve - CHECK_EQUAL(large_value + 1, kf.GetLength()); - CHECK_CLOSE(1.0, kf.GetPoint(0).co.Y, 0.01); - CHECK_CLOSE(100.0, kf.GetPoint(1).co.Y, 0.01); + CHECK(kf.GetLength() == large_value + 1); + CHECK(kf.GetPoint(0).co.Y == Approx(1.0).margin(0.01)); + CHECK(kf.GetPoint(1).co.Y == Approx(100.0).margin(0.01)); } -TEST(Remove_Point) +TEST_CASE( "Remove_Point", "[libopenshot][keyframe]" ) { Keyframe kf; kf.AddPoint(openshot::Point(Coordinate(1, 1), CONSTANT)); kf.AddPoint(openshot::Point(Coordinate(3, 100), CONSTANT)); - CHECK_EQUAL(1, kf.GetInt(2)); + CHECK(kf.GetInt(2) == 1); kf.AddPoint(openshot::Point(Coordinate(2, 50), CONSTANT)); - CHECK_EQUAL(50, kf.GetInt(2)); + CHECK(kf.GetInt(2) == 50); kf.RemovePoint(1); // This is the index of point with X == 2 - CHECK_EQUAL(1, kf.GetInt(2)); - CHECK_THROW(kf.RemovePoint(100), OutOfBoundsPoint); + CHECK(kf.GetInt(2) == 1); + CHECK_THROWS_AS(kf.RemovePoint(100), OutOfBoundsPoint); } -TEST(Constant_Interpolation_First_Segment) +TEST_CASE( "Constant_Interpolation_First_Segment", "[libopenshot][keyframe]" ) { Keyframe kf; kf.AddPoint(Point(Coordinate(1, 1), CONSTANT)); kf.AddPoint(Point(Coordinate(2, 50), CONSTANT)); kf.AddPoint(Point(Coordinate(3, 100), CONSTANT)); - CHECK_EQUAL(1, kf.GetInt(0)); - CHECK_EQUAL(1, kf.GetInt(1)); - CHECK_EQUAL(50, kf.GetInt(2)); - CHECK_EQUAL(100, kf.GetInt(3)); - CHECK_EQUAL(100, kf.GetInt(4)); + CHECK(kf.GetInt(0) == 1); + CHECK(kf.GetInt(1) == 1); + CHECK(kf.GetInt(2) == 50); + CHECK(kf.GetInt(3) == 100); + CHECK(kf.GetInt(4) == 100); } -TEST(isIncreasing) +TEST_CASE( "isIncreasing", "[libopenshot][keyframe]" ) { // Which cases need to be tested to keep same behaviour as // previously? @@ -450,64 +446,63 @@ TEST(isIncreasing) kf.AddPoint(15, 10, CONSTANT); // "invalid points" - CHECK_EQUAL(true, kf.IsIncreasing(0)); - CHECK_EQUAL(true, kf.IsIncreasing(15)); + CHECK(kf.IsIncreasing(0) == true); + CHECK(kf.IsIncreasing(15) == true); // all next equal - CHECK_EQUAL(false, kf.IsIncreasing(12)); + CHECK_FALSE(kf.IsIncreasing(12)); // first non-eq is larger - CHECK_EQUAL(true, kf.IsIncreasing(8)); + CHECK(kf.IsIncreasing(8) == true); // first non-eq is smaller - CHECK_EQUAL(false, kf.IsIncreasing(6)); + CHECK_FALSE(kf.IsIncreasing(6)); // bezier and linear - CHECK_EQUAL(true, kf.IsIncreasing(4)); - CHECK_EQUAL(true, kf.IsIncreasing(2)); + CHECK(kf.IsIncreasing(4) == true); + CHECK(kf.IsIncreasing(2) == true); } -TEST(GetLength) +TEST_CASE( "GetLength", "[libopenshot][keyframe]" ) { Keyframe f; - CHECK_EQUAL(0, f.GetLength()); + CHECK(f.GetLength() == 0); f.AddPoint(1, 1); - CHECK_EQUAL(1, f.GetLength()); + CHECK(f.GetLength() == 1); f.AddPoint(2, 1); - CHECK_EQUAL(3, f.GetLength()); + CHECK(f.GetLength() == 3); f.AddPoint(200, 1); - CHECK_EQUAL(201, f.GetLength()); + CHECK(f.GetLength() == 201); Keyframe g; g.AddPoint(200, 1); - CHECK_EQUAL(1, g.GetLength()); + CHECK(g.GetLength() == 1); g.AddPoint(1,1); - CHECK_EQUAL(201, g.GetLength()); + CHECK(g.GetLength() == 201); } -TEST(Use_Interpolation_of_Segment_End_Point) +TEST_CASE( "Use_Interpolation_of_Segment_End_Point", "[libopenshot][keyframe]" ) { Keyframe f; f.AddPoint(1,0, CONSTANT); f.AddPoint(100,155, BEZIER); - CHECK_CLOSE(75.9, f.GetValue(50), 0.1); + CHECK(f.GetValue(50) == Approx(75.9).margin(0.1)); } -TEST(Handle_Large_Segment) +TEST_CASE( "Handle_Large_Segment", "[libopenshot][keyframe]" ) { Keyframe kf; kf.AddPoint(1, 0, CONSTANT); kf.AddPoint(1000000, 1, LINEAR); - UNITTEST_TIME_CONSTRAINT(10); // 10 milliseconds would still be relatively slow, but need to think about slower build machines! - CHECK_CLOSE(0.5, kf.GetValue(500000), 0.01); - CHECK_EQUAL(true, kf.IsIncreasing(10)); + + CHECK(kf.GetValue(500000) == Approx(0.5).margin(0.01)); + CHECK(kf.IsIncreasing(10) == true); + Fraction fr = kf.GetRepeatFraction(250000); - CHECK_CLOSE(0.5, (double)fr.num / fr.den, 0.01); + CHECK((double)fr.num / fr.den == Approx(0.5).margin(0.01)); } -TEST(Point_Vector_Constructor) +TEST_CASE( "Point_Vector_Constructor", "[libopenshot][keyframe]" ) { std::vector points{Point(1, 10), Point(5, 20), Point(10, 30)}; Keyframe k1(points); - CHECK_EQUAL(11, k1.GetLength()); - CHECK_CLOSE(30.0f, k1.GetValue(10), 0.0001); + CHECK(k1.GetLength() == 11); + CHECK(k1.GetValue(10) == Approx(30.0f).margin(0.0001)); } - -}; // SUITE diff --git a/tests/Point.cpp b/tests/Point.cpp index 39012845f..45f493e07 100644 --- a/tests/Point.cpp +++ b/tests/Point.cpp @@ -28,98 +28,96 @@ * along with OpenShot Library. If not, see . */ -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include + #include "Point.h" #include "Enums.h" +#include "Exceptions.h" #include "Coordinate.h" #include "Json.h" -SUITE(POINT) { - -TEST(Default_Constructor) +TEST_CASE( "Default_Constructor", "[libopenshot][point]" ) { 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); + CHECK(p.co.X == 1); + CHECK(p.co.Y == 0); + CHECK(p.handle_left.X == 0.5); + CHECK(p.handle_left.Y == 1.0); + CHECK(p.handle_right.X == 0.5); + CHECK(p.handle_right.Y == 0.0); + CHECK(p.interpolation == openshot::InterpolationType::BEZIER); + CHECK(p.handle_type == openshot::HandleType::AUTO); } -TEST(XY_Constructor) +TEST_CASE( "XY_Constructor", "[libopenshot][point]" ) { // 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); + CHECK(p1.co.X == 2); + CHECK(p1.co.Y == 9); + CHECK(p1.interpolation == openshot::InterpolationType::BEZIER); } -TEST(Pair_Constructor) +TEST_CASE( "Pair_Constructor", "[libopenshot][point]" ) { // Create a point from a std::pair std::pair 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); + CHECK(p1.co.X == Approx(22.0f).margin(0.00001)); + CHECK(p1.co.Y == Approx(5.0f).margin(0.00001)); } -TEST(Constructor_With_Coordinate) +TEST_CASE( "Constructor_With_Coordinate", "[libopenshot][point]" ) { // 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); + CHECK(p1.co.X == Approx(3.0f).margin(0.00001)); + CHECK(p1.co.Y == Approx(7.0f).margin(0.00001)); + CHECK(p1.interpolation == openshot::InterpolationType::BEZIER); } -TEST(Constructor_With_Coordinate_And_LINEAR_Interpolation) +TEST_CASE( "Constructor_With_Coordinate_And_LINEAR_Interpolation", "[libopenshot][point]" ) { // 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); + CHECK(c1.X == 3); + CHECK(c1.Y == 9); + CHECK(p1.interpolation == openshot::InterpolationType::LINEAR); } -TEST(Constructor_With_Coordinate_And_BEZIER_Interpolation) +TEST_CASE( "Constructor_With_Coordinate_And_BEZIER_Interpolation", "[libopenshot][point]" ) { // 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); + CHECK(p1.co.X == 3); + CHECK(p1.co.Y == 9); + CHECK(p1.interpolation == openshot::InterpolationType::BEZIER); } -TEST(Constructor_With_Coordinate_And_CONSTANT_Interpolation) +TEST_CASE( "Constructor_With_Coordinate_And_CONSTANT_Interpolation", "[libopenshot][point]" ) { // 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); + CHECK(p1.co.X == 2); + CHECK(p1.co.Y == 8); + CHECK(p1.interpolation == openshot::InterpolationType::CONSTANT); } -TEST(Constructor_With_Coordinate_And_BEZIER_And_AUTO_Handle) +TEST_CASE( "Constructor_With_Coordinate_And_BEZIER_And_AUTO_Handle", "[libopenshot][point]" ) { // Create a point with a coordinate and interpolation openshot::Coordinate c1(3,9); @@ -127,13 +125,13 @@ TEST(Constructor_With_Coordinate_And_BEZIER_And_AUTO_Handle) 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); + CHECK(p1.co.X == 3); + CHECK(p1.co.Y == 9); + CHECK(p1.interpolation == openshot::InterpolationType::BEZIER); + CHECK(p1.handle_type == openshot::HandleType::AUTO); } -TEST(Constructor_With_Coordinate_And_BEZIER_And_MANUAL_Handle) +TEST_CASE( "Constructor_With_Coordinate_And_BEZIER_And_MANUAL_Handle", "[libopenshot][point]" ) { // Create a point with a coordinate and interpolation openshot::Coordinate c1(3,9); @@ -141,26 +139,31 @@ TEST(Constructor_With_Coordinate_And_BEZIER_And_MANUAL_Handle) 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); + CHECK(p1.co.X == 3); + CHECK(p1.co.Y == 9); + CHECK(p1.interpolation == openshot::InterpolationType::BEZIER); + CHECK(p1.handle_type == openshot::HandleType::MANUAL); } -TEST(Json) +TEST_CASE( "Json", "[libopenshot][point]" ) { 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); + CHECK(json_string2 == json1); } -TEST(SetJson) +TEST_CASE( "SetJson", "[libopenshot][point]" ) { openshot::Point p1; std::stringstream json_stream; + + // A string that's not JSON should cause an exception + CHECK_THROWS_AS(p1.SetJson("}{"), openshot::InvalidJSON); + + // Build a valid JSON string for Point settings json_stream << R"json( { "co": { "X": 1.0, "Y": 0.0 }, @@ -174,13 +177,12 @@ TEST(SetJson) 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); + CHECK(p1.handle_left.X == 2.0); + CHECK(p1.handle_left.Y == 3.0); + CHECK(p1.handle_right.X == 4.0); + CHECK(p1.handle_right.Y == -2.0); + CHECK(p1.handle_type == openshot::HandleType::MANUAL); + CHECK(p1.interpolation == openshot::InterpolationType::CONSTANT); } - -} // SUITE diff --git a/tests/QtImageReader.cpp b/tests/QtImageReader.cpp index 2fd78d5e4..6bfeebe4e 100644 --- a/tests/QtImageReader.cpp +++ b/tests/QtImageReader.cpp @@ -28,39 +28,38 @@ * along with OpenShot Library. If not, see . */ -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 -#include "QGuiApplication" -#include "OpenShot.h" +#include -using namespace std; -using namespace openshot; +#include -SUITE(QtImageReader) -{ +#include "QtImageReader.h" +#include "Frame.h" +#include "Clip.h" +#include "Timeline.h" + +using namespace openshot; -TEST(Default_Constructor) +TEST_CASE( "Default_Constructor", "[libopenshot][qtimagereader]" ) { // Check invalid path - CHECK_THROW(QtImageReader(""), InvalidFile); + CHECK_THROWS_AS(QtImageReader(""), InvalidFile); } -TEST(GetFrame_Before_Opening) +TEST_CASE( "GetFrame_Before_Opening", "[libopenshot][qtimagereader]" ) { // Create a reader - stringstream path; + std::stringstream path; path << TEST_MEDIA_PATH << "front.png"; QtImageReader r(path.str()); // Check invalid path - CHECK_THROW(r.GetFrame(1), ReaderClosed); + CHECK_THROWS_AS(r.GetFrame(1), ReaderClosed); } -TEST(Check_SVG_Loading) +TEST_CASE( "Check_SVG_Loading", "[libopenshot][qtimagereader]" ) { // Create a reader - stringstream path; + std::stringstream path; path << TEST_MEDIA_PATH << "1F0CF.svg"; QtImageReader r(path.str()); r.Open(); @@ -68,8 +67,8 @@ TEST(Check_SVG_Loading) // Get frame, with no Timeline or Clip // Default SVG scaling sizes things to 1920x1080 std::shared_ptr f = r.GetFrame(1); - CHECK_EQUAL(1080, f->GetImage()->width()); - CHECK_EQUAL(1080, f->GetImage()->height()); + CHECK(f->GetImage()->width() == 1080); + CHECK(f->GetImage()->height() == 1080); Fraction fps(30000,1000); Timeline t1(640, 480, fps, 44100, 2, LAYOUT_STEREO); @@ -87,21 +86,18 @@ TEST(Check_SVG_Loading) // Should scale to 480 clip1.Reader()->Open(); f = clip1.Reader()->GetFrame(2); - CHECK_EQUAL(480, f->GetImage()->width()); - CHECK_EQUAL(480, f->GetImage()->height()); + CHECK(f->GetImage()->width() == 480); + CHECK(f->GetImage()->height() == 480); // 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()); + CHECK(f->GetImage()->width() == 480 * 2); + CHECK(f->GetImage()->height() == 480 * 2); // Close reader t1.Close(); r.Close(); } - -} // SUITE(QtImageReader) - diff --git a/tests/ReaderBase.cpp b/tests/ReaderBase.cpp index dec61efd9..94880e004 100644 --- a/tests/ReaderBase.cpp +++ b/tests/ReaderBase.cpp @@ -29,65 +29,67 @@ */ #include +#include + +#include -#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) +TEST_CASE( "ReaderBase_Derived_Class", "[libopenshot][readerbase]" ) { // Create a new derived class from type ReaderBase class TestReader : public ReaderBase { public: TestReader() { }; - CacheBase* GetCache() { return NULL; }; + CacheBase* GetCache() { return nullptr; }; std::shared_ptr GetFrame(int64_t number) { std::shared_ptr f(new Frame()); return f; } void Close() { }; void Open() { }; - string Json() const { return ""; }; - void SetJson(string value) { }; + std::string Json() const { return ""; }; + void SetJson(std::string value) { }; Json::Value JsonValue() const { return Json::Value("{}"); }; void SetJsonValue(Json::Value root) { }; bool IsOpen() { return true; }; - string Name() { return "TestReader"; }; + std::string Name() { return "TestReader"; }; }; // Create an instance of the derived class TestReader t1; // Validate the new class - CHECK_EQUAL("TestReader", t1.Name()); + CHECK(t1.Name() == "TestReader"); t1.Close(); t1.Open(); - CHECK_EQUAL(true, t1.IsOpen()); + CHECK(t1.IsOpen() == true); - CHECK_EQUAL(true, t1.GetCache() == NULL); + CHECK(t1.GetCache() == nullptr); t1.SetJson("{ }"); t1.SetJsonValue(Json::Value("{}")); - CHECK_EQUAL("", t1.Json()); + CHECK(t1.Json() == ""); auto json = t1.JsonValue(); - CHECK_EQUAL(json, Json::Value("{}")); + CHECK(Json::Value("{}") == json); auto f = t1.GetFrame(1); + REQUIRE(f != nullptr); + CHECK(f->number == 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); + 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); } diff --git a/tests/Settings.cpp b/tests/Settings.cpp index ce5dc2824..e974ffd43 100644 --- a/tests/Settings.cpp +++ b/tests/Settings.cpp @@ -28,33 +28,31 @@ * along with OpenShot Library. If not, see . */ -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include + #include "Settings.h" -using namespace std; using namespace openshot; -TEST(Settings_Default_Constructor) +TEST_CASE( "Default_Constructor", "[libopenshot][settings]" ) { // Create an empty color Settings *s = Settings::Instance(); - CHECK_EQUAL(12, s->OMP_THREADS); - CHECK_EQUAL(false, s->HIGH_QUALITY_SCALING); + CHECK(s->OMP_THREADS == 12); + CHECK_FALSE(s->HIGH_QUALITY_SCALING); } -TEST(Settings_Change_Settings) +TEST_CASE( "Change_Settings", "[libopenshot][settings]" ) { // Create an empty color Settings *s = Settings::Instance(); s->OMP_THREADS = 8; s->HIGH_QUALITY_SCALING = true; - CHECK_EQUAL(8, s->OMP_THREADS); - CHECK_EQUAL(true, s->HIGH_QUALITY_SCALING); + CHECK(s->OMP_THREADS == 8); + CHECK(s->HIGH_QUALITY_SCALING == true); - CHECK_EQUAL(8, Settings::Instance()->OMP_THREADS); - CHECK_EQUAL(true, Settings::Instance()->HIGH_QUALITY_SCALING); + CHECK(Settings::Instance()->OMP_THREADS == 8); + CHECK(Settings::Instance()->HIGH_QUALITY_SCALING == true); } diff --git a/tests/Timeline.cpp b/tests/Timeline.cpp index fecba1788..d8aff6ee7 100644 --- a/tests/Timeline.cpp +++ b/tests/Timeline.cpp @@ -28,13 +28,13 @@ * along with OpenShot Library. If not, see . */ +#include #include #include #include -#include "UnitTest++.h" -// Prevent name clashes with juce::UnitTest -#define DONT_SET_USING_JUCE_NAMESPACE 1 +#include + #include "Timeline.h" #include "Clip.h" #include "Frame.h" @@ -42,76 +42,67 @@ #include "effects/Blur.h" #include "effects/Negate.h" -using namespace std; using namespace openshot; -SUITE(Timeline) -{ - -TEST(Constructor) +TEST_CASE( "constructor", "[libopenshot][timeline]" ) { - // Create a default fraction (should be 1/1) Fraction fps(30000,1000); Timeline t1(640, 480, fps, 44100, 2, LAYOUT_STEREO); // Check values - CHECK_EQUAL(640, t1.info.width); - CHECK_EQUAL(480, t1.info.height); - CHECK_EQUAL("Timeline", t1.Name()); + CHECK(t1.info.width == 640); + CHECK(t1.info.height == 480); - // Create a default fraction (should be 1/1) Timeline t2(300, 240, fps, 44100, 2, LAYOUT_STEREO); // Check values - CHECK_EQUAL(300, t2.info.width); - CHECK_EQUAL(240, t2.info.height); + CHECK(t2.info.width == 300); + CHECK(t2.info.height == 240); } -TEST(Width_and_Height_Functions) +TEST_CASE( "width and height functions", "[libopenshot][timeline]" ) { - // Create a default fraction (should be 1/1) Fraction fps(30000,1000); Timeline t1(640, 480, fps, 44100, 2, LAYOUT_STEREO); // Check values - CHECK_EQUAL(640, t1.info.width); - CHECK_EQUAL(480, t1.info.height); + CHECK(t1.info.width == 640); + CHECK(t1.info.height == 480); // Set width t1.info.width = 600; // Check values - CHECK_EQUAL(600, t1.info.width); - CHECK_EQUAL(480, t1.info.height); + CHECK(t1.info.width == 600); + CHECK(t1.info.height == 480); // Set height t1.info.height = 400; // Check values - CHECK_EQUAL(600, t1.info.width); - CHECK_EQUAL(400, t1.info.height); + CHECK(t1.info.width == 600); + CHECK(t1.info.height == 400); } -TEST(Framerate) +TEST_CASE( "Framerate", "[libopenshot][timeline]" ) { - // Create a default fraction (should be 1/1) Fraction fps(24,1); Timeline t1(640, 480, fps, 44100, 2, LAYOUT_STEREO); // Check values - CHECK_CLOSE(24.0f, t1.info.fps.ToFloat(), 0.00001); + CHECK(t1.info.fps.ToFloat() == Approx(24.0f).margin(0.00001)); } -TEST(Check_Two_Track_Video) +TEST_CASE( "two-track video", "[libopenshot][timeline]" ) { // Create a reader - stringstream path; + std::stringstream path; path << TEST_MEDIA_PATH << "test.mp4"; Clip clip_video(path.str()); clip_video.Layer(0); clip_video.Position(0.0); - stringstream path_overlay; + std::stringstream path_overlay; path_overlay << TEST_MEDIA_PATH << "front3.png"; Clip clip_overlay(path_overlay.str()); clip_overlay.Layer(1); @@ -125,10 +116,8 @@ TEST(Check_Two_Track_Video) t.AddClip(&clip_video); t.AddClip(&clip_overlay); - // Open Timeline t.Open(); - // Get frame std::shared_ptr f = t.GetFrame(1); // Get the image data @@ -136,124 +125,99 @@ TEST(Check_Two_Track_Video) int pixel_index = 230 * 4; // pixel 230 (4 bytes per pixel) // Check image properties - CHECK_CLOSE(21, (int)f->GetPixels(pixel_row)[pixel_index], 5); - CHECK_CLOSE(191, (int)f->GetPixels(pixel_row)[pixel_index + 1], 5); - CHECK_CLOSE(0, (int)f->GetPixels(pixel_row)[pixel_index + 2], 5); - CHECK_CLOSE(255, (int)f->GetPixels(pixel_row)[pixel_index + 3], 5); + CHECK((int)f->GetPixels(pixel_row)[pixel_index] == Approx(21).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 1] == Approx(191).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 2] == Approx(0).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 3] == Approx(255).margin(5)); - // Get frame f = t.GetFrame(2); // Check image properties - CHECK_CLOSE(176, (int)f->GetPixels(pixel_row)[pixel_index], 5); - CHECK_CLOSE(0, (int)f->GetPixels(pixel_row)[pixel_index + 1], 5); - CHECK_CLOSE(186, (int)f->GetPixels(pixel_row)[pixel_index + 2], 5); - CHECK_CLOSE(255, (int)f->GetPixels(pixel_row)[pixel_index + 3], 5); + CHECK((int)f->GetPixels(pixel_row)[pixel_index] == Approx(176).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 1] == Approx(0).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 2] == Approx(186).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 3] == Approx(255).margin(5)); - // Get frame f = t.GetFrame(3); // Check image properties - CHECK_CLOSE(23, (int)f->GetPixels(pixel_row)[pixel_index], 5); - CHECK_CLOSE(190, (int)f->GetPixels(pixel_row)[pixel_index + 1], 5); - CHECK_CLOSE(0, (int)f->GetPixels(pixel_row)[pixel_index + 2], 5); - CHECK_CLOSE(255, (int)f->GetPixels(pixel_row)[pixel_index + 3], 5); + CHECK((int)f->GetPixels(pixel_row)[pixel_index] == Approx(23).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 1] == Approx(190).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 2] == Approx(0).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 3] == Approx(255).margin(5)); - // Get frame f = t.GetFrame(24); // Check image properties - CHECK_CLOSE(186, (int)f->GetPixels(pixel_row)[pixel_index], 5); - CHECK_CLOSE(106, (int)f->GetPixels(pixel_row)[pixel_index + 1], 5); - CHECK_CLOSE(0, (int)f->GetPixels(pixel_row)[pixel_index + 2], 5); - CHECK_CLOSE(255, (int)f->GetPixels(pixel_row)[pixel_index + 3], 5); + CHECK((int)f->GetPixels(pixel_row)[pixel_index] == Approx(186).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 1] == Approx(106).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 2] == Approx(0).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 3] == Approx(255).margin(5)); - // Get frame f = t.GetFrame(5); // Check image properties - CHECK_CLOSE(23, (int)f->GetPixels(pixel_row)[pixel_index], 5); - CHECK_CLOSE(190, (int)f->GetPixels(pixel_row)[pixel_index + 1], 5); - CHECK_CLOSE(0, (int)f->GetPixels(pixel_row)[pixel_index + 2], 5); - CHECK_CLOSE(255, (int)f->GetPixels(pixel_row)[pixel_index + 3], 5); + CHECK((int)f->GetPixels(pixel_row)[pixel_index] == Approx(23).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 1] == Approx(190).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 2] == Approx(0).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 3] == Approx(255).margin(5)); - // Get frame f = t.GetFrame(25); // Check image properties - CHECK_CLOSE(0, (int)f->GetPixels(pixel_row)[pixel_index], 5); - CHECK_CLOSE(94, (int)f->GetPixels(pixel_row)[pixel_index + 1], 5); - CHECK_CLOSE(186, (int)f->GetPixels(pixel_row)[pixel_index + 2], 5); - CHECK_CLOSE(255, (int)f->GetPixels(pixel_row)[pixel_index + 3], 5); + CHECK((int)f->GetPixels(pixel_row)[pixel_index] == Approx(0).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 1] == Approx(94).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 2] == Approx(186).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 3] == Approx(255).margin(5)); - // Get frame f = t.GetFrame(4); // Check image properties - CHECK_CLOSE(176, (int)f->GetPixels(pixel_row)[pixel_index], 5); - CHECK_CLOSE(0, (int)f->GetPixels(pixel_row)[pixel_index + 1], 5); - CHECK_CLOSE(186, (int)f->GetPixels(pixel_row)[pixel_index + 2], 5); - CHECK_CLOSE(255, (int)f->GetPixels(pixel_row)[pixel_index + 3], 5); + CHECK((int)f->GetPixels(pixel_row)[pixel_index] == Approx(176).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 1] == Approx(0).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 2] == Approx(186).margin(5)); + CHECK((int)f->GetPixels(pixel_row)[pixel_index + 3] == Approx(255).margin(5)); - // Close reader t.Close(); } -TEST(Clip_Order) +TEST_CASE( "Clip order", "[libopenshot][timeline]" ) { // Create a timeline Timeline t(640, 480, Fraction(30, 1), 44100, 2, LAYOUT_STEREO); // Add some clips out of order - stringstream path_top; + std::stringstream path_top; path_top << TEST_MEDIA_PATH << "front3.png"; Clip clip_top(path_top.str()); clip_top.Layer(2); t.AddClip(&clip_top); - stringstream path_middle; + std::stringstream path_middle; path_middle << TEST_MEDIA_PATH << "front.png"; Clip clip_middle(path_middle.str()); clip_middle.Layer(0); t.AddClip(&clip_middle); - stringstream path_bottom; + std::stringstream path_bottom; path_bottom << TEST_MEDIA_PATH << "back.png"; Clip clip_bottom(path_bottom.str()); clip_bottom.Layer(1); t.AddClip(&clip_bottom); - // Open Timeline t.Open(); // Loop through Clips and check order (they should have been sorted into the correct order) // Bottom layer to top layer, then by position. - list::iterator clip_itr; - list clips = t.Clips(); - int counter = 0; - for (clip_itr=clips.begin(); clip_itr != clips.end(); ++clip_itr) - { - // Get clip object from the iterator - Clip *clip = (*clip_itr); - - switch (counter) { - case 0: - CHECK_EQUAL(0, clip->Layer()); - break; - case 1: - CHECK_EQUAL(1, clip->Layer()); - break; - case 2: - CHECK_EQUAL(2, clip->Layer()); - break; - } - - // increment counter - counter++; + std::list clips = t.Clips(); + int n = 0; + for (auto clip : clips) { + CHECK(clip->Layer() == n); + ++n; } // Add another clip - stringstream path_middle1; + std::stringstream path_middle1; path_middle1 << TEST_MEDIA_PATH << "interlaced.png"; Clip clip_middle1(path_middle1.str()); clip_middle1.Layer(1); @@ -261,40 +225,33 @@ TEST(Clip_Order) t.AddClip(&clip_middle1); // Loop through clips again, and re-check order - counter = 0; clips = t.Clips(); - for (clip_itr=clips.begin(); clip_itr != clips.end(); ++clip_itr) - { - // Get clip object from the iterator - Clip *clip = (*clip_itr); - - switch (counter) { + n = 0; + for (auto clip : clips) { + switch (n) { case 0: - CHECK_EQUAL(0, clip->Layer()); + CHECK(clip->Layer() == 0); break; case 1: - CHECK_EQUAL(1, clip->Layer()); - CHECK_CLOSE(0.0, clip->Position(), 0.0001); + CHECK(clip->Layer() == 1); + CHECK(clip->Position() == Approx(0.0).margin(0.0001)); break; case 2: - CHECK_EQUAL(1, clip->Layer()); - CHECK_CLOSE(0.5, clip->Position(), 0.0001); + CHECK(clip->Layer() == 1); + CHECK(clip->Position() == Approx(0.5).margin(0.0001)); break; case 3: - CHECK_EQUAL(2, clip->Layer()); + CHECK(clip->Layer() == 2); break; } - - // increment counter - counter++; + ++n; } - // Close reader t.Close(); } -TEST(Effect_Order) +TEST_CASE( "Effect order", "[libopenshot][timeline]" ) { // Create a timeline Timeline t(640, 480, Fraction(30, 1), 44100, 2, LAYOUT_STEREO); @@ -315,39 +272,27 @@ TEST(Effect_Order) effect_bottom.Layer(1); t.AddEffect(&effect_bottom); - // Open Timeline t.Open(); // Loop through effects and check order (they should have been sorted into the correct order) // Bottom layer to top layer, then by position, and then by order. - list::iterator effect_itr; - list effects = t.Effects(); - int counter = 0; - for (effect_itr=effects.begin(); effect_itr != effects.end(); ++effect_itr) - { - // Get clip object from the iterator - EffectBase *effect = (*effect_itr); - - switch (counter) { + std::list effects = t.Effects(); + int n = 0; + for (auto effect : effects) { + CHECK(effect->Layer() == n); + CHECK(effect->Order() == 0); + switch (n) { case 0: - CHECK_EQUAL(0, effect->Layer()); - CHECK_EQUAL("A", effect->Id()); - CHECK_EQUAL(0, effect->Order()); + CHECK(effect->Id() == "A"); break; case 1: - CHECK_EQUAL(1, effect->Layer()); - CHECK_EQUAL("B", effect->Id()); - CHECK_EQUAL(0, effect->Order()); + CHECK(effect->Id() == "B"); break; case 2: - CHECK_EQUAL(2, effect->Layer()); - CHECK_EQUAL("C", effect->Id()); - CHECK_EQUAL(0, effect->Order()); + CHECK(effect->Id() == "C"); break; } - - // increment counter - counter++; + ++n; } // Add some more effects out of order @@ -375,66 +320,59 @@ TEST(Effect_Order) // Loop through effects again, and re-check order effects = t.Effects(); - counter = 0; - for (effect_itr=effects.begin(); effect_itr != effects.end(); ++effect_itr) - { - // Get clip object from the iterator - EffectBase *effect = (*effect_itr); - - switch (counter) { + n = 0; + for (auto effect : effects) { + switch (n) { case 0: - CHECK_EQUAL(0, effect->Layer()); - CHECK_EQUAL("A", effect->Id()); - CHECK_EQUAL(0, effect->Order()); + CHECK(effect->Layer() == 0); + CHECK(effect->Id() == "A"); + CHECK(effect->Order() == 0); break; case 1: - CHECK_EQUAL(1, effect->Layer()); - CHECK_EQUAL("B-1", effect->Id()); - CHECK_CLOSE(0.0, effect->Position(), 0.0001); - CHECK_EQUAL(3, effect->Order()); + CHECK(effect->Layer() == 1); + CHECK(effect->Id() == "B-1"); + CHECK(effect->Position() == Approx(0.0).margin(0.0001)); + CHECK(effect->Order() == 3); break; case 2: - CHECK_EQUAL(1, effect->Layer()); - CHECK_EQUAL("B", effect->Id()); - CHECK_CLOSE(0.0, effect->Position(), 0.0001); - CHECK_EQUAL(0, effect->Order()); + CHECK(effect->Layer() == 1); + CHECK(effect->Id() == "B"); + CHECK(effect->Position() == Approx(0.0).margin(0.0001)); + CHECK(effect->Order() == 0); break; case 3: - CHECK_EQUAL(1, effect->Layer()); - CHECK_EQUAL("B-2", effect->Id()); - CHECK_CLOSE(0.5, effect->Position(), 0.0001); - CHECK_EQUAL(2, effect->Order()); + CHECK(effect->Layer() == 1); + CHECK(effect->Id() == "B-2"); + CHECK(effect->Position() == Approx(0.5).margin(0.0001)); + CHECK(effect->Order() == 2); break; case 4: - CHECK_EQUAL(1, effect->Layer()); - CHECK_EQUAL("B-3", effect->Id()); - CHECK_CLOSE(0.5, effect->Position(), 0.0001); - CHECK_EQUAL(1, effect->Order()); + CHECK(effect->Layer() == 1); + CHECK(effect->Id() == "B-3"); + CHECK(effect->Position() == Approx(0.5).margin(0.0001)); + CHECK(effect->Order() == 1); break; case 5: - CHECK_EQUAL(2, effect->Layer()); - CHECK_EQUAL("C", effect->Id()); - CHECK_EQUAL(0, effect->Order()); + CHECK(effect->Layer() == 2); + CHECK(effect->Id() == "C"); + CHECK(effect->Order() == 0); break; } - - // increment counter - counter++; + ++n; } - // Close reader t.Close(); } -TEST(GetClip_by_id) +TEST_CASE( "GetClip by id", "[libopenshot][timeline]" ) { Timeline t(640, 480, Fraction(30, 1), 44100, 2, LAYOUT_STEREO); - stringstream path1; + std::stringstream path1; path1 << TEST_MEDIA_PATH << "interlaced.png"; auto media_path1 = path1.str(); - stringstream path2; + std::stringstream path2; path2 << TEST_MEDIA_PATH << "front.png"; auto media_path2 = path2.str(); @@ -454,26 +392,26 @@ TEST(GetClip_by_id) // We explicitly want to get returned a Clip*, here Clip* matched = t.GetClip(clip1_id); - CHECK_EQUAL(clip1_id, matched->Id()); - CHECK_EQUAL(1, matched->Layer()); + CHECK(matched->Id() == clip1_id); + CHECK(matched->Layer() == 1); Clip* matched2 = t.GetClip(clip2_id); - CHECK_EQUAL(clip2_id, matched2->Id()); - CHECK_EQUAL(false, matched2->Layer() < 2); + CHECK(matched2->Id() == clip2_id); + CHECK_FALSE(matched2->Layer() < 2); Clip* matched3 = t.GetClip("BAD_ID"); - CHECK_EQUAL(true, matched3 == nullptr); + CHECK(matched3 == nullptr); // Ensure we can access the Clip API interfaces after lookup - CHECK_EQUAL(false, matched->Waveform()); - CHECK_EQUAL(true, matched2->Waveform()); + CHECK_FALSE(matched->Waveform()); + CHECK(matched2->Waveform() == true); } -TEST(GetClipEffect_by_id) +TEST_CASE( "GetClipEffect by id", "[libopenshot][timeline]" ) { Timeline t(640, 480, Fraction(30, 1), 44100, 2, LAYOUT_STEREO); - stringstream path1; + std::stringstream path1; path1 << TEST_MEDIA_PATH << "interlaced.png"; auto media_path1 = path1.str(); @@ -515,21 +453,21 @@ TEST(GetClipEffect_by_id) // Check that we can look up clip1's effect auto match1 = t.GetClipEffect("EFFECT00011"); - CHECK_EQUAL(blur1_id, match1->Id()); + CHECK(match1->Id() == blur1_id); // clip2 hasn't been added yet, shouldn't be found match1 = t.GetClipEffect(blur2_id); - CHECK_EQUAL(true, match1 == nullptr); + CHECK(match1 == nullptr); t.AddClip(&clip2); // Check that blur2 can now be found via clip2 match1 = t.GetClipEffect(blur2_id); - CHECK_EQUAL(blur2_id, match1->Id()); - CHECK_EQUAL(2, match1->Layer()); + CHECK(match1->Id() == blur2_id); + CHECK(match1->Layer() == 2); } -TEST(GetEffect_by_id) +TEST_CASE( "GetEffect by id", "[libopenshot][timeline]" ) { Timeline t(640, 480, Fraction(30, 1), 44100, 2, LAYOUT_STEREO); @@ -545,19 +483,19 @@ TEST(GetEffect_by_id) t.AddEffect(&blur1); auto match1 = t.GetEffect(blur1_id); - CHECK_EQUAL(blur1_id, match1->Id()); - CHECK_EQUAL(1, match1->Layer()); + CHECK(match1->Id() == blur1_id); + CHECK(match1->Layer() == 1); match1 = t.GetEffect("NOSUCHNAME"); - CHECK_EQUAL(true, match1 == nullptr); + CHECK(match1 == nullptr); } -TEST(Effect_Blur) +TEST_CASE( "Effect: Blur", "[libopenshot][timeline]" ) { // Create a timeline Timeline t(640, 480, Fraction(30, 1), 44100, 2, LAYOUT_STEREO); - stringstream path_top; + std::stringstream path_top; path_top << TEST_MEDIA_PATH << "interlaced.png"; Clip clip_top(path_top.str()); clip_top.Layer(2); @@ -579,16 +517,19 @@ TEST(Effect_Blur) // Get frame std::shared_ptr f = t.GetFrame(1); + REQUIRE(f != nullptr); + CHECK(f->number == 1); + // Close reader t.Close(); } -TEST(GetMaxFrame_GetMaxTime) +TEST_CASE( "GetMaxFrame and GetMaxTime", "[libopenshot][timeline]" ) { // Create a timeline Timeline t(640, 480, Fraction(30, 1), 44100, 2, LAYOUT_STEREO); - stringstream path1; + std::stringstream path1; path1 << TEST_MEDIA_PATH << "interlaced.png"; Clip clip1(path1.str()); clip1.Layer(1); @@ -596,8 +537,8 @@ TEST(GetMaxFrame_GetMaxTime) clip1.End(45); t.AddClip(&clip1); - CHECK_CLOSE(95.0, t.GetMaxTime(), 0.001); - CHECK_EQUAL(95 * 30 + 1, t.GetMaxFrame()); + CHECK(t.GetMaxTime() == Approx(95.0).margin(0.001)); + CHECK(t.GetMaxFrame() == 95 * 30 + 1); Clip clip2(path1.str()); clip2.Layer(2); @@ -605,16 +546,14 @@ TEST(GetMaxFrame_GetMaxTime) clip2.End(55); t.AddClip(&clip2); - CHECK_EQUAL(95 * 30 + 1, t.GetMaxFrame()); - CHECK_CLOSE(95.0, t.GetMaxTime(), 0.001); + CHECK(t.GetMaxFrame() == 95 * 30 + 1); + CHECK(t.GetMaxTime() == Approx(95.0).margin(0.001)); clip2.Position(100); clip1.Position(80); - CHECK_EQUAL(155 * 30 + 1, t.GetMaxFrame()); - CHECK_CLOSE(155.0, t.GetMaxTime(), 0.001); + CHECK(t.GetMaxFrame() == 155 * 30 + 1); + CHECK(t.GetMaxTime() == Approx(155.0).margin(0.001)); t.RemoveClip(&clip2); - CHECK_EQUAL(125 * 30 + 1, t.GetMaxFrame()); - CHECK_CLOSE(125.0, t.GetMaxTime(), 0.001); + CHECK(t.GetMaxFrame() == 125 * 30 + 1); + CHECK(t.GetMaxTime() == Approx(125.0).margin(0.001)); } - -} // SUITE diff --git a/tests/catch_main.cpp b/tests/catch_main.cpp new file mode 100644 index 000000000..1d97a17b0 --- /dev/null +++ b/tests/catch_main.cpp @@ -0,0 +1,33 @@ +/** + * @file + * @brief Source code for Unit test executable (runs all tests and reports successes and failures) + * @author Jonathan Thomas + * + * @ref License + */ + +/* LICENSE + * + * Copyright (c) 2008-2019 OpenShot Studios, LLC + * . 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 . + * + * 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 . + */ + +#define CATCH_CONFIG_MAIN +#include +