Flutter Linux Embedder
fl_platform_plugin_test.cc File Reference
#include "flutter/shell/platform/linux/fl_platform_plugin.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_json_method_codec.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_codec.h"
#include "flutter/shell/platform/linux/testing/fl_test.h"
#include "flutter/shell/platform/linux/testing/mock_binary_messenger.h"
#include "flutter/testing/testing.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Classes

class  MethodCallMatcher
 

Functions

 MATCHER_P (SuccessResponse, result, "")
 
static ::testing::Matcher< GBytes * > MethodCall (const std::string &name, ::testing::Matcher< FlValue * > args)
 
 MATCHER_P (FlValueEq, value, "equal to "+::testing::PrintToString(value))
 
 TEST (FlPlatformPluginTest, PlaySound)
 
 TEST (FlPlatformPluginTest, ExitApplication)
 

Function Documentation

◆ MATCHER_P() [1/2]

MATCHER_P ( FlValueEq  ,
value  ,
"equal to "+  ::testing::PrintToStringvalue 
)

Definition at line 86 of file fl_platform_plugin_test.cc.

86  {
87  return fl_value_equal(arg, value);
88 }

References fl_value_equal(), and value.

◆ MATCHER_P() [2/2]

MATCHER_P ( SuccessResponse  ,
result  ,
""   
)

Definition at line 17 of file fl_platform_plugin_test.cc.

17  {
18  g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
19  g_autoptr(FlMethodResponse) response =
20  fl_method_codec_decode_response(FL_METHOD_CODEC(codec), arg, nullptr);
21  if (fl_value_equal(fl_method_response_get_result(response, nullptr),
22  result)) {
23  return true;
24  }
25  *result_listener << ::testing::PrintToString(response);
26  return false;
27 }

References fl_json_method_codec_new(), fl_method_codec_decode_response(), fl_method_response_get_result(), fl_value_equal(), and result.

◆ MethodCall()

static ::testing::Matcher<GBytes*> MethodCall ( const std::string &  name,
::testing::Matcher< FlValue * >  args 
)

Definition at line 80 of file fl_platform_plugin_test.cc.

82  {
83  return MethodCallMatcher(::testing::StrEq(name), std::move(args));
84 }

References args.

Referenced by TEST().

◆ TEST() [1/2]

TEST ( FlPlatformPluginTest  ,
ExitApplication   
)

Definition at line 110 of file fl_platform_plugin_test.cc.

110  {
111  ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
112 
113  g_autoptr(FlPlatformPlugin) plugin = fl_platform_plugin_new(messenger);
114  EXPECT_NE(plugin, nullptr);
115  g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
116 
117  g_autoptr(FlValue) null = fl_value_new_null();
118  ON_CALL(messenger, fl_binary_messenger_send_response(
119  ::testing::Eq<FlBinaryMessenger*>(messenger),
120  ::testing::_, SuccessResponse(null), ::testing::_))
121  .WillByDefault(testing::Return(TRUE));
122 
123  // Indicate that the binding is initialized.
124  g_autoptr(GError) error = nullptr;
125  g_autoptr(GBytes) init_message = fl_method_codec_encode_method_call(
126  FL_METHOD_CODEC(codec), "System.initializationComplete", nullptr, &error);
127  messenger.ReceiveMessage("flutter/platform", init_message);
128 
129  g_autoptr(FlValue) request_args = fl_value_new_map();
130  fl_value_set_string_take(request_args, "type",
131  fl_value_new_string("cancelable"));
132  EXPECT_CALL(messenger,
134  ::testing::Eq<FlBinaryMessenger*>(messenger),
135  ::testing::StrEq("flutter/platform"),
136  MethodCall("System.requestAppExit", FlValueEq(request_args)),
137  ::testing::_, ::testing::_, ::testing::_));
138 
139  g_autoptr(FlValue) args = fl_value_new_map();
140  fl_value_set_string_take(args, "type", fl_value_new_string("cancelable"));
141  g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
142  FL_METHOD_CODEC(codec), "System.exitApplication", args, nullptr);
143  messenger.ReceiveMessage("flutter/platform", message);
144 }

References args, error, fl_binary_messenger_send_on_channel(), fl_binary_messenger_send_response(), fl_json_method_codec_new(), fl_method_codec_encode_method_call(), fl_platform_plugin_new(), fl_value_new_map(), fl_value_new_null(), fl_value_new_string(), fl_value_set_string_take(), MethodCall(), and TRUE.

◆ TEST() [2/2]

TEST ( FlPlatformPluginTest  ,
PlaySound   
)

Definition at line 90 of file fl_platform_plugin_test.cc.

90  {
91  ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
92 
93  g_autoptr(FlPlatformPlugin) plugin = fl_platform_plugin_new(messenger);
94  EXPECT_NE(plugin, nullptr);
95 
96  g_autoptr(FlValue) args = fl_value_new_string("SystemSoundType.alert");
97  g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
98  g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
99  FL_METHOD_CODEC(codec), "SystemSound.play", args, nullptr);
100 
101  g_autoptr(FlValue) null = fl_value_new_null();
102  EXPECT_CALL(messenger, fl_binary_messenger_send_response(
103  ::testing::Eq<FlBinaryMessenger*>(messenger),
104  ::testing::_, SuccessResponse(null), ::testing::_))
105  .WillOnce(::testing::Return(true));
106 
107  messenger.ReceiveMessage("flutter/platform", message);
108 }

References args, fl_binary_messenger_send_response(), fl_json_method_codec_new(), fl_method_codec_encode_method_call(), fl_platform_plugin_new(), fl_value_new_null(), and fl_value_new_string().

fl_json_method_codec_new
G_MODULE_EXPORT FlJsonMethodCodec * fl_json_method_codec_new()
Definition: fl_json_method_codec.cc:205
fl_method_codec_encode_method_call
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
Definition: fl_method_codec.cc:16
fl_value_set_string_take
G_MODULE_EXPORT void fl_value_set_string_take(FlValue *self, const gchar *key, FlValue *value)
Definition: fl_value.cc:610
MethodCall
static ::testing::Matcher< GBytes * > MethodCall(const std::string &name, ::testing::Matcher< FlValue * > args)
Definition: fl_platform_plugin_test.cc:80
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
fl_platform_plugin_new
FlPlatformPlugin * fl_platform_plugin_new(FlBinaryMessenger *messenger)
Definition: fl_platform_plugin.cc:391
fl_value_new_null
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:240
fl_method_response_get_result
G_MODULE_EXPORT FlValue * fl_method_response_get_result(FlMethodResponse *self, GError **error)
Definition: fl_method_response.cc:82
fl_value_new_map
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:355
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
fl_method_codec_decode_response
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
Definition: fl_method_codec.cc:62
fl_value_equal
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:433
result
GAsyncResult * result
Definition: fl_text_input_plugin.cc:106
MethodCallMatcher
Definition: fl_platform_plugin_test.cc:29
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_binary_messenger_send_response
G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(FlBinaryMessenger *self, FlBinaryMessengerResponseHandle *response_handle, GBytes *response, GError **error)
Definition: fl_binary_messenger.cc:438
value
uint8_t value
Definition: fl_standard_message_codec.cc:41
fl_binary_messenger_send_on_channel
G_MODULE_EXPORT void fl_binary_messenger_send_on_channel(FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_binary_messenger.cc:451
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:265