[pigeon] More simple integration tests (#2950)
* add AnEnum to AllTypes
* AllTypes AnEnum test
* echo string
* echo double
* echo uint8list... swift broken
* Forgot header again
* caps
* copy and paste is a good idea
diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart
index 0aa5cba..730eabc 100644
--- a/packages/pigeon/pigeons/core_tests.dart
+++ b/packages/pigeon/pigeons/core_tests.dart
@@ -4,6 +4,12 @@
import 'package:pigeon/pigeon.dart';
+enum AnEnum {
+ one,
+ two,
+ three,
+}
+
// A class containing all supported types.
class AllTypes {
bool? aBool;
@@ -21,6 +27,7 @@
List<List<bool?>?>? nestedList;
Map<String?, String?>? mapWithAnnotations;
Map<String?, Object?>? mapWithObject;
+ AnEnum? anEnum;
}
// A class for testing nested object handling.
@@ -64,10 +71,22 @@
@ObjCSelector('echoInt:')
int echoInt(int anInt);
- /// Returns the passed in boolean asynchronously.
+ /// Returns passed in double.
+ @ObjCSelector('echoDouble:')
+ double echoDouble(double aDouble);
+
+ /// Returns the passed in boolean.
@ObjCSelector('echoBool:')
bool echoBool(bool aBool);
+ /// Returns the passed in string.
+ @ObjCSelector('echoString:')
+ String echoString(String aString);
+
+ /// Returns the passed in Uint8List.
+ @ObjCSelector('echoUint8List:')
+ Uint8List echoUint8List(Uint8List aUint8List);
+
// ========== Asyncronous method tests ==========
/// A no-op function taking no arguments and returning no value, to sanity
diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java
index bfc0e56..838db53 100644
--- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java
+++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java
@@ -66,11 +66,26 @@
}
@Override
+ public Double echoDouble(@NonNull Double aDouble) {
+ return aDouble;
+ }
+
+ @Override
public Boolean echoBool(@NonNull Boolean aBool) {
return aBool;
}
@Override
+ public String echoString(@NonNull String aString) {
+ return aString;
+ }
+
+ @Override
+ public byte[] echoUint8List(@NonNull byte[] aUint8List) {
+ return aUint8List;
+ }
+
+ @Override
public void noopAsync(Result<Void> result) {
result.success(null);
}
diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m
index 8f8a62e..cbe1bda 100644
--- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m
+++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m
@@ -63,10 +63,25 @@
return anInt;
}
+- (nullable NSNumber *)echoDouble:(NSNumber *)aDouble
+ error:(FlutterError *_Nullable *_Nonnull)error {
+ return aDouble
+}
+
- (nullable NSNumber *)echoBool:(NSNumber *)aBool error:(FlutterError *_Nullable *_Nonnull)error {
return aBool;
}
+- (nullable NSString *)echoString:(NSString *)aString
+ error:(FlutterError *_Nullable *_Nonnull)error {
+ return aString;
+}
+
+- (nullable FlutterStandardTypedData *)echoUint8List:(FlutterStandardTypedData *)aUint8List
+ error:(FlutterError *_Nullable *_Nonnull)error {
+ return aUint8List;
+}
+
- (void)noopAsyncWithCompletion:(void (^)(FlutterError *_Nullable))completion {
completion(nil);
}
diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart
index 7f7a4d3..b701c66 100644
--- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart
+++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart
@@ -11,6 +11,12 @@
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;
import 'package:flutter/services.dart';
+enum AnEnum {
+ one,
+ two,
+ three,
+}
+
class AllTypes {
AllTypes({
this.aBool,
@@ -26,6 +32,7 @@
this.nestedList,
this.mapWithAnnotations,
this.mapWithObject,
+ this.anEnum,
});
bool? aBool;
@@ -41,6 +48,7 @@
List<List<bool?>?>? nestedList;
Map<String?, String?>? mapWithAnnotations;
Map<String?, Object?>? mapWithObject;
+ AnEnum? anEnum;
Object encode() {
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
@@ -57,6 +65,7 @@
pigeonMap['nestedList'] = nestedList;
pigeonMap['mapWithAnnotations'] = mapWithAnnotations;
pigeonMap['mapWithObject'] = mapWithObject;
+ pigeonMap['anEnum'] = anEnum?.index;
return pigeonMap;
}
@@ -80,6 +89,9 @@
?.cast<String?, String?>(),
mapWithObject: (pigeonMap['mapWithObject'] as Map<Object?, Object?>?)
?.cast<String?, Object?>(),
+ anEnum: pigeonMap['anEnum'] != null
+ ? AnEnum.values[pigeonMap['anEnum']! as int]
+ : null,
);
}
}
@@ -347,7 +359,37 @@
}
}
- /// Returns the passed in boolean asynchronously.
+ /// Returns passed in double.
+ Future<double> echoDouble(double arg_aDouble) async {
+ final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
+ 'dev.flutter.pigeon.HostIntegrationCoreApi.echoDouble', codec,
+ binaryMessenger: _binaryMessenger);
+ final Map<Object?, Object?>? replyMap =
+ await channel.send(<Object?>[arg_aDouble]) as Map<Object?, Object?>?;
+ if (replyMap == null) {
+ throw PlatformException(
+ code: 'channel-error',
+ message: 'Unable to establish connection on channel.',
+ );
+ } else if (replyMap['error'] != null) {
+ final Map<Object?, Object?> error =
+ (replyMap['error'] as Map<Object?, Object?>?)!;
+ throw PlatformException(
+ code: (error['code'] as String?)!,
+ message: error['message'] as String?,
+ details: error['details'],
+ );
+ } else if (replyMap['result'] == null) {
+ throw PlatformException(
+ code: 'null-error',
+ message: 'Host platform returned null value for non-null return value.',
+ );
+ } else {
+ return (replyMap['result'] as double?)!;
+ }
+ }
+
+ /// Returns the passed in boolean.
Future<bool> echoBool(bool arg_aBool) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.HostIntegrationCoreApi.echoBool', codec,
@@ -377,6 +419,66 @@
}
}
+ /// Returns the passed in string.
+ Future<String> echoString(String arg_aString) async {
+ final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
+ 'dev.flutter.pigeon.HostIntegrationCoreApi.echoString', codec,
+ binaryMessenger: _binaryMessenger);
+ final Map<Object?, Object?>? replyMap =
+ await channel.send(<Object?>[arg_aString]) as Map<Object?, Object?>?;
+ if (replyMap == null) {
+ throw PlatformException(
+ code: 'channel-error',
+ message: 'Unable to establish connection on channel.',
+ );
+ } else if (replyMap['error'] != null) {
+ final Map<Object?, Object?> error =
+ (replyMap['error'] as Map<Object?, Object?>?)!;
+ throw PlatformException(
+ code: (error['code'] as String?)!,
+ message: error['message'] as String?,
+ details: error['details'],
+ );
+ } else if (replyMap['result'] == null) {
+ throw PlatformException(
+ code: 'null-error',
+ message: 'Host platform returned null value for non-null return value.',
+ );
+ } else {
+ return (replyMap['result'] as String?)!;
+ }
+ }
+
+ /// Returns the passed in Uint8List.
+ Future<Uint8List> echoUint8List(Uint8List arg_aUint8List) async {
+ final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
+ 'dev.flutter.pigeon.HostIntegrationCoreApi.echoUint8List', codec,
+ binaryMessenger: _binaryMessenger);
+ final Map<Object?, Object?>? replyMap =
+ await channel.send(<Object?>[arg_aUint8List]) as Map<Object?, Object?>?;
+ if (replyMap == null) {
+ throw PlatformException(
+ code: 'channel-error',
+ message: 'Unable to establish connection on channel.',
+ );
+ } else if (replyMap['error'] != null) {
+ final Map<Object?, Object?> error =
+ (replyMap['error'] as Map<Object?, Object?>?)!;
+ throw PlatformException(
+ code: (error['code'] as String?)!,
+ message: error['message'] as String?,
+ details: error['details'],
+ );
+ } else if (replyMap['result'] == null) {
+ throw PlatformException(
+ code: 'null-error',
+ message: 'Host platform returned null value for non-null return value.',
+ );
+ } else {
+ return (replyMap['result'] as Uint8List?)!;
+ }
+ }
+
/// A no-op function taking no arguments and returning no value, to sanity
/// test basic asynchronous calling.
Future<void> noopAsync() async {
diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart
index fcd2e61..4e68c3a 100644
--- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart
+++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart
@@ -61,6 +61,7 @@
<bool>[true, false],
<bool>[false, true]
],
+ anEnum: AnEnum.two,
);
final AllTypes echoObject = await api.echoAllTypes(sentObject);
@@ -90,6 +91,7 @@
true);
expect(
mapEquals(echoObject.mapWithObject, sentObject.mapWithObject), true);
+ expect(echoObject.anEnum, sentObject.anEnum);
});
testWidgets('errors are returned correctly', (WidgetTester _) async {
@@ -143,9 +145,18 @@
(WidgetTester _) async {
final HostIntegrationCoreApi api = HostIntegrationCoreApi();
- const int inInt = -13;
- final int anInt = await api.echoInt(inInt);
- expect(anInt, inInt);
+ const int sentInt = -13;
+ final int receivedInt = await api.echoInt(sentInt);
+ expect(receivedInt, sentInt);
+ });
+
+ testWidgets('Doubles serialize and deserialize correctly',
+ (WidgetTester _) async {
+ final HostIntegrationCoreApi api = HostIntegrationCoreApi();
+
+ const double sentDouble = 2.0694;
+ final double receivedDouble = await api.echoDouble(sentDouble);
+ expect(receivedDouble, sentDouble);
});
testWidgets('booleans serialize and deserialize correctly',
@@ -157,6 +168,28 @@
expect(receivedBool, sentBool);
}
});
+
+ testWidgets('strings serialize and deserialize correctly',
+ (WidgetTester _) async {
+ final HostIntegrationCoreApi api = HostIntegrationCoreApi();
+ const String sentString = "I'm a computer";
+ final String receivedString = await api.echoString(sentString);
+ expect(receivedString, sentString);
+ });
+
+ // TODO(stuartmorgan): Enable these once they work for all generators;
+ // currently at least Swift is broken.
+ // TODO(tarrinneal): Finish tests for int lists once issue solved.
+ // See https://github.com/flutter/flutter/issues/115906
+ // testWidgets('Uint8List serialize and deserialize correctly',
+ // (WidgetTester _) async {
+ // final HostIntegrationCoreApi api = HostIntegrationCoreApi();
+ // final List<int> data = [102, 111, 114, 116, 121, 45, 116, 119, 111, 0];
+ // final Uint8List sentUint8List = Uint8List.fromList(data);
+ // final Uint8List receivedUint8List =
+ // await api.echoUint8List(sentUint8List);
+ // expect(receivedUint8List, sentUint8List);
+ // });
});
group('Host async API tests', () {
diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart
index 7f7a4d3..b701c66 100644
--- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart
+++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart
@@ -11,6 +11,12 @@
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;
import 'package:flutter/services.dart';
+enum AnEnum {
+ one,
+ two,
+ three,
+}
+
class AllTypes {
AllTypes({
this.aBool,
@@ -26,6 +32,7 @@
this.nestedList,
this.mapWithAnnotations,
this.mapWithObject,
+ this.anEnum,
});
bool? aBool;
@@ -41,6 +48,7 @@
List<List<bool?>?>? nestedList;
Map<String?, String?>? mapWithAnnotations;
Map<String?, Object?>? mapWithObject;
+ AnEnum? anEnum;
Object encode() {
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
@@ -57,6 +65,7 @@
pigeonMap['nestedList'] = nestedList;
pigeonMap['mapWithAnnotations'] = mapWithAnnotations;
pigeonMap['mapWithObject'] = mapWithObject;
+ pigeonMap['anEnum'] = anEnum?.index;
return pigeonMap;
}
@@ -80,6 +89,9 @@
?.cast<String?, String?>(),
mapWithObject: (pigeonMap['mapWithObject'] as Map<Object?, Object?>?)
?.cast<String?, Object?>(),
+ anEnum: pigeonMap['anEnum'] != null
+ ? AnEnum.values[pigeonMap['anEnum']! as int]
+ : null,
);
}
}
@@ -347,7 +359,37 @@
}
}
- /// Returns the passed in boolean asynchronously.
+ /// Returns passed in double.
+ Future<double> echoDouble(double arg_aDouble) async {
+ final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
+ 'dev.flutter.pigeon.HostIntegrationCoreApi.echoDouble', codec,
+ binaryMessenger: _binaryMessenger);
+ final Map<Object?, Object?>? replyMap =
+ await channel.send(<Object?>[arg_aDouble]) as Map<Object?, Object?>?;
+ if (replyMap == null) {
+ throw PlatformException(
+ code: 'channel-error',
+ message: 'Unable to establish connection on channel.',
+ );
+ } else if (replyMap['error'] != null) {
+ final Map<Object?, Object?> error =
+ (replyMap['error'] as Map<Object?, Object?>?)!;
+ throw PlatformException(
+ code: (error['code'] as String?)!,
+ message: error['message'] as String?,
+ details: error['details'],
+ );
+ } else if (replyMap['result'] == null) {
+ throw PlatformException(
+ code: 'null-error',
+ message: 'Host platform returned null value for non-null return value.',
+ );
+ } else {
+ return (replyMap['result'] as double?)!;
+ }
+ }
+
+ /// Returns the passed in boolean.
Future<bool> echoBool(bool arg_aBool) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.HostIntegrationCoreApi.echoBool', codec,
@@ -377,6 +419,66 @@
}
}
+ /// Returns the passed in string.
+ Future<String> echoString(String arg_aString) async {
+ final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
+ 'dev.flutter.pigeon.HostIntegrationCoreApi.echoString', codec,
+ binaryMessenger: _binaryMessenger);
+ final Map<Object?, Object?>? replyMap =
+ await channel.send(<Object?>[arg_aString]) as Map<Object?, Object?>?;
+ if (replyMap == null) {
+ throw PlatformException(
+ code: 'channel-error',
+ message: 'Unable to establish connection on channel.',
+ );
+ } else if (replyMap['error'] != null) {
+ final Map<Object?, Object?> error =
+ (replyMap['error'] as Map<Object?, Object?>?)!;
+ throw PlatformException(
+ code: (error['code'] as String?)!,
+ message: error['message'] as String?,
+ details: error['details'],
+ );
+ } else if (replyMap['result'] == null) {
+ throw PlatformException(
+ code: 'null-error',
+ message: 'Host platform returned null value for non-null return value.',
+ );
+ } else {
+ return (replyMap['result'] as String?)!;
+ }
+ }
+
+ /// Returns the passed in Uint8List.
+ Future<Uint8List> echoUint8List(Uint8List arg_aUint8List) async {
+ final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
+ 'dev.flutter.pigeon.HostIntegrationCoreApi.echoUint8List', codec,
+ binaryMessenger: _binaryMessenger);
+ final Map<Object?, Object?>? replyMap =
+ await channel.send(<Object?>[arg_aUint8List]) as Map<Object?, Object?>?;
+ if (replyMap == null) {
+ throw PlatformException(
+ code: 'channel-error',
+ message: 'Unable to establish connection on channel.',
+ );
+ } else if (replyMap['error'] != null) {
+ final Map<Object?, Object?> error =
+ (replyMap['error'] as Map<Object?, Object?>?)!;
+ throw PlatformException(
+ code: (error['code'] as String?)!,
+ message: error['message'] as String?,
+ details: error['details'],
+ );
+ } else if (replyMap['result'] == null) {
+ throw PlatformException(
+ code: 'null-error',
+ message: 'Host platform returned null value for non-null return value.',
+ );
+ } else {
+ return (replyMap['result'] as Uint8List?)!;
+ }
+ }
+
/// A no-op function taking no arguments and returning no value, to sanity
/// test basic asynchronous calling.
Future<void> noopAsync() async {
diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt
index 73d9a71..2b8843b 100644
--- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt
+++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt
@@ -57,10 +57,22 @@
return anInt
}
+ override fun echoDouble(aDouble: Double): Double {
+ return aDouble
+ }
+
override fun echoBool(aBool: Boolean): Boolean {
return aBool
}
+ override fun echoString(aString: String): String {
+ return aString
+ }
+
+ override fun echoUint8List(aUint8List: ByteArray): ByteArray {
+ return aUint8List
+ }
+
override fun noopAsync(callback: () -> Unit) {
callback()
}
diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift
index 441d980..b27bbb2 100644
--- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift
+++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift
@@ -52,10 +52,22 @@
return anInt
}
+ func echoDouble(aDouble: Double) -> Double {
+ return aDouble
+ }
+
func echoBool(aBool: Bool) -> Bool {
return aBool
}
+ func echoString(aString: String) -> String {
+ return aString
+ }
+
+ func echoUint8List(aUint8List: [UInt8]) -> [UInt8] {
+ return aUint8List
+ }
+
func noopAsync(completion: @escaping () -> Void) {
completion()
}
diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift
index 2b22866..be3d518 100644
--- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift
+++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift
@@ -52,10 +52,22 @@
return anInt
}
+ func echoDouble(aDouble: Double) -> Double {
+ return aDouble
+ }
+
func echoBool(aBool: Bool) -> Bool {
return aBool
}
+ func echoString(aString: String) -> String {
+ return aString
+ }
+
+ func echoUint8List(aUint8List: [UInt8]) -> [UInt8] {
+ return aUint8List
+ }
+
func noopAsync(completion: @escaping () -> Void) {
completion()
}
diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp
index e6a4221..6e1a25c 100644
--- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp
+++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp
@@ -76,8 +76,18 @@
ErrorOr<int64_t> TestPlugin::EchoInt(int64_t an_int) { return an_int; }
+ErrorOr<double> TestPlugin::EchoDouble(double a_double) { return a_double; }
+
ErrorOr<bool> TestPlugin::EchoBool(bool a_bool) { return a_bool; }
+ErrorOr<std::string> TestPlugin::EchoString(const std::string& a_string) {
+ return a_string;
+}
+
+ErrorOr<std::vector<uint8_t>> TestPlugin::EchoUint8List(
+ const std::vector<uint8_t>& a_uint8_list) {
+ return a_uint8_list;
+}
void TestPlugin::NoopAsync(
std::function<void(std::optional<FlutterError> reply)> result) {
result(std::nullopt);
diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h
index 4c4bfac..20b6d50 100644
--- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h
+++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h
@@ -45,7 +45,12 @@
SendMultipleTypes(bool a_bool, int64_t an_int,
const std::string& a_string) override;
core_tests_pigeontest::ErrorOr<int64_t> EchoInt(int64_t an_int) override;
+ core_tests_pigeontest::ErrorOr<double> EchoDouble(double a_double) override;
core_tests_pigeontest::ErrorOr<bool> EchoBool(bool a_bool) override;
+ core_tests_pigeontest::ErrorOr<std::string> EchoString(
+ const std::string& a_string) override;
+ core_tests_pigeontest::ErrorOr<std::vector<uint8_t>> EchoUint8List(
+ const std::vector<uint8_t>& a_uint8_list) override;
void NoopAsync(std::function<
void(std::optional<core_tests_pigeontest::FlutterError> reply)>
result) override;