7#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"
8#include "flutter/shell/platform/linux/fl_method_codec_private.h"
9#include "flutter/shell/platform/linux/fl_platform_plugin.h"
10#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_method_codec.h"
11#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_codec.h"
12#include "flutter/shell/platform/linux/testing/fl_test.h"
13#include "flutter/shell/platform/linux/testing/mock_binary_messenger.h"
14#include "flutter/testing/testing.h"
16#include "gmock/gmock.h"
17#include "gtest/gtest.h"
21 g_autoptr(FlMethodResponse) response =
36 ::testing::Matcher<FlValue*>
args)
40 ::testing::MatchResultListener* result_listener)
const {
42 g_autoptr(GError)
error =
nullptr;
43 g_autofree gchar*
name =
nullptr;
51 if (!name_.MatchAndExplain(
name, result_listener)) {
52 *result_listener <<
" where the name doesn't match: \"" <<
name <<
"\"";
55 if (!args_.MatchAndExplain(
args, result_listener)) {
56 *result_listener <<
" where the args don't match: "
64 *os <<
"method name ";
71 *os <<
"method name ";
72 name_.DescribeNegationTo(os);
74 args_.DescribeNegationTo(os);
78 ::testing::Matcher<std::string> name_;
79 ::testing::Matcher<FlValue*> args_;
83 const std::string&
name,
84 ::testing::Matcher<FlValue*>
args) {
98struct _FlTestApplication {
99 GtkApplication parent_instance;
100 gboolean* dispose_called;
105 gtk_application_get_type())
107static
void fl_test_application_startup(GApplication* application) {
108 G_APPLICATION_CLASS(fl_test_application_parent_class)->startup(application);
113 gtk_application_window_new(GTK_APPLICATION(application));
117 G_APPLICATION_CLASS(fl_test_application_parent_class)->activate(application);
119 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
121 EXPECT_NE(plugin,
nullptr);
127 EXPECT_CALL(messenger,
129 ::testing::Eq<FlBinaryMessenger*>(messenger), ::testing::_,
130 SuccessResponse(exit_result), ::testing::_))
131 .WillOnce(::testing::Return(
true));
137 FL_METHOD_CODEC(codec),
"System.exitApplication",
args,
nullptr);
138 messenger.ReceiveMessage(
"flutter/platform",
message);
142 FlTestApplication*
self = FL_TEST_APPLICATION(
object);
144 *
self->dispose_called =
true;
146 G_OBJECT_CLASS(fl_test_application_parent_class)->dispose(
object);
151 G_APPLICATION_CLASS(klass)->startup = fl_test_application_startup;
158 FlTestApplication*
self = FL_TEST_APPLICATION(
159 g_object_new(fl_test_application_get_type(),
nullptr));
162 g_application_set_application_id(G_APPLICATION(
self),
"dev.flutter.GtkTest");
163 g_application_set_flags(G_APPLICATION(
self), G_APPLICATION_NON_UNIQUE);
166 FL_IS_TEST_APPLICATION(
self);
168 self->dispose_called = dispose_called;
173TEST(FlPlatformPluginTest, PlaySound) {
174 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
177 EXPECT_NE(plugin,
nullptr);
182 FL_METHOD_CODEC(codec),
"SystemSound.play",
args,
nullptr);
186 ::testing::Eq<FlBinaryMessenger*>(messenger),
187 ::testing::_, SuccessResponse(null), ::testing::_))
188 .WillOnce(::testing::Return(
true));
190 messenger.ReceiveMessage(
"flutter/platform",
message);
193TEST(FlPlatformPluginTest, ExitApplication) {
194 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
197 EXPECT_NE(plugin,
nullptr);
202 ::testing::Eq<FlBinaryMessenger*>(messenger),
203 ::testing::_, SuccessResponse(null), ::testing::_))
204 .WillByDefault(testing::Return(
TRUE));
207 g_autoptr(GError)
error =
nullptr;
209 FL_METHOD_CODEC(codec),
"System.initializationComplete",
nullptr, &
error);
210 messenger.ReceiveMessage(
"flutter/platform", init_message);
215 EXPECT_CALL(messenger,
217 ::testing::Eq<FlBinaryMessenger*>(messenger),
218 ::testing::StrEq(
"flutter/platform"),
219 MethodCall(
"System.requestAppExit", FlValueEq(request_args)),
220 ::testing::_, ::testing::_, ::testing::_));
225 FL_METHOD_CODEC(codec),
"System.exitApplication",
args,
nullptr);
226 messenger.ReceiveMessage(
"flutter/platform",
message);
229TEST(FlPlatformPluginTest, ExitApplicationDispose) {
230 gtk_init(0,
nullptr);
232 gboolean dispose_called =
false;
236 g_application_run(G_APPLICATION(application), 0,
nullptr);
238 EXPECT_FALSE(dispose_called);
239 g_object_unref(application);
bool MatchAndExplain(GBytes *method_call, ::testing::MatchResultListener *result_listener) const
MethodCallMatcher(::testing::Matcher< std::string > name, ::testing::Matcher< FlValue * > args)
void DescribeTo(std::ostream *os) const
void DescribeNegationTo(std::ostream *os) const
G_MODULE_EXPORT void fl_binary_messenger_send_on_channel(FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(FlBinaryMessenger *self, FlBinaryMessengerResponseHandle *response_handle, GBytes *response, GError **error)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_MODULE_EXPORT FlJsonMethodCodec * fl_json_method_codec_new()
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
G_MODULE_EXPORT FlValue * fl_method_response_get_result(FlMethodResponse *self, GError **error)
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlValue * fl_value_new_map()
G_MODULE_EXPORT void fl_value_set_string_take(FlValue *self, const gchar *key, FlValue *value)
G_MODULE_EXPORT FlValue * fl_value_new_null()
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
typedefG_BEGIN_DECLS struct _FlValue FlValue
static CStringUniquePtr PrintToString(const char *format,...)
DEF_SWITCHES_START aot vmservice shared library name
#define EXPECT_TRUE(handle)