KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > jpf > jvm > JPF_gov_nasa_jpf_jvm_TestNativePeer


1 //
2
// Copyright (C) 2005 United States Government as represented by the
3
// Administrator of the National Aeronautics and Space Administration
4
// (NASA). All Rights Reserved.
5
//
6
// This software is distributed under the NASA Open Source Agreement
7
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
8
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
9
// directory tree for the complete NOSA document.
10
//
11
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18
//
19

20 package gov.nasa.jpf.jvm;
21
22 /**
23  * native peer class for unit testing MJI
24  */

25 public class JPF_gov_nasa_jpf_jvm_TestNativePeer {
26   public static void $clinit (MJIEnv env, int rcls) {
27     env.setStaticIntField(rcls, "sdata", 42);
28   }
29
30   public static void $init__I (MJIEnv env, int robj, int i) {
31     env.setIntField(robj, "idata", i);
32   }
33
34   public static int nativeCreate2DimIntArray (MJIEnv env, int robj, int size1,
35                                               int size2) {
36     int ar = env.newObjectArray("[I", size1);
37
38     for (int i = 0; i < size1; i++) {
39       int ea = env.newIntArray(size2);
40
41       if (i == 1) {
42         env.setIntArrayElement(ea, 1, 42);
43       }
44
45       env.setReferenceArrayElement(ar, i, ea);
46     }
47
48     return ar;
49   }
50
51   public static int nativeCreateIntArray (MJIEnv env, int robj, int size) {
52     int ar = env.newIntArray(size);
53
54     env.setIntArrayElement(ar, 1, 1);
55
56     return ar;
57   }
58
59   public static int nativeCreateStringArray (MJIEnv env, int robj, int size) {
60     int ar = env.newObjectArray("Ljava/lang/String;", size);
61
62     env.setReferenceArrayElement(ar, 1, env.newString("one"));
63
64     return ar;
65   }
66
67   public static void nativeException (MJIEnv env, int robj) {
68     env.throwException("java.lang.UnsupportedOperationException", "caught me");
69   }
70
71   public static int nativeCrash (MJIEnv env, int robj) {
72     String JavaDoc s = null;
73     return s.length();
74   }
75   
76   public static int nativeInstanceMethod (MJIEnv env, int robj, double d,
77                                           char c, boolean b, int i) {
78     if ((d == 2.0) && (c == '?') && b) {
79       return i + 2;
80     }
81
82     return 0;
83   }
84
85   public static long nativeStaticMethod (MJIEnv env, int rcls, long l,
86                                          int stringRef) {
87     String JavaDoc s = env.getStringObject(stringRef);
88
89     if ("Blah".equals(s)) {
90       return l + 2;
91     }
92
93     return 0;
94   }
95 }
96
Popular Tags