Flutter Engine
fl_method_channel_test.cc File Reference
#include "gtest/gtest.h"
#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"
#include "flutter/shell/platform/linux/fl_engine_private.h"
#include "flutter/shell/platform/linux/fl_method_codec_private.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
#include "flutter/shell/platform/linux/testing/fl_test.h"
#include "flutter/shell/platform/linux/testing/mock_renderer.h"

Go to the source code of this file.

Classes

struct  UserDataReassignMethod
 

Functions

static void method_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
 
 TEST (FlMethodChannelTest, InvokeMethod)
 
static void nullptr_args_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
 
 TEST (FlMethodChannelTest, InvokeMethodNullptrArgsMessage)
 
static void error_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
 
 TEST (FlMethodChannelTest, InvokeMethodError)
 
static void not_implemented_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
 
 TEST (FlMethodChannelTest, InvokeMethodNotImplemented)
 
static void failure_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
 
 TEST (FlMethodChannelTest, InvokeMethodFailure)
 
static void method_call_success_cb (FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
 
static void method_call_success_response_cb (FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
 
 TEST (FlMethodChannelTest, ReceiveMethodCallRespondSuccess)
 
static void method_call_error_cb (FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
 
static void method_call_error_response_cb (FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
 
 TEST (FlMethodChannelTest, ReceiveMethodCallRespondError)
 
static void method_call_not_implemented_cb (FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
 
static void method_call_not_implemented_response_cb (FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
 
 TEST (FlMethodChannelTest, ReceiveMethodCallRespondNotImplemented)
 
 G_DECLARE_FINAL_TYPE (TestMethodCodec, test_method_codec, TEST, METHOD_CODEC, FlMethodCodec) struct _TestMethodCodec
 
static void test_method_codec_dispose (GObject *object)
 
static GBytes * test_method_codec_encode_method_call (FlMethodCodec *codec, const gchar *name, FlValue *args, GError **error)
 
static gboolean test_method_codec_decode_method_call (FlMethodCodec *codec, GBytes *message, gchar **name, FlValue **args, GError **error)
 
static GBytes * test_method_codec_encode_success_envelope (FlMethodCodec *codec, FlValue *result, GError **error)
 
static GBytes * test_method_codec_encode_error_envelope (FlMethodCodec *codec, const gchar *code, const gchar *message, FlValue *details, GError **error)
 
static FlMethodResponse * test_method_codec_decode_response (FlMethodCodec *codec, GBytes *message, GError **error)
 
static void test_method_codec_class_init (TestMethodCodecClass *klass)
 
static void test_method_codec_init (TestMethodCodec *self)
 
TestMethodCodec * test_method_codec_new ()
 
static void method_call_success_error_cb (FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
 
 TEST (FlMethodChannelTest, ReceiveMethodCallRespondSuccessError)
 
static void method_call_error_error_cb (FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
 
 TEST (FlMethodChannelTest, ReceiveMethodCallRespondErrorError)
 
static void reassign_method_cb (FlMethodChannel *channel, FlMethodCall *method_call, gpointer raw_user_data)
 
 TEST (FlMethodChannelTest, ReplaceADisposedMethodChannel)
 
 TEST (FlMethodChannelTest, DisposeAReplacedMethodChannel)
 

Function Documentation

◆ error_response_cb()

static void error_response_cb ( GObject *  object,
GAsyncResult *  result,
gpointer  user_data 
)
static

Definition at line 94 of file fl_method_channel_test.cc.

References error, fl_method_channel_invoke_method_finish(), fl_method_error_response_get_code(), fl_method_error_response_get_details(), fl_method_error_response_get_message(), fl_value_get_string(), fl_value_get_type(), and FL_VALUE_TYPE_STRING.

Referenced by TEST().

96  {
97  g_autoptr(GError) error = nullptr;
98  g_autoptr(FlMethodResponse) response = fl_method_channel_invoke_method_finish(
99  FL_METHOD_CHANNEL(object), result, &error);
100  EXPECT_NE(response, nullptr);
101  EXPECT_EQ(error, nullptr);
102 
103  EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
104  EXPECT_STREQ(
105  fl_method_error_response_get_code(FL_METHOD_ERROR_RESPONSE(response)),
106  "CODE");
107  EXPECT_STREQ(
108  fl_method_error_response_get_message(FL_METHOD_ERROR_RESPONSE(response)),
109  "MESSAGE");
110  FlValue* details =
111  fl_method_error_response_get_details(FL_METHOD_ERROR_RESPONSE(response));
112  EXPECT_NE(details, nullptr);
113  EXPECT_EQ(fl_value_get_type(details), FL_VALUE_TYPE_STRING);
114  EXPECT_STREQ(fl_value_get_string(details), "DETAILS");
115 
116  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
117 }
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:428
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
void * user_data
GAsyncResult * result
G_MODULE_EXPORT const gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:642
G_MODULE_EXPORT const gchar * fl_method_error_response_get_code(FlMethodErrorResponse *self)
G_MODULE_EXPORT FlValue * fl_method_error_response_get_details(FlMethodErrorResponse *self)

◆ failure_response_cb()

static void failure_response_cb ( GObject *  object,
GAsyncResult *  result,
gpointer  user_data 
)
static

Definition at line 175 of file fl_method_channel_test.cc.

References error, and fl_method_channel_invoke_method_finish().

Referenced by TEST().

177  {
178  g_autoptr(GError) error = nullptr;
179  g_autoptr(FlMethodResponse) response = fl_method_channel_invoke_method_finish(
180  FL_METHOD_CHANNEL(object), result, &error);
181  EXPECT_EQ(response, nullptr);
182  EXPECT_NE(error, nullptr);
183 
184  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
185 }
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
const uint8_t uint32_t uint32_t GError ** error
void * user_data
GAsyncResult * result

◆ G_DECLARE_FINAL_TYPE()

G_DECLARE_FINAL_TYPE ( TestMethodCodec  ,
test_method_codec  ,
TEST  ,
METHOD_CODEC  ,
FlMethodCodec   
)

Definition at line 426 of file fl_method_channel_test.cc.

References fl_method_codec_get_type(), and G_DEFINE_TYPE().

432  {
433  FlMethodCodec parent_instance;
434 
435  FlStandardMethodCodec* wrapped_codec;
436 };

◆ method_call_error_cb()

static void method_call_error_cb ( FlMethodChannel *  channel,
FlMethodCall *  method_call,
gpointer  user_data 
)
static

Definition at line 279 of file fl_method_channel_test.cc.

References error, fl_method_call_get_args(), fl_method_call_get_name(), fl_method_call_respond_error(), fl_value_get_string(), fl_value_get_type(), fl_value_new_string(), and FL_VALUE_TYPE_STRING.

Referenced by TEST().

281  {
282  EXPECT_STREQ(fl_method_call_get_name(method_call), "Foo");
286  "Marco!");
287 
288  g_autoptr(FlValue) details = fl_value_new_string("DETAILS");
289  g_autoptr(GError) error = nullptr;
290  EXPECT_TRUE(fl_method_call_respond_error(method_call, "CODE", "MESSAGE",
291  details, &error));
292  EXPECT_EQ(error, nullptr);
293 }
G_BEGIN_DECLS FlMethodCall * method_call
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:428
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
G_MODULE_EXPORT FlValue * fl_method_call_get_args(FlMethodCall *self)
G_MODULE_EXPORT const gchar * fl_method_call_get_name(FlMethodCall *self)
G_MODULE_EXPORT gboolean fl_method_call_respond_error(FlMethodCall *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:265
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:642

◆ method_call_error_error_cb()

static void method_call_error_error_cb ( FlMethodChannel *  channel,
FlMethodCall *  method_call,
gpointer  user_data 
)
static

Definition at line 567 of file fl_method_channel_test.cc.

References fl_method_call_respond_error(), fl_method_call_respond_not_implemented(), and fl_value_new_int().

Referenced by TEST().

569  {
570  g_autoptr(FlValue) details = fl_value_new_int(42);
571  g_autoptr(GError) response_error = nullptr;
572  EXPECT_FALSE(fl_method_call_respond_error(method_call, "error", "ERROR",
573  details, &response_error));
574  EXPECT_NE(response_error, nullptr);
575 
576  // Respond to stop a warning occurring about not responding.
578 
579  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
580 }
G_BEGIN_DECLS FlMethodCall * method_call
G_MODULE_EXPORT gboolean fl_method_call_respond_not_implemented(FlMethodCall *self, GError **error)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
void * user_data
G_MODULE_EXPORT gboolean fl_method_call_respond_error(FlMethodCall *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:251

◆ method_call_error_response_cb()

static void method_call_error_response_cb ( FlBinaryMessenger *  messenger,
const gchar *  channel,
GBytes *  message,
FlBinaryMessengerResponseHandle *  response_handle,
gpointer  user_data 
)
static

Definition at line 297 of file fl_method_channel_test.cc.

References error, fl_binary_messenger_send_response(), fl_method_codec_decode_response(), fl_method_error_response_get_code(), fl_method_error_response_get_details(), fl_method_error_response_get_message(), fl_standard_method_codec_new(), fl_value_get_string(), fl_value_get_type(), and FL_VALUE_TYPE_STRING.

Referenced by TEST().

302  {
303  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
304  g_autoptr(GError) error = nullptr;
305  g_autoptr(FlMethodResponse) response =
306  fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
307  EXPECT_NE(response, nullptr);
308  EXPECT_EQ(error, nullptr);
309 
310  EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
311  EXPECT_STREQ(
312  fl_method_error_response_get_code(FL_METHOD_ERROR_RESPONSE(response)),
313  "CODE");
314  EXPECT_STREQ(
315  fl_method_error_response_get_message(FL_METHOD_ERROR_RESPONSE(response)),
316  "MESSAGE");
317  FlValue* details =
318  fl_method_error_response_get_details(FL_METHOD_ERROR_RESPONSE(response));
319  EXPECT_EQ(fl_value_get_type(details), FL_VALUE_TYPE_STRING);
320  EXPECT_STREQ(fl_value_get_string(details), "DETAILS");
321 
322  fl_binary_messenger_send_response(messenger, response_handle, nullptr,
323  nullptr);
324 
325  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
326 }
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:428
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
void * user_data
G_MODULE_EXPORT const gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(FlBinaryMessenger *self, FlBinaryMessengerResponseHandle *response_handle, GBytes *response, GError **error)
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:642
G_MODULE_EXPORT const gchar * fl_method_error_response_get_code(FlMethodErrorResponse *self)
G_MODULE_EXPORT FlValue * fl_method_error_response_get_details(FlMethodErrorResponse *self)

◆ method_call_not_implemented_cb()

static void method_call_not_implemented_cb ( FlMethodChannel *  channel,
FlMethodCall *  method_call,
gpointer  user_data 
)
static

Definition at line 359 of file fl_method_channel_test.cc.

References error, fl_method_call_get_args(), fl_method_call_get_name(), fl_method_call_respond_not_implemented(), fl_value_get_string(), fl_value_get_type(), and FL_VALUE_TYPE_STRING.

Referenced by TEST().

361  {
362  EXPECT_STREQ(fl_method_call_get_name(method_call), "Foo");
366  "Marco!");
367 
368  g_autoptr(GError) error = nullptr;
370  EXPECT_EQ(error, nullptr);
371 }
G_BEGIN_DECLS FlMethodCall * method_call
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:428
G_MODULE_EXPORT gboolean fl_method_call_respond_not_implemented(FlMethodCall *self, GError **error)
G_MODULE_EXPORT FlValue * fl_method_call_get_args(FlMethodCall *self)
G_MODULE_EXPORT const gchar * fl_method_call_get_name(FlMethodCall *self)
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:642

◆ method_call_not_implemented_response_cb()

static void method_call_not_implemented_response_cb ( FlBinaryMessenger *  messenger,
const gchar *  channel,
GBytes *  message,
FlBinaryMessengerResponseHandle *  response_handle,
gpointer  user_data 
)
static

Definition at line 375 of file fl_method_channel_test.cc.

References error, fl_binary_messenger_send_response(), fl_method_codec_decode_response(), and fl_standard_method_codec_new().

Referenced by TEST().

380  {
381  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
382  g_autoptr(GError) error = nullptr;
383  g_autoptr(FlMethodResponse) response =
384  fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
385  EXPECT_NE(response, nullptr);
386  EXPECT_EQ(error, nullptr);
387 
388  EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
389 
390  fl_binary_messenger_send_response(messenger, response_handle, nullptr,
391  nullptr);
392 
393  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
394 }
const uint8_t uint32_t uint32_t GError ** error
void * user_data
G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(FlBinaryMessenger *self, FlBinaryMessengerResponseHandle *response_handle, GBytes *response, GError **error)
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)

◆ method_call_success_cb()

static void method_call_success_cb ( FlMethodChannel *  channel,
FlMethodCall *  method_call,
gpointer  user_data 
)
static

Definition at line 206 of file fl_method_channel_test.cc.

References error, fl_method_call_get_args(), fl_method_call_get_name(), fl_method_call_respond_success(), fl_value_get_string(), fl_value_get_type(), fl_value_new_string(), FL_VALUE_TYPE_STRING, and result.

Referenced by TEST().

208  {
209  EXPECT_STREQ(fl_method_call_get_name(method_call), "Foo");
213  "Marco!");
214 
215  g_autoptr(FlValue) result = fl_value_new_string("Polo!");
216  g_autoptr(GError) error = nullptr;
218  EXPECT_EQ(error, nullptr);
219 }
G_BEGIN_DECLS FlMethodCall * method_call
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:428
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
G_MODULE_EXPORT gboolean fl_method_call_respond_success(FlMethodCall *self, FlValue *result, GError **error)
GAsyncResult * result
G_MODULE_EXPORT FlValue * fl_method_call_get_args(FlMethodCall *self)
G_MODULE_EXPORT const gchar * fl_method_call_get_name(FlMethodCall *self)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:265
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:642

◆ method_call_success_error_cb()

static void method_call_success_error_cb ( FlMethodChannel *  channel,
FlMethodCall *  method_call,
gpointer  user_data 
)
static

Definition at line 525 of file fl_method_channel_test.cc.

References fl_method_call_respond_not_implemented(), fl_method_call_respond_success(), fl_value_new_int(), and result.

Referenced by TEST().

527  {
528  g_autoptr(FlValue) result = fl_value_new_int(42);
529  g_autoptr(GError) response_error = nullptr;
530  EXPECT_FALSE(
532  EXPECT_NE(response_error, nullptr);
533 
534  // Respond to stop a warning occurring about not responding.
536 
537  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
538 }
G_BEGIN_DECLS FlMethodCall * method_call
G_MODULE_EXPORT gboolean fl_method_call_respond_not_implemented(FlMethodCall *self, GError **error)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
G_MODULE_EXPORT gboolean fl_method_call_respond_success(FlMethodCall *self, FlValue *result, GError **error)
void * user_data
GAsyncResult * result
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:251

◆ method_call_success_response_cb()

static void method_call_success_response_cb ( FlBinaryMessenger *  messenger,
const gchar *  channel,
GBytes *  message,
FlBinaryMessengerResponseHandle *  response_handle,
gpointer  user_data 
)
static

Definition at line 223 of file fl_method_channel_test.cc.

References error, fl_binary_messenger_send_response(), fl_method_codec_decode_response(), fl_method_success_response_get_result(), fl_standard_method_codec_new(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_STRING, and result.

Referenced by TEST().

228  {
229  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
230  g_autoptr(GError) error = nullptr;
231  g_autoptr(FlMethodResponse) response =
232  fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
233  EXPECT_NE(response, nullptr);
234  EXPECT_EQ(error, nullptr);
235 
236  EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
238  FL_METHOD_SUCCESS_RESPONSE(response));
239  EXPECT_EQ(fl_value_get_type(result), FL_VALUE_TYPE_STRING);
240  EXPECT_STREQ(fl_value_get_string(result), "Polo!");
241 
242  fl_binary_messenger_send_response(messenger, response_handle, nullptr,
243  nullptr);
244 
245  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
246 }
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:428
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
void * user_data
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)
GAsyncResult * result
G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(FlBinaryMessenger *self, FlBinaryMessengerResponseHandle *response_handle, GBytes *response, GError **error)
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:642

◆ method_response_cb()

static void method_response_cb ( GObject *  object,
GAsyncResult *  result,
gpointer  user_data 
)
static

Definition at line 19 of file fl_method_channel_test.cc.

References error, fl_method_channel_invoke_method_finish(), fl_method_response_get_result(), fl_value_get_string(), fl_value_get_type(), and FL_VALUE_TYPE_STRING.

Referenced by TEST().

21  {
22  g_autoptr(GError) error = nullptr;
23  g_autoptr(FlMethodResponse) response = fl_method_channel_invoke_method_finish(
24  FL_METHOD_CHANNEL(object), result, &error);
25  EXPECT_NE(response, nullptr);
26  EXPECT_EQ(error, nullptr);
27 
29  EXPECT_NE(r, nullptr);
30  EXPECT_EQ(error, nullptr);
31 
33  EXPECT_STREQ(fl_value_get_string(r), "Hello World!");
34 
35  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
36 }
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:428
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
void * user_data
GAsyncResult * result
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:642
G_MODULE_EXPORT FlValue * fl_method_response_get_result(FlMethodResponse *self, GError **error)

◆ not_implemented_response_cb()

static void not_implemented_response_cb ( GObject *  object,
GAsyncResult *  result,
gpointer  user_data 
)
static

Definition at line 142 of file fl_method_channel_test.cc.

References error, and fl_method_channel_invoke_method_finish().

Referenced by TEST().

144  {
145  g_autoptr(GError) error = nullptr;
146  g_autoptr(FlMethodResponse) response = fl_method_channel_invoke_method_finish(
147  FL_METHOD_CHANNEL(object), result, &error);
148  EXPECT_NE(response, nullptr);
149  EXPECT_EQ(error, nullptr);
150 
151  EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
152 
153  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
154 }
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
const uint8_t uint32_t uint32_t GError ** error
void * user_data
GAsyncResult * result

◆ nullptr_args_response_cb()

static void nullptr_args_response_cb ( GObject *  object,
GAsyncResult *  result,
gpointer  user_data 
)
static

Definition at line 58 of file fl_method_channel_test.cc.

References error, fl_method_channel_invoke_method_finish(), fl_method_response_get_result(), fl_value_get_type(), and FL_VALUE_TYPE_NULL.

Referenced by TEST().

60  {
61  g_autoptr(GError) error = nullptr;
62  g_autoptr(FlMethodResponse) response = fl_method_channel_invoke_method_finish(
63  FL_METHOD_CHANNEL(object), result, &error);
64  EXPECT_NE(response, nullptr);
65  EXPECT_EQ(error, nullptr);
66 
68  EXPECT_NE(r, nullptr);
69  EXPECT_EQ(error, nullptr);
71 
72  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
73 }
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:428
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
void * user_data
GAsyncResult * result
G_MODULE_EXPORT FlValue * fl_method_response_get_result(FlMethodResponse *self, GError **error)

◆ reassign_method_cb()

static void reassign_method_cb ( FlMethodChannel *  channel,
FlMethodCall *  method_call,
gpointer  raw_user_data 
)
static

Definition at line 614 of file fl_method_channel_test.cc.

References UserDataReassignMethod::count, error, fl_method_call_respond_success(), fl_value_new_string(), UserDataReassignMethod::loop, result, and user_data.

Referenced by TEST().

616  {
618  static_cast<UserDataReassignMethod*>(raw_user_data);
619  user_data->count += 1;
620 
621  g_autoptr(FlValue) result = fl_value_new_string("Polo!");
622  g_autoptr(GError) error = nullptr;
624  EXPECT_EQ(error, nullptr);
625 
626  g_main_loop_quit(user_data->loop);
627 }
G_BEGIN_DECLS FlMethodCall * method_call
const uint8_t uint32_t uint32_t GError ** error
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
G_MODULE_EXPORT gboolean fl_method_call_respond_success(FlMethodCall *self, FlValue *result, GError **error)
void * user_data
GAsyncResult * result
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:265

◆ TEST() [1/12]

TEST ( FlMethodChannelTest  ,
InvokeMethod   
)

Definition at line 39 of file fl_method_channel_test.cc.

References args, engine, fl_binary_messenger_new(), fl_method_channel_invoke_method(), fl_method_channel_new(), fl_standard_method_codec_new(), fl_value_new_string(), make_mock_engine(), and method_response_cb().

39  {
40  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
41 
42  g_autoptr(FlEngine) engine = make_mock_engine();
43  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
44  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
45  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
46  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
47 
48  g_autoptr(FlValue) args = fl_value_new_string("Hello World!");
49  fl_method_channel_invoke_method(channel, "Echo", args, nullptr,
50  method_response_cb, loop);
51 
52  // Blocks here until method_response_cb is called.
53  g_main_loop_run(loop);
54 }
G_BEGIN_DECLS FlValue * args
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
static void method_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:265
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)

◆ TEST() [2/12]

TEST ( FlMethodChannelTest  ,
InvokeMethodNullptrArgsMessage   
)

Definition at line 76 of file fl_method_channel_test.cc.

References engine, fl_binary_messenger_new(), fl_method_channel_invoke_method(), fl_method_channel_new(), fl_standard_method_codec_new(), make_mock_engine(), and nullptr_args_response_cb().

76  {
77  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
78 
79  g_autoptr(FlEngine) engine = make_mock_engine();
80  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
81  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
82  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
83  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
84 
85  fl_method_channel_invoke_method(channel, "Echo", nullptr, nullptr,
87 
88  // Blocks here until nullptr_args_response_cb is called.
89  g_main_loop_run(loop);
90 }
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
static void nullptr_args_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)

◆ TEST() [3/12]

TEST ( FlMethodChannelTest  ,
InvokeMethodError   
)

Definition at line 120 of file fl_method_channel_test.cc.

References args, engine, error_response_cb(), fl_binary_messenger_new(), fl_method_channel_invoke_method(), fl_method_channel_new(), fl_standard_method_codec_new(), fl_value_append_take(), fl_value_new_list(), fl_value_new_string(), and make_mock_engine().

120  {
121  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
122 
123  g_autoptr(FlEngine) engine = make_mock_engine();
124  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
125  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
126  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
127  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
128 
129  g_autoptr(FlValue) args = fl_value_new_list();
133  fl_method_channel_invoke_method(channel, "Error", args, nullptr,
134  error_response_cb, loop);
135 
136  // Blocks here until error_response_cb is called.
137  g_main_loop_run(loop);
138 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:338
G_BEGIN_DECLS FlValue * args
static void error_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:560
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:265
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)

◆ TEST() [4/12]

TEST ( FlMethodChannelTest  ,
InvokeMethodNotImplemented   
)

Definition at line 157 of file fl_method_channel_test.cc.

References engine, fl_binary_messenger_new(), fl_method_channel_invoke_method(), fl_method_channel_new(), fl_standard_method_codec_new(), make_mock_engine(), and not_implemented_response_cb().

157  {
158  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
159 
160  g_autoptr(FlEngine) engine = make_mock_engine();
161  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
162  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
163  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
164  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
165 
166  fl_method_channel_invoke_method(channel, "NotImplemented", nullptr, nullptr,
168 
169  // Blocks here until not_implemented_response_cb is called.
170  g_main_loop_run(loop);
171 }
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
static void not_implemented_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)

◆ TEST() [5/12]

TEST ( FlMethodChannelTest  ,
InvokeMethodFailure   
)

Definition at line 188 of file fl_method_channel_test.cc.

References engine, failure_response_cb(), fl_binary_messenger_new(), fl_method_channel_invoke_method(), fl_method_channel_new(), fl_standard_method_codec_new(), and make_mock_engine().

188  {
189  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
190 
191  g_autoptr(FlEngine) engine = make_mock_engine();
192  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
193  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
194  g_autoptr(FlMethodChannel) channel =
195  fl_method_channel_new(messenger, "test/failure", FL_METHOD_CODEC(codec));
196 
197  fl_method_channel_invoke_method(channel, "Echo", nullptr, nullptr,
198  failure_response_cb, loop);
199 
200  // Blocks here until failure_response_cb is called.
201  g_main_loop_run(loop);
202 }
static void failure_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)

◆ TEST() [6/12]

TEST ( FlMethodChannelTest  ,
ReceiveMethodCallRespondSuccess   
)

Definition at line 249 of file fl_method_channel_test.cc.

References args, engine, fl_binary_messenger_new(), fl_binary_messenger_set_message_handler_on_channel(), fl_method_channel_invoke_method(), fl_method_channel_new(), fl_method_channel_set_method_call_handler(), fl_standard_method_codec_new(), fl_value_append_take(), fl_value_new_list(), fl_value_new_string(), make_mock_engine(), method_call_success_cb(), and method_call_success_response_cb().

249  {
250  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
251 
252  g_autoptr(FlEngine) engine = make_mock_engine();
253  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
254  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
255  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
256  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
258  nullptr, nullptr);
259 
260  // Listen for response from the engine.
262  messenger, "test/responses", method_call_success_response_cb, loop,
263  nullptr);
264 
265  // Trigger the engine to make a method call.
266  g_autoptr(FlValue) args = fl_value_new_list();
267  fl_value_append_take(args, fl_value_new_string("test/standard-method"));
270  fl_method_channel_invoke_method(channel, "InvokeMethod", args, nullptr,
271  nullptr, loop);
272 
273  // Blocks here until method_call_success_response_cb is called.
274  g_main_loop_run(loop);
275 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:338
G_BEGIN_DECLS FlValue * args
G_MODULE_EXPORT void fl_binary_messenger_set_message_handler_on_channel(FlBinaryMessenger *self, const gchar *channel, FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
static void method_call_success_response_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:560
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
static void method_call_success_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:265
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)

◆ TEST() [7/12]

TEST ( FlMethodChannelTest  ,
ReceiveMethodCallRespondError   
)

Definition at line 329 of file fl_method_channel_test.cc.

References args, engine, fl_binary_messenger_new(), fl_binary_messenger_set_message_handler_on_channel(), fl_method_channel_invoke_method(), fl_method_channel_new(), fl_method_channel_set_method_call_handler(), fl_standard_method_codec_new(), fl_value_append_take(), fl_value_new_list(), fl_value_new_string(), make_mock_engine(), method_call_error_cb(), and method_call_error_response_cb().

329  {
330  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
331 
332  g_autoptr(FlEngine) engine = make_mock_engine();
333  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
334  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
335  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
336  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
338  nullptr, nullptr);
339 
340  // Listen for response from the engine.
342  messenger, "test/responses", method_call_error_response_cb, loop,
343  nullptr);
344 
345  // Trigger the engine to make a method call.
346  g_autoptr(FlValue) args = fl_value_new_list();
347  fl_value_append_take(args, fl_value_new_string("test/standard-method"));
350  fl_method_channel_invoke_method(channel, "InvokeMethod", args, nullptr,
351  nullptr, loop);
352 
353  // Blocks here until method_call_error_response_cb is called.
354  g_main_loop_run(loop);
355 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:338
G_BEGIN_DECLS FlValue * args
G_MODULE_EXPORT void fl_binary_messenger_set_message_handler_on_channel(FlBinaryMessenger *self, const gchar *channel, FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
static void method_call_error_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:560
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:265
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
static void method_call_error_response_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)

◆ TEST() [8/12]

TEST ( FlMethodChannelTest  ,
ReceiveMethodCallRespondNotImplemented   
)

Definition at line 397 of file fl_method_channel_test.cc.

References args, engine, fl_binary_messenger_new(), fl_binary_messenger_set_message_handler_on_channel(), fl_method_channel_invoke_method(), fl_method_channel_new(), fl_method_channel_set_method_call_handler(), fl_standard_method_codec_new(), fl_value_append_take(), fl_value_new_list(), fl_value_new_string(), make_mock_engine(), method_call_not_implemented_cb(), and method_call_not_implemented_response_cb().

397  {
398  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
399 
400  g_autoptr(FlEngine) engine = make_mock_engine();
401  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
402  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
403  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
404  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
406  channel, method_call_not_implemented_cb, nullptr, nullptr);
407 
408  // Listen for response from the engine.
410  messenger, "test/responses", method_call_not_implemented_response_cb,
411  loop, nullptr);
412 
413  // Trigger the engine to make a method call.
414  g_autoptr(FlValue) args = fl_value_new_list();
415  fl_value_append_take(args, fl_value_new_string("test/standard-method"));
418  fl_method_channel_invoke_method(channel, "InvokeMethod", args, nullptr,
419  nullptr, loop);
420 
421  // Blocks here until method_call_not_implemented_response_cb is called.
422  g_main_loop_run(loop);
423 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:338
G_BEGIN_DECLS FlValue * args
G_MODULE_EXPORT void fl_binary_messenger_set_message_handler_on_channel(FlBinaryMessenger *self, const gchar *channel, FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
static void method_call_not_implemented_response_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:560
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:265
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
static void method_call_not_implemented_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)

◆ TEST() [9/12]

TEST ( FlMethodChannelTest  ,
ReceiveMethodCallRespondSuccessError   
)

Definition at line 542 of file fl_method_channel_test.cc.

References args, engine, fl_binary_messenger_new(), fl_method_channel_invoke_method(), fl_method_channel_new(), fl_method_channel_set_method_call_handler(), fl_value_append_take(), fl_value_new_list(), fl_value_new_string(), make_mock_engine(), method_call_success_error_cb(), and test_method_codec_new().

542  {
543  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
544 
545  g_autoptr(FlEngine) engine = make_mock_engine();
546  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
547  g_autoptr(TestMethodCodec) codec = test_method_codec_new();
548  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
549  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
551  channel, method_call_success_error_cb, loop, nullptr);
552 
553  // Trigger the engine to make a method call.
554  g_autoptr(FlValue) args = fl_value_new_list();
555  fl_value_append_take(args, fl_value_new_string("test/standard-method"));
558  fl_method_channel_invoke_method(channel, "InvokeMethod", args, nullptr,
559  nullptr, loop);
560 
561  // Blocks here until method_call_success_error_cb is called.
562  g_main_loop_run(loop);
563 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:338
G_BEGIN_DECLS FlValue * args
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
static void method_call_success_error_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
TestMethodCodec * test_method_codec_new()
static FlEngine * make_mock_engine()
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:560
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:265
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)

