From 00c559a7d68af3b6ad616a709d7db7bfc4f5017a Mon Sep 17 00:00:00 2001 From: Jamieson Pryor Date: Fri, 24 Feb 2023 13:37:47 -0800 Subject: [PATCH] Update class_loader_ref_test.cc to use new fake_test_constants.h. PiperOrigin-RevId: 512152180 --- implementation/class_loader_ref_test.cc | 67 +++++++++---------------- 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/implementation/class_loader_ref_test.cc b/implementation/class_loader_ref_test.cc index c6e1b7e9..b7dcd5be 100644 --- a/implementation/class_loader_ref_test.cc +++ b/implementation/class_loader_ref_test.cc @@ -18,6 +18,7 @@ #include #include +#include "implementation/fake_test_constants.h" #include "jni_bind.h" #include "jni_test.h" @@ -297,12 +298,6 @@ TEST_F(JniTestWithNoDefaultJvmRef, // TestClass. static constexpr Jvm kClassLoaderJvm{kClassLoader}; - const jmethodID custom_test_init_jmethod{ - reinterpret_cast(0XBDBDBD)}; - const jmethodID custom_test_method_jmethod{ - reinterpret_cast(0XBEBEBE)}; - const jstring custom_test_class_name{reinterpret_cast(0XBFBFBF)}; - InSequence sequence; EXPECT_CALL(*env_, FindClass(StrEq("java/lang/ClassLoader"))) @@ -317,7 +312,7 @@ TEST_F(JniTestWithNoDefaultJvmRef, .WillOnce(testing::Return(Fake(1))); EXPECT_CALL(*env_, NewStringUTF(_)) - .WillOnce(testing::Return(custom_test_class_name)); + .WillOnce(testing::Return(Fake())); // We should only try to load the class once even if we create multiple // instances. @@ -328,21 +323,20 @@ TEST_F(JniTestWithNoDefaultJvmRef, .WillOnce(testing::Return(AsGlobal(Fake(2)))); EXPECT_CALL(*env_, GetMethodID(AsGlobal(Fake(2)), StrEq(""), StrEq("(I)V"))) - .WillOnce(testing::Return(custom_test_init_jmethod)); - EXPECT_CALL( - *env_, NewObjectV(AsGlobal(Fake(2)), custom_test_init_jmethod, _)) + .WillOnce(testing::Return(Fake(2))); + EXPECT_CALL(*env_, + NewObjectV(AsGlobal(Fake(2)), Fake(2), _)) .WillOnce(testing::Return(Fake(2))); - EXPECT_CALL( - *env_, NewObjectV(AsGlobal(Fake(2)), custom_test_init_jmethod, _)) + EXPECT_CALL(*env_, + NewObjectV(AsGlobal(Fake(2)), Fake(2), _)) .WillOnce(testing::Return(Fake(3))); EXPECT_CALL(*env_, GetMethodID(AsGlobal(Fake(2)), StrEq("methodNoCrossTalk"), StrEq("(I)I"))) - .WillOnce(testing::Return(custom_test_method_jmethod)); - EXPECT_CALL(*env_, - CallIntMethodV(Fake(2), custom_test_method_jmethod, _)) + .WillOnce(testing::Return(Fake(3))); + EXPECT_CALL(*env_, CallIntMethodV(Fake(2), Fake(3), _)) .WillOnce(testing::Return(123)); // Code under test. @@ -372,62 +366,47 @@ TEST_F(JniTestWithNoDefaultJvmRef, static constexpr jni::Jvm atypical_jvm_definition{class_loader}; - const jobject test_jobject{reinterpret_cast(0XAAAAAA)}; - const jstring test_name_jstring{reinterpret_cast(0XABABAB)}; - const jclass test_jclass{reinterpret_cast(0XACACAC)}; - const jmethodID test_method_jmethod{reinterpret_cast(0XAFAFAF)}; - - const jclass class_jclass{reinterpret_cast(0XBBBBBB)}; - const jmethodID get_class_loader_jmethod{ - reinterpret_cast(0XBDBDBD)}; - const jclass class_loader_jclass{reinterpret_cast(0XCACACA)}; - const jobject class_loader_jobject{reinterpret_cast(0XCDCDCD)}; - const jobject class_loader_from_object_ref_jobject{ - reinterpret_cast(0XAAADCD)}; - InSequence seq; // The java/lang/Class and java/lang/ClassLoader will always be from the // default loader, and they only need to be cached once. EXPECT_CALL(*env_, FindClass(StrEq("java/lang/Class"))) - .WillOnce(testing::Return(class_jclass)); + .WillOnce(testing::Return(Fake(2))); EXPECT_CALL(*env_, FindClass(StrEq("java/lang/ClassLoader"))) - .WillOnce(testing::Return(class_loader_jclass)); + .WillOnce(testing::Return(Fake(3))); - EXPECT_CALL(*env_, GetObjectClass(test_jobject)) - .WillOnce(testing::Return(test_jclass)); + EXPECT_CALL(*env_, GetObjectClass(Fake(1))) + .WillOnce(testing::Return(Fake(1))); EXPECT_CALL(*env_, - GetMethodID(AsGlobal(class_jclass), StrEq("getClassLoader"), + GetMethodID(AsGlobal(Fake(2)), StrEq("getClassLoader"), StrEq("()Ljava/lang/ClassLoader;"))) - .WillOnce(testing::Return(get_class_loader_jmethod)); + .WillOnce(testing::Return(Fake(2))); - EXPECT_CALL(*env_, - CallObjectMethodV(test_jclass, get_class_loader_jmethod, _)) - .WillOnce(testing::Return(class_loader_from_object_ref_jobject)); + EXPECT_CALL(*env_, CallObjectMethodV(Fake(1), Fake(2), _)) + .WillOnce(testing::Return(Fake(3))); EXPECT_CALL(*env_, - GetMethodID(Eq(AsGlobal(class_loader_jclass)), StrEq("loadClass"), + GetMethodID(Eq(AsGlobal(Fake(3))), StrEq("loadClass"), StrEq("(Ljava/lang/String;)Ljava/lang/Class;"))) .WillOnce(testing::Return(Fake(1))); EXPECT_CALL(*env_, NewStringUTF(StrEq("com.google.ARCore"))) - .WillOnce(testing::Return(test_name_jstring)); + .WillOnce(testing::Return(Fake())); - EXPECT_CALL(*env_, CallObjectMethodV(class_loader_from_object_ref_jobject, - Fake(1), _)) - .WillOnce(testing::Return(class_loader_jobject)); + EXPECT_CALL(*env_, CallObjectMethodV(Fake(3), Fake(1), _)) + .WillOnce(testing::Return(Fake(2))); // Make sure we try to get the method with the loaded class, not the direct // object class. EXPECT_CALL(*env_, GetMethodID(_, StrEq("Foo"), StrEq("()V"))) - .WillOnce(testing::Return(test_method_jmethod)); + .WillOnce(testing::Return(Fake(1))); // Code under test. jni::JvmRef jvm_ref{jvm_.get()}; jni::LocalObject - obj1{test_jobject}; + obj1{Fake(1)}; obj1("Foo"); this->TearDown();