| // Copyright 2013 The Flutter Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| import Flutter |
| import UIKit |
| |
| extension FlutterError: Error {} |
| |
| /** |
| * This plugin handles the native side of the integration tests in |
| * example/integration_test/. |
| */ |
| public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { |
| var flutterAPI: FlutterIntegrationCoreApi |
| |
| public static func register(with registrar: FlutterPluginRegistrar) { |
| let plugin = TestPlugin(binaryMessenger: registrar.messenger()) |
| HostIntegrationCoreApiSetup.setUp(binaryMessenger: registrar.messenger(), api: plugin) |
| } |
| |
| init(binaryMessenger: FlutterBinaryMessenger) { |
| flutterAPI = FlutterIntegrationCoreApi(binaryMessenger: binaryMessenger) |
| } |
| |
| // MARK: HostIntegrationCoreApi implementation |
| |
| func noop() { |
| |
| } |
| |
| func echo(_ everything: AllTypes) -> AllTypes { |
| return everything |
| } |
| |
| func echo(_ everything: AllNullableTypes?) -> AllNullableTypes? { |
| return everything |
| } |
| |
| func throwError() throws { |
| throw FlutterError(code: "code", message: "message", details: "details") |
| } |
| |
| func echo(_ anInt: Int32) -> Int32 { |
| return anInt |
| } |
| |
| func echo(_ aDouble: Double) -> Double { |
| return aDouble |
| } |
| |
| func echo(_ aBool: Bool) -> Bool { |
| return aBool |
| } |
| |
| func echo(_ aString: String) -> String { |
| return aString |
| } |
| |
| func echo(_ aUint8List: FlutterStandardTypedData) -> FlutterStandardTypedData { |
| return aUint8List |
| } |
| |
| func echo(_ anObject: Any) -> Any { |
| return anObject |
| } |
| |
| func extractNestedNullableString(from wrapper: AllNullableTypesWrapper) -> String? { |
| return wrapper.values.aNullableString; |
| } |
| |
| func createNestedObject(with nullableString: String?) -> AllNullableTypesWrapper { |
| return AllNullableTypesWrapper(values: AllNullableTypes(aNullableString: nullableString)) |
| } |
| |
| func sendMultipleNullableTypes(aBool aNullableBool: Bool?, anInt aNullableInt: Int32?, aString aNullableString: String?) -> AllNullableTypes { |
| let someThings = AllNullableTypes(aNullableBool: aNullableBool, aNullableInt: aNullableInt, aNullableString: aNullableString) |
| return someThings |
| } |
| |
| func echo(_ aNullableInt: Int32?) -> Int32? { |
| return aNullableInt |
| } |
| |
| func echo(_ aNullableDouble: Double?) -> Double? { |
| return aNullableDouble |
| } |
| |
| func echo(_ aNullableBool: Bool?) -> Bool? { |
| return aNullableBool |
| } |
| |
| func echo(_ aNullableString: String?) -> String? { |
| return aNullableString |
| } |
| |
| func echo(_ aNullableUint8List: FlutterStandardTypedData?) -> FlutterStandardTypedData? { |
| return aNullableUint8List |
| } |
| |
| func echo(_ aNullableObject: Any?) -> Any? { |
| return aNullableObject |
| } |
| |
| func noopAsync(completion: @escaping (Result<Void, Error>) -> Void) { |
| completion(.success(Void())) |
| } |
| |
| func echoAsync(_ aString: String, completion: @escaping (Result<String, Error>) -> Void) { |
| let result: Result<String, Error> |
| result = .success(aString) |
| completion(result) |
| } |
| |
| func throwAsyncError(completion: @escaping (Result<Any?, Error>) -> Void) { |
| completion(.failure(FlutterError(code: "code", message: "message", details: "details"))) |
| } |
| |
| func throwAsyncErrorFromVoid(completion: @escaping (Result<Void, Error>) -> Void) { |
| completion(.failure(FlutterError(code: "code", message: "message", details: "details"))) |
| } |
| |
| func callFlutterNoop(completion: @escaping (Result<Void, Error>) -> Void) { |
| flutterAPI.noop() { |
| completion(.success(Void())) |
| } |
| } |
| |
| func callFlutterEcho(_ everything: AllTypes, completion: @escaping (Result<AllTypes, Error>) -> Void) { |
| flutterAPI.echo(everything) { |
| let result: Result<AllTypes, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterSendMultipleNullableTypes( |
| aBool aNullableBool: Bool?, |
| anInt aNullableInt: Int32?, |
| aString aNullableString: String?, |
| completion: @escaping (Result<AllNullableTypes, Error>) -> Void |
| ) { |
| flutterAPI.sendMultipleNullableTypes( |
| aBool: aNullableBool, |
| anInt: aNullableInt, |
| aString: aNullableString |
| ) { |
| let result: Result<AllNullableTypes, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEcho(_ aBool: Bool, completion: @escaping (Result<Bool, Error>) -> Void) { |
| flutterAPI.echo(aBool) { |
| let result: Result<Bool, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEcho(_ anInt: Int32, completion: @escaping (Result<Int32, Error>) -> Void) { |
| flutterAPI.echo(anInt) { |
| let result: Result<Int32, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEcho(_ aDouble: Double, completion: @escaping (Result<Double, Error>) -> Void) { |
| flutterAPI.echo(aDouble) { |
| let result: Result<Double, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEcho(_ aString: String, completion: @escaping (Result<String, Error>) -> Void) { |
| flutterAPI.echo(aString) { |
| let result: Result<String, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEcho(_ aList: FlutterStandardTypedData, completion: @escaping (Result<FlutterStandardTypedData, Error>) -> Void) { |
| flutterAPI.echo(aList) { |
| let result: Result<FlutterStandardTypedData, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEcho(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { |
| flutterAPI.echo(aList) { |
| let result: Result<[Any?], Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEcho(_ aMap: [String? : Any?], completion: @escaping (Result<[String? : Any?], Error>) -> Void) { |
| flutterAPI.echo(aMap) { |
| let result: Result<[String? : Any?], Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEchoNullable(_ aBool: Bool?, completion: @escaping (Result<Bool?, Error>) -> Void) { |
| flutterAPI.echoNullable(aBool) { |
| let result: Result<Bool?, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEchoNullable(_ anInt: Int32?, completion: @escaping (Result<Int32?, Error>) -> Void) { |
| flutterAPI.echoNullable(anInt) { |
| let result: Result<Int32?, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEchoNullable(_ aDouble: Double?, completion: @escaping (Result<Double?, Error>) -> Void) { |
| flutterAPI.echoNullable(aDouble) { |
| let result: Result<Double?, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEchoNullable(_ aString: String?, completion: @escaping (Result<String?, Error>) -> Void) { |
| flutterAPI.echoNullable(aString) { |
| let result: Result<String?, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEchoNullable(_ aList: FlutterStandardTypedData?, completion: @escaping (Result<FlutterStandardTypedData?, Error>) -> Void) { |
| flutterAPI.echoNullable(aList) { |
| let result: Result<FlutterStandardTypedData?, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEchoNullable(_ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) { |
| flutterAPI.echoNullable(aList) { |
| let result: Result<[Any?]?, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| |
| func callFlutterEchoNullable(_ aMap: [String? : Any?]?, completion: @escaping (Result<[String? : Any?]?, Error>) -> Void) { |
| flutterAPI.echoNullable(aMap) { |
| let result: Result<[String? : Any?]?, Error> |
| result = .success($0) |
| completion(result) |
| } |
| } |
| } |