From b6e59ef1d0162f6ddacd8e675fd059cd306f62fe Mon Sep 17 00:00:00 2001 From: Mark Donszelmann Date: Mon, 5 Oct 2009 15:31:30 +0200 Subject: Added it0009-jni-dep-lib-shared test --- .../jni-dep-lib-shared/pom.xml | 72 +++++++++++++++++++++ .../src/main/c/HelloWorldSharedLibJNI.c | 17 +++++ .../mypackage/HelloWorldSharedLibJNI.java | 15 +++++ .../src/test/java/HelloWorldSharedLibJNITest.java | 25 ++++++++ .../it0009-jni-dep-lib-shared/lib-shared/pom.xml | 74 ++++++++++++++++++++++ .../lib-shared/src/main/c/HelloWorldLib.c | 7 ++ .../lib-shared/src/main/include/HelloWorldLib.h | 9 +++ .../lib-shared/src/test/c/HelloWorldTest.c | 9 +++ src/it/it0009-jni-dep-lib-shared/pom.xml | 49 ++++++++++++++ 9 files changed, 277 insertions(+) create mode 100644 src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/pom.xml create mode 100644 src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/src/main/c/HelloWorldSharedLibJNI.c create mode 100644 src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/src/main/java/com/mycompany/mypackage/HelloWorldSharedLibJNI.java create mode 100644 src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/src/test/java/HelloWorldSharedLibJNITest.java create mode 100644 src/it/it0009-jni-dep-lib-shared/lib-shared/pom.xml create mode 100644 src/it/it0009-jni-dep-lib-shared/lib-shared/src/main/c/HelloWorldLib.c create mode 100644 src/it/it0009-jni-dep-lib-shared/lib-shared/src/main/include/HelloWorldLib.h create mode 100644 src/it/it0009-jni-dep-lib-shared/lib-shared/src/test/c/HelloWorldTest.c create mode 100644 src/it/it0009-jni-dep-lib-shared/pom.xml (limited to 'src/it') diff --git a/src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/pom.xml b/src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/pom.xml new file mode 100644 index 0000000..45d3487 --- /dev/null +++ b/src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/pom.xml @@ -0,0 +1,72 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.nar + it0009-pom + 1.0-SNAPSHOT + + + it0009-jni-dep-lib-shared + nar + + Maven NAR JNI + 1.0-SNAPSHOT + + JNI + + + + integration-test + + + maven-nar-plugin + true + + + + jni + com.mycompany.mypackage + false + + + + + + maven-surefire-plugin + + true + + + + + + + + org.apache.maven.its.nar + it0009-lib-shared + 1.0-SNAPSHOT + + + diff --git a/src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/src/main/c/HelloWorldSharedLibJNI.c b/src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/src/main/c/HelloWorldSharedLibJNI.c new file mode 100644 index 0000000..e5b8e4b --- /dev/null +++ b/src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/src/main/c/HelloWorldSharedLibJNI.c @@ -0,0 +1,17 @@ +#include +#include "HelloWorldLib.h" + +#include "com_mycompany_mypackage_HelloWorldSharedLibJNI.h" + +JNIEXPORT jstring JNICALL Java_com_mycompany_mypackage_HelloWorldSharedLibJNI_sayHello( JNIEnv *env, jobject obj ) { + jstring value; /* the return value */ + + char buf[80]; /* working buffer (really only need 20 ) */ + + sprintf ( buf, "%s", HelloWorldLib_sayHello()); + + value = (*env)->NewStringUTF( env, buf ); + + return value; +} + diff --git a/src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/src/main/java/com/mycompany/mypackage/HelloWorldSharedLibJNI.java b/src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/src/main/java/com/mycompany/mypackage/HelloWorldSharedLibJNI.java new file mode 100644 index 0000000..a0ef934 --- /dev/null +++ b/src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/src/main/java/com/mycompany/mypackage/HelloWorldSharedLibJNI.java @@ -0,0 +1,15 @@ +package com.mycompany.mypackage; + +public class HelloWorldSharedLibJNI { + static { + NarSystem.loadLibrary(); + } + + public native String sayHello(); + + public static void main( String[] args ) { + HelloWorldSharedLibJNI app = new HelloWorldSharedLibJNI(); + System.out.println( app.sayHello() ); + } +} + diff --git a/src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/src/test/java/HelloWorldSharedLibJNITest.java b/src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/src/test/java/HelloWorldSharedLibJNITest.java new file mode 100644 index 0000000..f263997 --- /dev/null +++ b/src/it/it0009-jni-dep-lib-shared/jni-dep-lib-shared/src/test/java/HelloWorldSharedLibJNITest.java @@ -0,0 +1,25 @@ +import junit.framework.*; + +import com.mycompany.mypackage.HelloWorldSharedLibJNI; + +public class HelloWorldSharedLibJNITest extends TestCase { + + public HelloWorldSharedLibJNITest(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testNativeHelloWorldSharedLibJNI() throws Exception { + HelloWorldSharedLibJNI app = new HelloWorldSharedLibJNI(); + + this.assertEquals( "Hello NAR LIB World!", app.sayHello() ); + } +} + diff --git a/src/it/it0009-jni-dep-lib-shared/lib-shared/pom.xml b/src/it/it0009-jni-dep-lib-shared/lib-shared/pom.xml new file mode 100644 index 0000000..b29f03a --- /dev/null +++ b/src/it/it0009-jni-dep-lib-shared/lib-shared/pom.xml @@ -0,0 +1,74 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.nar + it0009-pom + 1.0-SNAPSHOT + + + it0009-lib-shared + nar + + Maven NAR Shared Library + 1.0-SNAPSHOT + + Simple shared library and test file + + http://maven.apache.org/ + + + + install + + + maven-nar-plugin + true + + + + shared + + + + + HelloWorldTest + shared + + + + + + maven-surefire-plugin + + true + + + + + diff --git a/src/it/it0009-jni-dep-lib-shared/lib-shared/src/main/c/HelloWorldLib.c b/src/it/it0009-jni-dep-lib-shared/lib-shared/src/main/c/HelloWorldLib.c new file mode 100644 index 0000000..9f65143 --- /dev/null +++ b/src/it/it0009-jni-dep-lib-shared/lib-shared/src/main/c/HelloWorldLib.c @@ -0,0 +1,7 @@ +#include +#include "HelloWorldLib.h" + +char* HelloWorldLib_sayHello() { + return "Hello NAR LIB World!"; +} + diff --git a/src/it/it0009-jni-dep-lib-shared/lib-shared/src/main/include/HelloWorldLib.h b/src/it/it0009-jni-dep-lib-shared/lib-shared/src/main/include/HelloWorldLib.h new file mode 100644 index 0000000..e801bec --- /dev/null +++ b/src/it/it0009-jni-dep-lib-shared/lib-shared/src/main/include/HelloWorldLib.h @@ -0,0 +1,9 @@ +#ifndef HelloWorldLib_H +#define HelloWorldLib_H + +#ifdef WIN32 +__declspec(dllexport) +#endif +extern char* HelloWorldLib_sayHello(); + +#endif diff --git a/src/it/it0009-jni-dep-lib-shared/lib-shared/src/test/c/HelloWorldTest.c b/src/it/it0009-jni-dep-lib-shared/lib-shared/src/test/c/HelloWorldTest.c new file mode 100644 index 0000000..4aa35d8 --- /dev/null +++ b/src/it/it0009-jni-dep-lib-shared/lib-shared/src/test/c/HelloWorldTest.c @@ -0,0 +1,9 @@ +#include +#include "HelloWorldLib.h" + +int main(int argc, char *argv[]) { + printf("%s\n", HelloWorldLib_sayHello()); + return 0; +} + + diff --git a/src/it/it0009-jni-dep-lib-shared/pom.xml b/src/it/it0009-jni-dep-lib-shared/pom.xml new file mode 100644 index 0000000..f6719de --- /dev/null +++ b/src/it/it0009-jni-dep-lib-shared/pom.xml @@ -0,0 +1,49 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.nar + it-parent + 1.0-SNAPSHOT + ../it-parent/pom.xml + + + it0009-pom + pom + + Maven NAR JNI and Shared Library + 1.0-SNAPSHOT + + JNI depending on a shared library. + + + + install + + + + jni-dep-lib-shared + lib-shared + + -- cgit v1.2.3