[llvm-commits] CVS: llvm-java/test/Programs/SingleSource/UnitTests/test.c Test.java

Alkis Evlogimenos alkis at cs.uiuc.edu
Thu Apr 21 01:27:40 PDT 2005



Changes in directory llvm-java/test/Programs/SingleSource/UnitTests:

test.c updated: 1.6 -> 1.7
Test.java updated: 1.9 -> 1.10
---
Log message:

Add instance and static methods to test calling Java methods through JNI.


---
Diffs of the changes:  (+129 -1)

 Test.java |   30 +++++++++++++++++-
 test.c    |  100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 129 insertions(+), 1 deletion(-)


Index: llvm-java/test/Programs/SingleSource/UnitTests/test.c
diff -u llvm-java/test/Programs/SingleSource/UnitTests/test.c:1.6 llvm-java/test/Programs/SingleSource/UnitTests/test.c:1.7
--- llvm-java/test/Programs/SingleSource/UnitTests/test.c:1.6	Sat Apr  2 20:05:33 2005
+++ llvm-java/test/Programs/SingleSource/UnitTests/test.c	Thu Apr 21 03:27:28 2005
@@ -138,3 +138,103 @@
   b = (*env)->GetStaticByteField(env, clazz, id);
   Java_Test_println__I(env, clazz, b);
 }
+
+void Java_Test_printMethods(JNIEnv *env, jobject obj)
+{
+  jclass classTest;
+  jclass objClass;
+  jfieldID id;
+  jboolean z;
+  jint i;
+  jlong l;
+  jfloat f;
+  jdouble d;
+  jshort s;
+  jbyte b;
+
+  classTest = (*env)->FindClass(env, "Test");
+  if (!classTest)
+    printf("ERROR: Class Test not found!\n");
+
+  if (!(*env)->IsInstanceOf(env, obj, classTest))
+    printf("ERROR: IsInstanceOf\n");
+  objClass = (*env)->GetObjectClass(env, obj);
+  if (!(*env)->IsAssignableFrom(env, objClass, classTest))
+    printf("ERROR: IsAssignableFrom\n");
+
+  id = (*env)->GetMethodID(env, objClass, "z", "()Z");
+  z = (*env)->CallBooleanMethod(env, obj, id);
+  Java_Test_println__Z(env, objClass, z);
+
+  id = (*env)->GetMethodID(env, objClass, "i", "(I)I");
+  i = (*env)->CallIntMethod(env, obj, id, 2);
+  Java_Test_println__I(env, objClass, i);
+
+  id = (*env)->GetMethodID(env, objClass, "j", "(BS)J");
+  l = (*env)->CallLongMethod(env, obj, id, 23, 45);
+  Java_Test_println__J(env, objClass, l);
+
+  id = (*env)->GetMethodID(env, objClass, "f", "(B)F");
+  f = (*env)->CallFloatMethod(env, obj, id, 123);
+  Java_Test_println__F(env, objClass, f);
+
+  id = (*env)->GetMethodID(env, objClass, "d", "(IJ)D");
+  d = (*env)->CallDoubleMethod(env, obj, id, 654, 123ll);
+  Java_Test_println__D(env, objClass, d);
+
+  id = (*env)->GetMethodID(env, objClass, "s", "(DB)S");
+  s = (*env)->CallShortMethod(env, obj, id, 2.0, 123);
+  Java_Test_println__I(env, objClass, s);
+
+  id = (*env)->GetMethodID(env, objClass, "b", "(SF)B");
+  b = (*env)->CallByteMethod(env, obj, id, 23, -2.0);
+  Java_Test_println__I(env, objClass, b);
+}
+
+void Java_Test_printStaticMethods(JNIEnv *env, jobject clazz)
+{
+  jclass classTest;
+  jfieldID id;
+  jboolean z;
+  jint i;
+  jlong l;
+  jfloat f;
+  jdouble d;
+  jshort s;
+  jbyte b;
+
+  classTest = (*env)->FindClass(env, "Test");
+  if (!classTest)
+    printf("ERROR: Class Test not found!\n");
+
+  if (!(*env)->IsAssignableFrom(env, clazz, classTest))
+    printf("ERROR: IsAssignableFrom\n");
+
+  id = (*env)->GetStaticMethodID(env, clazz, "Z", "()Z");
+  z = (*env)->CallStaticBooleanMethod(env, clazz, id);
+  Java_Test_println__Z(env, clazz, z);
+
+  id = (*env)->GetStaticMethodID(env, clazz, "I", "(I)I");
+  i = (*env)->CallStaticIntMethod(env, clazz, id, 2);
+  Java_Test_println__I(env, clazz, i);
+
+  id = (*env)->GetStaticMethodID(env, clazz, "J", "(BS)J");
+  l = (*env)->CallStaticLongMethod(env, clazz, id, 23, 45);
+  Java_Test_println__J(env, clazz, l);
+
+  id = (*env)->GetStaticMethodID(env, clazz, "F", "(B)F");
+  f = (*env)->CallStaticFloatMethod(env, clazz, id, 123);
+  Java_Test_println__F(env, clazz, f);
+
+  id = (*env)->GetStaticMethodID(env, clazz, "D", "(IJ)D");
+  d = (*env)->CallStaticDoubleMethod(env, clazz, id, 654, 12354123ll);
+  Java_Test_println__D(env, clazz, d);
+
+  id = (*env)->GetStaticMethodID(env, clazz, "S", "(DB)S");
+  s = (*env)->CallStaticShortMethod(env, clazz, id, 2.0, 123);
+  Java_Test_println__I(env, clazz, s);
+
+  id = (*env)->GetStaticMethodID(env, clazz, "B", "(SF)B");
+  b = (*env)->CallStaticByteMethod(env, clazz, id, 21, -58.0);
+  Java_Test_println__I(env, clazz, b);
+}


