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
6
7#import <OCMock/OCMock.h>
8
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
41- (void)testDoesntPassCallOn {
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
52- (void)testSetMessageHandlerWithTaskQueue {
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
66- (void)testMakeBackgroundTaskQueue {
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}
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
TEST(FlutterBinaryMessengerRelayTest, Create)
BOOL FLTThrowsObjcException(dispatch_block_t block)
Returns YES if the block throws an exception.
const gchar * channel
const gchar FlBinaryMessengerMessageHandler handler
G_BEGIN_DECLS GBytes * message
NSObject< FlutterBinaryMessenger > * parent
NSObject< FlutterTaskQueue > * makeBackgroundTaskQueue()
TODO(gaaclarke): Remove optional when macos supports Background Platform Channels.
void sendOnChannel:message:binaryReply:(NSString *channel,[message] NSData *_Nullable message,[binaryReply] FlutterBinaryReply _Nullable callback)
FlutterBinaryMessengerConnection setMessageHandlerOnChannel:binaryMessageHandler:taskQueue:(NSString *channel,[binaryMessageHandler] FlutterBinaryMessageHandler _Nullable handler,[taskQueue] NSObject< FlutterTaskQueue > *_Nullable taskQueue)