- Reorganization of the build script to make it more portable
- Removed the conditional code that decided whether to use JVM for unit tests or not - Changed the unit test code so the test code is now imported by using the DLL function - Introduced mechanisms to concentrate the loading of classes to specific methods instead of putting them into another function git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@301 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
@@ -32,6 +32,8 @@
|
||||
|
||||
#ifdef DO_UNIT_TEST
|
||||
# include <test/CuTest.h>
|
||||
|
||||
# define TEST_CASE(name) static void name(CuTest *tc)
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
@@ -77,6 +79,8 @@ static void LIBUSB_CALL fd_removed_callback(int fd, void *user_data);
|
||||
* Local helper functions
|
||||
*
|
||||
*******************************************************************************************/
|
||||
static __inline int ReferencesLoad(JNIEnv *env);
|
||||
static __inline void ReferencesUnload(JNIEnv *env);
|
||||
static __inline jbyteArray JNICALL to_byteArray(JNIEnv *env, const void *data, size_t len);
|
||||
static __inline void JNICALL ThrowIfUnsuccessful(JNIEnv *env, int libusb_result);
|
||||
static __inline void JNICALL ThrowLibusbError(JNIEnv *env, jint code);
|
||||
@@ -134,16 +138,105 @@ static jfieldID usb_epDescFID_bLength, usb_epDescFID_bDescriptorType,
|
||||
static jfieldID usb_pollfdFID_fd, usb_pollfdFID_events;
|
||||
|
||||
#ifdef DO_UNIT_TEST
|
||||
#if TEST_USING_JVM
|
||||
static struct TestContext
|
||||
{
|
||||
JNIEnv *env;
|
||||
}test_context = { NULL };
|
||||
static struct TestContext
|
||||
{
|
||||
JNIEnv *env;
|
||||
}test_context = { NULL };
|
||||
|
||||
# define TEST_CONTEXT() JNIEnv *env = test_context.env
|
||||
#endif
|
||||
# define TEST_CONTEXT() JNIEnv *env = test_context.env
|
||||
#endif
|
||||
|
||||
/*! \brief Structure holding all the global information needed. */
|
||||
static struct {
|
||||
struct {
|
||||
int onLoadCalled;
|
||||
int refs_loaded;
|
||||
|
||||
struct {
|
||||
struct {
|
||||
jclass usb_devClazz;
|
||||
}Usb_Device;
|
||||
|
||||
struct {
|
||||
jclass usb_devDescClazz;
|
||||
}Usb_Device_Descriptor;
|
||||
|
||||
struct {
|
||||
jclass usb_confDescClazz;
|
||||
}Usb_Config_Descriptor;
|
||||
}objs;
|
||||
}jni;
|
||||
}info = { { 0 } };
|
||||
|
||||
/********************************************************************************************
|
||||
*
|
||||
* Library Events
|
||||
*
|
||||
*******************************************************************************************/
|
||||
|
||||
/*! \brief The VM calls JNI_OnLoad when the native library is loaded (for example, through
|
||||
* System.loadLibrary).
|
||||
*
|
||||
* \see http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/invocation.html#JNI_OnLoad
|
||||
*
|
||||
* \return The JNI version needed by the native library (use constants as JNI_VERSION_X_Y).
|
||||
*/
|
||||
jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||
{
|
||||
JNIEnv* env = NULL;
|
||||
|
||||
info.jni.onLoadCalled = -1;
|
||||
|
||||
if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_1) != JNI_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ReferencesLoad(env);
|
||||
|
||||
return JNI_VERSION_1_1;
|
||||
}
|
||||
|
||||
#if defined(DO_UNIT_TEST)
|
||||
TEST_CASE(JNI_OnLoad_test)
|
||||
{
|
||||
TEST_CONTEXT();
|
||||
|
||||
CuAssert(tc, "correct initialization", info.jni.onLoadCalled == 0);
|
||||
info.jni.onLoadCalled=10;
|
||||
|
||||
/* Load the LibusbJava1 class to force the initialization of the library */
|
||||
jclass clazz = env->FindClass("ch/ntb/inf/libusbJava/LibusbJava1");
|
||||
CuAssert(tc, "ch/ntb/inf/libusbJava/LibusbJava1 loaded", clazz != NULL);
|
||||
|
||||
CuAssert(tc, "JNI_OnLoad was executed", info.jni.onLoadCalled != 0);
|
||||
env->DeleteLocalRef(clazz);
|
||||
|
||||
/* As garbage collection is not necessarily run after freeing a reference
|
||||
* and there is no way to force the run of GC, we can't test this here. */
|
||||
// CuAssert(tc, "JNI_OnUnload was executed", info.jni.onLoadCalled == 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! \brief The VM calls JNI_OnUnload when the class loader containing the native library is
|
||||
* garbage collected.
|
||||
*
|
||||
* This function can be used to perform cleanup operations. Because this function is
|
||||
* called in an unknown context (such as from a finalizer), the programmer should be
|
||||
* conservative on using Java VM services, and refrain from arbitrary Java call-backs.
|
||||
*
|
||||
* \see http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/invocation.html#JNI_OnUnload
|
||||
*/
|
||||
void JNI_OnUnload(JavaVM *vm, void *reserved)
|
||||
{
|
||||
JNIEnv* env = NULL;
|
||||
|
||||
if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_1) == JNI_OK) {
|
||||
ReferencesUnload(env);
|
||||
}
|
||||
|
||||
info.jni.onLoadCalled = 0;
|
||||
}
|
||||
|
||||
/********************************************************************************************
|
||||
*
|
||||
* Methods
|
||||
@@ -182,10 +275,14 @@ JNIEXPORT jlong JNICALL Java_ch_ntb_inf_libusbJava_LibusbJava1_libusb_1init( JNI
|
||||
printf("context = %p\n", &context);
|
||||
#endif
|
||||
|
||||
if (!res) {
|
||||
if (res != 0)
|
||||
{
|
||||
ThrowLibusbError(env, res);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (jlong) context;
|
||||
} else {
|
||||
return (jlong) res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1828,6 +1925,26 @@ JNIEXPORT jstring JNICALL Java_ch_ntb_inf_libusbJava_LibusbJava1_libusb_1strerro
|
||||
return env->NewStringUTF(str);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: ch_ntb_inf_libusbJava_LibusbJava1
|
||||
* Method: setup
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_ch_ntb_inf_libusbJava_LibusbJava1_setup(JNIEnv *env, jclass obj)
|
||||
{
|
||||
return ReferencesLoad(env);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: ch_ntb_inf_libusbJava_LibusbJava1
|
||||
* Method: teardown
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_ch_ntb_inf_libusbJava_LibusbJava1_teardown(JNIEnv *env, jclass obj)
|
||||
{
|
||||
ReferencesUnload(env);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: ch_ntb_inf_libusbJava_LibusbJava1
|
||||
* Method: libusb_exceptionTest
|
||||
@@ -2001,36 +2118,67 @@ no_class:
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DO_UNIT_TEST
|
||||
# if TEST_USING_JVM
|
||||
static void JVMTest(CuTest *tc)
|
||||
{
|
||||
TEST_CONTEXT();
|
||||
/*! \brief Loads all class References from the environment.
|
||||
*
|
||||
* \param env Pointer to an environment enabling access to the jvm
|
||||
*
|
||||
* \return
|
||||
* - 0 if the references could be loaded successfully
|
||||
* - <0 if an error occured
|
||||
*/
|
||||
static __inline int ReferencesLoad(JNIEnv *env)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
ThrowLibusbError(env, -1);
|
||||
CuAssert(tc, "LibusbError-Exception occured", env->ExceptionOccurred() != NULL);
|
||||
env->ExceptionClear();
|
||||
}
|
||||
# endif
|
||||
|
||||
static void FailingTest(CuTest* tc)
|
||||
if (info.jni.refs_loaded != 0)
|
||||
{
|
||||
CuAssert(tc, "test should fail", 3 == 1 + 1);
|
||||
info.jni.refs_loaded = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static __inline void ReferencesUnload(JNIEnv *env)
|
||||
{
|
||||
if (info.jni.refs_loaded == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DO_UNIT_TEST
|
||||
TEST_CASE(JVMTest)
|
||||
{
|
||||
TEST_CONTEXT();
|
||||
|
||||
ThrowLibusbError(env, -1);
|
||||
jthrowable e = env->ExceptionOccurred();
|
||||
CuAssert(tc, "LibusbError-Exception occured", e != NULL);
|
||||
env->ExceptionClear();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DO_UNIT_TEST
|
||||
typedef CuSuite* (*tSuiteNew)(void);
|
||||
|
||||
extern "C" JNIEXPORT CuSuite* GetLibusbJavaSuite(tSuiteNew SuiteNew, JNIEnv *env);
|
||||
|
||||
/*! \brief Exports the test suite for the libraries helper functions
|
||||
*
|
||||
* \test */
|
||||
CuSuite* CuGetLibusbJavaSuite(JNIEnv *env)
|
||||
* \param SuiteNew Pointer to an allocator function for a CuTest instance
|
||||
* \param env JNI Environment for the test
|
||||
*
|
||||
* \return A fully setup test suite. */
|
||||
JNIEXPORT CuSuite* GetLibusbJavaSuite(tSuiteNew SuiteNew, JNIEnv *env)
|
||||
{
|
||||
CuSuite* suite = CuSuiteNew();
|
||||
CuSuite* suite = SuiteNew();
|
||||
|
||||
SUITE_ADD_TEST(suite, FailingTest);
|
||||
# if TEST_USING_JVM
|
||||
SUITE_ADD_TEST(suite, JVMTest);
|
||||
# endif
|
||||
SUITE_ADD_TEST(suite, JNI_OnLoad_test);
|
||||
SUITE_ADD_TEST(suite, JVMTest);
|
||||
|
||||
test_context.env = env;
|
||||
return suite;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="LibusbJava" basedir=".">
|
||||
<!-- ======================================================================
|
||||
<!-- ======================================================================
|
||||
|
||||
Build file for libusbJava Shared Library
|
||||
|
||||
@@ -9,180 +9,192 @@
|
||||
|
||||
http://libusbJava.sourceforge.net
|
||||
====================================================================== -->
|
||||
<description>
|
||||
<description>
|
||||
Build file for libusbJava Shared Library
|
||||
</description>
|
||||
|
||||
|
||||
<property file="version.properties" />
|
||||
<property name="abi" value="0" />
|
||||
<property name="version" value="${abi}.0.0" />
|
||||
<property name="out_dir" value="${basedir}/out" />
|
||||
<property name="ver_info" value="${out_dir}/LibusbJava.res" />
|
||||
|
||||
<patternset id="buildfiles">
|
||||
<include name="**/*.o" />
|
||||
<include name="**/*.dll" />
|
||||
<include name="**/*.exe" />
|
||||
<include name="**/*.res" />
|
||||
<include name="**/*.rc" />
|
||||
<include name="**/*.so.*" />
|
||||
</patternset>
|
||||
|
||||
<target name="clean" description="--> Clean build files">
|
||||
<delete>
|
||||
<fileset dir=".">
|
||||
<patternset refid="buildfiles" />
|
||||
</fileset>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<target name="linux" depends="clean, LibusbJava Test" description="--> Build libusbJava-1.0.so">
|
||||
<echo level="info" message="Building Library" />
|
||||
<exec dir="." executable="g++" failonerror="true">
|
||||
<arg value="-Wno-write-strings" />
|
||||
<arg value="-shared" />
|
||||
<arg value="-fPIC" />
|
||||
<arg value="-Wl,-soname,libusbJava-1.0.so" />
|
||||
<arg value="-I/usr/lib" />
|
||||
<arg value="-I/usr/lib/jvm/java-6-openjdk/include/" />
|
||||
<arg value="${basedir}/LibusbJava.cpp" />
|
||||
<arg value="-o${out_dir}/libusbJava-1.0.so.${version}" />
|
||||
<arg value="/usr/lib/libusb-1.0.so" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="Windows 32Bit" depends="clean, LibusbJava Test, Windows Resource" description="--> Build LibusbJava-1_0.dll">
|
||||
<echo level="info" message="Building Library" />
|
||||
<exec dir="." executable="g++" failonerror="true">
|
||||
<arg value="-Wno-write-strings" />
|
||||
<arg value="-D_JNI_IMPLEMENTATION_" />
|
||||
<arg value="-Wl,--kill-at" />
|
||||
<arg value="-mwindows" />
|
||||
<arg value="-static" />
|
||||
<arg value="-shared" />
|
||||
<arg value="-IC:/Program Files/Java/jdk${java.version}/include" />
|
||||
<arg value="-IC:/Program Files/Java/jdk${java.version}/include/win32" />
|
||||
<arg value="-I${basedir}" />
|
||||
<arg value="${basedir}/LibusbJava.cpp" />
|
||||
<arg value="${ver_info}" />
|
||||
<arg value="-o" />
|
||||
<arg value="${out_dir}/x86/LibusbJava-1_0.dll" />
|
||||
<arg value="-L${basedir}/MinGW32/static" />
|
||||
<arg value="-lusb-1.0" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="Windows 64Bit" depends="clean, LibusbJava Test, Windows Resource" description="--> Build LibusbJava-1_0.dll">
|
||||
<echo level="info" message="Building Library" />
|
||||
<exec dir="." executable="g++" failonerror="true">
|
||||
<arg value="-Wno-write-strings" />
|
||||
<arg value="-D_JNI_IMPLEMENTATION_" />
|
||||
<arg value="-Wl,--kill-at" />
|
||||
<arg value="-mwindows" />
|
||||
<arg value="-static" />
|
||||
<arg value="-shared" />
|
||||
<arg value="-IC:/Program Files/Java/jdk${java.version}/include" />
|
||||
<arg value="-IC:/Program Files/Java/jdk${java.version}/include/win32" />
|
||||
<arg value="-I${basedir}" />
|
||||
<arg value="${basedir}/LibusbJava.cpp" />
|
||||
<arg value="${ver_info}" />
|
||||
<arg value="-o" />
|
||||
<arg value="${out_dir}/LibusbJava-1_0.dll" />
|
||||
<arg value="-L${basedir}/MinGW64/static" />
|
||||
<arg value="-lusb-1.0" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="Windows 64Bit Debug" depends="clean, LibusbJava Test, Windows Resource" description="--> Build LibusbJava-1_0.dll">
|
||||
<echo level="info" message="Building Library" />
|
||||
<exec dir="." executable="g++" failonerror="true">
|
||||
<arg value="-Wall" />
|
||||
<arg value="-Wno-write-strings" />
|
||||
<arg value="-D_JNI_IMPLEMENTATION_" />
|
||||
<arg value="-Wl,--kill-at" />
|
||||
<arg value="-O0" />
|
||||
<arg value="-g" />
|
||||
<arg value="-mwindows" />
|
||||
<arg value="-static" />
|
||||
<arg value="-shared" />
|
||||
<arg value="-IC:/Program Files/Java/jdk${java.version}/include" />
|
||||
<arg value="-IC:/Program Files/Java/jdk${java.version}/include/win32" />
|
||||
<arg value="-I${basedir}" />
|
||||
<arg value="${basedir}/LibusbJava.cpp" />
|
||||
<arg value="${ver_info}" />
|
||||
<arg value="-o" />
|
||||
<arg value="${out_dir}/LibusbJava-1_0.dll" />
|
||||
<arg value="-L${basedir}/MinGW64/static" />
|
||||
<arg value="-lusb-1.0" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<property name="version" value="${abi}.0.0" />
|
||||
<property name="out_dir" value="${basedir}/out" />
|
||||
<property name="ver_info" value="${out_dir}/LibusbJava.res" />
|
||||
<property name="Unit-Test Executable" value="${out_dir}/LibusbJava-UnitTest.exe" />
|
||||
|
||||
<target name="LibusbJava Test" depends="Build LibusbJava Test" description="--> Execute Unit-Tests">
|
||||
<echo level="info" message="Executing Unit-Tests" />
|
||||
<exec dir="." executable="${Unit-Test Executable}" failonerror="true" />
|
||||
</target>
|
||||
|
||||
<target name="Build LibusbJava Test" description="--> Build Unit-Tests">
|
||||
<property name="Unit-Test Executable" value="${out_dir}/LibusbJava-UnitTest.exe" />
|
||||
|
||||
<echo level="info" message="Building Unit-Tests with JDK ${java.version}" />
|
||||
<exec dir="." executable="g++" failonerror="true">
|
||||
<arg value="-Wall" />
|
||||
<arg value="-Wno-write-strings" />
|
||||
<arg value="-D_JNI_IMPLEMENTATION_" />
|
||||
<arg value="-DDO_UNIT_TEST=1" />
|
||||
<arg value="-DTEST_USING_JVM=1" />
|
||||
<arg value="-Wl,--kill-at" />
|
||||
<arg value="-O0" />
|
||||
<arg value="-g" />
|
||||
<arg value="-mwindows" />
|
||||
<arg value="-static" />
|
||||
<arg value="-IC:/Program Files/Java/jdk${java.version}/include" />
|
||||
<arg value="-IC:/Program Files/Java/jdk${java.version}/include/win32" />
|
||||
<arg value="-I${basedir}" />
|
||||
<arg value="${basedir}/LibusbJava.cpp" />
|
||||
<arg value="${basedir}/test/CuTest.c" />
|
||||
<arg value="${basedir}/test/LibusbJavaTest.cpp" />
|
||||
<arg value="-o" />
|
||||
<arg value="${Unit-Test Executable}" />
|
||||
<arg value="-L${basedir}/MinGW64/static" />
|
||||
<arg value="-LC:/Program Files/Java/jdk${java.version}/lib" />
|
||||
<arg value="-lusb-1.0" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="Windows Resource" description="--> Build Version resource">
|
||||
<property name="rc_file" value="${out_dir}/LibusbJava.rc" />
|
||||
<basename property="filename" file="${rc_file}"/>
|
||||
<echo level="info" message="Generating rc-File: ${filename}" />
|
||||
<exec dir="." executable="build_rc.cmd">
|
||||
<arg value="${rc_file}" />
|
||||
<arg value="${version.major}" />
|
||||
<arg value="${version.minor}" />
|
||||
<arg value="${version.micro}" />
|
||||
<arg value="${version.nano}" />
|
||||
</exec>
|
||||
<basename property="target_file" file="${ver_info}"/>
|
||||
<echo level="info" message="Compiling res-File: ${target_file}" />
|
||||
<exec dir="." executable="windres">
|
||||
<arg value="-Ocoff" />
|
||||
<arg value="-o${ver_info}" />
|
||||
<arg value="${rc_file}" />
|
||||
</exec>
|
||||
</target>
|
||||
<property name="LIB_CCFLAGS_WIN" value="-I"C:/Program Files/Java/jdk${java.version}/include"
|
||||
-I"C:/Program Files/Java/jdk${java.version}/include/win32"
|
||||
-I${basedir}
|
||||
-Wall
|
||||
-Wno-write-strings
|
||||
-D_JNI_IMPLEMENTATION_
|
||||
-Wl,--kill-at
|
||||
-mwindows
|
||||
-m32
|
||||
-m64
|
||||
-static
|
||||
-shared
|
||||
${basedir}/LibusbJava.cpp
|
||||
${ver_info}
|
||||
-o ${out_dir}/LibusbJava-1_0.dll
|
||||
-L${basedir}/MinGW64/static
|
||||
-L${basedir}/MinGW32/static
|
||||
-lusb-1.0" />
|
||||
<property name="APP_CCFLAGS_WIN" value="-Wall
|
||||
-Wno-write-strings
|
||||
-D_JNI_IMPLEMENTATION_
|
||||
-DDO_UNIT_TEST=1
|
||||
-DTEST_USING_JVM=1
|
||||
-Wl,--kill-at
|
||||
-O0
|
||||
-g
|
||||
-mwindows
|
||||
-static
|
||||
-I"C:/Program Files/Java/jdk${java.version}/include"
|
||||
-I"C:/Program Files/Java/jdk${java.version}/include/win32"
|
||||
-I${basedir}
|
||||
${basedir}/test/CuTest.c
|
||||
${basedir}/test/LibusbJavaTest.cpp
|
||||
-o
|
||||
${Unit-Test Executable}
|
||||
-L${basedir}/MinGW64/static
|
||||
-L"C:/Program Files/Java/jdk${java.version}/lib"" />
|
||||
|
||||
<property name="LIB_CCFLAGS_LIN" value="-Wno-write-strings
|
||||
-shared
|
||||
-fPIC
|
||||
-Wl,-soname,libusbJava-1.0.so
|
||||
-I/usr/lib
|
||||
-I/usr/lib/jvm/java-6-openjdk/include/
|
||||
${basedir}/LibusbJava.cpp
|
||||
-o${out_dir}/libusbJava-1.0.so.${version}
|
||||
/usr/lib/libusb-1.0.so" />
|
||||
<property name="APP_CCFLAGS_LIN" value="-Wall
|
||||
-Wno-write-strings
|
||||
-D_JNI_IMPLEMENTATION_
|
||||
-Wl,--kill-at
|
||||
-static
|
||||
-I/usr/lib
|
||||
-I/usr/lib/jvm/java-6-openjdk/include/
|
||||
-I${basedir}
|
||||
${basedir}/test/CuTest.c
|
||||
${basedir}/test/LibusbJavaTest.cpp
|
||||
-o
|
||||
${Unit-Test Executable}" />
|
||||
|
||||
<patternset id="buildfiles">
|
||||
<include name="**/*.o" />
|
||||
<include name="**/*.dll" />
|
||||
<include name="**/*.exe" />
|
||||
<include name="**/*.res" />
|
||||
<include name="**/*.rc" />
|
||||
<include name="**/*.so.*" />
|
||||
</patternset>
|
||||
|
||||
<target name="clean" description="--> Clean build files">
|
||||
<delete>
|
||||
<fileset dir=".">
|
||||
<patternset refid="buildfiles" />
|
||||
</fileset>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<!-- Linux targets -->
|
||||
<target name="linux" depends="clean, LibusbJava Test Linux" description="--> Build libusbJava-1.0.so">
|
||||
<echo level="info" message="Building Library" />
|
||||
<exec dir="." executable="g++" failonerror="true">
|
||||
<arg line="${LIB_CCFLAGS_LIN}" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="LibusbJava Test Linux" depends="Build LibusbJava Test Linux" description="--> Execute Unit-Tests">
|
||||
<echo level="info" message="Executing Unit-Tests" />
|
||||
<exec dir="." executable="${Unit-Test Executable}" failonerror="true" />
|
||||
</target>
|
||||
|
||||
<target name="Build LibusbJava Test Linux">
|
||||
<property name="LIB_CCFLAGS" value="${LIB_CCFLAGS_LIN}" />
|
||||
<property name="APP_CCFLAGS" value="${APP_CCFLAGS_LIN}" />
|
||||
<antcall target="Build LibusbJava Test" />
|
||||
</target>
|
||||
|
||||
<!-- Windows targets -->
|
||||
<target name="Windows 64Bit" depends="clean, LibusbJava Test Windows, Windows Resource" description="--> Build LibusbJava-1_0.dll">
|
||||
<echo level="info" message="Building Library" />
|
||||
<exec dir="." executable="g++" failonerror="true">
|
||||
<arg line="${LIB_CCFLAGS_WIN}" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="Windows 64Bit Debug" depends="clean, Windows Resource" description="--> Build LibusbJava-1_0.dll">
|
||||
<echo level="info" message="Building Library" />
|
||||
<exec dir="." executable="g++" failonerror="true">
|
||||
<arg line="${LIB_CCFLAGS_WIN} -g -O0" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="LibusbJava Test Windows" depends="Build LibusbJava Test Windows" description="--> Execute Unit-Tests">
|
||||
<echo level="info" message="Executing Unit-Tests" />
|
||||
<exec dir="." executable="${Unit-Test Executable}" failonerror="true" />
|
||||
</target>
|
||||
|
||||
<target name="Build LibusbJava Test Windows" depends="Windows Resource">
|
||||
<property name="LIB_CCFLAGS" value="${LIB_CCFLAGS_WIN}" />
|
||||
<property name="APP_CCFLAGS" value="${APP_CCFLAGS_WIN}" />
|
||||
<antcall target="Build LibusbJava Test" />
|
||||
</target>
|
||||
|
||||
<target name="Windows Resource" description="--> Build Version resource">
|
||||
<property name="rc_file" value="${out_dir}/LibusbJava.rc" />
|
||||
<basename property="filename" file="${rc_file}" />
|
||||
<echo level="info" message="Generating rc-File: ${filename}" />
|
||||
<exec dir="." executable="build_rc.cmd">
|
||||
<arg value="${rc_file}" />
|
||||
<arg value="${version.major}" />
|
||||
<arg value="${version.minor}" />
|
||||
<arg value="${version.micro}" />
|
||||
<arg value="${version.nano}" />
|
||||
</exec>
|
||||
<basename property="target_file" file="${ver_info}" />
|
||||
<echo level="info" message="Compiling res-File: ${target_file}" />
|
||||
<exec dir="." executable="windres">
|
||||
<arg value="-Ocoff" />
|
||||
<arg value="-o${ver_info}" />
|
||||
<arg value="${rc_file}" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<!-- Mac -->
|
||||
<target name="mac" depends="clean" description="--> Build LibusbJava-1.0.jnilib">
|
||||
<exec dir="." executable="g++" failonerror="true">
|
||||
<arg value="-v" />
|
||||
<arg value="-dynamiclib" />
|
||||
<arg line="-I /System/Library/Frameworks/JavaVM.framework/Headers/" />
|
||||
<arg value="ch_ntb_inf_libusbJava_LibusbJava.cpp" />
|
||||
<arg line="-o LibusbJava-1_0.jnilib" />
|
||||
<arg line="-l stdc++" />
|
||||
<arg value="/usr/local/lib/libusb.dylib" />
|
||||
<arg value="/usr/local/lib/libusbpp.dylib" />
|
||||
</exec>
|
||||
</target>
|
||||
<exec dir="." executable="g++" failonerror="true">
|
||||
<arg value="-v" />
|
||||
<arg value="-dynamiclib" />
|
||||
<arg line="-I /System/Library/Frameworks/JavaVM.framework/Headers/" />
|
||||
<arg value="ch_ntb_inf_libusbJava_LibusbJava.cpp" />
|
||||
<arg line="-o LibusbJava-1_0.jnilib" />
|
||||
<arg line="-l stdc++" />
|
||||
<arg value="/usr/local/lib/libusb.dylib" />
|
||||
<arg value="/usr/local/lib/libusbpp.dylib" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<!-- Generic targets -->
|
||||
<target name="Build LibusbJava Test" description="--> Build Unit-Tests">
|
||||
<echo level="info" message="Building Library for unit tests:" />
|
||||
<exec dir="." executable="g++" failonerror="true">
|
||||
<arg line="${LIB_CCFLAGS}" />
|
||||
<arg value="-DDO_UNIT_TEST" />
|
||||
<arg value="-DTEST_USING_JVM" />
|
||||
<arg value="${basedir}/test/CuTest.c" />
|
||||
<arg value="-O0" />
|
||||
<arg value="-g" />
|
||||
</exec>
|
||||
|
||||
<echo level="info" message="Building Unit-Tests with JDK ${java.version}" />
|
||||
<exec dir="." executable="g++" failonerror="true">
|
||||
<arg line="${APP_CCFLAGS}" />
|
||||
<arg value="-DDO_UNIT_TEST=1" />
|
||||
<arg value="-DTEST_USING_JVM=1" />
|
||||
<arg value="-O0" />
|
||||
<arg value="-g" />
|
||||
</exec>
|
||||
</target>
|
||||
</project>
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
#define PATH_SEPARATOR ';' /* define it to be ':' on Solaris */
|
||||
#define USER_CLASSPATH "../java/bin" /* where Prog.class is */
|
||||
|
||||
extern CuSuite* CuGetLibusbJavaSuite(JNIEnv *env);
|
||||
|
||||
const char *lib_paths[] = {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
"server\\jvm.dll",
|
||||
@@ -66,7 +64,6 @@ int main(void)
|
||||
{
|
||||
int test_fail_count = -1;
|
||||
|
||||
#if TEST_USING_JVM
|
||||
jint result = -1;
|
||||
|
||||
globals.jni.lib = JvmLibraryLoad();
|
||||
@@ -98,11 +95,8 @@ int main(void)
|
||||
goto end_no_attach;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
test_fail_count = RunAllTests();
|
||||
|
||||
#if TEST_USING_JVM
|
||||
/* Check if there is still a pending exception. Usually all the tests should clear the
|
||||
* exceptions if any have been expected. If this is not the case something went wrong... */
|
||||
if (globals.jvm.env->ExceptionOccurred()) {
|
||||
@@ -122,27 +116,58 @@ end_no_CreateJavaVM:
|
||||
JvmLibraryFree();
|
||||
|
||||
end_no_jvm_lib:
|
||||
#endif
|
||||
return test_fail_count;
|
||||
|
||||
}
|
||||
|
||||
typedef CuSuite* (*tSuiteNew)(void);
|
||||
typedef CuSuite* (*tGetDLLtests)(tSuiteNew SuiteNew, JNIEnv *env);
|
||||
|
||||
/*! \brief Executes all the tests
|
||||
*
|
||||
* \return Number of tests that failed */
|
||||
static inline int RunAllTests(void)
|
||||
{
|
||||
CuSuite *suite = CuGetLibusbJavaSuite(globals.thread_env);
|
||||
CuString *output = CuStringNew();
|
||||
int result = 0;
|
||||
tGetDLLtests getTestSuite = NULL;
|
||||
tLibHandle libusb = LoadLibrary("LibusbJava-1_0.dll");
|
||||
|
||||
if (libusb == NULL) {
|
||||
printf("Failed to load LibusbJava-1_0.dll: %lu", GetLastError());
|
||||
goto no_lib;
|
||||
}
|
||||
|
||||
getTestSuite = (tGetDLLtests)GetProcAddress(libusb, "GetLibusbJavaSuite");
|
||||
if (getTestSuite == NULL)
|
||||
{
|
||||
printf("Failed to get unit tests: %lu", GetLastError());
|
||||
goto no_suite_new;
|
||||
}
|
||||
|
||||
/* Run the test procedures */
|
||||
{
|
||||
CuSuite *suite = getTestSuite(&CuSuiteNew, globals.thread_env);
|
||||
CuString *output = CuStringNew();
|
||||
|
||||
|
||||
CuSuiteRun(suite);
|
||||
CuSuiteSummary(suite, output);
|
||||
CuSuiteDetails(suite, output);
|
||||
CuSuiteRun(suite);
|
||||
CuSuiteSummary(suite, output);
|
||||
CuSuiteDetails(suite, output);
|
||||
|
||||
printf("%s\n", output->buffer);
|
||||
printf("%s\n", output->buffer);
|
||||
|
||||
return suite->failCount;
|
||||
result = suite->failCount;
|
||||
}
|
||||
|
||||
FreeLibrary(libusb);
|
||||
|
||||
return result;
|
||||
|
||||
no_suite_new:
|
||||
FreeLibrary(libusb);
|
||||
|
||||
no_lib:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*! \brief Creates a java virtual machine and places all the received handles into
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
version.major=1
|
||||
version.minor=0
|
||||
version.micro=0
|
||||
version.micro=1
|
||||
version.nano=0
|
||||
Reference in New Issue
Block a user