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/mock_renderer.h"

Go to the source code of this file.

Functions

static FlEngine * make_mock_engine ()
 
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)
 

Function Documentation

◆ error_response_cb()

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

Definition at line 105 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().

107  {
108  g_autoptr(GError) error = nullptr;
109  g_autoptr(FlMethodResponse) response = fl_method_channel_invoke_method_finish(
110  FL_METHOD_CHANNEL(object), result, &error);
111  EXPECT_NE(response, nullptr);
112  EXPECT_EQ(error, nullptr);
113 
114  EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
115  EXPECT_STREQ(
116  fl_method_error_response_get_code(FL_METHOD_ERROR_RESPONSE(response)),
117  "CODE");
118  EXPECT_STREQ(
119  fl_method_error_response_get_message(FL_METHOD_ERROR_RESPONSE(response)),
120  "MESSAGE");
121  FlValue* details =
122  fl_method_error_response_get_details(FL_METHOD_ERROR_RESPONSE(response));
123  EXPECT_NE(details, nullptr);
124  EXPECT_EQ(fl_value_get_type(details), FL_VALUE_TYPE_STRING);
125  EXPECT_STREQ(fl_value_get_string(details), "DETAILS");
126 
127  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
128 }
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
G_MODULE_EXPORT const gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
G_BEGIN_DECLS FlMethodCall gpointer user_data
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:596
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 186 of file fl_method_channel_test.cc.

References error, and fl_method_channel_invoke_method_finish().

Referenced by TEST().

188  {
189  g_autoptr(GError) error = nullptr;
190  g_autoptr(FlMethodResponse) response = fl_method_channel_invoke_method_finish(
191  FL_METHOD_CHANNEL(object), result, &error);
192  EXPECT_EQ(response, nullptr);
193  EXPECT_NE(error, nullptr);
194 
195  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
196 }
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
FlMethodResponse GError ** error
G_BEGIN_DECLS FlMethodCall gpointer user_data

◆ G_DECLARE_FINAL_TYPE()

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

Definition at line 437 of file fl_method_channel_test.cc.

References fl_method_codec_get_type(), and G_DEFINE_TYPE().

443  {
444  FlMethodCodec parent_instance;
445 
446  FlStandardMethodCodec* wrapped_codec;
447 };

◆ make_mock_engine()

static FlEngine* make_mock_engine ( )
static

Definition at line 17 of file fl_method_channel_test.cc.

References engine, fl_dart_project_new(), fl_engine_new(), fl_engine_start(), and fl_mock_renderer_new().

Referenced by TEST().

17  {
18  g_autoptr(FlDartProject) project = fl_dart_project_new();
19  g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
20  g_autoptr(FlEngine) engine = fl_engine_new(project, FL_RENDERER(renderer));
21  g_autoptr(GError) engine_error = nullptr;
22  EXPECT_TRUE(fl_engine_start(engine, &engine_error));
23  EXPECT_EQ(engine_error, nullptr);
24 
25  return static_cast<FlEngine*>(g_object_ref(engine));
26 }
FlMockRenderer * fl_mock_renderer_new()
gboolean fl_engine_start(FlEngine *self, GError **error)
Definition: fl_engine.cc:352
FlEngine * fl_engine_new(FlDartProject *project, FlRenderer *renderer)
Definition: fl_engine.cc:337
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()

◆ method_call_error_cb()

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

Definition at line 290 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().

292  {
293  EXPECT_STREQ(fl_method_call_get_name(method_call), "Foo");
297  "Marco!");
298 
299  g_autoptr(FlValue) details = fl_value_new_string("DETAILS");
300  g_autoptr(GError) error = nullptr;
301  EXPECT_TRUE(fl_method_call_respond_error(method_call, "CODE", "MESSAGE",
302  details, &error));
303  EXPECT_EQ(error, nullptr);
304 }
G_BEGIN_DECLS FlMethodCall * method_call
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse 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 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:247
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:596

