diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index dd3be1d2c4..890e7d6e98 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -187,16 +187,76 @@ abstract class HostIntegrationCoreApi { @async void callFlutterNoop(); + @async + @ObjCSelector('callFlutterEchoAllTypes:') + AllTypes callFlutterEchoAllTypes(AllTypes everything); + + // TODO(stuartmorgan): Add callFlutterEchoAllNullableTypes and the associated + // test once either https://github.com/flutter/flutter/issues/116117 is fixed, + // or the problematic type is moved out of AllNullableTypes and into its own + // test, since the type mismatch breaks the second `encode` round. + + @async + @ObjCSelector('callFlutterSendMultipleNullableTypesABool:anInt:aString:') + AllNullableTypes callFlutterSendMultipleNullableTypes( + bool? aNullableBool, int? aNullableInt, String? aNullableString); + + @async + @ObjCSelector('callFlutterEchoBool:') + bool callFlutterEchoBool(bool aBool); + + @async + @ObjCSelector('callFlutterEchoInt:') + int callFlutterEchoInt(int anInt); + + @async + @ObjCSelector('callFlutterEchoDouble:') + double callFlutterEchoDouble(double aDouble); + @async @ObjCSelector('callFlutterEchoString:') String callFlutterEchoString(String aString); - // TODO(stuartmorgan): Add callFlutterEchoAllTypes and the associated test - // once either https://github.com/flutter/flutter/issues/116117 is fixed, or - // the problematic type is moved out of AllTypes and into its own test, since - // the type mismatch breaks the second `encode` round. + @async + @ObjCSelector('callFlutterEchoUint8List:') + Uint8List callFlutterEchoUint8List(Uint8List aList); - // TODO(stuartmorgan): Fill in the rest of the callFlutterEcho* tests. + @async + @ObjCSelector('callFlutterEchoList:') + List callFlutterEchoList(List aList); + + @async + @ObjCSelector('callFlutterEchoMap:') + Map callFlutterEchoMap(Map aMap); + + @async + @ObjCSelector('callFlutterEchoNullableBool:') + bool? callFlutterEchoNullableBool(bool? aBool); + + @async + @ObjCSelector('callFlutterEchoNullableInt:') + int? callFlutterEchoNullableInt(int? anInt); + + @async + @ObjCSelector('callFlutterEchoNullableDouble:') + double? callFlutterEchoNullableDouble(double? aDouble); + + @async + @ObjCSelector('callFlutterEchoNullableString:') + String? callFlutterEchoNullableString(String? aString); + + @async + @ObjCSelector('callFlutterEchoNullableUint8List:') + Uint8List? callFlutterEchoNullableUint8List(Uint8List? aList); + + @async + @ObjCSelector('callFlutterEchoNullableList:') + List? callFlutterEchoNullableList(List? aList); + + @async + @ObjCSelector('callFlutterEchoNullableMap:') + Map? callFlutterEchoNullableMap( + Map? aMap); } /// The core interface that the Dart platform_test code implements for host @@ -280,7 +340,7 @@ abstract class FlutterIntegrationCoreApi { /// Returns the passed map, to test serialization and deserialization. @ObjCSelector('echoNullableMap:') - Map echoNullableMap(Map aMap); + Map? echoNullableMap(Map? aMap); } /// An API that can be implemented for minimal, compile-only tests. 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 f0b19118a9..8adeaba6a5 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 @@ -13,6 +13,8 @@ import com.example.alternate_language_test_plugin.CoreTests.FlutterIntegrationCo import com.example.alternate_language_test_plugin.CoreTests.HostIntegrationCoreApi; import com.example.alternate_language_test_plugin.CoreTests.Result; import io.flutter.embedding.engine.plugins.FlutterPlugin; +import java.util.List; +import java.util.Map; /** This plugin handles the native side of the integration tests in example/integration_test/. */ public class AlternateLanguageTestPlugin implements FlutterPlugin, HostIntegrationCoreApi { @@ -154,6 +156,67 @@ public class AlternateLanguageTestPlugin implements FlutterPlugin, HostIntegrati }); } + @Override + public void callFlutterEchoAllTypes(@NonNull AllTypes everything, Result result) { + flutterApi.echoAllTypes( + everything, + new FlutterIntegrationCoreApi.Reply() { + public void reply(AllTypes value) { + result.success(value); + } + }); + } + + @Override + public void callFlutterSendMultipleNullableTypes( + @Nullable Boolean aNullableBool, + @Nullable Long aNullableInt, + @Nullable String aNullableString, + Result result) { + flutterApi.sendMultipleNullableTypes( + aNullableBool, + aNullableInt, + aNullableString, + new FlutterIntegrationCoreApi.Reply() { + public void reply(AllNullableTypes value) { + result.success(value); + } + }); + } + + @Override + public void callFlutterEchoBool(@NonNull Boolean aBool, Result result) { + flutterApi.echoBool( + aBool, + new FlutterIntegrationCoreApi.Reply() { + public void reply(Boolean value) { + result.success(value); + } + }); + } + + @Override + public void callFlutterEchoInt(@NonNull Long anInt, Result result) { + flutterApi.echoInt( + anInt, + new FlutterIntegrationCoreApi.Reply() { + public void reply(Long value) { + result.success(value); + } + }); + } + + @Override + public void callFlutterEchoDouble(@NonNull Double aDouble, Result result) { + flutterApi.echoDouble( + aDouble, + new FlutterIntegrationCoreApi.Reply() { + public void reply(Double value) { + result.success(value); + } + }); + } + @Override public void callFlutterEchoString(@NonNull String aString, Result result) { flutterApi.echoString( @@ -164,4 +227,117 @@ public class AlternateLanguageTestPlugin implements FlutterPlugin, HostIntegrati } }); } + + @Override + public void callFlutterEchoUint8List(@NonNull byte[] aList, Result result) { + flutterApi.echoUint8List( + aList, + new FlutterIntegrationCoreApi.Reply() { + public void reply(byte[] value) { + result.success(value); + } + }); + } + + @Override + public void callFlutterEchoList(@NonNull List aList, Result> result) { + flutterApi.echoList( + aList, + new FlutterIntegrationCoreApi.Reply>() { + public void reply(List value) { + result.success(value); + } + }); + } + + @Override + public void callFlutterEchoMap( + @NonNull Map aMap, Result> result) { + flutterApi.echoMap( + aMap, + new FlutterIntegrationCoreApi.Reply>() { + public void reply(Map value) { + result.success(value); + } + }); + } + + @Override + public void callFlutterEchoNullableBool(@Nullable Boolean aBool, Result result) { + flutterApi.echoNullableBool( + aBool, + new FlutterIntegrationCoreApi.Reply() { + public void reply(Boolean value) { + result.success(value); + } + }); + } + + @Override + public void callFlutterEchoNullableInt(@Nullable Long anInt, Result result) { + flutterApi.echoNullableInt( + anInt, + new FlutterIntegrationCoreApi.Reply() { + public void reply(Long value) { + result.success(value); + } + }); + } + + @Override + public void callFlutterEchoNullableDouble(@Nullable Double aDouble, Result result) { + flutterApi.echoNullableDouble( + aDouble, + new FlutterIntegrationCoreApi.Reply() { + public void reply(Double value) { + result.success(value); + } + }); + } + + @Override + public void callFlutterEchoNullableString(@Nullable String aString, Result result) { + flutterApi.echoNullableString( + aString, + new FlutterIntegrationCoreApi.Reply() { + public void reply(String value) { + result.success(value); + } + }); + } + + @Override + public void callFlutterEchoNullableUint8List(@Nullable byte[] aList, Result result) { + flutterApi.echoNullableUint8List( + aList, + new FlutterIntegrationCoreApi.Reply() { + public void reply(byte[] value) { + result.success(value); + } + }); + } + + @Override + public void callFlutterEchoNullableList( + @Nullable List aList, Result> result) { + flutterApi.echoNullableList( + aList, + new FlutterIntegrationCoreApi.Reply>() { + public void reply(List value) { + result.success(value); + } + }); + } + + @Override + public void callFlutterEchoNullableMap( + @Nullable Map aMap, Result> result) { + flutterApi.echoNullableMap( + aMap, + new FlutterIntegrationCoreApi.Reply>() { + public void reply(Map value) { + result.success(value); + } + }); + } } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java index 9c0ef122a4..487a2b650e 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java @@ -831,8 +831,43 @@ public class CoreTests { void callFlutterNoop(Result result); + void callFlutterEchoAllTypes(@NonNull AllTypes everything, Result result); + + void callFlutterSendMultipleNullableTypes( + @Nullable Boolean aNullableBool, + @Nullable Long aNullableInt, + @Nullable String aNullableString, + Result result); + + void callFlutterEchoBool(@NonNull Boolean aBool, Result result); + + void callFlutterEchoInt(@NonNull Long anInt, Result result); + + void callFlutterEchoDouble(@NonNull Double aDouble, Result result); + void callFlutterEchoString(@NonNull String aString, Result result); + void callFlutterEchoUint8List(@NonNull byte[] aList, Result result); + + void callFlutterEchoList(@NonNull List aList, Result> result); + + void callFlutterEchoMap(@NonNull Map aMap, Result> result); + + void callFlutterEchoNullableBool(@Nullable Boolean aBool, Result result); + + void callFlutterEchoNullableInt(@Nullable Long anInt, Result result); + + void callFlutterEchoNullableDouble(@Nullable Double aDouble, Result result); + + void callFlutterEchoNullableString(@Nullable String aString, Result result); + + void callFlutterEchoNullableUint8List(@Nullable byte[] aList, Result result); + + void callFlutterEchoNullableList(@Nullable List aList, Result> result); + + void callFlutterEchoNullableMap( + @Nullable Map aMap, Result> result); + /** The codec used by HostIntegrationCoreApi. */ static MessageCodec getCodec() { return HostIntegrationCoreApiCodec.INSTANCE; @@ -1463,6 +1498,210 @@ public class CoreTests { channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoAllTypes", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + AllTypes everythingArg = (AllTypes) args.get(0); + if (everythingArg == null) { + throw new NullPointerException("everythingArg unexpectedly null."); + } + Result resultCallback = + new Result() { + public void success(AllTypes result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoAllTypes(everythingArg, resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + Boolean aNullableBoolArg = (Boolean) args.get(0); + Number aNullableIntArg = (Number) args.get(1); + String aNullableStringArg = (String) args.get(2); + Result resultCallback = + new Result() { + public void success(AllNullableTypes result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterSendMultipleNullableTypes( + aNullableBoolArg, + (aNullableIntArg == null) ? null : aNullableIntArg.longValue(), + aNullableStringArg, + resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoBool", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + Boolean aBoolArg = (Boolean) args.get(0); + if (aBoolArg == null) { + throw new NullPointerException("aBoolArg unexpectedly null."); + } + Result resultCallback = + new Result() { + public void success(Boolean result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoBool(aBoolArg, resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoInt", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + Number anIntArg = (Number) args.get(0); + if (anIntArg == null) { + throw new NullPointerException("anIntArg unexpectedly null."); + } + Result resultCallback = + new Result() { + public void success(Long result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoInt( + (anIntArg == null) ? null : anIntArg.longValue(), resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoDouble", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + Double aDoubleArg = (Double) args.get(0); + if (aDoubleArg == null) { + throw new NullPointerException("aDoubleArg unexpectedly null."); + } + Result resultCallback = + new Result() { + public void success(Double result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoDouble(aDoubleArg, resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -1503,6 +1742,386 @@ public class CoreTests { channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoUint8List", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + byte[] aListArg = (byte[]) args.get(0); + if (aListArg == null) { + throw new NullPointerException("aListArg unexpectedly null."); + } + Result resultCallback = + new Result() { + public void success(byte[] result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoUint8List(aListArg, resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoList", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + List aListArg = (List) args.get(0); + if (aListArg == null) { + throw new NullPointerException("aListArg unexpectedly null."); + } + Result> resultCallback = + new Result>() { + public void success(List result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoList(aListArg, resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoMap", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + Map aMapArg = (Map) args.get(0); + if (aMapArg == null) { + throw new NullPointerException("aMapArg unexpectedly null."); + } + Result> resultCallback = + new Result>() { + public void success(Map result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoMap(aMapArg, resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableBool", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + Boolean aBoolArg = (Boolean) args.get(0); + Result resultCallback = + new Result() { + public void success(Boolean result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoNullableBool(aBoolArg, resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableInt", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + Number anIntArg = (Number) args.get(0); + Result resultCallback = + new Result() { + public void success(Long result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoNullableInt( + (anIntArg == null) ? null : anIntArg.longValue(), resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableDouble", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + Double aDoubleArg = (Double) args.get(0); + Result resultCallback = + new Result() { + public void success(Double result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoNullableDouble(aDoubleArg, resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableString", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + String aStringArg = (String) args.get(0); + Result resultCallback = + new Result() { + public void success(String result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoNullableString(aStringArg, resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableUint8List", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + byte[] aListArg = (byte[]) args.get(0); + Result resultCallback = + new Result() { + public void success(byte[] result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoNullableUint8List(aListArg, resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableList", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + List aListArg = (List) args.get(0); + Result> resultCallback = + new Result>() { + public void success(List result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoNullableList(aListArg, resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableMap", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + Map aMapArg = (Map) args.get(0); + Result> resultCallback = + new Result>() { + public void success(Map result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.callFlutterEchoNullableMap(aMapArg, resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } } } @@ -1823,7 +2442,7 @@ public class CoreTests { } /** Returns the passed map, to test serialization and deserialization. */ public void echoNullableMap( - @NonNull Map aMapArg, Reply> callback) { + @Nullable Map aMapArg, Reply> callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, 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 e81590f1c7..22cfcc1f18 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 @@ -138,6 +138,51 @@ }]; } +- (void)callFlutterEchoAllTypes:(AllTypes *)everything + completion:(void (^)(AllTypes *_Nullable, FlutterError *_Nullable))completion { + [self.flutterAPI echoAllTypes:everything + completion:^(AllTypes *value, NSError *error) { + completion(value, error); + }]; +} + +- (void)callFlutterSendMultipleNullableTypesABool:(nullable NSNumber *)aNullableBool + anInt:(nullable NSNumber *)aNullableInt + aString:(nullable NSString *)aNullableString + completion:(void (^)(AllNullableTypes *_Nullable, + FlutterError *_Nullable))completion { + [self.flutterAPI sendMultipleNullableTypesABool:aNullableBool + anInt:aNullableInt + aString:aNullableString + completion:^(AllNullableTypes *value, NSError *error) { + completion(value, error); + }]; +} + +- (void)callFlutterEchoBool:(NSNumber *)aBool + completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { + [self.flutterAPI echoBool:aBool + completion:^(NSNumber *value, NSError *error) { + completion(value, error); + }]; +} + +- (void)callFlutterEchoInt:(NSNumber *)anInt + completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { + [self.flutterAPI echoInt:anInt + completion:^(NSNumber *value, NSError *error) { + completion(value, error); + }]; +} + +- (void)callFlutterEchoDouble:(NSNumber *)aDouble + completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { + [self.flutterAPI echoDouble:aDouble + completion:^(NSNumber *value, NSError *error) { + completion(value, error); + }]; +} + - (void)callFlutterEchoString:(NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion { [self.flutterAPI echoString:aString @@ -146,4 +191,93 @@ }]; } +- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)aList + completion:(void (^)(FlutterStandardTypedData *_Nullable, + FlutterError *_Nullable))completion { + [self.flutterAPI echoUint8List:aList + completion:^(FlutterStandardTypedData *value, NSError *error) { + completion(value, error); + }]; +} + +- (void)callFlutterEchoList:(NSArray *)aList + completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { + [self.flutterAPI echoList:aList + completion:^(NSArray *value, NSError *error) { + completion(value, error); + }]; +} + +- (void)callFlutterEchoMap:(NSDictionary *)aMap + completion:(void (^)(NSDictionary *_Nullable, + FlutterError *_Nullable))completion { + [self.flutterAPI echoMap:aMap + completion:^(NSDictionary *value, NSError *error) { + completion(value, error); + }]; +} + +- (void)callFlutterEchoNullableBool:(nullable NSNumber *)aBool + completion: + (void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { + [self.flutterAPI echoNullableBool:aBool + completion:^(NSNumber *value, NSError *error) { + completion(value, error); + }]; +} + +- (void)callFlutterEchoNullableInt:(nullable NSNumber *)anInt + completion: + (void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { + [self.flutterAPI echoNullableInt:anInt + completion:^(NSNumber *value, NSError *error) { + completion(value, error); + }]; +} + +- (void)callFlutterEchoNullableDouble:(nullable NSNumber *)aDouble + completion: + (void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { + [self.flutterAPI echoNullableDouble:aDouble + completion:^(NSNumber *value, NSError *error) { + completion(value, error); + }]; +} + +- (void)callFlutterEchoNullableString:(nullable NSString *)aString + completion: + (void (^)(NSString *_Nullable, FlutterError *_Nullable))completion { + [self.flutterAPI echoNullableString:aString + completion:^(NSString *value, NSError *error) { + completion(value, error); + }]; +} + +- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)aList + completion:(void (^)(FlutterStandardTypedData *_Nullable, + FlutterError *_Nullable))completion { + [self.flutterAPI echoNullableUint8List:aList + completion:^(FlutterStandardTypedData *value, NSError *error) { + completion(value, error); + }]; +} + +- (void)callFlutterEchoNullableList:(nullable NSArray *)aList + completion: + (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { + [self.flutterAPI echoNullableList:aList + completion:^(NSArray *value, NSError *error) { + completion(value, error); + }]; +} + +- (void)callFlutterEchoNullableMap:(nullable NSDictionary *)aMap + completion:(void (^)(NSDictionary *_Nullable, + FlutterError *_Nullable))completion { + [self.flutterAPI echoNullableMap:aMap + completion:^(NSDictionary *value, NSError *error) { + completion(value, error); + }]; +} + @end diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h index 84b7e3c895..2dee9bc496 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h @@ -182,8 +182,50 @@ NSObject *HostIntegrationCoreApiGetCodec(void); - (void)echoAsyncString:(NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterNoopWithCompletion:(void (^)(FlutterError *_Nullable))completion; +- (void)callFlutterEchoAllTypes:(AllTypes *)everything + completion:(void (^)(AllTypes *_Nullable, FlutterError *_Nullable))completion; +- (void)callFlutterSendMultipleNullableTypesABool:(nullable NSNumber *)aNullableBool + anInt:(nullable NSNumber *)aNullableInt + aString:(nullable NSString *)aNullableString + completion:(void (^)(AllNullableTypes *_Nullable, + FlutterError *_Nullable))completion; +- (void)callFlutterEchoBool:(NSNumber *)aBool + completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion; +- (void)callFlutterEchoInt:(NSNumber *)anInt + completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion; +- (void)callFlutterEchoDouble:(NSNumber *)aDouble + completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterEchoString:(NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; +- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)aList + completion:(void (^)(FlutterStandardTypedData *_Nullable, + FlutterError *_Nullable))completion; +- (void)callFlutterEchoList:(NSArray *)aList + completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; +- (void)callFlutterEchoMap:(NSDictionary *)aMap + completion:(void (^)(NSDictionary *_Nullable, + FlutterError *_Nullable))completion; +- (void)callFlutterEchoNullableBool:(nullable NSNumber *)aBool + completion: + (void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion; +- (void)callFlutterEchoNullableInt:(nullable NSNumber *)anInt + completion: + (void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion; +- (void)callFlutterEchoNullableDouble:(nullable NSNumber *)aDouble + completion: + (void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion; +- (void)callFlutterEchoNullableString:(nullable NSString *)aString + completion: + (void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; +- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)aList + completion:(void (^)(FlutterStandardTypedData *_Nullable, + FlutterError *_Nullable))completion; +- (void)callFlutterEchoNullableList:(nullable NSArray *)aList + completion: + (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; +- (void)callFlutterEchoNullableMap:(nullable NSDictionary *)aMap + completion:(void (^)(NSDictionary *_Nullable, + FlutterError *_Nullable))completion; @end extern void HostIntegrationCoreApiSetup(id binaryMessenger, @@ -254,7 +296,7 @@ NSObject *FlutterIntegrationCoreApiGetCodec(void); - (void)echoNullableList:(nullable NSArray *)aList completion:(void (^)(NSArray *_Nullable, NSError *_Nullable))completion; /// Returns the passed map, to test serialization and deserialization. -- (void)echoNullableMap:(NSDictionary *)aMap +- (void)echoNullableMap:(nullable NSDictionary *)aMap completion: (void (^)(NSDictionary *_Nullable, NSError *_Nullable))completion; @end diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m index e7e136eb6a..4b285ad3d3 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m @@ -759,6 +759,123 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, [channel setMessageHandler:nil]; } } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoAllTypes" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoAllTypes:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoAllTypes:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + AllTypes *arg_everything = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoAllTypes:arg_everything + completion:^(AllTypes *_Nullable output, FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName: + @"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector + (callFlutterSendMultipleNullableTypesABool:anInt:aString:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterSendMultipleNullableTypesABool:anInt:aString:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSNumber *arg_aNullableBool = GetNullableObjectAtIndex(args, 0); + NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 1); + NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 2); + [api callFlutterSendMultipleNullableTypesABool:arg_aNullableBool + anInt:arg_aNullableInt + aString:arg_aNullableString + completion:^(AllNullableTypes *_Nullable output, + FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoBool" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoBool:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoBool:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSNumber *arg_aBool = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoBool:arg_aBool + completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoInt" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoInt:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoInt:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSNumber *arg_anInt = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoInt:arg_anInt + completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoDouble" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoDouble:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoDouble:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSNumber *arg_aDouble = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoDouble:arg_aDouble + completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString" @@ -781,6 +898,236 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, [channel setMessageHandler:nil]; } } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoUint8List" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoUint8List:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoUint8List:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + FlutterStandardTypedData *arg_aList = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoUint8List:arg_aList + completion:^(FlutterStandardTypedData *_Nullable output, + FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoList" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoList:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoList:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoList:arg_aList + completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoMap" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoMap:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoMap:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSDictionary *arg_aMap = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoMap:arg_aMap + completion:^(NSDictionary *_Nullable output, + FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableBool" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableBool:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoNullableBool:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSNumber *arg_aBool = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableBool:arg_aBool + completion:^(NSNumber *_Nullable output, + FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableInt" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableInt:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoNullableInt:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSNumber *arg_anInt = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableInt:arg_anInt + completion:^(NSNumber *_Nullable output, + FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableDouble" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableDouble:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoNullableDouble:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSNumber *arg_aDouble = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableDouble:arg_aDouble + completion:^(NSNumber *_Nullable output, + FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableString" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableString:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoNullableString:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSString *arg_aString = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableString:arg_aString + completion:^(NSString *_Nullable output, + FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName: + @"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableUint8List" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableUint8List:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoNullableUint8List:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + FlutterStandardTypedData *arg_aList = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableUint8List:arg_aList + completion:^(FlutterStandardTypedData *_Nullable output, + FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableList" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableList:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoNullableList:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableList:arg_aList + completion:^(NSArray *_Nullable output, + FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableMap" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableMap:completion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(callFlutterEchoNullableMap:completion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSDictionary *arg_aMap = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableMap:arg_aMap + completion:^(NSDictionary *_Nullable output, + FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } } @interface FlutterIntegrationCoreApiCodecReader : FlutterStandardReader @end @@ -1067,7 +1414,7 @@ NSObject *FlutterIntegrationCoreApiGetCodec() { completion(output, nil); }]; } -- (void)echoNullableMap:(NSDictionary *)arg_aMap +- (void)echoNullableMap:(nullable NSDictionary *)arg_aMap completion: (void (^)(NSDictionary *_Nullable, NSError *_Nullable))completion { FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel 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 a47622b3c5..93fbc21e80 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 @@ -97,21 +97,11 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect(echoObject.aFloatArray, genericAllTypes.aFloatArray); expect(listEquals(echoObject.aList, genericAllTypes.aList), true); expect(mapEquals(echoObject.aMap, genericAllTypes.aMap), true); - // TODO(stuartmorgan): Enable this once the Dart types are fixed; see - // https://github.com/flutter/flutter/issues/116117 - // expect(echoObject.nestedList.length, genericAllTypes.nestedList.length); - //for (int i = 0; i < echoObject.nestedList!.length; i++) { - // expect(listEquals(echoObject.nestedList![i], genericAllTypes.nestedList![i]), - // true); - //} - // expect( - // mapEquals( - // echoObject.mapWithAnnotations, genericAllTypes.mapWithAnnotations), - // true); - // expect( - // mapEquals(echoObject.mapWithObject, genericAllTypes.mapWithObject), true); expect(echoObject.anEnum, genericAllTypes.anEnum); - }); + }, + // TODO(stuartmorgan): Fix and re-enable. + // See https://github.com/flutter/flutter/issues/118726 + skip: targetGenerator == TargetGenerator.kotlin); testWidgets('all nullable datatypes serialize and deserialize correctly', (WidgetTester _) async { @@ -160,7 +150,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect(echoObject?.aNullableEnum, genericAllNullableTypes.aNullableEnum); }); - testWidgets('all nulla datatypes serialize and deserialize correctly', + testWidgets('all null datatypes serialize and deserialize correctly', (WidgetTester _) async { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); @@ -233,7 +223,10 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect(echoNullFilledObject?.aNullableEnum, allTypesNull.aNullableEnum); expect(echoNullFilledObject?.aNullableEnum, null); - }); + }, + // TODO(stuartmorgan): Fix and re-enable. + // See https://github.com/flutter/flutter/issues/118733 + skip: targetGenerator == TargetGenerator.objc); testWidgets('errors are returned correctly', (WidgetTester _) async { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); @@ -518,15 +511,294 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect(api.callFlutterNoop(), completes); }); + testWidgets('all datatypes serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final AllTypes echoObject = + await api.callFlutterEchoAllTypes(genericAllTypes); + + expect(echoObject.aBool, genericAllTypes.aBool); + expect(echoObject.anInt, genericAllTypes.anInt); + expect(echoObject.aDouble, genericAllTypes.aDouble); + expect(echoObject.aString, genericAllTypes.aString); + expect(echoObject.aByteArray, genericAllTypes.aByteArray); + expect(echoObject.a4ByteArray, genericAllTypes.a4ByteArray); + expect(echoObject.a8ByteArray, genericAllTypes.a8ByteArray); + expect(echoObject.aFloatArray, genericAllTypes.aFloatArray); + expect(listEquals(echoObject.aList, genericAllTypes.aList), true); + expect(mapEquals(echoObject.aMap, genericAllTypes.aMap), true); + expect(echoObject.anEnum, genericAllTypes.anEnum); + }, + // TODO(stuartmorgan): Fix and re-enable. + // See https://github.com/flutter/flutter/issues/118726 + skip: targetGenerator == TargetGenerator.kotlin || + // TODO(stuartmorgan): Fix and re-enable. + // See https://github.com/flutter/flutter/issues/118739 + targetGenerator == TargetGenerator.cpp); + + testWidgets( + 'Arguments of multiple types serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + const String aNullableString = 'this is a String'; + const bool aNullableBool = false; + const int aNullableInt = 42; + + final AllNullableTypes compositeObject = + await api.callFlutterSendMultipleNullableTypes( + aNullableBool, aNullableInt, aNullableString); + expect(compositeObject.aNullableInt, aNullableInt); + expect(compositeObject.aNullableBool, aNullableBool); + expect(compositeObject.aNullableString, aNullableString); + }); + + testWidgets( + 'Arguments of multiple null types serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final AllNullableTypes compositeObject = + await api.callFlutterSendMultipleNullableTypes(null, null, null); + expect(compositeObject.aNullableInt, null); + expect(compositeObject.aNullableBool, null); + expect(compositeObject.aNullableString, null); + }); + + testWidgets('booleans serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + for (final bool sentObject in [true, false]) { + final bool echoObject = await api.callFlutterEchoBool(sentObject); + expect(echoObject, sentObject); + } + }); + + testWidgets('ints serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + const int sentObject = -13; + final int echoObject = await api.callFlutterEchoInt(sentObject); + expect(echoObject, sentObject); + }, + // TODO(stuartmorgan): Fix and re-enable. + // See https://github.com/flutter/flutter/issues/118726 + skip: targetGenerator == TargetGenerator.kotlin); + + testWidgets('doubles serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + const double sentObject = 2.0694; + final double echoObject = await api.callFlutterEchoDouble(sentObject); + expect(echoObject, sentObject); + }); + testWidgets('strings serialize and deserialize correctly', (WidgetTester _) async { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); const String sentObject = 'Hello Dart!'; - final String echoObject = await api.callFlutterEchoString(sentObject); expect(echoObject, sentObject); }); + + testWidgets('Uint8Lists serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final List data = [ + 102, + 111, + 114, + 116, + 121, + 45, + 116, + 119, + 111, + 0 + ]; + final Uint8List sentObject = Uint8List.fromList(data); + final Uint8List echoObject = + await api.callFlutterEchoUint8List(sentObject); + expect(echoObject, sentObject); + }); + + testWidgets('lists serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + const List sentObject = [7, 'Hello Dart!']; + final List echoObject = + await api.callFlutterEchoList(sentObject); + expect(listEquals(echoObject, sentObject), true); + }); + + testWidgets('maps serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + const Map sentObject = { + 'a': 1, + 'b': 2.3, + 'c': 'four', + }; + final Map echoObject = + await api.callFlutterEchoMap(sentObject); + expect(mapEquals(echoObject, sentObject), true); + }); + + testWidgets('nullable booleans serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + for (final bool? sentObject in [true, false]) { + final bool? echoObject = + await api.callFlutterEchoNullableBool(sentObject); + expect(echoObject, sentObject); + } + }); + + testWidgets('null booleans serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + const bool? sentObject = null; + final bool? echoObject = + await api.callFlutterEchoNullableBool(sentObject); + expect(echoObject, sentObject); + }); + + testWidgets('nullable ints serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + const int sentObject = -13; + final int? echoObject = await api.callFlutterEchoNullableInt(sentObject); + expect(echoObject, sentObject); + }, + // TODO(stuartmorgan): Fix and re-enable. + // See https://github.com/flutter/flutter/issues/118726 + skip: targetGenerator == TargetGenerator.kotlin); + + testWidgets('null ints serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final int? echoObject = await api.callFlutterEchoNullableInt(null); + expect(echoObject, null); + }); + + testWidgets('nullable doubles serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + const double sentObject = 2.0694; + final double? echoObject = + await api.callFlutterEchoNullableDouble(sentObject); + expect(echoObject, sentObject); + }); + + testWidgets('null doubles serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final double? echoObject = await api.callFlutterEchoNullableDouble(null); + expect(echoObject, null); + }); + + testWidgets('nullable strings serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + const String sentObject = "I'm a computer"; + final String? echoObject = + await api.callFlutterEchoNullableString(sentObject); + expect(echoObject, sentObject); + }); + + testWidgets('null strings serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final String? echoObject = await api.callFlutterEchoNullableString(null); + expect(echoObject, null); + }); + + testWidgets('nullable Uint8Lists serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + final List data = [ + 102, + 111, + 114, + 116, + 121, + 45, + 116, + 119, + 111, + 0 + ]; + final Uint8List sentObject = Uint8List.fromList(data); + final Uint8List? echoObject = + await api.callFlutterEchoNullableUint8List(sentObject); + expect(echoObject, sentObject); + }); + + testWidgets('null Uint8Lists serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final Uint8List? echoObject = + await api.callFlutterEchoNullableUint8List(null); + expect(echoObject, null); + }); + + testWidgets('nullable lists serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + const List sentObject = [7, 'Hello Dart!']; + final List? echoObject = + await api.callFlutterEchoNullableList(sentObject); + expect(listEquals(echoObject, sentObject), true); + }); + + testWidgets('null lists serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final List? echoObject = + await api.callFlutterEchoNullableList(null); + expect(listEquals(echoObject, null), true); + }); + + testWidgets('nullable maps serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + const Map sentObject = { + 'a': 1, + 'b': 2.3, + 'c': 'four', + }; + final Map? echoObject = + await api.callFlutterEchoNullableMap(sentObject); + expect(mapEquals(echoObject, sentObject), true); + }); + + testWidgets('null maps serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final Map? echoObject = + await api.callFlutterEchoNullableMap(null); + expect(mapEquals(echoObject, null), true); + }); }); } @@ -587,7 +859,7 @@ class _FlutterApiTestImplementation implements FlutterIntegrationCoreApi { List? echoNullableList(List? aList) => aList; @override - Map echoNullableMap(Map aMap) => aMap; + Map? echoNullableMap(Map? aMap) => aMap; @override String? echoNullableString(String? aString) => aString; 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 e0f645116f..59f67127cf 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 @@ -812,6 +812,148 @@ class HostIntegrationCoreApi { } } + Future callFlutterEchoAllTypes(AllTypes arg_everything) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoAllTypes', + codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_everything]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as AllTypes?)!; + } + } + + Future callFlutterSendMultipleNullableTypes( + bool? arg_aNullableBool, + int? arg_aNullableInt, + String? arg_aNullableString) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes', + codec, + binaryMessenger: _binaryMessenger); + final List? replyList = await channel.send( + [arg_aNullableBool, arg_aNullableInt, arg_aNullableString]) + as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as AllNullableTypes?)!; + } + } + + Future callFlutterEchoBool(bool arg_aBool) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoBool', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_aBool]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as bool?)!; + } + } + + Future callFlutterEchoInt(int arg_anInt) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoInt', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_anInt]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as int?)!; + } + } + + Future callFlutterEchoDouble(double arg_aDouble) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoDouble', + codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_aDouble]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as double?)!; + } + } + Future callFlutterEchoString(String arg_aString) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString', @@ -839,6 +981,253 @@ class HostIntegrationCoreApi { return (replyList[0] as String?)!; } } + + Future callFlutterEchoUint8List(Uint8List arg_aList) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoUint8List', + codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_aList]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as Uint8List?)!; + } + } + + Future> callFlutterEchoList(List arg_aList) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoList', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_aList]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as List?)!.cast(); + } + } + + Future> callFlutterEchoMap( + Map arg_aMap) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoMap', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_aMap]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as Map?)!.cast(); + } + } + + Future callFlutterEchoNullableBool(bool? arg_aBool) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableBool', + codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_aBool]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return (replyList[0] as bool?); + } + } + + Future callFlutterEchoNullableInt(int? arg_anInt) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableInt', + codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_anInt]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return (replyList[0] as int?); + } + } + + Future callFlutterEchoNullableDouble(double? arg_aDouble) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableDouble', + codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_aDouble]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return (replyList[0] as double?); + } + } + + Future callFlutterEchoNullableString(String? arg_aString) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableString', + codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_aString]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return (replyList[0] as String?); + } + } + + Future callFlutterEchoNullableUint8List( + Uint8List? arg_aList) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableUint8List', + codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_aList]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return (replyList[0] as Uint8List?); + } + } + + Future?> callFlutterEchoNullableList( + List? arg_aList) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableList', + codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_aList]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return (replyList[0] as List?)?.cast(); + } + } + + Future?> callFlutterEchoNullableMap( + Map? arg_aMap) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableMap', + codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_aMap]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return (replyList[0] as Map?)?.cast(); + } + } } class _FlutterIntegrationCoreApiCodec extends StandardMessageCodec { @@ -938,7 +1327,7 @@ abstract class FlutterIntegrationCoreApi { List? echoNullableList(List? aList); /// Returns the passed map, to test serialization and deserialization. - Map echoNullableMap(Map aMap); + Map? echoNullableMap(Map? aMap); static void setup(FlutterIntegrationCoreApi? api, {BinaryMessenger? binaryMessenger}) { @@ -1274,9 +1663,7 @@ abstract class FlutterIntegrationCoreApi { final List args = (message as List?)!; final Map? arg_aMap = (args[0] as Map?)?.cast(); - assert(arg_aMap != null, - 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap was null, expected non-null Map.'); - final Map output = api.echoNullableMap(arg_aMap!); + final Map? output = api.echoNullableMap(arg_aMap); return output; }); } diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt index 035863f57f..e9fa5c22ae 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt @@ -270,7 +270,22 @@ interface HostIntegrationCoreApi { /** Returns the passed string asynchronously. */ fun echoAsyncString(aString: String, callback: (String) -> Unit) fun callFlutterNoop(callback: () -> Unit) + fun callFlutterEchoAllTypes(everything: AllTypes, callback: (AllTypes) -> Unit) + fun callFlutterSendMultipleNullableTypes(aNullableBool: Boolean?, aNullableInt: Long?, aNullableString: String?, callback: (AllNullableTypes) -> Unit) + fun callFlutterEchoBool(aBool: Boolean, callback: (Boolean) -> Unit) + fun callFlutterEchoInt(anInt: Long, callback: (Long) -> Unit) + fun callFlutterEchoDouble(aDouble: Double, callback: (Double) -> Unit) fun callFlutterEchoString(aString: String, callback: (String) -> Unit) + fun callFlutterEchoUint8List(aList: ByteArray, callback: (ByteArray) -> Unit) + fun callFlutterEchoList(aList: List, callback: (List) -> Unit) + fun callFlutterEchoMap(aMap: Map, callback: (Map) -> Unit) + fun callFlutterEchoNullableBool(aBool: Boolean?, callback: (Boolean?) -> Unit) + fun callFlutterEchoNullableInt(anInt: Long?, callback: (Long?) -> Unit) + fun callFlutterEchoNullableDouble(aDouble: Double?, callback: (Double?) -> Unit) + fun callFlutterEchoNullableString(aString: String?, callback: (String?) -> Unit) + fun callFlutterEchoNullableUint8List(aList: ByteArray?, callback: (ByteArray?) -> Unit) + fun callFlutterEchoNullableList(aList: List?, callback: (List?) -> Unit) + fun callFlutterEchoNullableMap(aMap: Map?, callback: (Map?) -> Unit) companion object { /** The codec used by HostIntegrationCoreApi. */ @@ -678,6 +693,108 @@ interface HostIntegrationCoreApi { channel.setMessageHandler(null) } } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoAllTypes", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val everythingArg = args[0] as AllTypes + api.callFlutterEchoAllTypes(everythingArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val aNullableBoolArg = args[0] as? Boolean + val aNullableIntArg = args[1].let { if (it is Int) it.toLong() else it as? Long } + val aNullableStringArg = args[2] as? String + api.callFlutterSendMultipleNullableTypes(aNullableBoolArg, aNullableIntArg, aNullableStringArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoBool", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val aBoolArg = args[0] as Boolean + api.callFlutterEchoBool(aBoolArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoInt", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val anIntArg = args[0].let { if (it is Int) it.toLong() else it as Long } + api.callFlutterEchoInt(anIntArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoDouble", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val aDoubleArg = args[0] as Double + api.callFlutterEchoDouble(aDoubleArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } run { val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString", codec) if (api != null) { @@ -698,6 +815,206 @@ interface HostIntegrationCoreApi { channel.setMessageHandler(null) } } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoUint8List", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val aListArg = args[0] as ByteArray + api.callFlutterEchoUint8List(aListArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoList", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val aListArg = args[0] as List + api.callFlutterEchoList(aListArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoMap", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val aMapArg = args[0] as Map + api.callFlutterEchoMap(aMapArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableBool", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val aBoolArg = args[0] as? Boolean + api.callFlutterEchoNullableBool(aBoolArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableInt", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val anIntArg = args[0].let { if (it is Int) it.toLong() else it as? Long } + api.callFlutterEchoNullableInt(anIntArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableDouble", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val aDoubleArg = args[0] as? Double + api.callFlutterEchoNullableDouble(aDoubleArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableString", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val aStringArg = args[0] as? String + api.callFlutterEchoNullableString(aStringArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableUint8List", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val aListArg = args[0] as? ByteArray + api.callFlutterEchoNullableUint8List(aListArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableList", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val aListArg = args[0] as? List + api.callFlutterEchoNullableList(aListArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableMap", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val aMapArg = args[0] as? Map + api.callFlutterEchoNullableMap(aMapArg) { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } } } } @@ -899,10 +1216,10 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { } } /** Returns the passed map, to test serialization and deserialization. */ - fun echoNullableMap(aMapArg: Map, callback: (Map) -> Unit) { + fun echoNullableMap(aMapArg: Map?, callback: (Map?) -> Unit) { val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap", codec) channel.send(listOf(aMapArg)) { - val result = it as Map + val result = it as? Map? callback(result) } } 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 b8620dfc91..e224d02061 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 @@ -116,7 +116,75 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi { flutterApi!!.noop() { callback() } } - override fun callFlutterEchoString(aString: String, callback: (String) -> Unit) { - flutterApi!!.echoString(aString) { flutterString -> callback(flutterString) } + override fun callFlutterEchoAllTypes(everything: AllTypes, callback: (AllTypes) -> Unit) { + flutterApi!!.echoAllTypes(everything) { echo -> callback(echo) } } + + override fun callFlutterSendMultipleNullableTypes( + aNullableBool: Boolean?, + aNullableInt: Long?, + aNullableString: String?, + callback: (AllNullableTypes) -> Unit + ) { + flutterApi!!.sendMultipleNullableTypes(aNullableBool, aNullableInt, aNullableString) { + echo -> callback(echo) + } + } + + override fun callFlutterEchoBool(aBool: Boolean, callback: (Boolean) -> Unit) { + flutterApi!!.echoBool(aBool) { echo -> callback(echo) } + } + + override fun callFlutterEchoInt(anInt: Long, callback: (Long) -> Unit) { + flutterApi!!.echoInt(anInt) { echo -> callback(echo) } + } + + override fun callFlutterEchoDouble(aDouble: Double, callback: (Double) -> Unit) { + flutterApi!!.echoDouble(aDouble) { echo -> callback(echo) } + } + + override fun callFlutterEchoString(aString: String, callback: (String) -> Unit) { + flutterApi!!.echoString(aString) { echo -> callback(echo) } + } + + override fun callFlutterEchoUint8List(aList: ByteArray, callback: (ByteArray) -> Unit) { + flutterApi!!.echoUint8List(aList) { echo -> callback(echo) } + } + + override fun callFlutterEchoList(aList: List, callback: (List) -> Unit) { + flutterApi!!.echoList(aList) { echo -> callback(echo) } + } + + override fun callFlutterEchoMap(aMap: Map, callback: (Map) -> Unit) { + flutterApi!!.echoMap(aMap) { echo -> callback(echo) } + } + + override fun callFlutterEchoNullableBool(aBool: Boolean?, callback: (Boolean?) -> Unit) { + flutterApi!!.echoNullableBool(aBool) { echo -> callback(echo) } + } + + override fun callFlutterEchoNullableInt(anInt: Long?, callback: (Long?) -> Unit) { + flutterApi!!.echoNullableInt(anInt) { echo -> callback(echo) } + } + + override fun callFlutterEchoNullableDouble(aDouble: Double?, callback: (Double?) -> Unit) { + flutterApi!!.echoNullableDouble(aDouble) { echo -> callback(echo) } + } + + override fun callFlutterEchoNullableString(aString: String?, callback: (String?) -> Unit) { + flutterApi!!.echoNullableString(aString) { echo -> callback(echo) } + } + + override fun callFlutterEchoNullableUint8List(aList: ByteArray?, callback: (ByteArray?) -> Unit) { + flutterApi!!.echoNullableUint8List(aList) { echo -> callback(echo) } + } + + override fun callFlutterEchoNullableList(aList: List?, callback: (List?) -> Unit) { + flutterApi!!.echoNullableList(aList) { echo -> callback(echo) } + } + + override fun callFlutterEchoNullableMap(aMap: Map?, callback: (Map?) -> Unit) { + flutterApi!!.echoNullableMap(aMap) { echo -> callback(echo) } + } + } diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index 83d03ff0b9..f4af18cfbf 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -281,7 +281,22 @@ protocol HostIntegrationCoreApi { /// Returns the passed string asynchronously. func echoAsyncString(aString: String, completion: @escaping (String) -> Void) func callFlutterNoop(completion: @escaping () -> Void) + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) + func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) + func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) + func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) + func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) + func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -554,6 +569,68 @@ class HostIntegrationCoreApiSetup { } else { callFlutterNoopChannel.setMessageHandler(nil) } + let callFlutterEchoAllTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoAllTypes", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoAllTypesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let everythingArg = args[0] as! AllTypes + api.callFlutterEchoAllTypes(everything: everythingArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoAllTypesChannel.setMessageHandler(nil) + } + let callFlutterSendMultipleNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterSendMultipleNullableTypesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool + let aNullableIntArg = args[1] as? Int32 + let aNullableStringArg = args[2] as? String + api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterSendMultipleNullableTypesChannel.setMessageHandler(nil) + } + let callFlutterEchoBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoBool", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aBoolArg = args[0] as! Bool + api.callFlutterEchoBool(aBool: aBoolArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoBoolChannel.setMessageHandler(nil) + } + let callFlutterEchoIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoInt", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let anIntArg = args[0] as! Int32 + api.callFlutterEchoInt(anInt: anIntArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoIntChannel.setMessageHandler(nil) + } + let callFlutterEchoDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoDouble", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aDoubleArg = args[0] as! Double + api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoDoubleChannel.setMessageHandler(nil) + } let callFlutterEchoStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoStringChannel.setMessageHandler { message, reply in @@ -566,6 +643,126 @@ class HostIntegrationCoreApiSetup { } else { callFlutterEchoStringChannel.setMessageHandler(nil) } + let callFlutterEchoUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoUint8List", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aListArg = args[0] as! FlutterStandardTypedData + api.callFlutterEchoUint8List(aList: aListArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoUint8ListChannel.setMessageHandler(nil) + } + let callFlutterEchoListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoList", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aListArg = args[0] as! [Any?] + api.callFlutterEchoList(aList: aListArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoListChannel.setMessageHandler(nil) + } + let callFlutterEchoMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoMap", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aMapArg = args[0] as! [String?: Any?] + api.callFlutterEchoMap(aMap: aMapArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoMapChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableBool", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aBoolArg = args[0] as? Bool + api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableBoolChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableInt", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let anIntArg = args[0] as? Int32 + api.callFlutterEchoNullableInt(anInt: anIntArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableIntChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aDoubleArg = args[0] as? Double + api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableDoubleChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableString", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aStringArg = args[0] as? String + api.callFlutterEchoNullableString(aString: aStringArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableStringChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aListArg = args[0] as? FlutterStandardTypedData + api.callFlutterEchoNullableUint8List(aList: aListArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableUint8ListChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableList", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aListArg = args[0] as? [Any?] + api.callFlutterEchoNullableList(aList: aListArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableListChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableMap", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aMapArg = args[0] as? [String?: Any?] + api.callFlutterEchoNullableMap(aMap: aMapArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableMapChannel.setMessageHandler(nil) + } } } private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader { @@ -765,10 +962,10 @@ class FlutterIntegrationCoreApi { } } /// Returns the passed map, to test serialization and deserialization. - func echoNullableMap(aMap aMapArg: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) { + func echoNullableMap(aMap aMapArg: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aMapArg] as [Any?]) { response in - let result = response as! [String?: Any?] + let result = response as? [String?: Any?] completion(result) } } 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 7170f5f18a..3515e4914b 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -114,9 +114,78 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } - func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) { - flutterAPI.echoString(aString: aString) { flutterString in - completion(flutterString) + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) { + flutterAPI.echoAllTypes(everything: everything) { completion($0) } + } + + func callFlutterSendMultipleNullableTypes( + aNullableBool: Bool?, + aNullableInt: Int32?, + aNullableString: String?, + completion: @escaping (AllNullableTypes) -> Void + ) { + flutterAPI.sendMultipleNullableTypes( + aNullableBool: aNullableBool, + aNullableInt: aNullableInt, + aNullableString: aNullableString + ) { + completion($0) } } + + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) { + flutterAPI.echoBool(aBool: aBool) { completion($0) } + } + + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) { + flutterAPI.echoInt(anInt: anInt) { completion($0) } + } + + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) { + flutterAPI.echoDouble(aDouble: aDouble) { completion($0) } + } + + func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) { + flutterAPI.echoString(aString: aString) { completion($0) } + } + + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) { + flutterAPI.echoUint8List(aList: aList) { completion($0) } + } + + func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) { + flutterAPI.echoList(aList: aList) { completion($0) } + } + + func callFlutterEchoMap(aMap: [String? : Any?], completion: @escaping ([String? : Any?]) -> Void) { + flutterAPI.echoMap(aMap: aMap) { completion($0) } + } + + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) { + flutterAPI.echoNullableBool(aBool: aBool) { completion($0) } + } + + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) { + flutterAPI.echoNullableInt(anInt: anInt) { completion($0) } + } + + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) { + flutterAPI.echoNullableDouble(aDouble: aDouble) { completion($0) } + } + + func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) { + flutterAPI.echoNullableString(aString: aString) { completion($0) } + } + + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) { + flutterAPI.echoNullableUint8List(aList: aList) { completion($0) } + } + + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) { + flutterAPI.echoNullableList(aList: aList) { completion($0) } + } + + func callFlutterEchoNullableMap(aMap: [String? : Any?]?, completion: @escaping ([String? : Any?]?) -> Void) { + flutterAPI.echoNullableMap(aMap: aMap) { completion($0) } + } } diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index 83d03ff0b9..f4af18cfbf 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -281,7 +281,22 @@ protocol HostIntegrationCoreApi { /// Returns the passed string asynchronously. func echoAsyncString(aString: String, completion: @escaping (String) -> Void) func callFlutterNoop(completion: @escaping () -> Void) + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) + func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) + func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) + func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) + func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) + func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -554,6 +569,68 @@ class HostIntegrationCoreApiSetup { } else { callFlutterNoopChannel.setMessageHandler(nil) } + let callFlutterEchoAllTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoAllTypes", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoAllTypesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let everythingArg = args[0] as! AllTypes + api.callFlutterEchoAllTypes(everything: everythingArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoAllTypesChannel.setMessageHandler(nil) + } + let callFlutterSendMultipleNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterSendMultipleNullableTypesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool + let aNullableIntArg = args[1] as? Int32 + let aNullableStringArg = args[2] as? String + api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterSendMultipleNullableTypesChannel.setMessageHandler(nil) + } + let callFlutterEchoBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoBool", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aBoolArg = args[0] as! Bool + api.callFlutterEchoBool(aBool: aBoolArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoBoolChannel.setMessageHandler(nil) + } + let callFlutterEchoIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoInt", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let anIntArg = args[0] as! Int32 + api.callFlutterEchoInt(anInt: anIntArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoIntChannel.setMessageHandler(nil) + } + let callFlutterEchoDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoDouble", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aDoubleArg = args[0] as! Double + api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoDoubleChannel.setMessageHandler(nil) + } let callFlutterEchoStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoStringChannel.setMessageHandler { message, reply in @@ -566,6 +643,126 @@ class HostIntegrationCoreApiSetup { } else { callFlutterEchoStringChannel.setMessageHandler(nil) } + let callFlutterEchoUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoUint8List", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aListArg = args[0] as! FlutterStandardTypedData + api.callFlutterEchoUint8List(aList: aListArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoUint8ListChannel.setMessageHandler(nil) + } + let callFlutterEchoListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoList", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aListArg = args[0] as! [Any?] + api.callFlutterEchoList(aList: aListArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoListChannel.setMessageHandler(nil) + } + let callFlutterEchoMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoMap", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aMapArg = args[0] as! [String?: Any?] + api.callFlutterEchoMap(aMap: aMapArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoMapChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableBool", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aBoolArg = args[0] as? Bool + api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableBoolChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableInt", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let anIntArg = args[0] as? Int32 + api.callFlutterEchoNullableInt(anInt: anIntArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableIntChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aDoubleArg = args[0] as? Double + api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableDoubleChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableString", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aStringArg = args[0] as? String + api.callFlutterEchoNullableString(aString: aStringArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableStringChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aListArg = args[0] as? FlutterStandardTypedData + api.callFlutterEchoNullableUint8List(aList: aListArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableUint8ListChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableList", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aListArg = args[0] as? [Any?] + api.callFlutterEchoNullableList(aList: aListArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableListChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableMap", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aMapArg = args[0] as? [String?: Any?] + api.callFlutterEchoNullableMap(aMap: aMapArg) { result in + reply(wrapResult(result)) + } + } + } else { + callFlutterEchoNullableMapChannel.setMessageHandler(nil) + } } } private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader { @@ -765,10 +962,10 @@ class FlutterIntegrationCoreApi { } } /// Returns the passed map, to test serialization and deserialization. - func echoNullableMap(aMap aMapArg: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) { + func echoNullableMap(aMap aMapArg: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aMapArg] as [Any?]) { response in - let result = response as! [String?: Any?] + let result = response as? [String?: Any?] completion(result) } } 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 2cfe48764a..74614735af 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -23,7 +23,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { // MARK: HostIntegrationCoreApi implementation - func noop() { + func noop() { } func echoAllTypes(everything: AllTypes) -> AllTypes { @@ -114,9 +114,78 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } - func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) { - flutterAPI.echoString(aString: aString) { flutterString in - completion(flutterString) + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) { + flutterAPI.echoAllTypes(everything: everything) { completion($0) } + } + + func callFlutterSendMultipleNullableTypes( + aNullableBool: Bool?, + aNullableInt: Int32?, + aNullableString: String?, + completion: @escaping (AllNullableTypes) -> Void + ) { + flutterAPI.sendMultipleNullableTypes( + aNullableBool: aNullableBool, + aNullableInt: aNullableInt, + aNullableString: aNullableString + ) { + completion($0) } } + + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) { + flutterAPI.echoBool(aBool: aBool) { completion($0) } + } + + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) { + flutterAPI.echoInt(anInt: anInt) { completion($0) } + } + + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) { + flutterAPI.echoDouble(aDouble: aDouble) { completion($0) } + } + + func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) { + flutterAPI.echoString(aString: aString) { completion($0) } + } + + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) { + flutterAPI.echoUint8List(aList: aList) { completion($0) } + } + + func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) { + flutterAPI.echoList(aList: aList) { completion($0) } + } + + func callFlutterEchoMap(aMap: [String? : Any?], completion: @escaping ([String? : Any?]) -> Void) { + flutterAPI.echoMap(aMap: aMap) { completion($0) } + } + + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) { + flutterAPI.echoNullableBool(aBool: aBool) { completion($0) } + } + + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) { + flutterAPI.echoNullableInt(anInt: anInt) { completion($0) } + } + + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) { + flutterAPI.echoNullableDouble(aDouble: aDouble) { completion($0) } + } + + func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) { + flutterAPI.echoNullableString(aString: aString) { completion($0) } + } + + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) { + flutterAPI.echoNullableUint8List(aList: aList) { completion($0) } + } + + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) { + flutterAPI.echoNullableList(aList: aList) { completion($0) } + } + + func callFlutterEchoNullableMap(aMap: [String? : Any?]?, completion: @escaping ([String? : Any?]?) -> Void) { + flutterAPI.echoNullableMap(aMap: aMap) { completion($0) } + } } diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp index aa098122b0..30d9b451a8 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp @@ -1311,6 +1311,201 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, channel->SetMessageHandler(nullptr); } } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoAllTypes", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_everything_arg = args.at(0); + if (encodable_everything_arg.IsNull()) { + reply(WrapError("everything_arg unexpectedly null.")); + return; + } + const auto& everything_arg = std::any_cast( + std::get( + encodable_everything_arg)); + api->CallFlutterEchoAllTypes( + everything_arg, [reply](ErrorOr&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + wrapped.push_back(flutter::CustomEncodableValue( + std::move(output).TakeValue())); + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi." + "callFlutterSendMultipleNullableTypes", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_nullable_bool_arg = args.at(0); + const auto* a_nullable_bool_arg = + std::get_if(&encodable_a_nullable_bool_arg); + const auto& encodable_a_nullable_int_arg = args.at(1); + const int64_t a_nullable_int_arg_value = + encodable_a_nullable_int_arg.IsNull() + ? 0 + : encodable_a_nullable_int_arg.LongValue(); + const auto* a_nullable_int_arg = + encodable_a_nullable_int_arg.IsNull() + ? nullptr + : &a_nullable_int_arg_value; + const auto& encodable_a_nullable_string_arg = args.at(2); + const auto* a_nullable_string_arg = + std::get_if(&encodable_a_nullable_string_arg); + api->CallFlutterSendMultipleNullableTypes( + a_nullable_bool_arg, a_nullable_int_arg, + a_nullable_string_arg, + [reply](ErrorOr&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + wrapped.push_back(flutter::CustomEncodableValue( + std::move(output).TakeValue())); + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoBool", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_bool_arg = args.at(0); + if (encodable_a_bool_arg.IsNull()) { + reply(WrapError("a_bool_arg unexpectedly null.")); + return; + } + const auto& a_bool_arg = std::get(encodable_a_bool_arg); + api->CallFlutterEchoBool( + a_bool_arg, [reply](ErrorOr&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + wrapped.push_back( + flutter::EncodableValue(std::move(output).TakeValue())); + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoInt", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_an_int_arg = args.at(0); + if (encodable_an_int_arg.IsNull()) { + reply(WrapError("an_int_arg unexpectedly null.")); + return; + } + const int64_t an_int_arg = encodable_an_int_arg.LongValue(); + api->CallFlutterEchoInt( + an_int_arg, [reply](ErrorOr&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + wrapped.push_back( + flutter::EncodableValue(std::move(output).TakeValue())); + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoDouble", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_double_arg = args.at(0); + if (encodable_a_double_arg.IsNull()) { + reply(WrapError("a_double_arg unexpectedly null.")); + return; + } + const auto& a_double_arg = + std::get(encodable_a_double_arg); + api->CallFlutterEchoDouble( + a_double_arg, [reply](ErrorOr&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + wrapped.push_back( + flutter::EncodableValue(std::move(output).TakeValue())); + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } { auto channel = std::make_unique>( binary_messenger, @@ -1348,6 +1543,399 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, channel->SetMessageHandler(nullptr); } } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoUint8List", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_list_arg = args.at(0); + if (encodable_a_list_arg.IsNull()) { + reply(WrapError("a_list_arg unexpectedly null.")); + return; + } + const auto& a_list_arg = + std::get>(encodable_a_list_arg); + api->CallFlutterEchoUint8List( + a_list_arg, [reply](ErrorOr>&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + wrapped.push_back( + flutter::EncodableValue(std::move(output).TakeValue())); + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoList", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_list_arg = args.at(0); + if (encodable_a_list_arg.IsNull()) { + reply(WrapError("a_list_arg unexpectedly null.")); + return; + } + const auto& a_list_arg = + std::get(encodable_a_list_arg); + api->CallFlutterEchoList( + a_list_arg, + [reply](ErrorOr&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + wrapped.push_back( + flutter::EncodableValue(std::move(output).TakeValue())); + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoMap", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_map_arg = args.at(0); + if (encodable_a_map_arg.IsNull()) { + reply(WrapError("a_map_arg unexpectedly null.")); + return; + } + const auto& a_map_arg = + std::get(encodable_a_map_arg); + api->CallFlutterEchoMap( + a_map_arg, [reply](ErrorOr&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + wrapped.push_back( + flutter::EncodableValue(std::move(output).TakeValue())); + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableBool", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_bool_arg = args.at(0); + const auto* a_bool_arg = std::get_if(&encodable_a_bool_arg); + api->CallFlutterEchoNullableBool( + a_bool_arg, [reply](ErrorOr>&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + auto output_optional = std::move(output).TakeValue(); + if (output_optional) { + wrapped.push_back(flutter::EncodableValue( + std::move(output_optional).value())); + } else { + wrapped.push_back(flutter::EncodableValue()); + } + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableInt", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_an_int_arg = args.at(0); + const int64_t an_int_arg_value = + encodable_an_int_arg.IsNull() + ? 0 + : encodable_an_int_arg.LongValue(); + const auto* an_int_arg = + encodable_an_int_arg.IsNull() ? nullptr : &an_int_arg_value; + api->CallFlutterEchoNullableInt( + an_int_arg, + [reply](ErrorOr>&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + auto output_optional = std::move(output).TakeValue(); + if (output_optional) { + wrapped.push_back(flutter::EncodableValue( + std::move(output_optional).value())); + } else { + wrapped.push_back(flutter::EncodableValue()); + } + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi." + "callFlutterEchoNullableDouble", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_double_arg = args.at(0); + const auto* a_double_arg = + std::get_if(&encodable_a_double_arg); + api->CallFlutterEchoNullableDouble( + a_double_arg, + [reply](ErrorOr>&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + auto output_optional = std::move(output).TakeValue(); + if (output_optional) { + wrapped.push_back(flutter::EncodableValue( + std::move(output_optional).value())); + } else { + wrapped.push_back(flutter::EncodableValue()); + } + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi." + "callFlutterEchoNullableString", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_string_arg = args.at(0); + const auto* a_string_arg = + std::get_if(&encodable_a_string_arg); + api->CallFlutterEchoNullableString( + a_string_arg, + [reply](ErrorOr>&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + auto output_optional = std::move(output).TakeValue(); + if (output_optional) { + wrapped.push_back(flutter::EncodableValue( + std::move(output_optional).value())); + } else { + wrapped.push_back(flutter::EncodableValue()); + } + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi." + "callFlutterEchoNullableUint8List", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_list_arg = args.at(0); + const auto* a_list_arg = + std::get_if>(&encodable_a_list_arg); + api->CallFlutterEchoNullableUint8List( + a_list_arg, + [reply]( + ErrorOr>>&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + auto output_optional = std::move(output).TakeValue(); + if (output_optional) { + wrapped.push_back(flutter::EncodableValue( + std::move(output_optional).value())); + } else { + wrapped.push_back(flutter::EncodableValue()); + } + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableList", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_list_arg = args.at(0); + const auto* a_list_arg = + std::get_if(&encodable_a_list_arg); + api->CallFlutterEchoNullableList( + a_list_arg, + [reply]( + ErrorOr>&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + auto output_optional = std::move(output).TakeValue(); + if (output_optional) { + wrapped.push_back(flutter::EncodableValue( + std::move(output_optional).value())); + } else { + wrapped.push_back(flutter::EncodableValue()); + } + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableMap", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_map_arg = args.at(0); + const auto* a_map_arg = + std::get_if(&encodable_a_map_arg); + api->CallFlutterEchoNullableMap( + a_map_arg, + [reply]( + ErrorOr>&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + flutter::EncodableList wrapped; + auto output_optional = std::move(output).TakeValue(); + if (output_optional) { + wrapped.push_back(flutter::EncodableValue( + std::move(output_optional).value())); + } else { + wrapped.push_back(flutter::EncodableValue()); + } + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } } flutter::EncodableValue HostIntegrationCoreApi::WrapError( @@ -1826,8 +2414,8 @@ void FlutterIntegrationCoreApi::EchoNullableList( }); } void FlutterIntegrationCoreApi::EchoNullableMap( - const flutter::EncodableMap& a_map_arg, - std::function&& on_success, + const flutter::EncodableMap* a_map_arg, + std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( binary_messenger_, @@ -1835,7 +2423,8 @@ void FlutterIntegrationCoreApi::EchoNullableMap( &GetCodec()); flutter::EncodableValue encoded_api_arguments = flutter::EncodableValue(flutter::EncodableList{ - flutter::EncodableValue(a_map_arg), + a_map_arg ? flutter::EncodableValue(*a_map_arg) + : flutter::EncodableValue(), }); channel->Send( encoded_api_arguments, @@ -1844,8 +2433,8 @@ void FlutterIntegrationCoreApi::EchoNullableMap( std::unique_ptr response = GetCodec().DecodeMessage(reply, reply_size); const auto& encodable_return_value = *response; - const auto& return_value = - std::get(encodable_return_value); + const auto* return_value = + std::get_if(&encodable_return_value); on_success(return_value); }); } diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h index ed9c2ee30c..0bc91f0757 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h @@ -327,9 +327,56 @@ class HostIntegrationCoreApi { std::function reply)> result) = 0; virtual void CallFlutterNoop( std::function reply)> result) = 0; + virtual void CallFlutterEchoAllTypes( + const AllTypes& everything, + std::function reply)> result) = 0; + virtual void CallFlutterSendMultipleNullableTypes( + const bool* a_nullable_bool, const int64_t* a_nullable_int, + const std::string* a_nullable_string, + std::function reply)> result) = 0; + virtual void CallFlutterEchoBool( + bool a_bool, std::function reply)> result) = 0; + virtual void CallFlutterEchoInt( + int64_t an_int, std::function reply)> result) = 0; + virtual void CallFlutterEchoDouble( + double a_double, std::function reply)> result) = 0; virtual void CallFlutterEchoString( const std::string& a_string, std::function reply)> result) = 0; + virtual void CallFlutterEchoUint8List( + const std::vector& a_list, + std::function> reply)> result) = 0; + virtual void CallFlutterEchoList( + const flutter::EncodableList& a_list, + std::function reply)> result) = 0; + virtual void CallFlutterEchoMap( + const flutter::EncodableMap& a_map, + std::function reply)> result) = 0; + virtual void CallFlutterEchoNullableBool( + const bool* a_bool, + std::function> reply)> result) = 0; + virtual void CallFlutterEchoNullableInt( + const int64_t* an_int, + std::function> reply)> result) = 0; + virtual void CallFlutterEchoNullableDouble( + const double* a_double, + std::function> reply)> result) = 0; + virtual void CallFlutterEchoNullableString( + const std::string* a_string, + std::function> reply)> + result) = 0; + virtual void CallFlutterEchoNullableUint8List( + const std::vector* a_list, + std::function>> reply)> + result) = 0; + virtual void CallFlutterEchoNullableList( + const flutter::EncodableList* a_list, + std::function> reply)> + result) = 0; + virtual void CallFlutterEchoNullableMap( + const flutter::EncodableMap* a_map, + std::function> reply)> + result) = 0; // The codec used by HostIntegrationCoreApi. static const flutter::StandardMessageCodec& GetCodec(); @@ -449,8 +496,8 @@ class FlutterIntegrationCoreApi { std::function&& on_error); // Returns the passed map, to test serialization and deserialization. void EchoNullableMap( - const flutter::EncodableMap& a_map, - std::function&& on_success, + const flutter::EncodableMap* a_map, + std::function&& on_success, std::function&& on_error); }; 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 b5477b49df..56c0a3a868 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp @@ -23,6 +23,9 @@ using core_tests_pigeontest::ErrorOr; using core_tests_pigeontest::FlutterError; using core_tests_pigeontest::FlutterIntegrationCoreApi; using core_tests_pigeontest::HostIntegrationCoreApi; +using flutter::EncodableList; +using flutter::EncodableMap; +using flutter::EncodableValue; // static void TestPlugin::RegisterWithRegistrar( @@ -73,8 +76,8 @@ ErrorOr> TestPlugin::EchoUint8List( return a_uint8_list; } -ErrorOr TestPlugin::EchoObject( - const flutter::EncodableValue& an_object) { +ErrorOr TestPlugin::EchoObject( + const EncodableValue& an_object) { return an_object; } @@ -158,8 +161,8 @@ ErrorOr>> TestPlugin::EchoNullableUint8List( return *a_nullable_uint8_list; }; -ErrorOr> TestPlugin::EchoNullableObject( - const flutter::EncodableValue* a_nullable_object) { +ErrorOr> TestPlugin::EchoNullableObject( + const EncodableValue* a_nullable_object) { if (!a_nullable_object) { return std::nullopt; } @@ -183,12 +186,153 @@ void TestPlugin::CallFlutterNoop( [result](const FlutterError& error) { result(error); }); } +void TestPlugin::CallFlutterEchoAllTypes( + const AllTypes& everything, + std::function reply)> result) { + flutter_api_->EchoAllTypes( + everything, [result](const AllTypes& echo) { result(echo); }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterSendMultipleNullableTypes( + const bool* a_nullable_bool, const int64_t* a_nullable_int, + const std::string* a_nullable_string, + std::function reply)> result) { + flutter_api_->SendMultipleNullableTypes( + a_nullable_bool, a_nullable_int, a_nullable_string, + [result](const AllNullableTypes& echo) { result(echo); }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterEchoBool( + bool a_bool, std::function reply)> result) { + flutter_api_->EchoBool( + a_bool, [result](bool echo) { result(echo); }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterEchoInt( + int64_t an_int, std::function reply)> result) { + flutter_api_->EchoInt( + an_int, [result](int64_t echo) { result(echo); }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterEchoDouble( + double a_double, std::function reply)> result) { + flutter_api_->EchoDouble( + a_double, [result](double echo) { result(echo); }, + [result](const FlutterError& error) { result(error); }); +} + void TestPlugin::CallFlutterEchoString( const std::string& a_string, std::function reply)> result) { flutter_api_->EchoString( + a_string, [result](const std::string& echo) { result(echo); }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterEchoUint8List( + const std::vector& a_list, + std::function> reply)> result) { + flutter_api_->EchoUint8List( + a_list, [result](const std::vector& echo) { result(echo); }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterEchoList( + const EncodableList& a_list, + std::function reply)> result) { + flutter_api_->EchoList( + a_list, [result](const EncodableList& echo) { result(echo); }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterEchoMap( + const EncodableMap& a_map, + std::function reply)> result) { + flutter_api_->EchoMap( + a_map, [result](const EncodableMap& echo) { result(echo); }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterEchoNullableBool( + const bool* a_bool, + std::function> reply)> result) { + flutter_api_->EchoNullableBool( + a_bool, + [result](const bool* echo) { + result(echo ? std::optional(*echo) : std::nullopt); + }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterEchoNullableInt( + const int64_t* an_int, + std::function> reply)> result) { + flutter_api_->EchoNullableInt( + an_int, + [result](const int64_t* echo) { + result(echo ? std::optional(*echo) : std::nullopt); + }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterEchoNullableDouble( + const double* a_double, + std::function> reply)> result) { + flutter_api_->EchoNullableDouble( + a_double, + [result](const double* echo) { + result(echo ? std::optional(*echo) : std::nullopt); + }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterEchoNullableString( + const std::string* a_string, + std::function> reply)> result) { + flutter_api_->EchoNullableString( a_string, - [result](const std::string& flutter_string) { result(flutter_string); }, + [result](const std::string* echo) { + result(echo ? std::optional(*echo) : std::nullopt); + }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterEchoNullableUint8List( + const std::vector* a_list, + std::function>> reply)> + result) { + flutter_api_->EchoNullableUint8List( + a_list, + [result](const std::vector* echo) { + result(echo ? std::optional>(*echo) + : std::nullopt); + }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterEchoNullableList( + const EncodableList* a_list, + std::function> reply)> result) { + flutter_api_->EchoNullableList( + a_list, + [result](const EncodableList* echo) { + result(echo ? std::optional(*echo) : std::nullopt); + }, + [result](const FlutterError& error) { result(error); }); +} + +void TestPlugin::CallFlutterEchoNullableMap( + const EncodableMap* a_map, + std::function> reply)> result) { + flutter_api_->EchoNullableMap( + a_map, + [result](const EncodableMap* echo) { + result(echo ? std::optional(*echo) : std::nullopt); + }, [result](const FlutterError& error) { result(error); }); } 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 1c5bb9d5ff..aa0e19c185 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h @@ -82,10 +82,88 @@ class TestPlugin : public flutter::Plugin, std::function< void(std::optional reply)> result) override; + void CallFlutterEchoAllTypes( + const core_tests_pigeontest::AllTypes& everything, + std::function< + void(core_tests_pigeontest::ErrorOr + reply)> + result) override; + void CallFlutterSendMultipleNullableTypes( + const bool* a_nullable_bool, const int64_t* a_nullable_int, + const std::string* a_nullable_string, + std::function + reply)> + result) override; + void CallFlutterEchoBool( + bool a_bool, + std::function reply)> result) + override; + void CallFlutterEchoInt( + int64_t an_int, + std::function reply)> result) + override; + void CallFlutterEchoDouble( + double a_double, + std::function reply)> result) + override; void CallFlutterEchoString( const std::string& a_string, std::function reply)> result) override; + void CallFlutterEchoUint8List( + const std::vector& a_list, + std::function< + void(core_tests_pigeontest::ErrorOr> reply)> + result) override; + void CallFlutterEchoList( + const flutter::EncodableList& a_list, + std::function< + void(core_tests_pigeontest::ErrorOr reply)> + result) override; + void CallFlutterEchoMap( + const flutter::EncodableMap& a_map, + std::function< + void(core_tests_pigeontest::ErrorOr reply)> + result) override; + void CallFlutterEchoNullableBool( + const bool* a_bool, + std::function< + void(core_tests_pigeontest::ErrorOr> reply)> + result) override; + void CallFlutterEchoNullableInt( + const int64_t* an_int, + std::function< + void(core_tests_pigeontest::ErrorOr> reply)> + result) override; + void CallFlutterEchoNullableDouble( + const double* a_double, + std::function< + void(core_tests_pigeontest::ErrorOr> reply)> + result) override; + void CallFlutterEchoNullableString( + const std::string* a_string, + std::function> reply)> + result) override; + void CallFlutterEchoNullableUint8List( + const std::vector* a_list, + std::function>> + reply)> + result) override; + void CallFlutterEchoNullableList( + const flutter::EncodableList* a_list, + std::function> + reply)> + result) override; + void CallFlutterEchoNullableMap( + const flutter::EncodableMap* a_map, + std::function> + reply)> + result) override; private: std::unique_ptr