void testMemberRetrieval() { CompoundDataPtr c = new CompoundData(); c->writable()["floatElement"] = new FloatData( 42.0f ); c->writable()["stringElement"] = new StringData( "cake" ); try { FloatData *f = c->member<FloatData>( "floatElement", false ); BOOST_CHECK( f ); BOOST_CHECK( f->staticTypeId() == FloatData::staticTypeId() ); IntData *i = c->member<IntData>( "floatElement", false ); BOOST_CHECK( !i ); StringData *s = c->member<StringData>( "iAmMissing", false ); BOOST_CHECK( !s ); } catch ( std::exception &e ) { BOOST_WARN( !e.what() ); BOOST_CHECK( !"Exception thrown during member retrieval with exceptions disabled." ); } try { FloatData *f = c->member<FloatData>( "floatElement", true ); BOOST_REQUIRE( f ); BOOST_CHECK( f->staticTypeId() == FloatData::staticTypeId() ); StringData *s = c->member<StringData>( "stringElement", true ); BOOST_REQUIRE( s ); BOOST_CHECK( s->staticTypeId() == StringData::staticTypeId() ); } catch ( std::exception &e ) { BOOST_WARN( !e.what() ); BOOST_CHECK( !"Exception thrown during member retrieval." ); } try { IntData *i = c->member<IntData>( "floatElement", true ); BOOST_CHECK( !"Exception not thrown during invalid member retrieval." ); BOOST_CHECK( !i ); } catch ( IECore::Exception &e ) { } catch( ... ) { BOOST_CHECK( !"Incorrect exception type thrown during invalid member retrieval." ); } try { StringData *s = c->member<StringData>( "iAmMissing", true, false ); BOOST_CHECK( !"Exception not thrown during missing member retrieval." ); BOOST_CHECK( !s ); } catch ( IECore::Exception &e ) { } catch( ... ) { BOOST_CHECK( !"Incorrect exception type thrown during invalid member retrieval." ); } try { StringData *s = c->member<StringData>( "iAmMissing", true, true ); BOOST_REQUIRE( s ); BOOST_CHECK( s->staticTypeId() == StringData::staticTypeId() ); FloatData *f = c->member<CompoundData>( "newParent", true, true )->member<FloatData>( "newChild", true, true ); BOOST_REQUIRE( f ); BOOST_CHECK( f->staticTypeId() == FloatData::staticTypeId() ); } catch ( std::exception &e ) { BOOST_CHECK( !"Exception thrown during creation of member." ); } }