Flutter Engine
The Flutter Engine
mock_signal_handler.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_SIGNAL_HANDLER_H_
6#define FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_SIGNAL_HANDLER_H_
7
8#include <glib-object.h>
9#include <glib.h>
10
11#include "gmock/gmock.h"
12
13// Expects a signal that has no arguments.
14//
15// MockSignalHandler timeout(timer, "timeout");
16// EXPECT_SIGNAL(timeout).Times(3);
17//
18#define EXPECT_SIGNAL(mock) EXPECT_CALL(mock, Handler())
19
20// Expects a signal that has 1 argument.
21//
22// MockSignalHandler1<int> name_changed(object, "name-changed");
23// EXPECT_SIGNAL(name_changed, testing::StrEq("example"));
24//
25#define EXPECT_SIGNAL1(mock, a1) EXPECT_CALL(mock, Handler1(a1))
26
27// Expects a signal that has 2 arguments.
28//
29// MockSignalHandler2<int, GObject*> child_added(parent, "children::add");
30// EXPECT_SIGNAL2(child_added, testing::Eq(1), testing::A<GObject*>());
31//
32#define EXPECT_SIGNAL2(mock, a1, a2) EXPECT_CALL(mock, Handler2(a1, a2))
33
34namespace flutter {
35namespace testing {
36
38 public:
39 SignalHandler(gpointer instance, const gchar* name, GCallback callback);
40 virtual ~SignalHandler();
41
42 private:
43 gulong id_ = 0;
44 gpointer instance_ = nullptr;
45};
46
47// A mock signal handler that has no arguments. Used with EXPECT_SIGNAL().
49 public:
50 MockSignalHandler(gpointer instance, const gchar* name)
51 : SignalHandler(instance, name, G_CALLBACK(OnSignal)) {}
52
53 MOCK_METHOD(void, Handler, ());
54
55 private:
56 static void OnSignal(MockSignalHandler* mock) { mock->Handler(); }
57};
58
59// A mock signal handler that has 1 argument. Used with EXPECT_SIGNAL1().
60template <typename A1>
62 public:
63 MockSignalHandler1(gpointer instance, const gchar* name)
64 : SignalHandler(instance, name, G_CALLBACK(OnSignal1)) {}
65
66 MOCK_METHOD(void, Handler1, (A1 a1));
67
68 private:
69 static void OnSignal1(MockSignalHandler1* mock, A1 a1) { mock->Handler1(a1); }
70};
71
72// A mock signal handler that has 2 arguments. Used with EXPECT_SIGNAL2().
73template <typename A1, typename A2>
75 public:
76 MockSignalHandler2(gpointer instance, const gchar* name)
77 : SignalHandler(instance, name, G_CALLBACK(OnSignal2)) {}
78
79 MOCK_METHOD(void, Handler2, (A1 a1, A2 a2));
80
81 private:
82 static void OnSignal2(MockSignalHandler2* mock, A1 a1, A2 a2) {
83 mock->Handler2(a1, a2);
84 }
85};
86
87} // namespace testing
88} // namespace flutter
89
90#endif // FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_SIGNAL_HANDLER_H_
MockSignalHandler1(gpointer instance, const gchar *name)
MOCK_METHOD(void, Handler1,(A1 a1))
MockSignalHandler2(gpointer instance, const gchar *name)
MOCK_METHOD(void, Handler2,(A1 a1, A2 a2))
MockSignalHandler(gpointer instance, const gchar *name)
SignalHandler(gpointer instance, const gchar *name, GCallback callback)
VkInstance instance
Definition: main.cc:48
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32