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.
18 package gov.nasa.jpf.test.vm.basic;
20 import gov.nasa.jpf.util.test.TestJPF;
22 import org.junit.Test;
26 * basic method invocation test
34 class TestMethodBase extends TestJPF implements TMI {
48 TestMethodBase (int a) {
53 boolean baz (boolean p, byte b, char c, short s, int i, long l, float f, double d, Object o) {
62 assert o.equals(new Integer(42));
87 public class MethodTest extends TestMethodBase {
95 public MethodTest () {
107 double foo (boolean p, byte b, char c, short s, int i, long l, float f, double d, Object o) {
116 assert o.equals(new Integer(42));
133 public void testCtor() {
134 if (verifyNoPropertyViolation()) {
135 MethodTest o1 = new MethodTest();
136 assert o1.data == 42;
137 assert o1.baseData == 42;
139 MethodTest o2 = new MethodTest(42);
140 assert o2.data == 42;
141 assert o2.baseData == 42;
146 public void testCall() {
147 if (verifyNoPropertyViolation()) {
148 MethodTest o = new MethodTest();
149 assert o.foo(true, (byte) 4, '?', (short) 42, 4242, 424242, 4.2f, 4.242, new Integer(42)) == 4.242;
155 public void testInheritedCall() {
156 if (verifyNoPropertyViolation()) {
157 MethodTest o = new MethodTest();
158 assert o.baz(true, (byte) 4, '?', (short) 42, 4242, 424242, 4.2f, 4.242, new Integer(42));
159 assert o.baseData == 44;
164 public void testVirtualCall() {
165 if (verifyNoPropertyViolation()) {
166 MethodTest o = new MethodTest();
167 TestMethodBase b = o;
170 assert o.baseData == 45;
175 public void testSpecialCall() {
176 if (verifyNoPropertyViolation()) {
177 MethodTest o = new MethodTest();
183 public void testStaticCall() {
184 if (verifyNoPropertyViolation()) {
185 assert TestMethodBase.sData == -1;
188 assert TestMethodBase.sData == 9;
190 TestMethodBase.taz();
191 assert TestMethodBase.sData == 24;
194 //TestMethod o = new TestMethod();
196 // statically equiv. to this: (no warnings) - pcd
200 assert TestMethodBase.sData == 9;
205 public void testInterfaceCall() {
206 if (verifyNoPropertyViolation()) {
207 MethodTest o = new MethodTest();
211 assert o.baseData == 45;
217 assert false : "should bever be invoked";
222 static class A0 extends A {
229 static class A1 extends A {
237 * this is tricky - both the allocations and the foo() calls have to be
238 * the same instructions, and we have to remove all 'a' references before
239 * forcing a GC. Otherwise we don't allocate 'a's with the same reference values
242 @Test public void testCallAcrossGC () {
244 if (verifyNoPropertyViolation()){
245 System.out.println("testing virtual calls on GC boundaries");
249 assert a.foo() == 0 : "wrong A.foo() called for A0";
252 Runtime.getRuntime().gc(); // this should recycle 'a'
255 assert a.foo() == 1 : "wrong A.foo() called for A1";