--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/RegressionTests__BehaviorLookupObjectTests.st Tue Apr 06 10:12:58 2010 +0200
@@ -0,0 +1,142 @@
+"{ Package: 'exept:regression' }"
+
+"{ NameSpace: RegressionTests }"
+
+TestCase subclass:#BehaviorLookupObjectTests
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ category:'tests-Regression'
+!
+
+Object subclass:#BadLookupClass
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ privateIn:BehaviorLookupObjectTests
+!
+
+Object subclass:#ClassWithSpecialLookup
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ privateIn:BehaviorLookupObjectTests
+!
+
+Object subclass:#LookupClass
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ privateIn:BehaviorLookupObjectTests
+!
+
+
+!BehaviorLookupObjectTests methodsFor:'helpers'!
+
+returnConstant98765
+ ^ 98765
+! !
+
+!BehaviorLookupObjectTests methodsFor:'tests'!
+
+testLookupObject_01a
+ ClassWithSpecialLookup setLookupObject:BadLookupClass.
+ self should:[ ClassWithSpecialLookup new x ] raise:MessageNotUnderstood.
+
+ "/ at some time during the development, it crashed the second time,
+ "/ due to a badly updated inlineCache
+ ClassWithSpecialLookup setLookupObject:BadLookupClass.
+ self should:[ ClassWithSpecialLookup new x ] raise:MessageNotUnderstood.
+!
+
+testLookupObject_01b
+ |firstException rslt|
+
+ firstException := true.
+
+ "/ catch it, and proceed without a method (leads to another dnu)...
+ MessageNotUnderstood handle:[:ex |
+ firstException ifTrue:[
+ firstException := false.
+ self assert:(ex suspendedContext selector == #doesNotUnderstand:).
+ self assert:(ex suspendedContext sender selector == #lookupMethodForMessage:to:from:).
+ "/ here, we return a method...
+ ex proceedWith:nil.
+ ].
+ self assert:(ex suspendedContext selector == #doesNotUnderstand:).
+ self assert:(ex suspendedContext sender selector == #x).
+ ex proceedWith:12345.
+ ] do:[
+ ClassWithSpecialLookup setLookupObject:BadLookupClass.
+ ObjectMemory flushInlineCaches.
+ rslt := ClassWithSpecialLookup new x
+ ].
+
+ self assert:(rslt = 12345).
+!
+
+testLookupObject_01c
+ |rslt|
+
+ "/ catch it, and proceed with a method...
+ MessageNotUnderstood handle:[:ex |
+ self assert:(ex suspendedContext selector == #doesNotUnderstand:).
+ self assert:(ex suspendedContext sender selector == #lookupMethodForMessage:to:from:).
+ "/ here, we return a method...
+ ex proceedWith:(self class compiledMethodAt:#returnConstant98765).
+ ] do:[
+ ClassWithSpecialLookup setLookupObject:BadLookupClass.
+ ObjectMemory flushInlineCaches.
+ rslt := ClassWithSpecialLookup new x
+ ].
+
+ self assert:(rslt = 98765).
+!
+
+testLookupObject_02
+ "/ check lookupObject with 2.. arguments
+ ClassWithSpecialLookup setLookupObject:LookupClass.
+ self should:[ ClassWithSpecialLookup new x:1234 ] raise:MessageNotUnderstood.
+
+ ClassWithSpecialLookup setLookupObject:LookupClass.
+ self should:[ ClassWithSpecialLookup new a1:1 a2:2] raise:MessageNotUnderstood.
+
+"/ ClassWithSpecialLookup setLookupObject:LookupClass.
+"/ self should:[ ClassWithSpecialLookup new a1:1 a2:2 a3:3] raise:MessageNotUnderstood.
+"/
+"/ ClassWithSpecialLookup setLookupObject:LookupClass.
+"/ self should:[ ClassWithSpecialLookup new a1:1 a2:2 a3:3 a4:4] raise:MessageNotUnderstood.
+"/
+"/ ClassWithSpecialLookup setLookupObject:LookupClass.
+"/ self should:[ ClassWithSpecialLookup new a1:1 a2:2 a3:3 a4:4 a5:5] raise:MessageNotUnderstood.
+"/
+"/ ClassWithSpecialLookup setLookupObject:LookupClass.
+"/ self should:[ ClassWithSpecialLookup new a1:1 a2:2 a3:3 a4:4 a5:5 a6:6] raise:MessageNotUnderstood.
+"/
+"/ ClassWithSpecialLookup setLookupObject:LookupClass.
+"/ self should:[ ClassWithSpecialLookup new a1:1 a2:2 a3:3 a4:4 a5:5 a6:6 a7:7] raise:MessageNotUnderstood.
+!
+
+testLookupObject_02c
+ |rslt|
+
+ "/ catch it, and proceed with a method...
+ MessageNotUnderstood handle:[:ex |
+ self assert:(ex suspendedContext selector == #doesNotUnderstand:).
+ self assert:(ex suspendedContext sender selector == #lookupMethodForMessage:to:from:).
+ "/ here, we return a method...
+ ex proceedWith:(self class compiledMethodAt:#returnConstant98765).
+ ] do:[
+ ClassWithSpecialLookup setLookupObject:BadLookupClass.
+ ObjectMemory flushInlineCaches.
+ rslt := ClassWithSpecialLookup new x:1234
+ ].
+
+ self assert:(rslt = 98765).
+! !
+
+!BehaviorLookupObjectTests class methodsFor:'documentation'!
+
+version_CVS
+ ^ '$Header$'
+! !