Flutter iOS Embedder
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 
12 #import "flutter/testing/testing.h"
13 #include "gtest/gtest.h"
14 
16 
17 @interface FlutterBinaryMessengerRelayTest : NSObject
18 @end
19 
20 @implementation FlutterBinaryMessengerRelayTest
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 
94 TEST(FlutterBinaryMessengerRelayTest, SetMessageHandlerWithTaskQueue) {
95  ASSERT_FALSE(FLTThrowsObjcException(^{
96  [[FlutterBinaryMessengerRelayTest alloc] testSetMessageHandlerWithTaskQueue];
97  }));
98 }
99 
100 TEST(FlutterBinaryMessengerRelayTest, SetMakeBackgroundTaskQueue) {
101  ASSERT_FALSE(FLTThrowsObjcException(^{
102  [[FlutterBinaryMessengerRelayTest alloc] testMakeBackgroundTaskQueue];
103  }));
104 }
-[FlutterBinaryMessenger-p sendOnChannel:message:binaryReply:]
void sendOnChannel:message:binaryReply:(NSString *channel,[message] NSData *_Nullable message,[binaryReply] FlutterBinaryReply _Nullable callback)
FlutterBinaryMessengerRelayTest
Definition: FlutterBinaryMessengerRelayTest.mm:17
flutter_task_queue_dispatch.h
FlutterMacros.h
FlutterTestUtils.h
FlutterBinaryMessageHandler
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
Definition: FlutterBinaryMessenger.h:30
FlutterBinaryMessengerRelay.h
-[FlutterBinaryMessenger-p makeBackgroundTaskQueue]
NSObject< FlutterTaskQueue > * makeBackgroundTaskQueue()
TODO(gaaclarke): Remove optional when macos supports Background Platform Channels.
-[FlutterBinaryMessenger-p setMessageHandlerOnChannel:binaryMessageHandler:taskQueue:]
FlutterBinaryMessengerConnection setMessageHandlerOnChannel:binaryMessageHandler:taskQueue:(NSString *channel,[binaryMessageHandler] FlutterBinaryMessageHandler _Nullable handler,[taskQueue] NSObject< FlutterTaskQueue > *_Nullable taskQueue)
FLTThrowsObjcException
BOOL FLTThrowsObjcException(dispatch_block_t block)
Returns YES if the block throws an exception.
Definition: FlutterTestUtils.mm:11
TEST
TEST(FlutterBinaryMessengerRelayTest, Create)
Definition: FlutterBinaryMessengerRelayTest.mm:76
FlutterTaskQueueDispatch-p
Definition: flutter_task_queue_dispatch.h:16
FlutterBinaryMessengerRelay
Definition: FlutterBinaryMessengerRelay.h:14
FlutterBinaryMessenger-p
Definition: FlutterBinaryMessenger.h:49
FlutterBinaryMessengerRelay::parent
NSObject< FlutterBinaryMessenger > * parent
Definition: FlutterBinaryMessengerRelay.h:15
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13
FlutterBinaryReply
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)