From e7ff3dc2d8dd663002b22fe19a343af53987912d Mon Sep 17 00:00:00 2001 From: Jamieson Pryor Date: Tue, 28 Nov 2023 23:23:50 -0800 Subject: [PATCH] Add Rank 1 helpers into static methods and convert rank 1 field tests. PiperOrigin-RevId: 586219433 --- .../com/jnibind/test/ArrayTestFieldRank1.java | 92 ------------------- .../com/jnibind/test/ArrayTestHelpers.java | 66 ++++++++----- javatests/com/jnibind/test/BUILD | 4 + .../test/array_test_field_rank_1_jni.cc | 74 +++++++-------- .../jnibind/test/array_test_helpers_native.h | 41 ++++++--- .../test/array_test_method_rank_1_jni.cc | 20 ++-- 6 files changed, 121 insertions(+), 176 deletions(-) diff --git a/javatests/com/jnibind/test/ArrayTestFieldRank1.java b/javatests/com/jnibind/test/ArrayTestFieldRank1.java index 6b78674..7584c65 100644 --- a/javatests/com/jnibind/test/ArrayTestFieldRank1.java +++ b/javatests/com/jnibind/test/ArrayTestFieldRank1.java @@ -16,10 +16,6 @@ package com.jnibind.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; import org.junit.AfterClass; import org.junit.Test; @@ -74,94 +70,6 @@ public static void doShutDown() { native void nativeObjectTests(ArrayTestFieldRank1 arrayTest, ObjectTestHelper[] objectArray); - void booleanArray(boolean baseOffset, boolean stride, boolean[] arr) { - // Booleans stride up until true (i.e. once) and then red line. - // This isn't intuitive, but allows for generalised testing. - for (int i = 0; i < arr.length; i++) { - if (baseOffset || (i > 0 && stride)) { - assertTrue(arr[i]); - } else { - assertFalse(arr[i]); - } - } - } - - void byteArray(byte baseOffset, byte stride, byte[] arr) { - for (int i = 0; i < arr.length; i++) { - assertEquals(i * stride + baseOffset, arr[i]); - } - } - - void charArray(char baseOffset, char stride, char[] arr) { - for (int i = 0; i < arr.length; i++) { - assertEquals(i * stride + baseOffset, arr[i]); - } - } - - void shortArray(short baseOffset, short stride, short[] arr) { - for (int i = 0; i < arr.length; i++) { - assertEquals(i * stride + baseOffset, arr[i]); - } - } - - void intArray(int baseOffset, int stride, int[] arr) { - for (int i = 0; i < arr.length; i++) { - assertEquals(i * stride + baseOffset, arr[i]); - } - } - - void longArray(long baseOffset, long stride, long[] arr) { - for (int i = 0; i < arr.length; i++) { - assertEquals(i * stride + baseOffset, arr[i]); - } - } - - void floatArray(float baseOffset, float stride, float[] arr) { - for (int i = 0; i < arr.length; i++) { - assertEquals(i * stride + baseOffset, arr[i], 1.f); - } - } - - void doubleArray(double baseOffset, double stride, double[] arr) { - for (int i = 0; i < arr.length; i++) { - assertEquals((double) i * stride + baseOffset, arr[i], 0); - } - } - - void stringArray(String[] arr, boolean isFooBazBar) { - if (isFooBazBar) { - assertEquals(3, arr.length); - assertEquals("Foo", arr[0]); - assertEquals("Baz", arr[1]); - assertEquals("Bar", arr[2]); - } else { - assertNotEquals("Foo", arr[0]); - assertNotEquals("Baz", arr[1]); - assertNotEquals("Bar", arr[2]); - } - } - - void stringEqual(boolean expectEqual, String lhs, String rhs) { - if (expectEqual) { - assertEquals(lhs, rhs); - } else { - assertNotEquals(lhs, rhs); - } - } - - void object(int objectMemberOffset, ObjectTestHelper obj) { - assertEquals(objectMemberOffset, obj.intVal1); - } - - void objectArray(int objectMemberOffset, ObjectTestHelper[] arr) { - for (int i = 0; i < arr.length; i++) { - int idxPlusOffset = i + objectMemberOffset; - ObjectTestHelper dummyThatMatchesIdx = - new ObjectTestHelper(idxPlusOffset, idxPlusOffset, idxPlusOffset); - assertTrue(dummyThatMatchesIdx.isEqualTo(arr[i])); - } - } - @Test public void booleanTests() { boolean[] arr = {false, false, false}; diff --git a/javatests/com/jnibind/test/ArrayTestHelpers.java b/javatests/com/jnibind/test/ArrayTestHelpers.java index c2c11df..4eb8dc7 100644 --- a/javatests/com/jnibind/test/ArrayTestHelpers.java +++ b/javatests/com/jnibind/test/ArrayTestHelpers.java @@ -15,8 +15,10 @@ */ package com.jnibind.test; +import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -24,9 +26,23 @@ final class ArrayTestHelpers { private ArrayTestHelpers() {} - static void assertBoolean1D(boolean testForTrue, boolean[] arr) { + /** Rank 0 Verification Methods. */ + static void assertString(String lhs, String rhs) { + assertEquals(lhs, rhs); + } + + static void assertObject(int objectMemberOffset, ObjectTestHelper arr) { + assertTrue( + arr.isEqualTo( + new ObjectTestHelper(objectMemberOffset, objectMemberOffset, objectMemberOffset))); + } + + /** Rank 1 Verification Methods. */ + static void assertBoolean1D(boolean baseOffset, boolean stride, boolean[] arr) { + // Booleans stride up until true (i.e. once) and then red line. + // This isn't intuitive, but allows for generalised testing. for (int i = 0; i < arr.length; i++) { - if (testForTrue) { + if (baseOffset || (i > 0 && stride)) { assertTrue(arr[i]); } else { assertFalse(arr[i]); @@ -34,53 +50,59 @@ static void assertBoolean1D(boolean testForTrue, boolean[] arr) { } } - static void assertByte1D(byte baseOffset, byte[] arr) { + static void assertByte1D(byte baseOffset, byte stride, byte[] arr) { for (int i = 0; i < arr.length; i++) { - assertEquals(i + baseOffset, arr[i]); + assertEquals(i * stride + baseOffset, arr[i]); } } - static void assertChar1D(char baseOffset, char[] arr) { + static void assertChar1D(char baseOffset, char stride, char[] arr) { for (int i = 0; i < arr.length; i++) { - assertEquals(i + baseOffset, arr[i]); + assertEquals(i * stride + baseOffset, arr[i]); } } - static void assertShort1D(short baseOffset, short[] arr) { + static void assertShort1D(short baseOffset, short stride, short[] arr) { for (int i = 0; i < arr.length; i++) { - assertEquals(i + baseOffset, arr[i]); + assertEquals(i * stride + baseOffset, arr[i]); } } - static void assertInt1D(int baseOffset, int[] arr) { + static void assertInt1D(int baseOffset, int stride, int[] arr) { for (int i = 0; i < arr.length; i++) { - assertEquals(i + baseOffset, arr[i]); + assertEquals(i * stride + baseOffset, arr[i]); } } - static void assertLong1D(long baseOffset, long[] arr) { + static void assertLong1D(long baseOffset, long stride, long[] arr) { for (int i = 0; i < arr.length; i++) { - assertEquals(i + baseOffset, arr[i]); + assertEquals(i * stride + baseOffset, arr[i]); } } - static void assertFloat1D(float baseOffset, float[] arr) { + static void assertFloat1D(float baseOffset, float stride, float[] arr) { for (int i = 0; i < arr.length; i++) { - assertEquals(i + baseOffset, arr[i], 1.f); + assertEquals(i * stride + baseOffset, arr[i], 1.f); } } - static void assertDouble1D(double baseOffset, double[] arr) { + static void assertDouble1D(double baseOffset, double stride, double[] arr) { for (int i = 0; i < arr.length; i++) { - assertEquals((double) i + baseOffset, arr[i], 0); + assertEquals((double) i * stride + baseOffset, arr[i], 0); } } - static void assertString1D(String[] arr) { - assertEquals(3, arr.length); - assertEquals("Foo", arr[0]); - assertEquals("Baz", arr[1]); - assertEquals("Bar", arr[2]); + static void assertString1D(String[] arr, boolean isFooBazBar) { + if (isFooBazBar) { + assertThat(arr).hasLength(3); + assertEquals("Foo", arr[0]); + assertEquals("Baz", arr[1]); + assertEquals("Bar", arr[2]); + } else { + assertNotEquals("Foo", arr[0]); + assertNotEquals("Baz", arr[1]); + assertNotEquals("Bar", arr[2]); + } } static void assertObject1D(int objectMemberOffset, ObjectTestHelper[] arr) { @@ -98,7 +120,7 @@ static void assertObjectArrayOfNulls1D(ObjectTestHelper[] arr) { } } - /** 2D Tests RJNI declarations. * */ + /** Rank 2 Verification Methods. */ static void assertBoolean2D(boolean testForTrue, boolean[][] arr) { // All even are true (unless testForTrue when they're flipped). for (int i = 0; i < arr.length; i++) { diff --git a/javatests/com/jnibind/test/BUILD b/javatests/com/jnibind/test/BUILD index 8e52d06..7aee9d4 100644 --- a/javatests/com/jnibind/test/BUILD +++ b/javatests/com/jnibind/test/BUILD @@ -8,6 +8,7 @@ cc_library( testonly = True, srcs = ["array_test_field_rank_1_jni.cc"], deps = [ + ":array_test_helpers_native", ":object_test_helper_jni", "//:jni_bind", "//metaprogramming:lambda_string", @@ -28,6 +29,9 @@ java_test( srcs = ["ArrayTestFieldRank1.java"], data = [":libarray_test_field_rank_1_jni.so"], jvm_flags = ["-Djava.library.path=./javatests/com/jnibind/test"], + runtime_deps = [ + ":array_test_helpers", + ], deps = [ ":object_test_helper", "@maven//:com_google_truth_truth_1_1", diff --git a/javatests/com/jnibind/test/array_test_field_rank_1_jni.cc b/javatests/com/jnibind/test/array_test_field_rank_1_jni.cc index a5b2320..1dd453b 100644 --- a/javatests/com/jnibind/test/array_test_field_rank_1_jni.cc +++ b/javatests/com/jnibind/test/array_test_field_rank_1_jni.cc @@ -18,6 +18,7 @@ #include #include +#include "array_test_helpers_native.h" #include "object_test_helper_jni.h" #include "jni_bind.h" #include "metaprogramming/lambda_string.h" @@ -32,6 +33,7 @@ using ::jni::LocalString; using ::jni::Method; using ::jni::Params; using ::jni::Return; +using ::jni::StaticRef; static std::unique_ptr> jvm; @@ -39,22 +41,6 @@ static std::unique_ptr> jvm; static constexpr Class kArrayTestFieldRank1 { "com/jnibind/test/ArrayTestFieldRank1", - // Validator functions. - Method {"booleanArray", Return{}, Params{jboolean{}, jboolean{}, Array{jboolean{}}}}, - Method {"byteArray", Return{}, Params{jbyte{},jbyte{}, Array{jbyte{}}}}, - Method {"charArray", Return{}, Params{jchar{}, jchar{}, Array{jchar{}}}}, - Method {"shortArray", Return{}, Params{jshort{},jshort{}, Array{jshort{}}}}, - Method {"intArray", Return{}, Params{int{},int{}, Array{jint{}}}}, - Method {"longArray", Return{}, Params{jlong{},jlong{}, Array{jlong{}}}}, - Method {"floatArray", Return{}, Params{float{},float{}, Array{jfloat{}}}}, - Method {"doubleArray", Return{}, Params{jdouble{},jdouble{}, Array{jdouble{}}}}, - - Method {"stringArray", Return{}, Params{Array{jstring{}}, jboolean{}}}, - Method {"stringEqual", Return{}, Params{jboolean{}, jstring{}, jstring{}}}, - - Method {"object", Return{}, Params{int{}, kObjectTestHelperClass}}, - Method {"objectArray", Return{}, Params{int{}, Array{kObjectTestHelperClass}}}, - // Fields under test: Rank 1 Primitives. Field {"booleanArrayField", Array{jboolean{}}}, Field {"byteArrayField", Array{jbyte{}}}, @@ -81,19 +67,21 @@ void GenericFieldTest(LocalObject fixture, MethodNameLambda method_name_lambda) { // Field starts in default state. LocalArray arr{fixture[field_name_lambda()].Get()}; - fixture(method_name_lambda(), SpanType{0}, SpanType{0}, - fixture[field_name_lambda()].Get()); + StaticRef{}(method_name_lambda(), SpanType{0}, + SpanType{0}, + fixture[field_name_lambda()].Get()); // Updating the field manually works. { ArrayView pin = arr.Pin(); for (int i = 0; i < arr.Length(); ++i) { - pin.ptr()[i] = static_cast(i * stride); + pin.ptr()[i] = static_cast(i * SpanType{1}); } } - fixture(method_name_lambda(), SpanType{0}, stride, - fixture[field_name_lambda()].Get()); + StaticRef{}(method_name_lambda(), SpanType{0}, + SpanType{1}, + fixture[field_name_lambda()].Get()); // Updating the field repeatedly works. { @@ -102,13 +90,13 @@ void GenericFieldTest(LocalObject fixture, pin.ptr()[i] = base + static_cast(stride * i); } } - fixture(method_name_lambda(), base, stride, - fixture[field_name_lambda()].Get()); + StaticRef{}(method_name_lambda(), base, stride, + fixture[field_name_lambda()].Get()); // Not pinning the value has no effect. { std::memset(arr.Pin(false).ptr(), 0, arr.Length() * sizeof(SpanType)); } - fixture(method_name_lambda(), base, stride, - fixture[field_name_lambda()].Get()); + StaticRef{}(method_name_lambda(), base, stride, + fixture[field_name_lambda()].Get()); } extern "C" { @@ -128,7 +116,7 @@ Java_com_jnibind_test_ArrayTestFieldRank1_nativeBooleanTests( JNIEnv* env, jclass, jobject test_fixture, jbooleanArray boolean_array) { GenericFieldTest(LocalObject{test_fixture}, jboolean{true}, jboolean{0}, jboolean{true}, - STR("booleanArrayField"), STR("booleanArray")); + STR("booleanArrayField"), STR("assertBoolean1D")); } JNIEXPORT void JNICALL @@ -136,7 +124,7 @@ Java_com_jnibind_test_ArrayTestFieldRank1_nativeByteTests( JNIEnv* env, jclass, jobject test_fixture, jbyteArray byte_array) { GenericFieldTest(LocalObject{test_fixture}, std::numeric_limits::max(), jbyte{10}, jbyte{1}, - STR("byteArrayField"), STR("byteArray")); + STR("byteArrayField"), STR("assertByte1D")); } JNIEXPORT void JNICALL @@ -144,7 +132,7 @@ Java_com_jnibind_test_ArrayTestFieldRank1_nativeCharTests( JNIEnv* env, jclass, jobject test_fixture, jcharArray char_array) { GenericFieldTest(LocalObject{test_fixture}, std::numeric_limits::max(), jchar{10}, jchar{1}, - STR("charArrayField"), STR("charArray")); + STR("charArrayField"), STR("assertChar1D")); } JNIEXPORT void JNICALL @@ -152,14 +140,14 @@ Java_com_jnibind_test_ArrayTestFieldRank1_nativeShortTests( JNIEnv* env, jclass, jobject test_fixture, jshortArray short_array) { GenericFieldTest(LocalObject{test_fixture}, std::numeric_limits::max(), jshort{10}, jshort{1}, - STR("shortArrayField"), STR("shortArray")); + STR("shortArrayField"), STR("assertShort1D")); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank1_nativeIntTests( JNIEnv* env, jclass, jobject test_fixture, jintArray int_array) { GenericFieldTest(LocalObject{test_fixture}, std::numeric_limits::max(), jint{10}, jint{1}, - STR("intArrayField"), STR("intArray")); + STR("intArrayField"), STR("assertInt1D")); } JNIEXPORT void JNICALL @@ -167,7 +155,7 @@ Java_com_jnibind_test_ArrayTestFieldRank1_nativeLongTests( JNIEnv* env, jclass, jobject test_fixture, jlongArray long_array) { GenericFieldTest(LocalObject{test_fixture}, std::numeric_limits::max(), jlong{10}, jlong{1}, - STR("longArrayField"), STR("longArray")); + STR("longArrayField"), STR("assertLong1D")); } JNIEXPORT void JNICALL @@ -175,7 +163,7 @@ Java_com_jnibind_test_ArrayTestFieldRank1_nativeFloatTests( JNIEnv* env, jclass, jobject test_fixture, jfloatArray float_array) { GenericFieldTest(LocalObject{test_fixture}, std::numeric_limits::max(), jfloat{10.f}, - jfloat{1.f}, STR("floatArrayField"), STR("floatArray")); + jfloat{1.f}, STR("floatArrayField"), STR("assertFloat1D")); } JNIEXPORT void JNICALL @@ -183,7 +171,7 @@ Java_com_jnibind_test_ArrayTestFieldRank1_nativeDoubleTests( JNIEnv* env, jclass, jobject test_fixture, jdoubleArray double_array) { GenericFieldTest(LocalObject{test_fixture}, std::numeric_limits::max(), jdouble{10}, jdouble{1}, - STR("doubleArrayField"), STR("doubleArray")); + STR("doubleArrayField"), STR("assertDouble1D")); } JNIEXPORT void JNICALL @@ -192,33 +180,41 @@ Java_com_jnibind_test_ArrayTestFieldRank1_nativeStringTests( LocalObject fixture{test_fixture}; // Field starts in default state. - fixture("stringArray", fixture["stringArrayField"].Get(), jboolean{false}); + StaticRef{}( + "assertString1D", fixture["stringArrayField"].Get(), jboolean{false}); // Updating the field manually works. LocalArray arr = fixture["stringArrayField"].Get(); arr.Set(0, LocalString{"Foo"}); arr.Set(1, LocalString{"Baz"}); arr.Set(2, LocalString{"Bar"}); - fixture("stringArray", arr, true); + StaticRef{}("assertString1D", arr, true); // Updating the field repeatedly works. arr.Set(0, LocalString{"FAKE"}); arr.Set(1, LocalString{"DEAD"}); arr.Set(2, LocalString{"BEEF"}); - fixture("stringArray", arr, false); + StaticRef{}("assertString1D", arr, false); // Updating the field repeatedly works. arr.Set(0, "Foo"); const char* kBaz = "Baz"; arr.Set(1, kBaz); arr.Set(2, std::string{"Bar"}); - fixture("stringArray", arr, true); + StaticRef{}("assertString1D", arr, true); // Iterating over values works. static constexpr std::array vals{"Foo", "Baz", "Bar"}; int i = 0; for (LocalString local_string : arr.Pin()) { - fixture("stringEqual", jboolean{true}, local_string, vals[i]); + StaticRef{}("assertString", local_string, vals[i]); + ++i; + } + + // Iterating over passed values works. + i = 0; + for (LocalString local_string : LocalArray{object_array}.Pin()) { + StaticRef{}("assertString", local_string, vals[i]); ++i; } } @@ -233,7 +229,7 @@ Java_com_jnibind_test_ArrayTestFieldRank1_nativeObjectTests( int i = 0; for (LocalObject new_obj : fixture["objectArrayField"].Get().Pin()) { - fixture("object", i, new_obj); + StaticRef{}("assertObject", i, new_obj); i++; } } diff --git a/javatests/com/jnibind/test/array_test_helpers_native.h b/javatests/com/jnibind/test/array_test_helpers_native.h index 2c75852..8e2c94e 100644 --- a/javatests/com/jnibind/test/array_test_helpers_native.h +++ b/javatests/com/jnibind/test/array_test_helpers_native.h @@ -27,32 +27,43 @@ constexpr jni::Class kArrayTestHelperClass{ "com/jnibind/test/ArrayTestHelpers", ::jni::Static{ - // Rank 1 verification. - ::jni::Method{"assertBoolean1D", ::jni::Return{}, - ::jni::Params{jboolean{}, ::jni::Array{}}}, + + // Rank 0 Verification. + ::jni::Method{"assertString", ::jni::Return{}, + ::jni::Params{jstring{}, jstring{}}}, + ::jni::Method{"assertObject", ::jni::Return{}, + ::jni::Params{jint{}, kObjectTestHelperClass}}, + + // Rank 1 Verification. + ::jni::Method{ + "assertBoolean1D", ::jni::Return{}, + ::jni::Params{jboolean{}, jboolean{}, ::jni::Array{}}}, ::jni::Method{"assertByte1D", ::jni::Return{}, - ::jni::Params{jbyte{}, ::jni::Array{}}}, + ::jni::Params{jbyte{}, jbyte{}, ::jni::Array{}}}, ::jni::Method{"assertChar1D", ::jni::Return{}, - ::jni::Params{jchar{}, ::jni::Array{}}}, - ::jni::Method{"assertShort1D", ::jni::Return{}, - ::jni::Params{jshort{}, ::jni::Array{}}}, + ::jni::Params{jchar{}, jchar{}, ::jni::Array{}}}, + ::jni::Method{ + "assertShort1D", ::jni::Return{}, + ::jni::Params{jshort{}, jshort{}, ::jni::Array{}}}, ::jni::Method{"assertInt1D", ::jni::Return{}, - ::jni::Params{jint{}, ::jni::Array{}}}, + ::jni::Params{jint{}, jint{}, ::jni::Array{}}}, ::jni::Method{"assertLong1D", ::jni::Return{}, - ::jni::Params{jlong{}, ::jni::Array{}}}, - ::jni::Method{"assertFloat1D", ::jni::Return{}, - ::jni::Params{jfloat{}, ::jni::Array{}}}, - ::jni::Method{"assertDouble1D", ::jni::Return{}, - ::jni::Params{jdouble{}, ::jni::Array{}}}, + ::jni::Params{jlong{}, jlong{}, ::jni::Array{}}}, + ::jni::Method{ + "assertFloat1D", ::jni::Return{}, + ::jni::Params{jfloat{}, jfloat{}, ::jni::Array{}}}, + ::jni::Method{ + "assertDouble1D", ::jni::Return{}, + ::jni::Params{jdouble{}, jdouble{}, ::jni::Array{}}}, ::jni::Method{"assertString1D", ::jni::Return{}, - ::jni::Params{::jni::Array{jstring{}}}}, + ::jni::Params{::jni::Array{jstring{}}, jboolean{}}}, ::jni::Method{ "assertObject1D", ::jni::Return{}, ::jni::Params{jint{}, ::jni::Array{kObjectTestHelperClass}}}, ::jni::Method{"assertObjectArrayOfNulls1D", ::jni::Return{}, ::jni::Params{::jni::Array{kObjectTestHelperClass}}}, - // Rank 2 verification. + // Rank 2 Verification. ::jni::Method{"assertBoolean2D", ::jni::Return{}, ::jni::Params{jboolean{}, ::jni::Array{}}}, ::jni::Method{"assertByte2D", ::jni::Return{}, diff --git a/javatests/com/jnibind/test/array_test_method_rank_1_jni.cc b/javatests/com/jnibind/test/array_test_method_rank_1_jni.cc index a530b61..f7ab0fb 100644 --- a/javatests/com/jnibind/test/array_test_method_rank_1_jni.cc +++ b/javatests/com/jnibind/test/array_test_method_rank_1_jni.cc @@ -41,10 +41,11 @@ template void GenericMethodTest(LocalArray local_arr, SpanType base, MethodNameLambda method_name_lambda) { // Simple lvalue pass through works as expected. - StaticRef{}(method_name_lambda(), base, local_arr); + StaticRef{}(method_name_lambda(), base, SpanType{1}, + local_arr); // Simple rvalue pass through works as expected. - StaticRef{}(method_name_lambda(), base, + StaticRef{}(method_name_lambda(), base, SpanType{1}, std::move(local_arr)); // Building a new array, and setting all the values by hand works. @@ -55,7 +56,8 @@ void GenericMethodTest(LocalArray local_arr, SpanType base, array_view.ptr()[i] = base + static_cast(i); } } - StaticRef{}(method_name_lambda(), base, new_array); + StaticRef{}(method_name_lambda(), base, SpanType{1}, + new_array); // You can pull the view multiple times. { @@ -73,7 +75,8 @@ void GenericMethodTest(LocalArray local_arr, SpanType base, val = base + i; i++; } - StaticRef{}(method_name_lambda(), base, new_array); + StaticRef{}(method_name_lambda(), base, SpanType{1}, + new_array); // You can build an array of null values and set the values manually. LocalArray arr_built_from_null{5}; @@ -84,7 +87,8 @@ void GenericMethodTest(LocalArray local_arr, SpanType base, val = base + j; j++; } - StaticRef{}(method_name_lambda(), base, new_array); + StaticRef{}(method_name_lambda(), base, SpanType{1}, + new_array); } extern "C" { @@ -160,7 +164,7 @@ Java_com_jnibind_test_ArrayTestMethodRank1_nativeStringTests( JNIEnv* env, jclass, jobjectArray object_array) { // Simple lvalue pass through works as expected. LocalArray local_arr{object_array}; - StaticRef{}("assertString1D", local_arr); + StaticRef{}("assertString1D", local_arr, true); // TODO(b/143908983): Currently not possible to write. // Simple rvalue pass through works as expected. @@ -176,7 +180,7 @@ Java_com_jnibind_test_ArrayTestMethodRank1_nativeStringTests( new_array.Set(0, LocalString{"Foo"}); new_array.Set(1, LocalString{"Baz"}); new_array.Set(2, LocalString{"Bar"}); - StaticRef{}("assertString1D", new_array); + StaticRef{}("assertString1D", new_array, true); // And it can be iterated over. std::size_t i = 0; @@ -186,7 +190,7 @@ Java_com_jnibind_test_ArrayTestMethodRank1_nativeStringTests( i++; } - StaticRef{}("assertString1D", validator_array); + StaticRef{}("assertString1D", validator_array, true); } JNIEXPORT void JNICALL