JavaLookupResolutionAlgorithmTests.st
branchdirectory_structure_refactoring
changeset 1818 2e5ed72e7dfd
parent 1755 dac7ae2c49a6
child 1893 167f2898b9ad
equal deleted inserted replaced
1817:b86c40afbf1f 1818:2e5ed72e7dfd
       
     1 "
       
     2  Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
       
     3                          SWING Research Group, Czech Technical University 
       
     4                          in Prague
       
     5 
       
     6  Permission is hereby granted, free of charge, to any person
       
     7  obtaining a copy of this software and associated documentation
       
     8  files (the 'Software'), to deal in the Software without
       
     9  restriction, including without limitation the rights to use,
       
    10  copy, modify, merge, publish, distribute, sublicense, and/or sell
       
    11  copies of the Software, and to permit persons to whom the
       
    12  Software is furnished to do so, subject to the following
       
    13  conditions:
       
    14 
       
    15  The above copyright notice and this permission notice shall be
       
    16  included in all copies or substantial portions of the Software.
       
    17 
       
    18  THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
       
    19  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
       
    20  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
       
    21  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
       
    22  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
       
    23  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
       
    24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
       
    25  OTHER DEALINGS IN THE SOFTWARE.
       
    26 "
       
    27 "{ Package: 'stx:libjava' }"
       
    28 
       
    29 TestCase subclass:#JavaLookupResolutionAlgorithmTests
       
    30 	instanceVariableNames:''
       
    31 	classVariableNames:''
       
    32 	poolDictionaries:''
       
    33 	category:'Languages-Java-Tests-Interop'
       
    34 !
       
    35 
       
    36 !JavaLookupResolutionAlgorithmTests class methodsFor:'documentation'!
       
    37 
       
    38 copyright
       
    39 "
       
    40  Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
       
    41                          SWING Research Group, Czech Technical University 
       
    42                          in Prague
       
    43 
       
    44  Permission is hereby granted, free of charge, to any person
       
    45  obtaining a copy of this software and associated documentation
       
    46  files (the 'Software'), to deal in the Software without
       
    47  restriction, including without limitation the rights to use,
       
    48  copy, modify, merge, publish, distribute, sublicense, and/or sell
       
    49  copies of the Software, and to permit persons to whom the
       
    50  Software is furnished to do so, subject to the following
       
    51  conditions:
       
    52 
       
    53  The above copyright notice and this permission notice shall be
       
    54  included in all copies or substantial portions of the Software.
       
    55 
       
    56  THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
       
    57  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
       
    58  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
       
    59  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
       
    60  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
       
    61  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
       
    62  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
       
    63  OTHER DEALINGS IN THE SOFTWARE.
       
    64 
       
    65 "
       
    66 !
       
    67 
       
    68 documentation
       
    69 "
       
    70     This testcase tests the method lookup algorithm used to lookup
       
    71     Java methods when calling Java from Smalltalk or vice versa.
       
    72 
       
    73     Does not test proxy generation.
       
    74 
       
    75     [author:]
       
    76         Jan Vrany <jan.vrany@fit.cvut.cz>
       
    77 
       
    78     [instance variables:]
       
    79 
       
    80     [class variables:]
       
    81 
       
    82     [see also:]
       
    83 
       
    84 "
       
    85 ! !
       
    86 
       
    87 !JavaLookupResolutionAlgorithmTests methodsFor:'running'!
       
    88 
       
    89 testLookup
       
    90     |lo o match ilc|
       
    91 
       
    92     lo := JavaLookup instance.
       
    93     o := (Java classForName:('java.lang.Object')) new.
       
    94     ilc := nil.
       
    95     match := lo 
       
    96                 lookupMethodForSelector:#toString
       
    97                 directedTo:o class
       
    98                 for:o
       
    99                 withArguments:nil
       
   100                 from:thisContext
       
   101                 ilc: ilc.
       
   102     self assert: match body class = ProxyMethodJavaMethodInvocationNode.
       
   103     self assert: match body method descriptor name = #toString.
       
   104     self assert: match body method descriptor parameters isEmpty.
       
   105     self assert: match body method descriptor return javaClassName =  #'java/lang/String'.
       
   106 
       
   107     "Created: / 30-08-2011 / 21:23:56 / Jan Kurs <kursjan@fit.cvut.cz>"
       
   108     "Modified: / 30-12-2011 / 10:44:48 / kursjan <kursjan@fit.cvut.cz>"
       
   109 !
       
   110 
       
   111 testLookup2
       
   112     |lo o match|
       
   113 
       
   114     lo := JavaLookup instance.
       
   115     o := (Java classForName:('java.lang.Object')) new.
       
   116     match := lo 
       
   117                 lookupMethodForSelector:#hashCode
       
   118                 directedTo:o class
       
   119                 for:o
       
   120                 withArguments:nil
       
   121                 from:thisContext
       
   122                 ilc: nil.
       
   123     self assert: match body class = ProxyMethodJavaMethodInvocationNode.
       
   124     self assert: match body method descriptor name = #hashCode.
       
   125     self assert: match body method descriptor parameters isEmpty.
       
   126     self assert: match body method descriptor return javaClassName =  #int.
       
   127 
       
   128     "Created: / 30-08-2011 / 21:54:53 / Jan Kurs <kursjan@fit.cvut.cz>"
       
   129     "Modified: / 30-12-2011 / 10:46:34 / kursjan <kursjan@fit.cvut.cz>"
       
   130 !
       
   131 
       
   132 testLookup3
       
   133     |lo o match |
       
   134 
       
   135     lo := JavaLookup instance.
       
   136     o := (Java classForName:('java.lang.Object')) new.
       
   137     match := lo 
       
   138                 lookupMethodForSelector:#wait
       
   139                 directedTo:o class
       
   140                 for:o
       
   141                 withArguments:nil
       
   142                 from:thisContext
       
   143                 ilc: nil.
       
   144 
       
   145     self assert: match body class = ProxyMethodJavaMethodInvocationNode.
       
   146     self assert: match body method descriptor name = #wait.
       
   147     self assert: match body method descriptor parameters isEmpty.
       
   148     self assert: match body method descriptor return javaClassName =  #void.
       
   149 
       
   150     "Created: / 30-08-2011 / 21:55:36 / Jan Kurs <kursjan@fit.cvut.cz>"
       
   151     "Modified: / 30-12-2011 / 10:47:49 / kursjan <kursjan@fit.cvut.cz>"
       
   152 !
       
   153 
       
   154 testLookup4
       
   155     |lo o match|
       
   156 
       
   157     lo := JavaLookup instance.
       
   158     o := (Java classForName:('java.lang.Object')) new.
       
   159     match := lo 
       
   160                 lookupMethodForSelector:#wait:
       
   161                 directedTo:o class
       
   162                 for:o
       
   163                 withArguments: (Array with: 1)
       
   164                 from:thisContext
       
   165                 ilc: nil.
       
   166 
       
   167     self assert: match body class = ProxyMethodJavaMethodInvocationNode.
       
   168     self assert: match body method descriptor name = #wait.
       
   169     self assert: match body method descriptor parameters size = 1.
       
   170     self assert: match body method descriptor return javaClassName =  #void.
       
   171 
       
   172     "Created: / 30-08-2011 / 21:57:59 / Jan Kurs <kursjan@fit.cvut.cz>"
       
   173     "Modified: / 30-12-2011 / 10:49:09 / kursjan <kursjan@fit.cvut.cz>"
       
   174     "Modified: / 12-05-2012 / 21:34:05 / Jan Kurs (kursjan@fit.cvut.cz)"
       
   175 !
       
   176 
       
   177 testLookupException
       
   178     |lo o match|
       
   179 
       
   180     lo := JavaLookup instance.
       
   181     o := (Java classForName:('java.lang.Object')) new.
       
   182     match := lo 
       
   183                 lookupMethodForSelector:#foo:
       
   184                 directedTo:o class
       
   185                 for:o
       
   186                 withArguments:nil
       
   187                 from:thisContext
       
   188                 ilc: nil.
       
   189     self assert:match isNil.
       
   190 
       
   191     "Created: / 30-08-2011 / 22:10:50 / Jan Kurs <kursjan@fit.cvut.cz>"
       
   192     "Modified: / 30-12-2011 / 10:50:03 / kursjan <kursjan@fit.cvut.cz>"
       
   193 ! !
       
   194 
       
   195 !JavaLookupResolutionAlgorithmTests class methodsFor:'documentation'!
       
   196 
       
   197 version_SVN
       
   198     ^ '$Id$'
       
   199 ! !