src/AbstractJavaTestCase.st
author vranyj1
Fri, 25 Nov 2011 08:02:14 +0000
branchjk_new_structure
changeset 1155 d6f6d5fc0343
parent 1152 040cba55a7d2
permissions -rw-r--r--
(none)

"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 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.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010
"
"{ 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

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 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.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010

"
! !

!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$'
! !