Index: base/android/jni_array_unittest.cc |
diff --git a/base/android/jni_array_unittest.cc b/base/android/jni_array_unittest.cc |
index 09de2429e560170e6f67e4b8bd7e6c963997af7c..245cd5082aa6201496a32dc7ccaeec43f363921d 100644 |
--- a/base/android/jni_array_unittest.cc |
+++ b/base/android/jni_array_unittest.cc |
@@ -45,6 +45,30 @@ TEST(JniArray, BasicConversions) { |
EXPECT_EQ(expected_vec, vectorFromBytes); |
} |
+void CheckBoolConversion(JNIEnv* env, |
+ const bool* bool_array, |
+ const size_t len, |
+ const ScopedJavaLocalRef<jbooleanArray>& booleans) { |
+ ASSERT_TRUE(booleans.obj()); |
+ |
+ jsize java_array_len = env->GetArrayLength(booleans.obj()); |
+ ASSERT_EQ(static_cast<jsize>(len), java_array_len); |
+ |
+ jboolean value; |
+ for (size_t i = 0; i < len; ++i) { |
+ env->GetBooleanArrayRegion(booleans.obj(), i, 1, &value); |
+ ASSERT_EQ(bool_array[i], value); |
+ } |
+} |
+ |
+TEST(JniArray, BoolConversions) { |
+ const bool kBools[] = {false, true, false}; |
+ const size_t kLen = arraysize(kBools); |
+ |
+ JNIEnv* env = AttachCurrentThread(); |
+ CheckBoolConversion(env, kBools, kLen, ToJavaBooleanArray(env, kBools, kLen)); |
+} |
+ |
void CheckIntConversion( |
JNIEnv* env, |
const int* int_array, |
@@ -113,6 +137,17 @@ void CheckIntArrayConversion(JNIEnv* env, |
} |
} |
+void CheckBoolArrayConversion(JNIEnv* env, |
+ ScopedJavaLocalRef<jbooleanArray> jbooleans, |
+ std::vector<bool> bool_vector, |
+ const size_t len) { |
+ jboolean value; |
+ for (size_t i = 0; i < len; ++i) { |
+ env->GetBooleanArrayRegion(jbooleans.obj(), i, 1, &value); |
+ ASSERT_EQ(bool_vector[i], value); |
+ } |
+} |
+ |
void CheckFloatConversion( |
JNIEnv* env, |
const float* float_array, |
@@ -142,6 +177,29 @@ TEST(JniArray, FloatConversions) { |
CheckFloatConversion(env, kFloats, kLen, ToJavaFloatArray(env, vec)); |
} |
+TEST(JniArray, JavaBooleanArrayToBoolVector) { |
+ const bool kBools[] = {false, true, false}; |
+ const size_t kLen = arraysize(kBools); |
+ |
+ JNIEnv* env = AttachCurrentThread(); |
+ ScopedJavaLocalRef<jbooleanArray> jbooleans(env, env->NewBooleanArray(kLen)); |
+ ASSERT_TRUE(jbooleans.obj()); |
+ |
+ for (size_t i = 0; i < kLen; ++i) { |
+ jboolean j = static_cast<jboolean>(kBools[i]); |
+ env->SetBooleanArrayRegion(jbooleans.obj(), i, 1, &j); |
+ ASSERT_FALSE(HasException(env)); |
+ } |
+ |
+ std::vector<bool> bools; |
+ JavaBooleanArrayToBoolVector(env, jbooleans.obj(), &bools); |
+ |
+ ASSERT_EQ(static_cast<jsize>(bools.size()), |
+ env->GetArrayLength(jbooleans.obj())); |
+ |
+ CheckBoolArrayConversion(env, jbooleans, bools, kLen); |
+} |
+ |
TEST(JniArray, JavaIntArrayToIntVector) { |
const int kInts[] = {0, 1, -1}; |
const size_t kLen = arraysize(kInts); |