diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2024-08-20 23:21:06 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2024-08-20 23:21:06 +0200 |
| commit | 9b7f943969e17273ac9bd78bb238ffbea3865993 (patch) | |
| tree | 32d7d5c5f35414717b8bfa25f786fc4d2ebce029 /libs/samba/src | |
| parent | 088a7aef623700798647ad5b279388c4f7a59299 (diff) | |
Support building libsamba.so for unittests
Unittests still fail as there is no samba server to talk to (step 2).
Diffstat (limited to 'libs/samba/src')
| -rw-r--r-- | libs/samba/src/.gitignore | 2 | ||||
| -rw-r--r-- | libs/samba/src/main/cpp/jni.cpp | 26 | ||||
| -rw-r--r-- | libs/samba/src/main/cpp/samba.cpp | 1 | ||||
| -rw-r--r-- | libs/samba/src/test/java/org/the_jk/cleversync/samba/SambaTreeTest.kt | 39 |
4 files changed, 68 insertions, 0 deletions
diff --git a/libs/samba/src/.gitignore b/libs/samba/src/.gitignore new file mode 100644 index 0000000..2b22da4 --- /dev/null +++ b/libs/samba/src/.gitignore @@ -0,0 +1,2 @@ +testDebug/ +testRelease/ 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 <android/log.h> +#else +#include <iostream> +#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<jstring>(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<JNIEnv*>(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 <algorithm> #include <cassert> #include <jni.h> #include <memory> diff --git a/libs/samba/src/test/java/org/the_jk/cleversync/samba/SambaTreeTest.kt b/libs/samba/src/test/java/org/the_jk/cleversync/samba/SambaTreeTest.kt new file mode 100644 index 0000000..3f1fa04 --- /dev/null +++ b/libs/samba/src/test/java/org/the_jk/cleversync/samba/SambaTreeTest.kt @@ -0,0 +1,39 @@ +package org.the_jk.cleversync.samba + +import com.google.common.truth.Truth.assertThat +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import org.the_jk.cleversync.io.samba.SambaCredentials + +@Config(manifest=Config.NONE) +@RunWith(RobolectricTestRunner::class) +class SambaTreeTest { + private lateinit var uri: String + private lateinit var credentials: SambaCredentials + + @Before + fun setUp() { + uri = "smb://127.0.0.1:10445/" + credentials = SambaCredentials("test", "notverysecret") + } + + @After + fun tearDown() { + + } + + @Test + fun listRoot() { + val result = SambaTreeFactory.tree(uri, credentials) + assertThat(result.isSuccess).isTrue() + val root = result.getOrThrow() + val content = root.list() + assertThat(content.directories).hasSize(1) + assertThat(content.files).isEmpty() + assertThat(content.links).isEmpty() + } +} |
