# javaCall.test --
#
#	This file tests the java::call command.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1997 by Sun Microsystems, Inc.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# 2016 - reinserted in JBlend project

package require TTXN
  # package under test is JBlend 2.0
package require JBlend 2.0


Name: javaCall-1.1
Description: {errors}
Test: {
    java::call
}
Expected: error {wrong # args: should be "java::call ?-noconvert? class signature ?arg arg ...?"}

Name: javaCall-1.2
Description: {errors}
Test: {
    java::call foo
}
Expected: error {wrong # args: should be "java::call ?-noconvert? class signature ?arg arg ...?"}

Name: javaCall-1.3
Description: {errors}
Test: {
    java::call -noconvert
}
Expected: error {wrong # args: should be "java::call ?-noconvert? class signature ?arg arg ...?"}

Name: javaCall-1.4
Description: {errors}
Test: {
    java::call -noconvert foo
}
Expected: error {wrong # args: should be "java::call ?-noconvert? class signature ?arg arg ...?"}

Name: javaCall-1.5
Description: {errors}
Test: {
    java::call -n foo
}
Expected: error {wrong # args: should be "java::call ?-noconvert? class signature ?arg arg ...?"}

Name: javaCall-1.6
Description: {errors}
Test: {
    java::call - foo
}
Expected: error {unknown class "-"}

Name: javaCall-1.7
Description: {errors}
Test: {
    java::call foo bar
}
Expected: error {unknown class "foo"}

Name: javaCall-1.8
Description: {errors}
Only: SpecialTestClasses
Test: {
    list [catch {java::call tests.JavaTest \{} msg] $msg
}
Expected: {1 {unmatched open brace in list}}

Name: javaCall-1.9
Description: {errors}
Only: SpecialTestClasses
Test: {
    list [catch {java::call tests.JavaTest {}} msg] $msg
}
Expected: {1 {bad signature ""}}

Name: javaCall-2.1
Description: {static methods}
Only: SpecialTestClasses
Test: {
    java::call tests.JavaTest smethod
}
Expected: static

Name: javaCall-2.2
Description: {static methods}
Only: SpecialTestClasses
Test: {
    [java::call -noconvert tests.JavaTest smethod] toString
}
Expected: static

Name: javaCall-2.3
Description: {static methods}
Only: SpecialTestClasses
Test: {
    [java::call -n tests.JavaTest smethod] toString
}
Expected: static

Name: javaCall-3.1
Description: {instance methods}
Only: SpecialTestClasses
Test: {
    list [catch {java::call tests.JavaTest imethod} msg] $msg
}
Expected: {1 {no accessible static method "imethod" in class tests.JavaTest}}

Name: javaCall-4.1
Description: {arrays}
Only: SpecialTestClasses
Test: {
    list [catch {
	set x [java::call tests.invoke.ArrayTestClass blue 5]
	set y [java::call tests.invoke.ArrayTestClass blue $x 6]
   } msg] $msg
}
Expected: {0 {blue diamonds, String[][]}}

Name: javaCall-4.2
Description: {arrays}
Only: SpecialTestClasses
Test: {
    list [catch {
	set x [java::call tests.invoke.ArrayTestClass pink 5]
	set y [java::call tests.invoke.ArrayTestClass pink $x 6]
   } msg] $msg
}
Expected: {0 {pink hearts, int[][]}}

Name: javaCall-4.3
Description: {arrays}
Only: SpecialTestClasses
Test: {
    list [catch {
	set x [java::call tests.invoke.ArrayTestClass green 5]
	set y [java::call tests.invoke.ArrayTestClass green $x 6]
   } msg] $msg
}
Expected: {0 {green clovers, java.lang.Integer[][]}}

Name: javaCall-5.1
Description: {void return}
Only: SpecialTestClasses
Test: {
    java::call tests.JavaTest voidsmethod
}
Expected: ""

Name: javaCall-6.1
Description: {null return}
Only: SpecialTestClasses
Test: {
    java::call -noconvert tests.JavaTest nullsmethod
}
Expected: [java::null]

Name: javaCall-6.2
Description: {null return}
Only: SpecialTestClasses
Test: {
    java::call tests.JavaTest nullsmethod
}
Expected: ""

Name: javaCall-7.1
Description: {throw TclException in a Java method}
Only: SpecialTestClasses
Test: {
    # Should not wrap a TclException in a ReflectException!
    set errorCode NONE
    list [catch {java::call tests.JavaTest \
        throwTclException [java::getinterp]} err] $err $errorCode
}
Expected: {1 {no nuts in my fudge please!} NONE}

Name: javaCall-7.2
Description: {Interp.setResult(null)}
Only: SpecialTestClasses
Test: {
    java::call tests.JavaTest testSetResultNPE [java::getinterp]
}
Expected: {OK}

Name: javaCall-7.3
Description: {Interp.setResult(null)}
Only: SpecialTestClasses
Test: {
    java::call tests.JavaTest testResetResultNPE [java::getinterp]
}
Expected: {OK}


Name: javaCall-8.0
Description: {load class from a jar on the TCL_CLASSPATH}
Only: SpecialTestClasses
Test: {
    set env(TCL_CLASSPATH) [file join $env(BUILD_DIR) btests hello hello.jar]
    set result [java::call hello.SayHello hello]
    unset env(TCL_CLASSPATH)
    set result
}
Expected: {hello}


# === cleanup ========================================

::tcltest::cleanupTests
return
