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.vm;
21 import gov.nasa.jpf.jvm.ClassFile;
22 import gov.nasa.jpf.jvm.DirClassFileContainer;
23 import gov.nasa.jpf.jvm.JVMAnnotationParser;
24 import gov.nasa.jpf.jvm.JVMClassFileContainer;
25 import gov.nasa.jpf.util.test.TestJPF;
28 import org.junit.Test;
31 * unit test for AnnotationInfo creation
33 public class AnnotationInfoTest extends TestJPF {
36 String value() default "nothing";
41 int[] someArray() default { 1, 2, 3 };
44 protected AnnotationInfo createAnnotationInfo (String annotationName) throws ClassParseException {
45 DirClassFileContainer dfc = new DirClassFileContainer( new File("build/tests"));
46 ClassPath cp = new ClassPath();
47 cp.addClassFileContainer(dfc);
49 JVMClassFileContainer.JVMClassFileMatch match = (JVMClassFileContainer.JVMClassFileMatch)cp.findMatch( annotationName);
50 byte[] data = match.getData();
52 ClassFile cf = new ClassFile( data);
53 JVMAnnotationParser parser = new JVMAnnotationParser(cf);
55 return new AnnotationInfo( annotationName, null, parser);
59 public void testStringDefaultValue() {
61 String annotationName = "gov.nasa.jpf.vm.AnnotationInfoTest$X";
63 AnnotationInfo ai = createAnnotationInfo(annotationName);
64 AnnotationInfo.Entry[] entries = ai.getEntries();
66 assertTrue(entries.length == 1);
67 assertTrue(entries[0].getKey().equals("value"));
68 assertTrue(entries[0].getValue().equals("nothing"));
70 } catch (Throwable t){
72 fail("unexpected exception: " + t);
77 public void testIntArrayDefaultValue() {
79 String annotationName = "gov.nasa.jpf.vm.AnnotationInfoTest$Y";
81 AnnotationInfo ai = createAnnotationInfo(annotationName);
82 AnnotationInfo.Entry[] entries = ai.getEntries();
84 assertTrue(entries.length == 2);
85 assertTrue(entries[1].getKey().equals("someArray"));
87 Object[] a = (Object[]) entries[1].getValue();
88 assertTrue(a.length == 3);
89 assertTrue((Integer)a[0] == 1 && (Integer)a[1] == 2 && (Integer)a[2] == 3);
91 } catch (Throwable t){
93 fail("unexpected exception: " + t);