◆ method_call_error_error_cb()

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

Definition at line 578 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().

580  {
581  g_autoptr(FlValue) details = fl_value_new_int(42);
582  g_autoptr(GError) response_error = nullptr;
583  EXPECT_FALSE(fl_method_call_respond_error(method_call, "error", "ERROR",
584  details, &response_error));
585  EXPECT_NE(response_error, nullptr);
586 
587  // Respond to stop a warning occuring about not responding.
589 
590  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
591 }
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:39
G_MODULE_EXPORT gboolean fl_method_call_respond_error(FlMethodCall *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
G_BEGIN_DECLS FlMethodCall gpointer user_data
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233

◆ 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 308 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().

313  {
314  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
315  g_autoptr(GError) error = nullptr;
316  g_autoptr(FlMethodResponse) response =
317  fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
318  EXPECT_NE(response, nullptr);
319  EXPECT_EQ(error, nullptr);
320 
321  EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
322  EXPECT_STREQ(
323  fl_method_error_response_get_code(FL_METHOD_ERROR_RESPONSE(response)),
324  "CODE");
325  EXPECT_STREQ(
326  fl_method_error_response_get_message(FL_METHOD_ERROR_RESPONSE(response)),
327  "MESSAGE");
328  FlValue* details =
329  fl_method_error_response_get_details(FL_METHOD_ERROR_RESPONSE(response));
330  EXPECT_EQ(fl_value_get_type(details), FL_VALUE_TYPE_STRING);
331  EXPECT_STREQ(fl_value_get_string(details), "DETAILS");
332 
333  fl_binary_messenger_send_response(messenger, response_handle, nullptr,
334  nullptr);
335 
336  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
337 }
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
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()
G_BEGIN_DECLS FlMethodCall gpointer user_data
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:596
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 370 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().

372  {
373  EXPECT_STREQ(fl_method_call_get_name(method_call), "Foo");
377  "Marco!");
378 
379  g_autoptr(GError) error = nullptr;
381  EXPECT_EQ(error, nullptr);
382 }
G_BEGIN_DECLS FlMethodCall * method_call
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
G_MODULE_EXPORT gboolean fl_method_call_respond_not_implemented(FlMethodCall *self, GError **error)
FlMethodResponse 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:596

◆ 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 386 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().

391  {
392  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
393  g_autoptr(GError) error = nullptr;
394  g_autoptr(FlMethodResponse) response =
395  fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
396  EXPECT_NE(response, nullptr);
397  EXPECT_EQ(error, nullptr);
398 
399  EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
400 
401  fl_binary_messenger_send_response(messenger, response_handle, nullptr,
402  nullptr);
403 
404  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
405 }
FlMethodResponse GError ** error
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()
G_BEGIN_DECLS FlMethodCall gpointer user_data
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 217 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(), and FL_VALUE_TYPE_STRING.

Referenced by TEST().