◆ TEST() [10/12]

TEST ( FlMethodChannelTest  ,
ReceiveMethodCallRespondErrorError   
)

Definition at line 584 of file fl_method_channel_test.cc.

References args, engine, fl_binary_messenger_new(), fl_method_channel_invoke_method(), fl_method_channel_new(), fl_method_channel_set_method_call_handler(), fl_value_append_take(), fl_value_new_list(), fl_value_new_string(), make_mock_engine(), method_call_error_error_cb(), and test_method_codec_new().

584  {
585  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
586 
587  g_autoptr(FlEngine) engine = make_mock_engine();
588  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
589  g_autoptr(TestMethodCodec) codec = test_method_codec_new();
590  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
591  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
593  loop, nullptr);
594 
595  // Trigger the engine to make a method call.
596  g_autoptr(FlValue) args = fl_value_new_list();
597  fl_value_append_take(args, fl_value_new_string("test/standard-method"));
600  fl_method_channel_invoke_method(channel, "InvokeMethod", args, nullptr,
601  nullptr, loop);
602 
603  // Blocks here until method_call_error_error_cb is called.
604  g_main_loop_run(loop);
605 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:338
G_BEGIN_DECLS FlValue * args
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
TestMethodCodec * test_method_codec_new()
static FlEngine * make_mock_engine()
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:560
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
static void method_call_error_error_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:265
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)

