mirror of
https://github.com/flutter/packages.git
synced 2025-06-29 14:18:54 +08:00
[pigeon] fixed error returning errors from async void(void) functions (#380)
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
## 0.2.3
|
||||
|
||||
* bugfix in iOS async handlers of functions with no arguments.
|
||||
|
||||
## 0.2.2
|
||||
|
||||
* Added support for enums.
|
||||
|
@ -8,7 +8,7 @@ import 'dart:mirrors';
|
||||
import 'ast.dart';
|
||||
|
||||
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
||||
const String pigeonVersion = '0.2.2';
|
||||
const String pigeonVersion = '0.2.3';
|
||||
|
||||
/// Read all the content from [stdin] to a String.
|
||||
String readStdin() {
|
||||
|
@ -283,7 +283,7 @@ void _writeHostApiSource(Indent indent, ObjcOptions options, Api api) {
|
||||
}
|
||||
if (func.isAsynchronous) {
|
||||
if (func.returnType == 'void') {
|
||||
const String callback = 'callback(error);';
|
||||
const String callback = 'callback(wrapResult(nil, error));';
|
||||
if (func.argType == 'void') {
|
||||
indent.writeScoped(
|
||||
'[api ${func.name}:^(FlutterError *_Nullable error) {',
|
||||
|
@ -60,6 +60,7 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@interface MockApi2Host : NSObject<Api2Host>
|
||||
@property(nonatomic, copy) NSNumber* output;
|
||||
@property(nonatomic, retain) FlutterError* voidVoidError;
|
||||
@end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -76,6 +77,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)voidVoid:(nonnull void (^)(FlutterError* _Nullable))completion {
|
||||
completion(self.voidVoidError);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -100,6 +105,42 @@
|
||||
[self waitForExpectationsWithTimeout:1.0 handler:nil];
|
||||
}
|
||||
|
||||
- (void)testAsyncFlutter2HostVoidVoid {
|
||||
MockBinaryMessenger* binaryMessenger = [[MockBinaryMessenger alloc] init];
|
||||
MockApi2Host* mockApi2Host = [[MockApi2Host alloc] init];
|
||||
mockApi2Host.output = @(2);
|
||||
Api2HostSetup(binaryMessenger, mockApi2Host);
|
||||
NSString* channelName = @"dev.flutter.pigeon.Api2Host.voidVoid";
|
||||
XCTAssertNotNil(binaryMessenger.handlers[channelName]);
|
||||
|
||||
XCTestExpectation* expectation = [self expectationWithDescription:@"voidvoid callback"];
|
||||
binaryMessenger.handlers[channelName](nil, ^(NSData* data) {
|
||||
NSDictionary* outputMap = [binaryMessenger.codec decode:data];
|
||||
XCTAssertEqualObjects(outputMap[@"result"], [NSNull null]);
|
||||
XCTAssertEqualObjects(outputMap[@"error"], [NSNull null]);
|
||||
[expectation fulfill];
|
||||
});
|
||||
[self waitForExpectationsWithTimeout:1.0 handler:nil];
|
||||
}
|
||||
|
||||
- (void)testAsyncFlutter2HostVoidVoidError {
|
||||
MockBinaryMessenger* binaryMessenger = [[MockBinaryMessenger alloc] init];
|
||||
MockApi2Host* mockApi2Host = [[MockApi2Host alloc] init];
|
||||
mockApi2Host.voidVoidError = [FlutterError errorWithCode:@"code" message:@"message" details:nil];
|
||||
Api2HostSetup(binaryMessenger, mockApi2Host);
|
||||
NSString* channelName = @"dev.flutter.pigeon.Api2Host.voidVoid";
|
||||
XCTAssertNotNil(binaryMessenger.handlers[channelName]);
|
||||
|
||||
XCTestExpectation* expectation = [self expectationWithDescription:@"voidvoid callback"];
|
||||
binaryMessenger.handlers[channelName](nil, ^(NSData* data) {
|
||||
NSDictionary* outputMap = [binaryMessenger.codec decode:data];
|
||||
XCTAssertNotNil(outputMap[@"error"]);
|
||||
XCTAssertEqualObjects(outputMap[@"error"][@"code"], mockApi2Host.voidVoidError.code);
|
||||
[expectation fulfill];
|
||||
});
|
||||
[self waitForExpectationsWithTimeout:1.0 handler:nil];
|
||||
}
|
||||
|
||||
- (void)testAsyncFlutter2Host {
|
||||
MockBinaryMessenger* binaryMessenger = [[MockBinaryMessenger alloc] init];
|
||||
MockApi2Host* mockApi2Host = [[MockApi2Host alloc] init];
|
||||
|
@ -2,7 +2,7 @@ name: pigeon
|
||||
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
||||
repository: https://github.com/flutter/packages/tree/master/packages/pigeon
|
||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
|
||||
version: 0.2.2 # This must match the version in lib/generator_tools.dart
|
||||
version: 0.2.3 # This must match the version in lib/generator_tools.dart
|
||||
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
|
Reference in New Issue
Block a user