initial checkin
authorClaus Gittinger <cg@exept.de>
Tue, 06 Apr 2010 10:12:58 +0200
changeset 558 42dd167a9462
parent 557 c4d3715477f8
child 559 92ef051a8990
initial checkin
RegressionTests__BehaviorLookupObjectTests.st
--- /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$'
+! !