◆ TEST() [11/12]

TEST ( FlMethodChannelTest  ,
ReplaceADisposedMethodChannel   
)

Definition at line 636 of file fl_method_channel_test.cc.

References args, engine, fl_binary_messenger_new(), fl_method_channel_invoke_method(), fl_method_channel_new(), fl_method_channel_set_method_call_handler(), fl_standard_method_codec_new(), fl_value_append_take(), fl_value_new_list(), fl_value_new_string(), UserDataReassignMethod::loop, make_mock_engine(), and reassign_method_cb().

636  {
637  const char* method_name = "test/standard-method";
638  // The loop is used to pause the main process until the callback is fully
639  // executed.
640  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
641  g_autoptr(FlEngine) engine = make_mock_engine();
642  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
643  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
644 
645  g_autoptr(FlValue) args = fl_value_new_list();
649 
650  // Register the first channel and test if it works.
651  UserDataReassignMethod user_data1{
652  .loop = loop,
653  .count = 100,
654  };
655  FlMethodChannel* channel1 =
656  fl_method_channel_new(messenger, method_name, FL_METHOD_CODEC(codec));
658  &user_data1, nullptr);
659 
660  fl_method_channel_invoke_method(channel1, "InvokeMethod", args, nullptr,
661  nullptr, nullptr);
662  g_main_loop_run(loop);
663  EXPECT_EQ(user_data1.count, 101);
664 
665  // Dispose the first channel.
666  g_object_unref(channel1);
667 
668  // Register the second channel and test if it works.
669  UserDataReassignMethod user_data2{
670  .loop = loop,
671  .count = 100,
672  };
673  g_autoptr(FlMethodChannel) channel2 =
674  fl_method_channel_new(messenger, method_name, FL_METHOD_CODEC(codec));
676  &user_data2, nullptr);
677 
678  fl_method_channel_invoke_method(channel2, "InvokeMethod", args, nullptr,
679  nullptr, nullptr);
680  g_main_loop_run(loop);
681 
682  EXPECT_EQ(user_data1.count, 101);
683  EXPECT_EQ(user_data2.count, 101);
684 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:338
G_BEGIN_DECLS FlValue * args
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
static void reassign_method_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer raw_user_data)
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:560
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:265
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)

