6 #include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
11 #include "flutter/shell/platform/linux/testing/mock_texture_registrar.h"
12 #include "gtest/gtest.h"
26 fl_test_registrar_texture,
28 TEST_REGISTRAR_TEXTURE,
32 struct _FlTestRegistrarTexture {
33 FlTextureGL parent_instance;
37 fl_test_registrar_texture,
38 fl_texture_gl_get_type())
40 static gboolean fl_test_registrar_texture_populate(FlTextureGL* texture,
46 EXPECT_TRUE(FL_IS_TEST_REGISTRAR_TEXTURE(texture));
59 FlTestRegistrarTextureClass* klass) {
60 FL_TEXTURE_GL_CLASS(klass)->populate = fl_test_registrar_texture_populate;
66 return FL_TEST_REGISTRAR_TEXTURE(
67 g_object_new(fl_test_registrar_texture_get_type(),
nullptr));
71 g_return_val_if_fail(FL_TEXTURE_REGISTRAR(pointer), ((
void*)NULL));
72 FlTextureRegistrar* registrar = FL_TEXTURE_REGISTRAR(pointer);
75 int64_t*
id =
static_cast<int64_t*
>(malloc(
sizeof(int64_t)));
81 TEST(FlTextureRegistrarTest, MockRegistrar) {
83 g_autoptr(FlMockTextureRegistrar) registrar = fl_mock_texture_registrar_new();
84 EXPECT_TRUE(FL_IS_MOCK_TEXTURE_REGISTRAR(registrar));
87 FL_TEXTURE_REGISTRAR(registrar), texture));
88 EXPECT_EQ(fl_mock_texture_registrar_get_texture(registrar), texture);
90 FL_TEXTURE_REGISTRAR(registrar), texture));
91 EXPECT_TRUE(fl_mock_texture_registrar_get_frame_available(registrar));
93 FL_TEXTURE_REGISTRAR(registrar), texture));
94 EXPECT_EQ(fl_mock_texture_registrar_get_texture(registrar),
nullptr);
98 TEST(FlTextureRegistrarTest, RegisterTexture) {
101 bool register_called =
false;
103 MOCK_ENGINE_PROC(RegisterExternalTexture,
104 ([®ister_called](
auto engine, int64_t
texture_id) {
105 register_called =
true;
108 bool unregister_called =
false;
110 MOCK_ENGINE_PROC(UnregisterExternalTexture,
111 ([&unregister_called](
auto engine, int64_t
texture_id) {
112 unregister_called =
true;
120 EXPECT_FALSE(register_called);
122 EXPECT_TRUE(register_called);
123 EXPECT_FALSE(unregister_called);
125 EXPECT_TRUE(unregister_called);
129 TEST(FlTextureRegistrarTest, MarkTextureFrameAvailable) {
132 bool register_called =
false;
134 MOCK_ENGINE_PROC(RegisterExternalTexture,
135 ([®ister_called](
auto engine, int64_t
texture_id) {
136 register_called =
true;
141 UnregisterExternalTexture,
142 ([](
auto engine, int64_t
texture_id) {
return kSuccess; }));
144 MOCK_ENGINE_PROC(MarkExternalTextureFrameAvailable,
154 EXPECT_TRUE(register_called);
160 TEST(FlTextureRegistrarTest, MarkInvalidTextureFrameAvailable) {
165 RegisterExternalTexture,
166 ([](
auto engine, int64_t
texture_id) {
return kSuccess; }));
169 UnregisterExternalTexture,
170 ([](
auto engine, int64_t
texture_id) {
return kSuccess; }));
172 MOCK_ENGINE_PROC(MarkExternalTextureFrameAvailable,
174 return kInternalInconsistency;
190 DISABLED_RegistrarRegisterTextureInMultipleThreads) {
196 RegisterExternalTexture,
197 ([](
auto engine, int64_t
texture_id) {
return kSuccess; }));
200 UnregisterExternalTexture,
201 ([](
auto engine, int64_t
texture_id) {
return kSuccess; }));
214 pthread_join(threads[t], &
id);
215 ids[t] =
static_cast<int64_t*
>(
id)[0];