* tests/codepatching: Moved to tests/regression/codepatching.
[cacao.git] / tests / regression / codepatching / test.java
1 public class test extends Thread {
2     static boolean doit = true;
3
4     public static void main(String[] argv) {
5         int threadcount = 1;
6
7         if (argv.length > 0) {
8             for (int i = 0; i < argv.length; i++) {
9                 if (argv[i].equals("--help")) {
10                     usage();
11
12                 } else if (argv[i].equals("skip")) {
13                     doit = false;
14
15                 } else {
16                     threadcount = Integer.valueOf(argv[i]).intValue();
17                 }
18             }
19         }
20
21         System.out.println("Running with " + threadcount + " threads.");
22
23         for (int i = 0; i < threadcount; i++) {
24             new test().start();
25         }
26     }
27
28     static void usage() {
29         System.out.println("test [number of threads] [skip]");
30         System.exit(1);
31     }
32
33     public test() {
34     }
35
36     public void start() {
37         run();
38     }
39
40     public void run() {
41         invokestatic();
42
43         getstatic();
44         putstatic();
45
46         getfield();
47         putfield();
48         putfieldconst();
49
50         newarray();
51         multianewarray();
52
53         invokespecial();
54
55         checkcast();
56         _instanceof();
57     }
58
59
60     final private static void invokestatic() {
61         System.out.print("invokestatic: ");
62         try {
63             if (doit)
64                 invokestatic.sub();
65             else
66                 System.out.println("OK");
67         } catch (Throwable t) {
68             System.out.println("FAILED: " + t);
69         }
70     }
71
72
73     private void getstatic() {
74         try {
75             p("getstatic (I): ");
76             if (doit)
77                 check(getstaticI.i, 123);
78             else
79                 ok();
80         } catch (Throwable t) {
81             failed(t);
82         }
83
84         try {
85             p("getstatic (J): ");
86             if (doit)
87                 check(getstaticJ.l, 1234567890123L);
88             else
89                 ok();
90         } catch (Throwable t) {
91             failed(t);
92         }
93
94         try {
95             p("getstatic (F): ");
96             if (doit)
97                 check(getstaticF.f, 123.456F);
98             else
99                 ok();
100         } catch (Throwable t) {
101             failed(t);
102         }
103
104         try {
105             p("getstatic (D): ");
106             if (doit)
107                 check(getstaticD.d, 789.012);
108             else
109                 ok();
110         } catch (Throwable t) {
111             failed(t);
112         }
113
114         try {
115             p("getstatic (L): ");
116             if (doit)
117                 check(getstaticL.o, null);
118             else
119                 ok();
120         } catch (Throwable t) {
121             failed(t);
122         }
123     }
124
125     private void putstatic() {
126         try {
127             p("putstatic (I): ");
128             if (doit) {
129                 int i = 123;
130                 putstaticI.i = i;
131                 check(putstaticI.i, i);
132             } else
133                 ok();
134         } catch (Throwable t) {
135             failed(t);
136         }
137
138         try {
139             p("putstatic (J): ");
140             if (doit) {
141                 long l = 1234567890123L;
142                 putstaticJ.l = l;
143                 check(putstaticJ.l, l);
144             } else
145                 ok();
146         } catch (Throwable t) {
147             failed(t);
148         }
149
150         try {
151             p("putstatic (F): ");
152             if (doit) {
153                 float f = 123.456F;
154                 putstaticF.f = f;
155                 check(putstaticF.f, f);
156             } else
157                 ok();
158         } catch (Throwable t) {
159             failed(t);
160         }
161
162         try {
163             p("putstatic (D): ");
164             if (doit) {
165                 double d = 789.012;
166                 putstaticD.d = d;
167                 check(putstaticD.d, d);
168             } else
169                 ok();
170         } catch (Throwable t) {
171             failed(t);
172         }
173
174
175         try {
176             p("putstatic (L): ");
177             if (doit) {
178                 Object o = null;
179                 putstaticL.o = o;
180                 check(putstaticL.o, o);
181             } else
182                 ok();
183         } catch (Throwable t) {
184             failed(t);
185         }
186     }
187
188     private void getfield() {
189         try {
190             p("getfield (I): ");
191             if (doit)
192                 check(new getfieldI().i, 123);
193             else
194                 ok();
195         } catch (Throwable t) {
196             failed(t);
197         }
198
199         try {
200             p("getfield (J): ");
201             if (doit)
202                 check(new getfieldJ().l, 1234567890123L);
203             else
204                 ok();
205         } catch (Throwable t) {
206             failed(t);
207         }
208
209         try {
210             p("getfield (F): ");
211             if (doit)
212                 check(new getfieldF().f, 123.456F);
213             else
214                 ok();
215         } catch (Throwable t) {
216             failed(t);
217         }
218
219         try {
220             p("getfield (D): ");
221             if (doit)
222                 check(new getfieldD().d, 789.012);
223             else
224                 ok();
225         } catch (Throwable t) {
226             failed(t);
227         }
228
229         try {
230             p("getfield (L): ");
231             if (doit)
232                 check(new getfieldL().o, null);
233             else
234                 ok();
235         } catch (Throwable t) {
236             failed(t);
237         }
238     }
239
240     private void putfield() {
241         try {
242             p("putfield (I): ");
243             if (doit) {
244                 putfieldI pfi = new putfieldI();
245                 int i = 123;
246                 pfi.i = i;
247                 check(pfi.i, i);
248             } else
249                 ok();
250         } catch (Throwable t) {
251             failed(t);
252         }
253
254         try {
255             p("putfield (J): ");
256             if (doit) {
257                 putfieldJ pfj = new putfieldJ();
258                 long l = 1234567890123L;
259                 pfj.l = l;
260                 check(pfj.l, l);
261             } else
262                 ok();
263         } catch (Throwable t) {
264             failed(t);
265         }
266
267         try {
268             p("putfield (F): ");
269             if (doit) {
270                 putfieldF pff = new putfieldF();
271                 float f = 123.456F;
272                 pff.f = f;
273                 check(pff.f, f);
274             } else
275                 ok();
276         } catch (Throwable t) {
277             failed(t);
278         }
279
280         try {
281             p("putfield (D): ");
282             if (doit) {
283                 putfieldD pfd = new putfieldD();
284                 double d = 789.012;
285                 pfd.d = d;
286                 check(pfd.d, d);
287             } else
288                 ok();
289         } catch (Throwable t) {
290             failed(t);
291         }
292
293         try {
294             p("putfield (L): ");
295             if (doit) {
296                 putfieldL pfl = new putfieldL();
297                 Object o = null;
298                 pfl.o = o;
299                 check(pfl.o, o);
300             } else
301                 ok();
302         } catch (Throwable t) {
303             failed(t);
304         }
305     }
306
307     private void putfieldconst() {
308         try {
309             p("putfieldconst (I,F): ");
310             if (doit) {
311                 putfieldconstIF pfcif = new putfieldconstIF();
312                 pfcif.i = 123;
313                 check(pfcif.i, 123);
314             } else
315                 ok();
316         } catch (Throwable t) {
317             failed(t);
318         }
319  
320         try {
321             p("putfieldconst zero (I,F): ");
322             if (doit) {
323                 putfieldconstIF pfcif = new putfieldconstIF();
324                 pfcif.i = 0;
325                 check(pfcif.i, 0);
326             } else
327                 ok();
328         } catch (Throwable t) {
329             failed(t);
330         }
331  
332         try {
333             p("putfieldconst (J,D,L): ");
334             if (doit) {
335                 putfieldconstJDL pfcjdl = new putfieldconstJDL();
336                 pfcjdl.l = 1234567890123L;
337                 check(pfcjdl.l, 1234567890123L);
338             } else
339                 ok();
340         } catch (Throwable t) {
341             failed(t);
342         }
343
344         try {
345             p("putfieldconst zero (J,D,L): ");
346             if (doit) {
347                 putfieldconstJDL pfcjdl = new putfieldconstJDL();
348                 pfcjdl.l = 0L;
349                 check(pfcjdl.l, 0L);
350             } else
351                 ok();
352         } catch (Throwable t) {
353             failed(t);
354         }
355     }
356
357     private void newarray() {
358         try {
359             p("newarray: ");
360             if (doit) {
361                 newarray[] na = new newarray[1];
362             }
363             ok();
364         } catch (Throwable t) {
365             failed(t);
366         }
367     }
368
369     private void multianewarray() {
370         try {
371             p("multianewarray: ");
372             if (doit) {
373                 multianewarray[][] ma = new multianewarray[1][1];
374             }
375             ok();
376         } catch (Throwable t) {
377             failed(t);
378         }
379     }
380
381     private void invokespecial() {
382         try {
383             p("invokespecial: ");
384             if (doit)
385                 new invokespecial();
386             else
387                 ok();
388         } catch (Throwable t) {
389             failed(t);
390         }
391     }
392
393     private void checkcast() {
394         Object o = new Object();
395
396         // class
397         try {
398             p("checkcast class: ");
399             if (doit) {
400                 checkcastC cc = (checkcastC) o;
401                 failed();
402             } else
403                 ok();
404         } catch (ClassCastException e) {
405             ok();
406         } catch (Throwable t) {
407             failed(t);
408         }
409
410         // interface
411         try {
412             p("checkcast interface: ");
413             if (doit) {
414                 checkcastI ci = (checkcastI) o;
415                 failed();
416             } else
417                 ok();
418         } catch (ClassCastException e) {
419             ok();
420         } catch (Throwable t) {
421             failed(t);
422         }
423
424
425         // array
426
427         Object[] oa = new Object[1];
428
429         try {
430             p("checkcast class array: ");
431             if (doit) {
432                 checkcastC[] cca = (checkcastC[]) oa;
433                 failed();
434             } else
435                 ok();
436         } catch (ClassCastException e) {
437             ok();
438         } catch (Throwable t) {
439             failed(t);
440         }
441     }
442
443     private void _instanceof() {
444         Object o = new Object();
445
446         try {
447             p("instanceof class: ");
448             if (doit)
449                 if (o instanceof instanceofC)
450                     failed();
451                 else
452                     ok();
453             else
454                 ok();
455         } catch (Throwable t) {
456             failed(t);
457         }
458
459         try {
460             p("instanceof interface: ");
461             if (doit)
462                 if (o instanceof instanceofI)
463                     failed();
464                 else
465                     ok();
466             else
467                 ok();
468         } catch (Throwable t) {
469             failed(t);
470         }
471
472
473         // array
474
475         Object[] oa = new Object[1];
476
477         try {
478             p("instanceof class array: ");
479             if (doit)
480                 if (oa instanceof instanceofC[])
481                     failed();
482                 else
483                     ok();
484             else
485                 ok();
486         } catch (Throwable t) {
487             failed(t);
488         }
489     }
490
491     private void ok() {
492         pln("OK");
493     }
494
495     private void failed() {
496         pln("FAILED");
497     }
498
499     private void failed(Throwable t) {
500         pln("FAILED: " + t);
501     }
502
503     private void check(int a, int b) {
504         if (a == b)
505             ok();
506         else
507             pln("FAILED: " + a + " != " + b);
508     }
509
510     private void check(long a, long b) {
511         if (a == b)
512             ok();
513         else
514             pln("FAILED: " + a + " != " + b);
515     }
516
517     private void check(float a, float b) {
518         if (a == b)
519             ok();
520         else
521             pln("FAILED: " + a + " != " + b);
522     }
523
524     private void check(double a, double b) {
525         if (a == b)
526             ok();
527         else
528             pln("FAILED: " + a + " != " + b);
529     }
530
531     private void check(Object a, Object b) {
532         if (a == b)
533             ok();
534         else
535             pln("FAILED: " + a + " != " + b);
536     }
537
538     private final void p(String s) {
539         System.out.print(s);
540     }
541
542     private final void pln(String s) {
543         System.out.println(s);
544     }
545 }