svn: r1586

This commit is contained in:
Kathy Gray 2005-12-11 23:57:33 +00:00
parent 40990e30e3
commit 350c360fa9
2 changed files with 143 additions and 0 deletions

View File

@ -4,6 +4,76 @@
(prepare-for-tests "Full") (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 (interact-test
'full 'full
(list "float x = 3/2;" "x" "double y = 3.2/2;" "y") (list "float x = 3/2;" "x" "double y = 3.2/2;" "y")

View File

@ -250,6 +250,56 @@
}" }"
'intermediate #f "Correct instanceof usage") '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 tests with errors
(execute-test (execute-test
@ -330,6 +380,29 @@
} }
}" 'intermediate #t "Incompatible return type from inherited interface") }" '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 ;;Interact tests