• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <OCMock/OCMock.h>
6#import <XCTest/XCTest.h>
7#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterBinaryMessengerRelay.h"
8
9#ifndef __has_feature
10#define __has_feature(x) 0 /* for non-clang compilers */
11#endif
12
13#if !__has_feature(objc_arc)
14#error ARC must be enabled!
15#endif
16
17@interface FlutterBinaryMessengerRelayTest : XCTestCase
18@end
19
20@implementation FlutterBinaryMessengerRelayTest
21
22- (void)setUp {
23}
24
25- (void)tearDown {
26}
27
28- (void)testCreate {
29  id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
30  FlutterBinaryMessengerRelay* relay =
31      [[FlutterBinaryMessengerRelay alloc] initWithParent:messenger];
32  XCTAssertNotNil(relay);
33  XCTAssertEqual(messenger, relay.parent);
34}
35
36- (void)testPassesCallOn {
37  id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
38  FlutterBinaryMessengerRelay* relay =
39      [[FlutterBinaryMessengerRelay alloc] initWithParent:messenger];
40  char messageData[] = {'a', 'a', 'r', 'o', 'n'};
41  NSData* message = [NSData dataWithBytes:messageData length:sizeof(messageData)];
42  NSString* channel = @"foobar";
43  [relay sendOnChannel:channel message:message binaryReply:nil];
44  OCMVerify([messenger sendOnChannel:channel message:message binaryReply:nil]);
45}
46
47- (void)testDoesntPassCallOn {
48  id messenger = OCMStrictProtocolMock(@protocol(FlutterBinaryMessenger));
49  FlutterBinaryMessengerRelay* relay =
50      [[FlutterBinaryMessengerRelay alloc] initWithParent:messenger];
51  char messageData[] = {'a', 'a', 'r', 'o', 'n'};
52  NSData* message = [NSData dataWithBytes:messageData length:sizeof(messageData)];
53  NSString* channel = @"foobar";
54  relay.parent = nil;
55  [relay sendOnChannel:channel message:message binaryReply:nil];
56}
57
58@end
59