diff --git a/shell/platform/linux/fl_basic_message_channel_test.cc b/shell/platform/linux/fl_basic_message_channel_test.cc index 0850196bb783a..d4c338836e6a6 100644 --- a/shell/platform/linux/fl_basic_message_channel_test.cc +++ b/shell/platform/linux/fl_basic_message_channel_test.cc @@ -9,20 +9,9 @@ #include "flutter/shell/platform/linux/fl_engine_private.h" #include "flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h" #include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h" +#include "flutter/shell/platform/linux/testing/fl_test.h" #include "flutter/shell/platform/linux/testing/mock_renderer.h" -// Creates a mock engine that responds to platform messages. -static FlEngine* make_mock_engine() { - g_autoptr(FlDartProject) project = fl_dart_project_new(); - g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new(); - g_autoptr(FlEngine) engine = fl_engine_new(project, FL_RENDERER(renderer)); - g_autoptr(GError) engine_error = nullptr; - EXPECT_TRUE(fl_engine_start(engine, &engine_error)); - EXPECT_EQ(engine_error, nullptr); - - return static_cast(g_object_ref(engine)); -} - // Called when the message response is received in the SendMessage test. static void echo_response_cb(GObject* object, GAsyncResult* result, diff --git a/shell/platform/linux/fl_binary_messenger_test.cc b/shell/platform/linux/fl_binary_messenger_test.cc index 4916019214178..4d568545cb670 100644 --- a/shell/platform/linux/fl_binary_messenger_test.cc +++ b/shell/platform/linux/fl_binary_messenger_test.cc @@ -10,20 +10,9 @@ #include "flutter/shell/platform/linux/fl_binary_messenger_private.h" #include "flutter/shell/platform/linux/fl_engine_private.h" #include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h" +#include "flutter/shell/platform/linux/testing/fl_test.h" #include "flutter/shell/platform/linux/testing/mock_renderer.h" -// Creates a mock engine that responds to platform messages. -static FlEngine* make_mock_engine() { - g_autoptr(FlDartProject) project = fl_dart_project_new(); - g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new(); - g_autoptr(FlEngine) engine = fl_engine_new(project, FL_RENDERER(renderer)); - g_autoptr(GError) engine_error = nullptr; - EXPECT_TRUE(fl_engine_start(engine, &engine_error)); - EXPECT_EQ(engine_error, nullptr); - - return static_cast(g_object_ref(engine)); -} - // Checks sending nullptr for a message works. TEST(FlBinaryMessengerTest, SendNullptrMessage) { g_autoptr(FlEngine) engine = make_mock_engine(); diff --git a/shell/platform/linux/fl_key_event_plugin_test.cc b/shell/platform/linux/fl_key_event_plugin_test.cc index 0193727b0112d..4f3f99a39de39 100644 --- a/shell/platform/linux/fl_key_event_plugin_test.cc +++ b/shell/platform/linux/fl_key_event_plugin_test.cc @@ -11,20 +11,9 @@ #include "flutter/shell/platform/linux/fl_engine_private.h" #include "flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h" #include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h" +#include "flutter/shell/platform/linux/testing/fl_test.h" #include "flutter/shell/platform/linux/testing/mock_renderer.h" -// Creates a mock engine that responds to platform messages. -static FlEngine* make_mock_engine() { - g_autoptr(FlDartProject) project = fl_dart_project_new(); - g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new(); - g_autoptr(FlEngine) engine = fl_engine_new(project, FL_RENDERER(renderer)); - g_autoptr(GError) engine_error = nullptr; - EXPECT_TRUE(fl_engine_start(engine, &engine_error)); - EXPECT_EQ(engine_error, nullptr); - - return static_cast(g_object_ref(engine)); -} - const char* expected_value = nullptr; // Called when the message response is received in the send_key_event test. diff --git a/shell/platform/linux/fl_method_channel_test.cc b/shell/platform/linux/fl_method_channel_test.cc index 5026641aaae37..360ae327861d6 100644 --- a/shell/platform/linux/fl_method_channel_test.cc +++ b/shell/platform/linux/fl_method_channel_test.cc @@ -11,20 +11,9 @@ #include "flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h" #include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h" #include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h" +#include "flutter/shell/platform/linux/testing/fl_test.h" #include "flutter/shell/platform/linux/testing/mock_renderer.h" -// Creates a mock engine that responds to platform messages. -static FlEngine* make_mock_engine() { - g_autoptr(FlDartProject) project = fl_dart_project_new(); - g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new(); - g_autoptr(FlEngine) engine = fl_engine_new(project, FL_RENDERER(renderer)); - g_autoptr(GError) engine_error = nullptr; - EXPECT_TRUE(fl_engine_start(engine, &engine_error)); - EXPECT_EQ(engine_error, nullptr); - - return static_cast(g_object_ref(engine)); -} - // Called when when the method call response is received in the InvokeMethod // test. static void method_response_cb(GObject* object, diff --git a/shell/platform/linux/testing/fl_test.cc b/shell/platform/linux/testing/fl_test.cc index bd0864c62d315..735d4a9e74e81 100644 --- a/shell/platform/linux/testing/fl_test.cc +++ b/shell/platform/linux/testing/fl_test.cc @@ -1,9 +1,15 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// FLUTTER_NOLINT + +#include "gtest/gtest.h" #include "flutter/shell/platform/linux/testing/fl_test.h" +#include "flutter/shell/platform/linux/fl_engine_private.h" +#include "flutter/shell/platform/linux/testing/mock_renderer.h" + static uint8_t hex_digit_to_int(char value) { if (value >= '0' && value <= '9') return value - '0'; @@ -39,3 +45,14 @@ gchar* bytes_to_hex_string(GBytes* bytes) { g_string_append_printf(hex_string, "%02x", data[i]); return g_string_free(hex_string, FALSE); } + +FlEngine* make_mock_engine() { + g_autoptr(FlDartProject) project = fl_dart_project_new(); + g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new(); + g_autoptr(FlEngine) engine = fl_engine_new(project, FL_RENDERER(renderer)); + g_autoptr(GError) engine_error = nullptr; + EXPECT_TRUE(fl_engine_start(engine, &engine_error)); + EXPECT_EQ(engine_error, nullptr); + + return static_cast(g_object_ref(engine)); +} diff --git a/shell/platform/linux/testing/fl_test.h b/shell/platform/linux/testing/fl_test.h index 9f28da3f3b048..fe897fc71a769 100644 --- a/shell/platform/linux/testing/fl_test.h +++ b/shell/platform/linux/testing/fl_test.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_SHELL_PLATFORM_LINUX_FL_TEST_H_ #define FLUTTER_SHELL_PLATFORM_LINUX_FL_TEST_H_ +#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h" + #include #include @@ -18,6 +20,9 @@ GBytes* hex_string_to_bytes(const gchar* hex_string); // Helper function to convert GBytes into a hexadecimal string (e.g. "01feab") gchar* bytes_to_hex_string(GBytes* bytes); +// Creates a mock engine that responds to platform messages. +FlEngine* make_mock_engine(); + G_END_DECLS #endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_TEST_H_