From 1cefdbdff559aff5a3ee5c0878ba3b505109e0f9 Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Wed, 29 Feb 2012 09:34:50 -0800 Subject: Test invocation of static methods through JNI stub Additional unit test to avoid regressions like Change I707f8e64. Change-Id: Ic343bf5273ca06b646f0235c88d6edbe3d20d448 --- src/jni_compiler_test.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/jni_compiler_test.cc b/src/jni_compiler_test.cc index cf7068570f..2166d37a21 100644 --- a/src/jni_compiler_test.cc +++ b/src/jni_compiler_test.cc @@ -36,6 +36,11 @@ JNIEXPORT jint JNICALL Java_MyClass_bar(JNIEnv* env, jobject thisObj, jint count return count + 1; } +extern "C" +JNIEXPORT jint JNICALL Java_MyClass_sbar(JNIEnv* env, jclass myClass, jint count) { + return count + 1; +} + namespace art { class JniCompilerTest : public CommonTest { @@ -128,7 +133,7 @@ TEST_F(JniCompilerTest, CompileAndRunNoArgMethod) { TEST_F(JniCompilerTest, CompileAndRunIntMethodThroughStub) { SirtRef class_loader(LoadDex("MyClassNatives")); SetupForTest(class_loader.get(), false, "bar", "(I)I", - NULL /* calling through stub will load &Java_MyClass_bar */); + NULL /* calling through stub will link with &Java_MyClass_bar */); std::string reason; ASSERT_TRUE(Runtime::Current()->GetJavaVM()->LoadNativeLibrary("", class_loader.get(), reason)) @@ -138,6 +143,19 @@ TEST_F(JniCompilerTest, CompileAndRunIntMethodThroughStub) { EXPECT_EQ(25, result); } +TEST_F(JniCompilerTest, CompileAndRunStaticIntMethodThroughStub) { + SirtRef class_loader(LoadDex("MyClassNatives")); + SetupForTest(class_loader.get(), true, "sbar", "(I)I", + NULL /* calling through stub will link with &Java_MyClass_sbar */); + + std::string reason; + ASSERT_TRUE(Runtime::Current()->GetJavaVM()->LoadNativeLibrary("", class_loader.get(), reason)) + << reason; + + jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 42); + EXPECT_EQ(43, result); +} + int gJava_MyClass_fooI_calls = 0; jint Java_MyClass_fooI(JNIEnv* env, jobject thisObj, jint x) { // 2 = SirtRef + thisObj -- cgit v1.2.3-59-g8ed1b