◆ TEST() [12/12]

TEST ( FlMethodChannelTest  ,
DisposeAReplacedMethodChannel   
)

Definition at line 693 of file fl_method_channel_test.cc.

References args, engine, fl_binary_messenger_new(), fl_method_channel_invoke_method(), fl_method_channel_new(), fl_method_channel_set_method_call_handler(), fl_standard_method_codec_new(), fl_value_append_take(), fl_value_new_list(), fl_value_new_string(), UserDataReassignMethod::loop, make_mock_engine(), and reassign_method_cb().

693  {
694  const char* method_name = "test/standard-method";
695  // The loop is used to pause the main process until the callback is fully
696  // executed.
697  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
698  g_autoptr(FlEngine) engine = make_mock_engine();
699  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
700  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
701 
702  g_autoptr(FlValue) args = fl_value_new_list();
706 
707  // Register the first channel and test if it works.
708  UserDataReassignMethod user_data1{
709  .loop = loop,
710  .count = 100,
711  };
712  FlMethodChannel* channel1 =
713  fl_method_channel_new(messenger, method_name, FL_METHOD_CODEC(codec));
715  &user_data1, nullptr);
716 
717  fl_method_channel_invoke_method(channel1, "InvokeMethod", args, nullptr,
718  nullptr, nullptr);
719  g_main_loop_run(loop);
720  EXPECT_EQ(user_data1.count, 101);
721 
722  // Register a new channel to the same name.
723  UserDataReassignMethod user_data2{
724  .loop = loop,
725  .count = 100,
726  };
727  g_autoptr(FlMethodChannel) channel2 =
728  fl_method_channel_new(messenger, method_name, FL_METHOD_CODEC(codec));
730  &user_data2, nullptr);
731 
732  fl_method_channel_invoke_method(channel2, "InvokeMethod", args, nullptr,
733  nullptr, nullptr);
734  g_main_loop_run(loop);
735  EXPECT_EQ(user_data1.count, 101);
736  EXPECT_EQ(user_data2.count, 101);
737 
738  // Dispose the first channel. The new channel should keep working.
739  g_object_unref(channel1);
740 
741  fl_method_channel_invoke_method(channel2, "InvokeMethod", args, nullptr,
742  nullptr, nullptr);
743  g_main_loop_run(loop);
744  EXPECT_EQ(user_data1.count, 101);
745  EXPECT_EQ(user_data2.count, 102);
746 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:338
G_BEGIN_DECLS FlValue * args
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
static void reassign_method_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer raw_user_data)
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:560
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:265
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)

◆ test_method_codec_class_init()

static void test_method_codec_class_init ( TestMethodCodecClass *  klass)
static

Definition at line 501 of file fl_method_channel_test.cc.

References test_method_codec_decode_method_call(), test_method_codec_decode_response(), test_method_codec_dispose(), test_method_codec_encode_error_envelope(), test_method_codec_encode_method_call(), and test_method_codec_encode_success_envelope().

501  {
502  G_OBJECT_CLASS(klass)->dispose = test_method_codec_dispose;
503  FL_METHOD_CODEC_CLASS(klass)->encode_method_call =
505  FL_METHOD_CODEC_CLASS(klass)->decode_method_call =
507  FL_METHOD_CODEC_CLASS(klass)->encode_success_envelope =
509  FL_METHOD_CODEC_CLASS(klass)->encode_error_envelope =
511  FL_METHOD_CODEC_CLASS(klass)->decode_response =
513 }
static gboolean test_method_codec_decode_method_call(FlMethodCodec *codec, GBytes *message, gchar **name, FlValue **args, GError **error)
static GBytes * test_method_codec_encode_method_call(FlMethodCodec *codec, const gchar *name, FlValue *args, GError **error)
static FlMethodResponse * test_method_codec_decode_response(FlMethodCodec *codec, GBytes *message, GError **error)
static GBytes * test_method_codec_encode_success_envelope(FlMethodCodec *codec, FlValue *result, GError **error)
static void test_method_codec_dispose(GObject *object)
static GBytes * test_method_codec_encode_error_envelope(FlMethodCodec *codec, const gchar *code, const gchar *message, FlValue *details, GError **error)

