From 3705f9d9adaca497801c532d3f3087041f5504b4 Mon Sep 17 00:00:00 2001 From: Mark Donszelmann Date: Sat, 3 Oct 2009 20:55:35 +0200 Subject: Added test 5 --- src/it/it0003-jni/pom.xml | 1 + src/it/it0005-jni-static/pom.xml | 72 ++++++++++++++++++++++ .../src/main/c/HelloWorldStaticJNI.c | 16 +++++ .../mycompany/mypackage/HelloWorldStaticJNI.java | 15 +++++ .../src/test/java/HelloWorldStaticJNITest.java | 25 ++++++++ 5 files changed, 129 insertions(+) create mode 100644 src/it/it0005-jni-static/pom.xml create mode 100644 src/it/it0005-jni-static/src/main/c/HelloWorldStaticJNI.c create mode 100644 src/it/it0005-jni-static/src/main/java/com/mycompany/mypackage/HelloWorldStaticJNI.java create mode 100644 src/it/it0005-jni-static/src/test/java/HelloWorldStaticJNITest.java (limited to 'src') diff --git a/src/it/it0003-jni/pom.xml b/src/it/it0003-jni/pom.xml index 8c1881b..eaf71c6 100644 --- a/src/it/it0003-jni/pom.xml +++ b/src/it/it0003-jni/pom.xml @@ -43,6 +43,7 @@ under the License. true --> + integration-test diff --git a/src/it/it0005-jni-static/pom.xml b/src/it/it0005-jni-static/pom.xml new file mode 100644 index 0000000..97f51e5 --- /dev/null +++ b/src/it/it0005-jni-static/pom.xml @@ -0,0 +1,72 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.nar + it-parent + 1.0-SNAPSHOT + ../it-parent/pom.xml + + + it0005-jni-static + nar + + Maven NAR Static JNI Test + 1.0-SNAPSHOT + + Simple Static JNI Library + + http://maven.apache.org/ + + + + integration-test + + + maven-nar-plugin + true + + static + + + jni + com.mycompany.mypackage + false + + + + + + maven-surefire-plugin + + true + + + + + diff --git a/src/it/it0005-jni-static/src/main/c/HelloWorldStaticJNI.c b/src/it/it0005-jni-static/src/main/c/HelloWorldStaticJNI.c new file mode 100644 index 0000000..62b181b --- /dev/null +++ b/src/it/it0005-jni-static/src/main/c/HelloWorldStaticJNI.c @@ -0,0 +1,16 @@ +#include +#include "com_mycompany_mypackage_HelloWorldStaticJNI.h" + +JNIEXPORT jstring JNICALL Java_com_mycompany_mypackage_HelloWorldStaticJNI_sayHello( JNIEnv *env, jobject obj ) { + jstring value; /* the return value */ + + char buf[40]; /* working buffer (really only need 20 ) */ + + + sprintf ( buf, "%s", "Hello Static NAR World!" ); + + value = (*env)->NewStringUTF( env, buf ); + + return value; +} + diff --git a/src/it/it0005-jni-static/src/main/java/com/mycompany/mypackage/HelloWorldStaticJNI.java b/src/it/it0005-jni-static/src/main/java/com/mycompany/mypackage/HelloWorldStaticJNI.java new file mode 100644 index 0000000..f08de6a --- /dev/null +++ b/src/it/it0005-jni-static/src/main/java/com/mycompany/mypackage/HelloWorldStaticJNI.java @@ -0,0 +1,15 @@ +package com.mycompany.mypackage; + +public class HelloWorldStaticJNI { + static { + NarSystem.loadLibrary(); + } + + public native String sayHello(); + + public static void main( String[] args ) { + HelloWorldStaticJNI app = new HelloWorldStaticJNI(); + System.out.println( app.sayHello() ); + } +} + diff --git a/src/it/it0005-jni-static/src/test/java/HelloWorldStaticJNITest.java b/src/it/it0005-jni-static/src/test/java/HelloWorldStaticJNITest.java new file mode 100644 index 0000000..c647f95 --- /dev/null +++ b/src/it/it0005-jni-static/src/test/java/HelloWorldStaticJNITest.java @@ -0,0 +1,25 @@ +import junit.framework.*; + +import com.mycompany.mypackage.HelloWorldStaticJNI; + +public class HelloWorldStaticJNITest extends TestCase { + + public HelloWorldStaticJNITest(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testNativeHelloWorldJNI() throws Exception { + HelloWorldStaticJNI app = new HelloWorldStaticJNI(); + + this.assertEquals( "Hello Static NAR World!", app.sayHello() ); + } +} + -- cgit v1.2.3