219  {
220  EXPECT_STREQ(fl_method_call_get_name(method_call), "Foo");
224  "Marco!");
225 
226  g_autoptr(FlValue) result = fl_value_new_string("Polo!");
227  g_autoptr(GError) error = nullptr;
228  EXPECT_TRUE(fl_method_call_respond_success(method_call, result, &error));
229  EXPECT_EQ(error, nullptr);
230 }
G_BEGIN_DECLS FlMethodCall * method_call
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
G_MODULE_EXPORT gboolean fl_method_call_respond_success(FlMethodCall *self, FlValue *result, 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 FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:596

◆ method_call_success_error_cb()

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

Definition at line 536 of file fl_method_channel_test.cc.

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

Referenced by TEST().

538  {
539  g_autoptr(FlValue) result = fl_value_new_int(42);
540  g_autoptr(GError) response_error = nullptr;
541  EXPECT_FALSE(
542  fl_method_call_respond_success(method_call, result, &response_error));
543  EXPECT_NE(response_error, nullptr);
544 
545  // Respond to stop a warning occuring about not responding.
547 
548  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
549 }
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:39
G_MODULE_EXPORT gboolean fl_method_call_respond_success(FlMethodCall *self, FlValue *result, GError **error)
G_BEGIN_DECLS FlMethodCall gpointer user_data
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233

◆ 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 234 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(), and FL_VALUE_TYPE_STRING.

Referenced by TEST().

239  {
240  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
241  g_autoptr(GError) error = nullptr;
242  g_autoptr(FlMethodResponse) response =
243  fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
244  EXPECT_NE(response, nullptr);
245  EXPECT_EQ(error, nullptr);
246 
247  EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
249  FL_METHOD_SUCCESS_RESPONSE(response));
250  EXPECT_EQ(fl_value_get_type(result), FL_VALUE_TYPE_STRING);
251  EXPECT_STREQ(fl_value_get_string(result), "Polo!");
252 
253  fl_binary_messenger_send_response(messenger, response_handle, nullptr,
254  nullptr);
255 
256  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
257 }
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *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()
G_BEGIN_DECLS FlMethodCall gpointer user_data
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:596

◆ method_response_cb()

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

Definition at line 30 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().

32  {
33  g_autoptr(GError) error = nullptr;
34  g_autoptr(FlMethodResponse) response = fl_method_channel_invoke_method_finish(
35  FL_METHOD_CHANNEL(object), result, &error);
36  EXPECT_NE(response, nullptr);
37  EXPECT_EQ(error, nullptr);
38 
40  EXPECT_NE(r, nullptr);
41  EXPECT_EQ(error, nullptr);
42 
44  EXPECT_STREQ(fl_value_get_string(r), "Hello World!");
45 
46  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
47 }
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
G_BEGIN_DECLS FlMethodCall gpointer user_data
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:596
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 153 of file fl_method_channel_test.cc.

References error, and fl_method_channel_invoke_method_finish().

Referenced by TEST().

155  {
156  g_autoptr(GError) error = nullptr;
157  g_autoptr(FlMethodResponse) response = fl_method_channel_invoke_method_finish(
158  FL_METHOD_CHANNEL(object), result, &error);
159  EXPECT_NE(response, nullptr);
160  EXPECT_EQ(error, nullptr);
161 
162  EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
163 
164  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
165 }
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
FlMethodResponse GError ** error
G_BEGIN_DECLS FlMethodCall gpointer user_data

◆ nullptr_args_response_cb()

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

Definition at line 69 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().

71  {
72  g_autoptr(GError) error = nullptr;
73  g_autoptr(FlMethodResponse) response = fl_method_channel_invoke_method_finish(
74  FL_METHOD_CHANNEL(object), result, &error);
75  EXPECT_NE(response, nullptr);
76  EXPECT_EQ(error, nullptr);
77 
79  EXPECT_NE(r, nullptr);
80  EXPECT_EQ(error, nullptr);
82 
83  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
84 }
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
G_BEGIN_DECLS FlMethodCall gpointer user_data
G_MODULE_EXPORT FlValue * fl_method_response_get_result(FlMethodResponse *self, GError **error)

◆ TEST() [1/10]

TEST ( FlMethodChannelTest  ,
InvokeMethod   
)

Definition at line 50 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(), fl_value_new_string(), make_mock_engine(), and method_response_cb().

50  {
51  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
52 
53  g_autoptr(FlEngine) engine = make_mock_engine();
54  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
55  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
56  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
57  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
58 
59  g_autoptr(FlValue) args = fl_value_new_string("Hello World!");
60  fl_method_channel_invoke_method(channel, "Echo", args, nullptr,
61  method_response_cb, loop);
62 
63  // Blocks here until method_response_cb is called.
64  g_main_loop_run(loop);
65 }
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
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:247
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 FlEngine * make_mock_engine()

