"
Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
SWING Research Group, Czech Technical University
in Prague
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.
"
"{ Package: 'stx:libjava' }"
TestCase subclass:#JavaLookupTests
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'Languages-Java-Tests-Interop'
!
!JavaLookupTests class methodsFor:'documentation'!
copyright
"
Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
SWING Research Group, Czech Technical University
in Prague
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.
"
!
documentation
"
This testcase tests the java-smalltalk interop lookup
(JavaLookup)
[author:]
Jan Vrany <jan.vrany@fit.cvut.cz>
[instance variables:]
[class variables:]
[see also:]
"
! !
!JavaLookupTests class methodsFor:'resources'!
resources
^ Array with: JavaLookupTestsResource.
"Created: / 11-04-2011 / 19:38:11 / kursjan <kursjan@fit.cvut.cz>"
"Modified: / 29-08-2011 / 23:35:06 / Jan Kurs <kursjan@fit.cvut.cz>"
"Modified: / 29-10-2012 / 07:47:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLookupTests methodsFor:'running'!
setUp
| md |
md := self javaTestClass methodDictionary.
md copy keysAndValuesDo:[:sel :m|
m isProxyMethod ifTrue:[md removeKey: sel]
].
"Created: / 03-12-2012 / 17:50:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 16-12-2012 / 13:35:52 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
! !
!JavaLookupTests methodsFor:'support'!
javaTestClass
^ JAVA cz cvut fit swing methodLookup Object.
"Created: / 05-09-2011 / 20:13:48 / Jan Kurs <kursjan@fit.cvut.cz>"
"Modified: / 30-11-2012 / 22:16:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
personManipulatorClass
"Person Manipulator can interact with Person class defined in Java"
^ JAVA cz cvut fit swing methodLookup PersonManipulator.
"Created: / 06-09-2011 / 21:48:16 / Jan Kurs <kursjan@fit.cvut.cz>"
"Modified: / 30-11-2012 / 22:16:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
setManipulatorClass
"Person Manipulator can interact with Person class defined in Java"
^ JAVA cz cvut fit swing methodLookup SetManipulator.
"Created: / 25-09-2011 / 16:41:02 / Jan Kurs <kursjan@fit.cvut.cz>"
"Modified: / 30-11-2012 / 22:13:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
!JavaLookupTests methodsFor:'tests - java lookup'!
test3
"I am not sure with this test :)"
self shouldnt: [(Java classForName: 'cz.cvut.fit.swing.methodLookup.Object') new isNumber] raise: Exception.
self assert: (Java classForName: 'cz.cvut.fit.swing.methodLookup.Object') new isNumber = false.
"Created: / 11-04-2011 / 19:43:37 / kursjan <kursjan@fit.cvut.cz>"
!
testBasic
self
shouldnt:[ (Java classForName:'java.lang.Object') new hash ]
raise:Exception.
self
shouldnt:[ (Java classForName:'java.lang.Object') new toString ]
raise:Exception.
"Created: / 11-04-2011 / 19:22:07 / kursjan <kursjan@fit.cvut.cz>"
!
testBoolean
self assert: (self javaTestClass new getTrue) = true.
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
"Created: / 05-09-2011 / 21:06:13 / Jan Kurs <kursjan@fit.cvut.cz>"
!
testBoolean2
self assert: (self javaTestClass new getFalse) = false.
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
"Created: / 05-09-2011 / 21:06:25 / Jan Kurs <kursjan@fit.cvut.cz>"
!
testBoolean3
self assert: (self javaTestClass new getTruePrim) = true.
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
"Created: / 05-09-2011 / 21:07:29 / Jan Kurs <kursjan@fit.cvut.cz>"
!
testBoolean4
self assert: (self javaTestClass new getFalsePrim) = false.
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
"Created: / 05-09-2011 / 21:07:38 / Jan Kurs <kursjan@fit.cvut.cz>"
!
testBoolean5
self assert: (self javaTestClass new getFalseWithConversion) = false.
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
"Created: / 25-09-2011 / 19:23:36 / Jan Kurs <kursjan@fit.cvut.cz>"
!
testBoolean6
self assert: (self javaTestClass new getFalseFromBooleanValueOf) = false.
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
"Created: / 25-09-2011 / 19:40:22 / Jan Kurs <kursjan@fit.cvut.cz>"
!
testClass
self assert: ((Java classForName: 'java.lang.Object') isKindOf: JavaClass).
self assert: ((Java classForName: 'java.lang.Object') new isKindOf: JavaObject)
"Created: / 11-04-2011 / 19:22:07 / kursjan <kursjan@fit.cvut.cz>"
!
testDoesNotUnderstand
self
should:[ (Java classForName:'java.lang.Object') new bafickyBaf ]
raise:MessageNotUnderstood.
"Created: / 11-04-2011 / 19:22:07 / kursjan <kursjan@fit.cvut.cz>"
"Created: / 30-08-2011 / 22:06:16 / Jan Kurs <kursjan@fit.cvut.cz>"
!
testInterfaceMethodsWithNarrowerReturnType
"when a class A implements an interface I, and overridden method has narrower
return type (e.g. method in I should return java.lang.Object, but overridden
method in A declares return type of java.lang.String), java compiler generates
synthetic method with the same name and return type declared in I, which just
delegates to overridden method. This situation should not be considered
as error case, instead, one of the methods should be returned."
self assert: (self javaTestClass new getMethodReturningObject) = 'working'.
"Created: / 16-12-2012 / 12:56:01 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!
testMultipleParameters
"test multiple parameters"
self
assert: (self javaTestClass new foo) = 0
"Created: / 11-04-2011 / 19:48:54 / kursjan <kursjan@fit.cvut.cz>"
"Modified: / 05-09-2011 / 20:18:03 / Jan Kurs <kursjan@fit.cvut.cz>"
!
testMultipleParameters1
"test multiple parameters"
self
assert: (self javaTestClass new foo: 1) = 1
"Created: / 11-04-2011 / 19:48:54 / kursjan <kursjan@fit.cvut.cz>"
"Created: / 05-09-2011 / 20:18:14 / Jan Kurs <kursjan@fit.cvut.cz>"
!
testMultipleParameters2
"test multiple parameters"
self
assert: (self javaTestClass new foo: 1 and: 2) = 2
"Created: / 11-04-2011 / 19:48:54 / kursjan <kursjan@fit.cvut.cz>"
"Created: / 05-09-2011 / 20:18:30 / Jan Kurs <kursjan@fit.cvut.cz>"
!
testPassingNilAsParameter
"
Scenario: from smalltalk, pass a nil to an overloaded method with object-type argument.
Question: What to do? Both matches, so Ambibuous message looks good,
but then it behave differently if you do
foo overloadedMethod: 'XXX'
foo overloadedMethod: nil
than if you do
foo overloadedMethod: nil
foo overloadedMethod: 'XXX'.
On the other hand, which method do choose? Random one? Would lead into
hard-to-debug situations.
No good solution so far..."
<skip>
self assert: false message:'Solution wanted'
"/ self
"/ should:[r := self javaTestClass new overloadedMethod: nil]
"/ raise: AmbiguousMessage
"Created: / 16-12-2012 / 11:35:14 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
"Modified: / 16-12-2012 / 17:21:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
testPassingNilAsParameter2
"nil should match any formal argument object type (so should not match primitives)"
self assert: (self javaTestClass new overloadedMethodInt: nil) = 2.
"Created: / 16-12-2012 / 16:21:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
testSayHello
self assert: (self javaTestClass new sayHello = 'hello').
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
"Modified: / 05-09-2011 / 21:05:40 / Jan Kurs <kursjan@fit.cvut.cz>"
!
testSayHelloStatic
self assert: self javaTestClass staticSayHello = 'static hello'.
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
"Created: / 05-09-2011 / 20:26:44 / Jan Kurs <kursjan@fit.cvut.cz>"
!
testTypeOverloading
"test type overloading"
self assert:(self javaTestClass new overloadedMethod: 1) = 4.
self assert:(self javaTestClass new overloadedMethod: 'Hi') = 3.
self assert:(self javaTestClass new overloadedMethod: 'Hi') = 3.
self assert:(self javaTestClass new overloadedMethod: 1) = 4.
"Created: / 11-04-2011 / 20:02:54 / kursjan <kursjan@fit.cvut.cz>"
"Modified: / 05-09-2011 / 21:37:53 / Jan Kurs <kursjan@fit.cvut.cz>"
"Modified (format): / 03-12-2012 / 17:45:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLookupTests methodsFor:'tests - obsolete'!
_testSetManipulator_add
"test interaction of smalltalk Set and java.util.Set"
| aSet anObject |
self breakPoint: #jk info: 'using SetSample, because it contains DNU hook - this is workaround'.
aSet := SetSample new.
anObject := Object new.
self setManipulatorClass new addElement: aSet and: anObject.
self assert: aSet size = 1.
self assert:(self setManipulatorClass new getSize: aSet) = 1.
self assert:(aSet contains: [:e | e = anObject ]).
"Created: / 29-10-2012 / 07:17:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
_testSetManipulator_contains
"test interaction of smalltalk Set and java.util.Set"
| aSet anObject |
self breakPoint: #jk info: 'using SetSample, because it contains DNU hook - this is workaround'.
aSet := SetSample new.
anObject := Object new.
self assert: (self setManipulatorClass new contains: aSet and: anObject) = false.
aSet add: anObject.
self assert: (self setManipulatorClass new contains: aSet and: anObject) = true.
"Created: / 29-10-2012 / 07:18:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
_testSetManipulator_getSize
"test interaction of smalltalk Set and java.util.Set"
| aSet |
self breakPoint: #jk info: 'using SetSample, because it contains DNU hook - this is workaround'.
aSet := SetSample new.
self assert:(self setManipulatorClass new getSize: aSet) = 0.
aSet add: Object new.
self assert:(self setManipulatorClass new getSize: aSet) = 1.
"Created: / 29-10-2012 / 07:17:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
_testSetManipulator_isEmpty
"test interaction of smalltalk Set and java.util.Set"
| aSet |
self breakPoint: #jk info: 'using SetSample, because it contains DNU hook - this is workaround'.
aSet := SetSample new.
self assert: (self setManipulatorClass new isEmpty:aSet).
aSet add: Object new.
self assert: (self setManipulatorClass new isEmpty:aSet) not.
"Created: / 29-10-2012 / 07:17:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
_testSetManipulator_remove
"test interaction of smalltalk Set and java.util.Set"
| aSet anObject |
self breakPoint: #jk info: 'using SetSample, because it contains DNU hook - this is workaround'.
aSet := SetSample new.
anObject := Object new.
aSet add: anObject.
self setManipulatorClass new remove: aSet and: anObject.
self assert: aSet size = 0.
self assert:(self setManipulatorClass new getSize: aSet) = 0.
self assert:(aSet contains: [:e | e = anObject ]) not.
"Created: / 29-10-2012 / 07:17:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLookupTests methodsFor:'tests - smalltalk lookup'!
testPersonManipulator_getAge
"test interaction of Smalltallk objects with Java code"
| person |
person := PersonSample new.
person name: 'Anne'.
person age: 18.
self
assert:(self personManipulatorClass new getPersonAge: person) = 18.
"Created: / 11-04-2011 / 20:02:54 / kursjan <kursjan@fit.cvut.cz>"
"Created: / 25-09-2011 / 17:27:45 / Jan Kurs <kursjan@fit.cvut.cz>"
!
testPersonManipulator_getName
"test interaction of Smalltallk objects with Java code"
| person |
person := PersonSample new.
person name: 'Anne'.
person age: 18.
self
assert:(self personManipulatorClass new getPersonName: person) = 'Anne'.
"Created: / 11-04-2011 / 20:02:54 / kursjan <kursjan@fit.cvut.cz>"
"Created: / 25-09-2011 / 17:27:34 / Jan Kurs <kursjan@fit.cvut.cz>"
! !
!JavaLookupTests class methodsFor:'documentation'!
version_CVS
^ '$Header: /cvs/stx/stx/libjava/JavaLookupTests.st,v 1.1 2013-02-16 18:08:32 vrany Exp $'
!
version_HG
^ '$Changeset: <not expanded> $'
!
version_SVN
^ '§Id§'
! !