◆ test_method_codec_decode_method_call()

static gboolean test_method_codec_decode_method_call ( FlMethodCodec *  codec,
GBytes *  message,
gchar **  name,
FlValue **  args,
GError **  error 
)
static

Definition at line 460 of file fl_method_channel_test.cc.

References fl_method_codec_decode_method_call().

Referenced by test_method_codec_class_init().

464  {
465  EXPECT_TRUE(TEST_IS_METHOD_CODEC(codec));
466  TestMethodCodec* self = TEST_METHOD_CODEC(codec);
468  FL_METHOD_CODEC(self->wrapped_codec), message, name, args, error);
469 }
G_BEGIN_DECLS FlValue * args
const uint8_t uint32_t uint32_t GError ** error
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)

◆ test_method_codec_decode_response()

static FlMethodResponse* test_method_codec_decode_response ( FlMethodCodec *  codec,
GBytes *  message,
GError **  error 
)
static

Definition at line 492 of file fl_method_channel_test.cc.

References fl_method_codec_decode_response().

Referenced by test_method_codec_class_init().

494  {
495  EXPECT_TRUE(TEST_IS_METHOD_CODEC(codec));
496  TestMethodCodec* self = TEST_METHOD_CODEC(codec);
497  return fl_method_codec_decode_response(FL_METHOD_CODEC(self->wrapped_codec),
498  message, error);
499 }
const uint8_t uint32_t uint32_t GError ** error
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)

◆ test_method_codec_dispose()

static void test_method_codec_dispose ( GObject *  object)
static

Definition at line 440 of file fl_method_channel_test.cc.

Referenced by test_method_codec_class_init().

440  {
441  TestMethodCodec* self = TEST_METHOD_CODEC(object);
442 
443  g_clear_object(&self->wrapped_codec);
444 
445  G_OBJECT_CLASS(test_method_codec_parent_class)->dispose(object);
446 }

◆ test_method_codec_encode_error_envelope()

static GBytes* test_method_codec_encode_error_envelope ( FlMethodCodec *  codec,
const gchar *  code,
const gchar *  message,
FlValue details,
GError **  error 
)
static

Definition at line 481 of file fl_method_channel_test.cc.

References FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_FAILED.

Referenced by test_method_codec_class_init().

485  {
487  "Unsupported type");
488  return nullptr;
489 }
const uint8_t uint32_t uint32_t GError ** error
#define FL_MESSAGE_CODEC_ERROR

◆ test_method_codec_encode_method_call()

static GBytes* test_method_codec_encode_method_call ( FlMethodCodec *  codec,
const gchar *  name,
FlValue args,
GError **  error 
)
static

Definition at line 449 of file fl_method_channel_test.cc.

References fl_method_codec_encode_method_call().

