| Flutter Linux Embedder |

Classes | Functions | Variables
fl_keyboard_handler_test.cc File Reference
`#include "flutter/shell/platform/linux/fl_keyboard_handler.h"`
`#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"`
`#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 "gmock/gmock.h"`
`#include "gtest/gtest.h"`

Go to the source code of this file.

## Classes
struct | _FlMockKeyboardHandlerDelegate

## Functions
G_BEGIN_DECLS | G_DECLARE_FINAL_TYPE (FlMockKeyboardHandlerDelegate, fl_mock_keyboard_handler_delegate, FL, MOCK_KEYBOARD_HANDLER_DELEGATE, GObject)
static void | fl_mock_keyboard_handler_delegate_keyboard_view_delegate_iface_init (FlKeyboardViewDelegateInterface *iface)
| G_DEFINE_TYPE_WITH_CODE (FlMockKeyboardHandlerDelegate, fl_mock_keyboard_handler_delegate, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(fl_keyboard_view_delegate_get_type(), fl_mock_keyboard_handler_delegate_keyboard_view_delegate_iface_init)) static void fl_mock_keyboard_handler_delegate_init(FlMockKeyboardHandlerDelegate *self)
static void | fl_mock_keyboard_handler_delegate_class_init (FlMockKeyboardHandlerDelegateClass *klass)
static FlMockKeyboardHandlerDelegate * | fl_mock_keyboard_handler_delegate_new ()
| TEST (FlKeyboardHandlerTest, KeyboardChannelGetPressedState)

## Variables
static constexpr char | kKeyboardChannelName [] = "flutter/keyboard"
static constexpr char | kGetKeyboardStateMethod [] = "getKeyboardState"
static constexpr uint64_t | kMockPhysicalKey = 42
static constexpr uint64_t | kMockLogicalKey = 42

## Function Documentation

## ◆ fl_mock_keyboard_handler_delegate_class_init()

static void fl_mock_keyboard_handler_delegate_class_init | ( | FlMockKeyboardHandlerDelegateClass * | klass | ) |
| static

Definition at line 48 of file fl_keyboard_handler_test.cc.

49 {}

## ◆ fl_mock_keyboard_handler_delegate_keyboard_view_delegate_iface_init()

static void fl_mock_keyboard_handler_delegate_keyboard_view_delegate_iface_init | ( | FlKeyboardViewDelegateInterface * | iface | ) |
| static

Definition at line 51 of file fl_keyboard_handler_test.cc.

52 {}

## ◆ fl_mock_keyboard_handler_delegate_new()

static FlMockKeyboardHandlerDelegate* fl_mock_keyboard_handler_delegate_new | ( |  | ) |
| static

Definition at line 54 of file fl_keyboard_handler_test.cc.

54 {
55 FlMockKeyboardHandlerDelegate* self = FL_MOCK_KEYBOARD_HANDLER_DELEGATE(
56 g_object_new(fl_mock_keyboard_handler_delegate_get_type(), nullptr));
57
58 // Added to stop compiler complaining about an unused function.
59 FL_IS_MOCK_KEYBOARD_HANDLER_DELEGATE(self);
60
61 return self;
62 }

Referenced by TEST().

## ◆ G_DECLARE_FINAL_TYPE()

G_BEGIN_DECLS G_DECLARE_FINAL_TYPE | ( | FlMockKeyboardHandlerDelegate | ,
|  | fl_mock_keyboard_handler_delegate | ,
|  | FL | ,
|  | MOCK_KEYBOARD_HANDLER_DELEGATE | ,
|  | GObject |
| ) |  |

## ◆ G_DEFINE_TYPE_WITH_CODE()

G_DEFINE_TYPE_WITH_CODE | ( | FlMockKeyboardHandlerDelegate | ,
|  | fl_mock_keyboard_handler_delegate | ,
|  | G_TYPE_OBJECT | ,
|  | G_IMPLEMENT_INTERFACE( fl_keyboard_view_delegate_get_type(), fl_mock_keyboard_handler_delegate_keyboard_view_delegate_iface_init) |
| ) |  |

Definition at line 37 of file fl_keyboard_handler_test.cc.

46 {}

## ◆ TEST()

TEST | ( | FlKeyboardHandlerTest | ,
|  | KeyboardChannelGetPressedState |
| ) |  |

Definition at line 64 of file fl_keyboard_handler_test.cc.

