* tests/Makefile.am (EXTRA_DIST): Added $(srcdir) to actually find the
[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         putstaticconst();
46
47         getfield();
48         putfield();
49         putfieldconst();
50
51         newarray();
52         multianewarray();
53
54         invokespecial();
55
56         checkcast();
57         _instanceof();
58
59         aastoreconst();
60     }
61
62
63     final private static void invokestatic() {
64         try {
65             p("invokestatic: ");
66             if (doit)
67                 invokestatic.sub();
68             else
69                 ok();
70         } catch (NoClassDefFoundError t) {
71             failed(t);
72         }
73     }
74
75
76     private void getstatic() {
77         try {
78             p("getstatic (I): ");
79             if (doit)
80                 check(getstaticI.i, 123);
81             else
82                 ok();
83         } catch (NoClassDefFoundError t) {
84             failed(t);
85         }
86
87         try {
88             p("getstatic (J): ");
89             if (doit)
90                 check(getstaticJ.l, 1234567890123L);
91             else
92                 ok();
93         } catch (NoClassDefFoundError t) {
94             failed(t);
95         }
96
97         try {
98             p("getstatic (F): ");
99             if (doit)
100                 check(getstaticF.f, 123.456F);
101             else
102                 ok();
103         } catch (NoClassDefFoundError t) {
104             failed(t);
105         }
106
107         try {
108             p("getstatic (D): ");
109             if (doit)
110                 check(getstaticD.d, 789.012);
111             else
112                 ok();
113         } catch (NoClassDefFoundError t) {
114             failed(t);
115         }
116
117         try {
118             p("getstatic (L): ");
119             if (doit)
120                 check(getstaticL.o, null);
121             else
122                 ok();
123         } catch (NoClassDefFoundError t) {
124             failed(t);
125         }
126     }
127
128     private void putstatic() {
129         try {
130             p("putstatic (I): ");
131             if (doit) {
132                 int i = 123;
133                 putstaticI.i = i;
134                 check(putstaticI.i, i);
135             } else
136                 ok();
137         } catch (NoClassDefFoundError t) {
138             failed(t);
139         }
140
141         try {
142             p("putstatic (J): ");
143             if (doit) {
144                 long l = 1234567890123L;
145                 putstaticJ.l = l;
146                 check(putstaticJ.l, l);
147             } else
148                 ok();
149         } catch (NoClassDefFoundError t) {
150             failed(t);
151         }
152
153         try {
154             p("putstatic (F): ");
155             if (doit) {
156                 float f = 123.456F;
157                 putstaticF.f = f;
158                 check(putstaticF.f, f);
159             } else
160                 ok();
161         } catch (NoClassDefFoundError t) {
162             failed(t);
163         }
164
165         try {
166             p("putstatic (D): ");
167             if (doit) {
168                 double d = 789.012;
169                 putstaticD.d = d;
170                 check(putstaticD.d, d);
171             } else
172                 ok();
173         } catch (NoClassDefFoundError t) {
174             failed(t);
175         }
176
177
178         try {
179             p("putstatic (L): ");
180             if (doit) {
181                 Object o = null;
182                 putstaticL.o = o;
183                 check(putstaticL.o, o);
184             } else
185                 ok();
186         } catch (NoClassDefFoundError t) {
187             failed(t);
188         }
189     }
190
191     private void putstaticconst() {
192         try {
193             p("putstaticconst (I): ");
194             if (doit) {
195                 putstaticconstI.i = 123;
196                 check(putstaticconstI.i, 123);
197             } else
198                 ok();
199         } catch (NoClassDefFoundError t) {
200             failed(t);
201         }
202
203         try {
204             p("putstaticconst (J): ");
205             if (doit) {
206                 putstaticconstJ.l = 1234567890123L;
207                 check(putstaticconstJ.l, 1234567890123L);
208             } else
209                 ok();
210         } catch (NoClassDefFoundError t) {
211             failed(t);
212         }
213
214         try {
215             p("putstaticconst (F): ");
216             if (doit) {
217                 putstaticconstF.f = 123.456F;
218                 check(putstaticconstF.f, 123.456F);
219             } else
220                 ok();
221         } catch (NoClassDefFoundError t) {
222             failed(t);
223         }
224
225         try {
226             p("putstaticconst (D): ");
227             if (doit) {
228                 putstaticconstD.d = 789.012;
229                 check(putstaticconstD.d, 789.012);
230             } else
231                 ok();
232         } catch (NoClassDefFoundError t) {
233             failed(t);
234         }
235
236         try {
237             p("putstaticconst zero (I): ");
238             if (doit) {
239                 putstaticconstI.i = 0;
240                 check(putstaticconstI.i, 0);
241             } else
242                 ok();
243         } catch (NoClassDefFoundError t) {
244             failed(t);
245         }
246
247         try {
248             p("putstaticconst zero (J): ");
249             if (doit) {
250                 putstaticconstJ.l = 0L;
251                 check(putstaticconstJ.l, 0L);
252             } else
253                 ok();
254         } catch (NoClassDefFoundError t) {
255             failed(t);
256         }
257
258         try {
259             p("putstaticconst zero (F): ");
260             if (doit) {
261                 putstaticconstF.f = 0.0F;
262                 check(putstaticconstF.f, 0.0F);
263             } else
264                 ok();
265         } catch (NoClassDefFoundError t) {
266             failed(t);
267         }
268
269         try {
270             p("putstaticconst zero (D): ");
271             if (doit) {
272                 putstaticconstD.d = 0.0;
273                 check(putstaticconstD.d, 0.0);
274             } else
275                 ok();
276         } catch (NoClassDefFoundError t) {
277             failed(t);
278         }
279
280         try {
281             p("putstaticconst zero (L): ");
282             if (doit) {
283                 putstaticconstL.o = null;
284                 check(putstaticconstL.o, null);
285             } else
286                 ok();
287         } catch (NoClassDefFoundError t) {
288             failed(t);
289         }
290
291         try {
292             p("putstaticconst unresolved class: ");
293             if (doit) {
294                 putstaticconstC.c = putstaticconstC.class;
295                 check(putstaticconstC.c, Class.forName("putstaticconstC"));
296             } else
297                 ok();
298         } catch (NoClassDefFoundError t) {
299             failed(t);
300         } catch (ClassNotFoundException t) {
301             failed(t);
302         }
303     }
304
305     private void getfield() {
306         try {
307             p("getfield (I): ");
308             if (doit)
309                 check(new getfieldI().i, 123);
310             else
311                 ok();
312         } catch (NoClassDefFoundError t) {
313             failed(t);
314         }
315
316         try {
317             p("getfield (J): ");
318             if (doit)
319                 check(new getfieldJ().l, 1234567890123L);
320             else
321                 ok();
322         } catch (NoClassDefFoundError t) {
323             failed(t);
324         }
325
326         try {
327             p("getfield (F): ");
328             if (doit)
329                 check(new getfieldF().f, 123.456F);
330             else
331                 ok();
332         } catch (NoClassDefFoundError t) {
333             failed(t);
334         }
335
336         try {
337             p("getfield (D): ");
338             if (doit)
339                 check(new getfieldD().d, 789.012);
340             else
341                 ok();
342         } catch (NoClassDefFoundError t) {
343             failed(t);
344         }
345
346         try {
347             p("getfield (L): ");
348             if (doit)
349                 check(new getfieldL().o, null);
350             else
351                 ok();
352         } catch (NoClassDefFoundError t) {
353             failed(t);
354         }
355     }
356
357     private void putfield() {
358         try {
359             p("putfield (I): ");
360             if (doit) {
361                 putfieldI pfi = new putfieldI();
362                 int i = 123;
363                 pfi.i = i;
364                 check(pfi.i, i);
365             } else
366                 ok();
367         } catch (NoClassDefFoundError t) {
368             failed(t);
369         }
370
371         try {
372             p("putfield (J): ");
373             if (doit) {
374                 putfieldJ pfj = new putfieldJ();
375                 long l = 1234567890123L;
376                 pfj.l = l;
377                 check(pfj.l, l);
378             } else
379                 ok();
380         } catch (NoClassDefFoundError t) {
381             failed(t);
382         }
383
384         try {
385             p("putfield (F): ");
386             if (doit) {
387                 putfieldF pff = new putfieldF();
388                 float f = 123.456F;
389                 pff.f = f;
390                 check(pff.f, f);
391             } else
392                 ok();
393         } catch (NoClassDefFoundError t) {
394             failed(t);
395         }
396
397         try {
398             p("putfield (D): ");
399             if (doit) {
400                 putfieldD pfd = new putfieldD();
401                 double d = 789.012;
402                 pfd.d = d;
403                 check(pfd.d, d);
404             } else
405                 ok();
406         } catch (NoClassDefFoundError t) {
407             failed(t);
408         }
409
410         try {
411             p("putfield (L): ");
412             if (doit) {
413                 putfieldL pfl = new putfieldL();
414                 Object o = null;
415                 pfl.o = o;
416                 check(pfl.o, o);
417             } else
418                 ok();
419         } catch (NoClassDefFoundError t) {
420             failed(t);
421         }
422     }
423
424     private void putfieldconst() {
425         try {
426             p("putfieldconst (I): ");
427             if (doit) {
428                 putfieldconstI pfci = new putfieldconstI();
429                 pfci.i = 123;
430                 check(pfci.i, 123);
431             } else
432                 ok();
433         } catch (NoClassDefFoundError t) {
434             failed(t);
435         }
436  
437         try {
438             p("putfieldconst (J): ");
439             if (doit) {
440                 putfieldconstJ pfcj = new putfieldconstJ();
441                 pfcj.l = 1234567890123L;
442                 check(pfcj.l, 1234567890123L);
443             } else
444                 ok();
445         } catch (NoClassDefFoundError t) {
446             failed(t);
447         }
448
449         try {
450             p("putfieldconst (F): ");
451             if (doit) {
452                 putfieldconstF pfcf = new putfieldconstF();
453                 pfcf.f = 123.456F;
454                 check(pfcf.f, 123.456F);
455             } else
456                 ok();
457         } catch (NoClassDefFoundError t) {
458             failed(t);
459         }
460  
461         try {
462             p("putfieldconst (D): ");
463             if (doit) {
464                 putfieldconstD pfcd = new putfieldconstD();
465                 pfcd.d = 789.012;
466                 check(pfcd.d, 789.012);
467             } else
468                 ok();
469         } catch (NoClassDefFoundError t) {
470             failed(t);
471         }
472
473         try {
474             p("putfieldconst zero (I): ");
475             if (doit) {
476                 putfieldconstI pfci = new putfieldconstI();
477                 pfci.i = 0;
478                 check(pfci.i, 0);
479             } else
480                 ok();
481         } catch (NoClassDefFoundError t) {
482             failed(t);
483         }
484  
485         try {
486             p("putfieldconst zero (J): ");
487             if (doit) {
488                 putfieldconstJ pfcj = new putfieldconstJ();
489                 pfcj.l = 0L;
490                 check(pfcj.l, 0L);
491             } else
492                 ok();
493         } catch (NoClassDefFoundError t) {
494             failed(t);
495         }
496
497         try {
498             p("putfieldconst zero (F): ");
499             if (doit) {
500                 putfieldconstF pfcf = new putfieldconstF();
501                 pfcf.f = 0.0F;
502                 check(pfcf.f, 0.0F);
503             } else
504                 ok();
505         } catch (NoClassDefFoundError t) {
506             failed(t);
507         }
508  
509         try {
510             p("putfieldconst zero (D): ");
511             if (doit) {
512                 putfieldconstD pfcd = new putfieldconstD();
513                 pfcd.d = 0.0;
514                 check(pfcd.d, 0.0);
515             } else
516                 ok();
517         } catch (NoClassDefFoundError t) {
518             failed(t);
519         }
520
521         try {
522             p("putfieldconst zero (L): ");
523             if (doit) {
524                 putfieldconstL pfcl = new putfieldconstL();
525                 pfcl.o = null;
526                 check(pfcl.o, null);
527             } else
528                 ok();
529         } catch (NoClassDefFoundError t) {
530             failed(t);
531         }
532
533         try {
534             p("putfieldconst unresolved class: ");
535             if (doit) {
536                 putfieldconstC pfcc = new putfieldconstC();
537                 pfcc.c = putfieldconstC.class;
538                 check(pfcc.c, Class.forName("putfieldconstC"));
539             } else
540                 ok();
541         } catch (NoClassDefFoundError t) {
542             failed(t);
543         } catch (ClassNotFoundException t) {
544             failed(t);
545         }
546     }
547
548     private void newarray() {
549         try {
550             p("newarray: ");
551             if (doit) {
552                 newarray[] na = new newarray[1];
553             }
554             ok();
555         } catch (NoClassDefFoundError t) {
556             failed(t);
557         }
558     }
559
560     private void multianewarray() {
561         try {
562             p("multianewarray: ");
563             if (doit) {
564                 multianewarray[][] ma = new multianewarray[1][1];
565             }
566             ok();
567         } catch (NoClassDefFoundError t) {
568             failed(t);
569         }
570     }
571
572     private void invokespecial() {
573         try {
574             p("invokespecial: ");
575             if (doit)
576                 new invokespecial();
577             else
578                 ok();
579         } catch (NoClassDefFoundError t) {
580             failed(t);
581         }
582     }
583
584     private void checkcast() {
585         Object o = new Object();
586
587         // class
588         try {
589             p("checkcast class: ");
590             if (doit) {
591                 checkcastC cc = (checkcastC) o;
592                 failed();
593             } else
594                 ok();
595         } catch (ClassCastException e) {
596             ok();
597         } catch (NoClassDefFoundError t) {
598             failed(t);
599         }
600
601         // interface
602         try {
603             p("checkcast interface: ");
604             if (doit) {
605                 checkcastI ci = (checkcastI) o;
606                 failed();
607             } else
608                 ok();
609         } catch (ClassCastException e) {
610             ok();
611         } catch (NoClassDefFoundError t) {
612             failed(t);
613         }
614
615
616         // array
617
618         Object[] oa = new Object[1];
619
620         try {
621             p("checkcast class array: ");
622             if (doit) {
623                 checkcastC[] cca = (checkcastC[]) oa;
624                 failed();
625             } else
626                 ok();
627         } catch (ClassCastException e) {
628             ok();
629         } catch (NoClassDefFoundError t) {
630             failed(t);
631         }
632     }
633
634     private void _instanceof() {
635         Object o = new Object();
636
637         try {
638             p("instanceof class: ");
639             if (doit)
640                 if (o instanceof instanceofC)
641                     failed();
642                 else
643                     ok();
644             else
645                 ok();
646         } catch (NoClassDefFoundError t) {
647             failed(t);
648         }
649
650         try {
651             p("instanceof interface: ");
652             if (doit)
653                 if (o instanceof instanceofI)
654                     failed();
655                 else
656                     ok();
657             else
658                 ok();
659         } catch (NoClassDefFoundError t) {
660             failed(t);
661         }
662
663
664         // array
665
666         Object[] oa = new Object[1];
667
668         try {
669             p("instanceof class array: ");
670             if (doit)
671                 if (oa instanceof instanceofC[])
672                     failed();
673                 else
674                     ok();
675             else
676                 ok();
677         } catch (NoClassDefFoundError t) {
678             failed(t);
679         }
680     }
681
682     private void aastoreconst() {
683         Class[] ca = new Class[1];
684
685         try {
686             p("aastoreconst of unresolved class != NULL: ");
687             if (doit) {
688                 ca[0] = aastoreconstClass.class;
689
690                 if (ca[0] != null)
691                     ok();
692                 else
693                     failed();
694
695                 p("aastoreconst of unresolved correct value: ");
696                 check(ca[0],Class.forName("aastoreconstClass"));
697             } else
698                 ok();
699         } catch (NoClassDefFoundError t) {
700             failed(t);
701         } catch (ClassNotFoundException t) {
702             failed(t);
703         }
704     }
705
706     private static final void ok() {
707         pln("OK");
708     }
709
710     private static final void failed() {
711         pln("FAILED");
712     }
713
714     private static final void failed(Throwable t) {
715         pln("FAILED: " + t);
716     }
717
718     private static final void check(int a, int b) {
719         if (a == b)
720             ok();
721         else
722             pln("FAILED: " + a + " != " + b + " (0x" + Integer.toHexString(a) + " != 0x" + Integer.toHexString(b) + ")");
723     }
724
725     private static final void check(long a, long b) {
726         if (a == b)
727             ok();
728         else
729             pln("FAILED: " + a + " != " + b + " (0x" + Long.toHexString(a) + " != 0x" + Long.toHexString(b) + ")");
730     }
731
732     private static final void check(float a, float b) {
733         if (a == b)
734             ok();
735         else
736             pln("FAILED: " + a + " != " + b);
737     }
738
739     private static final void check(double a, double b) {
740         if (a == b)
741             ok();
742         else
743             pln("FAILED: " + a + " != " + b);
744     }
745
746     private static final void check(Object a, Object b) {
747         if (a == b)
748             ok();
749         else
750             pln("FAILED: " + a + " != " + b);
751     }
752
753     private static final void p(String s) {
754         System.out.print(s);
755     }
756
757     private static final void pln(String s) {
758         System.out.println(s);
759     }
760 }
761
762 // vim: et ts=4 sw=4
763