Referenced by test_method_codec_class_init().

452  {
453  EXPECT_TRUE(TEST_IS_METHOD_CODEC(codec));
454  TestMethodCodec* self = TEST_METHOD_CODEC(codec);
456  FL_METHOD_CODEC(self->wrapped_codec), name, args, error);
457 }
G_BEGIN_DECLS FlValue * args
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
const uint8_t uint32_t uint32_t GError ** error
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ test_method_codec_encode_success_envelope()

static GBytes* test_method_codec_encode_success_envelope ( FlMethodCodec *  codec,
FlValue result,
GError **  error 
)
static

Definition at line 472 of file fl_method_channel_test.cc.

References FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_FAILED.

Referenced by test_method_codec_class_init().

474  {
476  "Unsupported type");
477  return nullptr;
478 }
const uint8_t uint32_t uint32_t GError ** error
#define FL_MESSAGE_CODEC_ERROR

◆ test_method_codec_init()

static void test_method_codec_init ( TestMethodCodec *  self)
static

Definition at line 515 of file fl_method_channel_test.cc.

References fl_standard_method_codec_new().

515  {
516  self->wrapped_codec = fl_standard_method_codec_new();
517 }
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()

◆ test_method_codec_new()

TestMethodCodec* test_method_codec_new ( )

Definition at line 519 of file fl_method_channel_test.cc.

Referenced by TEST().

519  {
520  return TEST_METHOD_CODEC(g_object_new(test_method_codec_get_type(), nullptr));
521 }