Skip to content

Commit 323859e

Browse files
Yingjie Wangcato-o
authored andcommitted
fixed image bounds error status null bug + test case
Signed-off-by: Yingjie Wang <yingjiew@pixar.com>
1 parent 21bd2c9 commit 323859e

2 files changed

Lines changed: 117 additions & 8 deletions

File tree

src/opentimelineio/clip.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,27 @@ Clip::available_image_bounds(ErrorStatus* error_status) const
192192
auto active_media = media_reference();
193193
if (!active_media)
194194
{
195-
*error_status = ErrorStatus(
196-
ErrorStatus::CANNOT_COMPUTE_BOUNDS,
197-
"No image bounds set on clip",
198-
this);
195+
if(error_status)
196+
{
197+
*error_status = ErrorStatus(
198+
ErrorStatus::CANNOT_COMPUTE_BOUNDS,
199+
"No image bounds set on clip",
200+
this);
201+
}
202+
199203
return std::optional<IMATH_NAMESPACE::Box2d>();
200204
}
201205

202206
if (!active_media->available_image_bounds())
203207
{
204-
*error_status = ErrorStatus(
205-
ErrorStatus::CANNOT_COMPUTE_BOUNDS,
206-
"No image bounds set on media reference on clip",
207-
this);
208+
if(error_status)
209+
{
210+
*error_status = ErrorStatus(
211+
ErrorStatus::CANNOT_COMPUTE_BOUNDS,
212+
"No image bounds set on media reference on clip",
213+
this);
214+
}
215+
208216
return std::optional<IMATH_NAMESPACE::Box2d>();
209217
}
210218

tests/test_clip.cpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,107 @@ main(int argc, char** argv)
260260
assertEqual(marker->color().c_str(), red);
261261
});
262262

263+
// test to ensure null error_status pointers are correctly handled
264+
tests.add_test("test_error_ptr_null", [] {
265+
266+
// std::cout << "running error null test" << std::endl;
267+
268+
using namespace otio;
269+
270+
// tests for no image bounds on media reference on clip
271+
otio::ErrorStatus status_mr;
272+
SerializableObject::Retainer<> so_mr =
273+
SerializableObject::from_json_string(
274+
R"(
275+
{
276+
"OTIO_SCHEMA": "Clip.1",
277+
"media_reference": {
278+
"OTIO_SCHEMA": "ExternalReference.1",
279+
"target_url": "unit_test_url",
280+
"available_range": {
281+
"OTIO_SCHEMA": "TimeRange.1",
282+
"duration": {
283+
"OTIO_SCHEMA": "RationalTime.1",
284+
"rate": 24,
285+
"value": 8
286+
},
287+
"start_time": {
288+
"OTIO_SCHEMA": "RationalTime.1",
289+
"rate": 24,
290+
"value": 10
291+
}
292+
},
293+
"available_image_bounds": null
294+
}
295+
})",
296+
&status_mr);
297+
298+
// checks status is not an error
299+
assertFalse(is_error(status_mr));
300+
301+
// makes sure clip has a value and isn't null
302+
const Clip* mr_clip = dynamic_cast<const Clip*>(so_mr.value);
303+
assertNotNull(mr_clip);
304+
305+
// check that there is an error, and that it's the correct error
306+
otio::ErrorStatus mr_bounds_error;
307+
mr_clip->available_image_bounds(&mr_bounds_error);
308+
assertTrue(otio::is_error(mr_bounds_error));
309+
assertEqual(
310+
mr_bounds_error.outcome,
311+
otio::ErrorStatus::CANNOT_COMPUTE_BOUNDS);
312+
313+
// check that if null ptr, nothing happens
314+
otio::ErrorStatus* null_test = nullptr;
315+
316+
assertEqual(
317+
mr_clip->available_image_bounds(null_test), std::optional<IMATH_NAMESPACE::Box2d>()
318+
);
319+
320+
321+
322+
});
323+
324+
tests.add_test("test_error_ptr_null_no_media", [] {
325+
using namespace otio;
326+
327+
// tests for no image bounds and no media reference on clip
328+
329+
otio::ErrorStatus status;
330+
SerializableObject::Retainer<> so =
331+
SerializableObject::from_json_string(
332+
R"(
333+
{
334+
"OTIO_SCHEMA": "Clip.1"
335+
})",
336+
&status);
337+
338+
assertFalse(is_error(status));
339+
340+
Clip* clip = dynamic_cast<Clip*>(so.value);
341+
assertNotNull(clip);
342+
343+
// set media reference key to null
344+
otio::ErrorStatus* media_ref_key_error;
345+
clip->set_active_media_reference_key("", media_ref_key_error);
346+
347+
otio::ErrorStatus bounds_error_no_mr;
348+
clip->available_image_bounds(&bounds_error_no_mr);
349+
assertTrue(otio::is_error(bounds_error_no_mr));
350+
351+
assertEqual(
352+
bounds_error_no_mr.outcome,
353+
otio::ErrorStatus::CANNOT_COMPUTE_BOUNDS);
354+
355+
// std::cout<< "bounds error details: " << bounds_error_no_mr.details << std::endl;
356+
357+
otio::ErrorStatus* null_test_no_mr = nullptr;
358+
359+
assertEqual(
360+
clip->available_image_bounds(null_test_no_mr), std::optional<IMATH_NAMESPACE::Box2d>()
361+
);
362+
});
363+
263364
tests.run(argc, argv);
264365
return 0;
265366
}

0 commit comments

Comments
 (0)