MCPcopy Create free account
hub / github.com/ImageEngine/cortex / testMemberRetrieval

Method testMemberRetrieval

test/IECore/CompoundDataTest.cpp:52–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50struct CompoundDataTest
51{
52 void testMemberRetrieval()
53 {
54
55 CompoundDataPtr c = new CompoundData();
56
57 c->writable()["floatElement"] = new FloatData( 42.0f );
58 c->writable()["stringElement"] = new StringData( "cake" );
59
60 try
61 {
62 FloatData *f = c->member<FloatData>( "floatElement", false );
63 BOOST_CHECK( f );
64 BOOST_CHECK( f->staticTypeId() == FloatData::staticTypeId() );
65
66 IntData *i = c->member<IntData>( "floatElement", false );
67 BOOST_CHECK( !i );
68
69 StringData *s = c->member<StringData>( "iAmMissing", false );
70 BOOST_CHECK( !s );
71
72 }
73 catch ( std::exception &e )
74 {
75 BOOST_WARN( !e.what() );
76 BOOST_CHECK( !"Exception thrown during member retrieval with exceptions disabled." );
77 }
78
79 try
80 {
81 FloatData *f = c->member<FloatData>( "floatElement", true );
82 BOOST_REQUIRE( f );
83 BOOST_CHECK( f->staticTypeId() == FloatData::staticTypeId() );
84
85 StringData *s = c->member<StringData>( "stringElement", true );
86 BOOST_REQUIRE( s );
87 BOOST_CHECK( s->staticTypeId() == StringData::staticTypeId() );
88 }
89 catch ( std::exception &e )
90 {
91 BOOST_WARN( !e.what() );
92 BOOST_CHECK( !"Exception thrown during member retrieval." );
93 }
94
95 try
96 {
97 IntData *i = c->member<IntData>( "floatElement", true );
98 BOOST_CHECK( !"Exception not thrown during invalid member retrieval." );
99 BOOST_CHECK( !i );
100 }
101 catch ( IECore::Exception & )
102 {
103 }
104 catch( ... )
105 {
106 BOOST_CHECK( !"Incorrect exception type thrown during invalid member retrieval." );
107 }
108
109 try

Callers

nothing calls this directly

Calls 3

staticTypeIdMethod · 0.80
whatMethod · 0.80
writableMethod · 0.45

Tested by

no test coverage detected