Replace hacky code creating fake devices (#162056)
This commit is contained in:
parent
663d020788
commit
6e9b863e6d
@ -6,28 +6,12 @@
|
|||||||
#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
|
#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
|
||||||
#include "flutter/shell/platform/linux/fl_engine_private.h"
|
#include "flutter/shell/platform/linux/fl_engine_private.h"
|
||||||
|
|
||||||
|
#include <gdk/gdkwayland.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
// Disgusting hack but could not find any way to create a GdkDevice
|
|
||||||
struct _FakeGdkDevice {
|
|
||||||
GObject parent_instance;
|
|
||||||
gchar* name;
|
|
||||||
GdkInputSource source;
|
|
||||||
};
|
|
||||||
GdkDevice* makeFakeDevice(GdkInputSource source) {
|
|
||||||
_FakeGdkDevice* device =
|
|
||||||
static_cast<_FakeGdkDevice*>(g_malloc0(sizeof(_FakeGdkDevice)));
|
|
||||||
device->source = source;
|
|
||||||
// Bully the type checker
|
|
||||||
(reinterpret_cast<GTypeInstance*>(device))->g_class =
|
|
||||||
static_cast<GTypeClass*>(g_malloc0(sizeof(GTypeClass)));
|
|
||||||
(reinterpret_cast<GTypeInstance*>(device))->g_class->g_type = GDK_TYPE_DEVICE;
|
|
||||||
return reinterpret_cast<GdkDevice*>(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(FlScrollingManagerTest, DiscreteDirectional) {
|
TEST(FlScrollingManagerTest, DiscreteDirectional) {
|
||||||
g_autoptr(FlDartProject) project = fl_dart_project_new();
|
g_autoptr(FlDartProject) project = fl_dart_project_new();
|
||||||
g_autoptr(FlEngine) engine = fl_engine_new(project);
|
g_autoptr(FlEngine) engine = fl_engine_new(project);
|
||||||
@ -50,7 +34,9 @@ TEST(FlScrollingManagerTest, DiscreteDirectional) {
|
|||||||
|
|
||||||
g_autoptr(FlScrollingManager) manager = fl_scrolling_manager_new(engine, 0);
|
g_autoptr(FlScrollingManager) manager = fl_scrolling_manager_new(engine, 0);
|
||||||
|
|
||||||
GdkDevice* mouse = makeFakeDevice(GDK_SOURCE_MOUSE);
|
GdkDevice* mouse =
|
||||||
|
GDK_DEVICE(g_object_new(gdk_wayland_device_get_type(), "input-source",
|
||||||
|
GDK_SOURCE_MOUSE, nullptr));
|
||||||
GdkEventScroll* event =
|
GdkEventScroll* event =
|
||||||
reinterpret_cast<GdkEventScroll*>(gdk_event_new(GDK_SCROLL));
|
reinterpret_cast<GdkEventScroll*>(gdk_event_new(GDK_SCROLL));
|
||||||
event->time = 1;
|
event->time = 1;
|
||||||
@ -121,7 +107,9 @@ TEST(FlScrollingManagerTest, DiscreteScrolling) {
|
|||||||
|
|
||||||
g_autoptr(FlScrollingManager) manager = fl_scrolling_manager_new(engine, 0);
|
g_autoptr(FlScrollingManager) manager = fl_scrolling_manager_new(engine, 0);
|
||||||
|
|
||||||
GdkDevice* mouse = makeFakeDevice(GDK_SOURCE_MOUSE);
|
GdkDevice* mouse =
|
||||||
|
GDK_DEVICE(g_object_new(gdk_wayland_device_get_type(), "input-source",
|
||||||
|
GDK_SOURCE_MOUSE, nullptr));
|
||||||
GdkEventScroll* event =
|
GdkEventScroll* event =
|
||||||
reinterpret_cast<GdkEventScroll*>(gdk_event_new(GDK_SCROLL));
|
reinterpret_cast<GdkEventScroll*>(gdk_event_new(GDK_SCROLL));
|
||||||
event->time = 1;
|
event->time = 1;
|
||||||
@ -164,7 +152,9 @@ TEST(FlScrollingManagerTest, Panning) {
|
|||||||
|
|
||||||
g_autoptr(FlScrollingManager) manager = fl_scrolling_manager_new(engine, 0);
|
g_autoptr(FlScrollingManager) manager = fl_scrolling_manager_new(engine, 0);
|
||||||
|
|
||||||
GdkDevice* touchpad = makeFakeDevice(GDK_SOURCE_TOUCHPAD);
|
GdkDevice* touchpad =
|
||||||
|
GDK_DEVICE(g_object_new(gdk_wayland_device_get_type(), "input-source",
|
||||||
|
GDK_SOURCE_TOUCHPAD, nullptr));
|
||||||
GdkEventScroll* event =
|
GdkEventScroll* event =
|
||||||
reinterpret_cast<GdkEventScroll*>(gdk_event_new(GDK_SCROLL));
|
reinterpret_cast<GdkEventScroll*>(gdk_event_new(GDK_SCROLL));
|
||||||
event->time = 1;
|
event->time = 1;
|
||||||
|
@ -6,27 +6,12 @@
|
|||||||
#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
|
#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
|
||||||
#include "flutter/shell/platform/linux/fl_engine_private.h"
|
#include "flutter/shell/platform/linux/fl_engine_private.h"
|
||||||
|
|
||||||
|
#include <gdk/gdkwayland.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
struct _FakeGdkDevice {
|
|
||||||
GObject parent_instance;
|
|
||||||
gchar* name;
|
|
||||||
GdkInputSource source;
|
|
||||||
};
|
|
||||||
static GdkDevice* makeFakeDevice(GdkInputSource source) {
|
|
||||||
_FakeGdkDevice* device =
|
|
||||||
static_cast<_FakeGdkDevice*>(g_malloc0(sizeof(_FakeGdkDevice)));
|
|
||||||
device->source = source;
|
|
||||||
// Bully the type checker
|
|
||||||
(reinterpret_cast<GTypeInstance*>(device))->g_class =
|
|
||||||
static_cast<GTypeClass*>(g_malloc0(sizeof(GTypeClass)));
|
|
||||||
(reinterpret_cast<GTypeInstance*>(device))->g_class->g_type = GDK_TYPE_DEVICE;
|
|
||||||
return reinterpret_cast<GdkDevice*>(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(FlTouchManagerTest, TouchEvents) {
|
TEST(FlTouchManagerTest, TouchEvents) {
|
||||||
g_autoptr(FlDartProject) project = fl_dart_project_new();
|
g_autoptr(FlDartProject) project = fl_dart_project_new();
|
||||||
g_autoptr(FlEngine) engine = fl_engine_new(project);
|
g_autoptr(FlEngine) engine = fl_engine_new(project);
|
||||||
@ -49,7 +34,9 @@ TEST(FlTouchManagerTest, TouchEvents) {
|
|||||||
|
|
||||||
g_autoptr(FlTouchManager) manager = fl_touch_manager_new(engine, 0);
|
g_autoptr(FlTouchManager) manager = fl_touch_manager_new(engine, 0);
|
||||||
|
|
||||||
GdkDevice* touchscreen = makeFakeDevice(GDK_SOURCE_TOUCHSCREEN);
|
GdkDevice* touchscreen =
|
||||||
|
GDK_DEVICE(g_object_new(gdk_wayland_device_get_type(), "input-source",
|
||||||
|
GDK_SOURCE_TOUCHSCREEN, nullptr));
|
||||||
GdkEventTouch* event =
|
GdkEventTouch* event =
|
||||||
reinterpret_cast<GdkEventTouch*>(gdk_event_new(GDK_TOUCH_BEGIN));
|
reinterpret_cast<GdkEventTouch*>(gdk_event_new(GDK_TOUCH_BEGIN));
|
||||||
event->time = 1;
|
event->time = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user