◆ TEST() [2/10]

TEST ( FlMethodChannelTest  ,
InvokeMethodNullptrArgsMessage   
)

Definition at line 87 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().

87  {
88  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
89 
90  g_autoptr(FlEngine) engine = make_mock_engine();
91  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
92  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
93  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
94  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
95 
96  fl_method_channel_invoke_method(channel, "Echo", nullptr, nullptr,
98 
99  // Blocks here until nullptr_args_response_cb is called.
100  g_main_loop_run(loop);
101 }
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)
static FlEngine * make_mock_engine()

◆ TEST() [3/10]

TEST ( FlMethodChannelTest  ,
InvokeMethodError   
)

Definition at line 131 of file fl_method_channel_test.cc.

References 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().

131  {
132  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
133 
134  g_autoptr(FlEngine) engine = make_mock_engine();
135  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
136  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
137  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
138  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
139 
140  g_autoptr(FlValue) args = fl_value_new_list();
142  fl_value_append_take(args, fl_value_new_string("MESSAGE"));
143  fl_value_append_take(args, fl_value_new_string("DETAILS"));
144  fl_method_channel_invoke_method(channel, "Error", args, nullptr,
145  error_response_cb, loop);
146 
147  // Blocks here until error_response_cb is called.
148  g_main_loop_run(loop);
149 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
static void error_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
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:514
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:247
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 FlEngine * make_mock_engine()

◆ TEST() [4/10]

TEST ( FlMethodChannelTest  ,
InvokeMethodNotImplemented   
)

Definition at line 168 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().

168  {
169  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
170 
171  g_autoptr(FlEngine) engine = make_mock_engine();
172  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
173  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
174  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
175  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
176 
177  fl_method_channel_invoke_method(channel, "NotImplemented", nullptr, nullptr,
179 
180  // Blocks here until not_implemented_response_cb is called.
181  g_main_loop_run(loop);
182 }
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)
static FlEngine * make_mock_engine()

◆ TEST() [5/10]

TEST ( FlMethodChannelTest  ,
InvokeMethodFailure   
)

Definition at line 199 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().

199  {
200  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
201 
202  g_autoptr(FlEngine) engine = make_mock_engine();
203  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
204  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
205  g_autoptr(FlMethodChannel) channel =
206  fl_method_channel_new(messenger, "test/failure", FL_METHOD_CODEC(codec));
207 
208  fl_method_channel_invoke_method(channel, "Echo", nullptr, nullptr,
209  failure_response_cb, loop);
210 
211  // Blocks here until failure_response_cb is called.
212  g_main_loop_run(loop);
213 }
static void failure_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
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)
static FlEngine * make_mock_engine()

◆ TEST() [6/10]

TEST ( FlMethodChannelTest  ,
ReceiveMethodCallRespondSuccess   
)

Definition at line 260 of file fl_method_channel_test.cc.

References 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().

260  {
261  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
262 
263  g_autoptr(FlEngine) engine = make_mock_engine();
264  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
265  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
266  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
267  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
269  nullptr, nullptr);
270 
271  // Listen for response from the engine.
273  messenger, "test/responses", method_call_success_response_cb, loop,
274  nullptr);
275 
276  // Trigger the engine to make a method call.
277  g_autoptr(FlValue) args = fl_value_new_list();
278  fl_value_append_take(args, fl_value_new_string("test/standard-method"));
280  fl_value_append_take(args, fl_value_new_string("Marco!"));
281  fl_method_channel_invoke_method(channel, "InvokeMethod", args, nullptr,
282  nullptr, loop);
283 
284  // Blocks here until method_call_success_response_cb is called.
285  g_main_loop_run(loop);
286 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
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:39
static void method_call_success_response_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
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:514
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:247
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 FlEngine * make_mock_engine()

◆ TEST() [7/10]

TEST ( FlMethodChannelTest  ,
ReceiveMethodCallRespondError   
)

