summaryrefslogtreecommitdiff
path: root/test/files/jvm
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-06-11 12:09:35 +0000
committermichelou <michelou@epfl.ch>2007-06-11 12:09:35 +0000
commitd2d5fb166c5c7294b0459732b3fa3815b8d82fda (patch)
tree04ed62066f0f8a45568f0f0b18762596a3ddd94e /test/files/jvm
parent908decebd0f890068221ff586ebd7b3492f37c0f (diff)
downloadscala-d2d5fb166c5c7294b0459732b3fa3815b8d82fda.tar.gz
scala-d2d5fb166c5c7294b0459732b3fa3815b8d82fda.tar.bz2
scala-d2d5fb166c5c7294b0459732b3fa3815b8d82fda.zip
added test for @native attribute
Diffstat (limited to 'test/files/jvm')
-rwxr-xr-xtest/files/jvm/libnatives.sobin0 -> 5359 bytes
-rwxr-xr-xtest/files/jvm/mkLibNatives.sh23
-rw-r--r--test/files/jvm/natives.c8
-rw-r--r--test/files/jvm/natives.check1
-rw-r--r--test/files/jvm/natives.h21
-rw-r--r--test/files/jvm/natives.scala12
6 files changed, 65 insertions, 0 deletions
diff --git a/test/files/jvm/libnatives.so b/test/files/jvm/libnatives.so
new file mode 100755
index 0000000000..ccbcdd646f
--- /dev/null
+++ b/test/files/jvm/libnatives.so
Binary files differ
diff --git a/test/files/jvm/mkLibNatives.sh b/test/files/jvm/mkLibNatives.sh
new file mode 100755
index 0000000000..9d4ded597f
--- /dev/null
+++ b/test/files/jvm/mkLibNatives.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+CLASS_NAME=Test\$
+CLASS_DIR=natives-jvm
+
+OBJ_NAME=natives
+LIB_NAME=libnatives
+
+JAVAH=javah
+JAVAH_OPTIONS="-jni -force -classpath ${CLASS_DIR} -o ${OBJ_NAME}.h"
+
+CC=gcc
+CC_OPTIONS=-c
+CC_INCLUDES="-I${JAVA_HOME}/include -I${JAVA_HOME}/include/${OSTYPE}"
+
+#echo ${JAVAH} ${JAVAH_OPTIONS} ${CLASS_NAME}
+#${JAVAH} ${JAVAH_OPTIONS} ${CLASS_NAME}
+
+#echo ${CC} ${CC_OPTIONS} ${CC_INCLUDES} -o ${OBJ_NAME}.o natives.c
+${CC} ${CC_OPTIONS} ${CC_INCLUDES} -o ${OBJ_NAME}.o natives.c
+
+#echo ${CC} -shared -Wl,-soname,${LIB_NAME} -o ${LIB_NAME}.so ${OBJ_NAME}.o
+${CC} -shared -Wl,-soname,${LIB_NAME} -o ${LIB_NAME}.so ${OBJ_NAME}.o
diff --git a/test/files/jvm/natives.c b/test/files/jvm/natives.c
new file mode 100644
index 0000000000..7b6d7b5ba5
--- /dev/null
+++ b/test/files/jvm/natives.c
@@ -0,0 +1,8 @@
+#include "natives.h"
+
+JNIEXPORT jstring JNICALL Java_Test_00024_sayHello
+ (JNIEnv *env, jobject thisobject, jstring js)
+
+{
+ return js;
+}
diff --git a/test/files/jvm/natives.check b/test/files/jvm/natives.check
new file mode 100644
index 0000000000..2265459198
--- /dev/null
+++ b/test/files/jvm/natives.check
@@ -0,0 +1 @@
+Invocation returned "Scala is great!"
diff --git a/test/files/jvm/natives.h b/test/files/jvm/natives.h
new file mode 100644
index 0000000000..0d360d3654
--- /dev/null
+++ b/test/files/jvm/natives.h
@@ -0,0 +1,21 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class Test__ */
+
+#ifndef _Included_Test__
+#define _Included_Test__
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: Test__
+ * Method: sayHello
+ * Signature: (Ljava/lang/String;)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_Test_00024_sayHello
+ (JNIEnv *, jobject, jstring);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/test/files/jvm/natives.scala b/test/files/jvm/natives.scala
new file mode 100644
index 0000000000..d3cb24a9d9
--- /dev/null
+++ b/test/files/jvm/natives.scala
@@ -0,0 +1,12 @@
+object Test {
+ //println("java.library.path=" + System.getProperty("java.library.path"))
+ System.loadLibrary("natives")
+
+ @native
+ def sayHello(s: String): String = null
+
+ def main(args: Array[String]) {
+ val s = sayHello("Scala is great!")
+ println("Invocation returned \"" + s + "\"")
+ }
+}