Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of running junit tests calling native code #9

Open
sureshjoshi opened this issue Nov 14, 2017 · 1 comment
Open

Add example of running junit tests calling native code #9

sureshjoshi opened this issue Nov 14, 2017 · 1 comment

Comments

@sureshjoshi
Copy link
Owner

A problem with running native code is that you often need to use the instrumentation tests to run unit tests.

Actually, in reality, you just need to compile your libraries for your platform (as junit runs on your computer's native platform).

@sureshjoshi sureshjoshi self-assigned this Nov 14, 2017
@sureshjoshi
Copy link
Owner Author

Rough CMake is

if (APPLE)
  find_package(JNI REQUIRED)

  find_package(SWIG REQUIRED)
  include(${SWIG_USE_FILE})

  include_directories(${JAVA_INCLUDE_PATH})
  set_property(SOURCE SeePlusPlus.i PROPERTY CPLUSPLUS ON)
  swig_add_library(SeePlusPlus_Wrapper LANGUAGE java SOURCES SeePlusPlus.i)
  swig_link_libraries(SeePlusPlus_Wrapper SeePlusPlus)
  add_library(protobuf-lite SHARED IMPORTED)
  set_target_properties(protobuf-lite PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/jniLibs/osx/libprotobuf-lite.dylib)
  target_link_libraries( # Specifies the target library.
                         SeePlusPlus
                         protobuf-lite)

And then

    @Test
    fun addition_isCorrect() {
        val wrapperLib = File("app/src/main/jniLibs/osx/libSeePlusPlus_Wrapper.jnilib")
        System.load(wrapperLib.absolutePath)
        var mCpp = SeePlusPlus()
        val result = mCpp.Multiply(5, 1)
        Assert.assertEquals(5, result)
    }

sureshjoshi added a commit that referenced this issue Nov 16, 2017
Essentially, JUnit runs on the computer's platform, so having Android NDK-built libraries is of no use. Need to re-build these libraries 'natively' - using Mac/Linux/Windows.
@sureshjoshi sureshjoshi removed their assignment Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant