| Flutter macOS 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
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/testing/testing.h"
12 #include "gtest/gtest.h"
13
14 FLUTTER_ASSERT_ARC
15
16 @protocol FlutterTaskQueue <NSObject>
17 @end
18
19 @interface FlutterBinaryMessengerRelayTest : NSObject
20 @end
21
22 @implementation FlutterBinaryMessengerRelayTest
23
24 - (void)testCreate {
25 id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
26 FlutterBinaryMessengerRelay* relay =
27 [[FlutterBinaryMessengerRelay alloc] initWithParent:messenger];
28 EXPECT_NE(relay, nil);
29 EXPECT_EQ(messenger, relay.parent);
30 }
31
32 - (void)testPassesCallOn {
33 id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
34 FlutterBinaryMessengerRelay* relay =
35 [[FlutterBinaryMessengerRelay alloc] initWithParent:messenger];
36 char messageData[] = {'a', 'a', 'r', 'o', 'n'};
37 NSData* message = [NSData dataWithBytes:messageData length:sizeof(messageData)];
38 NSString* channel = @"foobar";
39 [relay sendOnChannel:channel message:message binaryReply:nil];
40 OCMVerify([messenger sendOnChannel:channel message:message binaryReply:nil]);
41 }
42
43 - (void)testDoesntPassCallOn {
44 id messenger = OCMStrictProtocolMock(@protocol(FlutterBinaryMessenger));
45 FlutterBinaryMessengerRelay* relay =
46 [[FlutterBinaryMessengerRelay alloc] initWithParent:messenger];
47 char messageData[] = {'a', 'a', 'r', 'o', 'n'};
48 NSData* message = [NSData dataWithBytes:messageData length:sizeof(messageData)];
49 NSString* channel = @"foobar";
50 relay.parent = nil;
51 [relay sendOnChannel:channel message:message binaryReply:nil];
52 }
53
54 - (void)testSetMessageHandlerWithTaskQueue {
55 id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
56 FlutterBinaryMessengerRelay* relay =
57 [[FlutterBinaryMessengerRelay alloc] initWithParent:messenger];
58 NSString* channel = @"foobar";
59 NSObject<FlutterTaskQueue>* taskQueue = OCMProtocolMock(@protocol(FlutterTaskQueue));
60 FlutterBinaryMessageHandler handler = ^(NSData* _Nullable, FlutterBinaryReply _Nonnull) {
61 };
62 [relay setMessageHandlerOnChannel:channel binaryMessageHandler:handler taskQueue:taskQueue];
63 OCMVerify([messenger setMessageHandlerOnChannel:channel
64 binaryMessageHandler:handler
65 taskQueue:taskQueue]);
66 }
67
68 - (void)testMakeBackgroundTaskQueue {
69 id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
70 FlutterBinaryMessengerRelay* relay =
71 [[FlutterBinaryMessengerRelay alloc] initWithParent:messenger];
72 [relay makeBackgroundTaskQueue];
73 OCMVerify([messenger makeBackgroundTaskQueue]);
74 }
75
76 @end
77
78 TEST(FlutterBinaryMessengerRelayTest, Create) {
79 ASSERT_FALSE(FLTThrowsObjcException(^{
80 [[FlutterBinaryMessengerRelayTest alloc] testCreate];
81 }));
82 }
83
84 TEST(FlutterBinaryMessengerRelayTest, PassesCallOn) {
85 ASSERT_FALSE(FLTThrowsObjcException(^{
86 [[FlutterBinaryMessengerRelayTest alloc] testPassesCallOn];
87 }));
88 }
89
90 TEST(FlutterBinaryMessengerRelayTest, DoesntPassCallOn) {
91 ASSERT_FALSE(FLTThrowsObjcException(^{
92 [[FlutterBinaryMessengerRelayTest alloc] testDoesntPassCallOn];
93 }));
94 }
95
96 TEST(FlutterBinaryMessengerRelayTest, SetMessageHandlerWithTaskQueue) {
97 ASSERT_FALSE(FLTThrowsObjcException(^{
98 [[FlutterBinaryMessengerRelayTest alloc] testSetMessageHandlerWithTaskQueue];
99 }));
100 }
101
102 TEST(FlutterBinaryMessengerRelayTest, SetMakeBackgroundTaskQueue) {
103 ASSERT_FALSE(FLTThrowsObjcException(^{
104 [[FlutterBinaryMessengerRelayTest alloc] testMakeBackgroundTaskQueue];
105 }));
106 }
FLUTTER_ASSERT_ARC
#define FLUTTER_ASSERT_ARC
Definition: FlutterMacros.h:44
-[FlutterBinaryMessenger-p sendOnChannel:message:binaryReply:]
void sendOnChannel:message:binaryReply:(NSString *channel,[message] NSData *_Nullable message,[binaryReply] FlutterBinaryReply _Nullable callback)
FlutterBinaryMessengerRelayTest
Definition: FlutterBinaryMessengerRelayTest.mm:19
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)
FlutterTaskQueue-p
Definition: FlutterBinaryMessengerRelayTest.mm:16
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:78
FlutterBinaryMessengerRelay
Definition: FlutterBinaryMessengerRelay.h:14
FlutterBinaryMessenger-p
Definition: FlutterBinaryMessenger.h:48
FlutterBinaryMessengerRelay::parent
NSObject< FlutterBinaryMessenger > * parent
Definition: FlutterBinaryMessengerRelay.h:15
FlutterBinaryReply
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)