@@ -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