Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.2.7

* [swift] Fixes a bug when calling methods that return `void`.

## 4.2.6

* Fixes bug with parsing documentation comments that start with '/'.
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'dart:mirrors';
import 'ast.dart';

/// The current version of pigeon. This must match the version in pubspec.yaml.
const String pigeonVersion = '4.2.6';
const String pigeonVersion = '4.2.7';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
4 changes: 2 additions & 2 deletions packages/pigeon/lib/swift_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void _writeHostApi(Indent indent, Api api, Root root) {
indent.write('$call ');
if (method.returnType.isVoid) {
indent.scoped('{', '}', () {
indent.writeln('reply(nil)');
Comment thread
stuartmorgan-g marked this conversation as resolved.
indent.writeln('reply(wrapResult(nil))');
});
} else {
indent.scoped('{ result in', '}', () {
Expand All @@ -242,7 +242,7 @@ void _writeHostApi(Indent indent, Api api, Root root) {
} else {
if (method.returnType.isVoid) {
indent.writeln(call);
indent.writeln('reply(nil)');
indent.writeln('reply(wrapResult(nil))');
} else {
indent.writeln('let result = $call');
indent.writeln('reply(wrapResult(result))');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// 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.

// TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#104231)
// ignore: unnecessary_import
import 'dart:typed_data';

import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:test_plugin/all_datatypes.gen.dart';
import 'package:test_plugin/all_void.gen.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('Host API tests', () {
testWidgets('voidCallVoidReturn', (WidgetTester _) async {
final AllVoidHostApi api = AllVoidHostApi();

expect(api.doit(), completes);
});

testWidgets('allDataTypesEcho', (WidgetTester _) async {
final HostEverything api = HostEverything();

final Everything sentObject = Everything(
aBool: true,
anInt: 42,
aDouble: 3.14159,
aString: 'Hello host!',
aByteArray: Uint8List.fromList(<int>[1, 2, 3]),
a4ByteArray: Int32List.fromList(<int>[4, 5, 6]),
a8ByteArray: Int64List.fromList(<int>[7, 8, 9]),
aFloatArray: Float64List.fromList(<double>[2.71828, 3.14159]),
aList: <Object?>['Thing 1', 2],
aMap: <Object?, Object?>{'a': 1, 'b': 2.0},
nestedList: <List<bool>>[
<bool>[true, false],
<bool>[false, true]
],
);

final Everything echoObject = await api.echo(sentObject);
expect(echoObject.aBool, sentObject.aBool);
expect(echoObject.anInt, sentObject.anInt);
expect(echoObject.aDouble, sentObject.aDouble);
expect(echoObject.aString, sentObject.aString);
// TODO(stuartmorgan): Enable these once they work for all generators;
// currently at least Swift is broken.
// See https://github.com/flutter/flutter/issues/115906
//expect(echoObject.aByteArray, sentObject.aByteArray);
//expect(echoObject.a4ByteArray, sentObject.a4ByteArray);
//expect(echoObject.a8ByteArray, sentObject.a8ByteArray);
//expect(echoObject.aFloatArray, sentObject.aFloatArray);
expect(listEquals(echoObject.aList, sentObject.aList), true);
expect(mapEquals(echoObject.aMap, sentObject.aMap), true);
expect(echoObject.nestedList?.length, sentObject.nestedList?.length);
// TODO(stuartmorgan): Enable this once the Dart types are fixed; see
// https://github.com/flutter/flutter/issues/116117
//for (int i = 0; i < echoObject.nestedList!.length; i++) {
// expect(listEquals(echoObject.nestedList![i], sentObject.nestedList![i]),
// true);
//}
expect(
mapEquals(
echoObject.mapWithAnnotations, sentObject.mapWithAnnotations),
true);
expect(
mapEquals(echoObject.mapWithObject, sentObject.mapWithObject), true);
});
});

group('Flutter API tests', () {
// TODO(stuartmorgan): Add Flutter API tests, driven by wrapper host APIs
// that forward the arguments and return values in the opposite direction.
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AsyncHandlersTest: XCTestCase {
let expectation = XCTestExpectation(description: "voidvoid callback")
binaryMessenger.handlers[channelName]?(nil) { data in
let outputMap = binaryMessenger.codec.decode(data) as? [String: Any]
XCTAssertNil(outputMap?["result"])
XCTAssertEqual(outputMap?["result"] as! NSNull, NSNull())
XCTAssertNil(outputMap?["error"])
expectation.fulfill()
}
Expand Down
23 changes: 17 additions & 6 deletions packages/pigeon/platform_tests/test_plugin/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';
import 'package:test_plugin/all_void.gen.dart';
import 'package:test_plugin/test_plugin.dart';

void main() {
Expand All @@ -21,6 +22,8 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
// ignore: unused_field
final TestPlugin _testPlugin = TestPlugin();
late final AllVoidHostApi api;
String status = 'Calling...';

@override
void initState() {
Expand All @@ -29,9 +32,18 @@ class _MyAppState extends State<MyApp> {
}

Future<void> initPlatformState() async {
// TODO(tarrinneal): Call TestPlugin methods here for manual integration
// testing, once they exist. See
// https://github.com/flutter/flutter/issues/111505
api = AllVoidHostApi();
try {
await api.doit();
} catch (e) {
setState(() {
status = 'Failed: $e';
});
return;
}
setState(() {
status = 'Success!';
});
}

@override
Expand All @@ -41,9 +53,8 @@ class _MyAppState extends State<MyApp> {
appBar: AppBar(
title: const Text('Pigeon integration tests'),
),
body: const Center(
child: Text(
'TODO, see https://github.com/flutter/flutter/issues/111505'),
body: Center(
child: Text(status),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
integration_test:
sdk: flutter

flutter:
uses-material-design: true
9 changes: 4 additions & 5 deletions packages/pigeon/platform_tests/test_plugin/lib/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# changes on generated files. This will need a way to avoid unnecessary churn,
# such as a flag to suppress version stamp generation.
*.gen.dart
# TODO(stuartmorgan): Add exceptions for specific files that are used in
# integration tests, as they will need to be checked in to avoid analysis
# failures. The exclusion of other files is to prevent having multiple
# copies of all of the Dart output until more tests are restructured to
# minimize duplication.
# The following are files that are used in integration tests, which need to be
# checked in to avoid analysis failures.
!all_datatypes.gen.dart
!all_void.gen.dart
Loading