00001 package jpl.test; 00002 00003 import jpl.Compound; 00004 import jpl.Query; 00005 import jpl.Term; 00006 00007 // This class contains members which support those tests which are performed from Prolog. 00008 // See also TestJUnit 00009 public class Test { 00010 public Test() { 00011 } 00012 public Test(Term t) { 00013 this.termFromConstructor = t; 00014 } 00015 public Term termFromConstructor; 00016 // 00017 public static boolean fieldStaticBoolean; 00018 public static final boolean fieldStaticBoolean1 = false; 00019 public static final boolean fieldStaticBoolean2 = true; 00020 // 00021 public static char fieldStaticChar; 00022 public static final char fieldStaticChar1 = '\u0000'; 00023 public static final char fieldStaticChar2 = '\uFFFF'; 00024 // 00025 public static byte fieldStaticByte; 00026 public static final byte fieldStaticByte1 = -(1 << 7); 00027 public static final byte fieldStaticByte2 = -1; 00028 public static final byte fieldStaticByte3 = 0; 00029 public static final byte fieldStaticByte4 = 1; 00030 public static final byte fieldStaticByte5 = (1 << 7) - 1; 00031 // 00032 public static short fieldStaticShort; 00033 public static final short fieldStaticShort1 = -(1 << 15); 00034 public static final short fieldStaticShort2 = -(1 << 7); 00035 public static final short fieldStaticShort3 = -1; 00036 public static final short fieldStaticShort4 = 0; 00037 public static final short fieldStaticShort5 = 1; 00038 public static final short fieldStaticShort6 = (1 << 7) - 1; 00039 public static final short fieldStaticShort7 = (1 << 15) - 1; 00040 // 00041 public static int fieldStaticInt; 00042 public static final int fieldStaticInt1 = -(1 << 31); 00043 public static final int fieldStaticInt2 = -(1 << 15); 00044 public static final int fieldStaticInt3 = -(1 << 7); 00045 public static final int fieldStaticInt4 = -1; 00046 public static final int fieldStaticInt5 = 0; 00047 public static final int fieldStaticInt6 = 1; 00048 public static final int fieldStaticInt7 = (1 << 7) - 1; 00049 public static final int fieldStaticInt8 = (1 << 15) - 1; 00050 public static final int fieldStaticInt9 = (1 << 31) - 1; 00051 // 00052 public static long fieldStaticLong; 00053 public static final long fieldStaticLong1 = -(1 << 63); 00054 public static final long fieldStaticLong2 = -(1 << 31); 00055 public static final long fieldStaticLong3 = -(1 << 15); 00056 public static final long fieldStaticLong4 = -(1 << 7); 00057 public static final long fieldStaticLong5 = -1; 00058 public static final long fieldStaticLong6 = 0; 00059 public static final long fieldStaticLong7 = 1; 00060 public static final long fieldStaticLong8 = (1 << 7) - 1; 00061 public static final long fieldStaticLong9 = (1 << 15) - 1; 00062 public static final long fieldStaticLong10 = (1 << 31) - 1; 00063 public static final long fieldStaticLong11 = (1 << 63) - 1; 00064 // 00065 public static float fieldStaticFloat; 00066 public static final float fieldStaticFloat1 = 12345.6789F; 00067 public static final float fieldStaticFloat2 = 3.4e+38F; // nearly MAX_VALUE 00068 public static final float fieldStaticFloat3 = 1.4e-45F; // nearly MIN_VALUE 00069 public static final float fieldStaticFloat4 = 0.0F; 00070 public static final float fieldStaticFloat5 = java.lang.Float.MIN_VALUE; 00071 public static final float fieldStaticFloat6 = java.lang.Float.MAX_VALUE; 00072 public static final float fieldStaticFloat7 = java.lang.Float.NEGATIVE_INFINITY; 00073 public static final float fieldStaticFloat8 = java.lang.Float.POSITIVE_INFINITY; 00074 public static final float fieldStaticFloat9 = java.lang.Float.NaN; 00075 // 00076 public static double fieldStaticDouble; 00077 public static final double fieldStaticDouble1 = 12345.6789D; 00078 public static final double fieldStaticDouble2 = 2.3456789e+100D; 00079 public static final double fieldStaticDouble3 = 3.456789e-100D; 00080 public static final double fieldStaticDouble4 = 0.0D; 00081 public static final double fieldStaticDouble5 = Double.MIN_VALUE; 00082 public static final double fieldStaticDouble6 = Double.MAX_VALUE; 00083 public static final double fieldStaticDouble7 = Double.NEGATIVE_INFINITY; 00084 public static final double fieldStaticDouble8 = Double.POSITIVE_INFINITY; 00085 public static final double fieldStaticDouble9 = Double.NaN; 00086 // 00087 public static Object[] fieldStaticObjectArray; // can assign e.g. String[] 00088 public static long[] fieldStaticLongArray; // cannot assign e.g. int[] 00089 // 00090 public static long fac(long n) { // complements jpl:jpl_test_fac(+integer,-integer) 00091 if (n == 1) { 00092 return 1; 00093 } else if (n > 1) { 00094 // return n * ((Integer) new Query(new Compound("jpl_test_fac", new Term[] { new Integer(n - 1), new Variable("F") })).oneSolution().get("F")).intValue(); 00095 return n * ((jpl.Integer) Query.oneSolution("jpl_test_fac(?,F)", new Term[] {new jpl.Integer(n-1)}).get("F")).longValue(); 00096 } else { 00097 return 0; 00098 } 00099 } 00100 static void packageMethod() { // not callable via JPL 00101 return; 00102 } 00103 public static void publicMethod() { 00104 return; 00105 } 00106 protected static void protectedMethod() { // not callable via JPL 00107 return; 00108 } 00109 private static void privateMethod() { // not callable via JPL 00110 return; 00111 } 00112 public boolean fieldInstanceBoolean; 00113 public final boolean fieldInstanceBoolean1 = false; 00114 public final boolean fieldInstanceBoolean2 = true; 00115 public byte fieldInstanceByte; 00116 public final byte fieldInstanceByte1 = -(1 << 7); 00117 public final byte fieldInstanceByte2 = -1; 00118 public final byte fieldInstanceByte3 = 0; 00119 public final byte fieldInstanceByte4 = 1; 00120 public final byte fieldInstanceByte5 = (1 << 7) - 1; 00121 public char fieldInstanceChar; 00122 public final char fieldInstanceChar1 = '\u0000'; 00123 public final char fieldInstanceChar2 = '\uFFFF'; 00124 public double fieldInstanceDouble; 00125 public final double fieldInstanceDouble1 = 12345.6789D; 00126 public final double fieldInstanceDouble2 = 2.3456789e+100D; 00127 public final double fieldInstanceDouble3 = 3.456789e-100D; 00128 public final double fieldInstanceDouble4 = 0.0D; 00129 public final double fieldInstanceDouble5 = Double.MIN_VALUE; 00130 public final double fieldInstanceDouble6 = Double.MAX_VALUE; 00131 public final double fieldInstanceDouble7 = Double.NEGATIVE_INFINITY; 00132 public final double fieldInstanceDouble8 = Double.POSITIVE_INFINITY; 00133 public final double fieldInstanceDouble9 = Double.NaN; 00134 public float fieldInstanceFloat; 00135 public final float fieldInstanceFloat1 = 12345.6789F; 00136 public final float fieldInstanceFloat2 = 3.4e+38F; 00137 public final float fieldInstanceFloat3 = 1.4e-45F; 00138 public final float fieldInstanceFloat4 = 0.0F; 00139 public final float fieldInstanceFloat5 = java.lang.Float.MIN_VALUE; 00140 public final float fieldInstanceFloat6 = java.lang.Float.MAX_VALUE; 00141 public final float fieldInstanceFloat7 = java.lang.Float.NEGATIVE_INFINITY; 00142 public final float fieldInstanceFloat8 = java.lang.Float.POSITIVE_INFINITY; 00143 public final float fieldInstanceFloat9 = java.lang.Float.NaN; 00144 public int fieldInstanceInt; 00145 public final int fieldInstanceInt1 = -(1 << 31); 00146 public final int fieldInstanceInt2 = -(1 << 15); 00147 public final int fieldInstanceInt3 = -(1 << 7); 00148 public final int fieldInstanceInt4 = -1; 00149 public final int fieldInstanceInt5 = 0; 00150 public final int fieldInstanceInt6 = 1; 00151 public final int fieldInstanceInt7 = (1 << 7) - 1; 00152 public final int fieldInstanceInt8 = (1 << 15) - 1; 00153 public final int fieldInstanceInt9 = (1 << 31) - 1; 00154 public long fieldInstanceLong; 00155 public final long fieldInstanceLong1 = -(1 << 63); 00156 public final long fieldInstanceLong10 = (1 << 31) - 1; 00157 public final long fieldInstanceLong11 = (1 << 63) - 1; 00158 public final long fieldInstanceLong2 = -(1 << 31); 00159 public final long fieldInstanceLong3 = -(1 << 15); 00160 public final long fieldInstanceLong4 = -(1 << 7); 00161 public final long fieldInstanceLong5 = -1; 00162 public final long fieldInstanceLong6 = 0; 00163 public final long fieldInstanceLong7 = 1; 00164 public final long fieldInstanceLong8 = (1 << 7) - 1; 00165 public final long fieldInstanceLong9 = (1 << 15) - 1; 00166 public short fieldInstanceShort; 00167 public final short fieldInstanceShort1 = -(1 << 15); 00168 public final short fieldInstanceShort2 = -(1 << 7); 00169 public final short fieldInstanceShort3 = -1; 00170 public final short fieldInstanceShort4 = 0; 00171 public final short fieldInstanceShort5 = 1; 00172 public final short fieldInstanceShort6 = (1 << 7) - 1; 00173 public final short fieldInstanceShort7 = (1 << 15) - 1; 00174 // 00175 public Term term; // obsolete 00176 public static Term staticTerm; 00177 public Term instanceTerm; 00178 // 00179 // for testing accessibility of non-public fields: 00180 static boolean fieldPackageStaticBoolean; 00181 protected static boolean fieldProtectedStaticBoolean; 00182 private static boolean fieldPrivateStaticBoolean; 00183 // 00184 // for testing update of final field: 00185 public static final int fieldStaticFinalInt = 7; 00186 // 00187 // for testing passing general terms in from Prolog: 00188 public static Term fieldStaticTerm; 00189 public Term fieldInstanceTerm; 00190 public static boolean methodStaticTerm(Term t) { 00191 return t != null; 00192 } 00193 public boolean methodInstanceTerm(Term t) { 00194 return t != null; 00195 } 00196 public static Term methodStaticEchoTerm(Term t) { 00197 return t; 00198 } 00199 public static boolean methodStaticEchoBoolean(boolean v) { 00200 return v; 00201 } 00202 public static char methodStaticEchoChar(char v) { 00203 return v; 00204 } 00205 public static byte methodStaticEchoByte(byte v) { 00206 return v; 00207 } 00208 public static short methodStaticEchoShort(short v) { 00209 return v; 00210 } 00211 public static int methodStaticEchoInt(int v) { 00212 return v; 00213 } 00214 public static long methodStaticEchoLong(long v) { 00215 return v; 00216 } 00217 public static float methodStaticEchoFloat(float v) { 00218 return v; 00219 } 00220 public static double methodStaticEchoDouble(double v) { 00221 return v; 00222 } 00223 public Term methodInstanceTermEcho(Term t) { 00224 return t; 00225 } 00226 public static boolean methodStaticTermIsJNull(Term t) { 00227 return t.hasFunctor("@", 1) && t.arg(1).hasFunctor("null", 0); 00228 } 00229 public boolean methodInstanceTermIsJNull(Term t) { 00230 return t.hasFunctor("@", 1) && t.arg(1).hasFunctor("null", 0); 00231 } 00232 public static void hello() { 00233 System.out.println("hello"); 00234 } 00235 public static boolean[] newArrayBooleanFromValue(boolean v) { 00236 boolean[] a = new boolean[1]; 00237 a[0] = v; 00238 return a; 00239 } 00240 public static byte[] newArrayByteFromValue(byte v) { 00241 byte[] a = new byte[1]; 00242 a[0] = v; 00243 return a; 00244 } 00245 public static char[] newArrayCharFromValue(char v) { 00246 char[] a = new char[1]; 00247 a[0] = v; 00248 return a; 00249 } 00250 public static short[] newArrayShortFromValue(short v) { 00251 short[] a = new short[1]; 00252 a[0] = v; 00253 return a; 00254 } 00255 public static int[] newArrayIntFromValue(int v) { 00256 int[] a = new int[1]; 00257 a[0] = v; 00258 return a; 00259 } 00260 public static long[] newArrayLongFromValue(long v) { 00261 long[] a = new long[1]; 00262 a[0] = v; 00263 return a; 00264 } 00265 public static float[] newArrayFloatFromValue(float v) { 00266 float[] a = new float[1]; 00267 a[0] = v; 00268 return a; 00269 } 00270 public static double[] newArrayDoubleFromValue(double v) { 00271 double[] a = new double[1]; 00272 a[0] = v; 00273 return a; 00274 } 00275 public static String methodStaticArray(long[] a) { 00276 return "long[]"; 00277 } 00278 public static String methodStaticArray(int[] a) { 00279 return "int[]"; 00280 } 00281 public static String methodStaticArray(short[] a) { 00282 return "short[]"; 00283 } 00284 public static Term wrapTerm(Term in) { // for dmiles 11/Jul/2008 00285 return new Compound("javaWrap", new Term[] {in}); 00286 } 00287 }