Skip to content

Commit

Permalink
Portability fixes and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gershnik committed Aug 30, 2024
1 parent 4a1028d commit 8a183ce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion inc/smjni/java_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <smjni/utf_util.h>

#include <string>
#include <cstring>
#include <stdexcept>

#if __cpp_lib_ranges >= 201911L
#include <ranges>
Expand All @@ -42,7 +44,7 @@ namespace smjni
return jattach(env, ret);
}

inline local_java_ref<jstring> java_string_create(JNIEnv * env, nullptr_t)
inline local_java_ref<jstring> java_string_create(JNIEnv * env, std::nullptr_t)
{ return java_string_create(env, (const jchar *)nullptr, 0); }

inline local_java_ref<jstring> java_string_create(JNIEnv * env, const char16_t * str, size_t size)
Expand Down
1 change: 0 additions & 1 deletion src/java_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <smjni/java_string.h>

#include <iterator>
#include <cstring>
#include <vector>

using namespace smjni;
Expand Down
15 changes: 15 additions & 0 deletions tests/src/cpp/array_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <doctest.h>

#include <vector>

using namespace smjni;

TEST_SUITE_BEGIN("array");
Expand Down Expand Up @@ -131,6 +133,19 @@ TEST_CASE( "testObject" )
CHECK(buf == std::vector<std::string>{ "abc" });
}

{
auto str = java_string_create(env, "abc");
auto arr = java_array_create(env, java_runtime::object(), 5, str);
const java_array_access<jobjectArray> acc(env, arr);
std::vector<std::string> buf;
for(local_java_ref<jobject> obj: acc) {
if (obj) {
buf.push_back(java_string_to_cpp(env, obj));
}
}
CHECK(buf == std::vector<std::string>{ "abc", "abc", "abc", "abc", "abc" });
}

}

TEST_SUITE_END();

0 comments on commit 8a183ce

Please sign in to comment.