Home | History | Annotate | Download | only in runtime

Lines Matching defs:env_

41     vm_->AttachCurrentThread(&env_, nullptr);
43 ScopedLocalRef<jclass> aioobe(env_,
44 env_->FindClass("java/lang/ArrayIndexOutOfBoundsException"));
46 aioobe_ = reinterpret_cast<jclass>(env_->NewGlobalRef(aioobe.get()));
48 ScopedLocalRef<jclass> ase(env_, env_->FindClass("java/lang/ArrayStoreException"));
50 ase_ = reinterpret_cast<jclass>(env_->NewGlobalRef(ase.get()));
52 ScopedLocalRef<jclass> sioobe(env_,
53 env_->FindClass("java/lang/StringIndexOutOfBoundsException"));
55 sioobe_ = reinterpret_cast<jclass>(env_->NewGlobalRef(sioobe.get()));
59 ScopedObjectAccess soa(env_);
60 EXPECT_TRUE(env_->ExceptionCheck())
62 jthrowable exception = env_->ExceptionOccurred();
64 env_->ExceptionClear();
65 EXPECT_TRUE(env_->IsInstanceOf(exception, exception_class));
70 env_->DeleteGlobalRef(aioobe_);
74 env_->DeleteGlobalRef(ase_);
78 env_->DeleteGlobalRef(sioobe_);
89 ScopedObjectAccess soa(env_);
96 EXPECT_NE(env_->FindClass(name), nullptr) << name;
97 EXPECT_FALSE(env_->ExceptionCheck()) << name;
102 EXPECT_EQ(env_->FindClass(name), nullptr) << name;
104 EXPECT_TRUE(env_->ExceptionCheck()) << name;
105 env_->ExceptionClear();
116 env_->FindClass(nullptr);
134 EXPECT_EQ(env_->FindClass("java.lang.String"), nullptr);
135 EXPECT_FALSE(env_->ExceptionCheck());
138 EXPECT_EQ(env_->FindClass("[Ljava.lang.String;"), nullptr);
139 EXPECT_FALSE(env_->ExceptionCheck());
172 jclass c = env_->FindClass("java/lang/String");
175 jfieldID fid = env_->GetFieldID(nullptr, "count", "I");
179 fid = env_->GetFieldID(c, nullptr, "I");
183 fid = env_->GetFieldID(c, "count", nullptr);
195 jclass c = env_->FindClass("java/lang/String");
198 jfieldID fid = env_->GetStaticFieldID(nullptr, "CASE_INSENSITIVE_ORDER", "Ljava/util/Comparator;");
202 fid = env_->GetStaticFieldID(c, nullptr, "Ljava/util/Comparator;");
206 fid = env_->GetStaticFieldID(c, "CASE_INSENSITIVE_ORDER", nullptr);
218 jmethodID method = env_->GetMethodID(nullptr, "<init>", "(Ljava/lang/String;)V");
222 jclass jlnsme = env_->FindClass("java/lang/NoSuchMethodError");
224 method = env_->GetMethodID(jlnsme, nullptr, "(Ljava/lang/String;)V");
228 method = env_->GetMethodID(jlnsme, "<init>", nullptr);
240 jmethodID method = env_->GetStaticMethodID(nullptr, "valueOf", "(I)Ljava/lang/String;");
244 jclass jlstring = env_->FindClass("java/lang/String");
245 method = env_->GetStaticMethodID(jlstring, nullptr, "(I)Ljava/lang/String;");
249 method = env_->GetStaticMethodID(jlstring, "valueOf", nullptr);
261 jclass c = env_->FindClass("java/lang/String");
263 jfieldID fid = env_->GetFieldID(c, "count", "I");
267 jobject field = env_->ToReflectedField(nullptr, fid, JNI_FALSE);
275 field = env_->ToReflectedField(c, nullptr, JNI_FALSE);
280 fid = env_->FromReflectedField(nullptr);
292 jclass c = env_->FindClass("java/lang/String");
294 jmethodID mid = env_->GetMethodID(c, "<init>", "()V");
298 jobject method = env_->ToReflectedMethod(nullptr, mid, JNI_FALSE);
306 method = env_->ToReflectedMethod(c, nullptr, JNI_FALSE);
310 mid = env_->FromReflectedMethod(method);
323 EXPECT_EQ(env_->RegisterNatives(nullptr, methods, 0), JNI_ERR);
329 jclass jlobject = env_->FindClass("java/lang/Object");
330 EXPECT_EQ(env_->RegisterNatives(jlobject, nullptr, 1), JNI_ERR);
334 EXPECT_EQ(env_->UnregisterNatives(nullptr), JNI_ERR);
346 jbooleanArray array = env_->NewBooleanArray(10);
348 EXPECT_EQ(env_->GetByteArrayElements(reinterpret_cast<jbyteArray>(array), &is_copy), nullptr);
352 EXPECT_EQ(env_->GetShortArrayElements(reinterpret_cast<jshortArray>(array), &is_copy), nullptr);
356 EXPECT_EQ(env_->GetCharArrayElements(reinterpret_cast<jcharArray>(array), &is_copy), nullptr);
360 EXPECT_EQ(env_->GetIntArrayElements(reinterpret_cast<jintArray>(array), &is_copy), nullptr);
364 EXPECT_EQ(env_->GetLongArrayElements(reinterpret_cast<jlongArray>(array), &is_copy), nullptr);
368 EXPECT_EQ(env_->GetFloatArrayElements(reinterpret_cast<jfloatArray>(array), &is_copy), nullptr);
372 EXPECT_EQ(env_->GetDoubleArrayElements(reinterpret_cast<jdoubleArray>(array), &is_copy), nullptr);
376 jbyteArray array2 = env_->NewByteArray(10);
377 EXPECT_EQ(env_
382 jobject object = env_->NewStringUTF("Test String");
383 EXPECT_EQ(env_->GetBooleanArrayElements(reinterpret_cast<jbooleanArray>(object), &is_copy),
396 jbooleanArray array = env_->NewBooleanArray(10);
399 jboolean* elements = env_->GetBooleanArrayElements(array, &is_copy);
401 env_->ReleaseByteArrayElements(reinterpret_cast<jbyteArray>(array),
406 env_->ReleaseShortArrayElements(reinterpret_cast<jshortArray>(array),
411 env_->ReleaseCharArrayElements(reinterpret_cast<jcharArray>(array),
416 env_->ReleaseIntArrayElements(reinterpret_cast<jintArray>(array),
421 env_->ReleaseLongArrayElements(reinterpret_cast<jlongArray>(array),
426 env_->ReleaseFloatArrayElements(reinterpret_cast<jfloatArray>(array),
431 env_->ReleaseDoubleArrayElements(reinterpret_cast<jdoubleArray>(array),
438 env_->ReleaseBooleanArrayElements(array, elements, 0);
441 jbyteArray array = env_->NewByteArray(10);
443 jbyte* elements = env_->GetByteArrayElements(array, &is_copy);
445 env_->ReleaseBooleanArrayElements(reinterpret_cast<jbooleanArray>(array),
450 jobject object = env_->NewStringUTF("Test String");
451 env_->ReleaseBooleanArrayElements(reinterpret_cast<jbooleanArray>(object),
459 env_->ReleaseByteArrayElements(array, elements, 0);
468 jobject object = env_->NewStringUTF("Test String");
470 void* elements = env_->GetPrimitiveArrayCritical(reinterpret_cast<jarray>(object), &is_copy);
473 env_->ReleasePrimitiveArrayCritical(reinterpret_cast<jarray>(object), elements, 0);
484 jbooleanArray array = env_->NewBooleanArray(kLength);
487 env_->GetByteArrayRegion(reinterpret_cast<jbyteArray>(array), 0, kLength,
492 env_->GetShortArrayRegion(reinterpret_cast<jshortArray>(array), 0, kLength,
497 env_->GetCharArrayRegion(reinterpret_cast<jcharArray>(array), 0, kLength,
502 env_->GetIntArrayRegion(reinterpret_cast<jintArray>(array), 0, kLength,
507 env_->GetLongArrayRegion(reinterpret_cast<jlongArray>(array), 0, kLength,
512 env_->GetFloatArrayRegion(reinterpret_cast<jfloatArray>(array), 0, kLength,
517 env_->GetDoubleArrayRegion(reinterpret_cast<jdoubleArray>(array), 0, kLength,
522 jbyteArray array2 = env_->NewByteArray(10);
523 env_->GetBooleanArrayRegion(reinterpret_cast<jbooleanArray>(array2), 0, kLength,
528 jobject object = env_->NewStringUTF("Test String");
529 env_->GetBooleanArrayRegion(reinterpret_cast<jbooleanArray>(object), 0, kLength,
542 jbooleanArray array = env_->NewBooleanArray(kLength);
545 env_->SetByteArrayRegion(reinterpret_cast<jbyteArray>(array), 0, kLength,
550 env_->SetShortArrayRegion(reinterpret_cast<jshortArray>(array), 0, kLength,
555 env_->SetCharArrayRegion(reinterpret_cast<jcharArray>(array), 0, kLength,
560 env_->SetIntArrayRegion(reinterpret_cast<jintArray>(array), 0, kLength,
565 env_->SetLongArrayRegion(reinterpret_cast<jlongArray>(array), 0, kLength,
570 env_->SetFloatArrayRegion(reinterpret_cast<jfloatArray>(array), 0, kLength,
575 env_->SetDoubleArrayRegion(reinterpret_cast<jdoubleArray>(array), 0, kLength,
580 jbyteArray array2 = env_->NewByteArray(10);
581 env_->SetBooleanArrayRegion(reinterpret_cast<jbooleanArray>(array2), 0, kLength,
586 jobject object = env_->NewStringUTF("Test String");
587 env_->SetBooleanArrayRegion(reinterpret_cast<jbooleanArray>(object), 0, kLength,
599 jclass element_class = env_->FindClass("java/lang/String");
602 env_->NewObjectArray(-1, element_class, nullptr);
605 env_->NewObjectArray(std::numeric_limits<jint>::min(), element_class, nullptr);
636 env_ = Thread::Current()->GetJniEnv();
637 jklass_ = env_->FindClass("MyClassNatives");
641 jmethod_ = env_->GetStaticMethodID(jklass_, method_name, method_sig);
643 jmethod_ = env_->GetMethodID(jklass_, method_name, method_sig);
649 ASSERT_EQ(JNI_OK, env_->RegisterNatives(jklass_, methods, 1))
652 env_->UnregisterNatives(jklass_);
655 jmethodID constructor = env_->GetMethodID(jklass_, "<init>", "()V");
656 jobj_ = env_->NewObject(jklass_, constructor);
661 JNIEnv* env_;
673 jclass c = env_->FindClass("java/lang/String");
675 jobject o = env_
679 ASSERT_TRUE(env_->IsInstanceOf(o, c));
682 ASSERT_EQ(0, env_->GetIntField(o, env_->GetFieldID(c, "count", "I")));
686 ASSERT_EQ(JNI_VERSION_1_6, env_->GetVersion());
698 jclass jlnsfe = env_->FindClass("java/lang/NoSuchFieldError");
700 jclass c = env_->FindClass("java/lang/String");
704 jfieldID fid = env_->GetFieldID(c, "count", "J");
709 fid = env_->GetFieldID(c, "count", "Lrod/jane/freddy;");
714 fid = env_->GetFieldID(c, "Count", "I");
719 fid = env_->GetFieldID(c, "count", "I");
721 EXPECT_FALSE(env_->ExceptionCheck());
724 c = env_->FindClass("java/lang/StringBuilder");
725 fid = env_->GetFieldID(c, "count", "I");
728 EXPECT_FALSE(env_->ExceptionCheck());
731 fid = env_->GetFieldID(c, "CASE_INSENSITIVE_ORDER", "Ljava/util/Comparator;");
741 jclass jlnsfe = env_->FindClass("java/lang/NoSuchFieldError");
743 jclass c = env_->FindClass("java/lang/String");
747 jfieldID fid = env_->GetStaticFieldID(c, "CASE_INSENSITIVE_ORDER", "J");
752 fid = env_->GetStaticFieldID(c, "CASE_INSENSITIVE_ORDER", "Lrod/jane/freddy;");
757 fid = env_->GetStaticFieldID(c, "cASE_INSENSITIVE_ORDER", "Ljava/util/Comparator;");
762 fid = env_->GetStaticFieldID(c, "CASE_INSENSITIVE_ORDER", "Ljava/util/Comparator;");
765 EXPECT_FALSE(env_->ExceptionCheck());
768 fid = env_->GetStaticFieldID(c, "count", "I");
778 jclass jlobject = env_->FindClass("java/lang/Object");
779 jclass jlstring = env_->FindClass("java/lang/String");
780 jclass jlnsme = env_->FindClass("java/lang/NoSuchMethodError");
781 jclass jncrbc = env_->FindClass("java/nio/channels/ReadableByteChannel");
784 ASSERT_FALSE(env_->ExceptionCheck());
788 jmethodID method = env_->GetMethodID(jlobject, "foo", "()V");
793 method = env_->GetMethodID(jlobject, "equals", "(Ljava/lang/Object;)Z");
795 EXPECT_FALSE(env_->ExceptionCheck());
799 method = env_->GetMethodID(jlstring, "valueOf", "(I)Ljava/lang/String;");
804 method = env_->GetMethodID(jlnsme, "<init>", "(Ljava/lang/String;)V");
806 EXPECT_FALSE(env_->ExceptionCheck());
809 method = env_->GetMethodID(jncrbc, "close", "()V");
811 EXPECT_FALSE(env_->ExceptionCheck());
819 jclass jlobject = env_->FindClass("java/lang/Object");
823 method = env_->GetMethodID(jlobject, "<init>", "()V");
825 EXPECT_FALSE(env_->ExceptionCheck());
829 env_->CallVoidMethod(nullptr, method);
834 jclass jlobject = env_->FindClass("java/lang/Object");
835 jclass jlnsme = env_->FindClass("java/lang/NoSuchMethodError");
838 ASSERT_FALSE(env_->ExceptionCheck());
842 jmethodID method = env_->GetStaticMethodID(jlobject, "foo", "()V");
848 method = env_->GetStaticMethodID(jlobject, "equals", "(Ljava/lang/Object;)Z");
853 jclass jlstring = env_->FindClass("java/lang/String");
854 method = env_->GetStaticMethodID(jlstring, "valueOf", "(I)Ljava/lang/String;");
856 EXPECT_FALSE(env_->ExceptionCheck());
864 jclass jlrField = env_->FindClass("java/lang/reflect/Field");
865 jclass c = env_->FindClass("java/lang/String");
867 jfieldID fid = env_->GetFieldID(c, "count", "I");
870 jobject field = env_->ToReflectedField(c, fid, JNI_FALSE);
874 env_->DeleteLocalRef(env_->ToReflectedField(c, fid, JNI_FALSE));
877 ASSERT_TRUE(env_->IsInstanceOf(field, jlrField));
879 jfieldID fid2 = env_->FromReflectedField(field);
882 jstring s = env_->NewStringUTF("poop");
883 ASSERT_EQ(4, env_->GetIntField(s, fid2));
891 jclass jlrMethod = env_->FindClass("java/lang/reflect/Method");
893 jclass jlrConstructor = env_->FindClass("java/lang/reflect/Constructor");
895 jclass c = env_->FindClass("java/lang/String");
898 jmethodID mid = env_->GetMethodID(c, "<init>", "()V");
901 jobject method = env_->ToReflectedMethod(c, mid, JNI_FALSE);
905 env_->DeleteLocalRef(env_->ToReflectedMethod(c, mid, JNI_FALSE));
908 ASSERT_TRUE(env_->IsInstanceOf(method, jlrConstructor));
910 jmethodID mid2 = env_->FromReflectedMethod(method);
913 jstring s = reinterpret_cast<jstring>(env_->AllocObject(c));
915 env_->CallVoidMethod(s, mid2);
916 ASSERT_EQ(JNI_FALSE, env_->ExceptionCheck());
917 env_->ExceptionClear();
919 mid = env_->GetMethodID(c, "length", "()I");
922 method = env_->ToReflectedMethod(c, mid, JNI_FALSE);
924 ASSERT_TRUE(env_->IsInstanceOf(method, jlrMethod));
926 mid2 = env_->FromReflectedMethod(method);
929 s = env_->NewStringUTF("poop");
931 ASSERT_EQ(4, env_->CallIntMethod(s, mid2));
943 jclass jlobject = env_->FindClass("java/lang/Object");
944 jclass jlnsme = env_->FindClass("java/lang/NoSuchMethodError");
948 ASSERT_FALSE(env_->ExceptionCheck());
956 EXPECT_EQ(env_->RegisterNatives(jlobject, methods, 1), JNI_ERR);
963 EXPECT_EQ(env_->RegisterNatives(jlobject, methods, 1), JNI_ERR);
970 EXPECT_EQ(env_->RegisterNatives(jlobject, methods, 1), JNI_ERR);
977 EXPECT_EQ(env_->RegisterNatives(jlobject, methods, 1), JNI_ERR);
984 EXPECT_EQ(env_->RegisterNatives(jlobject, methods, 1), JNI_ERR);
992 EXPECT_EQ(env_->RegisterNatives(jlobject, methods, 1), JNI_OK);
994 EXPECT_FALSE(env_->ExceptionCheck());
995 EXPECT_EQ(env_->UnregisterNatives(jlobject), JNI_OK);
1000 EXPECT_EQ(env_->RegisterNatives(jlobject, methods, 0), JNI_OK);
1002 EXPECT_FALSE(env_->ExceptionCheck());
1003 EXPECT_EQ(env_->UnregisterNatives(jlobject), JNI_OK);
1009 EXPECT_EQ(env_->RegisterNatives(jlobject, methods, i), JNI_ERR);
1012 EXPECT_FALSE(env_->ExceptionCheck());
1015 EXPECT_EQ(env_->UnregisterNatives(jlnsme), JNI_OK);
1032 down_cast<JNIEnvExt*>(env_)->SetCheckJniEnabled(false); \
1034 EXPECT_EQ(env_->new_fn(-1), nullptr); \
1036 EXPECT_EQ(env_->new_fn(std::numeric_limits<jint>::min()), nullptr); \
1039 EXPECT_EQ(0, env_->GetArrayLength(nullptr)); \
1041 env_->get_region_fn(nullptr, 0, 0, nullptr); \
1043 env_->set_region_fn(nullptr, 0, 0, nullptr); \
1045 env_->get_elements_fn(nullptr, nullptr); \
1047 env_->release_elements_fn(nullptr, nullptr, 0); \
1050 scalar_type ## Array a = env_->new_fn(size); \
1051 env_->get_region_fn(a, 0, size, nullptr); \
1053 env_->set_region_fn(a, 0, size, nullptr); \
1055 down_cast<JNIEnvExt*>(env_)->SetCheckJniEnabled(true); \
1058 scalar_type ## Array a = env_->new_fn(size); \
1060 EXPECT_TRUE(env_->IsInstanceOf(a, env_->FindClass(expected_class_descriptor))); \
1061 EXPECT_EQ(size, env_->GetArrayLength(a)); \
1065 env_->get_region_fn(a, -1, 1, nullptr); \
1067 env_->set_region_fn(a, -1, 1, nullptr); \
1071 env_->get_region_fn(a, 0, -1, nullptr); \
1073 env_->set_region_fn(a, 0, -1, nullptr); \
1077 env_->get_region_fn(a, size - 1, size, nullptr); \
1079 env_->set_region_fn(a, size - 1, size, nullptr); \
1083 env_->get_region_fn(a, 0x7fffffff, 0x7fffffff, nullptr); \
1085 env_->set_region_fn(a, 0x7fffffff, 0x7fffffff, nullptr); \
1089 env_->get_region_fn(a, 2, 0, nullptr); \
1091 env_->get_region_fn(a, 123, 0, nullptr); \
1095 env_->set_region_fn(a, 2, 0, nullptr); \
1097 env_->set_region_fn(a, 123, 0, nullptr); \
1107 env_->set_region_fn(a, 0, size, &src_buf[0]); \
1109 env_->get_region_fn(a, 1, size - 2, &dst_buf[1]); \
1113 env_->get_region_fn(a, 0, 1, &dst_buf[0]); \
1114 env_->get_region_fn(a, size - 1, 1, &dst_buf[size - 1]); \
1118 env_->get_region_fn(a, 0, size, &dst_buf[0]); \
1122 void* v = env_->GetPrimitiveArrayCritical(a, nullptr); \
1125 env_->ReleasePrimitiveArrayCritical(a, v, 0); \
1127 scalar_type* xs = env_->get_elements_fn(a, nullptr); \
1130 env_->release_elements_fn(a, xs, 0); \
1191 jclass element_class = env_->FindClass("java/lang/String");
1193 jclass array_class = env_->FindClass("[Ljava/lang/String;");
1196 jobjectArray a = env_->NewObjectArray(0, element_class, nullptr);
1198 EXPECT_TRUE(env_->IsInstanceOf(a, array_class));
1199 EXPECT_EQ(0, env_->GetArrayLength(a));
1201 a = env_->NewObjectArray(1, element_class, nullptr);
1203 EXPECT_TRUE(env_->IsInstanceOf(a, array_class));
1204 EXPECT_EQ(1, env_->GetArrayLength(a));
1205 EXPECT_TRUE(env_->IsSameObject(env_->GetObjectArrayElement(a, 0), nullptr));
1222 env_->NewObjectArray(0, nullptr, nullptr);
1225 env_->NewObjectArray(1, primitive_class, nullptr);
1231 env_->NewObjectArray(0, nullptr, nullptr);
1234 env_->NewObjectArray(1, primitive_class, nullptr);
1242 jclass element_class = env_->FindClass("java/lang/String");
1244 jclass array_class = env_->FindClass("[Ljava/lang/String;");
1247 jstring s = env_->NewStringUTF("poop");
1248 jobjectArray a = env_->NewObjectArray(2, element_class, s);
1250 EXPECT_TRUE(env_->IsInstanceOf(a, array_class));
1251 EXPECT_EQ(2, env_->GetArrayLength(a));
1252 EXPECT_TRUE(env_->IsSameObject(env_->GetObjectArrayElement(a, 0), s));
1253 EXPECT_TRUE(env_->IsSameObject(env_->GetObjectArrayElement(a, 1), s));
1257 env_->NewObjectArray(2, element_class, a);
1266 EXPECT_EQ(0, env_->GetArrayLength(nullptr));
1269 EXPECT_EQ(JNI_ERR, env_->GetArrayLength(nullptr));
1275 jclass string_class = env_->FindClass("java/lang/String");
1277 jclass class_class = env_->FindClass("java/lang/Class");
1280 jstring s = env_->NewStringUTF("poop");
1281 jclass c = env_->GetObjectClass(s);
1282 ASSERT_TRUE(env_->IsSameObject(string_class, c));
1284 jclass c2 = env_->GetObjectClass(c);
1285 ASSERT_TRUE(env_->IsSameObject(class_class, env_->GetObjectClass(c2)));
1289 EXPECT_EQ(env_->GetObjectClass(nullptr), nullptr);
1294 jclass object_class = env_->FindClass("java/lang/Object");
1296 jclass string_class = env_->FindClass("java/lang/String");
1298 jclass runnable_interface = env_->FindClass("java/lang/Runnable");
1300 ASSERT_TRUE(env_->IsSameObject(object_class, env_->GetSuperclass(string_class)));
1301 ASSERT_EQ(env_->GetSuperclass(object_class), nullptr);
1302 ASSERT_EQ(env_->GetSuperclass(runnable_interface), nullptr);
1307 EXPECT_EQ(env_->GetSuperclass(nullptr), nullptr);
1310 EXPECT_EQ(env_->GetSuperclass(nullptr), nullptr);
1316 jclass object_class = env_->FindClass("java/lang/Object");
1318 jclass string_class = env_->FindClass("java/lang/String");
1323 ASSERT_TRUE(env_->IsAssignableFrom(string_class, object_class));
1324 ASSERT_FALSE(env_->IsAssignableFrom(object_class, string_class));
1326 jclass charsequence_interface = env_->FindClass("java/lang/CharSequence");
1331 ASSERT_TRUE(env_->IsAssignableFrom(string_class, charsequence_interface));
1332 ASSERT_FALSE(env_->IsAssignableFrom(charsequence_interface, string_class));
1335 jclass string_array_class = env_->FindClass("[Ljava/lang/String;");
1337 jclass object_array_class = env_->FindClass("[Ljava/lang/Object;");
1339 ASSERT_TRUE(env_->IsAssignableFrom(string_array_class, object_array_class));
1340 ASSERT_FALSE(env_->IsAssignableFrom(object_array_class, string_array_class));
1347 EXPECT_EQ(env_->IsAssignableFrom(nullptr, string_class), JNI_FALSE);
1349 EXPECT_EQ(env_->IsAssignableFrom(object_class, nullptr), JNI_FALSE);
1352 EXPECT_EQ(env_->IsAssignableFrom(nullptr, string_class), JNI_FALSE);
1354 EXPECT_EQ(env_->IsAssignableFrom(object_class, nullptr), JNI_FALSE);
1360 jclass local = env_->FindClass("java/lang/Object");
1362 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(local));
1364 jobject global = env_->NewGlobalRef(local);
1365 EXPECT_EQ(JNIGlobalRefType, env_->GetObjectRefType(global));
1367 jweak weak_global = env_->NewWeakGlobalRef(local);
1368 EXPECT_EQ(JNIWeakGlobalRefType, env_->GetObjectRefType(weak_global));
1373 EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(invalid));
1380 EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(nullptr));
1387 jclass java_lang_Class = env_->FindClass("java/lang/Class");
1389 jobjectArray local_ref = env_->NewObjectArray(1, java_lang_Class, nullptr);
1391 jweak weak_global = env_->NewWeakGlobalRef(local_ref);
1393 env_->DeleteLocalRef(local_ref);
1395 jobject new_global_ref = env_->NewGlobalRef(weak_global);
1397 jobject new_local_ref = env_->NewLocalRef(weak_global);
1402 EXPECT_EQ(env_->NewStringUTF(nullptr), nullptr);
1405 s = env_->NewStringUTF("");
1407 EXPECT_EQ(0, env_->GetStringLength(s));
1408 EXPECT_EQ(0, env_->GetStringUTFLength(s));
1409 s = env_->NewStringUTF("hello");
1411 EXPECT_EQ(5, env_->GetStringLength(s));
1412 EXPECT_EQ(5, env_->GetStringUTFLength(s));
1415 s = env_->NewStringUTF("\xed\xa0\x81\xed\xb0\x80");
1417 EXPECT_EQ(2, env_->GetStringLength(s));
1420 EXPECT_EQ(4, env_->GetStringUTFLength(s));
1421 const char* chars = env_->GetStringUTFChars(s, nullptr);
1423 env_->ReleaseStringUTFChars(s, chars);
1426 const jchar* jchars = env_->GetStringChars(s, nullptr);
1429 env_->ReleaseStringChars(s, jchars);
1432 s = env_->NewStringUTF("\xed\xa0\x81\xed\xb0\x80 \xf0\x9f\x8f\xa0");
1437 EXPECT_EQ(5, env_->GetStringLength(s));
1438 jchars = env_->GetStringChars(s, nullptr);
1445 env_->ReleaseStringChars(s, jchars);
1447 EXPECT_EQ(9, env_->GetStringUTFLength(s));
1448 chars = env_->GetStringUTFChars(s, nullptr);
1450 env_->ReleaseStringUTFChars(s, chars);
1454 s = env_->NewStringUTF("\x24 \xc2\xa2 \xe2\x82\xac \xf0\x9f\x8f\xa0");
1456 EXPECT_EQ(8, env_->GetStringLength(s));
1457 EXPECT_EQ(13, env_->GetStringUTFLength(s));
1463 s = env_->NewString(chars, 0);
1465 EXPECT_EQ(0, env_->GetStringLength(s));
1466 EXPECT_EQ(0, env_->GetStringUTFLength(s));
1467 s = env_->NewString(chars, 2);
1469 EXPECT_EQ(2, env_->GetStringLength(s));
1470 EXPECT_EQ(2, env_->GetStringUTFLength(s));
1476 jstring s = env_->NewString(nullptr, 0);
1478 EXPECT_EQ(0, env_->GetStringLength(s));
1483 env_->NewString(nullptr, 1);
1490 env_->NewString(nullptr, -1);
1492 env_->NewString(nullptr, std::numeric_limits<jint>::min());
1495 env_->NewString(nullptr, -1);
1497 env_->NewString(nullptr, std::numeric_limits<jint>::min());
1507 jstring s = env_->NewStringUTF("hello");
1510 env_->GetStringRegion(s, -1, 0, nullptr);
1512 env_->GetStringRegion(s, 0, -1, nullptr);
1514 env_->GetStringRegion(s, 0, 10, nullptr);
1516 env_->GetStringRegion(s, 10, 1, nullptr);
1519 env_->GetStringRegion(s, 0x7fffffff, 0x7fffffff, nullptr);
1523 env_->GetStringRegion(s, 1, 2, &chars[1]);
1530 env_->GetStringRegion(s, 2, 0, nullptr);
1532 env_->GetStringRegion(s, 123, 0, nullptr);
1535 env_->GetStringUTFRegion(s, -1, 0, nullptr);
1537 env_->GetStringUTFRegion(s, 0, -1, nullptr);
1539 env_->GetStringUTFRegion(s, 0, 10, nullptr);
1541 env_->GetStringUTFRegion(s, 10, 1, nullptr);
1544 env_->GetStringUTFRegion(s, 0x7fffffff, 0x7fffffff, nullptr);
1548 env_->GetStringUTFRegion(s, 1, 2, &bytes[1]);
1555 env_->GetStringUTFRegion(s, 2, 0, nullptr);
1557 env_->GetStringUTFRegion(s, 123, 0, nullptr);
1566 EXPECT_EQ(env_->GetStringUTFChars(nullptr, nullptr), nullptr);
1571 EXPECT_EQ(env_->GetStringUTFChars(nullptr, nullptr), nullptr);
1576 jstring s = env_->NewStringUTF("hello");
1579 const char* utf = env_->GetStringUTFChars(s, nullptr);
1581 env_->ReleaseStringUTFChars(s, utf);
1584 utf = env_->GetStringUTFChars(s, &is_copy);
1587 env_->ReleaseStringUTFChars(s, utf);
1591 jstring s = env_->NewStringUTF("hello");
1592 ScopedObjectAccess soa(env_);
1597 const jchar* chars = env_->GetStringChars(s, nullptr);
1603 env_->ReleaseStringChars(s, chars);
1606 chars = env_->GetStringChars(s, &is_copy);
1617 env_->ReleaseStringChars(s, chars);
1621 jstring s = env_->NewStringUTF("hello");
1625 const jchar* chars = env_->GetStringCritical(s, nullptr);
1631 env_->ReleaseStringCritical(s, chars);
1634 chars = env_->GetStringCritical(s, &is_copy);
1641 env_->ReleaseStringCritical(s, chars);
1645 jclass java_lang_Class = env_->FindClass("java/lang/Class");
1648 jobjectArray array = env_->NewObjectArray(1, java_lang_Class, nullptr);
1650 EXPECT_EQ(env_->GetObjectArrayElement(array, 0), nullptr);
1651 env_->SetObjectArrayElement(array, 0, java_lang_Class);
1652 EXPECT_TRUE(env_->IsSameObject(env_->GetObjectArrayElement(array, 0), java_lang_Class));
1655 env_->SetObjectArrayElement(array, -1, java_lang_Class);
1659 env_->SetObjectArrayElement(array, 1, java_lang_Class);
1663 env_->SetObjectArrayElement(array, 0, env_->NewStringUTF("not a jclass!"));
1669 EXPECT_EQ(nullptr, env_->GetObjectArrayElement(nullptr, 0));
1671 env_->SetObjectArrayElement(nullptr, 0, nullptr);
1674 EXPECT_EQ(nullptr, env_->GetObjectArrayElement(nullptr, 0));
1676 env_->SetObjectArrayElement(nullptr, 0, nullptr);
1683 jfieldID fid = env_->GetStaticFieldID(c, field_name, sig); \
1685 env_->SetStatic ## type ## Field(c, fid, value1); \
1686 expect_eq(value1, env_->GetStatic ## type ## Field(c, fid)); \
1687 env_->SetStatic ## type ## Field(c, fid, value2); \
1688 expect_eq(value2, env_->GetStatic ## type ## Field(c, fid)); \
1693 env_->GetStatic ## type ## Field(nullptr, fid); \
1694 env_->SetStatic ## type ## Field(nullptr, fid, value1); \
1697 env_->GetStatic ## type ## Field(c, nullptr); \
1699 env_->SetStatic ## type ## Field(c, nullptr, value1); \
1703 env_->GetStatic ## type ## Field(nullptr, fid); \
1705 env_->SetStatic ## type ## Field(nullptr, fid, value1); \
1707 env_->GetStatic ## type ## Field(c, nullptr); \
1709 env_->SetStatic ## type ## Field(c, nullptr, value1); \
1716 jfieldID fid = env_->GetFieldID(c, field_name, sig); \
1718 env_->Set ## type ## Field(instance, fid, value1); \
1719 expect_eq(value1, env_->Get ## type ## Field(instance, fid)); \
1720 env_->Set ## type ## Field(instance, fid, value2); \
1721 expect_eq(value2, env_->Get ## type ## Field(instance, fid)); \
1725 env_->Get ## type ## Field(nullptr, fid); \
1727 env_->Set ## type ## Field(nullptr, fid, value1); \
1729 env_->Get ## type ## Field(instance, nullptr); \
1731 env_->Set ## type ## Field(instance, nullptr, value1); \
1734 env_->Get ## type ## Field(nullptr, fid); \
1736 env_->Set ## type ## Field(nullptr, fid, value1); \
1738 env_->Get ## type ## Field(instance, nullptr); \
1740 env_->Set ## type ## Field(instance, nullptr, value1); \
1752 jclass c = env_->FindClass("AllFields");
1754 jobject o = env_->AllocObject(c);
1781 jclass c = env_->FindClass("AllFields");
1783 jobject o = env_->AllocObject(c);
1786 jstring s1 = env_->NewStringUTF("hello");
1788 jstring s2 = env_->NewStringUTF("world");
1791 jfieldID s_fid = env_->GetStaticFieldID(c, "sObject", "Ljava/lang/Object;");
1793 jfieldID i_fid = env_->GetFieldID(c, "iObject", "Ljava/lang/Object;");
1796 env_->SetStaticObjectField(c, s_fid, s1);
1797 ASSERT_TRUE(env_->IsSameObject(s1, env_->GetStaticObjectField(c, s_fid)));
1798 env_->SetStaticObjectField(c, s_fid, s2);
1799 ASSERT_TRUE(env_->IsSameObject(s2, env_->GetStaticObjectField(c, s_fid)));
1801 env_->SetObjectField(o, i_fid, s1);
1802 ASSERT_TRUE(env_->IsSameObject(s1, env_->GetObjectField(o, i_fid)));
1803 env_->SetObjectField(o, i_fid, s2);
1804 ASSERT_TRUE(env_->IsSameObject(s2, env_->GetObjectField(o, i_fid)));
1808 EXPECT_EQ(env_->NewLocalRef(nullptr), nullptr);
1812 jstring s = env_->NewStringUTF("");
1814 jobject o = env_->NewLocalRef(s);
1818 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(o));
1822 env_->DeleteLocalRef(nullptr);
1829 jstring s = env_->NewStringUTF("");
1831 env_->DeleteLocalRef(s);
1838 env_->DeleteLocalRef(s);
1842 env_->DeleteLocalRef(s);
1848 s = env_->NewStringUTF("");
1850 jobject o = env_->NewLocalRef(s);
1853 env_->DeleteLocalRef(s);
1854 env_->DeleteLocalRef(o);
1862 ASSERT_EQ(JNI_OK, env_->PushLocalFrame(0));
1863 env_->PopLocalFrame(nullptr);
1869 ASSERT_EQ(JNI_ERR, env_->PushLocalFrame(-1));
1872 ASSERT_EQ(JNI_ERR, env_->PushLocalFrame(8192));
1879 jobject original = env_->NewStringUTF("");
1884 ScopedObjectAccess soa(env_);
1886 ASSERT_EQ(JNI_OK, env_->PushLocalFrame(4));
1887 outer = env_->NewLocalRef(original);
1890 ASSERT_EQ(JNI_OK, env_->PushLocalFrame(4));
1891 inner1 = env_->NewLocalRef(outer);
1892 inner2 = env_->NewStringUTF("survivor");
1893 EXPECT_NE(env_->PopLocalFrame(inner2), nullptr);
1896 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(original));
1897 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(outer));
1900 EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(inner1));
1908 EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(inner2));
1912 EXPECT_EQ(env_->PopLocalFrame(nullptr), nullptr);
1914 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(original));
1916 EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(outer));
1918 EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(inner1));
1920 EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(inner2));
1925 EXPECT_EQ(env_->NewGlobalRef(nullptr), nullptr);
1929 jstring s = env_->NewStringUTF("");
1931 jobject o = env_->NewGlobalRef(s);
1935 EXPECT_EQ(env_->GetObjectRefType(o), JNIGlobalRefType);
1939 env_->DeleteGlobalRef(nullptr);
1946 jstring s = env_
1949 jobject o = env_->NewGlobalRef(s);
1951 env_->DeleteGlobalRef(o);
1958 env_->DeleteGlobalRef(o);
1962 env_->DeleteGlobalRef(o);
1968 jobject o1 = env_->NewGlobalRef(s);
1970 jobject o2 = env_->NewGlobalRef(s);
1973 env_->DeleteGlobalRef(o1);
1974 env_->DeleteGlobalRef(o2);
1978 EXPECT_EQ(env_->NewWeakGlobalRef(nullptr), nullptr);
1982 jstring s = env_->NewStringUTF("");
1984 jobject o = env_->NewWeakGlobalRef(s);
1988 EXPECT_EQ(env_->GetObjectRefType(o), JNIWeakGlobalRefType);
1992 env_->DeleteWeakGlobalRef(nullptr);
1999 jstring s = env_->NewStringUTF("");
2002 jobject o = env_->NewWeakGlobalRef(s);
2004 env_->DeleteWeakGlobalRef(o);
2011 env_->DeleteWeakGlobalRef(o);
2015 env_->DeleteWeakGlobalRef(o);
2021 jobject o1 = env_->NewWeakGlobalRef(s);
2023 jobject o2 = env_->NewWeakGlobalRef(s);
2026 env_->DeleteWeakGlobalRef(o1);
2027 env_->DeleteWeakGlobalRef(o2);
2032 env_->ExceptionClear();
2033 env_->ExceptionDescribe();
2037 jclass exception_class = env_->FindClass("java/lang/RuntimeException");
2039 jthrowable exception = reinterpret_cast<jthrowable>(env_->AllocObject(exception_class));
2042 EXPECT_EQ(JNI_OK, env_->Throw(exception));
2043 EXPECT_TRUE(env_->ExceptionCheck());
2044 jthrowable thrown_exception = env_->ExceptionOccurred();
2045 env_->ExceptionClear();
2046 EXPECT_TRUE(env_->IsSameObject(exception, thrown_exception));
2050 EXPECT_EQ(JNI_ERR, env_->Throw(nullptr));
2053 EXPECT_EQ(JNI_ERR, env_->Throw(nullptr));
2059 jclass exception_class = env_->FindClass("java/lang/RuntimeException");
2064 EXPECT_EQ(JNI_OK, env_->ThrowNew(exception_class, "hello world"));
2065 EXPECT_TRUE(env_->ExceptionCheck());
2066 thrown_exception = env_->ExceptionOccurred();
2067 env_->ExceptionClear();
2068 EXPECT_TRUE(env_->IsInstanceOf(thrown_exception, exception_class));
2070 EXPECT_EQ(JNI_OK, env_->ThrowNew(exception_class, nullptr));
2071 EXPECT_TRUE(env_->ExceptionCheck());
2072 thrown_exception = env_->ExceptionOccurred();
2073 env_->ExceptionClear();
2074 EXPECT_TRUE(env_->IsInstanceOf(thrown_exception, exception_class));
2079 EXPECT_EQ(JNI_ERR, env_->ThrowNew(nullptr, nullptr));
2082 EXPECT_EQ(JNI_ERR, env_->ThrowNew(nullptr, nullptr));
2104 jclass buffer_class = env_->FindClass("java/nio/Buffer");
2108 jobject buffer = env_->NewDirectByteBuffer(bytes, sizeof(bytes));
2110 ASSERT_TRUE(env_->IsInstanceOf(buffer, buffer_class));
2111 ASSERT_EQ(env_->GetDirectBufferAddress(buffer), bytes);
2112 ASSERT_EQ(env_->GetDirectBufferCapacity(buffer), static_cast<jlong>(sizeof(bytes)));
2116 env_->NewDirectByteBuffer(bytes, static_cast<jlong>(INT_MAX) + 1);
2126 jclass object_class = env_->FindClass("java/lang/Object");
2128 jobject object = env_->AllocObject(object_class);
2132 jclass imse_class = env_->FindClass("java/lang/IllegalMonitorStateException");
2138 env_->MonitorExit(object);
2139 EXPECT_TRUE(env_->ExceptionCheck());
2140 thrown_exception = env_->ExceptionOccurred();
2141 env_->ExceptionClear();
2142 EXPECT_TRUE(env_->IsInstanceOf(thrown_exception, imse_class));
2145 env_->MonitorEnter(object);
2146 EXPECT_FALSE(env_->ExceptionCheck());
2148 env_->MonitorExit(object);
2149 EXPECT_FALSE(env_->ExceptionCheck());
2154 env_->MonitorEnter(object);
2155 EXPECT_FALSE(env_->ExceptionCheck());
2159 env_->MonitorExit(object);
2160 EXPECT_FALSE(env_->ExceptionCheck());
2164 env_->MonitorExit(object);
2165 EXPECT_TRUE(env_->ExceptionCheck());
2166 thrown_exception = env_->ExceptionOccurred();
2167 env_->ExceptionClear();
2168 EXPECT_TRUE(env_->IsInstanceOf(thrown_exception, imse_class));
2173 env_->MonitorEnter(nullptr);
2175 env_->MonitorExit(nullptr);
2189 env_->MonitorEnter(jobj_);
2190 EXPECT_FALSE(env_->ExceptionCheck());
2193 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_);
2210 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_);
2241 jclass object_class = env_->FindClass("java/lang/Object");
2243 jobject object = env_->AllocObject(object_class);
2245 global_ref = env_->NewGlobalRef(object);
2249 env_->MonitorEnter(global_ref);
2250 ASSERT_TRUE(IsLocked(env_, global_ref));
2255 jint attach_result = vm_->AttachCurrentThread(&env_, nullptr);
2259 ASSERT_FALSE(IsLocked(env_, global_ref));
2262 env_->DeleteGlobalRef(global_ref);