This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: new JNI test
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 14 Dec 2001 15:02:48 -0700
- Subject: Patch: FYI: new JNI test
- Reply-to: tromey at redhat dot com
I'm checking this in.
This adds a new JNI test written in C++. This lets us test that our
<jni.h> is suitable for use from C++. Right now it isn't; see PR 5103.
(I have a patch for jni.h, too, but I'm still testing it.)
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
For PR libgcj/5103:
* libjava.jni/cxxtest.out: New file.
* libjava.jni/cxxtest.cc: New file.
* libjava.jni/cxxtest.java: New file.
* libjava.jni/jni.exp (gcj_jni_test_one): If there is no .c file,
assume there is a .cc file.
Index: libjava.jni/cxxtest.cc
===================================================================
RCS file: cxxtest.cc
diff -N cxxtest.cc
--- /dev/null Tue May 5 13:32:27 1998
+++ libjava.jni/cxxtest.cc Fri Dec 14 13:53:31 2001
@@ -0,0 +1,24 @@
+#include <jni.h>
+#include <cxxtest.h>
+
+jobjectArray
+Java_cxxtest_fetch (JNIEnv *env, jobject _this)
+{
+ jclass cls;
+ jfieldID fid;
+ jobjectArray obj;
+
+ cls = env->GetObjectClass (_this);
+ if (! cls)
+ return 0;
+
+ fid = env->GetFieldID (cls, "F", "[Ljava/lang/Object;");
+ if (! fid)
+ return 0;
+
+ obj = reinterpret_cast<jobjectArray> (env->GetObjectField (_this, fid));
+
+ return obj;
+}
+
+
Index: libjava.jni/cxxtest.java
===================================================================
RCS file: cxxtest.java
diff -N cxxtest.java
--- /dev/null Tue May 5 13:32:27 1998
+++ libjava.jni/cxxtest.java Fri Dec 14 13:53:31 2001
@@ -0,0 +1,25 @@
+// Test for array field lookup.
+
+public class cxxtest
+{
+ // A field for us to look up.
+ public Object[] F = new Object[7];
+
+ public native Object[] fetch ();
+
+ public void doit ()
+ {
+ System.out.println (F == fetch ());
+ }
+
+ public static void main (String[] args)
+ {
+ cxxtest q = new cxxtest ();
+ q.doit ();
+ }
+
+ static
+ {
+ System.loadLibrary ("cxxtest");
+ }
+}
Index: libjava.jni/cxxtest.out
===================================================================
RCS file: cxxtest.out
diff -N cxxtest.out
--- /dev/null Tue May 5 13:32:27 1998
+++ libjava.jni/cxxtest.out Fri Dec 14 13:53:31 2001
@@ -0,0 +1 @@
+true
Index: libjava.jni/jni.exp
===================================================================
RCS file: /cvs/gcc/gcc/libjava/testsuite/libjava.jni/jni.exp,v
retrieving revision 1.2
diff -u -r1.2 jni.exp
--- libjava.jni/jni.exp 2001/06/25 04:48:55 1.2
+++ libjava.jni/jni.exp 2001/12/14 21:53:31
@@ -106,6 +106,13 @@
}
set cfile [file rootname $file].c
+ set cxxflags ""
+ # If there is no `.c' file, assume there is a `.cc' file.
+ if {! [file exists $cfile]} {
+ set cfile [file rootname $file].cc
+ set cxxflags "-lstdc++"
+ }
+
if {! [gcj_jni_compile_c_to_so $cfile]} {
# FIXME
return 0
@@ -113,7 +120,7 @@
# We use -l$main because the .so is named the same as the main
# program.
- set args [list "additional_flags=-fjni -L. -l$main"]
+ set args [list "additional_flags=-fjni -L. -l$main $cxxflags"]
if {! [gcj_link $main $main $file $args]} {
# FIXME
return 0