# AmbiguousSignature.test --
#
#       These tests check the correctness of the Java Method Invoker
#       to determine if type correctness is retained when invoking
#       Methods with Java object arguments that are Ambiguous
#
# Copyright (c) 1998 by Mo DeJong.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

# Note: This test file must be sourced from the parent directory
#       or else the defs file may not be properly loaded.

if {[string compare test [info procs test]] == 1} then {source defs}

setupJavaPackage


test AmbiguousSignature-1.1 {} {
    set o [java::new Object]
    list [catch {$o {} [java::null]} err] $err
} {1 {bad signature ""}}


test AmbiguousSignature-1.0 {} {
    set o [java::new Object]
    list [catch {$o {{} java.util.Vector java.util.Hashtable} [java::null] [java::null]} err] $err
} {1 {no such method "{} java.util.Vector java.util.Hashtable" in class java.lang.Object}}


test AmbiguousSignature-1.1 {} {
    set o [java::new Object]
    list [catch {$o {equals Object Object} [java::null]} err] $err
} {1 {no such method "equals Object Object" in class java.lang.Object}}





test AmbiguousSignature-2.1 {overloaded method invocation} {
    set class tests.signature.MethodInvoker1
    set a [java::call $class getA]
    set b [java::call $class getB]

    set result {}
    lappend result [java::call $class call $a $a]
    lappend result [java::call $class call $a $b]
    lappend result [java::call $class call $b $b]
    lappend result [java::call $class call $b $a]
    set result
} {A+A A+B A+B A+A}



test AmbiguousSignature-2.2 {overloaded method invocation} {
    set class tests.signature.MethodInvoker2
    set a [java::call $class getA]
    set b [java::call $class getB]
    set c [java::call $class getC]

    set result {}
    lappend result [java::call $class call $a $a]
    lappend result [java::call $class call $a $c]
    lappend result [java::call $class call $c $a]
    lappend result [java::call $class call $c $c]
    set result
} {A+A A+C A+A B+C}



test AmbiguousSignature-2.3 {overloaded instance method invocation} {
    set class tests.signature.MethodInvoker3
    set m [java::new $class]

    set h  [java::call $class getHashtable]
    set h2 [java::call $class getHashtable2]
    set h2_cast [java::cast java.util.Hashtable $h2]
    set h3 [java::call $class getHashtable3]

    set v  [java::call $class getVector]
    set v2 [java::call $class getVector2]


    set result {}

    lappend result [$m call $h]
    lappend result [$m call $v]
    lappend result [$m call $v $h]
    lappend result [$m call $v $v]
    lappend result [$m call $h2]
    lappend result [$m call $v2]
    lappend result [$m call $h2_cast]
    lappend result [$m call $v $h2]
    lappend result [$m call $v $v2]
    lappend result [$m call $h3]
    lappend result [$m call $v2 $h3]
    set result
} {Hashtable Vector Vector+Hashtable Vector+Vector Hashtable2 Vector2 Hashtable Vector+Hashtable Vector+Vector Hashtable2 Vector+Hashtable}







test AmbiguousSignature-2.4 {overloaded method invocation} {
    set class tests.signature.MethodInvoker4
    set a [java::call $class getA]
    set b [java::call $class getB]
    set i [java::call $class getI]

    set result {}
    lappend result [java::call $class call $a]
    lappend result [java::call $class call $i]
    lappend result [java::call $class call $b]
    set result
} {A I I}




test AmbiguousSignature-2.5 {overloaded method invocation} {
    set class tests.signature.MethodInvoker5
    set i  [java::call $class getI]
    set i2 [java::call $class getI2]
    set i3 [java::call $class getI3]

    set result {}
    lappend result [java::call $class call $i]
    lappend result [java::call $class call $i2]
    lappend result [java::call $class call $i3]
    set result
} {I I2 I2}




test AmbiguousSignature-2.6 {overloaded method rules exception} {
    set class tests.signature.MethodInvoker6
    set o [java::call $class getO]
    set a [java::call $class getA]

    list [java::call $class call $o] [java::call $class call $a]
} {O I}








test AmbiguousSignature-3.1 {ambiguous method failures} {
    set class tests.signature.MethodFailure1
    set a [java::call $class getA]
    set b [java::call $class getB]
    set i [java::call $class getI]

    set result {}
    lappend result [java::call $class call $a]
    lappend result [java::call $class call $i]
    list $result [catch {java::call $class call $b} err] $err
} {{A I} 1 {ambiguous method signature "call"}}




test AmbiguousSignature-3.2 {ambiguous method failures} {
    set class tests.signature.MethodFailure2
    set a [java::call $class getA]
    set b [java::call $class getB]
    set i [java::call $class getI]
    
    set result {}
    lappend result [java::call $class call $a]
    lappend result [java::call $class call $i]
    list $result [catch {java::call $class call $b} err] $err
} {{A I} 1 {ambiguous method signature "call"}}





test AmbiguousSignature-3.3 {ambiguous method failures} {
    set class tests.signature.MethodFailure3
    set a [java::call $class getA]
    set b [java::call $class getB]
    set c [java::call $class getC]
    set i [java::call $class getI]
    
    set result {}
    lappend result [java::call $class call $a]
    lappend result [java::call $class call $b]
    lappend result [java::call $class call $i]
    list $result [catch {java::call $class call $c} err] $err
} {{A A I} 1 {ambiguous method signature "call"}}





test AmbiguousSignature-3.4 {ambiguous method failures} {
    set class tests.signature.MethodFailure4
    set a [java::call $class getA]
    set b [java::call $class getB]
    set c [java::call $class getC]
    set i [java::call $class getI]

    set result {}
    lappend result [java::call $class call $a]
    lappend result [java::call $class call $i]
    list $result [catch {java::call $class call $b} err] $err \
                 [catch {java::call $class call $c} err] $err
} {{A I} 1 {ambiguous method signature "call"} 1 {ambiguous method signature "call"}}



test AmbiguousSignature-3.5 {ambiguous method failures} {
    set class tests.signature.MethodFailure5
    set h [java::call $class getH]
    set d [java::call $class getD]

    set result {}
    lappend result [java::call $class call $h $d]
    lappend result [java::call $class call $d $h]
    list $result [catch {java::call $class call $d $d} err] $err \
	         [catch {java::call $class call $h $h} err] $err
} {{H+D D+H} 1 {ambiguous method signature "call"} 1 {ambiguous method signature "call"}}



