@@ -51,6 +51,7 @@ namespace IECore
5151struct ComputationCacheTest
5252{
5353
54+ static int getCount;
5455 typedef int ComputationParams;
5556 typedef ComputationCache< ComputationParams > Cache;
5657
@@ -65,6 +66,7 @@ struct ComputationCacheTest
6566 static IntDataPtr get ( const ComputationParams ¶ms )
6667 {
6768 int id = params;
69+ getCount++;
6870 return new IntData ( id );
6971 }
7072
@@ -150,6 +152,23 @@ struct ComputationCacheTest
150152 v->writable () = 42 ;
151153 BOOST_CHECK ( *v != *cache.get ( ComputationParams (1 ), Cache::NullIfMissing ) );
152154
155+ // test when the computation function does not match the already registered computation hash....
156+ IntDataPtr weirdValue = new IntData (666 );
157+ cache.clear ();
158+ cache.set ( ComputationParams (1 ), weirdValue, ObjectPool::StoreReference );
159+ ConstObjectPtr v0 = cache.get ( ComputationParams (1 ) );
160+ BOOST_CHECK ( *weirdValue == *cache.get ( ComputationParams (1 ), Cache::NullIfMissing ) );
161+ pool->clear ();
162+ int c1 = ComputationCacheTest::getCount;
163+ ConstObjectPtr v1 = cache.get ( ComputationParams (1 ) );
164+ int c2 = ComputationCacheTest::getCount;
165+ BOOST_CHECK_EQUAL ( 1 , static_cast < const IntData * >(v1.get ())->readable () );
166+ BOOST_CHECK_EQUAL ( c1 + 1 , c2 );
167+ ConstObjectPtr v2 = cache.get ( ComputationParams (1 ) );
168+ int c3 = ComputationCacheTest::getCount;
169+ BOOST_CHECK_EQUAL ( 1 , static_cast < const IntData * >(v2.get ())->readable () );
170+ // / garantee that there was no recomputation.
171+ BOOST_CHECK_EQUAL ( c2, c3 );
153172 }
154173
155174 struct GetFromCache
@@ -192,6 +211,7 @@ struct ComputationCacheTest
192211
193212};
194213
214+ int ComputationCacheTest::getCount (0 );
195215
196216struct ComputationCacheTestSuite : public boost ::unit_test::test_suite
197217{
0 commit comments