Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
platform_view_android_jni_impl_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "gmock/gmock.h"
6#include "gtest/gtest.h"
7
14
15namespace flutter {
16namespace testing {
17
18using ::testing::_;
19using ::testing::Return;
20using ::testing::ReturnArg;
21
22class PlatformViewAndroidJNIImplTest : public ::testing::Test {
23 public:
24 static void SetUpTestSuite() {
25 static std::once_flag jvm_init_flag;
26 std::call_once(jvm_init_flag, SetUpJVM);
27 }
28
29 private:
30 friend class MockJNIEnvProvider;
31 static MockJavaVM jvm_;
32 static void SetUpJVM();
33};
34
35MockJavaVM PlatformViewAndroidJNIImplTest::jvm_;
36
38 public:
40 PlatformViewAndroidJNIImplTest::jvm_.SetJNIEnv(&env_);
41 }
43 PlatformViewAndroidJNIImplTest::jvm_.SetJNIEnv(nullptr);
44 }
45 MockJNIEnv& env() { return env_; }
46
47 private:
48 MockJNIEnv env_;
49};
50
51void PlatformViewAndroidJNIImplTest::SetUpJVM() {
53
54 MockJNIEnvProvider env_provider;
55 MockJNIEnv& mock_env = env_provider.env();
56
57 const jclass kPlaceholderClass = reinterpret_cast<jclass>(100);
58 const jfieldID kPlaceholderFieldID = reinterpret_cast<jfieldID>(200);
59 const jmethodID kPlaceholderMethodID = reinterpret_cast<jmethodID>(300);
60
61 EXPECT_CALL(mock_env, GetObjectRefType(_))
62 .WillRepeatedly(Return(JNILocalRefType));
63 EXPECT_CALL(mock_env, NewLocalRef(_)).WillRepeatedly(ReturnArg<0>());
64 EXPECT_CALL(mock_env, DeleteLocalRef(_)).WillRepeatedly(Return());
65 EXPECT_CALL(mock_env, NewGlobalRef(_)).WillRepeatedly(ReturnArg<0>());
66 EXPECT_CALL(mock_env, DeleteGlobalRef(_)).WillRepeatedly(Return());
67 EXPECT_CALL(mock_env, FindClass(_)).WillRepeatedly(Return(kPlaceholderClass));
68 EXPECT_CALL(mock_env, GetFieldID(_, _, _))
69 .WillRepeatedly(Return(kPlaceholderFieldID));
70 EXPECT_CALL(mock_env, GetMethodID(_, _, _))
71 .WillRepeatedly(Return(kPlaceholderMethodID));
72 EXPECT_CALL(mock_env, GetStaticFieldID(_, _, _))
73 .WillRepeatedly(Return(kPlaceholderFieldID));
74 EXPECT_CALL(mock_env, GetStaticMethodID(_, _, _))
75 .WillRepeatedly(Return(kPlaceholderMethodID));
76 EXPECT_CALL(mock_env, ExceptionCheck()).WillRepeatedly(Return(JNI_FALSE));
77 EXPECT_CALL(mock_env, RegisterNatives(_, _, _)).WillRepeatedly(Return(0));
78
80}
81
82TEST_F(PlatformViewAndroidJNIImplTest, ImageGetHardwareBufferException) {
83 MockJNIEnvProvider env_provider;
84 MockJNIEnv& mock_env = env_provider.env();
85
86 // Call ImageGetHardwareBuffer and simulate throwing an exception.
87 // Verify that it clears the exception and does not abort the process.
88 EXPECT_CALL(mock_env, GetObjectRefType(_))
89 .WillRepeatedly(Return(JNILocalRefType));
90 EXPECT_CALL(mock_env, NewLocalRef(_)).WillRepeatedly(ReturnArg<0>());
91 EXPECT_CALL(mock_env, DeleteLocalRef(_)).WillRepeatedly(Return());
92 EXPECT_CALL(mock_env, CallObjectMethodV(_, _, _))
93 .WillRepeatedly(Return(nullptr));
94 EXPECT_CALL(mock_env, ExceptionCheck()).WillOnce(Return(JNI_TRUE));
95 EXPECT_CALL(mock_env, ExceptionDescribe()).WillOnce(Return());
96 EXPECT_CALL(mock_env, ExceptionClear()).Times(1).WillOnce(Return());
97
98 fml::jni::JavaObjectWeakGlobalRef flutter_jni_object;
99 PlatformViewAndroidJNIImpl android_jni(flutter_jni_object);
100
102 reinterpret_cast<jobject>(123));
103 android_jni.ImageGetHardwareBuffer(image);
104}
105
106} // namespace testing
107} // namespace flutter
void SetJNIEnv(JNIEnv *env)
Concrete implementation of PlatformViewAndroidJNI that is compiled with the Android toolchain.
JavaLocalRef ImageGetHardwareBuffer(JavaLocalRef image) override
Grab the HardwareBuffer from image.
FlutterVulkanImage * image
TEST_F(DisplayListTest, Defaults)
void InitJavaVM(JavaVM *vm)
Definition jni_util.cc:29