Flutter Engine
FlutterPlatformPluginTest.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 <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
7 
8 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
9 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
10 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h"
11 #import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
12 
13 @interface FlutterPlatformPluginTest : XCTestCase
14 @end
15 
16 @implementation FlutterPlatformPluginTest
17 
18 - (void)testHasStrings {
19  FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil];
20  std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>> _weakFactory =
21  std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(engine);
22  FlutterPlatformPlugin* plugin =
23  [[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakPtr()];
24 
25  // Set some string to the pasteboard.
26  __block bool calledSet = false;
27  FlutterResult resultSet = ^(id result) {
28  calledSet = true;
29  };
30  FlutterMethodCall* methodCallSet =
31  [FlutterMethodCall methodCallWithMethodName:@"Clipboard.setClipboardData"
32  arguments:@{@"text" : @"some string"}];
33  [plugin handleMethodCall:methodCallSet result:resultSet];
34  XCTAssertEqual(calledSet, true);
35 
36  // Call hasStrings and expect it to be true.
37  __block bool called = false;
38  __block bool value;
39  FlutterResult result = ^(id result) {
40  called = true;
41  value = result[@"value"];
42  };
43  FlutterMethodCall* methodCall =
44  [FlutterMethodCall methodCallWithMethodName:@"Clipboard.hasStrings" arguments:nil];
45  [plugin handleMethodCall:methodCall result:result];
46 
47  XCTAssertEqual(called, true);
48  XCTAssertEqual(value, true);
49 }
50 
51 @end
std::unique_ptr< fml::WeakPtrFactory< FlutterEngine > > _weakFactory
uint8_t value
void(^ FlutterResult)(id _Nullable result)
instancetype methodCallWithMethodName:arguments:(NSString *method, [arguments] id _Nullable arguments)