Consolidate GTK mocks (#164890)

This was split across three files, consolidate into one.

---------

Co-authored-by: Harlen Batagelo <hbatagelo@gmail.com>
This commit is contained in:
Robert Ancell
2025-03-12 04:30:09 +13:00
committed by GitHub
parent b60d60a166
commit 39dc5717d5
15 changed files with 412 additions and 503 deletions

View File

@@ -258,14 +258,12 @@ executable("flutter_linux_unittests") {
"testing/fl_test_gtk_logs.h",
"testing/mock_engine.cc",
"testing/mock_epoxy.cc",
"testing/mock_im_context.cc",
"testing/mock_keymap.cc",
"testing/mock_gtk.cc",
"testing/mock_plugin_registrar.cc",
"testing/mock_renderer.cc",
"testing/mock_settings.cc",
"testing/mock_signal_handler.cc",
"testing/mock_texture_registrar.cc",
"testing/mock_window.cc",
]
public_configs = [ "//flutter:config" ]

View File

@@ -10,7 +10,7 @@
#include "flutter/shell/platform/linux/fl_method_codec_private.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
#include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h"
#include "flutter/shell/platform/linux/testing/mock_keymap.h"
#include "flutter/shell/platform/linux/testing/mock_gtk.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -24,7 +24,7 @@ using ::flutter::testing::keycodes::kPhysicalKeyA;
constexpr guint16 kKeyCodeKeyA = 0x26u;
TEST(FlKeyboardHandlerTest, KeyboardChannelGetPressedState) {
::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =

View File

@@ -12,7 +12,7 @@
#include "flutter/shell/platform/linux/fl_engine_private.h"
#include "flutter/shell/platform/linux/key_mapping.h"
#include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h"
#include "flutter/shell/platform/linux/testing/mock_keymap.h"
#include "flutter/shell/platform/linux/testing/mock_gtk.h"
#include "gtest/gtest.h"
@@ -109,7 +109,7 @@ extern const MockLayoutData kLayoutRussian;
extern const MockLayoutData kLayoutFrench;
TEST(FlKeyboardManagerTest, EngineNoResponseChannelHandled) {
::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
// Channel handles all events.
@@ -174,7 +174,7 @@ TEST(FlKeyboardManagerTest, EngineNoResponseChannelHandled) {
}
TEST(FlKeyboardManagerTest, EngineHandledChannelNotHandledSync) {
::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
@@ -219,7 +219,7 @@ TEST(FlKeyboardManagerTest, EngineHandledChannelNotHandledSync) {
}
TEST(FlKeyboardManagerTest, EngineNotHandledChannelHandledSync) {
::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
@@ -264,7 +264,7 @@ TEST(FlKeyboardManagerTest, EngineNotHandledChannelHandledSync) {
}
TEST(FlKeyboardManagerTest, EngineHandledChannelHandledSync) {
::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
@@ -309,7 +309,7 @@ TEST(FlKeyboardManagerTest, EngineHandledChannelHandledSync) {
}
TEST(FlKeyboardManagerTest, EngineNotHandledChannelNotHandledSync) {
::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
@@ -362,7 +362,7 @@ static void channel_respond(FlMockBinaryMessenger* messenger,
}
TEST(FlKeyboardManagerTest, EngineHandledChannelNotHandledAsync) {
::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
@@ -423,7 +423,7 @@ TEST(FlKeyboardManagerTest, EngineHandledChannelNotHandledAsync) {
}
TEST(FlKeyboardManagerTest, EngineNotHandledChannelHandledAsync) {
::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
@@ -484,7 +484,7 @@ TEST(FlKeyboardManagerTest, EngineNotHandledChannelHandledAsync) {
}
TEST(FlKeyboardManagerTest, EngineHandledChannelHandledAsync) {
::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
@@ -545,7 +545,7 @@ TEST(FlKeyboardManagerTest, EngineHandledChannelHandledAsync) {
}
TEST(FlKeyboardManagerTest, EngineNotHandledChannelNotHandledAsync) {
::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
@@ -606,7 +606,7 @@ TEST(FlKeyboardManagerTest, EngineNotHandledChannelNotHandledAsync) {
}
TEST(FlKeyboardManagerTest, CorrectLogicalKeyForLayouts) {
::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlDartProject) project = fl_dart_project_new();
g_autoptr(FlEngine) engine = fl_engine_new(project);
@@ -739,7 +739,7 @@ TEST(FlKeyboardManagerTest, CorrectLogicalKeyForLayouts) {
}
TEST(FlKeyboardManagerTest, SynthesizeModifiersIfNeeded) {
::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlDartProject) project = fl_dart_project_new();
g_autoptr(FlEngine) engine = fl_engine_new(project);
@@ -801,7 +801,7 @@ TEST(FlKeyboardManagerTest, SynthesizeModifiersIfNeeded) {
}
TEST(FlKeyboardManagerTest, GetPressedState) {
::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =

View File

@@ -9,7 +9,7 @@
#include "flutter/shell/platform/linux/fl_text_input_handler.h"
#include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h"
#include "flutter/shell/platform/linux/testing/fl_test.h"
#include "flutter/shell/platform/linux/testing/mock_im_context.h"
#include "flutter/shell/platform/linux/testing/mock_gtk.h"
#include "flutter/testing/testing.h"
#include "gmock/gmock.h"
@@ -152,7 +152,7 @@ static void send_key_event(FlTextInputHandler* handler,
TEST(FlTextInputHandlerTest, MessageHandler) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
@@ -166,7 +166,7 @@ TEST(FlTextInputHandlerTest, MessageHandler) {
TEST(FlTextInputHandlerTest, SetClient) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
@@ -179,13 +179,13 @@ TEST(FlTextInputHandlerTest, SetClient) {
TEST(FlTextInputHandlerTest, Show) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
EXPECT_NE(handler, nullptr);
EXPECT_CALL(context, gtk_im_context_focus_in);
EXPECT_CALL(mock_gtk, gtk_im_context_focus_in);
gboolean called = FALSE;
fl_mock_binary_messenger_invoke_json_method(
@@ -210,13 +210,13 @@ TEST(FlTextInputHandlerTest, Show) {
TEST(FlTextInputHandlerTest, Hide) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
EXPECT_NE(handler, nullptr);
EXPECT_CALL(context, gtk_im_context_focus_out);
EXPECT_CALL(mock_gtk, gtk_im_context_focus_out);
gboolean called = FALSE;
fl_mock_binary_messenger_invoke_json_method(
@@ -241,7 +241,7 @@ TEST(FlTextInputHandlerTest, Hide) {
TEST(FlTextInputHandlerTest, ClearClient) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
@@ -270,7 +270,7 @@ TEST(FlTextInputHandlerTest, ClearClient) {
TEST(FlTextInputHandlerTest, PerformAction) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
@@ -330,7 +330,7 @@ TEST(FlTextInputHandlerTest, PerformAction) {
// Regression test for https://github.com/flutter/flutter/issues/125879.
TEST(FlTextInputHandlerTest, MultilineWithSendAction) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
@@ -388,7 +388,7 @@ TEST(FlTextInputHandlerTest, MultilineWithSendAction) {
TEST(FlTextInputHandlerTest, MoveCursor) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
@@ -453,7 +453,7 @@ TEST(FlTextInputHandlerTest, MoveCursor) {
TEST(FlTextInputHandlerTest, Select) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
@@ -518,16 +518,16 @@ TEST(FlTextInputHandlerTest, Select) {
TEST(FlTextInputHandlerTest, Composing) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
EXPECT_NE(handler, nullptr);
// update
EXPECT_CALL(context, gtk_im_context_get_preedit_string(
::testing::_, ::testing::A<gchar**>(), ::testing::_,
::testing::A<gint*>()))
EXPECT_CALL(mock_gtk, gtk_im_context_get_preedit_string(
::testing::_, ::testing::A<gchar**>(), ::testing::_,
::testing::A<gint*>()))
.WillOnce(
::testing::DoAll(::testing::SetArgPointee<1>(g_strdup("Flutter")),
::testing::SetArgPointee<3>(0)));
@@ -602,7 +602,7 @@ TEST(FlTextInputHandlerTest, Composing) {
TEST(FlTextInputHandlerTest, SurroundingText) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
@@ -616,8 +616,8 @@ TEST(FlTextInputHandlerTest, SurroundingText) {
});
// retrieve
EXPECT_CALL(context, gtk_im_context_set_surrounding(
::testing::_, ::testing::StrEq("Flutter"), -1, 3));
EXPECT_CALL(mock_gtk, gtk_im_context_set_surrounding(
::testing::_, ::testing::StrEq("Flutter"), -1, 3));
gboolean retrieved = false;
g_signal_emit_by_name(fl_text_input_handler_get_im_context(handler),
@@ -667,7 +667,7 @@ TEST(FlTextInputHandlerTest, SurroundingText) {
TEST(FlTextInputHandlerTest, SetMarkedTextRect) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
@@ -719,20 +719,20 @@ TEST(FlTextInputHandlerTest, SetMarkedTextRect) {
&called);
EXPECT_TRUE(called);
EXPECT_CALL(context, gtk_widget_translate_coordinates(
::testing::_, ::testing::_, ::testing::Eq(27),
::testing::Eq(32), ::testing::_, ::testing::_))
EXPECT_CALL(mock_gtk, gtk_widget_translate_coordinates(
::testing::_, ::testing::_, ::testing::Eq(27),
::testing::Eq(32), ::testing::_, ::testing::_))
.WillOnce(::testing::DoAll(::testing::SetArgPointee<4>(123),
::testing::SetArgPointee<5>(456),
::testing::Return(true)));
EXPECT_CALL(context, gtk_im_context_set_cursor_location(
::testing::_,
::testing::Pointee(::testing::AllOf(
::testing::Field(&GdkRectangle::x, 123),
::testing::Field(&GdkRectangle::y, 456),
::testing::Field(&GdkRectangle::width, 0),
::testing::Field(&GdkRectangle::height, 0)))));
EXPECT_CALL(mock_gtk, gtk_im_context_set_cursor_location(
::testing::_,
::testing::Pointee(::testing::AllOf(
::testing::Field(&GdkRectangle::x, 123),
::testing::Field(&GdkRectangle::y, 456),
::testing::Field(&GdkRectangle::width, 0),
::testing::Field(&GdkRectangle::height, 0)))));
// set marked text rect
g_autoptr(FlValue) rect = build_map({
@@ -764,7 +764,7 @@ TEST(FlTextInputHandlerTest, SetMarkedTextRect) {
TEST(FlTextInputHandlerTest, TextInputTypeNone) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
@@ -775,8 +775,8 @@ TEST(FlTextInputHandlerTest, TextInputTypeNone) {
.input_type = "TextInputType.none",
});
EXPECT_CALL(context, gtk_im_context_focus_in).Times(0);
EXPECT_CALL(context, gtk_im_context_focus_out);
EXPECT_CALL(mock_gtk, gtk_im_context_focus_in).Times(0);
EXPECT_CALL(mock_gtk, gtk_im_context_focus_out);
gboolean called = FALSE;
fl_mock_binary_messenger_invoke_json_method(
@@ -801,7 +801,7 @@ TEST(FlTextInputHandlerTest, TextInputTypeNone) {
TEST(FlTextInputHandlerTest, TextEditingDelta) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
@@ -865,7 +865,7 @@ TEST(FlTextInputHandlerTest, TextEditingDelta) {
TEST(FlTextInputHandlerTest, ComposingDelta) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));
@@ -881,9 +881,9 @@ TEST(FlTextInputHandlerTest, ComposingDelta) {
"preedit-start", nullptr);
// update
EXPECT_CALL(context, gtk_im_context_get_preedit_string(
::testing::_, ::testing::A<gchar**>(), ::testing::_,
::testing::A<gint*>()))
EXPECT_CALL(mock_gtk, gtk_im_context_get_preedit_string(
::testing::_, ::testing::A<gchar**>(), ::testing::_,
::testing::A<gint*>()))
.WillOnce(
::testing::DoAll(::testing::SetArgPointee<1>(g_strdup("Flutter ")),
::testing::SetArgPointee<3>(8)));
@@ -979,7 +979,7 @@ TEST(FlTextInputHandlerTest, ComposingDelta) {
TEST(FlTextInputHandlerTest, NonComposingDelta) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockIMContext> context;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlTextInputHandler) handler =
fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger));

View File

@@ -7,7 +7,7 @@
#include "flutter/shell/platform/linux/fl_engine_private.h"
#include "flutter/shell/platform/linux/testing/fl_test.h"
#include "flutter/shell/platform/linux/testing/fl_test_gtk_logs.h"
#include "flutter/shell/platform/linux/testing/mock_window.h"
#include "flutter/shell/platform/linux/testing/mock_gtk.h"
#include "gtest/gtest.h"

View File

@@ -6,17 +6,17 @@
#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_string_codec.h"
#include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h"
#include "flutter/shell/platform/linux/testing/mock_window.h"
#include "flutter/shell/platform/linux/testing/mock_gtk.h"
#include "gtest/gtest.h"
TEST(FlWindowStateMonitorTest, GainFocus) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
gtk_init(0, nullptr);
EXPECT_CALL(mock_window, gdk_window_get_state)
EXPECT_CALL(mock_gtk, gdk_window_get_state)
.WillOnce(::testing::Return(static_cast<GdkWindowState>(0)));
gboolean called = TRUE;
@@ -47,11 +47,11 @@ TEST(FlWindowStateMonitorTest, GainFocus) {
TEST(FlWindowStateMonitorTest, LoseFocus) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
gtk_init(0, nullptr);
EXPECT_CALL(mock_window, gdk_window_get_state)
EXPECT_CALL(mock_gtk, gdk_window_get_state)
.WillOnce(::testing::Return(GDK_WINDOW_STATE_FOCUSED));
gboolean called = TRUE;
fl_mock_binary_messenger_set_string_message_channel(
@@ -82,11 +82,11 @@ TEST(FlWindowStateMonitorTest, LoseFocus) {
TEST(FlWindowStateMonitorTest, EnterIconified) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
gtk_init(0, nullptr);
EXPECT_CALL(mock_window, gdk_window_get_state)
EXPECT_CALL(mock_gtk, gdk_window_get_state)
.WillOnce(::testing::Return(static_cast<GdkWindowState>(0)));
gboolean called = TRUE;
fl_mock_binary_messenger_set_string_message_channel(
@@ -116,11 +116,11 @@ TEST(FlWindowStateMonitorTest, EnterIconified) {
TEST(FlWindowStateMonitorTest, LeaveIconified) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
gtk_init(0, nullptr);
EXPECT_CALL(mock_window, gdk_window_get_state)
EXPECT_CALL(mock_gtk, gdk_window_get_state)
.WillOnce(::testing::Return(GDK_WINDOW_STATE_ICONIFIED));
gboolean called = TRUE;
fl_mock_binary_messenger_set_string_message_channel(
@@ -151,11 +151,11 @@ TEST(FlWindowStateMonitorTest, LeaveIconified) {
TEST(FlWindowStateMonitorTest, LeaveIconifiedFocused) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
gtk_init(0, nullptr);
EXPECT_CALL(mock_window, gdk_window_get_state)
EXPECT_CALL(mock_gtk, gdk_window_get_state)
.WillOnce(::testing::Return(GDK_WINDOW_STATE_ICONIFIED));
gboolean called = TRUE;
fl_mock_binary_messenger_set_string_message_channel(
@@ -186,11 +186,11 @@ TEST(FlWindowStateMonitorTest, LeaveIconifiedFocused) {
TEST(FlWindowStateMonitorTest, EnterWithdrawn) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
gtk_init(0, nullptr);
EXPECT_CALL(mock_window, gdk_window_get_state)
EXPECT_CALL(mock_gtk, gdk_window_get_state)
.WillOnce(::testing::Return(static_cast<GdkWindowState>(0)));
gboolean called = TRUE;
fl_mock_binary_messenger_set_string_message_channel(
@@ -220,11 +220,11 @@ TEST(FlWindowStateMonitorTest, EnterWithdrawn) {
TEST(FlWindowStateMonitorTest, LeaveWithdrawn) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
gtk_init(0, nullptr);
EXPECT_CALL(mock_window, gdk_window_get_state)
EXPECT_CALL(mock_gtk, gdk_window_get_state)
.WillOnce(::testing::Return(GDK_WINDOW_STATE_WITHDRAWN));
gboolean called = TRUE;
fl_mock_binary_messenger_set_string_message_channel(
@@ -255,11 +255,11 @@ TEST(FlWindowStateMonitorTest, LeaveWithdrawn) {
TEST(FlWindowStateMonitorTest, LeaveWithdrawnFocused) {
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
gtk_init(0, nullptr);
EXPECT_CALL(mock_window, gdk_window_get_state)
EXPECT_CALL(mock_gtk, gdk_window_get_state)
.WillOnce(::testing::Return(GDK_WINDOW_STATE_WITHDRAWN));
gboolean called = TRUE;
fl_mock_binary_messenger_set_string_message_channel(

View File

@@ -7,7 +7,7 @@
#include "flutter/shell/platform/linux/fl_engine_private.h"
#include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h"
#include "flutter/shell/platform/linux/testing/fl_test_gtk_logs.h"
#include "flutter/shell/platform/linux/testing/mock_window.h"
#include "flutter/shell/platform/linux/testing/mock_gtk.h"
#include "flutter/testing/testing.h"
#include "gmock/gmock.h"
@@ -72,15 +72,15 @@ static FlValue* make_destroy_window_args(int64_t view_id) {
TEST(FlWindowingHandlerTest, CreateRegular) {
flutter::testing::fl_ensure_gtk_init();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =
fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine);
EXPECT_CALL(mock_window, gtk_window_new);
EXPECT_CALL(mock_window, gtk_window_set_default_size(::testing::_, 800, 600));
EXPECT_CALL(mock_gtk, gtk_window_new);
EXPECT_CALL(mock_gtk, gtk_window_set_default_size(::testing::_, 800, 600));
g_autoptr(FlValue) args = make_create_regular_args(800, 600);
@@ -101,15 +101,15 @@ TEST(FlWindowingHandlerTest, CreateRegular) {
TEST(FlWindowingHandlerTest, CreateRegularMinSize) {
flutter::testing::fl_ensure_gtk_init();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =
fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine);
EXPECT_CALL(mock_window, gtk_window_new);
EXPECT_CALL(mock_window,
EXPECT_CALL(mock_gtk, gtk_window_new);
EXPECT_CALL(mock_gtk,
gtk_window_set_geometry_hints(
::testing::_, nullptr,
::testing::Pointee(::testing::AllOf(
@@ -137,15 +137,15 @@ TEST(FlWindowingHandlerTest, CreateRegularMinSize) {
TEST(FlWindowingHandlerTest, CreateRegularMaxSize) {
flutter::testing::fl_ensure_gtk_init();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =
fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine);
EXPECT_CALL(mock_window, gtk_window_new);
EXPECT_CALL(mock_window,
EXPECT_CALL(mock_gtk, gtk_window_new);
EXPECT_CALL(mock_gtk,
gtk_window_set_geometry_hints(
::testing::_, nullptr,
::testing::Pointee(::testing::AllOf(
@@ -173,15 +173,15 @@ TEST(FlWindowingHandlerTest, CreateRegularMaxSize) {
TEST(FlWindowingHandlerTest, CreateRegularWithTitle) {
flutter::testing::fl_ensure_gtk_init();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =
fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine);
EXPECT_CALL(mock_window, gtk_window_new);
EXPECT_CALL(mock_window,
EXPECT_CALL(mock_gtk, gtk_window_new);
EXPECT_CALL(mock_gtk,
gtk_window_set_title(::testing::_, ::testing::StrEq("TITLE")));
g_autoptr(FlValue) args = make_create_regular_args(800, 600);
@@ -204,15 +204,15 @@ TEST(FlWindowingHandlerTest, CreateRegularWithTitle) {
TEST(FlWindowingHandlerTest, CreateRegularMaximized) {
flutter::testing::fl_ensure_gtk_init();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =
fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine);
EXPECT_CALL(mock_window, gtk_window_new);
EXPECT_CALL(mock_window, gtk_window_maximize(::testing::_));
EXPECT_CALL(mock_gtk, gtk_window_new);
EXPECT_CALL(mock_gtk, gtk_window_maximize(::testing::_));
g_autoptr(FlValue) args = make_create_regular_args(800, 600);
fl_value_set_string_take(args, "state",
@@ -235,15 +235,15 @@ TEST(FlWindowingHandlerTest, CreateRegularMaximized) {
TEST(FlWindowingHandlerTest, CreateRegularMinimized) {
flutter::testing::fl_ensure_gtk_init();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =
fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine);
EXPECT_CALL(mock_window, gtk_window_new);
EXPECT_CALL(mock_window, gtk_window_iconify(::testing::_));
EXPECT_CALL(mock_gtk, gtk_window_new);
EXPECT_CALL(mock_gtk, gtk_window_iconify(::testing::_));
g_autoptr(FlValue) args = make_create_regular_args(800, 600);
fl_value_set_string_take(args, "state",
@@ -266,15 +266,15 @@ TEST(FlWindowingHandlerTest, CreateRegularMinimized) {
TEST(FlWindowingHandlerTest, ModifyRegularSize) {
flutter::testing::fl_ensure_gtk_init();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =
fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine);
EXPECT_CALL(mock_window, gtk_window_new);
EXPECT_CALL(mock_window, gtk_window_resize(::testing::_, 1024, 768));
EXPECT_CALL(mock_gtk, gtk_window_new);
EXPECT_CALL(mock_gtk, gtk_window_resize(::testing::_, 1024, 768));
g_autoptr(FlValue) create_args = make_create_regular_args(800, 600);
@@ -309,15 +309,15 @@ TEST(FlWindowingHandlerTest, ModifyRegularSize) {
TEST(FlWindowingHandlerTest, ModifyRegularTitle) {
flutter::testing::fl_ensure_gtk_init();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =
fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine);
EXPECT_CALL(mock_window, gtk_window_new);
EXPECT_CALL(mock_window,
EXPECT_CALL(mock_gtk, gtk_window_new);
EXPECT_CALL(mock_gtk,
gtk_window_set_title(::testing::_, ::testing::StrEq("TITLE")));
g_autoptr(FlValue) create_args = make_create_regular_args(800, 600);
@@ -353,14 +353,14 @@ TEST(FlWindowingHandlerTest, ModifyRegularTitle) {
TEST(FlWindowingHandlerTest, ModifyRegularMaximize) {
flutter::testing::fl_ensure_gtk_init();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =
fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine);
EXPECT_CALL(mock_window, gtk_window_new);
EXPECT_CALL(mock_gtk, gtk_window_new);
g_autoptr(FlValue) create_args = make_create_regular_args(800, 600);
@@ -375,7 +375,7 @@ TEST(FlWindowingHandlerTest, ModifyRegularMaximize) {
&view_id);
EXPECT_GT(view_id, 0);
EXPECT_CALL(mock_window, gtk_window_maximize(::testing::_));
EXPECT_CALL(mock_gtk, gtk_window_maximize(::testing::_));
g_autoptr(FlValue) modify_args = make_modify_regular_args(view_id);
fl_value_set_string_take(modify_args, "state",
@@ -398,15 +398,15 @@ TEST(FlWindowingHandlerTest, ModifyRegularMaximize) {
TEST(FlWindowingHandlerTest, ModifyRegularUnmaximize) {
flutter::testing::fl_ensure_gtk_init();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =
fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine);
EXPECT_CALL(mock_window, gtk_window_new);
EXPECT_CALL(mock_window, gtk_window_maximize(::testing::_));
EXPECT_CALL(mock_gtk, gtk_window_new);
EXPECT_CALL(mock_gtk, gtk_window_maximize(::testing::_));
g_autoptr(FlValue) create_args = make_create_regular_args(800, 600);
fl_value_set_string_take(create_args, "state",
@@ -423,9 +423,9 @@ TEST(FlWindowingHandlerTest, ModifyRegularUnmaximize) {
&view_id);
EXPECT_GT(view_id, 0);
EXPECT_CALL(mock_window, gtk_window_is_maximized(::testing::_))
EXPECT_CALL(mock_gtk, gtk_window_is_maximized(::testing::_))
.WillOnce(::testing::Return(TRUE));
EXPECT_CALL(mock_window, gtk_window_unmaximize(::testing::_));
EXPECT_CALL(mock_gtk, gtk_window_unmaximize(::testing::_));
g_autoptr(FlValue) modify_args = make_modify_regular_args(view_id);
fl_value_set_string_take(modify_args, "state",
@@ -448,14 +448,14 @@ TEST(FlWindowingHandlerTest, ModifyRegularUnmaximize) {
TEST(FlWindowingHandlerTest, ModifyRegularMinimize) {
flutter::testing::fl_ensure_gtk_init();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =
fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine);
EXPECT_CALL(mock_window, gtk_window_new);
EXPECT_CALL(mock_gtk, gtk_window_new);
g_autoptr(FlValue) create_args = make_create_regular_args(800, 600);
@@ -470,7 +470,7 @@ TEST(FlWindowingHandlerTest, ModifyRegularMinimize) {
&view_id);
EXPECT_GT(view_id, 0);
EXPECT_CALL(mock_window, gtk_window_iconify(::testing::_));
EXPECT_CALL(mock_gtk, gtk_window_iconify(::testing::_));
g_autoptr(FlValue) modify_args = make_modify_regular_args(view_id);
fl_value_set_string_take(modify_args, "state",
@@ -493,15 +493,15 @@ TEST(FlWindowingHandlerTest, ModifyRegularMinimize) {
TEST(FlWindowingHandlerTest, ModifyRegularUnminimize) {
flutter::testing::fl_ensure_gtk_init();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =
fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine);
EXPECT_CALL(mock_window, gtk_window_new);
EXPECT_CALL(mock_window, gtk_window_iconify(::testing::_));
EXPECT_CALL(mock_gtk, gtk_window_new);
EXPECT_CALL(mock_gtk, gtk_window_iconify(::testing::_));
g_autoptr(FlValue) create_args = make_create_regular_args(800, 600);
fl_value_set_string_take(create_args, "state",
@@ -518,9 +518,9 @@ TEST(FlWindowingHandlerTest, ModifyRegularUnminimize) {
&view_id);
EXPECT_GT(view_id, 0);
EXPECT_CALL(mock_window, gdk_window_get_state(::testing::_))
EXPECT_CALL(mock_gtk, gdk_window_get_state(::testing::_))
.WillOnce(::testing::Return(GDK_WINDOW_STATE_ICONIFIED));
EXPECT_CALL(mock_window, gtk_window_deiconify(::testing::_));
EXPECT_CALL(mock_gtk, gtk_window_deiconify(::testing::_));
g_autoptr(FlValue) modify_args = make_modify_regular_args(view_id);
fl_value_set_string_take(modify_args, "state",
@@ -572,15 +572,15 @@ TEST(FlWindowingHandlerTest, ModifyUnknownWindow) {
TEST(FlWindowingHandlerTest, DestroyWindow) {
flutter::testing::fl_ensure_gtk_init();
::testing::NiceMock<flutter::testing::MockWindow> mock_window;
::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
g_autoptr(FlEngine) engine =
fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine);
EXPECT_CALL(mock_window, gtk_window_new);
EXPECT_CALL(mock_window, gtk_widget_destroy);
EXPECT_CALL(mock_gtk, gtk_window_new);
EXPECT_CALL(mock_gtk, gtk_widget_destroy);
g_autoptr(FlValue) create_args = make_create_regular_args(800, 600);

View File

@@ -0,0 +1,210 @@
// 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.
#include <dlfcn.h>
#include "flutter/shell/platform/linux/testing/mock_gtk.h"
using namespace flutter::testing;
G_DECLARE_FINAL_TYPE(FlMockKeymap, fl_mock_keymap, FL, MOCK_KEYMAP, GObject)
struct _FlMockKeymap {
GObject parent_instance;
};
G_DEFINE_TYPE(FlMockKeymap, fl_mock_keymap, G_TYPE_OBJECT)
static void fl_mock_keymap_class_init(FlMockKeymapClass* klass) {
g_signal_new("keys-changed", fl_mock_keymap_get_type(), G_SIGNAL_RUN_LAST, 0,
nullptr, nullptr, nullptr, G_TYPE_NONE, 0);
}
static void fl_mock_keymap_init(FlMockKeymap* self) {}
static MockGtk* mock = nullptr;
MockGtk::MockGtk() {
mock = this;
}
MockGtk::~MockGtk() {
if (mock == this) {
mock = nullptr;
}
}
GdkKeymap* gdk_keymap_get_for_display(GdkDisplay* display) {
FlMockKeymap* keymap =
FL_MOCK_KEYMAP(g_object_new(fl_mock_keymap_get_type(), nullptr));
(void)FL_IS_MOCK_KEYMAP(keymap);
return reinterpret_cast<GdkKeymap*>(keymap);
}
guint gdk_keymap_lookup_key(GdkKeymap* keymap, const GdkKeymapKey* key) {
return mock->gdk_keymap_lookup_key(keymap, key);
}
GdkDisplay* gdk_display_get_default() {
return GDK_DISPLAY(g_object_new(gdk_display_get_type(), nullptr));
}
void gdk_display_beep(GdkDisplay* display) {}
GdkWindowState gdk_window_get_state(GdkWindow* window) {
return mock->gdk_window_get_state(window);
}
GdkDisplay* gdk_window_get_display(GdkWindow* window) {
return GDK_DISPLAY(g_object_new(gdk_display_get_type(), nullptr));
}
int gdk_display_get_n_monitors(GdkDisplay* display) {
return 1;
}
GdkMonitor* gdk_display_get_monitor(GdkDisplay* display, int n) {
return GDK_MONITOR(g_object_new(gdk_monitor_get_type(), nullptr));
}
GdkMonitor* gdk_display_get_monitor_at_window(GdkDisplay* display,
GdkWindow* window) {
return nullptr;
}
GdkCursor* gdk_cursor_new_from_name(GdkDisplay* display, const gchar* name) {
return nullptr;
}
void gdk_window_set_cursor(GdkWindow* window, GdkCursor* cursor) {}
GtkWidget* gtk_window_new(GtkWindowType type) {
GtkWindow* window = GTK_WINDOW(g_object_new(gtk_window_get_type(), nullptr));
mock->gtk_window_new(window, type);
return GTK_WIDGET(window);
}
void gtk_window_set_default_size(GtkWindow* window, gint width, gint height) {
mock->gtk_window_set_default_size(window, width, height);
}
void gtk_window_set_title(GtkWindow* window, const gchar* title) {
mock->gtk_window_set_title(window, title);
}
void gtk_window_set_geometry_hints(GtkWindow* window,
GtkWidget* widget,
GdkGeometry* geometry,
GdkWindowHints geometry_mask) {
mock->gtk_window_set_geometry_hints(window, widget, geometry, geometry_mask);
}
void gtk_window_resize(GtkWindow* window, gint width, gint height) {
mock->gtk_window_resize(window, width, height);
}
void gtk_window_maximize(GtkWindow* window) {
mock->gtk_window_maximize(window);
}
void gtk_window_unmaximize(GtkWindow* window) {
mock->gtk_window_unmaximize(window);
}
gboolean gtk_window_is_maximized(GtkWindow* window) {
return mock->gtk_window_is_maximized(window);
}
void gtk_window_iconify(GtkWindow* window) {
mock->gtk_window_iconify(window);
}
void gtk_window_deiconify(GtkWindow* window) {
mock->gtk_window_deiconify(window);
}
void gtk_widget_show(GtkWidget* widget) {}
void gtk_widget_destroy(GtkWidget* widget) {
mock->gtk_widget_destroy(widget);
}
void fl_gtk_widget_destroy(GtkWidget* widget) {
void (*destroy)(GtkWidget*) = reinterpret_cast<void (*)(GtkWidget*)>(
dlsym(RTLD_NEXT, "gtk_widget_destroy"));
destroy(widget);
}
gboolean gtk_widget_translate_coordinates(GtkWidget* src_widget,
GtkWidget* dest_widget,
gint src_x,
gint src_y,
gint* dest_x,
gint* dest_y) {
if (mock == nullptr) {
*dest_x = src_x;
*dest_y = src_y;
return TRUE;
}
return mock->gtk_widget_translate_coordinates(src_widget, dest_widget, src_x,
src_y, dest_x, dest_y);
}
GtkWidget* gtk_widget_get_toplevel(GtkWidget* widget) {
return widget;
}
void gtk_im_context_set_client_window(GtkIMContext* context,
GdkWindow* window) {
if (mock != nullptr) {
mock->gtk_im_context_set_client_window(context, window);
}
}
void gtk_im_context_get_preedit_string(GtkIMContext* context,
gchar** str,
PangoAttrList** attrs,
gint* cursor_pos) {
if (mock != nullptr) {
mock->gtk_im_context_get_preedit_string(context, str, attrs, cursor_pos);
}
}
gboolean gtk_im_context_filter_keypress(GtkIMContext* context,
GdkEventKey* event) {
if (mock == nullptr) {
return TRUE;
}
return mock->gtk_im_context_filter_keypress(context, event);
}
void gtk_im_context_focus_in(GtkIMContext* context) {
if (mock != nullptr) {
mock->gtk_im_context_focus_in(context);
}
}
void gtk_im_context_focus_out(GtkIMContext* context) {
if (mock != nullptr) {
mock->gtk_im_context_focus_out(context);
}
}
void gtk_im_context_set_cursor_location(GtkIMContext* context,
const GdkRectangle* area) {
if (mock != nullptr) {
mock->gtk_im_context_set_cursor_location(context, area);
}
}
void gtk_im_context_set_surrounding(GtkIMContext* context,
const gchar* text,
gint len,
gint cursor_index) {
if (mock != nullptr) {
mock->gtk_im_context_set_surrounding(context, text, len, cursor_index);
}
}

View File

@@ -0,0 +1,85 @@
// 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.
#ifndef FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_GTK_H_
#define FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_GTK_H_
#include "gmock/gmock.h"
#include <gtk/gtk.h>
namespace flutter {
namespace testing {
class MockGtk {
public:
MockGtk();
~MockGtk();
MOCK_METHOD(GdkKeymap*, gdk_keymap_get_for_display, (GdkDisplay * display));
MOCK_METHOD(guint,
gdk_keymap_lookup_key,
(GdkKeymap * keymap, const GdkKeymapKey* key));
MOCK_METHOD(GdkWindowState, gdk_window_get_state, (GdkWindow * window));
MOCK_METHOD(void, gtk_window_new, (GtkWindow * window, GtkWindowType type));
MOCK_METHOD(void,
gtk_window_set_default_size,
(GtkWindow * window, gint width, gint height));
MOCK_METHOD(void,
gtk_window_set_title,
(GtkWindow * window, const gchar* title));
MOCK_METHOD(void,
gtk_window_set_geometry_hints,
(GtkWindow * window,
GtkWidget* widget,
GdkGeometry* geometry,
GdkWindowHints geometry_mask));
MOCK_METHOD(void,
gtk_window_resize,
(GtkWindow * window, gint width, gint height));
MOCK_METHOD(void, gtk_window_maximize, (GtkWindow * window));
MOCK_METHOD(void, gtk_window_unmaximize, (GtkWindow * window));
MOCK_METHOD(gboolean, gtk_window_is_maximized, (GtkWindow * window));
MOCK_METHOD(void, gtk_window_iconify, (GtkWindow * window));
MOCK_METHOD(void, gtk_window_deiconify, (GtkWindow * window));
MOCK_METHOD(void, gtk_widget_destroy, (GtkWidget * widget));
MOCK_METHOD(gboolean,
gtk_widget_translate_coordinates,
(GtkWidget * src_widget,
GtkWidget* dest_widget,
gint src_x,
gint src_y,
gint* dest_x,
gint* dest_y));
MOCK_METHOD(GtkWidget*, gtk_widget_get_toplevel, (GtkWidget * widget));
MOCK_METHOD(void,
gtk_im_context_set_client_window,
(GtkIMContext * context, GdkWindow* window));
MOCK_METHOD(void,
gtk_im_context_get_preedit_string,
(GtkIMContext * context,
gchar** str,
PangoAttrList** attrs,
gint* cursor_pos));
MOCK_METHOD(gboolean,
gtk_im_context_filter_keypress,
(GtkIMContext * context, GdkEventKey* event));
MOCK_METHOD(gboolean, gtk_im_context_focus_in, (GtkIMContext * context));
MOCK_METHOD(void, gtk_im_context_focus_out, (GtkIMContext * context));
MOCK_METHOD(void,
gtk_im_context_set_cursor_location,
(GtkIMContext * context, const GdkRectangle* area));
MOCK_METHOD(
void,
gtk_im_context_set_surrounding,
(GtkIMContext * context, const gchar* text, gint len, gint cursor_index));
};
} // namespace testing
} // namespace flutter
// Calls original gtk_widget_destroy.
void fl_gtk_widget_destroy(GtkWidget* widget);
#endif // FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_GTK_H_

View File

@@ -1,92 +0,0 @@
// 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.
#include "flutter/shell/platform/linux/testing/mock_im_context.h"
using namespace flutter::testing;
static MockIMContext* mock = nullptr;
MockIMContext::MockIMContext() {
mock = this;
}
MockIMContext::~MockIMContext() {
if (mock == this) {
mock = nullptr;
}
}
void gtk_im_context_set_client_window(GtkIMContext* context,
GdkWindow* window) {
if (mock != nullptr) {
mock->gtk_im_context_set_client_window(context, window);
}
}
void gtk_im_context_get_preedit_string(GtkIMContext* context,
gchar** str,
PangoAttrList** attrs,
gint* cursor_pos) {
if (mock != nullptr) {
mock->gtk_im_context_get_preedit_string(context, str, attrs, cursor_pos);
}
}
gboolean gtk_im_context_filter_keypress(GtkIMContext* context,
GdkEventKey* event) {
if (mock == nullptr) {
return TRUE;
}
return mock->gtk_im_context_filter_keypress(context, event);
}
void gtk_im_context_focus_in(GtkIMContext* context) {
if (mock != nullptr) {
mock->gtk_im_context_focus_in(context);
}
}
void gtk_im_context_focus_out(GtkIMContext* context) {
if (mock != nullptr) {
mock->gtk_im_context_focus_out(context);
}
}
void gtk_im_context_set_cursor_location(GtkIMContext* context,
const GdkRectangle* area) {
if (mock != nullptr) {
mock->gtk_im_context_set_cursor_location(context, area);
}
}
void gtk_im_context_set_surrounding(GtkIMContext* context,
const gchar* text,
gint len,
gint cursor_index) {
if (mock != nullptr) {
mock->gtk_im_context_set_surrounding(context, text, len, cursor_index);
}
}
gboolean gtk_widget_translate_coordinates(GtkWidget* src_widget,
GtkWidget* dest_widget,
gint src_x,
gint src_y,
gint* dest_x,
gint* dest_y) {
if (mock == nullptr) {
*dest_x = src_x;
*dest_y = src_y;
return TRUE;
}
return mock->gtk_widget_translate_coordinates(src_widget, dest_widget, src_x,
src_y, dest_x, dest_y);
}
GtkWidget* gtk_widget_get_toplevel(GtkWidget* widget) {
return widget;
}

View File

@@ -1,55 +0,0 @@
// 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.
#ifndef FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_IM_CONTEXT_H_
#define FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_IM_CONTEXT_H_
#include <gtk/gtk.h>
#include "gmock/gmock.h"
namespace flutter {
namespace testing {
class MockIMContext {
public:
MockIMContext();
~MockIMContext();
MOCK_METHOD(void,
gtk_im_context_set_client_window,
(GtkIMContext * context, GdkWindow* window));
MOCK_METHOD(void,
gtk_im_context_get_preedit_string,
(GtkIMContext * context,
gchar** str,
PangoAttrList** attrs,
gint* cursor_pos));
MOCK_METHOD(gboolean,
gtk_im_context_filter_keypress,
(GtkIMContext * context, GdkEventKey* event));
MOCK_METHOD(gboolean, gtk_im_context_focus_in, (GtkIMContext * context));
MOCK_METHOD(void, gtk_im_context_focus_out, (GtkIMContext * context));
MOCK_METHOD(void,
gtk_im_context_set_cursor_location,
(GtkIMContext * context, const GdkRectangle* area));
MOCK_METHOD(
void,
gtk_im_context_set_surrounding,
(GtkIMContext * context, const gchar* text, gint len, gint cursor_index));
MOCK_METHOD(gboolean,
gtk_widget_translate_coordinates,
(GtkWidget * src_widget,
GtkWidget* dest_widget,
gint src_x,
gint src_y,
gint* dest_x,
gint* dest_y));
MOCK_METHOD(GtkWidget*, gtk_widget_get_toplevel, (GtkWidget * widget));
};
} // namespace testing
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_IM_CONTEXT_H_

View File

@@ -1,46 +0,0 @@
// 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.
#include "flutter/shell/platform/linux/testing/mock_keymap.h"
using namespace flutter::testing;
G_DECLARE_FINAL_TYPE(FlMockKeymap, fl_mock_keymap, FL, MOCK_KEYMAP, GObject)
struct _FlMockKeymap {
GObject parent_instance;
MockKeymap* mock;
};
G_DEFINE_TYPE(FlMockKeymap, fl_mock_keymap, G_TYPE_OBJECT)
static void fl_mock_keymap_class_init(FlMockKeymapClass* klass) {
g_signal_new("keys-changed", fl_mock_keymap_get_type(), G_SIGNAL_RUN_LAST, 0,
nullptr, nullptr, nullptr, G_TYPE_NONE, 0);
}
static void fl_mock_keymap_init(FlMockKeymap* self) {}
static MockKeymap* mock = nullptr;
MockKeymap::MockKeymap() {
mock = this;
}
MockKeymap::~MockKeymap() {
if (mock == this) {
mock = nullptr;
}
}
GdkKeymap* gdk_keymap_get_for_display(GdkDisplay* display) {
FlMockKeymap* keymap =
FL_MOCK_KEYMAP(g_object_new(fl_mock_keymap_get_type(), nullptr));
(void)FL_IS_MOCK_KEYMAP(keymap);
return reinterpret_cast<GdkKeymap*>(keymap);
}
guint gdk_keymap_lookup_key(GdkKeymap* keymap, const GdkKeymapKey* key) {
return mock->gdk_keymap_lookup_key(keymap, key);
}

View File

@@ -1,29 +0,0 @@
// 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.
#ifndef FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_KEYMAP_H_
#define FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_KEYMAP_H_
#include "gmock/gmock.h"
#include <gdk/gdk.h>
namespace flutter {
namespace testing {
class MockKeymap {
public:
MockKeymap();
~MockKeymap();
MOCK_METHOD(GdkKeymap*, gdk_keymap_get_for_display, (GdkDisplay * display));
MOCK_METHOD(guint,
gdk_keymap_lookup_key,
(GdkKeymap * keymap, const GdkKeymapKey* key));
};
} // namespace testing
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_KEYMAP_H_

View File

@@ -1,111 +0,0 @@
// 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.
#include <dlfcn.h>
#include "flutter/shell/platform/linux/testing/mock_window.h"
using namespace flutter::testing;
static MockWindow* mock = nullptr;
MockWindow::MockWindow() {
mock = this;
}
MockWindow::~MockWindow() {
if (mock == this) {
mock = nullptr;
}
}
GdkDisplay* gdk_display_get_default() {
return GDK_DISPLAY(g_object_new(gdk_display_get_type(), nullptr));
}
void gdk_display_beep(GdkDisplay* display) {}
GdkWindowState gdk_window_get_state(GdkWindow* window) {
return mock->gdk_window_get_state(window);
}
GdkDisplay* gdk_window_get_display(GdkWindow* window) {
return GDK_DISPLAY(g_object_new(gdk_display_get_type(), nullptr));
}
int gdk_display_get_n_monitors(GdkDisplay* display) {
return 1;
}
GdkMonitor* gdk_display_get_monitor(GdkDisplay* display, int n) {
return GDK_MONITOR(g_object_new(gdk_monitor_get_type(), nullptr));
}
GdkMonitor* gdk_display_get_monitor_at_window(GdkDisplay* display,
GdkWindow* window) {
return nullptr;
}
GdkCursor* gdk_cursor_new_from_name(GdkDisplay* display, const gchar* name) {
return nullptr;
}
void gdk_window_set_cursor(GdkWindow* window, GdkCursor* cursor) {}
GtkWidget* gtk_window_new(GtkWindowType type) {
GtkWindow* window = GTK_WINDOW(g_object_new(gtk_window_get_type(), nullptr));
mock->gtk_window_new(window, type);
return GTK_WIDGET(window);
}
void gtk_window_set_default_size(GtkWindow* window, gint width, gint height) {
mock->gtk_window_set_default_size(window, width, height);
}
void gtk_window_set_title(GtkWindow* window, const gchar* title) {
mock->gtk_window_set_title(window, title);
}
void gtk_window_set_geometry_hints(GtkWindow* window,
GtkWidget* widget,
GdkGeometry* geometry,
GdkWindowHints geometry_mask) {
mock->gtk_window_set_geometry_hints(window, widget, geometry, geometry_mask);
}
void gtk_window_resize(GtkWindow* window, gint width, gint height) {
mock->gtk_window_resize(window, width, height);
}
void gtk_window_maximize(GtkWindow* window) {
mock->gtk_window_maximize(window);
}
void gtk_window_unmaximize(GtkWindow* window) {
mock->gtk_window_unmaximize(window);
}
gboolean gtk_window_is_maximized(GtkWindow* window) {
return mock->gtk_window_is_maximized(window);
}
void gtk_window_iconify(GtkWindow* window) {
mock->gtk_window_iconify(window);
}
void gtk_window_deiconify(GtkWindow* window) {
mock->gtk_window_deiconify(window);
}
void gtk_widget_show(GtkWidget* widget) {}
void gtk_widget_destroy(GtkWidget* widget) {
mock->gtk_widget_destroy(widget);
}
void fl_gtk_widget_destroy(GtkWidget* widget) {
void (*destroy)(GtkWidget*) = reinterpret_cast<void (*)(GtkWidget*)>(
dlsym(RTLD_NEXT, "gtk_widget_destroy"));
destroy(widget);
}

View File

@@ -1,51 +0,0 @@
// 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.
#ifndef FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_WINDOW_H_
#define FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_WINDOW_H_
#include "gmock/gmock.h"
#include <gtk/gtk.h>
namespace flutter {
namespace testing {
class MockWindow {
public:
MockWindow();
~MockWindow();
MOCK_METHOD(GdkWindowState, gdk_window_get_state, (GdkWindow * window));
MOCK_METHOD(void, gtk_window_new, (GtkWindow * window, GtkWindowType type));
MOCK_METHOD(void,
gtk_window_set_default_size,
(GtkWindow * window, gint width, gint height));
MOCK_METHOD(void,
gtk_window_set_title,
(GtkWindow * window, const gchar* title));
MOCK_METHOD(void,
gtk_window_set_geometry_hints,
(GtkWindow * window,
GtkWidget* widget,
GdkGeometry* geometry,
GdkWindowHints geometry_mask));
MOCK_METHOD(void,
gtk_window_resize,
(GtkWindow * window, gint width, gint height));
MOCK_METHOD(void, gtk_window_maximize, (GtkWindow * window));
MOCK_METHOD(void, gtk_window_unmaximize, (GtkWindow * window));
MOCK_METHOD(gboolean, gtk_window_is_maximized, (GtkWindow * window));
MOCK_METHOD(void, gtk_window_iconify, (GtkWindow * window));
MOCK_METHOD(void, gtk_window_deiconify, (GtkWindow * window));
MOCK_METHOD(void, gtk_widget_destroy, (GtkWidget * widget));
};
} // namespace testing
} // namespace flutter
// Calls original gtk_widget_destroy.
void fl_gtk_widget_destroy(GtkWidget* widget);
#endif // FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_WINDOW_H_