JavaClassReader2Tests.st
author Claus Gittinger <cg@exept.de>
Thu, 24 Nov 2011 12:54:24 +0100
changeset 2290 cd61fd0b66ac
parent 2152 1cbdfbcc685c
permissions -rw-r--r--
fixed: #version_SVN ($ to ยง)

"
 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' }"

AbstractJavaTestCase subclass:#JavaClassReader2Tests
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Java-Tests-RuntimeConstantPool'
!

!JavaClassReader2Tests 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.

"
! !

!JavaClassReader2Tests methodsFor:'tests'!

_testJavaInitializationWithNewReader

    "Disabled by default, since it flushes
     Java causing hudson test runner to fail
     (proxy testcases are already loaded)"
    

    self assert: false.
    JavaClassReader useNewClassReader.
    Java flushAllJavaResources.
    Java initialize.
    JavaVM initializeVM.
    JavaClassReader useOldClassReader.

    "Modified: / 12-05-2011 / 18:21:32 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Created: / 01-06-2011 / 21:48:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

_testJavaInitializationWithOldReader

    "Disabled by default, since it flushes
     Java causing hudson test runner to fail
     (proxy testcases are already loaded)"

    JavaClassReader useOldClassReader.
    Java flushAllJavaResources.
    Java initialize.
    JavaVM initializeVM.
    JavaClassReader useOldClassReader.

    "Created: / 01-06-2011 / 21:47:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testReadingClass
    | reader  constantPool  result |

    reader := JavaClassReader new.
    constantPool := JavaConstantPool new: 1.
    constantPool at: 1 put: 'Ljava/lang/Object;'.
    reader constants: constantPool.
    reader stream: (ReadStream on: #( 1 0 )).
    result := reader readConstant_Class.
    self assertTrue: (result notNil).
    self assertTrue: (result isJavaRef).
    self assertTrue: (result isNewJavaRef).
    self assertTrue: (result name = 'Ljava/lang/Object;').

    "Created: / 10-05-2011 / 13:52:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 08-08-2011 / 17:25:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testReadingField
    | reader  constantPool  result |

    reader := JavaClassReader new.
    constantPool := JavaConstantPool new: 5.
    constantPool at: 1 put: 'class'.
    constantPool at: 2 put: (self getClassRefIn: constantPool withNameAt: 1).
    constantPool at: 3
        put: (self 
                getNameAndTypeIn: constantPool
                withNameAt: 4
                andTypeAt: 5).
    constantPool at: 4 put: 'name'.
    constantPool at: 5 put: 'type'.
    constantPool owner: self javaLangObject.
    reader constants: constantPool.
    reader stream: (ReadStream on: #( 2 0 3 0 )).
    result := reader readConstant_Fieldref.
    self assertTrue: (result notNil).
    self assertTrue: (result isJavaRef).
    self assertTrue: (result isNewJavaRef).
    self assertTrue: (result classRef isJavaRef).
    self assertTrue: (result nameAndType isNewJavaNameAndType).
    self assertTrue: (result nameAndType name = 'name').
    self assertTrue: (result nameAndType descriptor = 'type').
    self assertTrue: (result owner = self javaLangObject).

    "Created: / 10-05-2011 / 14:12:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 23-05-2011 / 18:00:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 08-08-2011 / 17:25:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testReadingInterfaceMethod
    | reader  constantPool  result |

    reader := JavaClassReader new.
    constantPool := JavaConstantPool new: 5.
    constantPool at: 1 put: 'class'.
    constantPool at: 2 put: (self getClassRefIn: constantPool withNameAt: 1).
    constantPool at: 3
        put: (self 
                getNameAndTypeIn: constantPool
                withNameAt: 4
                andTypeAt: 5).
    constantPool at: 4 put: 'name'.
    constantPool at: 5 put: 'type'.
    constantPool owner: self javaLangObject.
    reader constants: constantPool.
    reader stream: (ReadStream on: #( 2 0 3 0 )).
    result := reader readConstant_InterfaceMethodref.
    self assertTrue: (result notNil).
    self assertTrue: (result isJavaRef).
    self assertTrue: (result isNewJavaRef).
    self assertTrue: (result classRef isNewJavaRef).
    self assertTrue: (result classRef isNewJavaRef).
    self assertTrue: (result nameAndType isNewJavaNameAndType).
    self assertTrue: (result nameAndType name = 'name').
    self assertTrue: (result nameAndType descriptor = 'type').
    self assertTrue: (result owner = self javaLangObject).
    self assertTrue: (result owner = self javaLangObject).

    "Created: / 10-05-2011 / 14:12:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 23-05-2011 / 18:00:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 08-08-2011 / 17:25:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testReadingMethod
    | reader  constantPool  result |

    reader := JavaClassReader new.
    constantPool := JavaConstantPool new: 5.
    constantPool at: 1 put: 'class'.
    constantPool at: 2 put: (self getClassRefIn: constantPool withNameAt: 1).
    constantPool at: 3
        put: (self 
                getNameAndTypeIn: constantPool
                withNameAt: 4
                andTypeAt: 5).
    constantPool at: 4 put: 'name'.
    constantPool at: 5 put: 'type'.
    constantPool owner: self javaLangObject.
    reader constants: constantPool.
    reader stream: (ReadStream on: #( 2 0 3 0 )).
    result := reader readConstant_Methodref.
    self assertTrue: (result notNil).
    self assertTrue: (result isJavaRef).
    self assertTrue: (result isNewJavaRef).
    self assertTrue: (result classRef isNewJavaRef).
    self assertTrue: (result classRef isNewJavaRef).
    self assertTrue: (result nameAndType isNewJavaNameAndType).
    self assertTrue: (result nameAndType name = 'name').
    self assertTrue: (result nameAndType descriptor = 'type').
    self assertTrue: (result owner = self javaLangObject).

    "Created: / 10-05-2011 / 14:10:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 23-05-2011 / 18:00:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 08-08-2011 / 17:25:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testReadingNameAndType
    | reader  constantPool  result |

    reader := JavaClassReader new.
    constantPool := JavaConstantPool new: 2.
    constantPool at: 1 put: 'foo'.
    constantPool at: 2 put: 'bar'.
    reader constants: constantPool.
    reader stream: (ReadStream on: #( 1 0 2 0 )).
    result := reader readConstant_NameAndType.
    self assertTrue: (result notNil).
    self assertTrue: (result isJavaNameAndType).
    self assertTrue: (result isNewJavaNameAndType).
    self assertTrue: (result name = 'foo').
    self assertTrue: (result descriptor = 'bar').

    "Created: / 10-05-2011 / 13:56:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 08-08-2011 / 17:25:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testReadingStream

    |result|    
    result := JavaClassReader readStream: self getCrateClassReadStream.
    self assertTrue: (result notNil).

    "Created: / 10-05-2011 / 12:16:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 08-08-2011 / 17:25:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testWholeConstantPoolContainsFullyInitializedItems
    | result |

    result := JavaClassReader readStream: self getCrateClassReadStream.
    result constantPool do: 
            [:each | 
            each isJavaRef 
                ifTrue: [ self assertTrue: each isNewJavaRef. self assertTrue: each owner notNil. self assertTrue: each constantPool notNil.]
                ifFalse: 
                    [ each isJavaNameAndType 
                        ifTrue: [ self assertTrue: each isNewJavaNameAndType. self assertTrue: each owner notNil. self assertTrue: each constantPool notNil.] ] ].

    "Created: / 10-05-2011 / 17:01:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

testWholeConstantPoolContainsOnlyNewRefs
    | result |

    result := JavaClassReader readStream: self getCrateClassReadStream.
    result constantPool do: 
            [:each | 
            each isJavaRef 
                ifTrue: [ self assertTrue: each isNewJavaRef ]
                ifFalse: 
                    [ each isJavaNameAndType 
                        ifTrue: [ self assertTrue: each isNewJavaNameAndType ] ] ].

    "Created: / 10-05-2011 / 12:18:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 10-05-2011 / 16:59:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaClassReader2Tests class methodsFor:'documentation'!

version_SVN
    ^ '$Id: JavaClassReader2Tests.st,v 1.1 2011-08-18 19:06:53 vrany Exp $'
! !