Skip to content

Commit 611a24f

Browse files
committed
added composition class test script and moved tests from subclass to parent class test script
Signed-off-by: Yingjie Wang <[email protected]>
1 parent b5596f8 commit 611a24f

File tree

5 files changed

+68
-38
lines changed

5 files changed

+68
-38
lines changed

src/py-opentimelineio/opentimelineio-bindings/otio_serializableObjects.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,11 @@ Should be subclassed (for example by :class:`.Track` and :class:`.Stack`), not u
513513
.def("find_children", [](Composition* c, py::object descended_from_type, std::optional<TimeRange> const& search_range, bool shallow_search) {
514514
return find_children(c, descended_from_type, search_range, shallow_search);
515515
}, "descended_from_type"_a = py::none(), "search_range"_a = std::nullopt, "shallow_search"_a = false)
516+
517+
.def("find_clips", [](Composition* c, std::optional<TimeRange> const& search_range, bool shallow_search) {
518+
return find_clips(c, search_range, shallow_search);
519+
}, "search_range"_a = std::nullopt, "shallow_search"_a = false);
520+
516521
.def("handles_of_child", [](Composition* c, Composable* child) {
517522
auto result = c->handles_of_child(child, ErrorStatusHandler());
518523
return py::make_tuple(py::cast(result.first), py::cast(result.second));
@@ -587,9 +592,7 @@ Should be subclassed (for example by :class:`.Track` and :class:`.Stack`), not u
587592
auto result = t->neighbors_of(item, ErrorStatusHandler(), policy);
588593
return py::make_tuple(py::cast(result.first.take_value()), py::cast(result.second.take_value()));
589594
}, "item"_a, "policy"_a = Track::NeighborGapPolicy::never)
590-
.def("find_clips", [](Track* t, std::optional<TimeRange> const& search_range, bool shallow_search) {
591-
return find_clips(t, search_range, shallow_search);
592-
}, "search_range"_a = std::nullopt, "shallow_search"_a = false);
595+
593596

594597
py::class_<Track::Kind>(track_class, "Kind")
595598
.def_property_readonly_static("Audio", [](py::object /* self */) { return Track::Kind::audio; })
@@ -622,9 +625,7 @@ Should be subclassed (for example by :class:`.Track` and :class:`.Stack`), not u
622625
"markers"_a = py::none(),
623626
"effects"_a = py::none(),
624627
py::arg_v("metadata"_a = py::none()))
625-
.def("find_clips", [](Stack* s, std::optional<TimeRange> const& search_range, bool shallow_search) {
626-
return find_clips(s, search_range, shallow_search);
627-
}, "search_range"_a = std::nullopt, "shallow_search"_a = false);
628+
628629

629630
py::class_<Timeline, SerializableObjectWithMetadata, managing_ptr<Timeline>>(m, "Timeline", py::dynamic_attr())
630631
.def(py::init([](std::string name,

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ foreach(test ${tests_opentime})
1515
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
1616
endforeach()
1717

18-
list(APPEND tests_opentimelineio test_clip test_serialization test_serializableCollection test_stack_algo test_timeline test_track test_editAlgorithm)
18+
list(APPEND tests_opentimelineio test_clip test_serialization test_serializableCollection test_stack_algo test_timeline test_track test_editAlgorithm test_composition)
1919
foreach(test ${tests_opentimelineio})
2020
add_executable(${test} utils.h utils.cpp ${test}.cpp)
2121

tests/test_composition.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Contributors to the OpenTimelineIO project
3+
4+
#include "utils.h"
5+
6+
#include <opentimelineio/composition.h>
7+
#include <opentimelineio/item.h>
8+
#include <opentimelineio/clip.h>
9+
#include <opentimelineio/stack.h>
10+
#include <opentimelineio/track.h>
11+
#include <opentimelineio/transition.h>
12+
13+
#include <iostream>
14+
15+
namespace otime = opentime::OPENTIME_VERSION;
16+
namespace otio = opentimelineio::OPENTIMELINEIO_VERSION;
17+
18+
int
19+
main(int argc, char** argv)
20+
{
21+
Tests tests;
22+
23+
// test a basic case of find_children
24+
tests.add_test(
25+
"test_find_children", [] {
26+
using namespace otio;
27+
SerializableObject::Retainer<Composition> comp = new Composition;
28+
SerializableObject::Retainer<Item> item = new Item;
29+
30+
comp->append_child(item);
31+
opentimelineio::v1_0::ErrorStatus err;
32+
auto result = comp->find_children<>(&err);
33+
assertEqual(result.size(), 1);
34+
assertEqual(result[0].value, item.value);
35+
});
36+
37+
// test stack and track correctly calls find_clips from composition parent class
38+
tests.add_test(
39+
"test_find_clips", [] {
40+
using namespace otio;
41+
SerializableObject::Retainer<Stack> stack = new Stack();
42+
SerializableObject::Retainer<Track> track = new Track;
43+
SerializableObject::Retainer<Clip> clip = new Clip;
44+
SerializableObject::Retainer<Transition> transition = new Transition;
45+
46+
stack->append_child(track);
47+
track->append_child(transition);
48+
track->append_child(clip);
49+
50+
opentimelineio::v1_0::ErrorStatus err;
51+
auto items = stack->find_clips(&err);
52+
assertFalse(is_error(err));
53+
assertEqual(items.size(), 1);
54+
assertEqual(items[0].value, clip.value);
55+
});
56+
57+
tests.run(argc, argv);
58+
return 0;
59+
}

tests/test_stack_algo.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -213,22 +213,6 @@ main(int argc, char** argv)
213213
assertEqual(result->duration().value(), 300);
214214
});
215215

216-
// test stack correctly calls find_clips from superclass
217-
tests.add_test(
218-
"test_find_clips", [] {
219-
using namespace otio;
220-
SerializableObject::Retainer<Stack> stack = new Stack();
221-
SerializableObject::Retainer<Track> track = new Track;
222-
SerializableObject::Retainer<Clip> clip = new Clip;
223-
stack->append_child(track);
224-
track->append_child(clip);
225-
226-
opentimelineio::v1_0::ErrorStatus err;
227-
auto items = stack->find_clips(&err);
228-
assertFalse(is_error(err));
229-
assertEqual(items.size(), 1);
230-
});
231-
232216
tests.run(argc, argv);
233217
return 0;
234218
}

tests/test_track.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ main(int argc, char** argv)
5151
opentimelineio::v1_0::ErrorStatus err;
5252
auto result = tr->find_children<otio::Clip>(
5353
&err,
54-
TimeRange(RationalTime(0.0, 24.0), RationalTime(24.0, 24.0)));
54+
TimeRange(RationalTime(0.0, 24.0), RationalTime(24.0, 24.0)));
5555
assertEqual(result.size(), 1);
5656
assertEqual(result[0].value, cl0.value);
5757
result = tr->find_children<otio::Clip>(
@@ -166,20 +166,6 @@ main(int argc, char** argv)
166166
std::find(items.begin(), items.end(), clip.value) != items.end());
167167
});
168168

169-
// test track correctly calls find_clips from superclass
170-
tests.add_test(
171-
"test_find_clips", [] {
172-
using namespace otio;
173-
SerializableObject::Retainer<Track> track = new Track;
174-
SerializableObject::Retainer<Clip> clip = new Clip;
175-
track->append_child(clip);
176-
177-
opentimelineio::v1_0::ErrorStatus err;
178-
auto items = track->find_clips(&err);
179-
assertFalse(is_error(err));
180-
assertEqual(items.size(), 1);
181-
});
182-
183169
tests.run(argc, argv);
184170
return 0;
185171
}

0 commit comments

Comments
 (0)