"
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:#JavaClassRefTests
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'Languages-Java-Tests-RuntimeConstantPool'
!
!JavaClassRefTests 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.
"
! !
!JavaClassRefTests methodsFor:'arrays'!
testCorrectArrayCreation
|classRef result expectedResult |
classRef := self getClassRefNamed: '[Ljava/lang/Object;'.
result := classRef resolve.
expectedResult := JavaVM javaArrayClassFor: (Java classForName: 'java.lang.Object').
self assertTrue: (result = expectedResult).
"Created: / 23-05-2011 / 21:15:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
testCorrectMultiArrayCreation
| classRef result expectedResult |
classRef := self getClassRefNamed: '[[[[[Ljava/lang/Object;'.
result := classRef resolve.
expectedResult := JavaVM
javaArrayClassFor: (Java classForName: 'java.lang.Object').
self assertTrue: (result = expectedResult).
"Created: / 23-05-2011 / 21:15:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
!JavaClassRefTests methodsFor:'permission tests'!
testAccessingNonPublicFromInside
| javaClassRef initString throwedException |
self enableMockedExceptionThrowing.
[ initString := 'Lstx/libjava/tests/mocks/NonPublicClass;'.
javaClassRef := self getClassRefNamed: initString.
javaClassRef owner: (Java classForName: 'stx.libjava.tests.mocks.Crate').
javaClassRef resolve. ] on: Error
do: [:e | throwedException := e ].
self assertTrue: (throwedException isNil).
self disableMockedExceptionThrowing.
"Created: / 13-04-2011 / 13:42:47 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 23-05-2011 / 17:58:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
testAccessingNonPublicFromOutside
| javaClassRef initString throwedException |
self enableMockedExceptionThrowing.
[ initString := 'Lstx/libjava/tests/mocks/NonPublicClass;'.
javaClassRef := self getClassRefNamed: initString.
javaClassRef owner: (Java classForName: 'java.lang.Object').
javaClassRef resolve. ] on: Error
do: [:e | throwedException := e ].
self assertTrue: (throwedException notNil
and: [ throwedException messageText = 'IllegalAccessError' ]).
self disableMockedExceptionThrowing.
"Created: / 13-04-2011 / 13:37:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 23-05-2011 / 17:58:22 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
testAccessingPublic
| javaClassRef initString |
self enableMockedExceptionThrowing.
self shouldnt:
[ initString := 'Lstx/libjava/tests/mocks/PublicClass;'.
javaClassRef := self getClassRefNamed: initString.
javaClassRef owner: (Java classForName: 'java.lang.Object').
javaClassRef resolve. ]
raise: Error.
self disableMockedExceptionThrowing.
"Created: / 13-04-2011 / 13:36:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 23-05-2011 / 17:58:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
testNonPublicClassPresent
| javaClassRef initString |
self enableMockedExceptionThrowing.
initString := 'Lstx/libjava/tests/mocks/NonPublicClass;'.
javaClassRef := self getClassRefNamed: initString.
javaClassRef owner: (Java
classForName: 'stx.libjava.tests.mocks.SubclassOfNonPublicClass').
javaClassRef resolve.
self assertTrue: (javaClassRef valueCache notNil).
self disableMockedExceptionThrowing.
"Created: / 13-04-2011 / 13:38:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 23-05-2011 / 17:58:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
testPublicClassPresent
| javaClassRef initString |
self enableMockedExceptionThrowing.
initString := 'Lstx/libjava/tests/mocks/PublicClass;'.
javaClassRef := self getClassRefNamed: initString.
javaClassRef owner: (Java classForName: 'java.lang.Object').
javaClassRef resolve.
self assertTrue: (javaClassRef valueCache notNil).
self disableMockedExceptionThrowing.
"Created: / 13-04-2011 / 13:39:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 23-05-2011 / 17:58:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
!JavaClassRefTests methodsFor:'primitives'!
testAllPrimitiveArrayClasses
| classRef descriptor |
#( $B $C $D $F $I $J $S $Z ) do:
[:each |
descriptor := '[' , each.
classRef := self getClassRefNamed: descriptor.
self assertTrue: ((JavaDescriptor readFromString: descriptor) javaClass
= classRef resolve) ].
"Created: / 23-05-2011 / 20:49:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
testAllPrimitiveClasses
| classRef |
#( $B $C $D $F $I $J $S $Z )
do:
[:each |
classRef := self getClassRefNamed: each asString.
self assertTrue: ((JavaDescriptor baseTypes at: each) = classRef resolve) ].
"Created: / 23-05-2011 / 20:48:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
testAllPrimitiveMultiArrayClasses
| classRef descriptor |
#( $B $C $D $F $I $J $S $Z )
do:
[:each |
descriptor := '[[[[' , each.
classRef := self getClassRefNamed: descriptor.
self assertTrue: ((JavaDescriptor readFromString: descriptor) javaClass
= classRef resolve) ].
"Created: / 23-05-2011 / 20:50:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
!JavaClassRefTests methodsFor:'resolving static tests'!
testCorrectStaticResolving
| javaClassRef initString result expectedResult |
initString := 'Lstx/libjava/tests/mocks/ClassWithInnerClasses$InnerStatic;'.
javaClassRef := self getClassRefNamed: initString.
javaClassRef
owner: (Java classForName: 'stx.libjava.tests.mocks.ClassWithInnerClasses').
expectedResult := Java
classForName: 'stx.libjava.tests.mocks.ClassWithInnerClasses$InnerStatic'.
result := javaClassRef resolveStatic.
self assertTrue: (result = expectedResult).
"Created: / 28-04-2011 / 21:51:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 23-05-2011 / 17:58:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
!JavaClassRefTests methodsFor:'resolving tests'!
testCorrectInstanceCreation
| javaClassRef initString |
initString := 'Ljava/lang/String;'.
javaClassRef := self getClassRefNamed: initString.
self assertFalse: (javaClassRef isResolved).
self assertTrue: (javaClassRef valueCache isNil).
self assertTrue: (javaClassRef name = initString).
"Created: / 08-04-2011 / 14:01:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 23-05-2011 / 17:58:08 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
testCorrectResolving
| javaClassRef initString result expectedResult |
initString := 'Ljava/lang/String;'.
javaClassRef := self getClassRefNamed: initString.
javaClassRef owner: (Java classForName: 'java.lang.Object').
expectedResult := Java classForName: 'java.lang.String'.
result := javaClassRef resolve.
self assertTrue: (result = expectedResult).
"Created: / 08-04-2011 / 14:07:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 23-05-2011 / 17:58:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
testInvalidation
| javaClassRef initString |
initString := 'Ljava/lang/String;'.
javaClassRef := self getClassRefNamed: initString.
javaClassRef owner: (Java classForName: 'java.lang.Object').
self assertTrue: (javaClassRef isResolved not).
javaClassRef resolve.
self assertTrue: (javaClassRef isResolved).
javaClassRef invalidate.
self assertTrue: (javaClassRef isResolved not).
"Created: / 08-04-2011 / 14:09:06 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 23-05-2011 / 17:58:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
testInvalidationForClassNegative
| javaClassRef initString |
initString := 'Ljava/lang/String;'.
javaClassRef := self getClassRefNamed: initString.
javaClassRef owner: (Java classForName: 'java.lang.Object').
self assertTrue: (javaClassRef isResolved not).
javaClassRef resolve.
self assertTrue: (javaClassRef isResolved).
javaClassRef invalidateForClass: 'Ljava/lang/Object;'.
self assertTrue: (javaClassRef isResolved).
"Created: / 08-04-2011 / 16:21:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 23-05-2011 / 17:58:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
testInvalidationForClassPositive
| javaClassRef initString |
initString := 'Ljava/lang/String;'.
javaClassRef := self getClassRefNamed: initString.
javaClassRef owner: (Java classForName: 'java.lang.Object').
self assertTrue: (javaClassRef isResolved not).
javaClassRef resolve.
self assertTrue: (javaClassRef isResolved).
javaClassRef invalidateForClass: initString.
self assertTrue: (javaClassRef isResolved not).
"Created: / 08-04-2011 / 16:21:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 23-05-2011 / 17:57:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
testResolving
| javaClassRef initString |
initString := 'Ljava/lang/String;'.
javaClassRef := self getClassRefNamed: initString.
javaClassRef owner: (Java classForName: 'java.lang.Object').
self assertTrue: (javaClassRef isResolved not).
javaClassRef resolve.
self assertTrue: (javaClassRef isResolved).
"Created: / 08-04-2011 / 14:04:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 23-05-2011 / 17:57:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
!JavaClassRefTests class methodsFor:'documentation'!
version_SVN
^ '$Id: JavaClassRefTests.st,v 1.1 2011-08-18 19:06:53 vrany Exp $'
! !