diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 00e545e6c..e4f128b1a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,7 +15,7 @@ foreach(test ${tests_opentime}) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endforeach() -list(APPEND tests_opentimelineio test_clip test_serialization test_serializableCollection test_timeline test_track) +list(APPEND tests_opentimelineio test_clip test_find_children test_serialization test_serializableCollection test_timeline test_track) foreach(test ${tests_opentimelineio}) add_executable(${test} utils.h utils.cpp ${test}.cpp) diff --git a/tests/test_find_children.cpp b/tests/test_find_children.cpp new file mode 100644 index 000000000..3ebf9ff97 --- /dev/null +++ b/tests/test_find_children.cpp @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Contributors to the OpenTimelineIO project + +#include "utils.h" + +#include +#include +#include +#include + + +namespace otime = opentime::OPENTIME_VERSION; +namespace otio = opentimelineio::OPENTIMELINEIO_VERSION; + +using otime::RationalTime; +using otime::TimeRange; + +int +main(int argc, char** argv) +{ + Tests tests; + + // Find children works with one track + tests.add_test("test_find_children_ok", [] { + // Create a timeline, stack and two tracks with one clip each. + otio::SerializableObject::Retainer video_clip = new otio::Clip( + "video_0", + nullptr, + otio::TimeRange( + otio::RationalTime(0.0, 30.0), + otio::RationalTime(704.0, 30.0))); + otio::SerializableObject::Retainer video_track = new otio::Track("Video"); + otio::SerializableObject::Retainer stack = new otio::Stack(); + otio::SerializableObject::Retainer timeline = new otio::Timeline(); + video_track->append_child(video_clip); + + stack->append_child(video_track); + + timeline->set_tracks(stack); + + RationalTime time(703.0, 30.0); + RationalTime one_frame(1.0, 30.0); + TimeRange range(time, one_frame); + otio::ErrorStatus errorStatus; + auto items = timeline->find_children(&errorStatus, range); + assert(!otio::is_error(errorStatus)); + assert(!items.empty()); + }); + + // Find children seems broken with two tracks + tests.add_test("test_find_children_broken", [] { + + // Create a timeline, stack and two tracks with one clip each. + otio::SerializableObject::Retainer video_clip = new otio::Clip( + "video_0", + nullptr, + otio::TimeRange( + otio::RationalTime(0.0, 30.0), + otio::RationalTime(704.0, 30.0))); + otio::SerializableObject::Retainer audio_clip = new otio::Clip( + "audio_0", + nullptr, + otio::TimeRange( + otio::RationalTime(5.0, 24.0), + otio::RationalTime(20.0, 24.0))); + otio::SerializableObject::Retainer video_track = new otio::Track("Video"); + otio::SerializableObject::Retainer audio_track = new otio::Track("Audio"); + otio::SerializableObject::Retainer stack = new otio::Stack(); + otio::SerializableObject::Retainer timeline = new otio::Timeline(); + video_track->append_child(video_clip); + audio_track->append_child(audio_clip); + + stack->append_child(video_track); + stack->append_child(audio_track); + + timeline->set_tracks(stack); + + RationalTime time(703.0, 30.0); + RationalTime one_frame(1.0, 30.0); + TimeRange range(time, one_frame); + otio::ErrorStatus errorStatus; + auto items = timeline->find_children(&errorStatus, range); + assert(!otio::is_error(errorStatus)); + assert(!items.empty()); + }); + + tests.run(argc, argv); + return 0; +}