5#include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h"
10#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
11#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_message_codec.h"
12#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h"
13#include "gtest/gtest.h"
19class TestBinaryMessenger :
public BinaryMessenger {
21 void Send(
const std::string& channel,
23 const size_t message_size,
26 int length =
static_cast<int>(message_size);
33 last_message_handler_channel_ = channel;
34 last_message_handler_ = handler;
37 bool send_called() {
return send_called_; }
39 std::string last_message_handler_channel() {
40 return last_message_handler_channel_;
45 std::vector<uint8_t> last_message() {
return last_message_; }
48 mutable bool send_called_ =
false;
49 std::string last_message_handler_channel_;
51 mutable std::vector<uint8_t> last_message_;
58TEST(BasicMessageChannelTest, Registration) {
59 TestBinaryMessenger messenger;
60 const std::string channel_name(
"some_channel");
64 bool callback_called =
false;
65 const std::string message_value(
"hello");
67 [&callback_called, message_value](
const auto&
message,
auto reply) {
68 callback_called =
true;
71 EXPECT_EQ(std::get<std::string>(
message), message_value);
72 EXPECT_NE(reply,
nullptr);
74 EXPECT_EQ(messenger.last_message_handler_channel(), channel_name);
75 EXPECT_NE(messenger.last_message_handler(),
nullptr);
79 messenger.last_message_handler()(
81 [](
const uint8_t* reply,
const size_t reply_size) {});
82 EXPECT_EQ(callback_called,
true);
86TEST(BasicMessageChannelTest, Unregistration) {
87 TestBinaryMessenger messenger;
88 const std::string channel_name(
"some_channel");
93 EXPECT_EQ(messenger.last_message_handler_channel(), channel_name);
94 EXPECT_NE(messenger.last_message_handler(),
nullptr);
97 EXPECT_EQ(messenger.last_message_handler_channel(), channel_name);
98 EXPECT_EQ(messenger.last_message_handler(),
nullptr);
103TEST(BasicMessageChannelTest, Resize) {
104 TestBinaryMessenger messenger;
105 const std::string channel_name(
"flutter/test");
119 const int expected_message_size = 29;
121 EXPECT_EQ(messenger.send_called(),
true);
122 EXPECT_EQ(
static_cast<int>(messenger.last_message().size()),
123 expected_message_size);
125 int expected[expected_message_size] = {
126 7, 6, 114, 101, 115, 105, 122, 101, 12, 2, 7, 12, 102, 108, 117,
127 116, 116, 101, 114, 47, 116, 101, 115, 116, 3, 3, 0, 0, 0};
128 for (
int i = 0;
i < expected_message_size;
i++) {
129 EXPECT_EQ(messenger.last_message()[
i], expected[
i]);
136 TestBinaryMessenger messenger;
138 const std::string channel_name(
"flutter/test");
151 const int expected_message_size = 27;
153 EXPECT_EQ(messenger.send_called(),
true);
154 EXPECT_EQ(
static_cast<int>(messenger.last_message().size()),
155 expected_message_size);
157 int expected[expected_message_size] = {
158 7, 8, 111, 118, 101, 114, 102, 108, 111, 119, 12, 2, 7, 12,
159 102, 108, 117, 116, 116, 101, 114, 47, 116, 101, 115, 116, 1};
160 for (
int i = 0;
i < expected_message_size;
i++) {
161 EXPECT_EQ(messenger.last_message()[
i], expected[
i]);
static void SetWarnsOnOverflow(NSObject< FlutterBinaryMessenger > *binaryMessenger, NSString *channel, BOOL warns)
static FlutterBinaryMessengerConnection SetMessageHandler(NSObject< FlutterBinaryMessenger > *messenger, NSString *name, FlutterBinaryMessageHandler handler, NSObject< FlutterTaskQueue > *taskQueue)
void Resize(int new_size)
void SetMessageHandler(const MessageHandler< T > &handler) const
void SetWarnsOnOverflow(bool warns)
std::unique_ptr< std::vector< uint8_t > > EncodeMessage(const T &message) const
static const StandardMessageCodec & GetInstance(const StandardCodecSerializer *serializer=nullptr)
void Send(const std::string &channel, const uint8_t *message, size_t message_size, BinaryReply reply) const override
std::function< void(const uint8_t *message, size_t message_size, BinaryReply reply)> BinaryMessageHandler
TEST(FrameTimingsRecorderTest, RecordVsync)
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply