From 350c360fa96e994045fb4405ad5f5475c4fcc64b Mon Sep 17 00:00:00 2001 From: Kathy Gray Date: Sun, 11 Dec 2005 23:57:33 +0000 Subject: [PATCH] svn: r1586 --- collects/tests/profj/full-tests.ss | 70 +++++++++++++++++++++ collects/tests/profj/intermediate-tests.ss | 73 ++++++++++++++++++++++ 2 files changed, 143 insertions(+) diff --git a/collects/tests/profj/full-tests.ss b/collects/tests/profj/full-tests.ss index 369db265de..68925911c9 100644 --- a/collects/tests/profj/full-tests.ss +++ b/collects/tests/profj/full-tests.ss @@ -4,6 +4,76 @@ (prepare-for-tests "Full") + (parameterize ((dynamic? #t)) + (interact-test + "class X{ int x( int i) { return i; }}" + 'full + '("((dynamic) new X()).x(1)" "((dynamic) new X()).x()") + '(1 error) + "Test of casting known values to dynamic")) + + (execute-test + "interface A {} + interface B {} + class C implements A, B { + static void go() { + C c = new C(); + A a = c; + B b = c; + + if (a == b) { + b=b; + } + if (a == c) { + a=a; + } + if (c == b) { + b=b; + } + } + }" 'full #f "test of ==, using castable") + + (execute-test + "class A { } + class B extends A { } + class C extends A { } + class X { + A a = new B(); + C b = new C(); + boolean e() { + return a == b; + } + }" 'full #f "Test of ==") + + (execute-test + "class A { } + class B extends A { } + class C extends A { } + class X { + B a = new B(); + C b = new C(); + boolean e() { + return a == b; + } + }" 'full #t "Incompatible type test ==") + + (execute-test + "class A { + boolean b() { + return \"hi\" == new Object(); + } + }" 'full #f "Comparing String and Object") + + (execute-test + "final class A { + } + interface B { } + class X { + Object o( A a ) { + return (B) a; + } + }" 'full #t "Cast from final class to unimpl interface") + (interact-test 'full (list "float x = 3/2;" "x" "double y = 3.2/2;" "y") diff --git a/collects/tests/profj/intermediate-tests.ss b/collects/tests/profj/intermediate-tests.ss index 92f57f3e6d..aa779212d2 100644 --- a/collects/tests/profj/intermediate-tests.ss +++ b/collects/tests/profj/intermediate-tests.ss @@ -250,6 +250,56 @@ }" 'intermediate #f "Correct instanceof usage") + (execute-test + "class A { } + class B extends A { } + class C { + A a = new B(); + Object o () { + return ((B) a); + } + Object ob( B b) { + return ((A) b); + } + }" 'intermediate #f "Simple correct casting") + + (execute-test + "interface A { } + class C { + Object e( C c ) { + return (A) c; + } + }" 'intermediate #f "Cast of non-final class to empty interface") + + (execute-test + "interface A { } + interface B { int foo(); } + class C { + Object e( A a ) { + return (B) a; + } + }" 'intermediate #f "Cast of empty interface to non-empty interface") + + (execute-test + "interface A { int foo(); } + interface B { boolean foo(int i); } + class C { + Object e( A a) { + return (B) a; + } + }" 'intermediate #f "Cast of two non-same non-conflicting interfaces") + + (execute-test + "interface A { } + class C implements A { + Object e ( C c) { + return ((A) c); + } + Object e2( A a) { + return ((C) a); + } + }" 'intermediate #f "Casts of class to implementing iface, and reverse") + ;;Execute tests with errors (execute-test @@ -330,6 +380,29 @@ } }" 'intermediate #t "Incompatible return type from inherited interface") + (execute-test + "class X { + int c (Object o) { + return (int) o; + } + }" 'intermediate #t "Cast of object to primitive") + + (execute-test + "class X { + int c () { + return (int) false; + } + }" 'intermediate #t "cast of boolean to integer") + + (execute-test + "interface A { int x();} + interface B { boolean x(); } + class X { + Object o(A a) { + return (B) a; + } + }" 'intermediate #t "cast of incompatible interfaces") + ;;Interact tests