- First steps in doing unit tests of the C-part
git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@295 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
<option id="gnu.cpp.compiler.option.other.other.913778927" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value=" -mwindows -c -fmessage-length=0" valueType="string"/>
|
||||
<option id="gnu.cpp.compiler.option.preprocessor.def.1526583498" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" valueType="definedSymbols">
|
||||
<listOptionValue builtIn="false" value="_JNI_IMPLEMENTATION_"/>
|
||||
<listOptionValue builtIn="false" value="DO_UNIT_TEST=1"/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.728081923" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||
</tool>
|
||||
@@ -53,6 +54,9 @@
|
||||
<listOptionValue builtIn="false" value=""C:/Program Files/Java/jdk1.6.0_26/include""/>
|
||||
<listOptionValue builtIn="false" value=""C:/Program Files/Java/jdk1.6.0_26/include/win32""/>
|
||||
</option>
|
||||
<option id="gnu.c.compiler.option.preprocessor.def.symbols.645355643" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
|
||||
<listOptionValue builtIn="false" value="DO_UNIT_TEST=1"/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1861606347" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.so.debug.1427267537" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.so.debug">
|
||||
@@ -218,8 +222,8 @@
|
||||
<parser enabled="false"/>
|
||||
</scannerInfoProvider>
|
||||
</profile>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.mingw.so.debug.655628217;cdt.managedbuild.config.gnu.mingw.so.debug.655628217.;cdt.managedbuild.tool.gnu.cpp.compiler.mingw.so.debug.1164145566;cdt.managedbuild.tool.gnu.cpp.compiler.input.728081923">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.mingw.so.release.1888654320;cdt.managedbuild.config.gnu.mingw.so.release.1888654320.;cdt.managedbuild.tool.gnu.c.compiler.mingw.so.release.913614476;cdt.managedbuild.tool.gnu.c.compiler.input.1931731652">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
|
||||
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
|
||||
<buildOutputProvider>
|
||||
<openAction enabled="true" filePath=""/>
|
||||
@@ -261,8 +265,8 @@
|
||||
</scannerInfoProvider>
|
||||
</profile>
|
||||
</scannerConfigBuildInfo>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.mingw.so.release.1888654320;cdt.managedbuild.config.gnu.mingw.so.release.1888654320.;cdt.managedbuild.tool.gnu.c.compiler.mingw.so.release.913614476;cdt.managedbuild.tool.gnu.c.compiler.input.1931731652">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.mingw.so.debug.655628217;cdt.managedbuild.config.gnu.mingw.so.debug.655628217.;cdt.managedbuild.tool.gnu.cpp.compiler.mingw.so.debug.1164145566;cdt.managedbuild.tool.gnu.cpp.compiler.input.728081923">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
|
||||
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
|
||||
<buildOutputProvider>
|
||||
<openAction enabled="true" filePath=""/>
|
||||
|
||||
@@ -194,7 +194,7 @@ JNIEXPORT void JNICALL Java_ch_ntb_inf_libusbJava_LibusbJava1_libusb_1exit(JNIEn
|
||||
********************************************************************************************/
|
||||
JNIEXPORT jobject JNICALL Java_ch_ntb_inf_libusbJava_LibusbJava1_libusb_1get_1device_1list( JNIEnv *env, jclass obj, jlong ctx) {
|
||||
libusb_device **devs;
|
||||
libusb_context *context = NULL;
|
||||
libusb_context *context = (ctx != 0) ? (libusb_context*)ctx : NULL;
|
||||
ssize_t cnt;
|
||||
int res, a, i;
|
||||
uint8_t c, h, e;
|
||||
@@ -405,12 +405,8 @@ JNIEXPORT jobject JNICALL Java_ch_ntb_inf_libusbJava_LibusbJava1_libusb_1get_1de
|
||||
clearLibusbJavaError();
|
||||
|
||||
libusb_config_descriptor *conf_desc;
|
||||
if (ctx > 0) {
|
||||
context = (libusb_context*) ((unsigned long) ctx);
|
||||
cnt = libusb_get_device_list(context, &devs);
|
||||
} else {
|
||||
cnt = libusb_get_device_list(NULL, &devs);
|
||||
}
|
||||
|
||||
cnt = libusb_get_device_list(context, &devs);
|
||||
if (cnt < 0) {
|
||||
setLibusbJavaError("libusb_get_device_list: Error on Memory allocation");
|
||||
libusb_free_device_list(devs, 1);
|
||||
@@ -1825,6 +1821,18 @@ JNIEXPORT void JNICALL Java_ch_ntb_inf_libusbJava_LibusbJava1_libusb_1exceptionT
|
||||
ThrowLibusbError(env, code);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: ch_ntb_inf_libusbJava_LibusbJava1
|
||||
* Method: to_byteArrayTest
|
||||
* Signature: (Ljava/lang/String;I)[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL Java_ch_ntb_inf_libusbJava_LibusbJava1_to_1byteArrayTest(JNIEnv *env, jclass obj, jstring str, jint size)
|
||||
{
|
||||
jbyteArray result = to_byteArray(env, env->GetStringUTFChars (str, NULL), size);
|
||||
env->ReleaseStringUTFChars(str, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
/********************************************************************************************
|
||||
* Class: LibusbJava_1_0.cpp
|
||||
* Method: transfer_callback
|
||||
@@ -1868,16 +1876,21 @@ static void LIBUSB_CALL fd_removed_callback(int fd, void *user_data) {
|
||||
* \return The pointer to the newly created byte array. NULL if an error occured
|
||||
*
|
||||
* \note If NULL is returned, #libusbJavaError is set to a matching error string.
|
||||
*
|
||||
* \test Tested through the unit-test of the java part of this dll by passing a string
|
||||
* with length 5 and checking the result.
|
||||
* \test Tested through the Unit-Test of the java part of this dll by passing a string
|
||||
* with length 0 and checking the result.
|
||||
*/
|
||||
static __inline jbyteArray JNICALL to_byteArray(JNIEnv *env, const void *data, size_t len)
|
||||
{
|
||||
jbyteArray result = env->NewByteArray(len);
|
||||
|
||||
if (result != NULL) {
|
||||
/* Using SetByteArrayRegion, we avoid that the JNI layer first copies the data already
|
||||
* available in the array in our space just to overwrite them. As we just allocated the
|
||||
* byte aray with a length of "len", the set operation can never fail. The check for an
|
||||
* exception can be omitted. */
|
||||
/* By using SetByteArrayRegion, we avoid that the JNI layer first copies the data of
|
||||
* the array in our space just to overwrite them. As we just allocated the
|
||||
* byte array with a length of "len", the set operation can never fail. The check for an
|
||||
* exception can therefore be omitted. */
|
||||
env->SetByteArrayRegion(result, 0, len, (const signed char *)data);
|
||||
#if 0 /* No need to check for exceptions here... */
|
||||
if (env->ExceptionOccurred()){
|
||||
@@ -1902,7 +1915,10 @@ static __inline jbyteArray JNICALL to_byteArray(JNIEnv *env, const void *data, s
|
||||
* environment.
|
||||
*
|
||||
* \param env Java environment of the caller
|
||||
* \param libusb_result Result code of the libusb call
|
||||
* \param libusb_result Result code of the libusb call. If the result is != 0, a
|
||||
* LibusbError is thrown.
|
||||
*
|
||||
* \test Code-Review
|
||||
*/
|
||||
static __inline void JNICALL ThrowIfUnsuccessful(JNIEnv *env, int libusb_result)
|
||||
{
|
||||
@@ -1916,6 +1932,8 @@ static __inline void JNICALL ThrowIfUnsuccessful(JNIEnv *env, int libusb_result)
|
||||
*
|
||||
* \param env Environment to throw the exception in
|
||||
* \param code Error code that represents the cause of the exception
|
||||
*
|
||||
* \test Tested through the unit-test of the java part of this dll
|
||||
*/
|
||||
static __inline void JNICALL ThrowLibusbError(JNIEnv *env, jint code)
|
||||
{
|
||||
|
||||
@@ -487,6 +487,14 @@ JNIEXPORT jstring JNICALL Java_ch_ntb_inf_libusbJava_LibusbJava1_libusb_1strerro
|
||||
JNIEXPORT void JNICALL Java_ch_ntb_inf_libusbJava_LibusbJava1_libusb_1exceptionTest
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: ch_ntb_inf_libusbJava_LibusbJava1
|
||||
* Method: to_byteArrayTest
|
||||
* Signature: (Ljava/lang/String;I)[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL Java_ch_ntb_inf_libusbJava_LibusbJava1_to_1byteArrayTest
|
||||
(JNIEnv *, jclass, jstring, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user