Skip to content

Commit

Permalink
Adding disambiguating tests for jint and jdouble.
Browse files Browse the repository at this point in the history
This is potentially causing issues for Windows builds.

See #198 for context.

PiperOrigin-RevId: 569240465
  • Loading branch information
jwhpryor authored and copybara-github committed Sep 28, 2023
1 parent 39bed6b commit bac0e2a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions javatests/com/jnibind/test/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,15 @@ public void overloadTests() {
verify(rJniTestHelper).foo(123.f);
verify(rJniTestHelper).foo(123.f, 456.f);
}

/** Overload Tests: int double disambiguation */
native void jniCallFooOverload4(MethodTestHelper mockMethodTestHelper);

@Test
public void intAndDoubleDifferentiateOnOverload() {
jniCallFooOverload4(rJniTestHelper);

verify(rJniTestHelper).intDouble(123, 456.);
verify(rJniTestHelper).intDouble(456., 123);
}
}
4 changes: 4 additions & 0 deletions javatests/com/jnibind/test/MethodTestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,8 @@ public int foo(float f1) {
public int foo(float f1, float f2) {
return -1;
}

public void intDouble(int v1, double v2) {}

public void intDouble(double v1, int v2) {}
}
14 changes: 14 additions & 0 deletions javatests/com/jnibind/test/method_test_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ constexpr Class kMethodTestHelper {
Overload { Return<int>{}, Params<jfloat>{}},
Overload { Return<int>{}, Params<jfloat,jfloat>{}}
},

// Overloaded double/int Tests.
Method{"intDouble",
Overload { Return<void>{}, Params<jint, jdouble>{}},
Overload { Return<void>{}, Params<jdouble, jint>{}}
},
};
// clang-format on

Expand Down Expand Up @@ -251,4 +257,12 @@ JNIEXPORT int JNICALL Java_com_jnibind_test_MethodTest_jniCallFooOverload3(
return gtest_helper("foo", 123.f, 456.f);
}

/** Overload int/double disambiguation. */
JNIEXPORT void JNICALL Java_com_jnibind_test_MethodTest_jniCallFooOverload4(
JNIEnv* env, jclass, jobject object) {
LocalObject<kMethodTestHelper> gtest_helper{object};
gtest_helper("intDouble", 123, 456.);
gtest_helper("intDouble", 456., 123);
}

} // extern "C"

0 comments on commit bac0e2a

Please sign in to comment.