Definition at line 340 of file fl_method_channel_test.cc.

References 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().

340  {
341  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
342 
343  g_autoptr(FlEngine) engine = make_mock_engine();
344  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
345  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
346  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
347  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
349  nullptr, nullptr);
350 
351  // Listen for response from the engine.
353  messenger, "test/responses", method_call_error_response_cb, loop,
354  nullptr);
355 
356  // Trigger the engine to make a method call.
357  g_autoptr(FlValue) args = fl_value_new_list();
358  fl_value_append_take(args, fl_value_new_string("test/standard-method"));
360  fl_value_append_take(args, fl_value_new_string("Marco!"));
361  fl_method_channel_invoke_method(channel, "InvokeMethod", args, nullptr,
362  nullptr, loop);
363 
364  // Blocks here until method_call_error_response_cb is called.
365  g_main_loop_run(loop);
366 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
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:39
static void method_call_error_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
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:514
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:247
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 FlEngine * make_mock_engine()
static void method_call_error_response_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)

◆ TEST() [8/10]

TEST ( FlMethodChannelTest  ,
ReceiveMethodCallRespondNotImplemented   
)

Definition at line 408 of file fl_method_channel_test.cc.

References 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().

408  {
409  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
410 
411  g_autoptr(FlEngine) engine = make_mock_engine();
412  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
413  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
414  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
415  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
417  channel, method_call_not_implemented_cb, nullptr, nullptr);
418 
419  // Listen for response from the engine.
421  messenger, "test/responses", method_call_not_implemented_response_cb,
422  loop, nullptr);
423 
424  // Trigger the engine to make a method call.
425  g_autoptr(FlValue) args = fl_value_new_list();
426  fl_value_append_take(args, fl_value_new_string("test/standard-method"));
428  fl_value_append_take(args, fl_value_new_string("Marco!"));
429  fl_method_channel_invoke_method(channel, "InvokeMethod", args, nullptr,
430  nullptr, loop);
431 
432  // Blocks here until method_call_not_implemented_response_cb is called.
433  g_main_loop_run(loop);
434 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
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:39
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:514
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:247
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 FlEngine * make_mock_engine()
static void method_call_not_implemented_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)

◆ TEST() [9/10]

TEST ( FlMethodChannelTest  ,
ReceiveMethodCallRespondSuccessError   
)

Definition at line 553 of file fl_method_channel_test.cc.

References 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().

553  {
554  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
555 
556  g_autoptr(FlEngine) engine = make_mock_engine();
557  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
558  g_autoptr(TestMethodCodec) codec = test_method_codec_new();
559  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
560  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
562  channel, method_call_success_error_cb, loop, nullptr);
563 
564  // Trigger the engine to make a method call.
565  g_autoptr(FlValue) args = fl_value_new_list();
566  fl_value_append_take(args, fl_value_new_string("test/standard-method"));
568  fl_value_append_take(args, fl_value_new_string("Marco!"));
569  fl_method_channel_invoke_method(channel, "InvokeMethod", args, nullptr,
570  nullptr, loop);
571 
572  // Blocks here until method_call_success_error_cb is called.
573  g_main_loop_run(loop);
574 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
static void method_call_success_error_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
TestMethodCodec * test_method_codec_new()
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:514
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:247
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 FlEngine * make_mock_engine()

◆ TEST() [10/10]

TEST ( FlMethodChannelTest  ,
ReceiveMethodCallRespondErrorError   
)

Definition at line 595 of file fl_method_channel_test.cc.

References 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().