64 {
65 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
66 g_autoptr(FlEngine) engine =
67 FL_ENGINE(g_object_new(fl_engine_get_type(), "binary-messenger",
68 FL_BINARY_MESSENGER(messenger), nullptr));
69 g_autoptr(FlMockKeyboardHandlerDelegate) view_delegate =
70 fl_mock_keyboard_handler_delegate_new();
71 g_autoptr(FlKeyboardManager) manager =
72 fl_keyboard_manager_new(engine, FL_KEYBOARD_VIEW_DELEGATE(view_delegate));
73 fl_keyboard_manager_set_get_pressed_state_handler(
74 manager,
75 [](gpointer user_data) {
76 GHashTable* result = g_hash_table_new(g_direct_hash, g_direct_equal);
77 g_hash_table_insert(result,
78 reinterpret_cast<gpointer>(kMockPhysicalKey),
79 reinterpret_cast<gpointer>(kMockLogicalKey));
80
81 return result;
82 },
83 nullptr);
84 g_autoptr(FlKeyboardHandler) handler =
85 fl_keyboard_handler_new(FL_BINARY_MESSENGER(messenger), manager);
86 EXPECT_NE(handler, nullptr);
87
88 gboolean called = FALSE;
89 fl_mock_binary_messenger_invoke_standard_method(
90 messenger, kKeyboardChannelName, kGetKeyboardStateMethod, nullptr,
91 [](FlMockBinaryMessenger* messenger, FlMethodResponse* response,
92 gpointer user_data) {
93 gboolean* called = static_cast<gboolean*>(user_data);
94 *called = TRUE;
95
96 EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
97
98 g_autoptr(FlValue) expected_result = fl_value_new_map();
99 fl_value_set_take(expected_result, fl_value_new_int(kMockPhysicalKey),
100 fl_value_new_int(kMockLogicalKey));
101 EXPECT_TRUE(fl_value_equal(fl_method_success_response_get_result(
102 FL_METHOD_SUCCESS_RESPONSE(response)),
103 expected_result));
104 },
105 &called);
106 EXPECT_TRUE(called);
107
108 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
109 }
fl_binary_messenger_shutdown
void fl_binary_messenger_shutdown(FlBinaryMessenger *self)
Definition: fl_binary_messenger.cc:500
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90
fl_keyboard_handler_new
FlKeyboardHandler * fl_keyboard_handler_new(FlBinaryMessenger *messenger, FlKeyboardManager *keyboard_manager)
Definition: fl_keyboard_handler.cc:62
fl_mock_keyboard_handler_delegate_new
static FlMockKeyboardHandlerDelegate * fl_mock_keyboard_handler_delegate_new()
Definition: fl_keyboard_handler_test.cc:54
kKeyboardChannelName
static constexpr char kKeyboardChannelName[]
Definition: fl_keyboard_handler_test.cc:15
kMockPhysicalKey
static constexpr uint64_t kMockPhysicalKey
Definition: fl_keyboard_handler_test.cc:17
kMockLogicalKey
static constexpr uint64_t kMockLogicalKey
Definition: fl_keyboard_handler_test.cc:18
kGetKeyboardStateMethod
static constexpr char kGetKeyboardStateMethod[]
Definition: fl_keyboard_handler_test.cc:16
fl_keyboard_manager_set_get_pressed_state_handler
void fl_keyboard_manager_set_get_pressed_state_handler(FlKeyboardManager *self, FlKeyboardManagerGetPressedStateHandler get_pressed_state_handler, gpointer user_data)
Definition: fl_keyboard_manager.cc:604
fl_keyboard_manager_new
FlKeyboardManager * fl_keyboard_manager_new(FlEngine *engine, FlKeyboardViewDelegate *view_delegate)
Definition: fl_keyboard_manager.cc:462
fl_method_success_response_get_result
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)
Definition: fl_method_response.cc:138
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
fl_value_set_take
G_MODULE_EXPORT void fl_value_set_take(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:618
fl_value_equal
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:471
fl_value_new_int
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
fl_value_new_map
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:366
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42

References fl_binary_messenger_shutdown(), fl_keyboard_handler_new(), fl_keyboard_manager_new(), fl_keyboard_manager_set_get_pressed_state_handler(), fl_method_success_response_get_result(), fl_mock_keyboard_handler_delegate_new(), fl_value_equal(), fl_value_new_int(), fl_value_new_map(), fl_value_set_take(), kGetKeyboardStateMethod, kKeyboardChannelName, kMockLogicalKey, kMockPhysicalKey, TRUE, and user_data.

## Variable Documentation

## ◆ kGetKeyboardStateMethod

constexpr char kGetKeyboardStateMethod[] = "getKeyboardState"
| static constexpr

Definition at line 16 of file fl_keyboard_handler_test.cc.

Referenced by TEST().

## ◆ kKeyboardChannelName

constexpr char kKeyboardChannelName[] = "flutter/keyboard"
| static constexpr

Definition at line 15 of file fl_keyboard_handler_test.cc.

Referenced by TEST().

## ◆ kMockLogicalKey

constexpr uint64_t kMockLogicalKey = 42
| static constexpr

Definition at line 18 of file fl_keyboard_handler_test.cc.

Referenced by TEST().

## ◆ kMockPhysicalKey

constexpr uint64_t kMockPhysicalKey = 42
| static constexpr

Definition at line 17 of file fl_keyboard_handler_test.cc.

Referenced by TEST().