Index: llvm-java/test/Programs/SingleSource/UnitTests/Test.java
diff -u llvm-java/test/Programs/SingleSource/UnitTests/Test.java:1.9 llvm-java/test/Programs/SingleSource/UnitTests/Test.java:1.10
--- llvm-java/test/Programs/SingleSource/UnitTests/Test.java:1.9	Sat Apr  2 20:05:33 2005
+++ llvm-java/test/Programs/SingleSource/UnitTests/Test.java	Thu Apr 21 03:27:28 2005
@@ -1,5 +1,6 @@
 public class Test
 {
+    // Fields to test JNI getFieldID and get<TYPE>Field functions.
     public boolean z = false;
     public int i = 123;
     public long l = 1234567890123456789L;
@@ -8,6 +9,7 @@
     public short s = 456;
     public byte b = 78;
 
+    // Fields to test JNI getStaticFieldID and getStatic<TYPE>Field functions.
     public static boolean Z = true;
     public static int I = 321;
     public static long L = 1234567890987654321L;
@@ -16,6 +18,25 @@
     public static short S = 654;
     public static byte B = 87;
 
+    // Methods to test JNI getMethodID and call<TYPE>Method functions.
+    public boolean z() { return z; }
+    public int i(int ii) { return i + ii; }
+    public long j(byte bb, short ss) { return l + bb + ss; }
+    public float f(byte bb) { return f + bb; }
+    public double d(int ii, long ll) { return d + ii + ll; }
+    public short s(double dd, byte bb) { return (short) (s + dd + bb); }
+    public byte b(short ss, float ff) { return (byte)(B + ff + ss); }
+
+    // Methods to test JNI getStaticMethodID and
+    // callStatic<TYPE>Method functions.
+    public static boolean Z() { return Z; }
+    public static int I(int jj) { return I + jj; }
+    public static long J(byte bb, short ss) { return L + bb + ss; }
+    public static float F(byte bb) { return F + bb; }
+    public static double D(int ii, long ll) { return D + ii + ll; }
+    public static short S(double dd, byte bb) { return (short) (S + dd + bb); }
+    public static byte B(short ss, float ff) { return (byte)(B + ff + ss); }
+
     static {
         System.loadLibrary("test");
     }
@@ -37,6 +58,8 @@
 
     public native void printFields();
     public static native void printStaticFields();
+    public native void printMethods();
+    public static native void printStaticMethods();
 
     public static void main(String[] args) {
         println(true);
@@ -51,8 +74,13 @@
         println(-753.46);
         println(new byte[] { 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd' });
         println("Hello world");
-
+        println("Printing static fields:");
         printStaticFields();
+        println("Printing member fields:");
         new Test().printFields();
+        println("Calling static methods:");
+        printStaticMethods();
+        println("Calling member methods:");
+        new Test().printMethods();
     }
 }






More information about the llvm-commits mailing list