From 9b7f943969e17273ac9bd78bb238ffbea3865993 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Tue, 20 Aug 2024 23:21:06 +0200 Subject: Support building libsamba.so for unittests Unittests still fail as there is no samba server to talk to (step 2). --- libs/samba/src/main/cpp/jni.cpp | 26 ++++++++++++++++++++++++++ libs/samba/src/main/cpp/samba.cpp | 1 + 2 files changed, 27 insertions(+) (limited to 'libs/samba/src/main') diff --git a/libs/samba/src/main/cpp/jni.cpp b/libs/samba/src/main/cpp/jni.cpp index 30f03a9..aac1d28 100644 --- a/libs/samba/src/main/cpp/jni.cpp +++ b/libs/samba/src/main/cpp/jni.cpp @@ -1,6 +1,10 @@ #include "jni.hpp" +#ifdef ANDROID #include +#else +#include +#endif namespace { @@ -35,7 +39,12 @@ namespace internal { void _abort_if_not_ok(const char *file, int line, jint ret) { if (ret == JNI_OK) [[likely]] return; +#ifdef ANDROID __android_log_assert(nullptr, "jni", "JNI error: %s", _jni_error(ret)); +#else + std::cerr << "JNI error: " << _jni_error(ret) << std::endl; + abort(); +#endif } void _abort_with_exception(const char* file, int line, JNIEnv* env) { @@ -51,22 +60,39 @@ void _abort_with_exception(const char* file, int line, JNIEnv* env) { auto description = jni::CallObjectMethod(env, throwable, throwable_toString); auto str = jni::StringToUTF8(env, description); +#ifdef ANDROID __android_log_assert(nullptr, "jni", "JNI error: %s", str.c_str()); +#else + std::cerr << "JNI error: " << str << std::endl; + abort(); +#endif } } env->ExceptionClear(); +#ifdef ANDROID __android_log_assert(nullptr, "jni", "Unexpected NULL but no exception"); +#else + std::cerr << "Unexpected NULL but no exception" << std::endl; + abort(); +#endif } } } // namespace internal JNIEnv* AttachCurrentThread() { +#ifdef ANDROID JNIEnv* env; auto ret = g_vm->AttachCurrentThread(&env, nullptr); ABORT_IF_NOT_OK(ret); return env; +#else + void* v_env; + auto ret = g_vm->AttachCurrentThread(&v_env, nullptr); + ABORT_IF_NOT_OK(ret); + return reinterpret_cast(v_env); +#endif } JNIEnv* OnLoad(JavaVM* vm) { diff --git a/libs/samba/src/main/cpp/samba.cpp b/libs/samba/src/main/cpp/samba.cpp index 7b83eb4..7266a7f 100644 --- a/libs/samba/src/main/cpp/samba.cpp +++ b/libs/samba/src/main/cpp/samba.cpp @@ -1,3 +1,4 @@ +#include #include #include #include -- cgit v1.2.3-70-g09d2