595  {
596  g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
597 
598  g_autoptr(FlEngine) engine = make_mock_engine();
599  FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
600  g_autoptr(TestMethodCodec) codec = test_method_codec_new();
601  g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
602  messenger, "test/standard-method", FL_METHOD_CODEC(codec));
604  loop, nullptr);
605 
606  // Trigger the engine to make a method call.
607  g_autoptr(FlValue) args = fl_value_new_list();
608  fl_value_append_take(args, fl_value_new_string("test/standard-method"));
610  fl_value_append_take(args, fl_value_new_string("Marco!"));
611  fl_method_channel_invoke_method(channel, "InvokeMethod", args, nullptr,
612  nullptr, loop);
613 
614  // Blocks here until method_call_error_error_cb is called.
615  g_main_loop_run(loop);
616 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
TestMethodCodec * test_method_codec_new()
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:514
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:247
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 FlEngine * make_mock_engine()

◆ test_method_codec_class_init()

static void test_method_codec_class_init ( TestMethodCodecClass *  klass)
static

Definition at line 512 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().

512  {
513  G_OBJECT_CLASS(klass)->dispose = test_method_codec_dispose;
514  FL_METHOD_CODEC_CLASS(klass)->encode_method_call =
516  FL_METHOD_CODEC_CLASS(klass)->decode_method_call =
518  FL_METHOD_CODEC_CLASS(klass)->encode_success_envelope =
520  FL_METHOD_CODEC_CLASS(klass)->encode_error_envelope =
522  FL_METHOD_CODEC_CLASS(klass)->decode_response =
524 }
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 471 of file fl_method_channel_test.cc.

References fl_method_codec_decode_method_call().

Referenced by test_method_codec_class_init().

475  {
476  EXPECT_TRUE(TEST_IS_METHOD_CODEC(codec));
477  TestMethodCodec* self = TEST_METHOD_CODEC(codec);
479  FL_METHOD_CODEC(self->wrapped_codec), message, name, args, error);
480 }
FlMethodResponse GError ** error
const char * name
Definition: fuchsia.cc:50
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 503 of file fl_method_channel_test.cc.

References fl_method_codec_decode_response().

Referenced by test_method_codec_class_init().

505  {
506  EXPECT_TRUE(TEST_IS_METHOD_CODEC(codec));
507  TestMethodCodec* self = TEST_METHOD_CODEC(codec);
508  return fl_method_codec_decode_response(FL_METHOD_CODEC(self->wrapped_codec),
509  message, error);
510 }
FlMethodResponse 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 451 of file fl_method_channel_test.cc.

Referenced by test_method_codec_class_init().

451  {
452  TestMethodCodec* self = TEST_METHOD_CODEC(object);
453 
454  g_clear_object(&self->wrapped_codec);
455 
456  G_OBJECT_CLASS(test_method_codec_parent_class)->dispose(object);
457 }

◆ 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 492 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().

496  {
498  "Unsupported type");
499  return nullptr;
500 }
FlMethodResponse 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 460 of file fl_method_channel_test.cc.

References fl_method_codec_encode_method_call().

Referenced by test_method_codec_class_init().

463  {
464  EXPECT_TRUE(TEST_IS_METHOD_CODEC(codec));
465  TestMethodCodec* self = TEST_METHOD_CODEC(codec);
467  FL_METHOD_CODEC(self->wrapped_codec), name, args, error);
468 }
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
FlMethodResponse GError ** error
const char * name
Definition: fuchsia.cc:50

◆ test_method_codec_encode_success_envelope()

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

Definition at line 483 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 }
FlMethodResponse GError ** error
#define FL_MESSAGE_CODEC_ERROR

◆ test_method_codec_init()

static void test_method_codec_init ( TestMethodCodec *  self)
static

Definition at line 526 of file fl_method_channel_test.cc.

References fl_standard_method_codec_new().

526  {
527  self->wrapped_codec = fl_standard_method_codec_new();
528 }
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()

◆ test_method_codec_new()

TestMethodCodec* test_method_codec_new ( )

Definition at line 530 of file fl_method_channel_test.cc.

Referenced by TEST().

530  {
531  return TEST_METHOD_CODEC(g_object_new(test_method_codec_get_type(), nullptr));
532 }