2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package gov.nasa.jpf.test.vm.basic;
21 import gov.nasa.jpf.util.test.TestJPF;
22 import java.lang.reflect.Constructor;
23 import java.lang.reflect.Method;
24 import org.junit.Test;
27 * test automatic and recursive clinit invocation
29 public class RecursiveClinitTest extends TestJPF {
34 System.out.println("Base clinit");
38 static class Derived extends Base {
39 static int d = Base.d * 42;
41 System.out.println("Derived clinit");
44 public Derived (int i){
45 System.out.println("Derived(" + i + ')');
48 public static void foo(){
49 System.out.println("Derived.foo()");
54 public void testStaticField (){
55 if (verifyNoPropertyViolation()) {
56 System.out.println("main now referencing Derived.d");
58 System.out.println("back in main");
65 public void testNewInstance (){
66 if (verifyNoPropertyViolation()) {
67 System.out.println("main now calling Derived.class.newInstance()");
69 Derived.class.newInstance();
70 } catch (Throwable t) {
71 fail("instantiation failed with " + t);
73 System.out.println("back in main");
75 assertTrue(Derived.d == 42);
80 public void testMethodReflection (){
81 if (verifyNoPropertyViolation()) {
83 Class<?> clazz = Class.forName("gov.nasa.jpf.test.vm.basic.RecursiveClinitTest$Derived");
84 System.out.println("main now calling Derived.foo()");
85 Method m = clazz.getDeclaredMethod("foo", new Class[0]);
88 System.out.println("back in main");
89 assertTrue(Derived.d == 42);
91 } catch (Throwable t){
92 fail("test failed with: " + t);
98 public void testCtorReflection (){
99 if (verifyNoPropertyViolation()) {
101 Class<?> clazz = Class.forName("gov.nasa.jpf.test.vm.basic.RecursiveClinitTest$Derived");
102 System.out.println("main now creating Derived(-42)");
103 Constructor ctor = clazz.getConstructor(new Class[] {int.class});
104 Object o = ctor.newInstance( new Object[] {Integer.valueOf(-42)});
106 System.out.println("back in main");
107 assertTrue( o instanceof Derived);
108 assertTrue(Derived.d == 42);
110 } catch (Throwable t){
111 fail("test failed with: " + t);
116 // <2do> we also need the SerializatinConstructor