Skip to content

Commit 3b1a50a

Browse files
bbrto21swift-kim
authored andcommitted
Add more FlutterTizenEngine unit tests (#148)
* The original was taken from the Windows implementation Signed-off-by: Boram Bae <[email protected]>
1 parent 068fd30 commit 3b1a50a

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

shell/platform/tizen/flutter_tizen_engine_unittest.cc

+83
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,88 @@ TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) {
143143
modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; };
144144
}
145145

146+
TEST_F(FlutterTizenEngineTest, SendPlatformMessageWithoutResponse) {
147+
EngineModifier modifier(engine_);
148+
149+
const char* channel = "test";
150+
const std::vector<uint8_t> test_message = {1, 2, 3, 4};
151+
152+
// Without a response, SendPlatformMessage should be a simple pass-through.
153+
bool called = false;
154+
modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC(
155+
SendPlatformMessage, ([&called, test_message](auto engine, auto message) {
156+
called = true;
157+
EXPECT_STREQ(message->channel, "test");
158+
EXPECT_EQ(message->message_size, test_message.size());
159+
EXPECT_EQ(memcmp(message->message, test_message.data(),
160+
message->message_size),
161+
0);
162+
EXPECT_EQ(message->response_handle, nullptr);
163+
return kSuccess;
164+
}));
165+
166+
engine_->SendPlatformMessage(channel, test_message.data(),
167+
test_message.size(), nullptr, nullptr);
168+
EXPECT_TRUE(called);
169+
}
170+
171+
TEST_F(FlutterTizenEngineTest, SendPlatformMessageWithResponse) {
172+
EngineModifier modifier(engine_);
173+
174+
const char* channel = "test";
175+
const std::vector<uint8_t> test_message = {1, 2, 3, 4};
176+
auto* dummy_response_handle =
177+
reinterpret_cast<FlutterPlatformMessageResponseHandle*>(5);
178+
const FlutterDesktopBinaryReply reply_handler = [](auto... args) {};
179+
void* reply_user_data = reinterpret_cast<void*>(6);
180+
181+
// When a response is requested, a handle should be created, passed as part
182+
// of the message, and then released.
183+
bool create_response_handle_called = false;
184+
modifier.embedder_api().PlatformMessageCreateResponseHandle =
185+
MOCK_ENGINE_PROC(
186+
PlatformMessageCreateResponseHandle,
187+
([&create_response_handle_called, &reply_handler, reply_user_data,
188+
dummy_response_handle](auto engine, auto reply, auto user_data,
189+
auto response_handle) {
190+
create_response_handle_called = true;
191+
EXPECT_EQ(reply, reply_handler);
192+
EXPECT_EQ(user_data, reply_user_data);
193+
EXPECT_NE(response_handle, nullptr);
194+
*response_handle = dummy_response_handle;
195+
return kSuccess;
196+
}));
197+
bool release_response_handle_called = false;
198+
modifier.embedder_api().PlatformMessageReleaseResponseHandle =
199+
MOCK_ENGINE_PROC(
200+
PlatformMessageReleaseResponseHandle,
201+
([&release_response_handle_called, dummy_response_handle](
202+
auto engine, auto response_handle) {
203+
release_response_handle_called = true;
204+
EXPECT_EQ(response_handle, dummy_response_handle);
205+
return kSuccess;
206+
}));
207+
bool send_message_called = false;
208+
modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC(
209+
SendPlatformMessage, ([&send_message_called, test_message,
210+
dummy_response_handle](auto engine, auto message) {
211+
send_message_called = true;
212+
EXPECT_STREQ(message->channel, "test");
213+
EXPECT_EQ(message->message_size, test_message.size());
214+
EXPECT_EQ(memcmp(message->message, test_message.data(),
215+
message->message_size),
216+
0);
217+
EXPECT_EQ(message->response_handle, dummy_response_handle);
218+
return kSuccess;
219+
}));
220+
221+
engine_->SendPlatformMessage(channel, test_message.data(),
222+
test_message.size(), reply_handler,
223+
reply_user_data);
224+
EXPECT_TRUE(create_response_handle_called);
225+
EXPECT_TRUE(release_response_handle_called);
226+
EXPECT_TRUE(send_message_called);
227+
}
228+
146229
} // namespace testing
147230
} // namespace flutter

0 commit comments

Comments
 (0)