1 /* tests/regression/bugzilla/TestPatcher.java
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 import org.junit.Test;
27 import static org.junit.Assert.*;
31 public class TestPatcher {
32 static boolean doit = true;
34 final static int i = 123;
35 final static long l = 1234567890123L;
36 final static float f = 123.456F;
37 final static double d = 789.012;
38 final static Object o = new Object();
41 public void testNormal() {
62 public void testWithoutClasses() {
63 // Delete all classes.
64 //new File("TestPatcher$invokestatic.class").delete();
86 private void invokestatic() {
90 } catch (NoClassDefFoundError e) {
95 private void getstatic() {
98 assertTrue(getstaticI.i + " != " + i, getstaticI.i == i);
99 } catch (NoClassDefFoundError e) {
105 assertTrue(getstaticJ.l + " != " + l, getstaticJ.l == l);
106 } catch (NoClassDefFoundError e) {
112 assertTrue(getstaticF.f + " != " + f, getstaticF.f == f);
113 } catch (NoClassDefFoundError e) {
119 assertTrue(getstaticD.d + " != " + d, getstaticD.d == d);
120 } catch (NoClassDefFoundError e) {
126 assertTrue(getstaticL.o + " != null", getstaticL.o == null);
127 } catch (NoClassDefFoundError e) {
132 private void putstatic() {
136 assertTrue(putstaticI.i + " != " + i, putstaticI.i == i);
138 } catch (NoClassDefFoundError t) {
145 assertTrue(putstaticJ.l + " != " + l, putstaticJ.l == l);
147 } catch (NoClassDefFoundError t) {
154 assertTrue(putstaticF.f + " != " + f, putstaticF.f == f);
156 } catch (NoClassDefFoundError t) {
163 assertTrue(putstaticD.d + " != " + d, putstaticD.d == d);
165 } catch (NoClassDefFoundError t) {
173 assertTrue(putstaticL.o + " != " + o, putstaticL.o == o);
175 } catch (NoClassDefFoundError t) {
180 private void putstaticconst() {
183 putstaticconstI.i = i;
184 assertTrue(putstaticconstI.i + " != " + i, putstaticconstI.i == i);
186 } catch (NoClassDefFoundError t) {
192 putstaticconstJ.l = l;
193 assertTrue(putstaticconstJ.l + " != " + l, putstaticconstJ.l == l);
195 } catch (NoClassDefFoundError t) {
201 putstaticconstF.f = f;
202 assertTrue(putstaticconstF.f + " != " + f, putstaticconstF.f == f);
204 } catch (NoClassDefFoundError t) {
210 putstaticconstD.d = d;
211 assertTrue(putstaticconstD.d + " != " + d, putstaticconstD.d == d);
213 } catch (NoClassDefFoundError t) {
219 putstaticconstI.i = 0;
220 assertTrue(putstaticconstI.i + " != " + 0, putstaticconstI.i == 0);
222 } catch (NoClassDefFoundError t) {
228 putstaticconstJ.l = 0L;
229 assertTrue(putstaticconstJ.l + " != " + 0L, putstaticconstJ.l == 0L);
231 } catch (NoClassDefFoundError t) {
237 putstaticconstF.f = 0.0F;
238 assertTrue(putstaticconstF.f + " != " + 0.0F, putstaticconstF.f == 0.0F);
240 } catch (NoClassDefFoundError t) {
246 putstaticconstD.d = 0.0;
247 assertTrue(putstaticconstD.d + " != " + 0.0, putstaticconstD.d == 0.0);
249 } catch (NoClassDefFoundError t) {
255 putstaticconstL.o = null;
256 assertTrue(putstaticconstL.o + " != " + null, putstaticconstL.o == null);
258 } catch (NoClassDefFoundError t) {
264 putstaticconstC.c = putstaticconstC.class;
265 assertTrue(putstaticconstC.c + " != " + Class.forName("TestPatcher$putstaticconstC"), putstaticconstC.c == Class.forName("TestPatcher$putstaticconstC"));
267 } catch (NoClassDefFoundError t) {
269 } catch (ClassNotFoundException t) {
274 private void getfield() {
277 assertTrue(new getfieldI().i + " != " + i, new getfieldI().i == i);
278 } catch (NoClassDefFoundError t) {
284 assertTrue(new getfieldJ().l + " != " + l, new getfieldJ().l == l);
285 } catch (NoClassDefFoundError t) {
291 assertTrue(new getfieldF().f + " != " + f, new getfieldF().f == f);
292 } catch (NoClassDefFoundError t) {
298 assertTrue(new getfieldD().d + " != " + d, new getfieldD().d == d);
299 } catch (NoClassDefFoundError t) {
305 assertTrue(new getfieldL().o + " != " + null, new getfieldL().o == null);
306 } catch (NoClassDefFoundError t) {
311 private void putfield() {
314 TestPatcher.putfieldI pfi = new TestPatcher.putfieldI();
316 assertTrue(pfi.i + " != " + i, pfi.i == i);
318 } catch (NoClassDefFoundError t) {
324 putfieldJ pfj = new putfieldJ();
326 assertTrue(pfj.l + " != " + l, pfj.l == l);
328 } catch (NoClassDefFoundError t) {
334 putfieldF pff = new putfieldF();
336 assertTrue(pff.f + " != " + f, pff.f == f);
338 } catch (NoClassDefFoundError t) {
344 putfieldD pfd = new putfieldD();
346 assertTrue(pfd.d + " != " + d, pfd.d == d);
348 } catch (NoClassDefFoundError t) {
354 putfieldL pfl = new putfieldL();
356 assertTrue(pfl.o + " != " + o, pfl.o == o);
358 } catch (NoClassDefFoundError t) {
363 private void putfieldconst() {
366 putfieldconstI pfci = new putfieldconstI();
368 assertTrue(pfci.i + " != " + i, pfci.i == i);
370 } catch (NoClassDefFoundError t) {
376 putfieldconstJ pfcj = new putfieldconstJ();
378 assertTrue(pfcj.l + " != " + l, pfcj.l == l);
380 } catch (NoClassDefFoundError t) {
386 putfieldconstF pfcf = new putfieldconstF();
388 assertTrue(pfcf.f + " != " + f, pfcf.f == f);
390 } catch (NoClassDefFoundError t) {
396 putfieldconstD pfcd = new putfieldconstD();
398 assertTrue(pfcd.d + " != " + d, pfcd.d == d);
400 } catch (NoClassDefFoundError t) {
406 putfieldconstI pfci = new putfieldconstI();
408 assertTrue(pfci.i + " != " + 0, pfci.i == 0);
410 } catch (NoClassDefFoundError t) {
416 putfieldconstJ pfcj = new putfieldconstJ();
418 assertTrue(pfcj.l + " != " + 0L, pfcj.l == 0L);
420 } catch (NoClassDefFoundError t) {
426 putfieldconstF pfcf = new putfieldconstF();
428 assertTrue(pfcf.f + " != " + 0.0F, pfcf.f == 0.0F);
430 } catch (NoClassDefFoundError t) {
436 putfieldconstD pfcd = new putfieldconstD();
438 assertTrue(pfcd.d + " != " + 0.0, pfcd.d == 0.0);
440 } catch (NoClassDefFoundError t) {
446 putfieldconstL pfcl = new putfieldconstL();
448 assertTrue(pfcl.o + " != " + null, pfcl.o == null);
450 } catch (NoClassDefFoundError t) {
456 putfieldconstC pfcc = new putfieldconstC();
457 pfcc.c = putfieldconstC.class;
458 assertTrue(pfcc.c + " != " + Class.forName("TestPatcher$putfieldconstC"), pfcc.c == Class.forName("TestPatcher$putfieldconstC"));
460 } catch (NoClassDefFoundError t) {
462 } catch (ClassNotFoundException t) {
467 private void newarray() {
470 newarray[] na = new newarray[1];
473 } catch (NoClassDefFoundError t) {
478 private void multianewarray() {
481 multianewarray[][] ma = new multianewarray[1][1];
484 } catch (NoClassDefFoundError t) {
489 private void invokespecial() {
493 } catch (NoClassDefFoundError t) {
498 private void checkcast() {
499 Object o = new Object();
504 checkcastC cc = (checkcastC) o;
507 } catch (ClassCastException success) {
509 } catch (NoClassDefFoundError t) {
516 checkcastI ci = (checkcastI) o;
519 } catch (ClassCastException success) {
521 } catch (NoClassDefFoundError t) {
527 Object[] oa = new Object[1];
531 checkcastC[] cca = (checkcastC[]) oa;
534 } catch (ClassCastException e) {
536 } catch (NoClassDefFoundError t) {
541 private void _instanceof() {
542 Object o = new Object();
546 if (o instanceof instanceofC)
548 } catch (NoClassDefFoundError t) {
554 if (o instanceof instanceofI)
556 } catch (NoClassDefFoundError t) {
562 Object[] oa = new Object[1];
566 if (oa instanceof instanceofC[])
568 } catch (NoClassDefFoundError t) {
573 private void aastoreconst() {
574 Class[] ca = new Class[1];
578 ca[0] = aastoreconstClass.class;
583 assertTrue(ca[0] + " != " + Class.forName("TestPatcher$aastoreconstClass") , ca[0] == Class.forName("TestPatcher$aastoreconstClass"));
585 } catch (NoClassDefFoundError t) {
587 } catch (ClassNotFoundException t) {
592 static class invokestatic { static void sub() {} }
593 static class invokespecial { void invokespecial() {} }
595 static class getstaticI { static int i = TestPatcher.i; }
596 static class getstaticJ { static long l = TestPatcher.l; }
597 static class getstaticF { static float f = TestPatcher.f; }
598 static class getstaticD { static double d = TestPatcher.d; }
599 static class getstaticL { static Object o = null; }
601 static class putstaticI { static int i; }
602 static class putstaticJ { static long l; }
603 static class putstaticF { static float f; }
604 static class putstaticD { static double d; }
605 static class putstaticL { static Object o; }
607 static class putstaticconstI { static int i; }
608 static class putstaticconstJ { static long l; }
609 static class putstaticconstF { static float f; }
610 static class putstaticconstD { static double d; }
611 static class putstaticconstL { static Object o; }
612 static class putstaticconstC { static Class<putstaticconstC> c; }
614 static class getfieldI { int i = TestPatcher.i; }
615 static class getfieldJ { long l = TestPatcher.l; }
616 static class getfieldF { float f = TestPatcher.f; }
617 static class getfieldD { double d = TestPatcher.d; }
618 static class getfieldL { Object o = null; }
620 static class putfieldI { int i; }
621 static class putfieldJ { long l; }
622 static class putfieldF { float f; }
623 static class putfieldD { double d; }
624 static class putfieldL { Object o; }
626 static class putfieldconstI { int i; }
627 static class putfieldconstJ { long l; }
628 static class putfieldconstF { float f; }
629 static class putfieldconstD { double d; }
630 static class putfieldconstL { Object o; }
631 static class putfieldconstC { Class<putfieldconstC> c; }
633 static class newarray {}
634 static class multianewarray {}
636 static class instanceofC {}
637 static interface instanceofI {}
639 static class checkcastC {}
640 static interface checkcastI {}
642 static class aastoreconstClass {}