Initial import
[jpf-core.git] / src / tests / gov / nasa / jpf / vm / multiProcess / MethodTest.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
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
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
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.
17  */
18
19 package gov.nasa.jpf.vm.multiProcess;
20
21 import gov.nasa.jpf.util.test.TestMultiProcessJPF;
22 import gov.nasa.jpf.vm.MethodInfo;
23
24 import java.lang.reflect.Method;
25 import java.util.List;
26
27 import org.junit.Test;
28
29 /**
30  * @author Nastaran Shafiei <nastaran.shafiei@gmail.com>
31  */
32 public class MethodTest extends TestMultiProcessJPF {
33   public native void keepMethod(Method m, int prcId);
34
35   // To check the type safe cloning of methods
36   @Test
37   public void methodCloneTest() throws SecurityException, NoSuchMethodException {
38     if(!isJPFRun()) {
39       JPF_gov_nasa_jpf_vm_multiProcess_MethodTest.resetPrcIds();
40     }
41
42     if (mpVerifyNoPropertyViolation(2)) {
43       Method m = MethodTest.class.getMethod("methodCloneTest", new Class[]{});
44       int prcId = getProcessId();
45       keepMethod(m, prcId);
46     }
47
48     if(!isJPFRun()) {
49       List<MethodInfo> methods = JPF_gov_nasa_jpf_vm_multiProcess_MethodTest.getMethods();
50       assertEquals(methods.size(), 2);
51       assertTrue(methods.get(0)!=methods.get(1));
52     }
53   }
54
55   @Test
56   public void methodDeclaringClassTest() throws SecurityException, NoSuchMethodException {
57     if (mpVerifyNoPropertyViolation(2)) {
58       Class<?> cls = MethodTest.class;
59
60       // The loader of this class should be the same as the loader that loads 
61       // the class java.lang.Thread within this process
62       assertEquals(cls.getClassLoader(), ClassLoader.getSystemClassLoader());
63       for(Method m: cls.getDeclaredMethods()) {
64         assertEquals(m.getDeclaringClass(), cls);
65       }
66     }
67   }
68 }