Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
FlutterBinaryMessengerRelayTest.mm
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import "flutter/shell/platform/darwin/common/framework/Source/FlutterBinaryMessengerRelay.h"
6
7#import <OCMock/OCMock.h>
8
9#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
10#import "flutter/shell/platform/darwin/common/framework/Source/FlutterTestUtils.h"
11#import "flutter/shell/platform/darwin/ios/flutter_task_queue_dispatch.h"
12#import "flutter/testing/testing.h"
13#include "gtest/gtest.h"
14
16
18@end
19
21
22- (void)testCreate {
23 id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
25 [[FlutterBinaryMessengerRelay alloc] initWithParent:messenger];
26 EXPECT_NE(relay, nil);
27 EXPECT_EQ(messenger, relay.parent);
28}
29
30- (void)testPassesCallOn {
31 id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
33 [[FlutterBinaryMessengerRelay alloc] initWithParent:messenger];
34 char messageData[] = {'a', 'a', 'r', 'o', 'n'};
35 NSData* message = [NSData dataWithBytes:messageData length:sizeof(messageData)];
36 NSString* channel = @"foobar";
37 [relay sendOnChannel:channel message:message binaryReply:nil];
38 OCMVerify([messenger sendOnChannel:channel message:message binaryReply:nil]);
39}
40
42 id messenger = OCMStrictProtocolMock(@protocol(FlutterBinaryMessenger));
44 [[FlutterBinaryMessengerRelay alloc] initWithParent:messenger];
45 char messageData[] = {'a', 'a', 'r', 'o', 'n'};
46 NSData* message = [NSData dataWithBytes:messageData length:sizeof(messageData)];
47 NSString* channel = @"foobar";
48 relay.parent = nil;
49 [relay sendOnChannel:channel message:message binaryReply:nil];
50}
51
53 id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
55 [[FlutterBinaryMessengerRelay alloc] initWithParent:messenger];
56 NSString* channel = @"foobar";
57 NSObject<FlutterTaskQueue>* taskQueue = OCMProtocolMock(@protocol(FlutterTaskQueueDispatch));
58 FlutterBinaryMessageHandler handler = ^(NSData* _Nullable, FlutterBinaryReply _Nonnull) {
59 };
60 [relay setMessageHandlerOnChannel:channel binaryMessageHandler:handler taskQueue:taskQueue];
61 OCMVerify([messenger setMessageHandlerOnChannel:channel
62 binaryMessageHandler:handler
63 taskQueue:taskQueue]);
64}
65
67 id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
69 [[FlutterBinaryMessengerRelay alloc] initWithParent:messenger];
71 OCMVerify([messenger makeBackgroundTaskQueue]);
72}
73
74@end
75
77 ASSERT_FALSE(FLTThrowsObjcException(^{
78 [[FlutterBinaryMessengerRelayTest alloc] testCreate];
79 }));
80}
81
83 ASSERT_FALSE(FLTThrowsObjcException(^{
84 [[FlutterBinaryMessengerRelayTest alloc] testPassesCallOn];
85 }));
86}
87
89 ASSERT_FALSE(FLTThrowsObjcException(^{
90 [[FlutterBinaryMessengerRelayTest alloc] testDoesntPassCallOn];
91 }));
92}
93
94TEST(FlutterBinaryMessengerRelayTest, SetMessageHandlerWithTaskQueue) {
95 ASSERT_FALSE(FLTThrowsObjcException(^{
96 [[FlutterBinaryMessengerRelayTest alloc] testSetMessageHandlerWithTaskQueue];
97 }));
98}
99
100TEST(FlutterBinaryMessengerRelayTest, SetMakeBackgroundTaskQueue) {
101 ASSERT_FALSE(FLTThrowsObjcException(^{
102 [[FlutterBinaryMessengerRelayTest alloc] testMakeBackgroundTaskQueue];
103 }));
104}
#define TEST(S, s, D, expected)
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
BOOL FLTThrowsObjcException(dispatch_block_t block)
Returns YES if the block throws an exception.
static sk_sp< Effect > Create()
FlutterBinaryMessengerConnection setMessageHandlerOnChannel:binaryMessageHandler:taskQueue:(NSString *channel, [binaryMessageHandler] FlutterBinaryMessageHandler handler, [taskQueue] NSObject< FlutterTaskQueue > *taskQueue)
NSObject< FlutterBinaryMessenger > * parent
void sendOnChannel:message:binaryReply:(NSString *channel, [message] NSData *message, [binaryReply] FlutterBinaryReply callback)
NSObject< FlutterTaskQueue > * makeBackgroundTaskQueue()
TODO(gaaclarke): Remove optional when macos supports Background Platform Channels.
Win32Message message