diff --git a/src/external/jnipp/CMakeLists.txt b/src/external/jnipp/CMakeLists.txt new file mode 100644 index 000000000..9b0c18794 --- /dev/null +++ b/src/external/jnipp/CMakeLists.txt @@ -0,0 +1,19 @@ +# Copyright 2021, Collabora, Ltd. +# +# SPDX-License-Identifier: MIT + +cmake_minimum_required(VERSION 3.10.2) +project(jnipp) + +find_package(JNI REQUIRED) +include(CTest) + +add_library(jnipp jnipp.cpp) +target_include_directories( + jnipp + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${JNI_INCLUDE_DIRS}) +target_compile_features(jnipp PUBLIC cxx_std_11) +target_link_libraries(jnipp PUBLIC ${CMAKE_DL_LIBS}) + +add_subdirectory(tests) diff --git a/src/external/jnipp/tests/CMakeLists.txt b/src/external/jnipp/tests/CMakeLists.txt new file mode 100644 index 000000000..b17c12d94 --- /dev/null +++ b/src/external/jnipp/tests/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright 2021, Collabora, Ltd. +# +# SPDX-License-Identifier: MIT + +add_executable(main_test main.cpp testing.h) +target_link_libraries(main_test PRIVATE jnipp) +add_test(NAME main_test COMMAND main_test) + +add_executable(external_create external_create.cpp testing.h) +target_link_libraries(external_create PUBLIC jnipp ${JNI_LIBRARIES}) +target_include_directories(external_create PUBLIC ${JNI_INCLUDE_DIRS}) +add_test(NAME external_create COMMAND external_create) + + +add_executable(external_detach external_detach.cpp testing.h) +target_link_libraries(external_detach PUBLIC jnipp ${JNI_LIBRARIES}) +target_include_directories(external_detach PUBLIC ${JNI_INCLUDE_DIRS}) +add_test(NAME external_detach COMMAND external_detach) diff --git a/src/external/jnipp/tests/external_create.cpp b/src/external/jnipp/tests/external_create.cpp new file mode 100644 index 000000000..735c248cb --- /dev/null +++ b/src/external/jnipp/tests/external_create.cpp @@ -0,0 +1,37 @@ +// Project Dependencies +#include +#include + +// Standard Dependencies +#include + +// Local Dependencies +#include "testing.h" + +/* + jni::Vm Tests + */ +TEST(Vm_externalCreateAndAttach) { + JNIEnv *env; + JavaVMInitArgs args = {}; + args.version = JNI_VERSION_1_2; + JavaVM *javaVm{}; + auto ret = JNI_CreateJavaVM(&javaVm, (void **)&env, &args); + ASSERT(ret == 0); + + { + jni::init(env); + jni::Class cls("java/lang/String"); + } + JavaVM *localVmPointer{}; + + ret = env->GetJavaVM(&localVmPointer); + ASSERT(ret == 0); +} + +int main() { + // jni::Vm Tests + RUN_TEST(Vm_externalCreateAndAttach); + + return 0; +} diff --git a/src/external/jnipp/tests/external_detach.cpp b/src/external/jnipp/tests/external_detach.cpp new file mode 100644 index 000000000..dda0245d1 --- /dev/null +++ b/src/external/jnipp/tests/external_detach.cpp @@ -0,0 +1,34 @@ +// Project Dependencies +#include +#include + +// Standard Dependencies +#include + +// Local Dependencies +#include "testing.h" + +/* + jni::Vm Tests + */ +TEST(Vm_externalDetach) { + jni::Vm vm; + + jni::Class cls("java/lang/String"); + + JNIEnv *env = (JNIEnv *)jni::env(); + JavaVM *localVmPointer{}; + + auto ret = env->GetJavaVM(&localVmPointer); + ASSERT(ret == 0); + ret = localVmPointer->DetachCurrentThread(); + ASSERT(ret == 0); + + ASSERT(1); +} + +int main() { + // jni::Vm Tests + RUN_TEST(Vm_externalDetach); + return 0; +} diff --git a/src/external/jnipp/tests/main.cpp b/src/external/jnipp/tests/main.cpp index d40355922..7c1adfcb1 100644 --- a/src/external/jnipp/tests/main.cpp +++ b/src/external/jnipp/tests/main.cpp @@ -622,8 +622,6 @@ int main() RUN_TEST(Arg_ObjectPtr); } - std::cout << "Press a key to continue..." << std::endl; - std::cin.get(); return 0; }