More exceptions, other output.
[cacao.git] / tests / extest.java
1 public class extest {
2     public static void main(String[] argv) { 
3         System.out.println("---------- normal exceptions --------------------");
4
5         try {
6             System.out.print("throw Exception:                ");
7             sub();
8             System.out.println("FAILED");
9         } catch (Exception e) {
10             System.out.println("PASSED");
11         }
12
13         try {
14             System.out.print("native NullPointerException:    ");
15             System.arraycopy(null, 1, null, 1, 1);
16             System.out.println("FAILED");
17         } catch (Exception e) {
18             System.out.println("PASSED");
19         }
20
21         try {
22             System.out.print("NullPointerException:           ");
23             int[] ia = null;
24             int i = ia.length;
25             System.out.println("FAILED");
26         } catch (NullPointerException e) {
27             System.out.println("PASSED");
28         }
29
30         try {
31             System.out.print("ArithmeticException:            ");
32             int i = 1, j = 0, k = i / j;
33             System.out.println("FAILED");
34         } catch (ArithmeticException e) {
35             System.out.println("PASSED");
36         }
37
38         System.out.println();
39         System.out.println("---------- test soft inline exceptions ----------");
40
41         try {
42             System.out.print("ArrayIndexOutOfBoundsException: ");
43             int[] ia = new int[1];
44             ia[0xcafebabe] = 1;
45             System.out.println("FAILED");
46         } catch (ArrayIndexOutOfBoundsException e) {
47             String msg = e.getMessage();
48
49             if (msg != null && msg.compareTo("Array index out of range: -889275714") != 0) {
50                 System.out.println("FAILED: wrong index");
51
52             } else {
53                 System.out.println("PASSED");
54             }
55         }
56
57         try {
58             System.out.print("NegativeArraySizeException:     ");
59             int[] ia = new int[-1];
60             System.out.println("FAILED");
61         } catch (NegativeArraySizeException e) {
62             System.out.println("PASSED");
63         }
64         
65         try {
66             System.out.print("ClassCastException:             ");
67             Object o = new Object();
68             Integer i = null;
69             i = (Integer) o;
70             System.out.println("FAILED");
71         } catch (ClassCastException e) {
72             System.out.println("PASSED");
73         }
74
75         try {
76             System.out.print("OutOfMemoryError:               ");
77             /* 100 MB should be enough */
78             byte[] ba = new byte[100 * 1024 * 1024];
79             System.out.println("FAILED");
80         } catch (OutOfMemoryError e) {
81             System.out.println("PASSED");
82         }
83         
84         System.out.println();
85         System.out.println("---------- no passed beyond this point ----------");
86
87         System.out.println("NullPointerException (without catch): ");
88         String s = null;
89         int i = s.length();
90         System.out.println("FAILED");
91     }
92
93     public synchronized static void sub() throws Exception {
94         sub2();
95     }
96
97     public static void sub2() throws Exception {
98         sub3();
99     }
100
101     public synchronized static void sub3() throws Exception {
102         sub4();
103     }
104
105     public static void sub4() throws Exception {
106         throw new Exception();
107     }
108 }