I have java application, where I use C++ code. All c++ code is compiled to .so file. I have to write unit tests for native part of the project. I wrote such unit test:
#include <gtest/gtest.h>
#include <gtest-all.cc>
#include <myTestedFile.h>
#include <jni.h>
#include <iostream>
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
return 0;
}
TEST(MyTest, Test1)
{
jclass jc;
int k = jni_return_five((JNIEnv*)0, jc);
ASSERT_EQ(k,5);
}
there is file myTestedFile.cpp
#include "myTestedFile.h"
JNIEXPORT jint JNICALL jni_freerdp_new(JNIEnv *env, jclass cls)
{
jclass commonClass = env->FindClass(
"com/android/appportal/common/Myclass");
return 5;
}
I start this test with such way
adb push libs/armeabi-v7a/myTest /data/local/tmp
adb push libs/armeabi-v7a/myLibrary.so /data/local/tmp
adb shel "LD_LIBRARY_PATH=/data/local/tmp data/local/tmp/myTest"
After this I have output
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from MyTest
[ RUN ] MyTest.Test1
Segmentation fault
Test is passed succesfully, if I dont get references to java classes in the jni code. Can anyone help me with this error?
Aucun commentaire:
Enregistrer un commentaire