AbstractJavaTestCase.st
changeset 749 e898eaeff091
child 2152 1cbdfbcc685c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AbstractJavaTestCase.st	Fri Aug 19 08:58:19 2011 +0000
@@ -0,0 +1,354 @@
+"
+ COPYRIGHT (c) 1996-2011 by Claus Gittinger
+ COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+                            SWING Research Group, Czech Technical University in Prague
+
+ Parts of the code written by Claus Gittinger are under following
+ license:
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+
+ Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+ [1] Code written at SWING Research Group contain a signature
+     of one of the above copright owners.
+"
+"{ Package: 'stx:libjava' }"
+
+TestCase subclass:#AbstractJavaTestCase
+	instanceVariableNames:'exceptionThrowerBackup'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Languages-Java-Tests-RuntimeConstantPool'
+!
+
+!AbstractJavaTestCase class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1996-2011 by Claus Gittinger
+ COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+                            SWING Research Group, Czech Technical University in Prague
+
+ Parts of the code written by Claus Gittinger are under following
+ license:
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+
+ Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+ [1] Code written at SWING Research Group contain a signature
+     of one of the above copright owners.
+
+"
+! !
+
+!AbstractJavaTestCase class methodsFor:'resources'!
+
+resources
+    ^ Array with: JavaInitializedResource with: JavaTestsResource.
+
+    "Created: / 26-04-2011 / 13:03:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
+!AbstractJavaTestCase methodsFor:'cp creation helpers'!
+
+getClassRefNamed: name 
+    "creates classRef with correctly prepared constant pool"
+    
+    | cp |
+
+    cp := JavaConstantPool new:2.
+    cp at: 1 put: (self getClassRefIn: cp withNameAt: 2).
+    cp at: 2 put: name.
+
+    ^ cp at: 1.
+
+    "Created: / 23-05-2011 / 16:17:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+getFieldRefNamed: name typed: type inClass: classString
+    "creates fieldRef with correctly prepared constant pool"
+    | cp |
+
+    cp := JavaConstantPool new: 6.
+    cp at: 1 put: (self getClassRefIn: cp withNameAt: 2).
+    cp at: 2 put: classString.
+    cp at: 3 put: name.
+    cp at: 4 put: type.
+    cp at: 5
+        put: (self 
+                getFieldRefIn: cp
+                withNameAndTypeAt: 6 andClassAt: 1).
+    cp at: 6 put: (self getNameAndTypeIn: cp withNameAt: 3 andTypeAt: 4).
+    ^ cp at: 5.
+
+    "Created: / 23-05-2011 / 15:56:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+getInterfaceMethodRefNamed: name typed: type inClass: classString 
+   "creates interfaceMethodRef with correctly prepared constant pool"
+    | cp |
+
+    cp := JavaConstantPool new: 6.
+    cp at: 1 put: (self getClassRefIn: cp withNameAt: 2).
+    cp at: 2 put: classString.
+    cp at: 3 put: name.
+    cp at: 4 put: type.
+    cp at: 5
+        put: (self 
+                getInterfaceMethodRefIn: cp
+                withNameAndTypeAt: 6
+                andClassAt: 1).
+    cp at: 6
+        put: (self 
+                getNameAndTypeIn: cp
+                withNameAt: 3
+                andTypeAt: 4).
+    ^ cp at: 5.
+
+    "Created: / 23-05-2011 / 16:15:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+getMethodRefNamed: name typed: type inClass: classString 
+   "creates methodRef with correctly prepared constant pool"
+    | cp |
+
+    cp := JavaConstantPool new: 6.
+    cp at: 1 put: (self getClassRefIn: cp withNameAt: 2).
+    cp at: 2 put: classString.
+    cp at: 3 put: name.
+    cp at: 4 put: type.
+    cp at: 5
+        put: (self 
+                getMethodRefIn: cp
+                withNameAndTypeAt: 6
+                andClassAt: 1).
+    cp at: 6
+        put: (self 
+                getNameAndTypeIn: cp
+                withNameAt: 3
+                andTypeAt: 4).
+    ^ cp at: 5.
+
+    "Created: / 23-05-2011 / 16:00:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
+!AbstractJavaTestCase methodsFor:'helpers'!
+
+disableMockedExceptionThrowing
+    JavaResolver uniqueInstance exceptionThrower: exceptionThrowerBackup.
+
+    "Created: / 13-04-2011 / 14:11:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+enableMockedExceptionThrowing
+    exceptionThrowerBackup := JavaResolver uniqueInstance exceptionThrower.
+    JavaResolver uniqueInstance exceptionThrower: JavaExceptionThrowerMock new.
+
+    "Created: / 13-04-2011 / 14:11:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+getCrateClassReadStream
+    ^ ((Filename named: UserPreferences current javaTestsDirectory) 
+        / 'libjava' / 'bin' 
+        / 'stx' / 'libjava' 
+        / 'tests' / 'mocks' 
+        / 'Crate.class') readStream.
+
+    "Created: / 10-05-2011 / 12:13:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 12-05-2011 / 16:26:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+getPrettyBigConstantPool
+    | cp |
+
+    cp := JavaConstantPool new: 20.
+    cp at: 1 put: 6.
+    cp at: 2 put: 'Ljava/lang/Object;'.
+    cp at: 3 putClassRefWithNameAt: 2.
+    cp 
+        at: 4
+        putMethodRefWithClassAt: 3
+        andNameAndTypeAt: 5.
+    cp 
+        at: 5
+        putNameAndTypeWithNameAt: 6
+        andDescriptorAt: 7.
+    cp at: 6 put: '<init>'.
+    cp at: 7 put: '()V'.
+    cp at: 8 put: 'Ljava/lang/String;'.
+    cp at: 9 putClassRefWithNameAt: 8.
+    cp 
+        at: 10
+        putMethodRefWithClassAt: 9
+        andNameAndTypeAt: 13.
+    cp at: 11 put: 'length'.
+    cp at: 12 put: '()I'.
+    cp 
+        at: 13
+        putNameAndTypeWithNameAt: 11
+        andDescriptorAt: 12.
+    cp at: 14 putClassRefWithNameAt: 15.
+    cp at: 15 put: 'Ljava/lang/Runnable;'.
+    cp at: 16 put: 'run'.
+    cp at: 17 put: '()V'.
+    cp 
+        at: 18
+        putNameAndTypeWithNameAt: 16
+        andDescriptorAt: 17.
+    cp at: 19 putClassRefWithNameAt: 15.
+    cp 
+        at: 20
+        putInterfaceMethodRefWithClassAt: 19
+        andNameAndTypeAt: 18.
+    ^ cp
+
+    "Modified: / 23-05-2011 / 15:16:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+javaLangObject
+^Java classForName:'java.lang.Object'.
+
+    "Created: / 12-05-2011 / 19:09:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
+!AbstractJavaTestCase methodsFor:'refs creation'!
+
+getClassRefIn: aJavaConstantPool withNameAt: nameCPIndex 
+    | result |
+
+    result := JavaClassRef2 in: aJavaConstantPool withNameAt: nameCPIndex.
+    result owner: self javaLangObject.
+    ^ result.
+
+    "Created: / 12-05-2011 / 19:14:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 23-05-2011 / 16:24:32 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+getFieldRefIn: cp withNameAndTypeAt: nmIndex andClassAt: classIndex 
+    |result|
+
+    result := JavaFieldRef2 
+        in: cp
+        withNameAndTypeAt: nmIndex
+        andClassAt: classIndex.
+result owner: self javaLangObject.
+    ^ result.
+
+    "Created: / 23-05-2011 / 16:01:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+getInterfaceMethodRefIn: cp withNameAndTypeAt: nmIndex andClassAt: classIndex 
+    |result|
+
+    result:= JavaInterfaceMethodRef2 
+        in: cp
+        withNameAndTypeAt: nmIndex
+        andClassAt: classIndex.
+ result owner: self javaLangObject.
+    ^ result.
+
+    "Created: / 23-05-2011 / 15:58:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+getMethodRefIn: cp withNameAndTypeAt: nmIndex andClassAt: classIndex 
+    |result|
+
+    result := JavaMethodRef2 
+        in: cp
+        withNameAndTypeAt: nmIndex
+        andClassAt: classIndex.
+ result owner: self javaLangObject.
+    ^ result.
+
+    "Created: / 23-05-2011 / 15:58:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+getNameAndTypeIn: cp withNameAt: nameIndex andTypeAt: typeIndex 
+    |result|
+
+    result := JavaNameAndType2 
+        in: cp
+        withNameAt: nameIndex
+        andDescriptorAt: typeIndex.
+ result owner: self javaLangObject.
+    ^ result.
+
+    "Created: / 23-05-2011 / 16:00:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
+!AbstractJavaTestCase methodsFor:'running'!
+
+setUp
+    self enableMockedExceptionThrowing.
+
+    "Created: / 12-05-2011 / 17:30:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 23-05-2011 / 18:02:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+tearDown
+
+    self disableMockedExceptionThrowing.
+
+    "Created: / 12-05-2011 / 17:30:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 08-08-2011 / 17:24:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!AbstractJavaTestCase class methodsFor:'documentation'!
+
+version_SVN
+    ^ '$Id$'
+! !
\ No newline at end of file