code_junkie

How to create a JNIEnv mock in C/C++

Nov 11th, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #include "jni.h"
  2. #include <iostream>
  3.  
  4. jint JNICALL MockGetVersion(JNIEnv *)
  5. {
  6. return 23;
  7. }
  8.  
  9. JNINativeInterface_ jnini = {
  10. 0, 0, 0, 0, //4 reserved pointers
  11. MockGetVersion
  12. };
  13.  
  14. // class Foo { public static native void bar(); }
  15. void Java_Foo_bar(JNIEnv* jni, jclass)
  16. {
  17. std::cout << jni->GetVersion() << std::endl;
  18. }
  19.  
  20. int main()
  21. {
  22. JNIEnv_ myjni = {&jnini};
  23. Java_Foo_bar(&myjni, 0);
  24. return 0;
  25. }
Add Comment
Please, Sign In to add comment