2 * Copyright (C) 2015, 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.ListenerAdapter;
21 import gov.nasa.jpf.annotation.JPFAttribute;
22 import gov.nasa.jpf.util.test.TestJPF;
23 import gov.nasa.jpf.vm.ClassInfo;
24 import gov.nasa.jpf.vm.FieldInfo;
25 import gov.nasa.jpf.vm.MethodInfo;
26 import gov.nasa.jpf.vm.VM;
27 import org.junit.Test;
30 * regression test for JPFAttribute annotations
32 public class JPFAttrAnnotationTest extends TestJPF {
34 static final String LISTENER = "gov.nasa.jpf.test.vm.basic.JPFAttrAnnotationTest$LoadListener";
35 static final String ATTR_CLS = "gov.nasa.jpf.test.vm.basic.JPFAttrAnnotationTest$MyAttr"; // needs to const
36 static final String TGT_CLS = "gov.nasa.jpf.test.vm.basic.JPFAttrAnnotationTest$SomeClass";
38 public static class MyAttr {}
40 @JPFAttribute(ATTR_CLS)
41 public static class SomeClass {
45 @JPFAttribute(ATTR_CLS)
46 Object data2 = "whatever";
50 @JPFAttribute(ATTR_CLS)
52 System.out.println("SomeClass.bar() executed");
56 public static class LoadListener extends ListenerAdapter {
59 public void classLoaded (VM vm, ClassInfo ci){
60 if (ci.getName().equals(TGT_CLS)){
61 System.out.println("#--- checking attribute annotations of " + ci.getName());
63 assertTrue( ci.hasAttr(MyAttr.class));
64 System.out.println("# class attr Ok");
66 MethodInfo mi = ci.getMethod("bar()V", false);
67 assertTrue( mi.hasAttr(MyAttr.class));
68 System.out.println("# method bar() attr Ok");
70 mi = ci.getMethod("foo()V", false);
71 assertFalse( mi.hasAttr(MyAttr.class));
73 FieldInfo fi = ci.getDeclaredInstanceField("data2");
74 assertTrue( fi.hasAttr(MyAttr.class));
75 System.out.println("# field data2 attr Ok");
77 fi = ci.getDeclaredInstanceField("data1");
78 assertFalse( fi.hasAttr(MyAttr.class));
84 public void testAttrs(){
85 if (verifyNoPropertyViolation("+listener=" + LISTENER)){
86 SomeClass o = new SomeClass();