From b005a049e2036055d496cc7e09e3049ee5c999f7 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Mon, 4 Apr 2022 22:33:30 -0400 Subject: [PATCH] JNI for test coverage #3965 --- .../main/java/com/rusefi/native_/EngineLogic.java | 2 ++ .../native/com_rusefi_native__EngineLogic.h | 8 ++++++++ unit_tests/native/native_impl.cpp | 15 ++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/java_console/io/src/main/java/com/rusefi/native_/EngineLogic.java b/java_console/io/src/main/java/com/rusefi/native_/EngineLogic.java index 874c4ac117..e654f8a105 100644 --- a/java_console/io/src/main/java/com/rusefi/native_/EngineLogic.java +++ b/java_console/io/src/main/java/com/rusefi/native_/EngineLogic.java @@ -12,6 +12,8 @@ public class EngineLogic { public native void setConfiguration(byte[] content, int offset, int size); + public native void setEngineType(int engineType); + public native void invokePeriodicCallback(); public native byte[] getOutputs(); diff --git a/unit_tests/native/com_rusefi_native__EngineLogic.h b/unit_tests/native/com_rusefi_native__EngineLogic.h index e4b7f70709..321f9399ce 100644 --- a/unit_tests/native/com_rusefi_native__EngineLogic.h +++ b/unit_tests/native/com_rusefi_native__EngineLogic.h @@ -39,6 +39,14 @@ JNIEXPORT jbyteArray JNICALL Java_com_rusefi_native_1_EngineLogic_getConfigurati JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setConfiguration (JNIEnv *, jobject, jbyteArray, jint, jint); +/* + * Class: com_rusefi_native__EngineLogic + * Method: setEngineType + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setEngineType + (JNIEnv *, jobject, jint); + /* * Class: com_rusefi_native__EngineLogic * Method: invokePeriodicCallback diff --git a/unit_tests/native/native_impl.cpp b/unit_tests/native/native_impl.cpp index 8d4c60fb74..749caff740 100644 --- a/unit_tests/native/native_impl.cpp +++ b/unit_tests/native/native_impl.cpp @@ -30,7 +30,14 @@ JNIEXPORT jstring JNICALL Java_com_rusefi_native_1_EngineLogic_getVersion(JNIEnv } JNIEXPORT jbyteArray JNICALL Java_com_rusefi_native_1_EngineLogic_getConfiguration(JNIEnv *env, jobject instance) { - return nullptr; + jbyteArray retVal = env->NewByteArray(sizeof(engine_configuration_s)); + jbyte *buf = env->GetByteArrayElements(retVal, NULL); + EngineTestHelper* eth = getEth(); + + memcpy(buf, (const void*)ð->persistentConfig.engineConfiguration, sizeof(engine_configuration_s)); + env->ReleaseByteArrayElements(retVal, buf, 0); + + return retVal; } JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setConfiguration(JNIEnv *env, jobject instance, @@ -53,6 +60,12 @@ JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setSensor env->ReleaseStringUTFChars(sensorName, sensorNameNative); } +JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setEngineType + (JNIEnv *, jobject, jint engineType) { + EngineTestHelper* eth = getEth(); + resetConfigurationExt((engine_type_e)engineType); +} + JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_invokePeriodicCallback (JNIEnv *, jobject) {