From b29476200ad9e6049df8d10405de22af9c3c62ea Mon Sep 17 00:00:00 2001 From: Huan Lin Date: Fri, 23 Jun 2023 12:28:47 -0700 Subject: [PATCH 01/14] [pigeon]fix a crash when casting NSNull to an Array --- packages/pigeon/CHANGELOG.md | 4 ++ packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/lib/swift_generator.dart | 2 +- .../ios/Runner.xcodeproj/project.pbxproj | 4 ++ .../ios/RunnerTests/NSNullFieldTests.swift | 61 +++++++++++++++++++ packages/pigeon/pubspec.yaml | 2 +- 6 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/NSNullFieldTests.swift diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 861b58d6e19..d3df2a391ef 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 10.1.1 + +* [swift] Fixes a crash when casting `NSNull` to an array. + ## 10.1.0 * [objc] Adds macOS support to facilitate code sharing with existing iOS plugins. diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index ce2d0655d2b..2b67bd552c4 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -11,7 +11,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '10.1.0'; +const String pigeonVersion = '10.1.1'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index a133a24ed4e..6e9ec0d006e 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -627,7 +627,7 @@ import FlutterMacOS if (listEncodedClassNames != null && listEncodedClassNames.contains(type.baseName)) { indent.writeln('var $variableName: $fieldType? = nil'); - indent.write('if let ${variableName}List = $value as! [Any?]? '); + indent.write('if let ${variableName}List: [Any?] = nilOrValue($value) '); indent.addScoped('{', '}', () { indent.writeln( '$variableName = $fieldType.fromList(${variableName}List)'); diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/Runner.xcodeproj/project.pbxproj b/packages/pigeon/platform_tests/test_plugin/example/ios/Runner.xcodeproj/project.pbxproj index eb200b273bb..969f97022eb 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/Runner.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; + E04641FA2A46270400661C9E /* NSNullFieldTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E04641F92A46270400661C9E /* NSNullFieldTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -88,6 +89,7 @@ 9808B6775522250A40D7D452 /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = ""; }; BC37C4E8AE005B445F208C02 /* Pods_RunnerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RunnerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BF5B776B52F984FB430C15A3 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; + E04641F92A46270400661C9E /* NSNullFieldTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSNullFieldTests.swift; sourceTree = ""; }; EB04430DB6D43CCC08FA526B /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -126,6 +128,7 @@ 33A341C6291ECDFD00D34E0F /* NullableReturnsTests.swift */, 33A341C7291ECDFD00D34E0F /* PrimitiveTests.swift */, 33A341B7291ECCA100D34E0F /* RunnerTests.swift */, + E04641F92A46270400661C9E /* NSNullFieldTests.swift */, 33A341CA291ECDFD00D34E0F /* Utils.swift */, ); path = RunnerTests; @@ -413,6 +416,7 @@ 33A341D5291ECDFD00D34E0F /* AsyncHandlersTest.swift in Sources */, 33A341CE291ECDFD00D34E0F /* EnumTests.swift in Sources */, 33A341CD291ECDFD00D34E0F /* ListTests.swift in Sources */, + E04641FA2A46270400661C9E /* NSNullFieldTests.swift in Sources */, 33A341D1291ECDFD00D34E0F /* MockBinaryMessenger.swift in Sources */, 33A341CF291ECDFD00D34E0F /* NonNullFieldsTest.swift in Sources */, 33A341CB291ECDFD00D34E0F /* MultipleArityTests.swift in Sources */, diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/NSNullFieldTests.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/NSNullFieldTests.swift new file mode 100644 index 00000000000..036608f2fd8 --- /dev/null +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/NSNullFieldTests.swift @@ -0,0 +1,61 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import XCTest +@testable import test_plugin + +/// Tests NSNull is correctly handled by `nilOrValue` helper, by manually setting nullable fields to NSNull. +final class NSNullFieldTests: XCTestCase { + + func testNSNull_nullListToCustomStructField() throws { + let reply = NullFieldsSearchReply( + result: nil, + error: nil, + indices: nil, + request: nil, + type: nil) + var list = reply.toList() + // request field + list[3] = NSNull() + let copy = NullFieldsSearchReply.fromList(list) + XCTAssertNotNil(copy) + XCTAssertNil(copy!.request) + } + + func testNSNull_nullListField() { + let reply = NullFieldsSearchReply( + result: nil, + error: nil, + indices: nil, + request: nil, + type: nil) + var list = reply.toList() + // indices field + list[2] = NSNull() + let copy = NullFieldsSearchReply.fromList(list) + XCTAssertNotNil(copy) + XCTAssertNil(copy!.indices) + } + + func testNSNull_nullBasicFields() throws { + let reply = NullFieldsSearchReply( + result: nil, + error: nil, + indices: nil, + request: nil, + type: nil) + var list = reply.toList() + // result field + list[0] = NSNull() + // error field + list[1] = NSNull() + // type field + list[4] = NSNull() + let copy = NullFieldsSearchReply.fromList(list) + XCTAssertNotNil(copy) + XCTAssertNil(copy!.result) + XCTAssertNil(copy!.error) + XCTAssertNil(copy!.type) + } +} diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index 3c4e0776eae..82531c4a887 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon -version: 10.1.0 # This must match the version in lib/generator_tools.dart +version: 10.1.1 # This must match the version in lib/generator_tools.dart environment: sdk: ">=2.19.0 <4.0.0" From 8da8cfb97c695af8a7878f209a74f9836b459916 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Thu, 29 Jun 2023 18:48:10 -0700 Subject: [PATCH 02/14] format --- packages/pigeon/lib/swift_generator.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 6e9ec0d006e..26547fb6591 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -627,7 +627,8 @@ import FlutterMacOS if (listEncodedClassNames != null && listEncodedClassNames.contains(type.baseName)) { indent.writeln('var $variableName: $fieldType? = nil'); - indent.write('if let ${variableName}List: [Any?] = nilOrValue($value) '); + indent + .write('if let ${variableName}List: [Any?] = nilOrValue($value) '); indent.addScoped('{', '}', () { indent.writeln( '$variableName = $fieldType.fromList(${variableName}List)'); From 1682682bf94a6c365554f533dd20a33eacbea26b Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Fri, 30 Jun 2023 01:01:31 -0700 Subject: [PATCH 03/14] Easy button --- .../shared_test_plugin_code/lib/integration_tests.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 730dedfc9d4..9417d9d358f 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 @@ -549,7 +549,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { (WidgetTester _) async { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); - const List sentObject = [7, 'Hello Dart!']; + const List sentObject = [7, 'Hello Dart!', null]; final List? echoObject = await api.echoNullableList(sentObject); expect(listEquals(echoObject, sentObject), true); }); @@ -562,6 +562,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { 'a': 1, 'b': 2.3, 'c': 'four', + 'd': null, }; final Map? echoObject = await api.echoNullableMap(sentObject); From 7665c10ffacb852b0ac7ea43de0c8117329d803b Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Fri, 30 Jun 2023 12:47:28 -0700 Subject: [PATCH 04/14] class with collections of null --- .../lib/integration_tests.dart | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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 9417d9d358f..92b40c9c537 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 @@ -237,6 +237,34 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { // See https://github.com/flutter/flutter/issues/118733 skip: targetGenerator == TargetGenerator.objc); + testWidgets('Classes with list of null serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final AllNullableTypes nullableListTypes = + AllNullableTypes(aNullableList: ['String', null]); + + final AllNullableTypes? echoNullFilledObject = + await api.echoAllNullableTypes(nullableListTypes); + + expect( + echoNullFilledObject?.aNullableList, nullableListTypes.aNullableList); + }); + + testWidgets('Classes with map of null serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final AllNullableTypes nullableListTypes = AllNullableTypes( + aNullableMap: {'String': 'string', 'null': null}); + + final AllNullableTypes? echoNullFilledObject = + await api.echoAllNullableTypes(nullableListTypes); + + expect( + echoNullFilledObject?.aNullableMap, nullableListTypes.aNullableMap); + }); + testWidgets('errors are returned correctly', (WidgetTester _) async { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); From 5947fcdd63255072b81134b1b4a38ba6e365dd82 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Fri, 30 Jun 2023 14:01:59 -0700 Subject: [PATCH 05/14] not there yet --- .../mock_handler_tester/test/message.dart | 2 +- .../pigeon/mock_handler_tester/test/test.dart | 2 +- packages/pigeon/pigeons/core_tests.dart | 8 +- .../CoreTests.java | 51 +++++- .../AllDatatypesTest.java | 20 +++ .../ios/Classes/CoreTests.gen.h | 8 +- .../ios/Classes/CoreTests.gen.m | 13 +- .../macos/Classes/CoreTests.gen.h | 8 +- .../macos/Classes/CoreTests.gen.m | 13 +- .../lib/core_tests.gen.dart | 14 +- .../lib/flutter_unittests.gen.dart | 2 +- .../lib/multiple_arity.gen.dart | 2 +- .../lib/non_null_fields.gen.dart | 2 +- .../lib/null_fields.gen.dart | 2 +- .../lib/nullable_returns.gen.dart | 2 +- .../lib/primitive.gen.dart | 2 +- .../lib/integration_tests.dart | 168 ++++++++++-------- .../lib/src/generated/core_tests.gen.dart | 12 ++ .../com/example/test_plugin/CoreTests.gen.kt | 16 +- .../example/test_plugin/AllDatatypesTest.kt | 20 ++- .../ios/Classes/CoreTests.gen.swift | 19 +- .../test_plugin/ios/Classes/TestPlugin.swift | 2 +- .../macos/Classes/CoreTests.gen.swift | 19 +- .../macos/Classes/TestPlugin.swift | 2 +- .../windows/pigeon/core_tests.gen.cpp | 48 ++++- .../windows/pigeon/core_tests.gen.h | 17 +- 26 files changed, 351 insertions(+), 123 deletions(-) diff --git a/packages/pigeon/mock_handler_tester/test/message.dart b/packages/pigeon/mock_handler_tester/test/message.dart index ac7d0bf0ab7..de2b7db48b5 100644 --- a/packages/pigeon/mock_handler_tester/test/message.dart +++ b/packages/pigeon/mock_handler_tester/test/message.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.2.5), do not edit directly. +// Autogenerated from Pigeon (v10.1.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/mock_handler_tester/test/test.dart b/packages/pigeon/mock_handler_tester/test/test.dart index 31140756656..3af78ca43ca 100644 --- a/packages/pigeon/mock_handler_tester/test/test.dart +++ b/packages/pigeon/mock_handler_tester/test/test.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.2.5), do not edit directly. +// Autogenerated from Pigeon (v10.1.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import // ignore_for_file: avoid_relative_lib_imports diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index ac9fd7768dc..3ee2535e597 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -25,6 +25,7 @@ class AllTypes { this.aMap = const {}, this.anEnum = AnEnum.one, this.aString = '', + required this.aClass, }); bool aBool; @@ -41,6 +42,7 @@ class AllTypes { Map aMap; AnEnum anEnum; String aString; + AllNullableTypes aClass; } // A class containing all supported nullable types. @@ -61,6 +63,7 @@ class AllNullableTypes { this.nullableMapWithObject, this.aNullableEnum, this.aNullableString, + this.aNullableClass, ); bool? aNullableBool; @@ -80,6 +83,7 @@ class AllNullableTypes { Map? nullableMapWithObject; AnEnum? aNullableEnum; String? aNullableString; + AllTypes? aNullableClass; } // A class for testing nested object handling. @@ -92,7 +96,7 @@ class AllNullableTypesWrapper { /// platform_test integration tests. @HostApi() abstract class HostIntegrationCoreApi { - // ========== Syncronous method tests ========== + // ========== Synchronous method tests ========== /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. @@ -342,7 +346,7 @@ abstract class HostIntegrationCoreApi { /// Returns the passed map, to test serialization and deserialization asynchronously. @async @ObjCSelector('echoAsyncNullableMap:') - @SwiftFunction('echAsyncoNullable(_:)') + @SwiftFunction('echoAsyncNullable(_:)') Map? echoAsyncNullableMap(Map? aMap); // ========== Flutter API test wrappers ========== 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 8b8f6b5e261..8cff9596c0f 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 @@ -229,6 +229,19 @@ public void setAString(@NonNull String setterArg) { this.aString = setterArg; } + private @NonNull AllNullableTypes aClass; + + public @NonNull AllNullableTypes getAClass() { + return aClass; + } + + public void setAClass(@NonNull AllNullableTypes setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"aClass\" is null."); + } + this.aClass = setterArg; + } + /** Constructor is non-public to enforce null safety; use Builder. */ AllTypes() {} @@ -318,6 +331,13 @@ public static final class Builder { return this; } + private @Nullable AllNullableTypes aClass; + + public @NonNull Builder setAClass(@NonNull AllNullableTypes setterArg) { + this.aClass = setterArg; + return this; + } + public @NonNull AllTypes build() { AllTypes pigeonReturn = new AllTypes(); pigeonReturn.setABool(aBool); @@ -332,13 +352,14 @@ public static final class Builder { pigeonReturn.setAMap(aMap); pigeonReturn.setAnEnum(anEnum); pigeonReturn.setAString(aString); + pigeonReturn.setAClass(aClass); return pigeonReturn; } } @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(12); + ArrayList toListResult = new ArrayList(13); toListResult.add(aBool); toListResult.add(anInt); toListResult.add(anInt64); @@ -351,6 +372,7 @@ ArrayList toList() { toListResult.add(aMap); toListResult.add(anEnum == null ? null : anEnum.index); toListResult.add(aString); + toListResult.add((aClass == null) ? null : aClass.toList()); return toListResult; } @@ -384,6 +406,9 @@ ArrayList toList() { pigeonResult.setAnEnum(anEnum == null ? null : AnEnum.values()[(int) anEnum]); Object aString = list.get(11); pigeonResult.setAString((String) aString); + Object aClass = list.get(12); + pigeonResult.setAClass( + (aClass == null) ? null : AllNullableTypes.fromList((ArrayList) aClass)); return pigeonResult; } } @@ -540,6 +565,16 @@ public void setANullableString(@Nullable String setterArg) { this.aNullableString = setterArg; } + private @Nullable AllTypes aNullableClass; + + public @Nullable AllTypes getANullableClass() { + return aNullableClass; + } + + public void setANullableClass(@Nullable AllTypes setterArg) { + this.aNullableClass = setterArg; + } + public static final class Builder { private @Nullable Boolean aNullableBool; @@ -648,6 +683,13 @@ public static final class Builder { return this; } + private @Nullable AllTypes aNullableClass; + + public @NonNull Builder setANullableClass(@Nullable AllTypes setterArg) { + this.aNullableClass = setterArg; + return this; + } + public @NonNull AllNullableTypes build() { AllNullableTypes pigeonReturn = new AllNullableTypes(); pigeonReturn.setANullableBool(aNullableBool); @@ -665,13 +707,14 @@ public static final class Builder { pigeonReturn.setNullableMapWithObject(nullableMapWithObject); pigeonReturn.setANullableEnum(aNullableEnum); pigeonReturn.setANullableString(aNullableString); + pigeonReturn.setANullableClass(aNullableClass); return pigeonReturn; } } @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(15); + ArrayList toListResult = new ArrayList(16); toListResult.add(aNullableBool); toListResult.add(aNullableInt); toListResult.add(aNullableInt64); @@ -687,6 +730,7 @@ ArrayList toList() { toListResult.add(nullableMapWithObject); toListResult.add(aNullableEnum == null ? null : aNullableEnum.index); toListResult.add(aNullableString); + toListResult.add((aNullableClass == null) ? null : aNullableClass.toList()); return toListResult; } @@ -731,6 +775,9 @@ ArrayList toList() { aNullableEnum == null ? null : AnEnum.values()[(int) aNullableEnum]); Object aNullableString = list.get(14); pigeonResult.setANullableString((String) aNullableString); + Object aNullableClass = list.get(15); + pigeonResult.setANullableClass( + (aNullableClass == null) ? null : AllTypes.fromList((ArrayList) aNullableClass)); return pigeonResult; } } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java index e2d6414ad9d..42b73100903 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java @@ -8,6 +8,7 @@ import static org.mockito.Mockito.*; import com.example.alternate_language_test_plugin.CoreTests.AllNullableTypes; +import com.example.alternate_language_test_plugin.CoreTests.AllTypes; import com.example.alternate_language_test_plugin.CoreTests.FlutterIntegrationCoreApi; import io.flutter.plugin.common.BinaryMessenger; import java.nio.ByteBuffer; @@ -54,6 +55,7 @@ public void nullValues() { assertNull(everything.getANullableList()); assertNull(everything.getANullableMap()); assertNull(everything.getNullableMapWithObject()); + assertNull(everything.getANullableClass()); }); assertTrue(didCall[0]); } @@ -84,6 +86,19 @@ private static boolean floatArraysEqual(double[] x, double[] y) { @Test public void hasValues() { + AllTypes allEverything = new AllTypes(); + allEverything.setABool(false); + allEverything.setAnInt(1234L); + allEverything.setADouble(2.0); + allEverything.setAString("hello"); + allEverything.setAByteArray(new byte[] {1, 2, 3, 4}); + allEverything.setA4ByteArray(new int[] {1, 2, 3, 4}); + allEverything.setA8ByteArray(new long[] {1, 2, 3, 4}); + allEverything.setAFloatArray(new double[] {0.5, 0.25, 1.5, 1.25}); + allEverything.setAList(Arrays.asList(new int[] {1, 2, 3})); + allEverything.setAMap(makeMap("hello", 1234)); + allEverything.setAClass(new AllNullableTypes()); + AllNullableTypes everything = new AllNullableTypes(); everything.setANullableBool(false); everything.setANullableInt(1234L); @@ -96,6 +111,8 @@ public void hasValues() { everything.setANullableList(Arrays.asList(new int[] {1, 2, 3})); everything.setANullableMap(makeMap("hello", 1234)); everything.setNullableMapWithObject(makeStringMap("hello", 1234)); + everything.setANullableClass(allEverything); + BinaryMessenger binaryMessenger = mock(BinaryMessenger.class); doAnswer( invocation -> { @@ -140,6 +157,9 @@ public void hasValues() { assertArrayEquals( everything.getNullableMapWithObject().values().toArray(), result.getNullableMapWithObject().values().toArray()); + // assertThat(everything.getANullableClass()) + // .usingRecursiveComparison() + // .isEqualTo(result.getANullableClass()); }); assertTrue(didCall[0]); } 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 cbe0a6a80f4..e984aadb2bf 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 @@ -39,7 +39,8 @@ typedef NS_ENUM(NSUInteger, AnEnum) { aList:(NSArray *)aList aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum - aString:(NSString *)aString; + aString:(NSString *)aString + aClass:(AllNullableTypes *)aClass; @property(nonatomic, strong) NSNumber *aBool; @property(nonatomic, strong) NSNumber *anInt; @property(nonatomic, strong) NSNumber *anInt64; @@ -52,6 +53,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong) NSDictionary *aMap; @property(nonatomic, assign) AnEnum anEnum; @property(nonatomic, copy) NSString *aString; +@property(nonatomic, strong) AllNullableTypes *aClass; @end @interface AllNullableTypes : NSObject @@ -70,7 +72,8 @@ typedef NS_ENUM(NSUInteger, AnEnum) { (nullable NSDictionary *)nullableMapWithAnnotations nullableMapWithObject:(nullable NSDictionary *)nullableMapWithObject aNullableEnum:(AnEnum)aNullableEnum - aNullableString:(nullable NSString *)aNullableString; + aNullableString:(nullable NSString *)aNullableString + aNullableClass:(nullable AllTypes *)aNullableClass; @property(nonatomic, strong, nullable) NSNumber *aNullableBool; @property(nonatomic, strong, nullable) NSNumber *aNullableInt; @property(nonatomic, strong, nullable) NSNumber *aNullableInt64; @@ -87,6 +90,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong, nullable) NSDictionary *nullableMapWithObject; @property(nonatomic, assign) AnEnum aNullableEnum; @property(nonatomic, copy, nullable) NSString *aNullableString; +@property(nonatomic, strong, nullable) AllTypes *aNullableClass; @end @interface AllNullableTypesWrapper : NSObject 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 34c07a7a091..1c5fadaed47 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 @@ -66,7 +66,8 @@ + (instancetype)makeWithABool:(NSNumber *)aBool aList:(NSArray *)aList aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum - aString:(NSString *)aString { + aString:(NSString *)aString + aClass:(AllNullableTypes *)aClass { AllTypes *pigeonResult = [[AllTypes alloc] init]; pigeonResult.aBool = aBool; pigeonResult.anInt = anInt; @@ -80,6 +81,7 @@ + (instancetype)makeWithABool:(NSNumber *)aBool pigeonResult.aMap = aMap; pigeonResult.anEnum = anEnum; pigeonResult.aString = aString; + pigeonResult.aClass = aClass; return pigeonResult; } + (AllTypes *)fromList:(NSArray *)list { @@ -107,6 +109,8 @@ + (AllTypes *)fromList:(NSArray *)list { pigeonResult.anEnum = [GetNullableObjectAtIndex(list, 10) integerValue]; pigeonResult.aString = GetNullableObjectAtIndex(list, 11); NSAssert(pigeonResult.aString != nil, @""); + pigeonResult.aClass = [AllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 12))]; + NSAssert(pigeonResult.aClass != nil, @""); return pigeonResult; } + (nullable AllTypes *)nullableFromList:(NSArray *)list { @@ -126,6 +130,7 @@ - (NSArray *)toList { (self.aMap ?: [NSNull null]), @(self.anEnum), (self.aString ?: [NSNull null]), + (self.aClass ? [self.aClass toList] : [NSNull null]), ]; } @end @@ -146,7 +151,8 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool (nullable NSDictionary *)nullableMapWithAnnotations nullableMapWithObject:(nullable NSDictionary *)nullableMapWithObject aNullableEnum:(AnEnum)aNullableEnum - aNullableString:(nullable NSString *)aNullableString { + aNullableString:(nullable NSString *)aNullableString + aNullableClass:(nullable AllTypes *)aNullableClass { AllNullableTypes *pigeonResult = [[AllNullableTypes alloc] init]; pigeonResult.aNullableBool = aNullableBool; pigeonResult.aNullableInt = aNullableInt; @@ -163,6 +169,7 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool pigeonResult.nullableMapWithObject = nullableMapWithObject; pigeonResult.aNullableEnum = aNullableEnum; pigeonResult.aNullableString = aNullableString; + pigeonResult.aNullableClass = aNullableClass; return pigeonResult; } + (AllNullableTypes *)fromList:(NSArray *)list { @@ -182,6 +189,7 @@ + (AllNullableTypes *)fromList:(NSArray *)list { pigeonResult.nullableMapWithObject = GetNullableObjectAtIndex(list, 12); pigeonResult.aNullableEnum = [GetNullableObjectAtIndex(list, 13) integerValue]; pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 14); + pigeonResult.aNullableClass = [AllTypes nullableFromList:(GetNullableObjectAtIndex(list, 15))]; return pigeonResult; } + (nullable AllNullableTypes *)nullableFromList:(NSArray *)list { @@ -204,6 +212,7 @@ - (NSArray *)toList { (self.nullableMapWithObject ?: [NSNull null]), @(self.aNullableEnum), (self.aNullableString ?: [NSNull null]), + (self.aNullableClass ? [self.aNullableClass toList] : [NSNull null]), ]; } @end diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h index cbe0a6a80f4..e984aadb2bf 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h @@ -39,7 +39,8 @@ typedef NS_ENUM(NSUInteger, AnEnum) { aList:(NSArray *)aList aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum - aString:(NSString *)aString; + aString:(NSString *)aString + aClass:(AllNullableTypes *)aClass; @property(nonatomic, strong) NSNumber *aBool; @property(nonatomic, strong) NSNumber *anInt; @property(nonatomic, strong) NSNumber *anInt64; @@ -52,6 +53,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong) NSDictionary *aMap; @property(nonatomic, assign) AnEnum anEnum; @property(nonatomic, copy) NSString *aString; +@property(nonatomic, strong) AllNullableTypes *aClass; @end @interface AllNullableTypes : NSObject @@ -70,7 +72,8 @@ typedef NS_ENUM(NSUInteger, AnEnum) { (nullable NSDictionary *)nullableMapWithAnnotations nullableMapWithObject:(nullable NSDictionary *)nullableMapWithObject aNullableEnum:(AnEnum)aNullableEnum - aNullableString:(nullable NSString *)aNullableString; + aNullableString:(nullable NSString *)aNullableString + aNullableClass:(nullable AllTypes *)aNullableClass; @property(nonatomic, strong, nullable) NSNumber *aNullableBool; @property(nonatomic, strong, nullable) NSNumber *aNullableInt; @property(nonatomic, strong, nullable) NSNumber *aNullableInt64; @@ -87,6 +90,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong, nullable) NSDictionary *nullableMapWithObject; @property(nonatomic, assign) AnEnum aNullableEnum; @property(nonatomic, copy, nullable) NSString *aNullableString; +@property(nonatomic, strong, nullable) AllTypes *aNullableClass; @end @interface AllNullableTypesWrapper : NSObject diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m index 34c07a7a091..1c5fadaed47 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m @@ -66,7 +66,8 @@ + (instancetype)makeWithABool:(NSNumber *)aBool aList:(NSArray *)aList aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum - aString:(NSString *)aString { + aString:(NSString *)aString + aClass:(AllNullableTypes *)aClass { AllTypes *pigeonResult = [[AllTypes alloc] init]; pigeonResult.aBool = aBool; pigeonResult.anInt = anInt; @@ -80,6 +81,7 @@ + (instancetype)makeWithABool:(NSNumber *)aBool pigeonResult.aMap = aMap; pigeonResult.anEnum = anEnum; pigeonResult.aString = aString; + pigeonResult.aClass = aClass; return pigeonResult; } + (AllTypes *)fromList:(NSArray *)list { @@ -107,6 +109,8 @@ + (AllTypes *)fromList:(NSArray *)list { pigeonResult.anEnum = [GetNullableObjectAtIndex(list, 10) integerValue]; pigeonResult.aString = GetNullableObjectAtIndex(list, 11); NSAssert(pigeonResult.aString != nil, @""); + pigeonResult.aClass = [AllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 12))]; + NSAssert(pigeonResult.aClass != nil, @""); return pigeonResult; } + (nullable AllTypes *)nullableFromList:(NSArray *)list { @@ -126,6 +130,7 @@ - (NSArray *)toList { (self.aMap ?: [NSNull null]), @(self.anEnum), (self.aString ?: [NSNull null]), + (self.aClass ? [self.aClass toList] : [NSNull null]), ]; } @end @@ -146,7 +151,8 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool (nullable NSDictionary *)nullableMapWithAnnotations nullableMapWithObject:(nullable NSDictionary *)nullableMapWithObject aNullableEnum:(AnEnum)aNullableEnum - aNullableString:(nullable NSString *)aNullableString { + aNullableString:(nullable NSString *)aNullableString + aNullableClass:(nullable AllTypes *)aNullableClass { AllNullableTypes *pigeonResult = [[AllNullableTypes alloc] init]; pigeonResult.aNullableBool = aNullableBool; pigeonResult.aNullableInt = aNullableInt; @@ -163,6 +169,7 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool pigeonResult.nullableMapWithObject = nullableMapWithObject; pigeonResult.aNullableEnum = aNullableEnum; pigeonResult.aNullableString = aNullableString; + pigeonResult.aNullableClass = aNullableClass; return pigeonResult; } + (AllNullableTypes *)fromList:(NSArray *)list { @@ -182,6 +189,7 @@ + (AllNullableTypes *)fromList:(NSArray *)list { pigeonResult.nullableMapWithObject = GetNullableObjectAtIndex(list, 12); pigeonResult.aNullableEnum = [GetNullableObjectAtIndex(list, 13) integerValue]; pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 14); + pigeonResult.aNullableClass = [AllTypes nullableFromList:(GetNullableObjectAtIndex(list, 15))]; return pigeonResult; } + (nullable AllNullableTypes *)nullableFromList:(NSArray *)list { @@ -204,6 +212,7 @@ - (NSArray *)toList { (self.nullableMapWithObject ?: [NSNull null]), @(self.aNullableEnum), (self.aNullableString ?: [NSNull null]), + (self.aNullableClass ? [self.aNullableClass toList] : [NSNull null]), ]; } @end diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart index 8cd39604220..7808355ecd0 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.2.5), do not edit directly. +// Autogenerated from Pigeon (v10.1.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import @@ -32,6 +32,7 @@ class AllTypes { required this.aMap, required this.anEnum, required this.aString, + required this.aClass, }); bool aBool; @@ -58,6 +59,8 @@ class AllTypes { String aString; + AllNullableTypes aClass; + Object encode() { return [ aBool, @@ -72,6 +75,7 @@ class AllTypes { aMap, anEnum.index, aString, + aClass.encode(), ]; } @@ -90,6 +94,7 @@ class AllTypes { aMap: result[9]! as Map, anEnum: AnEnum.values[result[10]! as int], aString: result[11]! as String, + aClass: AllNullableTypes.decode(result[12]! as List), ); } } @@ -111,6 +116,7 @@ class AllNullableTypes { this.nullableMapWithObject, this.aNullableEnum, this.aNullableString, + this.aNullableClass, }); bool? aNullableBool; @@ -143,6 +149,8 @@ class AllNullableTypes { String? aNullableString; + AllTypes? aNullableClass; + Object encode() { return [ aNullableBool, @@ -160,6 +168,7 @@ class AllNullableTypes { nullableMapWithObject, aNullableEnum?.index, aNullableString, + aNullableClass?.encode(), ]; } @@ -184,6 +193,9 @@ class AllNullableTypes { aNullableEnum: result[13] != null ? AnEnum.values[result[13]! as int] : null, aNullableString: result[14] as String?, + aNullableClass: result[15] != null + ? AllTypes.decode(result[15]! as List) + : null, ); } } diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart index f8e8b21584f..fc3f96d8c50 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.2.5), do not edit directly. +// Autogenerated from Pigeon (v10.1.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart index 6cfd7a3ece5..9790d321d4b 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.2.5), do not edit directly. +// Autogenerated from Pigeon (v10.1.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart index 6fa2ee5d5f5..8c344ea4649 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.2.5), do not edit directly. +// Autogenerated from Pigeon (v10.1.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart index 379e13700b2..77a0e1e0c4c 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.2.5), do not edit directly. +// Autogenerated from Pigeon (v10.1.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart index 50ae58f3bda..f001b42b1a8 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.2.5), do not edit directly. +// Autogenerated from Pigeon (v10.1.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart index c5981a987d9..1590e7c575a 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.2.5), do not edit directly. +// Autogenerated from Pigeon (v10.1.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import 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 92b40c9c537..5f1a402bf18 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 @@ -49,9 +49,16 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { a4ByteArray: Int32List.fromList([4, 5, 6]), a8ByteArray: Int64List.fromList([7, 8, 9]), aFloatArray: Float64List.fromList([2.71828, _doublePi]), - aList: ['Thing 1', 2, true, 3.14], - aMap: {'a': 1, 'b': 2.0, 'c': 'three', 'd': false}, + aList: ['Thing 1', 2, true, 3.14, null], + aMap: { + 'a': 1, + 'b': 2.0, + 'c': 'three', + 'd': false, + 'e': null + }, anEnum: AnEnum.two, + aClass: AllNullableTypes(aNullableInt64: 1), ); final AllNullableTypes genericAllNullableTypes = AllNullableTypes( @@ -64,12 +71,13 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { aNullable4ByteArray: Int32List.fromList([4, 5, 6]), aNullable8ByteArray: Int64List.fromList([7, 8, 9]), aNullableFloatArray: Float64List.fromList([2.71828, _doublePi]), - aNullableList: ['Thing 1', 2, true, 3.14], + aNullableList: ['Thing 1', 2, true, 3.14, null], aNullableMap: { 'a': 1, 'b': 2.0, 'c': 'three', - 'd': false + 'd': false, + 'e': null }, nullableNestedList: >[ [true, false], @@ -78,6 +86,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { nullableMapWithAnnotations: {}, nullableMapWithObject: {}, aNullableEnum: AnEnum.two, + aNullableClass: genericAllTypes, ); group('Host sync API tests', () { @@ -105,6 +114,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect(listEquals(echoObject.aList, genericAllTypes.aList), true); expect(mapEquals(echoObject.aMap, genericAllTypes.aMap), true); expect(echoObject.anEnum, genericAllTypes.anEnum); + expect(echoObject.aClass, genericAllTypes.aClass); }); testWidgets('all nullable datatypes serialize and deserialize correctly', @@ -154,6 +164,8 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { genericAllNullableTypes.nullableMapWithObject), true); expect(echoObject?.aNullableEnum, genericAllNullableTypes.aNullableEnum); + expect( + echoObject?.aNullableClass, genericAllNullableTypes.aNullableClass); }); testWidgets('all null datatypes serialize and deserialize correctly', @@ -162,76 +174,77 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes allTypesNull = AllNullableTypes(); - final AllNullableTypes? echoNullFilledObject = + final AllNullableTypes? echoNullFilledClass = await api.echoAllNullableTypes(allTypesNull); - expect(echoNullFilledObject?.aNullableBool, allTypesNull.aNullableBool); - expect(echoNullFilledObject?.aNullableBool, null); + expect(echoNullFilledClass?.aNullableBool, allTypesNull.aNullableBool); + expect(echoNullFilledClass?.aNullableBool, null); - expect(echoNullFilledObject?.aNullableInt, allTypesNull.aNullableInt); - expect(echoNullFilledObject?.aNullableInt, null); + expect(echoNullFilledClass?.aNullableInt, allTypesNull.aNullableInt); + expect(echoNullFilledClass?.aNullableInt, null); - expect(echoNullFilledObject?.aNullableInt64, allTypesNull.aNullableInt64); - expect(echoNullFilledObject?.aNullableInt64, null); + expect(echoNullFilledClass?.aNullableInt64, allTypesNull.aNullableInt64); + expect(echoNullFilledClass?.aNullableInt64, null); expect( - echoNullFilledObject?.aNullableDouble, allTypesNull.aNullableDouble); - expect(echoNullFilledObject?.aNullableDouble, null); + echoNullFilledClass?.aNullableDouble, allTypesNull.aNullableDouble); + expect(echoNullFilledClass?.aNullableDouble, null); expect( - echoNullFilledObject?.aNullableString, allTypesNull.aNullableString); - expect(echoNullFilledObject?.aNullableString, null); + echoNullFilledClass?.aNullableString, allTypesNull.aNullableString); + expect(echoNullFilledClass?.aNullableString, null); - expect(echoNullFilledObject?.aNullableByteArray, + expect(echoNullFilledClass?.aNullableByteArray, allTypesNull.aNullableByteArray); - expect(echoNullFilledObject?.aNullableByteArray, null); + expect(echoNullFilledClass?.aNullableByteArray, null); - expect(echoNullFilledObject?.aNullable4ByteArray, + expect(echoNullFilledClass?.aNullable4ByteArray, allTypesNull.aNullable4ByteArray); - expect(echoNullFilledObject?.aNullable4ByteArray, null); + expect(echoNullFilledClass?.aNullable4ByteArray, null); - expect(echoNullFilledObject?.aNullable8ByteArray, + expect(echoNullFilledClass?.aNullable8ByteArray, allTypesNull.aNullable8ByteArray); - expect(echoNullFilledObject?.aNullable8ByteArray, null); + expect(echoNullFilledClass?.aNullable8ByteArray, null); - expect(echoNullFilledObject?.aNullableFloatArray, + expect(echoNullFilledClass?.aNullableFloatArray, allTypesNull.aNullableFloatArray); - expect(echoNullFilledObject?.aNullableFloatArray, null); + expect(echoNullFilledClass?.aNullableFloatArray, null); expect( listEquals( - echoNullFilledObject?.aNullableList, allTypesNull.aNullableList), + echoNullFilledClass?.aNullableList, allTypesNull.aNullableList), true); - expect(echoNullFilledObject?.aNullableList, null); + expect(echoNullFilledClass?.aNullableList, null); expect( mapEquals( - echoNullFilledObject?.aNullableMap, allTypesNull.aNullableMap), + echoNullFilledClass?.aNullableMap, allTypesNull.aNullableMap), true); - expect(echoNullFilledObject?.aNullableMap, null); + expect(echoNullFilledClass?.aNullableMap, null); // TODO(stuartmorgan): Enable this once the Dart types are fixed; see // https://github.com/flutter/flutter/issues/116117 - //for (int i = 0; i < echoNullFilledObject?.nullableNestedList!.length; i++) { - // expect(listEquals(echoNullFilledObject?.nullableNestedList![i], allTypesNull.nullableNestedList![i]), + //for (int i = 0; i < echoNullFilledClass?.nullableNestedList!.length; i++) { + // expect(listEquals(echoNullFilledClass?.nullableNestedList![i], allTypesNull.nullableNestedList![i]), // true); //} - expect(echoNullFilledObject?.nullableNestedList, null); + expect(echoNullFilledClass?.nullableNestedList, null); expect( - mapEquals(echoNullFilledObject?.nullableMapWithAnnotations, + mapEquals(echoNullFilledClass?.nullableMapWithAnnotations, allTypesNull.nullableMapWithAnnotations), true); - expect(echoNullFilledObject?.nullableMapWithAnnotations, null); + expect(echoNullFilledClass?.nullableMapWithAnnotations, null); expect( - mapEquals(echoNullFilledObject?.nullableMapWithObject, + mapEquals(echoNullFilledClass?.nullableMapWithObject, allTypesNull.nullableMapWithObject), true); - expect(echoNullFilledObject?.nullableMapWithObject, null); + expect(echoNullFilledClass?.nullableMapWithObject, null); - expect(echoNullFilledObject?.aNullableEnum, allTypesNull.aNullableEnum); - expect(echoNullFilledObject?.aNullableEnum, null); + expect(echoNullFilledClass?.aNullableEnum, allTypesNull.aNullableEnum); + expect(echoNullFilledClass?.aNullableEnum, null); + expect(echoNullFilledClass?.aNullableClass, allTypesNull.aNullableClass); }, // TODO(stuartmorgan): Fix and re-enable. // See https://github.com/flutter/flutter/issues/118733 @@ -244,11 +257,11 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes nullableListTypes = AllNullableTypes(aNullableList: ['String', null]); - final AllNullableTypes? echoNullFilledObject = + final AllNullableTypes? echoNullFilledClass = await api.echoAllNullableTypes(nullableListTypes); expect( - echoNullFilledObject?.aNullableList, nullableListTypes.aNullableList); + echoNullFilledClass?.aNullableList, nullableListTypes.aNullableList); }); testWidgets('Classes with map of null serialize and deserialize correctly', @@ -258,11 +271,10 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes nullableListTypes = AllNullableTypes( aNullableMap: {'String': 'string', 'null': null}); - final AllNullableTypes? echoNullFilledObject = + final AllNullableTypes? echoNullFilledClass = await api.echoAllNullableTypes(nullableListTypes); - expect( - echoNullFilledObject?.aNullableMap, nullableListTypes.aNullableMap); + expect(echoNullFilledClass?.aNullableMap, nullableListTypes.aNullableMap); }); testWidgets('errors are returned correctly', (WidgetTester _) async { @@ -336,11 +348,11 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { (WidgetTester _) async { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); - final AllNullableTypes echoNullFilledObject = + final AllNullableTypes echoNullFilledClass = await api.sendMultipleNullableTypes(null, null, null); - expect(echoNullFilledObject.aNullableInt, null); - expect(echoNullFilledObject.aNullableBool, null); - expect(echoNullFilledObject.aNullableString, null); + expect(echoNullFilledClass.aNullableInt, null); + expect(echoNullFilledClass.aNullableBool, null); + expect(echoNullFilledClass.aNullableString, null); }); testWidgets('Int serialize and deserialize correctly', @@ -729,76 +741,77 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes allTypesNull = AllNullableTypes(); - final AllNullableTypes? echoNullFilledObject = + final AllNullableTypes? echoNullFilledClass = await api.echoAsyncNullableAllNullableTypes(allTypesNull); - expect(echoNullFilledObject?.aNullableBool, allTypesNull.aNullableBool); - expect(echoNullFilledObject?.aNullableBool, null); + expect(echoNullFilledClass?.aNullableBool, allTypesNull.aNullableBool); + expect(echoNullFilledClass?.aNullableBool, null); - expect(echoNullFilledObject?.aNullableInt, allTypesNull.aNullableInt); - expect(echoNullFilledObject?.aNullableInt, null); + expect(echoNullFilledClass?.aNullableInt, allTypesNull.aNullableInt); + expect(echoNullFilledClass?.aNullableInt, null); - expect(echoNullFilledObject?.aNullableInt64, allTypesNull.aNullableInt64); - expect(echoNullFilledObject?.aNullableInt64, null); + expect(echoNullFilledClass?.aNullableInt64, allTypesNull.aNullableInt64); + expect(echoNullFilledClass?.aNullableInt64, null); expect( - echoNullFilledObject?.aNullableDouble, allTypesNull.aNullableDouble); - expect(echoNullFilledObject?.aNullableDouble, null); + echoNullFilledClass?.aNullableDouble, allTypesNull.aNullableDouble); + expect(echoNullFilledClass?.aNullableDouble, null); expect( - echoNullFilledObject?.aNullableString, allTypesNull.aNullableString); - expect(echoNullFilledObject?.aNullableString, null); + echoNullFilledClass?.aNullableString, allTypesNull.aNullableString); + expect(echoNullFilledClass?.aNullableString, null); - expect(echoNullFilledObject?.aNullableByteArray, + expect(echoNullFilledClass?.aNullableByteArray, allTypesNull.aNullableByteArray); - expect(echoNullFilledObject?.aNullableByteArray, null); + expect(echoNullFilledClass?.aNullableByteArray, null); - expect(echoNullFilledObject?.aNullable4ByteArray, + expect(echoNullFilledClass?.aNullable4ByteArray, allTypesNull.aNullable4ByteArray); - expect(echoNullFilledObject?.aNullable4ByteArray, null); + expect(echoNullFilledClass?.aNullable4ByteArray, null); - expect(echoNullFilledObject?.aNullable8ByteArray, + expect(echoNullFilledClass?.aNullable8ByteArray, allTypesNull.aNullable8ByteArray); - expect(echoNullFilledObject?.aNullable8ByteArray, null); + expect(echoNullFilledClass?.aNullable8ByteArray, null); - expect(echoNullFilledObject?.aNullableFloatArray, + expect(echoNullFilledClass?.aNullableFloatArray, allTypesNull.aNullableFloatArray); - expect(echoNullFilledObject?.aNullableFloatArray, null); + expect(echoNullFilledClass?.aNullableFloatArray, null); expect( listEquals( - echoNullFilledObject?.aNullableList, allTypesNull.aNullableList), + echoNullFilledClass?.aNullableList, allTypesNull.aNullableList), true); - expect(echoNullFilledObject?.aNullableList, null); + expect(echoNullFilledClass?.aNullableList, null); expect( mapEquals( - echoNullFilledObject?.aNullableMap, allTypesNull.aNullableMap), + echoNullFilledClass?.aNullableMap, allTypesNull.aNullableMap), true); - expect(echoNullFilledObject?.aNullableMap, null); + expect(echoNullFilledClass?.aNullableMap, null); // TODO(stuartmorgan): Enable this once the Dart types are fixed; see // https://github.com/flutter/flutter/issues/116117 - //for (int i = 0; i < echoNullFilledObject?.nullableNestedList!.length; i++) { - // expect(listEquals(echoNullFilledObject?.nullableNestedList![i], allTypesNull.nullableNestedList![i]), + //for (int i = 0; i < echoNullFilledClass?.nullableNestedList!.length; i++) { + // expect(listEquals(echoNullFilledClass?.nullableNestedList![i], allTypesNull.nullableNestedList![i]), // true); //} - expect(echoNullFilledObject?.nullableNestedList, null); + expect(echoNullFilledClass?.nullableNestedList, null); expect( - mapEquals(echoNullFilledObject?.nullableMapWithAnnotations, + mapEquals(echoNullFilledClass?.nullableMapWithAnnotations, allTypesNull.nullableMapWithAnnotations), true); - expect(echoNullFilledObject?.nullableMapWithAnnotations, null); + expect(echoNullFilledClass?.nullableMapWithAnnotations, null); expect( - mapEquals(echoNullFilledObject?.nullableMapWithObject, + mapEquals(echoNullFilledClass?.nullableMapWithObject, allTypesNull.nullableMapWithObject), true); - expect(echoNullFilledObject?.nullableMapWithObject, null); + expect(echoNullFilledClass?.nullableMapWithObject, null); - expect(echoNullFilledObject?.aNullableEnum, allTypesNull.aNullableEnum); - expect(echoNullFilledObject?.aNullableEnum, null); + expect(echoNullFilledClass?.aNullableEnum, allTypesNull.aNullableEnum); + expect(echoNullFilledClass?.aNullableEnum, null); + expect(echoNullFilledClass?.aNullableClass, allTypesNull.aNullableClass); }, // TODO(stuartmorgan): Fix and re-enable. // See https://github.com/flutter/flutter/issues/118733 @@ -1141,6 +1154,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect(listEquals(echoObject.aList, genericAllTypes.aList), true); expect(mapEquals(echoObject.aMap, genericAllTypes.aMap), true); expect(echoObject.anEnum, genericAllTypes.anEnum); + expect(echoObject.aClass, genericAllNullableTypes.aNullableClass); }); testWidgets( 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 d6878146198..dc7962773f3 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 @@ -32,6 +32,7 @@ class AllTypes { required this.aMap, required this.anEnum, required this.aString, + required this.aClass, }); bool aBool; @@ -58,6 +59,8 @@ class AllTypes { String aString; + AllNullableTypes aClass; + Object encode() { return [ aBool, @@ -72,6 +75,7 @@ class AllTypes { aMap, anEnum.index, aString, + aClass.encode(), ]; } @@ -90,6 +94,7 @@ class AllTypes { aMap: result[9]! as Map, anEnum: AnEnum.values[result[10]! as int], aString: result[11]! as String, + aClass: AllNullableTypes.decode(result[12]! as List), ); } } @@ -111,6 +116,7 @@ class AllNullableTypes { this.nullableMapWithObject, this.aNullableEnum, this.aNullableString, + this.aNullableClass, }); bool? aNullableBool; @@ -143,6 +149,8 @@ class AllNullableTypes { String? aNullableString; + AllTypes? aNullableClass; + Object encode() { return [ aNullableBool, @@ -160,6 +168,7 @@ class AllNullableTypes { nullableMapWithObject, aNullableEnum?.index, aNullableString, + aNullableClass?.encode(), ]; } @@ -184,6 +193,9 @@ class AllNullableTypes { aNullableEnum: result[13] != null ? AnEnum.values[result[13]! as int] : null, aNullableString: result[14] as String?, + aNullableClass: result[15] != null + ? AllTypes.decode(result[15]! as List) + : null, ); } } 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 eaf7359de6a..4d12d214aa3 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 @@ -72,7 +72,8 @@ data class AllTypes ( val aList: List, val aMap: Map, val anEnum: AnEnum, - val aString: String + val aString: String, + val aClass: AllNullableTypes ) { companion object { @@ -90,7 +91,8 @@ data class AllTypes ( val aMap = list[9] as Map val anEnum = AnEnum.ofRaw(list[10] as Int)!! val aString = list[11] as String - return AllTypes(aBool, anInt, anInt64, aDouble, aByteArray, a4ByteArray, a8ByteArray, aFloatArray, aList, aMap, anEnum, aString) + val aClass = AllNullableTypes.fromList(list[12] as List) + return AllTypes(aBool, anInt, anInt64, aDouble, aByteArray, a4ByteArray, a8ByteArray, aFloatArray, aList, aMap, anEnum, aString, aClass) } } fun toList(): List { @@ -107,6 +109,7 @@ data class AllTypes ( aMap, anEnum.raw, aString, + aClass.toList(), ) } } @@ -127,7 +130,8 @@ data class AllNullableTypes ( val nullableMapWithAnnotations: Map? = null, val nullableMapWithObject: Map? = null, val aNullableEnum: AnEnum? = null, - val aNullableString: String? = null + val aNullableString: String? = null, + val aNullableClass: AllTypes? = null ) { companion object { @@ -150,7 +154,10 @@ data class AllNullableTypes ( AnEnum.ofRaw(it) } val aNullableString = list[14] as String? - return AllNullableTypes(aNullableBool, aNullableInt, aNullableInt64, aNullableDouble, aNullableByteArray, aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, aNullableList, aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, aNullableEnum, aNullableString) + val aNullableClass: AllTypes? = (list[15] as List?)?.let { + AllTypes.fromList(it) + } + return AllNullableTypes(aNullableBool, aNullableInt, aNullableInt64, aNullableDouble, aNullableByteArray, aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, aNullableList, aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, aNullableEnum, aNullableString, aNullableClass) } } fun toList(): List { @@ -170,6 +177,7 @@ data class AllNullableTypes ( nullableMapWithObject, aNullableEnum?.raw, aNullableString, + aNullableClass?.toList(), ) } } diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt index 62833efd5df..6faa1ff4f13 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt @@ -45,6 +45,7 @@ internal class AllDatatypesTest: TestCase() { assertNull(it.aNullableList) assertNull(it.aNullableMap) assertNull(it.nullableMapWithObject) + assertNull(it.aNullableClass) } assertTrue(didCall) @@ -63,7 +64,21 @@ internal class AllDatatypesTest: TestCase() { aNullableFloatArray = doubleArrayOf(0.5, 0.25, 1.5, 1.25), aNullableList = listOf(1, 2, 3), aNullableMap = mapOf("hello" to 1234), - nullableMapWithObject = mapOf("hello" to 1234) + nullableMapWithObject = mapOf("hello" to 1234), + aNullableClass = AllTypes( + true, + 1234L, + 2.0, + "hello", + byteArrayOf(1, 2, 3, 4), + intArrayOf(1, 2, 3, 4), + longArrayOf(1, 2, 3, 4), + doubleArrayOf(0.5, 0.25, 1.5, 1.25), + listOf(1, 2, 3), + mapOf("hello" to 1234), + mapOf("hello" to 1234), + AllNullableTypes() + ), ) val binaryMessenger = mockk() val api = FlutterIntegrationCoreApi(binaryMessenger) @@ -93,6 +108,7 @@ internal class AllDatatypesTest: TestCase() { assertEquals(everything.aNullableList, it.aNullableList) assertEquals(everything.aNullableMap, it.aNullableMap) assertEquals(everything.nullableMapWithObject, it.nullableMapWithObject) + assertEquals(everything.aNullableClass, it.aNullableClass) } assertTrue(didCall) @@ -107,7 +123,7 @@ internal class AllDatatypesTest: TestCase() { assertNotNull(list[1]) assertTrue(list[1] == 123L) - val list2 = listOf(null, 123, null, null, null, null, null, null, null, null, null, null, null, null, null) + val list2 = listOf(null, 123, null, null, null, null, null, null, null, null, null, null, null, null, null, null) val everything2 = AllNullableTypes.fromList(list2) assertEquals(everything.aNullableInt, everything2.aNullableInt) 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 2590ee6aa87..b407926ca29 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 @@ -58,6 +58,7 @@ struct AllTypes { var aMap: [AnyHashable: Any?] var anEnum: AnEnum var aString: String + var aClass: AllNullableTypes static func fromList(_ list: [Any?]) -> AllTypes? { let aBool = list[0] as! Bool @@ -72,6 +73,7 @@ struct AllTypes { let aMap = list[9] as! [AnyHashable: Any?] let anEnum = AnEnum(rawValue: list[10] as! Int)! let aString = list[11] as! String + let aClass = AllNullableTypes.fromList(list[12] as! [Any?])! return AllTypes( aBool: aBool, @@ -85,7 +87,8 @@ struct AllTypes { aList: aList, aMap: aMap, anEnum: anEnum, - aString: aString + aString: aString, + aClass: aClass ) } func toList() -> [Any?] { @@ -102,6 +105,7 @@ struct AllTypes { aMap, anEnum.rawValue, aString, + aClass.toList(), ] } } @@ -123,6 +127,7 @@ struct AllNullableTypes { var nullableMapWithObject: [String?: Any?]? = nil var aNullableEnum: AnEnum? = nil var aNullableString: String? = nil + var aNullableClass: AllTypes? = nil static func fromList(_ list: [Any?]) -> AllNullableTypes? { let aNullableBool: Bool? = nilOrValue(list[0]) @@ -144,6 +149,10 @@ struct AllNullableTypes { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! } let aNullableString: String? = nilOrValue(list[14]) + var aNullableClass: AllTypes? = nil + if let aNullableClassList: [Any?] = nilOrValue(list[15]) { + aNullableClass = AllTypes.fromList(aNullableClassList) + } return AllNullableTypes( aNullableBool: aNullableBool, @@ -160,7 +169,8 @@ struct AllNullableTypes { nullableMapWithAnnotations: nullableMapWithAnnotations, nullableMapWithObject: nullableMapWithObject, aNullableEnum: aNullableEnum, - aNullableString: aNullableString + aNullableString: aNullableString, + aNullableClass: aNullableClass ) } func toList() -> [Any?] { @@ -180,6 +190,7 @@ struct AllNullableTypes { nullableMapWithObject, aNullableEnum?.rawValue, aNullableString, + aNullableClass?.toList(), ] } } @@ -375,7 +386,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed list, to test serialization and deserialization asynchronously. func echoAsyncNullable(_ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) /// Returns the passed map, to test serialization and deserialization asynchronously. - func echAsyncoNullable(_ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) + func echoAsyncNullable(_ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) func callFlutterNoop(completion: @escaping (Result) -> Void) func callFlutterThrowError(completion: @escaping (Result) -> Void) func callFlutterThrowErrorFromVoid(completion: @escaping (Result) -> Void) @@ -1177,7 +1188,7 @@ class HostIntegrationCoreApiSetup { echoAsyncNullableMapChannel.setMessageHandler { message, reply in let args = message as! [Any?] let aMapArg: [String?: Any?]? = nilOrValue(args[0]) - api.echAsyncoNullable(aMapArg) { result in + api.echoAsyncNullable(aMapArg) { result in switch result { case .success(let res): reply(wrapResult(res)) 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 36ecbfd4328..368dbdeb64f 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -210,7 +210,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion(.success(aList)) } - func echAsyncoNullable(_ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) { + func echoAsyncNullable(_ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) { completion(.success(aMap)) } 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 2590ee6aa87..b407926ca29 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 @@ -58,6 +58,7 @@ struct AllTypes { var aMap: [AnyHashable: Any?] var anEnum: AnEnum var aString: String + var aClass: AllNullableTypes static func fromList(_ list: [Any?]) -> AllTypes? { let aBool = list[0] as! Bool @@ -72,6 +73,7 @@ struct AllTypes { let aMap = list[9] as! [AnyHashable: Any?] let anEnum = AnEnum(rawValue: list[10] as! Int)! let aString = list[11] as! String + let aClass = AllNullableTypes.fromList(list[12] as! [Any?])! return AllTypes( aBool: aBool, @@ -85,7 +87,8 @@ struct AllTypes { aList: aList, aMap: aMap, anEnum: anEnum, - aString: aString + aString: aString, + aClass: aClass ) } func toList() -> [Any?] { @@ -102,6 +105,7 @@ struct AllTypes { aMap, anEnum.rawValue, aString, + aClass.toList(), ] } } @@ -123,6 +127,7 @@ struct AllNullableTypes { var nullableMapWithObject: [String?: Any?]? = nil var aNullableEnum: AnEnum? = nil var aNullableString: String? = nil + var aNullableClass: AllTypes? = nil static func fromList(_ list: [Any?]) -> AllNullableTypes? { let aNullableBool: Bool? = nilOrValue(list[0]) @@ -144,6 +149,10 @@ struct AllNullableTypes { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! } let aNullableString: String? = nilOrValue(list[14]) + var aNullableClass: AllTypes? = nil + if let aNullableClassList: [Any?] = nilOrValue(list[15]) { + aNullableClass = AllTypes.fromList(aNullableClassList) + } return AllNullableTypes( aNullableBool: aNullableBool, @@ -160,7 +169,8 @@ struct AllNullableTypes { nullableMapWithAnnotations: nullableMapWithAnnotations, nullableMapWithObject: nullableMapWithObject, aNullableEnum: aNullableEnum, - aNullableString: aNullableString + aNullableString: aNullableString, + aNullableClass: aNullableClass ) } func toList() -> [Any?] { @@ -180,6 +190,7 @@ struct AllNullableTypes { nullableMapWithObject, aNullableEnum?.rawValue, aNullableString, + aNullableClass?.toList(), ] } } @@ -375,7 +386,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed list, to test serialization and deserialization asynchronously. func echoAsyncNullable(_ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) /// Returns the passed map, to test serialization and deserialization asynchronously. - func echAsyncoNullable(_ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) + func echoAsyncNullable(_ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) func callFlutterNoop(completion: @escaping (Result) -> Void) func callFlutterThrowError(completion: @escaping (Result) -> Void) func callFlutterThrowErrorFromVoid(completion: @escaping (Result) -> Void) @@ -1177,7 +1188,7 @@ class HostIntegrationCoreApiSetup { echoAsyncNullableMapChannel.setMessageHandler { message, reply in let args = message as! [Any?] let aMapArg: [String?: Any?]? = nilOrValue(args[0]) - api.echAsyncoNullable(aMapArg) { result in + api.echoAsyncNullable(aMapArg) { result in switch result { case .success(let res): reply(wrapResult(res)) 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 04bda07e95f..51a68c370e9 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -209,7 +209,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion(.success(aList)) } - func echAsyncoNullable(_ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) { + func echoAsyncNullable(_ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) { completion(.success(aMap)) } 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 a4a17f99a77..a1ac57ffe4c 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 @@ -33,7 +33,8 @@ AllTypes::AllTypes(bool a_bool, int64_t an_int, int64_t an_int64, const std::vector& a8_byte_array, const std::vector& a_float_array, const EncodableList& a_list, const EncodableMap& a_map, - const AnEnum& an_enum, const std::string& a_string) + const AnEnum& an_enum, const std::string& a_string, + const AllNullableTypes& a_class) : a_bool_(a_bool), an_int_(an_int), an_int64_(an_int64), @@ -45,7 +46,8 @@ AllTypes::AllTypes(bool a_bool, int64_t an_int, int64_t an_int64, a_list_(a_list), a_map_(a_map), an_enum_(an_enum), - a_string_(a_string) {} + a_string_(a_string), + a_class_(a_class) {} bool AllTypes::a_bool() const { return a_bool_; } @@ -115,9 +117,15 @@ void AllTypes::set_a_string(std::string_view value_arg) { a_string_ = value_arg; } +const AllNullableTypes& AllTypes::a_class() const { return a_class_; } + +void AllTypes::set_a_class(const AllNullableTypes& value_arg) { + a_class_ = value_arg; +} + EncodableList AllTypes::ToEncodableList() const { EncodableList list; - list.reserve(12); + list.reserve(13); list.push_back(EncodableValue(a_bool_)); list.push_back(EncodableValue(an_int_)); list.push_back(EncodableValue(an_int64_)); @@ -130,6 +138,7 @@ EncodableList AllTypes::ToEncodableList() const { list.push_back(EncodableValue(a_map_)); list.push_back(EncodableValue((int)an_enum_)); list.push_back(EncodableValue(a_string_)); + list.push_back(EncodableValue(a_class_.ToEncodableList())); return list; } @@ -141,7 +150,8 @@ AllTypes AllTypes::FromEncodableList(const EncodableList& list) { std::get>(list[6]), std::get>(list[7]), std::get(list[8]), std::get(list[9]), (AnEnum)(std::get(list[10])), - std::get(list[11])); + std::get(list[11]), + AllNullableTypes::FromEncodableList(std::get(list[12]))); return decoded; } @@ -160,7 +170,7 @@ AllNullableTypes::AllNullableTypes( const EncodableList* nullable_nested_list, const EncodableMap* nullable_map_with_annotations, const EncodableMap* nullable_map_with_object, const AnEnum* a_nullable_enum, - const std::string* a_nullable_string) + const std::string* a_nullable_string, const AllTypes* a_nullable_class) : a_nullable_bool_(a_nullable_bool ? std::optional(*a_nullable_bool) : std::nullopt), a_nullable_int_(a_nullable_int ? std::optional(*a_nullable_int) @@ -208,7 +218,10 @@ AllNullableTypes::AllNullableTypes( : std::nullopt), a_nullable_string_(a_nullable_string ? std::optional(*a_nullable_string) - : std::nullopt) {} + : std::nullopt), + a_nullable_class_(a_nullable_class + ? std::optional(*a_nullable_class) + : std::nullopt) {} const bool* AllNullableTypes::a_nullable_bool() const { return a_nullable_bool_ ? &(*a_nullable_bool_) : nullptr; @@ -423,9 +436,22 @@ void AllNullableTypes::set_a_nullable_string(std::string_view value_arg) { a_nullable_string_ = value_arg; } +const AllTypes* AllNullableTypes::a_nullable_class() const { + return a_nullable_class_ ? &(*a_nullable_class_) : nullptr; +} + +void AllNullableTypes::set_a_nullable_class(const AllTypes* value_arg) { + a_nullable_class_ = + value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypes::set_a_nullable_class(const AllTypes& value_arg) { + a_nullable_class_ = value_arg; +} + EncodableList AllNullableTypes::ToEncodableList() const { EncodableList list; - list.reserve(15); + list.reserve(16); list.push_back(a_nullable_bool_ ? EncodableValue(*a_nullable_bool_) : EncodableValue()); list.push_back(a_nullable_int_ ? EncodableValue(*a_nullable_int_) @@ -462,6 +488,9 @@ EncodableList AllNullableTypes::ToEncodableList() const { : EncodableValue()); list.push_back(a_nullable_string_ ? EncodableValue(*a_nullable_string_) : EncodableValue()); + list.push_back(a_nullable_class_ + ? EncodableValue(a_nullable_class_->ToEncodableList()) + : EncodableValue()); return list; } @@ -540,6 +569,11 @@ AllNullableTypes AllNullableTypes::FromEncodableList( decoded.set_a_nullable_string( std::get(encodable_a_nullable_string)); } + auto& encodable_a_nullable_class = list[15]; + if (!encodable_a_nullable_class.IsNull()) { + decoded.set_a_nullable_class(AllTypes::FromEncodableList( + std::get(encodable_a_nullable_class))); + } return decoded; } 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 413c19dae72..dad8c1a3e51 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 @@ -78,7 +78,8 @@ class AllTypes { const std::vector& a_float_array, const flutter::EncodableList& a_list, const flutter::EncodableMap& a_map, const AnEnum& an_enum, - const std::string& a_string); + const std::string& a_string, + const AllNullableTypes& a_class); bool a_bool() const; void set_a_bool(bool value_arg); @@ -116,9 +117,13 @@ class AllTypes { const std::string& a_string() const; void set_a_string(std::string_view value_arg); + const AllNullableTypes& a_class() const; + void set_a_class(const AllNullableTypes& value_arg); + private: static AllTypes FromEncodableList(const flutter::EncodableList& list); flutter::EncodableList ToEncodableList() const; + friend class AllNullableTypes; friend class HostIntegrationCoreApi; friend class HostIntegrationCoreApiCodecSerializer; friend class FlutterIntegrationCoreApi; @@ -142,6 +147,7 @@ class AllTypes { flutter::EncodableMap a_map_; AnEnum an_enum_; std::string a_string_; + AllNullableTypes a_class_; }; // Generated class from Pigeon that represents data sent in messages. @@ -163,7 +169,8 @@ class AllNullableTypes { const flutter::EncodableList* nullable_nested_list, const flutter::EncodableMap* nullable_map_with_annotations, const flutter::EncodableMap* nullable_map_with_object, - const AnEnum* a_nullable_enum, const std::string* a_nullable_string); + const AnEnum* a_nullable_enum, const std::string* a_nullable_string, + const AllTypes* a_nullable_class); const bool* a_nullable_bool() const; void set_a_nullable_bool(const bool* value_arg); @@ -227,9 +234,14 @@ class AllNullableTypes { void set_a_nullable_string(const std::string_view* value_arg); void set_a_nullable_string(std::string_view value_arg); + const AllTypes* a_nullable_class() const; + void set_a_nullable_class(const AllTypes* value_arg); + void set_a_nullable_class(const AllTypes& value_arg); + private: static AllNullableTypes FromEncodableList(const flutter::EncodableList& list); flutter::EncodableList ToEncodableList() const; + friend class AllTypes; friend class AllNullableTypesWrapper; friend class HostIntegrationCoreApi; friend class HostIntegrationCoreApiCodecSerializer; @@ -257,6 +269,7 @@ class AllNullableTypes { std::optional nullable_map_with_object_; std::optional a_nullable_enum_; std::optional a_nullable_string_; + std::optional a_nullable_class_; }; // Generated class from Pigeon that represents data sent in messages. From ec9ce83f6c3435eaa7ff58c3e5c1120e026278a0 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Mon, 3 Jul 2023 01:41:34 -0700 Subject: [PATCH 06/14] wrapped class int tests --- packages/pigeon/pigeons/core_tests.dart | 20 +- .../AlternateLanguageTestPlugin.java | 16 +- .../CoreTests.java | 178 ++++---- .../AllDatatypesTest.java | 143 +++--- .../ios/Classes/AlternateLanguageTestPlugin.m | 13 +- .../ios/Classes/CoreTests.gen.h | 27 +- .../ios/Classes/CoreTests.gen.m | 90 ++-- .../lib/main.dart | 7 + .../macos/Classes/CoreTests.gen.h | 27 +- .../macos/Classes/CoreTests.gen.m | 90 ++-- .../lib/core_tests.gen.dart | 86 ++-- .../lib/integration_tests.dart | 420 ++++++------------ .../lib/src/generated/core_tests.gen.dart | 86 ++-- .../com/example/test_plugin/CoreTests.gen.kt | 75 ++-- .../com/example/test_plugin/TestPlugin.kt | 12 +- .../example/test_plugin/AllDatatypesTest.kt | 78 ++-- .../ios/Classes/CoreTests.gen.swift | 76 ++-- .../test_plugin/ios/Classes/TestPlugin.swift | 12 +- .../macos/Classes/CoreTests.gen.swift | 76 ++-- .../macos/Classes/TestPlugin.swift | 12 +- .../windows/pigeon/core_tests.gen.cpp | 179 ++++---- .../windows/pigeon/core_tests.gen.h | 49 +- .../test_plugin/windows/test_plugin.cpp | 16 +- 23 files changed, 960 insertions(+), 828 deletions(-) create mode 100644 packages/pigeon/platform_tests/alternate_language_test_plugin/lib/main.dart diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 3ee2535e597..48af56ea819 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -25,7 +25,6 @@ class AllTypes { this.aMap = const {}, this.anEnum = AnEnum.one, this.aString = '', - required this.aClass, }); bool aBool; @@ -42,7 +41,6 @@ class AllTypes { Map aMap; AnEnum anEnum; String aString; - AllNullableTypes aClass; } // A class containing all supported nullable types. @@ -63,7 +61,6 @@ class AllNullableTypes { this.nullableMapWithObject, this.aNullableEnum, this.aNullableString, - this.aNullableClass, ); bool? aNullableBool; @@ -83,13 +80,13 @@ class AllNullableTypes { Map? nullableMapWithObject; AnEnum? aNullableEnum; String? aNullableString; - AllTypes? aNullableClass; } // A class for testing nested object handling. -class AllNullableTypesWrapper { - AllNullableTypesWrapper(this.values); - AllNullableTypes values; +class AllClassesWrapper { + AllClassesWrapper(this.allNullableTypes, this.allTypes); + AllNullableTypes allNullableTypes; + AllTypes? allTypes; } /// The core interface that each host language plugin must implement in @@ -156,6 +153,11 @@ abstract class HostIntegrationCoreApi { @SwiftFunction('echo(_:)') Map echoMap(Map aMap); + /// Returns the passed map to test nested class serialization and deserialization. + @ObjCSelector('echoClassWrapper:') + @SwiftFunction('echo(_:)') + AllClassesWrapper echoClassWrapper(AllClassesWrapper wrapper); + // ========== Syncronous nullable method tests ========== /// Returns the passed object, to test serialization and deserialization. @@ -167,13 +169,13 @@ abstract class HostIntegrationCoreApi { /// sending of nested objects. @ObjCSelector('extractNestedNullableStringFrom:') @SwiftFunction('extractNestedNullableString(from:)') - String? extractNestedNullableString(AllNullableTypesWrapper wrapper); + String? extractNestedNullableString(AllClassesWrapper wrapper); /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. @ObjCSelector('createNestedObjectWithNullableString:') @SwiftFunction('createNestedObject(with:)') - AllNullableTypesWrapper createNestedNullableString(String? nullableString); + AllClassesWrapper createNestedNullableString(String? nullableString); /// Returns passed in arguments of multiple types. @ObjCSelector('sendMultipleNullableTypesABool:anInt:aString:') 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 6ca4c01f357..c9c4406d688 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 @@ -6,8 +6,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.example.alternate_language_test_plugin.CoreTests.AllClassesWrapper; import com.example.alternate_language_test_plugin.CoreTests.AllNullableTypes; -import com.example.alternate_language_test_plugin.CoreTests.AllNullableTypesWrapper; import com.example.alternate_language_test_plugin.CoreTests.AllTypes; import com.example.alternate_language_test_plugin.CoreTests.FlutterIntegrationCoreApi; import com.example.alternate_language_test_plugin.CoreTests.HostIntegrationCoreApi; @@ -99,17 +99,21 @@ public void throwErrorFromVoid() { return aMap; } + @NonNull + public AllClassesWrapper echoClassWrapper(@NonNull AllClassesWrapper wrapper) { + return wrapper; + } + @Override - public @Nullable String extractNestedNullableString(@NonNull AllNullableTypesWrapper wrapper) { - return wrapper.getValues().getANullableString(); + public @Nullable String extractNestedNullableString(@NonNull AllClassesWrapper wrapper) { + return wrapper.getAllNullableTypes().getANullableString(); } @Override - public @NonNull AllNullableTypesWrapper createNestedNullableString( - @Nullable String nullableString) { + public @NonNull AllClassesWrapper createNestedNullableString(@Nullable String nullableString) { AllNullableTypes innerObject = new AllNullableTypes.Builder().setANullableString(nullableString).build(); - return new AllNullableTypesWrapper.Builder().setValues(innerObject).build(); + return new AllClassesWrapper.Builder().setAllNullableTypes(innerObject).build(); } @Override 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 8cff9596c0f..46ae86da851 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 @@ -229,19 +229,6 @@ public void setAString(@NonNull String setterArg) { this.aString = setterArg; } - private @NonNull AllNullableTypes aClass; - - public @NonNull AllNullableTypes getAClass() { - return aClass; - } - - public void setAClass(@NonNull AllNullableTypes setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"aClass\" is null."); - } - this.aClass = setterArg; - } - /** Constructor is non-public to enforce null safety; use Builder. */ AllTypes() {} @@ -331,13 +318,6 @@ public static final class Builder { return this; } - private @Nullable AllNullableTypes aClass; - - public @NonNull Builder setAClass(@NonNull AllNullableTypes setterArg) { - this.aClass = setterArg; - return this; - } - public @NonNull AllTypes build() { AllTypes pigeonReturn = new AllTypes(); pigeonReturn.setABool(aBool); @@ -352,14 +332,13 @@ public static final class Builder { pigeonReturn.setAMap(aMap); pigeonReturn.setAnEnum(anEnum); pigeonReturn.setAString(aString); - pigeonReturn.setAClass(aClass); return pigeonReturn; } } @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(13); + ArrayList toListResult = new ArrayList(12); toListResult.add(aBool); toListResult.add(anInt); toListResult.add(anInt64); @@ -372,7 +351,6 @@ ArrayList toList() { toListResult.add(aMap); toListResult.add(anEnum == null ? null : anEnum.index); toListResult.add(aString); - toListResult.add((aClass == null) ? null : aClass.toList()); return toListResult; } @@ -406,9 +384,6 @@ ArrayList toList() { pigeonResult.setAnEnum(anEnum == null ? null : AnEnum.values()[(int) anEnum]); Object aString = list.get(11); pigeonResult.setAString((String) aString); - Object aClass = list.get(12); - pigeonResult.setAClass( - (aClass == null) ? null : AllNullableTypes.fromList((ArrayList) aClass)); return pigeonResult; } } @@ -565,16 +540,6 @@ public void setANullableString(@Nullable String setterArg) { this.aNullableString = setterArg; } - private @Nullable AllTypes aNullableClass; - - public @Nullable AllTypes getANullableClass() { - return aNullableClass; - } - - public void setANullableClass(@Nullable AllTypes setterArg) { - this.aNullableClass = setterArg; - } - public static final class Builder { private @Nullable Boolean aNullableBool; @@ -683,13 +648,6 @@ public static final class Builder { return this; } - private @Nullable AllTypes aNullableClass; - - public @NonNull Builder setANullableClass(@Nullable AllTypes setterArg) { - this.aNullableClass = setterArg; - return this; - } - public @NonNull AllNullableTypes build() { AllNullableTypes pigeonReturn = new AllNullableTypes(); pigeonReturn.setANullableBool(aNullableBool); @@ -707,14 +665,13 @@ public static final class Builder { pigeonReturn.setNullableMapWithObject(nullableMapWithObject); pigeonReturn.setANullableEnum(aNullableEnum); pigeonReturn.setANullableString(aNullableString); - pigeonReturn.setANullableClass(aNullableClass); return pigeonReturn; } } @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(16); + ArrayList toListResult = new ArrayList(15); toListResult.add(aNullableBool); toListResult.add(aNullableInt); toListResult.add(aNullableInt64); @@ -730,7 +687,6 @@ ArrayList toList() { toListResult.add(nullableMapWithObject); toListResult.add(aNullableEnum == null ? null : aNullableEnum.index); toListResult.add(aNullableString); - toListResult.add((aNullableClass == null) ? null : aNullableClass.toList()); return toListResult; } @@ -775,59 +731,80 @@ ArrayList toList() { aNullableEnum == null ? null : AnEnum.values()[(int) aNullableEnum]); Object aNullableString = list.get(14); pigeonResult.setANullableString((String) aNullableString); - Object aNullableClass = list.get(15); - pigeonResult.setANullableClass( - (aNullableClass == null) ? null : AllTypes.fromList((ArrayList) aNullableClass)); return pigeonResult; } } /** Generated class from Pigeon that represents data sent in messages. */ - public static final class AllNullableTypesWrapper { - private @NonNull AllNullableTypes values; + public static final class AllClassesWrapper { + private @NonNull AllNullableTypes allNullableTypes; - public @NonNull AllNullableTypes getValues() { - return values; + public @NonNull AllNullableTypes getAllNullableTypes() { + return allNullableTypes; } - public void setValues(@NonNull AllNullableTypes setterArg) { + public void setAllNullableTypes(@NonNull AllNullableTypes setterArg) { if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"values\" is null."); + throw new IllegalStateException("Nonnull field \"allNullableTypes\" is null."); } - this.values = setterArg; + this.allNullableTypes = setterArg; + } + + private @Nullable AllTypes allTypes; + + public @Nullable AllTypes getAllTypes() { + return allTypes; + } + + public void setAllTypes(@Nullable AllTypes setterArg) { + this.allTypes = setterArg; } /** Constructor is non-public to enforce null safety; use Builder. */ - AllNullableTypesWrapper() {} + AllClassesWrapper() {} public static final class Builder { - private @Nullable AllNullableTypes values; + private @Nullable AllNullableTypes allNullableTypes; - public @NonNull Builder setValues(@NonNull AllNullableTypes setterArg) { - this.values = setterArg; + public @NonNull Builder setAllNullableTypes(@NonNull AllNullableTypes setterArg) { + this.allNullableTypes = setterArg; return this; } - public @NonNull AllNullableTypesWrapper build() { - AllNullableTypesWrapper pigeonReturn = new AllNullableTypesWrapper(); - pigeonReturn.setValues(values); + private @Nullable AllTypes allTypes; + + public @NonNull Builder setAllTypes(@Nullable AllTypes setterArg) { + this.allTypes = setterArg; + return this; + } + + public @NonNull AllClassesWrapper build() { + AllClassesWrapper pigeonReturn = new AllClassesWrapper(); + pigeonReturn.setAllNullableTypes(allNullableTypes); + pigeonReturn.setAllTypes(allTypes); return pigeonReturn; } } @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(1); - toListResult.add((values == null) ? null : values.toList()); + ArrayList toListResult = new ArrayList(2); + toListResult.add((allNullableTypes == null) ? null : allNullableTypes.toList()); + toListResult.add((allTypes == null) ? null : allTypes.toList()); return toListResult; } - static @NonNull AllNullableTypesWrapper fromList(@NonNull ArrayList list) { - AllNullableTypesWrapper pigeonResult = new AllNullableTypesWrapper(); - Object values = list.get(0); - pigeonResult.setValues( - (values == null) ? null : AllNullableTypes.fromList((ArrayList) values)); + static @NonNull AllClassesWrapper fromList(@NonNull ArrayList list) { + AllClassesWrapper pigeonResult = new AllClassesWrapper(); + Object allNullableTypes = list.get(0); + pigeonResult.setAllNullableTypes( + (allNullableTypes == null) + ? null + : AllNullableTypes.fromList((ArrayList) allNullableTypes)); + Object allTypes = list.get(1); + pigeonResult.setAllTypes( + (allTypes == null) ? null : AllTypes.fromList((ArrayList) allTypes)); return pigeonResult; } } @@ -895,9 +872,9 @@ private HostIntegrationCoreApiCodec() {} protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { switch (type) { case (byte) 128: - return AllNullableTypes.fromList((ArrayList) readValue(buffer)); + return AllClassesWrapper.fromList((ArrayList) readValue(buffer)); case (byte) 129: - return AllNullableTypesWrapper.fromList((ArrayList) readValue(buffer)); + return AllNullableTypes.fromList((ArrayList) readValue(buffer)); case (byte) 130: return AllTypes.fromList((ArrayList) readValue(buffer)); case (byte) 131: @@ -909,12 +886,12 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { @Override protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof AllNullableTypes) { + if (value instanceof AllClassesWrapper) { stream.write(128); - writeValue(stream, ((AllNullableTypes) value).toList()); - } else if (value instanceof AllNullableTypesWrapper) { + writeValue(stream, ((AllClassesWrapper) value).toList()); + } else if (value instanceof AllNullableTypes) { stream.write(129); - writeValue(stream, ((AllNullableTypesWrapper) value).toList()); + writeValue(stream, ((AllNullableTypes) value).toList()); } else if (value instanceof AllTypes) { stream.write(130); writeValue(stream, ((AllTypes) value).toList()); @@ -973,6 +950,9 @@ public interface HostIntegrationCoreApi { /** Returns the passed map, to test serialization and deserialization. */ @NonNull Map echoMap(@NonNull Map aMap); + /** Returns the passed map to test nested class serialization and deserialization. */ + @NonNull + AllClassesWrapper echoClassWrapper(@NonNull AllClassesWrapper wrapper); /** Returns the passed object, to test serialization and deserialization. */ @Nullable AllNullableTypes echoAllNullableTypes(@Nullable AllNullableTypes everything); @@ -980,12 +960,12 @@ public interface HostIntegrationCoreApi { * Returns the inner `aString` value from the wrapped object, to test sending of nested objects. */ @Nullable - String extractNestedNullableString(@NonNull AllNullableTypesWrapper wrapper); + String extractNestedNullableString(@NonNull AllClassesWrapper wrapper); /** * Returns the inner `aString` value from the wrapped object, to test sending of nested objects. */ @NonNull - AllNullableTypesWrapper createNestedNullableString(@Nullable String nullableString); + AllClassesWrapper createNestedNullableString(@Nullable String nullableString); /** Returns passed in arguments of multiple types. */ @NonNull AllNullableTypes sendMultipleNullableTypes( @@ -1429,6 +1409,31 @@ static void setup( channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoClassWrapper", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + AllClassesWrapper wrapperArg = (AllClassesWrapper) args.get(0); + try { + AllClassesWrapper output = api.echoClassWrapper(wrapperArg); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -1465,7 +1470,7 @@ static void setup( (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - AllNullableTypesWrapper wrapperArg = (AllNullableTypesWrapper) args.get(0); + AllClassesWrapper wrapperArg = (AllClassesWrapper) args.get(0); try { String output = api.extractNestedNullableString(wrapperArg); wrapped.add(0, output); @@ -1492,8 +1497,7 @@ static void setup( ArrayList args = (ArrayList) message; String nullableStringArg = (String) args.get(0); try { - AllNullableTypesWrapper output = - api.createNestedNullableString(nullableStringArg); + AllClassesWrapper output = api.createNestedNullableString(nullableStringArg); wrapped.add(0, output); } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); @@ -3015,9 +3019,9 @@ private FlutterIntegrationCoreApiCodec() {} protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { switch (type) { case (byte) 128: - return AllNullableTypes.fromList((ArrayList) readValue(buffer)); + return AllClassesWrapper.fromList((ArrayList) readValue(buffer)); case (byte) 129: - return AllNullableTypesWrapper.fromList((ArrayList) readValue(buffer)); + return AllNullableTypes.fromList((ArrayList) readValue(buffer)); case (byte) 130: return AllTypes.fromList((ArrayList) readValue(buffer)); case (byte) 131: @@ -3029,12 +3033,12 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { @Override protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof AllNullableTypes) { + if (value instanceof AllClassesWrapper) { stream.write(128); - writeValue(stream, ((AllNullableTypes) value).toList()); - } else if (value instanceof AllNullableTypesWrapper) { + writeValue(stream, ((AllClassesWrapper) value).toList()); + } else if (value instanceof AllNullableTypes) { stream.write(129); - writeValue(stream, ((AllNullableTypesWrapper) value).toList()); + writeValue(stream, ((AllNullableTypes) value).toList()); } else if (value instanceof AllTypes) { stream.write(130); writeValue(stream, ((AllTypes) value).toList()); diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java index 42b73100903..ee1bc58a846 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java @@ -18,6 +18,69 @@ import org.junit.Test; public class AllDatatypesTest { + + boolean compareAllTypes(AllTypes firstTypes, AllTypes secondTypes) { + + if (firstTypes == null && secondTypes == null) { + return true; + } + if (firstTypes == null || secondTypes == null) { + return false; + } + + assertEquals(firstTypes.getABool(), secondTypes.getABool()); + assertEquals(firstTypes.getAnInt(), secondTypes.getAnInt()); + assertEquals(firstTypes.getAnInt64(), secondTypes.getAnInt64()); + + assertEquals(firstTypes.getADouble(), secondTypes.getADouble()); + assertArrayEquals(firstTypes.getAByteArray(), secondTypes.getAByteArray()); + assertArrayEquals(firstTypes.getA4ByteArray(), secondTypes.getA4ByteArray()); + assertArrayEquals(firstTypes.getA8ByteArray(), secondTypes.getA8ByteArray()); + assertTrue(floatArraysEqual(firstTypes.getAFloatArray(), secondTypes.getAFloatArray())); + assertArrayEquals(firstTypes.getAList().toArray(), secondTypes.getAList().toArray()); + assertArrayEquals( + firstTypes.getAMap().keySet().toArray(), secondTypes.getAMap().keySet().toArray()); + assertArrayEquals( + firstTypes.getAMap().values().toArray(), secondTypes.getAMap().values().toArray()); + assertEquals(firstTypes.getAnEnum(), secondTypes.getAnEnum()); + assertEquals(firstTypes.getAString(), secondTypes.getAString()); + + return true; + } + + boolean compareAllNullableTypes(AllNullableTypes firstTypes, AllNullableTypes secondTypes) { + + if (firstTypes == null && secondTypes == null) { + return true; + } + if (firstTypes == null || secondTypes == null) { + return false; + } + assertEquals(firstTypes.getANullableBool(), secondTypes.getANullableBool()); + assertEquals(firstTypes.getANullableInt(), secondTypes.getANullableInt()); + assertEquals(firstTypes.getANullableDouble(), secondTypes.getANullableDouble()); + assertEquals(firstTypes.getANullableString(), secondTypes.getANullableString()); + assertArrayEquals(firstTypes.getANullableByteArray(), secondTypes.getANullableByteArray()); + assertArrayEquals(firstTypes.getANullable4ByteArray(), secondTypes.getANullable4ByteArray()); + assertArrayEquals(firstTypes.getANullable8ByteArray(), secondTypes.getANullable8ByteArray()); + assertTrue( + floatArraysEqual( + firstTypes.getANullableFloatArray(), secondTypes.getANullableFloatArray())); + assertArrayEquals( + firstTypes.getANullableList().toArray(), secondTypes.getANullableList().toArray()); + assertArrayEquals( + firstTypes.getANullableMap().keySet().toArray(), + secondTypes.getANullableMap().keySet().toArray()); + assertArrayEquals( + firstTypes.getANullableMap().values().toArray(), + secondTypes.getANullableMap().values().toArray()); + assertArrayEquals( + firstTypes.getNullableMapWithObject().values().toArray(), + secondTypes.getNullableMapWithObject().values().toArray()); + + return true; + } + @Test public void nullValues() { AllNullableTypes everything = new AllNullableTypes(); @@ -55,7 +118,6 @@ public void nullValues() { assertNull(everything.getANullableList()); assertNull(everything.getANullableMap()); assertNull(everything.getNullableMapWithObject()); - assertNull(everything.getANullableClass()); }); assertTrue(didCall[0]); } @@ -86,32 +148,36 @@ private static boolean floatArraysEqual(double[] x, double[] y) { @Test public void hasValues() { - AllTypes allEverything = new AllTypes(); - allEverything.setABool(false); - allEverything.setAnInt(1234L); - allEverything.setADouble(2.0); - allEverything.setAString("hello"); - allEverything.setAByteArray(new byte[] {1, 2, 3, 4}); - allEverything.setA4ByteArray(new int[] {1, 2, 3, 4}); - allEverything.setA8ByteArray(new long[] {1, 2, 3, 4}); - allEverything.setAFloatArray(new double[] {0.5, 0.25, 1.5, 1.25}); - allEverything.setAList(Arrays.asList(new int[] {1, 2, 3})); - allEverything.setAMap(makeMap("hello", 1234)); - allEverything.setAClass(new AllNullableTypes()); + AllTypes allEverything = + new AllTypes.Builder() + .setABool(false) + .setAnInt(1234L) + .setAnInt64(4321L) + .setADouble(2.0) + .setAString("hello") + .setAByteArray(new byte[] {1, 2, 3, 4}) + .setA4ByteArray(new int[] {1, 2, 3, 4}) + .setA8ByteArray(new long[] {1, 2, 3, 4}) + .setAFloatArray(new double[] {0.5, 0.25, 1.5, 1.25}) + .setAList(Arrays.asList(new int[] {1, 2, 3})) + .setAMap(makeMap("hello", 1234)) + .setAnEnum(CoreTests.AnEnum.ONE) + .build(); - AllNullableTypes everything = new AllNullableTypes(); - everything.setANullableBool(false); - everything.setANullableInt(1234L); - everything.setANullableDouble(2.0); - everything.setANullableString("hello"); - everything.setANullableByteArray(new byte[] {1, 2, 3, 4}); - everything.setANullable4ByteArray(new int[] {1, 2, 3, 4}); - everything.setANullable8ByteArray(new long[] {1, 2, 3, 4}); - everything.setANullableFloatArray(new double[] {0.5, 0.25, 1.5, 1.25}); - everything.setANullableList(Arrays.asList(new int[] {1, 2, 3})); - everything.setANullableMap(makeMap("hello", 1234)); - everything.setNullableMapWithObject(makeStringMap("hello", 1234)); - everything.setANullableClass(allEverything); + AllNullableTypes everything = + new AllNullableTypes.Builder() + .setANullableBool(false) + .setANullableInt(1234L) + .setANullableDouble(2.0) + .setANullableString("hello") + .setANullableByteArray(new byte[] {1, 2, 3, 4}) + .setANullable4ByteArray(new int[] {1, 2, 3, 4}) + .setANullable8ByteArray(new long[] {1, 2, 3, 4}) + .setANullableFloatArray(new double[] {0.5, 0.25, 1.5, 1.25}) + .setANullableList(Arrays.asList(new int[] {1, 2, 3})) + .setANullableMap(makeMap("hello", 1234)) + .setNullableMapWithObject(makeStringMap("hello", 1234)) + .build(); BinaryMessenger binaryMessenger = mock(BinaryMessenger.class); doAnswer( @@ -136,30 +202,7 @@ public void hasValues() { everything, (result) -> { didCall[0] = true; - assertEquals(everything.getANullableBool(), result.getANullableBool()); - assertEquals(everything.getANullableInt(), result.getANullableInt()); - assertEquals(everything.getANullableDouble(), result.getANullableDouble()); - assertEquals(everything.getANullableString(), result.getANullableString()); - assertArrayEquals(everything.getANullableByteArray(), result.getANullableByteArray()); - assertArrayEquals(everything.getANullable4ByteArray(), result.getANullable4ByteArray()); - assertArrayEquals(everything.getANullable8ByteArray(), result.getANullable8ByteArray()); - assertTrue( - floatArraysEqual( - everything.getANullableFloatArray(), result.getANullableFloatArray())); - assertArrayEquals( - everything.getANullableList().toArray(), result.getANullableList().toArray()); - assertArrayEquals( - everything.getANullableMap().keySet().toArray(), - result.getANullableMap().keySet().toArray()); - assertArrayEquals( - everything.getANullableMap().values().toArray(), - result.getANullableMap().values().toArray()); - assertArrayEquals( - everything.getNullableMapWithObject().values().toArray(), - result.getNullableMapWithObject().values().toArray()); - // assertThat(everything.getANullableClass()) - // .usingRecursiveComparison() - // .isEqualTo(result.getANullableClass()); + assert (compareAllNullableTypes(everything, result)); }); assertTrue(didCall[0]); } 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 843232acf3a..1df7a345754 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 @@ -87,17 +87,22 @@ - (nullable id)echoObject:(id)anObject error:(FlutterError *_Nullable *_Nonnull) return aMap; } -- (nullable NSString *)extractNestedNullableStringFrom:(AllNullableTypesWrapper *)wrapper +- (nullable AllClassesWrapper *)echoClassWrapper:(AllClassesWrapper *)wrapper + error:(FlutterError *_Nullable *_Nonnull)error { + return wrapper; +} + +- (nullable NSString *)extractNestedNullableStringFrom:(AllClassesWrapper *)wrapper error:(FlutterError *_Nullable *_Nonnull)error { - return wrapper.values.aNullableString; + return wrapper.allNullableTypes.aNullableString; } -- (nullable AllNullableTypesWrapper *) +- (nullable AllClassesWrapper *) createNestedObjectWithNullableString:(nullable NSString *)nullableString error:(FlutterError *_Nullable *_Nonnull)error { AllNullableTypes *innerObject = [[AllNullableTypes alloc] init]; innerObject.aNullableString = nullableString; - return [AllNullableTypesWrapper makeWithValues:innerObject]; + return [AllClassesWrapper makeWithAllNullableTypes:innerObject allTypes:nil]; } - (nullable AllNullableTypes *)sendMultipleNullableTypesABool:(nullable NSNumber *)aNullableBool 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 e984aadb2bf..95b362e84e6 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 @@ -22,7 +22,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @class AllTypes; @class AllNullableTypes; -@class AllNullableTypesWrapper; +@class AllClassesWrapper; @class TestMessage; @interface AllTypes : NSObject @@ -39,8 +39,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { aList:(NSArray *)aList aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum - aString:(NSString *)aString - aClass:(AllNullableTypes *)aClass; + aString:(NSString *)aString; @property(nonatomic, strong) NSNumber *aBool; @property(nonatomic, strong) NSNumber *anInt; @property(nonatomic, strong) NSNumber *anInt64; @@ -53,7 +52,6 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong) NSDictionary *aMap; @property(nonatomic, assign) AnEnum anEnum; @property(nonatomic, copy) NSString *aString; -@property(nonatomic, strong) AllNullableTypes *aClass; @end @interface AllNullableTypes : NSObject @@ -72,8 +70,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { (nullable NSDictionary *)nullableMapWithAnnotations nullableMapWithObject:(nullable NSDictionary *)nullableMapWithObject aNullableEnum:(AnEnum)aNullableEnum - aNullableString:(nullable NSString *)aNullableString - aNullableClass:(nullable AllTypes *)aNullableClass; + aNullableString:(nullable NSString *)aNullableString; @property(nonatomic, strong, nullable) NSNumber *aNullableBool; @property(nonatomic, strong, nullable) NSNumber *aNullableInt; @property(nonatomic, strong, nullable) NSNumber *aNullableInt64; @@ -90,14 +87,15 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong, nullable) NSDictionary *nullableMapWithObject; @property(nonatomic, assign) AnEnum aNullableEnum; @property(nonatomic, copy, nullable) NSString *aNullableString; -@property(nonatomic, strong, nullable) AllTypes *aNullableClass; @end -@interface AllNullableTypesWrapper : NSObject +@interface AllClassesWrapper : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithValues:(AllNullableTypes *)values; -@property(nonatomic, strong) AllNullableTypes *values; ++ (instancetype)makeWithAllNullableTypes:(AllNullableTypes *)allNullableTypes + allTypes:(nullable AllTypes *)allTypes; +@property(nonatomic, strong) AllNullableTypes *allNullableTypes; +@property(nonatomic, strong, nullable) AllTypes *allTypes; @end /// A data class containing a List, used in unit tests. @@ -163,18 +161,23 @@ NSObject *HostIntegrationCoreApiGetCodec(void); /// @return `nil` only when `error != nil`. - (nullable NSDictionary *)echoMap:(NSDictionary *)aMap error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns the passed map to test nested class serialization and deserialization. +/// +/// @return `nil` only when `error != nil`. +- (nullable AllClassesWrapper *)echoClassWrapper:(AllClassesWrapper *)wrapper + error:(FlutterError *_Nullable *_Nonnull)error; /// Returns the passed object, to test serialization and deserialization. - (nullable AllNullableTypes *)echoAllNullableTypes:(nullable AllNullableTypes *)everything error:(FlutterError *_Nullable *_Nonnull)error; /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. -- (nullable NSString *)extractNestedNullableStringFrom:(AllNullableTypesWrapper *)wrapper +- (nullable NSString *)extractNestedNullableStringFrom:(AllClassesWrapper *)wrapper error:(FlutterError *_Nullable *_Nonnull)error; /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. /// /// @return `nil` only when `error != nil`. -- (nullable AllNullableTypesWrapper *) +- (nullable AllClassesWrapper *) createNestedObjectWithNullableString:(nullable NSString *)nullableString error:(FlutterError *_Nullable *_Nonnull)error; /// Returns passed in arguments of multiple types. 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 1c5fadaed47..510b9a8f96b 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 @@ -42,9 +42,9 @@ + (nullable AllNullableTypes *)nullableFromList:(NSArray *)list; - (NSArray *)toList; @end -@interface AllNullableTypesWrapper () -+ (AllNullableTypesWrapper *)fromList:(NSArray *)list; -+ (nullable AllNullableTypesWrapper *)nullableFromList:(NSArray *)list; +@interface AllClassesWrapper () ++ (AllClassesWrapper *)fromList:(NSArray *)list; ++ (nullable AllClassesWrapper *)nullableFromList:(NSArray *)list; - (NSArray *)toList; @end @@ -66,8 +66,7 @@ + (instancetype)makeWithABool:(NSNumber *)aBool aList:(NSArray *)aList aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum - aString:(NSString *)aString - aClass:(AllNullableTypes *)aClass { + aString:(NSString *)aString { AllTypes *pigeonResult = [[AllTypes alloc] init]; pigeonResult.aBool = aBool; pigeonResult.anInt = anInt; @@ -81,7 +80,6 @@ + (instancetype)makeWithABool:(NSNumber *)aBool pigeonResult.aMap = aMap; pigeonResult.anEnum = anEnum; pigeonResult.aString = aString; - pigeonResult.aClass = aClass; return pigeonResult; } + (AllTypes *)fromList:(NSArray *)list { @@ -109,8 +107,6 @@ + (AllTypes *)fromList:(NSArray *)list { pigeonResult.anEnum = [GetNullableObjectAtIndex(list, 10) integerValue]; pigeonResult.aString = GetNullableObjectAtIndex(list, 11); NSAssert(pigeonResult.aString != nil, @""); - pigeonResult.aClass = [AllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 12))]; - NSAssert(pigeonResult.aClass != nil, @""); return pigeonResult; } + (nullable AllTypes *)nullableFromList:(NSArray *)list { @@ -130,7 +126,6 @@ - (NSArray *)toList { (self.aMap ?: [NSNull null]), @(self.anEnum), (self.aString ?: [NSNull null]), - (self.aClass ? [self.aClass toList] : [NSNull null]), ]; } @end @@ -151,8 +146,7 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool (nullable NSDictionary *)nullableMapWithAnnotations nullableMapWithObject:(nullable NSDictionary *)nullableMapWithObject aNullableEnum:(AnEnum)aNullableEnum - aNullableString:(nullable NSString *)aNullableString - aNullableClass:(nullable AllTypes *)aNullableClass { + aNullableString:(nullable NSString *)aNullableString { AllNullableTypes *pigeonResult = [[AllNullableTypes alloc] init]; pigeonResult.aNullableBool = aNullableBool; pigeonResult.aNullableInt = aNullableInt; @@ -169,7 +163,6 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool pigeonResult.nullableMapWithObject = nullableMapWithObject; pigeonResult.aNullableEnum = aNullableEnum; pigeonResult.aNullableString = aNullableString; - pigeonResult.aNullableClass = aNullableClass; return pigeonResult; } + (AllNullableTypes *)fromList:(NSArray *)list { @@ -189,7 +182,6 @@ + (AllNullableTypes *)fromList:(NSArray *)list { pigeonResult.nullableMapWithObject = GetNullableObjectAtIndex(list, 12); pigeonResult.aNullableEnum = [GetNullableObjectAtIndex(list, 13) integerValue]; pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 14); - pigeonResult.aNullableClass = [AllTypes nullableFromList:(GetNullableObjectAtIndex(list, 15))]; return pigeonResult; } + (nullable AllNullableTypes *)nullableFromList:(NSArray *)list { @@ -212,29 +204,33 @@ - (NSArray *)toList { (self.nullableMapWithObject ?: [NSNull null]), @(self.aNullableEnum), (self.aNullableString ?: [NSNull null]), - (self.aNullableClass ? [self.aNullableClass toList] : [NSNull null]), ]; } @end -@implementation AllNullableTypesWrapper -+ (instancetype)makeWithValues:(AllNullableTypes *)values { - AllNullableTypesWrapper *pigeonResult = [[AllNullableTypesWrapper alloc] init]; - pigeonResult.values = values; +@implementation AllClassesWrapper ++ (instancetype)makeWithAllNullableTypes:(AllNullableTypes *)allNullableTypes + allTypes:(nullable AllTypes *)allTypes { + AllClassesWrapper *pigeonResult = [[AllClassesWrapper alloc] init]; + pigeonResult.allNullableTypes = allNullableTypes; + pigeonResult.allTypes = allTypes; return pigeonResult; } -+ (AllNullableTypesWrapper *)fromList:(NSArray *)list { - AllNullableTypesWrapper *pigeonResult = [[AllNullableTypesWrapper alloc] init]; - pigeonResult.values = [AllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 0))]; - NSAssert(pigeonResult.values != nil, @""); ++ (AllClassesWrapper *)fromList:(NSArray *)list { + AllClassesWrapper *pigeonResult = [[AllClassesWrapper alloc] init]; + pigeonResult.allNullableTypes = + [AllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 0))]; + NSAssert(pigeonResult.allNullableTypes != nil, @""); + pigeonResult.allTypes = [AllTypes nullableFromList:(GetNullableObjectAtIndex(list, 1))]; return pigeonResult; } -+ (nullable AllNullableTypesWrapper *)nullableFromList:(NSArray *)list { - return (list) ? [AllNullableTypesWrapper fromList:list] : nil; ++ (nullable AllClassesWrapper *)nullableFromList:(NSArray *)list { + return (list) ? [AllClassesWrapper fromList:list] : nil; } - (NSArray *)toList { return @[ - (self.values ? [self.values toList] : [NSNull null]), + (self.allNullableTypes ? [self.allNullableTypes toList] : [NSNull null]), + (self.allTypes ? [self.allTypes toList] : [NSNull null]), ]; } @end @@ -266,9 +262,9 @@ @implementation HostIntegrationCoreApiCodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { case 128: - return [AllNullableTypes fromList:[self readValue]]; + return [AllClassesWrapper fromList:[self readValue]]; case 129: - return [AllNullableTypesWrapper fromList:[self readValue]]; + return [AllNullableTypes fromList:[self readValue]]; case 130: return [AllTypes fromList:[self readValue]]; case 131: @@ -283,10 +279,10 @@ @interface HostIntegrationCoreApiCodecWriter : FlutterStandardWriter @end @implementation HostIntegrationCoreApiCodecWriter - (void)writeValue:(id)value { - if ([value isKindOfClass:[AllNullableTypes class]]) { + if ([value isKindOfClass:[AllClassesWrapper class]]) { [self writeByte:128]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllNullableTypesWrapper class]]) { + } else if ([value isKindOfClass:[AllNullableTypes class]]) { [self writeByte:129]; [self writeValue:[value toList]]; } else if ([value isKindOfClass:[AllTypes class]]) { @@ -596,6 +592,28 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, [channel setMessageHandler:nil]; } } + /// Returns the passed map to test nested class serialization and deserialization. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.echoClassWrapper" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert( + [api respondsToSelector:@selector(echoClassWrapper:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoClassWrapper:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + AllClassesWrapper *arg_wrapper = GetNullableObjectAtIndex(args, 0); + FlutterError *error; + AllClassesWrapper *output = [api echoClassWrapper:arg_wrapper error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } /// Returns the passed object, to test serialization and deserialization. { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] @@ -632,7 +650,7 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - AllNullableTypesWrapper *arg_wrapper = GetNullableObjectAtIndex(args, 0); + AllClassesWrapper *arg_wrapper = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSString *output = [api extractNestedNullableStringFrom:arg_wrapper error:&error]; callback(wrapResult(output, error)); @@ -657,8 +675,8 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, NSArray *args = message; NSString *arg_nullableString = GetNullableObjectAtIndex(args, 0); FlutterError *error; - AllNullableTypesWrapper *output = - [api createNestedObjectWithNullableString:arg_nullableString error:&error]; + AllClassesWrapper *output = [api createNestedObjectWithNullableString:arg_nullableString + error:&error]; callback(wrapResult(output, error)); }]; } else { @@ -1806,9 +1824,9 @@ @implementation FlutterIntegrationCoreApiCodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { case 128: - return [AllNullableTypes fromList:[self readValue]]; + return [AllClassesWrapper fromList:[self readValue]]; case 129: - return [AllNullableTypesWrapper fromList:[self readValue]]; + return [AllNullableTypes fromList:[self readValue]]; case 130: return [AllTypes fromList:[self readValue]]; case 131: @@ -1823,10 +1841,10 @@ @interface FlutterIntegrationCoreApiCodecWriter : FlutterStandardWriter @end @implementation FlutterIntegrationCoreApiCodecWriter - (void)writeValue:(id)value { - if ([value isKindOfClass:[AllNullableTypes class]]) { + if ([value isKindOfClass:[AllClassesWrapper class]]) { [self writeByte:128]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllNullableTypesWrapper class]]) { + } else if ([value isKindOfClass:[AllNullableTypes class]]) { [self writeByte:129]; [self writeValue:[value toList]]; } else if ([value isKindOfClass:[AllTypes class]]) { diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/lib/main.dart b/packages/pigeon/platform_tests/alternate_language_test_plugin/lib/main.dart new file mode 100644 index 00000000000..84de3a47bed --- /dev/null +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/lib/main.dart @@ -0,0 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// There is intentionally no code here; tests use generated Pigeon APIs +// directly, as wrapping them in a plugin would just add maintenance burden +// when changing tests. diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h index e984aadb2bf..95b362e84e6 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h @@ -22,7 +22,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @class AllTypes; @class AllNullableTypes; -@class AllNullableTypesWrapper; +@class AllClassesWrapper; @class TestMessage; @interface AllTypes : NSObject @@ -39,8 +39,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { aList:(NSArray *)aList aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum - aString:(NSString *)aString - aClass:(AllNullableTypes *)aClass; + aString:(NSString *)aString; @property(nonatomic, strong) NSNumber *aBool; @property(nonatomic, strong) NSNumber *anInt; @property(nonatomic, strong) NSNumber *anInt64; @@ -53,7 +52,6 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong) NSDictionary *aMap; @property(nonatomic, assign) AnEnum anEnum; @property(nonatomic, copy) NSString *aString; -@property(nonatomic, strong) AllNullableTypes *aClass; @end @interface AllNullableTypes : NSObject @@ -72,8 +70,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { (nullable NSDictionary *)nullableMapWithAnnotations nullableMapWithObject:(nullable NSDictionary *)nullableMapWithObject aNullableEnum:(AnEnum)aNullableEnum - aNullableString:(nullable NSString *)aNullableString - aNullableClass:(nullable AllTypes *)aNullableClass; + aNullableString:(nullable NSString *)aNullableString; @property(nonatomic, strong, nullable) NSNumber *aNullableBool; @property(nonatomic, strong, nullable) NSNumber *aNullableInt; @property(nonatomic, strong, nullable) NSNumber *aNullableInt64; @@ -90,14 +87,15 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong, nullable) NSDictionary *nullableMapWithObject; @property(nonatomic, assign) AnEnum aNullableEnum; @property(nonatomic, copy, nullable) NSString *aNullableString; -@property(nonatomic, strong, nullable) AllTypes *aNullableClass; @end -@interface AllNullableTypesWrapper : NSObject +@interface AllClassesWrapper : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithValues:(AllNullableTypes *)values; -@property(nonatomic, strong) AllNullableTypes *values; ++ (instancetype)makeWithAllNullableTypes:(AllNullableTypes *)allNullableTypes + allTypes:(nullable AllTypes *)allTypes; +@property(nonatomic, strong) AllNullableTypes *allNullableTypes; +@property(nonatomic, strong, nullable) AllTypes *allTypes; @end /// A data class containing a List, used in unit tests. @@ -163,18 +161,23 @@ NSObject *HostIntegrationCoreApiGetCodec(void); /// @return `nil` only when `error != nil`. - (nullable NSDictionary *)echoMap:(NSDictionary *)aMap error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns the passed map to test nested class serialization and deserialization. +/// +/// @return `nil` only when `error != nil`. +- (nullable AllClassesWrapper *)echoClassWrapper:(AllClassesWrapper *)wrapper + error:(FlutterError *_Nullable *_Nonnull)error; /// Returns the passed object, to test serialization and deserialization. - (nullable AllNullableTypes *)echoAllNullableTypes:(nullable AllNullableTypes *)everything error:(FlutterError *_Nullable *_Nonnull)error; /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. -- (nullable NSString *)extractNestedNullableStringFrom:(AllNullableTypesWrapper *)wrapper +- (nullable NSString *)extractNestedNullableStringFrom:(AllClassesWrapper *)wrapper error:(FlutterError *_Nullable *_Nonnull)error; /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. /// /// @return `nil` only when `error != nil`. -- (nullable AllNullableTypesWrapper *) +- (nullable AllClassesWrapper *) createNestedObjectWithNullableString:(nullable NSString *)nullableString error:(FlutterError *_Nullable *_Nonnull)error; /// Returns passed in arguments of multiple types. diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m index 1c5fadaed47..510b9a8f96b 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m @@ -42,9 +42,9 @@ + (nullable AllNullableTypes *)nullableFromList:(NSArray *)list; - (NSArray *)toList; @end -@interface AllNullableTypesWrapper () -+ (AllNullableTypesWrapper *)fromList:(NSArray *)list; -+ (nullable AllNullableTypesWrapper *)nullableFromList:(NSArray *)list; +@interface AllClassesWrapper () ++ (AllClassesWrapper *)fromList:(NSArray *)list; ++ (nullable AllClassesWrapper *)nullableFromList:(NSArray *)list; - (NSArray *)toList; @end @@ -66,8 +66,7 @@ + (instancetype)makeWithABool:(NSNumber *)aBool aList:(NSArray *)aList aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum - aString:(NSString *)aString - aClass:(AllNullableTypes *)aClass { + aString:(NSString *)aString { AllTypes *pigeonResult = [[AllTypes alloc] init]; pigeonResult.aBool = aBool; pigeonResult.anInt = anInt; @@ -81,7 +80,6 @@ + (instancetype)makeWithABool:(NSNumber *)aBool pigeonResult.aMap = aMap; pigeonResult.anEnum = anEnum; pigeonResult.aString = aString; - pigeonResult.aClass = aClass; return pigeonResult; } + (AllTypes *)fromList:(NSArray *)list { @@ -109,8 +107,6 @@ + (AllTypes *)fromList:(NSArray *)list { pigeonResult.anEnum = [GetNullableObjectAtIndex(list, 10) integerValue]; pigeonResult.aString = GetNullableObjectAtIndex(list, 11); NSAssert(pigeonResult.aString != nil, @""); - pigeonResult.aClass = [AllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 12))]; - NSAssert(pigeonResult.aClass != nil, @""); return pigeonResult; } + (nullable AllTypes *)nullableFromList:(NSArray *)list { @@ -130,7 +126,6 @@ - (NSArray *)toList { (self.aMap ?: [NSNull null]), @(self.anEnum), (self.aString ?: [NSNull null]), - (self.aClass ? [self.aClass toList] : [NSNull null]), ]; } @end @@ -151,8 +146,7 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool (nullable NSDictionary *)nullableMapWithAnnotations nullableMapWithObject:(nullable NSDictionary *)nullableMapWithObject aNullableEnum:(AnEnum)aNullableEnum - aNullableString:(nullable NSString *)aNullableString - aNullableClass:(nullable AllTypes *)aNullableClass { + aNullableString:(nullable NSString *)aNullableString { AllNullableTypes *pigeonResult = [[AllNullableTypes alloc] init]; pigeonResult.aNullableBool = aNullableBool; pigeonResult.aNullableInt = aNullableInt; @@ -169,7 +163,6 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool pigeonResult.nullableMapWithObject = nullableMapWithObject; pigeonResult.aNullableEnum = aNullableEnum; pigeonResult.aNullableString = aNullableString; - pigeonResult.aNullableClass = aNullableClass; return pigeonResult; } + (AllNullableTypes *)fromList:(NSArray *)list { @@ -189,7 +182,6 @@ + (AllNullableTypes *)fromList:(NSArray *)list { pigeonResult.nullableMapWithObject = GetNullableObjectAtIndex(list, 12); pigeonResult.aNullableEnum = [GetNullableObjectAtIndex(list, 13) integerValue]; pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 14); - pigeonResult.aNullableClass = [AllTypes nullableFromList:(GetNullableObjectAtIndex(list, 15))]; return pigeonResult; } + (nullable AllNullableTypes *)nullableFromList:(NSArray *)list { @@ -212,29 +204,33 @@ - (NSArray *)toList { (self.nullableMapWithObject ?: [NSNull null]), @(self.aNullableEnum), (self.aNullableString ?: [NSNull null]), - (self.aNullableClass ? [self.aNullableClass toList] : [NSNull null]), ]; } @end -@implementation AllNullableTypesWrapper -+ (instancetype)makeWithValues:(AllNullableTypes *)values { - AllNullableTypesWrapper *pigeonResult = [[AllNullableTypesWrapper alloc] init]; - pigeonResult.values = values; +@implementation AllClassesWrapper ++ (instancetype)makeWithAllNullableTypes:(AllNullableTypes *)allNullableTypes + allTypes:(nullable AllTypes *)allTypes { + AllClassesWrapper *pigeonResult = [[AllClassesWrapper alloc] init]; + pigeonResult.allNullableTypes = allNullableTypes; + pigeonResult.allTypes = allTypes; return pigeonResult; } -+ (AllNullableTypesWrapper *)fromList:(NSArray *)list { - AllNullableTypesWrapper *pigeonResult = [[AllNullableTypesWrapper alloc] init]; - pigeonResult.values = [AllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 0))]; - NSAssert(pigeonResult.values != nil, @""); ++ (AllClassesWrapper *)fromList:(NSArray *)list { + AllClassesWrapper *pigeonResult = [[AllClassesWrapper alloc] init]; + pigeonResult.allNullableTypes = + [AllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 0))]; + NSAssert(pigeonResult.allNullableTypes != nil, @""); + pigeonResult.allTypes = [AllTypes nullableFromList:(GetNullableObjectAtIndex(list, 1))]; return pigeonResult; } -+ (nullable AllNullableTypesWrapper *)nullableFromList:(NSArray *)list { - return (list) ? [AllNullableTypesWrapper fromList:list] : nil; ++ (nullable AllClassesWrapper *)nullableFromList:(NSArray *)list { + return (list) ? [AllClassesWrapper fromList:list] : nil; } - (NSArray *)toList { return @[ - (self.values ? [self.values toList] : [NSNull null]), + (self.allNullableTypes ? [self.allNullableTypes toList] : [NSNull null]), + (self.allTypes ? [self.allTypes toList] : [NSNull null]), ]; } @end @@ -266,9 +262,9 @@ @implementation HostIntegrationCoreApiCodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { case 128: - return [AllNullableTypes fromList:[self readValue]]; + return [AllClassesWrapper fromList:[self readValue]]; case 129: - return [AllNullableTypesWrapper fromList:[self readValue]]; + return [AllNullableTypes fromList:[self readValue]]; case 130: return [AllTypes fromList:[self readValue]]; case 131: @@ -283,10 +279,10 @@ @interface HostIntegrationCoreApiCodecWriter : FlutterStandardWriter @end @implementation HostIntegrationCoreApiCodecWriter - (void)writeValue:(id)value { - if ([value isKindOfClass:[AllNullableTypes class]]) { + if ([value isKindOfClass:[AllClassesWrapper class]]) { [self writeByte:128]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllNullableTypesWrapper class]]) { + } else if ([value isKindOfClass:[AllNullableTypes class]]) { [self writeByte:129]; [self writeValue:[value toList]]; } else if ([value isKindOfClass:[AllTypes class]]) { @@ -596,6 +592,28 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, [channel setMessageHandler:nil]; } } + /// Returns the passed map to test nested class serialization and deserialization. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.echoClassWrapper" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert( + [api respondsToSelector:@selector(echoClassWrapper:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoClassWrapper:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + AllClassesWrapper *arg_wrapper = GetNullableObjectAtIndex(args, 0); + FlutterError *error; + AllClassesWrapper *output = [api echoClassWrapper:arg_wrapper error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } /// Returns the passed object, to test serialization and deserialization. { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] @@ -632,7 +650,7 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - AllNullableTypesWrapper *arg_wrapper = GetNullableObjectAtIndex(args, 0); + AllClassesWrapper *arg_wrapper = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSString *output = [api extractNestedNullableStringFrom:arg_wrapper error:&error]; callback(wrapResult(output, error)); @@ -657,8 +675,8 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, NSArray *args = message; NSString *arg_nullableString = GetNullableObjectAtIndex(args, 0); FlutterError *error; - AllNullableTypesWrapper *output = - [api createNestedObjectWithNullableString:arg_nullableString error:&error]; + AllClassesWrapper *output = [api createNestedObjectWithNullableString:arg_nullableString + error:&error]; callback(wrapResult(output, error)); }]; } else { @@ -1806,9 +1824,9 @@ @implementation FlutterIntegrationCoreApiCodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { case 128: - return [AllNullableTypes fromList:[self readValue]]; + return [AllClassesWrapper fromList:[self readValue]]; case 129: - return [AllNullableTypesWrapper fromList:[self readValue]]; + return [AllNullableTypes fromList:[self readValue]]; case 130: return [AllTypes fromList:[self readValue]]; case 131: @@ -1823,10 +1841,10 @@ @interface FlutterIntegrationCoreApiCodecWriter : FlutterStandardWriter @end @implementation FlutterIntegrationCoreApiCodecWriter - (void)writeValue:(id)value { - if ([value isKindOfClass:[AllNullableTypes class]]) { + if ([value isKindOfClass:[AllClassesWrapper class]]) { [self writeByte:128]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllNullableTypesWrapper class]]) { + } else if ([value isKindOfClass:[AllNullableTypes class]]) { [self writeByte:129]; [self writeValue:[value toList]]; } else if ([value isKindOfClass:[AllTypes class]]) { diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart index 7808355ecd0..a66b1c5cb91 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart @@ -32,7 +32,6 @@ class AllTypes { required this.aMap, required this.anEnum, required this.aString, - required this.aClass, }); bool aBool; @@ -59,8 +58,6 @@ class AllTypes { String aString; - AllNullableTypes aClass; - Object encode() { return [ aBool, @@ -75,7 +72,6 @@ class AllTypes { aMap, anEnum.index, aString, - aClass.encode(), ]; } @@ -94,7 +90,6 @@ class AllTypes { aMap: result[9]! as Map, anEnum: AnEnum.values[result[10]! as int], aString: result[11]! as String, - aClass: AllNullableTypes.decode(result[12]! as List), ); } } @@ -116,7 +111,6 @@ class AllNullableTypes { this.nullableMapWithObject, this.aNullableEnum, this.aNullableString, - this.aNullableClass, }); bool? aNullableBool; @@ -149,8 +143,6 @@ class AllNullableTypes { String? aNullableString; - AllTypes? aNullableClass; - Object encode() { return [ aNullableBool, @@ -168,7 +160,6 @@ class AllNullableTypes { nullableMapWithObject, aNullableEnum?.index, aNullableString, - aNullableClass?.encode(), ]; } @@ -193,30 +184,34 @@ class AllNullableTypes { aNullableEnum: result[13] != null ? AnEnum.values[result[13]! as int] : null, aNullableString: result[14] as String?, - aNullableClass: result[15] != null - ? AllTypes.decode(result[15]! as List) - : null, ); } } -class AllNullableTypesWrapper { - AllNullableTypesWrapper({ - required this.values, +class AllClassesWrapper { + AllClassesWrapper({ + required this.allNullableTypes, + this.allTypes, }); - AllNullableTypes values; + AllNullableTypes allNullableTypes; + + AllTypes? allTypes; Object encode() { return [ - values.encode(), + allNullableTypes.encode(), + allTypes?.encode(), ]; } - static AllNullableTypesWrapper decode(Object result) { + static AllClassesWrapper decode(Object result) { result as List; - return AllNullableTypesWrapper( - values: AllNullableTypes.decode(result[0]! as List), + return AllClassesWrapper( + allNullableTypes: AllNullableTypes.decode(result[0]! as List), + allTypes: result[1] != null + ? AllTypes.decode(result[1]! as List) + : null, ); } } @@ -247,10 +242,10 @@ class _HostIntegrationCoreApiCodec extends StandardMessageCodec { const _HostIntegrationCoreApiCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is AllNullableTypes) { + if (value is AllClassesWrapper) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is AllNullableTypesWrapper) { + } else if (value is AllNullableTypes) { buffer.putUint8(129); writeValue(buffer, value.encode()); } else if (value is AllTypes) { @@ -268,9 +263,9 @@ class _HostIntegrationCoreApiCodec extends StandardMessageCodec { Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { case 128: - return AllNullableTypes.decode(readValue(buffer)!); + return AllClassesWrapper.decode(readValue(buffer)!); case 129: - return AllNullableTypesWrapper.decode(readValue(buffer)!); + return AllNullableTypes.decode(readValue(buffer)!); case 130: return AllTypes.decode(readValue(buffer)!); case 131: @@ -634,6 +629,35 @@ class HostIntegrationCoreApi { } } + /// Returns the passed map to test nested class serialization and deserialization. + Future echoClassWrapper( + AllClassesWrapper arg_wrapper) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.echoClassWrapper', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_wrapper]) 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 AllClassesWrapper?)!; + } + } + /// Returns the passed object, to test serialization and deserialization. Future echoAllNullableTypes( AllNullableTypes? arg_everything) async { @@ -661,7 +685,7 @@ class HostIntegrationCoreApi { /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. Future extractNestedNullableString( - AllNullableTypesWrapper arg_wrapper) async { + AllClassesWrapper arg_wrapper) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.extractNestedNullableString', codec, @@ -686,7 +710,7 @@ class HostIntegrationCoreApi { /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. - Future createNestedNullableString( + Future createNestedNullableString( String? arg_nullableString) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.createNestedNullableString', @@ -711,7 +735,7 @@ class HostIntegrationCoreApi { message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as AllNullableTypesWrapper?)!; + return (replyList[0] as AllClassesWrapper?)!; } } @@ -1982,10 +2006,10 @@ class _FlutterIntegrationCoreApiCodec extends StandardMessageCodec { const _FlutterIntegrationCoreApiCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is AllNullableTypes) { + if (value is AllClassesWrapper) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is AllNullableTypesWrapper) { + } else if (value is AllNullableTypes) { buffer.putUint8(129); writeValue(buffer, value.encode()); } else if (value is AllTypes) { @@ -2003,9 +2027,9 @@ class _FlutterIntegrationCoreApiCodec extends StandardMessageCodec { Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { case 128: - return AllNullableTypes.decode(readValue(buffer)!); + return AllClassesWrapper.decode(readValue(buffer)!); case 129: - return AllNullableTypesWrapper.decode(readValue(buffer)!); + return AllNullableTypes.decode(readValue(buffer)!); case 130: return AllTypes.decode(readValue(buffer)!); case 131: 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 5f1a402bf18..73ed7aa07b4 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 @@ -39,6 +39,107 @@ enum TargetGenerator { void runPigeonIntegrationTests(TargetGenerator targetGenerator) { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + bool compareAllTypes(AllTypes? allTypesOne, AllTypes? allTypesTwo) { + if (allTypesOne == null && allTypesTwo == null) { + return true; + } + + if (allTypesOne == null || allTypesTwo == null) { + return false; + } + + expect(allTypesOne.aBool, allTypesTwo.aBool); + expect(allTypesOne.anInt, allTypesTwo.anInt); + expect(allTypesOne.anInt64, allTypesTwo.anInt64); + expect(allTypesOne.aDouble, allTypesTwo.aDouble); + expect(allTypesOne.aString, allTypesTwo.aString); + expect(allTypesOne.aByteArray, allTypesTwo.aByteArray); + expect(allTypesOne.a4ByteArray, allTypesTwo.a4ByteArray); + expect(allTypesOne.a8ByteArray, allTypesTwo.a8ByteArray); + expect(allTypesOne.aFloatArray, allTypesTwo.aFloatArray); + expect(listEquals(allTypesOne.aList, allTypesTwo.aList), true); + expect(mapEquals(allTypesOne.aMap, allTypesTwo.aMap), true); + expect(allTypesOne.anEnum, allTypesTwo.anEnum); + + return true; + } + + bool compareAllNullableTypes(AllNullableTypes? allNullableTypesOne, + AllNullableTypes? allNullableTypesTwo) { + if (allNullableTypesOne == null && allNullableTypesTwo == null) { + return true; + } + + if (allNullableTypesOne == null || allNullableTypesTwo == null) { + return false; + } + + expect( + allNullableTypesOne.aNullableBool, allNullableTypesTwo.aNullableBool); + expect(allNullableTypesOne.aNullableInt, allNullableTypesTwo.aNullableInt); + expect( + allNullableTypesOne.aNullableInt64, allNullableTypesTwo.aNullableInt64); + expect(allNullableTypesOne.aNullableDouble, + allNullableTypesTwo.aNullableDouble); + expect(allNullableTypesOne.aNullableString, + allNullableTypesTwo.aNullableString); + expect(allNullableTypesOne.aNullableByteArray, + allNullableTypesTwo.aNullableByteArray); + expect(allNullableTypesOne.aNullable4ByteArray, + allNullableTypesTwo.aNullable4ByteArray); + expect(allNullableTypesOne.aNullable8ByteArray, + allNullableTypesTwo.aNullable8ByteArray); + expect(allNullableTypesOne.aNullableFloatArray, + allNullableTypesTwo.aNullableFloatArray); + expect( + listEquals(allNullableTypesOne.aNullableList, + allNullableTypesTwo.aNullableList), + true); + expect( + mapEquals( + allNullableTypesOne.aNullableMap, allNullableTypesTwo.aNullableMap), + true); + expect(allNullableTypesOne.nullableNestedList?.length, + allNullableTypesTwo.nullableNestedList?.length); + // TODO(stuartmorgan): Enable this once the Dart types are fixed; see + // https://github.com/flutter/flutter/issues/116117 + //for (int i = 0; i < allNullableTypesOne.nullableNestedList!.length; i++) { + // expect(listEquals(allNullableTypesOne.nullableNestedList![i], allNullableTypesTwo.nullableNestedList![i]), + // true); + //} + expect( + mapEquals(allNullableTypesOne.nullableMapWithAnnotations, + allNullableTypesTwo.nullableMapWithAnnotations), + true); + expect( + mapEquals(allNullableTypesOne.nullableMapWithObject, + allNullableTypesTwo.nullableMapWithObject), + true); + // TODO(stuartmorgan): Fix and re-enable. + // See https://github.com/flutter/flutter/issues/118733 + if (targetGenerator != TargetGenerator.objc) { + expect( + allNullableTypesOne.aNullableEnum, allNullableTypesTwo.aNullableEnum); + } + + return true; + } + + bool compareAllClassesWrapper( + AllClassesWrapper? wrapperOne, AllClassesWrapper? wrapperTwo) { + if (wrapperOne == null && wrapperTwo == null) { + return true; + } + + if (wrapperOne == null || wrapperTwo == null) { + return false; + } + + return compareAllNullableTypes( + wrapperOne.allNullableTypes, wrapperTwo.allNullableTypes) && + compareAllTypes(wrapperOne.allTypes, wrapperTwo.allTypes); + } + final AllTypes genericAllTypes = AllTypes( aBool: true, anInt: _regularInt, @@ -58,7 +159,6 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { 'e': null }, anEnum: AnEnum.two, - aClass: AllNullableTypes(aNullableInt64: 1), ); final AllNullableTypes genericAllNullableTypes = AllNullableTypes( @@ -86,7 +186,6 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { nullableMapWithAnnotations: {}, nullableMapWithObject: {}, aNullableEnum: AnEnum.two, - aNullableClass: genericAllTypes, ); group('Host sync API tests', () { @@ -101,20 +200,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); final AllTypes echoObject = await api.echoAllTypes(genericAllTypes); - - expect(echoObject.aBool, genericAllTypes.aBool); - expect(echoObject.anInt, genericAllTypes.anInt); - expect(echoObject.anInt64, genericAllTypes.anInt64); - 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); - expect(echoObject.aClass, genericAllTypes.aClass); + expect(compareAllTypes(echoObject, genericAllTypes), true); }); testWidgets('all nullable datatypes serialize and deserialize correctly', @@ -123,49 +209,8 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes? echoObject = await api.echoAllNullableTypes(genericAllNullableTypes); - expect(echoObject?.aNullableBool, genericAllNullableTypes.aNullableBool); - expect(echoObject?.aNullableInt, genericAllNullableTypes.aNullableInt); - expect( - echoObject?.aNullableInt64, genericAllNullableTypes.aNullableInt64); - expect( - echoObject?.aNullableDouble, genericAllNullableTypes.aNullableDouble); expect( - echoObject?.aNullableString, genericAllNullableTypes.aNullableString); - expect(echoObject?.aNullableByteArray, - genericAllNullableTypes.aNullableByteArray); - expect(echoObject?.aNullable4ByteArray, - genericAllNullableTypes.aNullable4ByteArray); - expect(echoObject?.aNullable8ByteArray, - genericAllNullableTypes.aNullable8ByteArray); - expect(echoObject?.aNullableFloatArray, - genericAllNullableTypes.aNullableFloatArray); - expect( - listEquals( - echoObject?.aNullableList, genericAllNullableTypes.aNullableList), - true); - expect( - mapEquals( - echoObject?.aNullableMap, genericAllNullableTypes.aNullableMap), - true); - expect(echoObject?.nullableNestedList?.length, - genericAllNullableTypes.nullableNestedList?.length); - // TODO(stuartmorgan): Enable this once the Dart types are fixed; see - // https://github.com/flutter/flutter/issues/116117 - //for (int i = 0; i < echoObject?.nullableNestedList!.length; i++) { - // expect(listEquals(echoObject?.nullableNestedList![i], genericAllNullableTypes.nullableNestedList![i]), - // true); - //} - expect( - mapEquals(echoObject?.nullableMapWithAnnotations, - genericAllNullableTypes.nullableMapWithAnnotations), - true); - expect( - mapEquals(echoObject?.nullableMapWithObject, - genericAllNullableTypes.nullableMapWithObject), - true); - expect(echoObject?.aNullableEnum, genericAllNullableTypes.aNullableEnum); - expect( - echoObject?.aNullableClass, genericAllNullableTypes.aNullableClass); + compareAllNullableTypes(echoObject, genericAllNullableTypes), true); }); testWidgets('all null datatypes serialize and deserialize correctly', @@ -176,79 +221,8 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes? echoNullFilledClass = await api.echoAllNullableTypes(allTypesNull); - - expect(echoNullFilledClass?.aNullableBool, allTypesNull.aNullableBool); - expect(echoNullFilledClass?.aNullableBool, null); - - expect(echoNullFilledClass?.aNullableInt, allTypesNull.aNullableInt); - expect(echoNullFilledClass?.aNullableInt, null); - - expect(echoNullFilledClass?.aNullableInt64, allTypesNull.aNullableInt64); - expect(echoNullFilledClass?.aNullableInt64, null); - - expect( - echoNullFilledClass?.aNullableDouble, allTypesNull.aNullableDouble); - expect(echoNullFilledClass?.aNullableDouble, null); - - expect( - echoNullFilledClass?.aNullableString, allTypesNull.aNullableString); - expect(echoNullFilledClass?.aNullableString, null); - - expect(echoNullFilledClass?.aNullableByteArray, - allTypesNull.aNullableByteArray); - expect(echoNullFilledClass?.aNullableByteArray, null); - - expect(echoNullFilledClass?.aNullable4ByteArray, - allTypesNull.aNullable4ByteArray); - expect(echoNullFilledClass?.aNullable4ByteArray, null); - - expect(echoNullFilledClass?.aNullable8ByteArray, - allTypesNull.aNullable8ByteArray); - expect(echoNullFilledClass?.aNullable8ByteArray, null); - - expect(echoNullFilledClass?.aNullableFloatArray, - allTypesNull.aNullableFloatArray); - expect(echoNullFilledClass?.aNullableFloatArray, null); - - expect( - listEquals( - echoNullFilledClass?.aNullableList, allTypesNull.aNullableList), - true); - expect(echoNullFilledClass?.aNullableList, null); - - expect( - mapEquals( - echoNullFilledClass?.aNullableMap, allTypesNull.aNullableMap), - true); - expect(echoNullFilledClass?.aNullableMap, null); - - // TODO(stuartmorgan): Enable this once the Dart types are fixed; see - // https://github.com/flutter/flutter/issues/116117 - //for (int i = 0; i < echoNullFilledClass?.nullableNestedList!.length; i++) { - // expect(listEquals(echoNullFilledClass?.nullableNestedList![i], allTypesNull.nullableNestedList![i]), - // true); - //} - expect(echoNullFilledClass?.nullableNestedList, null); - - expect( - mapEquals(echoNullFilledClass?.nullableMapWithAnnotations, - allTypesNull.nullableMapWithAnnotations), - true); - expect(echoNullFilledClass?.nullableMapWithAnnotations, null); - - expect( - mapEquals(echoNullFilledClass?.nullableMapWithObject, - allTypesNull.nullableMapWithObject), - true); - expect(echoNullFilledClass?.nullableMapWithObject, null); - - expect(echoNullFilledClass?.aNullableEnum, allTypesNull.aNullableEnum); - expect(echoNullFilledClass?.aNullableEnum, null); - expect(echoNullFilledClass?.aNullableClass, allTypesNull.aNullableClass); - }, - // TODO(stuartmorgan): Fix and re-enable. - // See https://github.com/flutter/flutter/issues/118733 - skip: targetGenerator == TargetGenerator.objc); + expect(compareAllNullableTypes(allTypesNull, echoNullFilledClass), true); + }); testWidgets('Classes with list of null serialize and deserialize correctly', (WidgetTester _) async { @@ -260,8 +234,8 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes? echoNullFilledClass = await api.echoAllNullableTypes(nullableListTypes); - expect( - echoNullFilledClass?.aNullableList, nullableListTypes.aNullableList); + expect(compareAllNullableTypes(nullableListTypes, echoNullFilledClass), + true); }); testWidgets('Classes with map of null serialize and deserialize correctly', @@ -274,7 +248,8 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes? echoNullFilledClass = await api.echoAllNullableTypes(nullableListTypes); - expect(echoNullFilledClass?.aNullableMap, nullableListTypes.aNullableMap); + expect(compareAllNullableTypes(nullableListTypes, echoNullFilledClass), + true); }); testWidgets('errors are returned correctly', (WidgetTester _) async { @@ -310,12 +285,12 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { testWidgets('nested objects can be sent correctly', (WidgetTester _) async { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); - final AllNullableTypesWrapper sentObject = - AllNullableTypesWrapper(values: genericAllNullableTypes); + final AllClassesWrapper sentObject = AllClassesWrapper( + allNullableTypes: genericAllNullableTypes, allTypes: genericAllTypes); final String? receivedString = await api.extractNestedNullableString(sentObject); - expect(receivedString, sentObject.values.aNullableString); + expect(receivedString, sentObject.allNullableTypes.aNullableString); }); testWidgets('nested objects can be received correctly', @@ -323,9 +298,33 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); const String sentString = 'Some string'; - final AllNullableTypesWrapper receivedObject = + final AllClassesWrapper receivedObject = await api.createNestedNullableString(sentString); - expect(receivedObject.values.aNullableString, sentString); + expect(receivedObject.allNullableTypes.aNullableString, sentString); + }); + + testWidgets('nested classes can serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final AllClassesWrapper sentWrapper = AllClassesWrapper( + allNullableTypes: AllNullableTypes(), allTypes: genericAllTypes); + + final AllClassesWrapper receivedClassWrapper = + await api.echoClassWrapper(sentWrapper); + expect(compareAllClassesWrapper(sentWrapper, receivedClassWrapper), true); + }); + + testWidgets('nested null classes can serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final AllClassesWrapper sentWrapper = + AllClassesWrapper(allNullableTypes: AllNullableTypes()); + + final AllClassesWrapper receivedClassWrapper = + await api.echoClassWrapper(sentWrapper); + expect(compareAllClassesWrapper(sentWrapper, receivedClassWrapper), true); }); testWidgets( @@ -671,18 +670,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllTypes echoObject = await api.echoAsyncAllTypes(genericAllTypes); - expect(echoObject.aBool, genericAllTypes.aBool); - expect(echoObject.anInt, genericAllTypes.anInt); - expect(echoObject.anInt64, genericAllTypes.anInt64); - 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); + expect(compareAllTypes(echoObject, genericAllTypes), true); }); testWidgets( @@ -692,47 +680,8 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes? echoObject = await api.echoAsyncNullableAllNullableTypes(genericAllNullableTypes); - expect(echoObject?.aNullableBool, genericAllNullableTypes.aNullableBool); - expect(echoObject?.aNullableInt, genericAllNullableTypes.aNullableInt); expect( - echoObject?.aNullableInt64, genericAllNullableTypes.aNullableInt64); - expect( - echoObject?.aNullableDouble, genericAllNullableTypes.aNullableDouble); - expect( - echoObject?.aNullableString, genericAllNullableTypes.aNullableString); - expect(echoObject?.aNullableByteArray, - genericAllNullableTypes.aNullableByteArray); - expect(echoObject?.aNullable4ByteArray, - genericAllNullableTypes.aNullable4ByteArray); - expect(echoObject?.aNullable8ByteArray, - genericAllNullableTypes.aNullable8ByteArray); - expect(echoObject?.aNullableFloatArray, - genericAllNullableTypes.aNullableFloatArray); - expect( - listEquals( - echoObject?.aNullableList, genericAllNullableTypes.aNullableList), - true); - expect( - mapEquals( - echoObject?.aNullableMap, genericAllNullableTypes.aNullableMap), - true); - expect(echoObject?.nullableNestedList?.length, - genericAllNullableTypes.nullableNestedList?.length); - // TODO(stuartmorgan): Enable this once the Dart types are fixed; see - // https://github.com/flutter/flutter/issues/116117 - //for (int i = 0; i < echoObject?.nullableNestedList!.length; i++) { - // expect(listEquals(echoObject?.nullableNestedList![i], genericAllNullableTypes.nullableNestedList![i]), - // true); - //} - expect( - mapEquals(echoObject?.nullableMapWithAnnotations, - genericAllNullableTypes.nullableMapWithAnnotations), - true); - expect( - mapEquals(echoObject?.nullableMapWithObject, - genericAllNullableTypes.nullableMapWithObject), - true); - expect(echoObject?.aNullableEnum, genericAllNullableTypes.aNullableEnum); + compareAllNullableTypes(echoObject, genericAllNullableTypes), true); }); testWidgets('all null datatypes async serialize and deserialize correctly', @@ -743,79 +692,8 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes? echoNullFilledClass = await api.echoAsyncNullableAllNullableTypes(allTypesNull); - - expect(echoNullFilledClass?.aNullableBool, allTypesNull.aNullableBool); - expect(echoNullFilledClass?.aNullableBool, null); - - expect(echoNullFilledClass?.aNullableInt, allTypesNull.aNullableInt); - expect(echoNullFilledClass?.aNullableInt, null); - - expect(echoNullFilledClass?.aNullableInt64, allTypesNull.aNullableInt64); - expect(echoNullFilledClass?.aNullableInt64, null); - - expect( - echoNullFilledClass?.aNullableDouble, allTypesNull.aNullableDouble); - expect(echoNullFilledClass?.aNullableDouble, null); - - expect( - echoNullFilledClass?.aNullableString, allTypesNull.aNullableString); - expect(echoNullFilledClass?.aNullableString, null); - - expect(echoNullFilledClass?.aNullableByteArray, - allTypesNull.aNullableByteArray); - expect(echoNullFilledClass?.aNullableByteArray, null); - - expect(echoNullFilledClass?.aNullable4ByteArray, - allTypesNull.aNullable4ByteArray); - expect(echoNullFilledClass?.aNullable4ByteArray, null); - - expect(echoNullFilledClass?.aNullable8ByteArray, - allTypesNull.aNullable8ByteArray); - expect(echoNullFilledClass?.aNullable8ByteArray, null); - - expect(echoNullFilledClass?.aNullableFloatArray, - allTypesNull.aNullableFloatArray); - expect(echoNullFilledClass?.aNullableFloatArray, null); - - expect( - listEquals( - echoNullFilledClass?.aNullableList, allTypesNull.aNullableList), - true); - expect(echoNullFilledClass?.aNullableList, null); - - expect( - mapEquals( - echoNullFilledClass?.aNullableMap, allTypesNull.aNullableMap), - true); - expect(echoNullFilledClass?.aNullableMap, null); - - // TODO(stuartmorgan): Enable this once the Dart types are fixed; see - // https://github.com/flutter/flutter/issues/116117 - //for (int i = 0; i < echoNullFilledClass?.nullableNestedList!.length; i++) { - // expect(listEquals(echoNullFilledClass?.nullableNestedList![i], allTypesNull.nullableNestedList![i]), - // true); - //} - expect(echoNullFilledClass?.nullableNestedList, null); - - expect( - mapEquals(echoNullFilledClass?.nullableMapWithAnnotations, - allTypesNull.nullableMapWithAnnotations), - true); - expect(echoNullFilledClass?.nullableMapWithAnnotations, null); - - expect( - mapEquals(echoNullFilledClass?.nullableMapWithObject, - allTypesNull.nullableMapWithObject), - true); - expect(echoNullFilledClass?.nullableMapWithObject, null); - - expect(echoNullFilledClass?.aNullableEnum, allTypesNull.aNullableEnum); - expect(echoNullFilledClass?.aNullableEnum, null); - expect(echoNullFilledClass?.aNullableClass, allTypesNull.aNullableClass); - }, - // TODO(stuartmorgan): Fix and re-enable. - // See https://github.com/flutter/flutter/issues/118733 - skip: targetGenerator == TargetGenerator.objc); + expect(compareAllNullableTypes(echoNullFilledClass, allTypesNull), true); + }); testWidgets('Int async serialize and deserialize correctly', (WidgetTester _) async { @@ -1142,19 +1020,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllTypes echoObject = await api.callFlutterEchoAllTypes(genericAllTypes); - expect(echoObject.aBool, genericAllTypes.aBool); - expect(echoObject.anInt, genericAllTypes.anInt); - expect(echoObject.anInt64, genericAllTypes.anInt64); - 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); - expect(echoObject.aClass, genericAllNullableTypes.aNullableClass); + expect(compareAllTypes(echoObject, genericAllTypes), true); }); testWidgets( 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 dc7962773f3..94e63399dd2 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 @@ -32,7 +32,6 @@ class AllTypes { required this.aMap, required this.anEnum, required this.aString, - required this.aClass, }); bool aBool; @@ -59,8 +58,6 @@ class AllTypes { String aString; - AllNullableTypes aClass; - Object encode() { return [ aBool, @@ -75,7 +72,6 @@ class AllTypes { aMap, anEnum.index, aString, - aClass.encode(), ]; } @@ -94,7 +90,6 @@ class AllTypes { aMap: result[9]! as Map, anEnum: AnEnum.values[result[10]! as int], aString: result[11]! as String, - aClass: AllNullableTypes.decode(result[12]! as List), ); } } @@ -116,7 +111,6 @@ class AllNullableTypes { this.nullableMapWithObject, this.aNullableEnum, this.aNullableString, - this.aNullableClass, }); bool? aNullableBool; @@ -149,8 +143,6 @@ class AllNullableTypes { String? aNullableString; - AllTypes? aNullableClass; - Object encode() { return [ aNullableBool, @@ -168,7 +160,6 @@ class AllNullableTypes { nullableMapWithObject, aNullableEnum?.index, aNullableString, - aNullableClass?.encode(), ]; } @@ -193,30 +184,34 @@ class AllNullableTypes { aNullableEnum: result[13] != null ? AnEnum.values[result[13]! as int] : null, aNullableString: result[14] as String?, - aNullableClass: result[15] != null - ? AllTypes.decode(result[15]! as List) - : null, ); } } -class AllNullableTypesWrapper { - AllNullableTypesWrapper({ - required this.values, +class AllClassesWrapper { + AllClassesWrapper({ + required this.allNullableTypes, + this.allTypes, }); - AllNullableTypes values; + AllNullableTypes allNullableTypes; + + AllTypes? allTypes; Object encode() { return [ - values.encode(), + allNullableTypes.encode(), + allTypes?.encode(), ]; } - static AllNullableTypesWrapper decode(Object result) { + static AllClassesWrapper decode(Object result) { result as List; - return AllNullableTypesWrapper( - values: AllNullableTypes.decode(result[0]! as List), + return AllClassesWrapper( + allNullableTypes: AllNullableTypes.decode(result[0]! as List), + allTypes: result[1] != null + ? AllTypes.decode(result[1]! as List) + : null, ); } } @@ -247,10 +242,10 @@ class _HostIntegrationCoreApiCodec extends StandardMessageCodec { const _HostIntegrationCoreApiCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is AllNullableTypes) { + if (value is AllClassesWrapper) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is AllNullableTypesWrapper) { + } else if (value is AllNullableTypes) { buffer.putUint8(129); writeValue(buffer, value.encode()); } else if (value is AllTypes) { @@ -268,9 +263,9 @@ class _HostIntegrationCoreApiCodec extends StandardMessageCodec { Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { case 128: - return AllNullableTypes.decode(readValue(buffer)!); + return AllClassesWrapper.decode(readValue(buffer)!); case 129: - return AllNullableTypesWrapper.decode(readValue(buffer)!); + return AllNullableTypes.decode(readValue(buffer)!); case 130: return AllTypes.decode(readValue(buffer)!); case 131: @@ -634,6 +629,35 @@ class HostIntegrationCoreApi { } } + /// Returns the passed map to test nested class serialization and deserialization. + Future echoClassWrapper( + AllClassesWrapper arg_wrapper) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.echoClassWrapper', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_wrapper]) 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 AllClassesWrapper?)!; + } + } + /// Returns the passed object, to test serialization and deserialization. Future echoAllNullableTypes( AllNullableTypes? arg_everything) async { @@ -661,7 +685,7 @@ class HostIntegrationCoreApi { /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. Future extractNestedNullableString( - AllNullableTypesWrapper arg_wrapper) async { + AllClassesWrapper arg_wrapper) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.extractNestedNullableString', codec, @@ -686,7 +710,7 @@ class HostIntegrationCoreApi { /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. - Future createNestedNullableString( + Future createNestedNullableString( String? arg_nullableString) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.createNestedNullableString', @@ -711,7 +735,7 @@ class HostIntegrationCoreApi { message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as AllNullableTypesWrapper?)!; + return (replyList[0] as AllClassesWrapper?)!; } } @@ -1982,10 +2006,10 @@ class _FlutterIntegrationCoreApiCodec extends StandardMessageCodec { const _FlutterIntegrationCoreApiCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is AllNullableTypes) { + if (value is AllClassesWrapper) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is AllNullableTypesWrapper) { + } else if (value is AllNullableTypes) { buffer.putUint8(129); writeValue(buffer, value.encode()); } else if (value is AllTypes) { @@ -2003,9 +2027,9 @@ class _FlutterIntegrationCoreApiCodec extends StandardMessageCodec { Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { case 128: - return AllNullableTypes.decode(readValue(buffer)!); + return AllClassesWrapper.decode(readValue(buffer)!); case 129: - return AllNullableTypesWrapper.decode(readValue(buffer)!); + return AllNullableTypes.decode(readValue(buffer)!); case 130: return AllTypes.decode(readValue(buffer)!); case 131: 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 4d12d214aa3..06b6cfb25b5 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 @@ -72,8 +72,7 @@ data class AllTypes ( val aList: List, val aMap: Map, val anEnum: AnEnum, - val aString: String, - val aClass: AllNullableTypes + val aString: String ) { companion object { @@ -91,8 +90,7 @@ data class AllTypes ( val aMap = list[9] as Map val anEnum = AnEnum.ofRaw(list[10] as Int)!! val aString = list[11] as String - val aClass = AllNullableTypes.fromList(list[12] as List) - return AllTypes(aBool, anInt, anInt64, aDouble, aByteArray, a4ByteArray, a8ByteArray, aFloatArray, aList, aMap, anEnum, aString, aClass) + return AllTypes(aBool, anInt, anInt64, aDouble, aByteArray, a4ByteArray, a8ByteArray, aFloatArray, aList, aMap, anEnum, aString) } } fun toList(): List { @@ -109,7 +107,6 @@ data class AllTypes ( aMap, anEnum.raw, aString, - aClass.toList(), ) } } @@ -130,8 +127,7 @@ data class AllNullableTypes ( val nullableMapWithAnnotations: Map? = null, val nullableMapWithObject: Map? = null, val aNullableEnum: AnEnum? = null, - val aNullableString: String? = null, - val aNullableClass: AllTypes? = null + val aNullableString: String? = null ) { companion object { @@ -154,10 +150,7 @@ data class AllNullableTypes ( AnEnum.ofRaw(it) } val aNullableString = list[14] as String? - val aNullableClass: AllTypes? = (list[15] as List?)?.let { - AllTypes.fromList(it) - } - return AllNullableTypes(aNullableBool, aNullableInt, aNullableInt64, aNullableDouble, aNullableByteArray, aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, aNullableList, aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, aNullableEnum, aNullableString, aNullableClass) + return AllNullableTypes(aNullableBool, aNullableInt, aNullableInt64, aNullableDouble, aNullableByteArray, aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, aNullableList, aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, aNullableEnum, aNullableString) } } fun toList(): List { @@ -177,26 +170,30 @@ data class AllNullableTypes ( nullableMapWithObject, aNullableEnum?.raw, aNullableString, - aNullableClass?.toList(), ) } } /** Generated class from Pigeon that represents data sent in messages. */ -data class AllNullableTypesWrapper ( - val values: AllNullableTypes +data class AllClassesWrapper ( + val allNullableTypes: AllNullableTypes, + val allTypes: AllTypes? = null ) { companion object { @Suppress("UNCHECKED_CAST") - fun fromList(list: List): AllNullableTypesWrapper { - val values = AllNullableTypes.fromList(list[0] as List) - return AllNullableTypesWrapper(values) + fun fromList(list: List): AllClassesWrapper { + val allNullableTypes = AllNullableTypes.fromList(list[0] as List) + val allTypes: AllTypes? = (list[1] as List?)?.let { + AllTypes.fromList(it) + } + return AllClassesWrapper(allNullableTypes, allTypes) } } fun toList(): List { return listOf( - values.toList(), + allNullableTypes.toList(), + allTypes?.toList(), ) } } @@ -230,12 +227,12 @@ private object HostIntegrationCoreApiCodec : StandardMessageCodec() { return when (type) { 128.toByte() -> { return (readValue(buffer) as? List)?.let { - AllNullableTypes.fromList(it) + AllClassesWrapper.fromList(it) } } 129.toByte() -> { return (readValue(buffer) as? List)?.let { - AllNullableTypesWrapper.fromList(it) + AllNullableTypes.fromList(it) } } 130.toByte() -> { @@ -253,11 +250,11 @@ private object HostIntegrationCoreApiCodec : StandardMessageCodec() { } override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { when (value) { - is AllNullableTypes -> { + is AllClassesWrapper -> { stream.write(128) writeValue(stream, value.toList()) } - is AllNullableTypesWrapper -> { + is AllNullableTypes -> { stream.write(129) writeValue(stream, value.toList()) } @@ -310,18 +307,20 @@ interface HostIntegrationCoreApi { fun echoList(aList: List): List /** Returns the passed map, to test serialization and deserialization. */ fun echoMap(aMap: Map): Map + /** Returns the passed map to test nested class serialization and deserialization. */ + fun echoClassWrapper(wrapper: AllClassesWrapper): AllClassesWrapper /** Returns the passed object, to test serialization and deserialization. */ fun echoAllNullableTypes(everything: AllNullableTypes?): AllNullableTypes? /** * Returns the inner `aString` value from the wrapped object, to test * sending of nested objects. */ - fun extractNestedNullableString(wrapper: AllNullableTypesWrapper): String? + fun extractNestedNullableString(wrapper: AllClassesWrapper): String? /** * Returns the inner `aString` value from the wrapped object, to test * sending of nested objects. */ - fun createNestedNullableString(nullableString: String?): AllNullableTypesWrapper + fun createNestedNullableString(nullableString: String?): AllClassesWrapper /** Returns passed in arguments of multiple types. */ fun sendMultipleNullableTypes(aNullableBool: Boolean?, aNullableInt: Long?, aNullableString: String?): AllNullableTypes /** Returns passed in int. */ @@ -643,6 +642,24 @@ interface HostIntegrationCoreApi { channel.setMessageHandler(null) } } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.echoClassWrapper", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val wrapperArg = args[0] as AllClassesWrapper + var wrapped: List + try { + wrapped = listOf(api.echoClassWrapper(wrapperArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } run { val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllNullableTypes", codec) if (api != null) { @@ -666,7 +683,7 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val wrapperArg = args[0] as AllNullableTypesWrapper + val wrapperArg = args[0] as AllClassesWrapper var wrapped: List try { wrapped = listOf(api.extractNestedNullableString(wrapperArg)) @@ -1674,12 +1691,12 @@ private object FlutterIntegrationCoreApiCodec : StandardMessageCodec() { return when (type) { 128.toByte() -> { return (readValue(buffer) as? List)?.let { - AllNullableTypes.fromList(it) + AllClassesWrapper.fromList(it) } } 129.toByte() -> { return (readValue(buffer) as? List)?.let { - AllNullableTypesWrapper.fromList(it) + AllNullableTypes.fromList(it) } } 130.toByte() -> { @@ -1697,11 +1714,11 @@ private object FlutterIntegrationCoreApiCodec : StandardMessageCodec() { } override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { when (value) { - is AllNullableTypes -> { + is AllClassesWrapper -> { stream.write(128) writeValue(stream, value.toList()) } - is AllNullableTypesWrapper -> { + is AllNullableTypes -> { stream.write(129) writeValue(stream, value.toList()) } 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 1c2b68d8b41..93a6615752f 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 @@ -83,12 +83,16 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi { return aMap } - override fun extractNestedNullableString(wrapper: AllNullableTypesWrapper): String? { - return wrapper.values.aNullableString + override fun echoClassWrapper(wrapper: AllClassesWrapper): AllClassesWrapper { + return wrapper } - override fun createNestedNullableString(nullableString: String?): AllNullableTypesWrapper { - return AllNullableTypesWrapper(AllNullableTypes(aNullableString = nullableString)) + override fun extractNestedNullableString(wrapper: AllClassesWrapper): String? { + return wrapper.allNullableTypes.aNullableString + } + + override fun createNestedNullableString(nullableString: String?): AllClassesWrapper { + return AllClassesWrapper(AllNullableTypes(aNullableString = nullableString)) } override fun sendMultipleNullableTypes(aNullableBool: Boolean?, aNullableInt: Long?, aNullableString: String?): AllNullableTypes { diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt index 6faa1ff4f13..ca6e58418d4 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt @@ -14,6 +14,54 @@ import java.util.ArrayList internal class AllDatatypesTest: TestCase() { + fun compareAllTypes(firstTypes: AllTypes?, secondTypes: AllTypes?): Boolean { + + if (firstTypes == null && secondTypes == null) { + return true + } + if (firstTypes == null || secondTypes == null) { + return false + } + + assertEquals(firstTypes.aBool, secondTypes.aBool) + assertEquals(firstTypes.anInt, secondTypes.anInt) + assertEquals(firstTypes.anInt64, secondTypes.anInt64) + assertEquals(firstTypes.aDouble, secondTypes.aDouble) + assertEquals(firstTypes.aString, secondTypes.aString) + assertTrue(firstTypes.aByteArray.contentEquals(secondTypes.aByteArray)) + assertTrue(firstTypes.a4ByteArray.contentEquals(secondTypes.a4ByteArray)) + assertTrue(firstTypes.a8ByteArray.contentEquals(secondTypes.a8ByteArray)) + assertTrue(firstTypes.aFloatArray.contentEquals(secondTypes.aFloatArray)) + assertEquals(firstTypes.aList, secondTypes.aList) + assertEquals(firstTypes.aMap, secondTypes.aMap) + assertEquals(firstTypes.anEnum, secondTypes.anEnum) + + return true + } + + fun compareAllNullableTypes(firstTypes: AllNullableTypes?, secondTypes: AllNullableTypes?): Boolean { + if (firstTypes == null && secondTypes == null) { + return true + } + if (firstTypes == null || secondTypes == null) { + return false + } + + assertEquals(firstTypes.aNullableBool, secondTypes.aNullableBool) + assertEquals(firstTypes.aNullableInt, secondTypes.aNullableInt) + assertEquals(firstTypes.aNullableDouble, secondTypes.aNullableDouble) + assertEquals(firstTypes.aNullableString, secondTypes.aNullableString) + assertTrue(firstTypes.aNullableByteArray.contentEquals(secondTypes.aNullableByteArray)) + assertTrue(firstTypes.aNullable4ByteArray.contentEquals(secondTypes.aNullable4ByteArray)) + assertTrue(firstTypes.aNullable8ByteArray.contentEquals(secondTypes.aNullable8ByteArray)) + assertTrue(firstTypes.aNullableFloatArray.contentEquals(secondTypes.aNullableFloatArray)) + assertEquals(firstTypes.aNullableList, secondTypes.aNullableList) + assertEquals(firstTypes.aNullableMap, secondTypes.aNullableMap) + assertEquals(firstTypes.nullableMapWithObject, secondTypes.nullableMapWithObject) + + return true + } + @Test fun testNullValues() { val everything = AllNullableTypes() @@ -45,7 +93,6 @@ internal class AllDatatypesTest: TestCase() { assertNull(it.aNullableList) assertNull(it.aNullableMap) assertNull(it.nullableMapWithObject) - assertNull(it.aNullableClass) } assertTrue(didCall) @@ -65,20 +112,6 @@ internal class AllDatatypesTest: TestCase() { aNullableList = listOf(1, 2, 3), aNullableMap = mapOf("hello" to 1234), nullableMapWithObject = mapOf("hello" to 1234), - aNullableClass = AllTypes( - true, - 1234L, - 2.0, - "hello", - byteArrayOf(1, 2, 3, 4), - intArrayOf(1, 2, 3, 4), - longArrayOf(1, 2, 3, 4), - doubleArrayOf(0.5, 0.25, 1.5, 1.25), - listOf(1, 2, 3), - mapOf("hello" to 1234), - mapOf("hello" to 1234), - AllNullableTypes() - ), ) val binaryMessenger = mockk() val api = FlutterIntegrationCoreApi(binaryMessenger) @@ -97,18 +130,7 @@ internal class AllDatatypesTest: TestCase() { var didCall = false api.echoAllNullableTypes(everything) { didCall = true - assertEquals(everything.aNullableBool, it.aNullableBool) - assertEquals(everything.aNullableInt, it.aNullableInt) - assertEquals(everything.aNullableDouble, it.aNullableDouble) - assertEquals(everything.aNullableString, it.aNullableString) - assertTrue(everything.aNullableByteArray.contentEquals(it.aNullableByteArray)) - assertTrue(everything.aNullable4ByteArray.contentEquals(it.aNullable4ByteArray)) - assertTrue(everything.aNullable8ByteArray.contentEquals(it.aNullable8ByteArray)) - assertTrue(everything.aNullableFloatArray.contentEquals(it.aNullableFloatArray)) - assertEquals(everything.aNullableList, it.aNullableList) - assertEquals(everything.aNullableMap, it.aNullableMap) - assertEquals(everything.nullableMapWithObject, it.nullableMapWithObject) - assertEquals(everything.aNullableClass, it.aNullableClass) + assertTrue(compareAllNullableTypes(everything, it)) } assertTrue(didCall) @@ -123,7 +145,7 @@ internal class AllDatatypesTest: TestCase() { assertNotNull(list[1]) assertTrue(list[1] == 123L) - val list2 = listOf(null, 123, null, null, null, null, null, null, null, null, null, null, null, null, null, null) + val list2 = listOf(null, 123, null, null, null, null, null, null, null, null, null, null, null, null, null) val everything2 = AllNullableTypes.fromList(list2) assertEquals(everything.aNullableInt, everything2.aNullableInt) 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 b407926ca29..2328e419db4 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 @@ -58,7 +58,6 @@ struct AllTypes { var aMap: [AnyHashable: Any?] var anEnum: AnEnum var aString: String - var aClass: AllNullableTypes static func fromList(_ list: [Any?]) -> AllTypes? { let aBool = list[0] as! Bool @@ -73,7 +72,6 @@ struct AllTypes { let aMap = list[9] as! [AnyHashable: Any?] let anEnum = AnEnum(rawValue: list[10] as! Int)! let aString = list[11] as! String - let aClass = AllNullableTypes.fromList(list[12] as! [Any?])! return AllTypes( aBool: aBool, @@ -87,8 +85,7 @@ struct AllTypes { aList: aList, aMap: aMap, anEnum: anEnum, - aString: aString, - aClass: aClass + aString: aString ) } func toList() -> [Any?] { @@ -105,7 +102,6 @@ struct AllTypes { aMap, anEnum.rawValue, aString, - aClass.toList(), ] } } @@ -127,7 +123,6 @@ struct AllNullableTypes { var nullableMapWithObject: [String?: Any?]? = nil var aNullableEnum: AnEnum? = nil var aNullableString: String? = nil - var aNullableClass: AllTypes? = nil static func fromList(_ list: [Any?]) -> AllNullableTypes? { let aNullableBool: Bool? = nilOrValue(list[0]) @@ -149,10 +144,6 @@ struct AllNullableTypes { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! } let aNullableString: String? = nilOrValue(list[14]) - var aNullableClass: AllTypes? = nil - if let aNullableClassList: [Any?] = nilOrValue(list[15]) { - aNullableClass = AllTypes.fromList(aNullableClassList) - } return AllNullableTypes( aNullableBool: aNullableBool, @@ -169,8 +160,7 @@ struct AllNullableTypes { nullableMapWithAnnotations: nullableMapWithAnnotations, nullableMapWithObject: nullableMapWithObject, aNullableEnum: aNullableEnum, - aNullableString: aNullableString, - aNullableClass: aNullableClass + aNullableString: aNullableString ) } func toList() -> [Any?] { @@ -190,25 +180,31 @@ struct AllNullableTypes { nullableMapWithObject, aNullableEnum?.rawValue, aNullableString, - aNullableClass?.toList(), ] } } /// Generated class from Pigeon that represents data sent in messages. -struct AllNullableTypesWrapper { - var values: AllNullableTypes +struct AllClassesWrapper { + var allNullableTypes: AllNullableTypes + var allTypes: AllTypes? = nil - static func fromList(_ list: [Any?]) -> AllNullableTypesWrapper? { - let values = AllNullableTypes.fromList(list[0] as! [Any?])! + static func fromList(_ list: [Any?]) -> AllClassesWrapper? { + let allNullableTypes = AllNullableTypes.fromList(list[0] as! [Any?])! + var allTypes: AllTypes? = nil + if let allTypesList: [Any?] = nilOrValue(list[1]) { + allTypes = AllTypes.fromList(allTypesList) + } - return AllNullableTypesWrapper( - values: values + return AllClassesWrapper( + allNullableTypes: allNullableTypes, + allTypes: allTypes ) } func toList() -> [Any?] { return [ - values.toList(), + allNullableTypes.toList(), + allTypes?.toList(), ] } } @@ -237,9 +233,9 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { case 128: - return AllNullableTypes.fromList(self.readValue() as! [Any?]) + return AllClassesWrapper.fromList(self.readValue() as! [Any?]) case 129: - return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?]) + return AllNullableTypes.fromList(self.readValue() as! [Any?]) case 130: return AllTypes.fromList(self.readValue() as! [Any?]) case 131: @@ -252,10 +248,10 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader { private class HostIntegrationCoreApiCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { - if let value = value as? AllNullableTypes { + if let value = value as? AllClassesWrapper { super.writeByte(128) super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypesWrapper { + } else if let value = value as? AllNullableTypes { super.writeByte(129) super.writeValue(value.toList()) } else if let value = value as? AllTypes { @@ -316,14 +312,16 @@ protocol HostIntegrationCoreApi { func echo(_ aList: [Any?]) throws -> [Any?] /// Returns the passed map, to test serialization and deserialization. func echo(_ aMap: [String?: Any?]) throws -> [String?: Any?] + /// Returns the passed map to test nested class serialization and deserialization. + func echo(_ wrapper: AllClassesWrapper) throws -> AllClassesWrapper /// Returns the passed object, to test serialization and deserialization. func echo(_ everything: AllNullableTypes?) throws -> AllNullableTypes? /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. - func extractNestedNullableString(from wrapper: AllNullableTypesWrapper) throws -> String? + func extractNestedNullableString(from wrapper: AllClassesWrapper) throws -> String? /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. - func createNestedObject(with nullableString: String?) throws -> AllNullableTypesWrapper + func createNestedObject(with nullableString: String?) throws -> AllClassesWrapper /// Returns passed in arguments of multiple types. func sendMultipleNullableTypes(aBool aNullableBool: Bool?, anInt aNullableInt: Int64?, aString aNullableString: String?) throws -> AllNullableTypes /// Returns passed in int. @@ -615,6 +613,22 @@ class HostIntegrationCoreApiSetup { } else { echoMapChannel.setMessageHandler(nil) } + /// Returns the passed map to test nested class serialization and deserialization. + let echoClassWrapperChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoClassWrapper", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoClassWrapperChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let wrapperArg = args[0] as! AllClassesWrapper + do { + let result = try api.echo(wrapperArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoClassWrapperChannel.setMessageHandler(nil) + } /// Returns the passed object, to test serialization and deserialization. let echoAllNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { @@ -637,7 +651,7 @@ class HostIntegrationCoreApiSetup { if let api = api { extractNestedNullableStringChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let wrapperArg = args[0] as! AllNullableTypesWrapper + let wrapperArg = args[0] as! AllClassesWrapper do { let result = try api.extractNestedNullableString(from: wrapperArg) reply(wrapResult(result)) @@ -1525,9 +1539,9 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { case 128: - return AllNullableTypes.fromList(self.readValue() as! [Any?]) + return AllClassesWrapper.fromList(self.readValue() as! [Any?]) case 129: - return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?]) + return AllNullableTypes.fromList(self.readValue() as! [Any?]) case 130: return AllTypes.fromList(self.readValue() as! [Any?]) case 131: @@ -1540,10 +1554,10 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader { private class FlutterIntegrationCoreApiCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { - if let value = value as? AllNullableTypes { + if let value = value as? AllClassesWrapper { super.writeByte(128) super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypesWrapper { + } else if let value = value as? AllNullableTypes { super.writeByte(129) super.writeValue(value.toList()) } else if let value = value as? AllTypes { 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 368dbdeb64f..315c86c81e2 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -81,12 +81,16 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return aMap } - func extractNestedNullableString(from wrapper: AllNullableTypesWrapper) -> String? { - return wrapper.values.aNullableString; + func echo(_ wrapper: AllClassesWrapper) throws -> AllClassesWrapper { + return wrapper + } + + func extractNestedNullableString(from wrapper: AllClassesWrapper) -> String? { + return wrapper.allNullableTypes.aNullableString; } - func createNestedObject(with nullableString: String?) -> AllNullableTypesWrapper { - return AllNullableTypesWrapper(values: AllNullableTypes(aNullableString: nullableString)) + func createNestedObject(with nullableString: String?) -> AllClassesWrapper { + return AllClassesWrapper(allNullableTypes: AllNullableTypes(aNullableString: nullableString)) } func sendMultipleNullableTypes(aBool aNullableBool: Bool?, anInt aNullableInt: Int64?, aString aNullableString: String?) -> AllNullableTypes { 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 b407926ca29..2328e419db4 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 @@ -58,7 +58,6 @@ struct AllTypes { var aMap: [AnyHashable: Any?] var anEnum: AnEnum var aString: String - var aClass: AllNullableTypes static func fromList(_ list: [Any?]) -> AllTypes? { let aBool = list[0] as! Bool @@ -73,7 +72,6 @@ struct AllTypes { let aMap = list[9] as! [AnyHashable: Any?] let anEnum = AnEnum(rawValue: list[10] as! Int)! let aString = list[11] as! String - let aClass = AllNullableTypes.fromList(list[12] as! [Any?])! return AllTypes( aBool: aBool, @@ -87,8 +85,7 @@ struct AllTypes { aList: aList, aMap: aMap, anEnum: anEnum, - aString: aString, - aClass: aClass + aString: aString ) } func toList() -> [Any?] { @@ -105,7 +102,6 @@ struct AllTypes { aMap, anEnum.rawValue, aString, - aClass.toList(), ] } } @@ -127,7 +123,6 @@ struct AllNullableTypes { var nullableMapWithObject: [String?: Any?]? = nil var aNullableEnum: AnEnum? = nil var aNullableString: String? = nil - var aNullableClass: AllTypes? = nil static func fromList(_ list: [Any?]) -> AllNullableTypes? { let aNullableBool: Bool? = nilOrValue(list[0]) @@ -149,10 +144,6 @@ struct AllNullableTypes { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! } let aNullableString: String? = nilOrValue(list[14]) - var aNullableClass: AllTypes? = nil - if let aNullableClassList: [Any?] = nilOrValue(list[15]) { - aNullableClass = AllTypes.fromList(aNullableClassList) - } return AllNullableTypes( aNullableBool: aNullableBool, @@ -169,8 +160,7 @@ struct AllNullableTypes { nullableMapWithAnnotations: nullableMapWithAnnotations, nullableMapWithObject: nullableMapWithObject, aNullableEnum: aNullableEnum, - aNullableString: aNullableString, - aNullableClass: aNullableClass + aNullableString: aNullableString ) } func toList() -> [Any?] { @@ -190,25 +180,31 @@ struct AllNullableTypes { nullableMapWithObject, aNullableEnum?.rawValue, aNullableString, - aNullableClass?.toList(), ] } } /// Generated class from Pigeon that represents data sent in messages. -struct AllNullableTypesWrapper { - var values: AllNullableTypes +struct AllClassesWrapper { + var allNullableTypes: AllNullableTypes + var allTypes: AllTypes? = nil - static func fromList(_ list: [Any?]) -> AllNullableTypesWrapper? { - let values = AllNullableTypes.fromList(list[0] as! [Any?])! + static func fromList(_ list: [Any?]) -> AllClassesWrapper? { + let allNullableTypes = AllNullableTypes.fromList(list[0] as! [Any?])! + var allTypes: AllTypes? = nil + if let allTypesList: [Any?] = nilOrValue(list[1]) { + allTypes = AllTypes.fromList(allTypesList) + } - return AllNullableTypesWrapper( - values: values + return AllClassesWrapper( + allNullableTypes: allNullableTypes, + allTypes: allTypes ) } func toList() -> [Any?] { return [ - values.toList(), + allNullableTypes.toList(), + allTypes?.toList(), ] } } @@ -237,9 +233,9 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { case 128: - return AllNullableTypes.fromList(self.readValue() as! [Any?]) + return AllClassesWrapper.fromList(self.readValue() as! [Any?]) case 129: - return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?]) + return AllNullableTypes.fromList(self.readValue() as! [Any?]) case 130: return AllTypes.fromList(self.readValue() as! [Any?]) case 131: @@ -252,10 +248,10 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader { private class HostIntegrationCoreApiCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { - if let value = value as? AllNullableTypes { + if let value = value as? AllClassesWrapper { super.writeByte(128) super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypesWrapper { + } else if let value = value as? AllNullableTypes { super.writeByte(129) super.writeValue(value.toList()) } else if let value = value as? AllTypes { @@ -316,14 +312,16 @@ protocol HostIntegrationCoreApi { func echo(_ aList: [Any?]) throws -> [Any?] /// Returns the passed map, to test serialization and deserialization. func echo(_ aMap: [String?: Any?]) throws -> [String?: Any?] + /// Returns the passed map to test nested class serialization and deserialization. + func echo(_ wrapper: AllClassesWrapper) throws -> AllClassesWrapper /// Returns the passed object, to test serialization and deserialization. func echo(_ everything: AllNullableTypes?) throws -> AllNullableTypes? /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. - func extractNestedNullableString(from wrapper: AllNullableTypesWrapper) throws -> String? + func extractNestedNullableString(from wrapper: AllClassesWrapper) throws -> String? /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. - func createNestedObject(with nullableString: String?) throws -> AllNullableTypesWrapper + func createNestedObject(with nullableString: String?) throws -> AllClassesWrapper /// Returns passed in arguments of multiple types. func sendMultipleNullableTypes(aBool aNullableBool: Bool?, anInt aNullableInt: Int64?, aString aNullableString: String?) throws -> AllNullableTypes /// Returns passed in int. @@ -615,6 +613,22 @@ class HostIntegrationCoreApiSetup { } else { echoMapChannel.setMessageHandler(nil) } + /// Returns the passed map to test nested class serialization and deserialization. + let echoClassWrapperChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoClassWrapper", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoClassWrapperChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let wrapperArg = args[0] as! AllClassesWrapper + do { + let result = try api.echo(wrapperArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoClassWrapperChannel.setMessageHandler(nil) + } /// Returns the passed object, to test serialization and deserialization. let echoAllNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { @@ -637,7 +651,7 @@ class HostIntegrationCoreApiSetup { if let api = api { extractNestedNullableStringChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let wrapperArg = args[0] as! AllNullableTypesWrapper + let wrapperArg = args[0] as! AllClassesWrapper do { let result = try api.extractNestedNullableString(from: wrapperArg) reply(wrapResult(result)) @@ -1525,9 +1539,9 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { case 128: - return AllNullableTypes.fromList(self.readValue() as! [Any?]) + return AllClassesWrapper.fromList(self.readValue() as! [Any?]) case 129: - return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?]) + return AllNullableTypes.fromList(self.readValue() as! [Any?]) case 130: return AllTypes.fromList(self.readValue() as! [Any?]) case 131: @@ -1540,10 +1554,10 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader { private class FlutterIntegrationCoreApiCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { - if let value = value as? AllNullableTypes { + if let value = value as? AllClassesWrapper { super.writeByte(128) super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypesWrapper { + } else if let value = value as? AllNullableTypes { super.writeByte(129) super.writeValue(value.toList()) } else if let value = value as? AllTypes { 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 51a68c370e9..d5f27f6aea0 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -80,12 +80,16 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return aMap } - func extractNestedNullableString(from wrapper: AllNullableTypesWrapper) -> String? { - return wrapper.values.aNullableString; + func echo(_ wrapper: AllClassesWrapper) throws -> AllClassesWrapper { + return wrapper + } + + func extractNestedNullableString(from wrapper: AllClassesWrapper) -> String? { + return wrapper.allNullableTypes.aNullableString; } - func createNestedObject(with nullableString: String?) -> AllNullableTypesWrapper { - return AllNullableTypesWrapper(values: AllNullableTypes(aNullableString: nullableString)) + func createNestedObject(with nullableString: String?) -> AllClassesWrapper { + return AllClassesWrapper(allNullableTypes: AllNullableTypes(aNullableString: nullableString)) } func sendMultipleNullableTypes(aBool aNullableBool: Bool?, anInt aNullableInt: Int64?, aString aNullableString: String?) -> AllNullableTypes { 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 a1ac57ffe4c..af8e5a20c45 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 @@ -33,8 +33,7 @@ AllTypes::AllTypes(bool a_bool, int64_t an_int, int64_t an_int64, const std::vector& a8_byte_array, const std::vector& a_float_array, const EncodableList& a_list, const EncodableMap& a_map, - const AnEnum& an_enum, const std::string& a_string, - const AllNullableTypes& a_class) + const AnEnum& an_enum, const std::string& a_string) : a_bool_(a_bool), an_int_(an_int), an_int64_(an_int64), @@ -46,8 +45,7 @@ AllTypes::AllTypes(bool a_bool, int64_t an_int, int64_t an_int64, a_list_(a_list), a_map_(a_map), an_enum_(an_enum), - a_string_(a_string), - a_class_(a_class) {} + a_string_(a_string) {} bool AllTypes::a_bool() const { return a_bool_; } @@ -117,15 +115,9 @@ void AllTypes::set_a_string(std::string_view value_arg) { a_string_ = value_arg; } -const AllNullableTypes& AllTypes::a_class() const { return a_class_; } - -void AllTypes::set_a_class(const AllNullableTypes& value_arg) { - a_class_ = value_arg; -} - EncodableList AllTypes::ToEncodableList() const { EncodableList list; - list.reserve(13); + list.reserve(12); list.push_back(EncodableValue(a_bool_)); list.push_back(EncodableValue(an_int_)); list.push_back(EncodableValue(an_int64_)); @@ -138,7 +130,6 @@ EncodableList AllTypes::ToEncodableList() const { list.push_back(EncodableValue(a_map_)); list.push_back(EncodableValue((int)an_enum_)); list.push_back(EncodableValue(a_string_)); - list.push_back(EncodableValue(a_class_.ToEncodableList())); return list; } @@ -150,8 +141,7 @@ AllTypes AllTypes::FromEncodableList(const EncodableList& list) { std::get>(list[6]), std::get>(list[7]), std::get(list[8]), std::get(list[9]), (AnEnum)(std::get(list[10])), - std::get(list[11]), - AllNullableTypes::FromEncodableList(std::get(list[12]))); + std::get(list[11])); return decoded; } @@ -170,7 +160,7 @@ AllNullableTypes::AllNullableTypes( const EncodableList* nullable_nested_list, const EncodableMap* nullable_map_with_annotations, const EncodableMap* nullable_map_with_object, const AnEnum* a_nullable_enum, - const std::string* a_nullable_string, const AllTypes* a_nullable_class) + const std::string* a_nullable_string) : a_nullable_bool_(a_nullable_bool ? std::optional(*a_nullable_bool) : std::nullopt), a_nullable_int_(a_nullable_int ? std::optional(*a_nullable_int) @@ -218,10 +208,7 @@ AllNullableTypes::AllNullableTypes( : std::nullopt), a_nullable_string_(a_nullable_string ? std::optional(*a_nullable_string) - : std::nullopt), - a_nullable_class_(a_nullable_class - ? std::optional(*a_nullable_class) - : std::nullopt) {} + : std::nullopt) {} const bool* AllNullableTypes::a_nullable_bool() const { return a_nullable_bool_ ? &(*a_nullable_bool_) : nullptr; @@ -436,22 +423,9 @@ void AllNullableTypes::set_a_nullable_string(std::string_view value_arg) { a_nullable_string_ = value_arg; } -const AllTypes* AllNullableTypes::a_nullable_class() const { - return a_nullable_class_ ? &(*a_nullable_class_) : nullptr; -} - -void AllNullableTypes::set_a_nullable_class(const AllTypes* value_arg) { - a_nullable_class_ = - value_arg ? std::optional(*value_arg) : std::nullopt; -} - -void AllNullableTypes::set_a_nullable_class(const AllTypes& value_arg) { - a_nullable_class_ = value_arg; -} - EncodableList AllNullableTypes::ToEncodableList() const { EncodableList list; - list.reserve(16); + list.reserve(15); list.push_back(a_nullable_bool_ ? EncodableValue(*a_nullable_bool_) : EncodableValue()); list.push_back(a_nullable_int_ ? EncodableValue(*a_nullable_int_) @@ -488,9 +462,6 @@ EncodableList AllNullableTypes::ToEncodableList() const { : EncodableValue()); list.push_back(a_nullable_string_ ? EncodableValue(*a_nullable_string_) : EncodableValue()); - list.push_back(a_nullable_class_ - ? EncodableValue(a_nullable_class_->ToEncodableList()) - : EncodableValue()); return list; } @@ -569,38 +540,59 @@ AllNullableTypes AllNullableTypes::FromEncodableList( decoded.set_a_nullable_string( std::get(encodable_a_nullable_string)); } - auto& encodable_a_nullable_class = list[15]; - if (!encodable_a_nullable_class.IsNull()) { - decoded.set_a_nullable_class(AllTypes::FromEncodableList( - std::get(encodable_a_nullable_class))); - } return decoded; } -// AllNullableTypesWrapper +// AllClassesWrapper + +AllClassesWrapper::AllClassesWrapper(const AllNullableTypes& all_nullable_types) + : all_nullable_types_(all_nullable_types) {} + +AllClassesWrapper::AllClassesWrapper(const AllNullableTypes& all_nullable_types, + const AllTypes* all_types) + : all_nullable_types_(all_nullable_types), + all_types_(all_types ? std::optional(*all_types) + : std::nullopt) {} + +const AllNullableTypes& AllClassesWrapper::all_nullable_types() const { + return all_nullable_types_; +} + +void AllClassesWrapper::set_all_nullable_types( + const AllNullableTypes& value_arg) { + all_nullable_types_ = value_arg; +} -AllNullableTypesWrapper::AllNullableTypesWrapper(const AllNullableTypes& values) - : values_(values) {} +const AllTypes* AllClassesWrapper::all_types() const { + return all_types_ ? &(*all_types_) : nullptr; +} -const AllNullableTypes& AllNullableTypesWrapper::values() const { - return values_; +void AllClassesWrapper::set_all_types(const AllTypes* value_arg) { + all_types_ = value_arg ? std::optional(*value_arg) : std::nullopt; } -void AllNullableTypesWrapper::set_values(const AllNullableTypes& value_arg) { - values_ = value_arg; +void AllClassesWrapper::set_all_types(const AllTypes& value_arg) { + all_types_ = value_arg; } -EncodableList AllNullableTypesWrapper::ToEncodableList() const { +EncodableList AllClassesWrapper::ToEncodableList() const { EncodableList list; - list.reserve(1); - list.push_back(EncodableValue(values_.ToEncodableList())); + list.reserve(2); + list.push_back(EncodableValue(all_nullable_types_.ToEncodableList())); + list.push_back(all_types_ ? EncodableValue(all_types_->ToEncodableList()) + : EncodableValue()); return list; } -AllNullableTypesWrapper AllNullableTypesWrapper::FromEncodableList( +AllClassesWrapper AllClassesWrapper::FromEncodableList( const EncodableList& list) { - AllNullableTypesWrapper decoded( + AllClassesWrapper decoded( AllNullableTypes::FromEncodableList(std::get(list[0]))); + auto& encodable_all_types = list[1]; + if (!encodable_all_types.IsNull()) { + decoded.set_all_types(AllTypes::FromEncodableList( + std::get(encodable_all_types))); + } return decoded; } @@ -648,10 +640,10 @@ EncodableValue HostIntegrationCoreApiCodecSerializer::ReadValueOfType( uint8_t type, flutter::ByteStreamReader* stream) const { switch (type) { case 128: - return CustomEncodableValue(AllNullableTypes::FromEncodableList( + return CustomEncodableValue(AllClassesWrapper::FromEncodableList( std::get(ReadValue(stream)))); case 129: - return CustomEncodableValue(AllNullableTypesWrapper::FromEncodableList( + return CustomEncodableValue(AllNullableTypes::FromEncodableList( std::get(ReadValue(stream)))); case 130: return CustomEncodableValue(AllTypes::FromEncodableList( @@ -668,19 +660,18 @@ void HostIntegrationCoreApiCodecSerializer::WriteValue( const EncodableValue& value, flutter::ByteStreamWriter* stream) const { if (const CustomEncodableValue* custom_value = std::get_if(&value)) { - if (custom_value->type() == typeid(AllNullableTypes)) { + if (custom_value->type() == typeid(AllClassesWrapper)) { stream->WriteByte(128); - WriteValue( - EncodableValue( - std::any_cast(*custom_value).ToEncodableList()), - stream); + WriteValue(EncodableValue(std::any_cast(*custom_value) + .ToEncodableList()), + stream); return; } - if (custom_value->type() == typeid(AllNullableTypesWrapper)) { + if (custom_value->type() == typeid(AllNullableTypes)) { stream->WriteByte(129); WriteValue( - EncodableValue(std::any_cast(*custom_value) - .ToEncodableList()), + EncodableValue( + std::any_cast(*custom_value).ToEncodableList()), stream); return; } @@ -1124,6 +1115,42 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, channel->SetMessageHandler(nullptr); } } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoClassWrapper", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_wrapper_arg = args.at(0); + if (encodable_wrapper_arg.IsNull()) { + reply(WrapError("wrapper_arg unexpectedly null.")); + return; + } + const auto& wrapper_arg = std::any_cast( + std::get(encodable_wrapper_arg)); + ErrorOr output = + api->EchoClassWrapper(wrapper_arg); + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + EncodableList wrapped; + wrapped.push_back( + CustomEncodableValue(std::move(output).TakeValue())); + reply(EncodableValue(std::move(wrapped))); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } { auto channel = std::make_unique>( binary_messenger, @@ -1179,9 +1206,8 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, reply(WrapError("wrapper_arg unexpectedly null.")); return; } - const auto& wrapper_arg = - std::any_cast( - std::get(encodable_wrapper_arg)); + const auto& wrapper_arg = std::any_cast( + std::get(encodable_wrapper_arg)); ErrorOr> output = api->ExtractNestedNullableString(wrapper_arg); if (output.has_error()) { @@ -1219,7 +1245,7 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const auto& encodable_nullable_string_arg = args.at(0); const auto* nullable_string_arg = std::get_if(&encodable_nullable_string_arg); - ErrorOr output = + ErrorOr output = api->CreateNestedNullableString(nullable_string_arg); if (output.has_error()) { reply(WrapError(output.error())); @@ -3122,10 +3148,10 @@ EncodableValue FlutterIntegrationCoreApiCodecSerializer::ReadValueOfType( uint8_t type, flutter::ByteStreamReader* stream) const { switch (type) { case 128: - return CustomEncodableValue(AllNullableTypes::FromEncodableList( + return CustomEncodableValue(AllClassesWrapper::FromEncodableList( std::get(ReadValue(stream)))); case 129: - return CustomEncodableValue(AllNullableTypesWrapper::FromEncodableList( + return CustomEncodableValue(AllNullableTypes::FromEncodableList( std::get(ReadValue(stream)))); case 130: return CustomEncodableValue(AllTypes::FromEncodableList( @@ -3142,19 +3168,18 @@ void FlutterIntegrationCoreApiCodecSerializer::WriteValue( const EncodableValue& value, flutter::ByteStreamWriter* stream) const { if (const CustomEncodableValue* custom_value = std::get_if(&value)) { - if (custom_value->type() == typeid(AllNullableTypes)) { + if (custom_value->type() == typeid(AllClassesWrapper)) { stream->WriteByte(128); - WriteValue( - EncodableValue( - std::any_cast(*custom_value).ToEncodableList()), - stream); + WriteValue(EncodableValue(std::any_cast(*custom_value) + .ToEncodableList()), + stream); return; } - if (custom_value->type() == typeid(AllNullableTypesWrapper)) { + if (custom_value->type() == typeid(AllNullableTypes)) { stream->WriteByte(129); WriteValue( - EncodableValue(std::any_cast(*custom_value) - .ToEncodableList()), + EncodableValue( + std::any_cast(*custom_value).ToEncodableList()), stream); return; } 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 dad8c1a3e51..a6b6f37716c 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 @@ -78,8 +78,7 @@ class AllTypes { const std::vector& a_float_array, const flutter::EncodableList& a_list, const flutter::EncodableMap& a_map, const AnEnum& an_enum, - const std::string& a_string, - const AllNullableTypes& a_class); + const std::string& a_string); bool a_bool() const; void set_a_bool(bool value_arg); @@ -117,13 +116,10 @@ class AllTypes { const std::string& a_string() const; void set_a_string(std::string_view value_arg); - const AllNullableTypes& a_class() const; - void set_a_class(const AllNullableTypes& value_arg); - private: static AllTypes FromEncodableList(const flutter::EncodableList& list); flutter::EncodableList ToEncodableList() const; - friend class AllNullableTypes; + friend class AllClassesWrapper; friend class HostIntegrationCoreApi; friend class HostIntegrationCoreApiCodecSerializer; friend class FlutterIntegrationCoreApi; @@ -147,7 +143,6 @@ class AllTypes { flutter::EncodableMap a_map_; AnEnum an_enum_; std::string a_string_; - AllNullableTypes a_class_; }; // Generated class from Pigeon that represents data sent in messages. @@ -169,8 +164,7 @@ class AllNullableTypes { const flutter::EncodableList* nullable_nested_list, const flutter::EncodableMap* nullable_map_with_annotations, const flutter::EncodableMap* nullable_map_with_object, - const AnEnum* a_nullable_enum, const std::string* a_nullable_string, - const AllTypes* a_nullable_class); + const AnEnum* a_nullable_enum, const std::string* a_nullable_string); const bool* a_nullable_bool() const; void set_a_nullable_bool(const bool* value_arg); @@ -234,15 +228,10 @@ class AllNullableTypes { void set_a_nullable_string(const std::string_view* value_arg); void set_a_nullable_string(std::string_view value_arg); - const AllTypes* a_nullable_class() const; - void set_a_nullable_class(const AllTypes* value_arg); - void set_a_nullable_class(const AllTypes& value_arg); - private: static AllNullableTypes FromEncodableList(const flutter::EncodableList& list); flutter::EncodableList ToEncodableList() const; - friend class AllTypes; - friend class AllNullableTypesWrapper; + friend class AllClassesWrapper; friend class HostIntegrationCoreApi; friend class HostIntegrationCoreApiCodecSerializer; friend class FlutterIntegrationCoreApi; @@ -269,20 +258,27 @@ class AllNullableTypes { std::optional nullable_map_with_object_; std::optional a_nullable_enum_; std::optional a_nullable_string_; - std::optional a_nullable_class_; }; // Generated class from Pigeon that represents data sent in messages. -class AllNullableTypesWrapper { +class AllClassesWrapper { public: + // Constructs an object setting all non-nullable fields. + explicit AllClassesWrapper(const AllNullableTypes& all_nullable_types); + // Constructs an object setting all fields. - explicit AllNullableTypesWrapper(const AllNullableTypes& values); + explicit AllClassesWrapper(const AllNullableTypes& all_nullable_types, + const AllTypes* all_types); + + const AllNullableTypes& all_nullable_types() const; + void set_all_nullable_types(const AllNullableTypes& value_arg); - const AllNullableTypes& values() const; - void set_values(const AllNullableTypes& value_arg); + const AllTypes* all_types() const; + void set_all_types(const AllTypes* value_arg); + void set_all_types(const AllTypes& value_arg); private: - static AllNullableTypesWrapper FromEncodableList( + static AllClassesWrapper FromEncodableList( const flutter::EncodableList& list); flutter::EncodableList ToEncodableList() const; friend class HostIntegrationCoreApi; @@ -296,7 +292,8 @@ class AllNullableTypesWrapper { friend class FlutterSmallApi; friend class FlutterSmallApiCodecSerializer; friend class CoreTestsTest; - AllNullableTypes values_; + AllNullableTypes all_nullable_types_; + std::optional all_types_; }; // A data class containing a List, used in unit tests. @@ -390,16 +387,20 @@ class HostIntegrationCoreApi { // Returns the passed map, to test serialization and deserialization. virtual ErrorOr EchoMap( const flutter::EncodableMap& a_map) = 0; + // Returns the passed map to test nested class serialization and + // deserialization. + virtual ErrorOr EchoClassWrapper( + const AllClassesWrapper& wrapper) = 0; // Returns the passed object, to test serialization and deserialization. virtual ErrorOr> EchoAllNullableTypes( const AllNullableTypes* everything) = 0; // Returns the inner `aString` value from the wrapped object, to test // sending of nested objects. virtual ErrorOr> ExtractNestedNullableString( - const AllNullableTypesWrapper& wrapper) = 0; + const AllClassesWrapper& wrapper) = 0; // Returns the inner `aString` value from the wrapped object, to test // sending of nested objects. - virtual ErrorOr CreateNestedNullableString( + virtual ErrorOr CreateNestedNullableString( const std::string* nullable_string) = 0; // Returns passed in arguments of multiple types. virtual ErrorOr SendMultipleNullableTypes( 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 713f17bfd30..f443779001c 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp @@ -16,8 +16,8 @@ namespace test_plugin { +using core_tests_pigeontest::AllClassesWrapper; using core_tests_pigeontest::AllNullableTypes; -using core_tests_pigeontest::AllNullableTypesWrapper; using core_tests_pigeontest::AllTypes; using core_tests_pigeontest::ErrorOr; using core_tests_pigeontest::FlutterError; @@ -98,14 +98,20 @@ ErrorOr TestPlugin::EchoMap(const EncodableMap& a_map) { return a_map; } +ErrorOr TestPlugin::EchoClassWrapper( + const AllClassesWrapper& wrapper) { + return wrapper; +} + ErrorOr> TestPlugin::ExtractNestedNullableString( - const AllNullableTypesWrapper& wrapper) { - const std::string* inner_string = wrapper.values().a_nullable_string(); + const AllClassesWrapper& wrapper) { + const std::string* inner_string = + wrapper.allNullableTypes().a_nullable_string(); return inner_string ? std::optional(*inner_string) : std::nullopt; } -ErrorOr TestPlugin::CreateNestedNullableString( +ErrorOr TestPlugin::CreateNestedNullableString( const std::string* nullable_string) { AllNullableTypes inner_object; // The string pointer can't be passed through directly since the setter for @@ -116,7 +122,7 @@ ErrorOr TestPlugin::CreateNestedNullableString( } else { inner_object.set_a_nullable_string(nullptr); } - AllNullableTypesWrapper wrapper(inner_object); + AllClassesWrapper wrapper(inner_object); return wrapper; } From 0a93b384aee34a784c754ef4ce31f1828c6837b5 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Mon, 3 Jul 2023 02:40:13 -0700 Subject: [PATCH 07/14] forgot a mac --- .../macos/Classes/AlternateLanguageTestPlugin.m | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/AlternateLanguageTestPlugin.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/AlternateLanguageTestPlugin.m index 276b9a05f4a..488ff0dfb2c 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/AlternateLanguageTestPlugin.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/AlternateLanguageTestPlugin.m @@ -87,17 +87,22 @@ - (nullable id)echoObject:(id)anObject error:(FlutterError *_Nullable *_Nonnull) return aMap; } -- (nullable NSString *)extractNestedNullableStringFrom:(AllNullableTypesWrapper *)wrapper +- (nullable AllClassesWrapper *)echoClassWrapper:(AllClassesWrapper *)wrapper + error:(FlutterError *_Nullable *_Nonnull)error { + return wrapper; +} + +- (nullable NSString *)extractNestedNullableStringFrom:(AllClassesWrapper *)wrapper error:(FlutterError *_Nullable *_Nonnull)error { - return wrapper.values.aNullableString; + return wrapper.allNullableTypes.aNullableString; } -- (nullable AllNullableTypesWrapper *) +- (nullable AllClassesWrapper *) createNestedObjectWithNullableString:(nullable NSString *)nullableString error:(FlutterError *_Nullable *_Nonnull)error { AllNullableTypes *innerObject = [[AllNullableTypes alloc] init]; innerObject.aNullableString = nullableString; - return [AllNullableTypesWrapper makeWithValues:innerObject]; + return [AllClassesWrapper makeWithAllNullableTypes:innerObject allTypes:nil]; } - (nullable AllNullableTypes *)sendMultipleNullableTypesABool:(nullable NSNumber *)aNullableBool From 8602bb2b520e00fe761f70e047dead616f986ebc Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Mon, 3 Jul 2023 12:20:17 -0700 Subject: [PATCH 08/14] snakes are scary --- .../pigeon/platform_tests/test_plugin/windows/test_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f443779001c..125771085ce 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp @@ -106,7 +106,7 @@ ErrorOr TestPlugin::EchoClassWrapper( ErrorOr> TestPlugin::ExtractNestedNullableString( const AllClassesWrapper& wrapper) { const std::string* inner_string = - wrapper.allNullableTypes().a_nullable_string(); + wrapper.all_nullable_types().a_nullable_string(); return inner_string ? std::optional(*inner_string) : std::nullopt; } From aa88efcbf71d3e67161598079f5776e0f2d7af1f Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Mon, 3 Jul 2023 12:34:32 -0700 Subject: [PATCH 09/14] need to remove the version number from examples --- .../android/app/src/main/java/io/flutter/plugins/Messages.java | 2 +- .../main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt | 2 +- packages/pigeon/example/app/ios/Runner/Messages.g.swift | 2 +- packages/pigeon/example/app/lib/src/messages.g.dart | 2 +- packages/pigeon/example/app/macos/Runner/messages.g.h | 2 +- packages/pigeon/example/app/macos/Runner/messages.g.m | 2 +- packages/pigeon/example/app/windows/runner/messages.g.cpp | 2 +- packages/pigeon/example/app/windows/runner/messages.g.h | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java b/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java index c1c3b7a898d..1f5aaebba66 100644 --- a/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java +++ b/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v10.1.1), do not edit directly. +// Autogenerated from Pigeon (v10.1.2), do not edit directly. // See also: https://pub.dev/packages/pigeon import android.util.Log; diff --git a/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt b/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt index bc2dfa818ad..4aa5169e7f3 100644 --- a/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt +++ b/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v10.1.1), do not edit directly. +// Autogenerated from Pigeon (v10.1.2), do not edit directly. // See also: https://pub.dev/packages/pigeon diff --git a/packages/pigeon/example/app/ios/Runner/Messages.g.swift b/packages/pigeon/example/app/ios/Runner/Messages.g.swift index 8dd1a6b8878..3467edf3c3c 100644 --- a/packages/pigeon/example/app/ios/Runner/Messages.g.swift +++ b/packages/pigeon/example/app/ios/Runner/Messages.g.swift @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v10.1.1), do not edit directly. +// Autogenerated from Pigeon (v10.1.2), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation diff --git a/packages/pigeon/example/app/lib/src/messages.g.dart b/packages/pigeon/example/app/lib/src/messages.g.dart index 25e75e3f1ab..66ae5c55f33 100644 --- a/packages/pigeon/example/app/lib/src/messages.g.dart +++ b/packages/pigeon/example/app/lib/src/messages.g.dart @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v10.1.1), do not edit directly. +// Autogenerated from Pigeon (v10.1.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/example/app/macos/Runner/messages.g.h b/packages/pigeon/example/app/macos/Runner/messages.g.h index d789948007b..5fb709ca3d2 100644 --- a/packages/pigeon/example/app/macos/Runner/messages.g.h +++ b/packages/pigeon/example/app/macos/Runner/messages.g.h @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v10.1.1), do not edit directly. +// Autogenerated from Pigeon (v10.1.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #import diff --git a/packages/pigeon/example/app/macos/Runner/messages.g.m b/packages/pigeon/example/app/macos/Runner/messages.g.m index 8aa843612a5..8a43bffac32 100644 --- a/packages/pigeon/example/app/macos/Runner/messages.g.m +++ b/packages/pigeon/example/app/macos/Runner/messages.g.m @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v10.1.1), do not edit directly. +// Autogenerated from Pigeon (v10.1.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "messages.g.h" diff --git a/packages/pigeon/example/app/windows/runner/messages.g.cpp b/packages/pigeon/example/app/windows/runner/messages.g.cpp index ba7c06bb697..50053cf2334 100644 --- a/packages/pigeon/example/app/windows/runner/messages.g.cpp +++ b/packages/pigeon/example/app/windows/runner/messages.g.cpp @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v10.1.1), do not edit directly. +// Autogenerated from Pigeon (v10.1.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #undef _HAS_EXCEPTIONS diff --git a/packages/pigeon/example/app/windows/runner/messages.g.h b/packages/pigeon/example/app/windows/runner/messages.g.h index 1bf5dddf798..917de2da37a 100644 --- a/packages/pigeon/example/app/windows/runner/messages.g.h +++ b/packages/pigeon/example/app/windows/runner/messages.g.h @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v10.1.1), do not edit directly. +// Autogenerated from Pigeon (v10.1.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #ifndef PIGEON_MESSAGES_G_H_ From 9e4f28846598203030f4bab48ee63ec625014c47 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Mon, 3 Jul 2023 17:04:49 -0700 Subject: [PATCH 10/14] header --- .../pigeon/platform_tests/test_plugin/windows/test_plugin.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 c65931d91c7..19204ebc8b6 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h @@ -58,10 +58,12 @@ class TestPlugin : public flutter::Plugin, const flutter::EncodableList& a_list) override; core_tests_pigeontest::ErrorOr EchoMap( const flutter::EncodableMap& a_map) override; + core_tests_pigeontest::ErrorOr EchoClassWrapper( + const AllClassesWrapper& wrapper) override; core_tests_pigeontest::ErrorOr> ExtractNestedNullableString( - const core_tests_pigeontest::AllNullableTypesWrapper& wrapper) override; - core_tests_pigeontest::ErrorOr + const core_tests_pigeontest::AllClassesWrapper& wrapper) override; + core_tests_pigeontest::ErrorOr CreateNestedNullableString(const std::string* nullable_string) override; core_tests_pigeontest::ErrorOr SendMultipleNullableTypes(const bool* a_nullable_bool, From 246befbd117da40edda4b0ba56e2891008c95087 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Mon, 3 Jul 2023 20:09:53 -0700 Subject: [PATCH 11/14] core_tests_pigeontest:: --- .../pigeon/platform_tests/test_plugin/windows/test_plugin.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 19204ebc8b6..f6ebe209ab2 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h @@ -58,8 +58,8 @@ class TestPlugin : public flutter::Plugin, const flutter::EncodableList& a_list) override; core_tests_pigeontest::ErrorOr EchoMap( const flutter::EncodableMap& a_map) override; - core_tests_pigeontest::ErrorOr EchoClassWrapper( - const AllClassesWrapper& wrapper) override; + core_tests_pigeontest::ErrorOr EchoClassWrapper( + const core_tests_pigeontest::AllClassesWrapper& wrapper) override; core_tests_pigeontest::ErrorOr> ExtractNestedNullableString( const core_tests_pigeontest::AllClassesWrapper& wrapper) override; From 7d042a02f6a9ac7ba914a1790d39feadec7fe992 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Mon, 3 Jul 2023 20:20:41 -0700 Subject: [PATCH 12/14] format --- .../pigeon/platform_tests/test_plugin/windows/test_plugin.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 f6ebe209ab2..649d20fab5d 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h @@ -58,7 +58,8 @@ class TestPlugin : public flutter::Plugin, const flutter::EncodableList& a_list) override; core_tests_pigeontest::ErrorOr EchoMap( const flutter::EncodableMap& a_map) override; - core_tests_pigeontest::ErrorOr EchoClassWrapper( + core_tests_pigeontest::ErrorOr + EchoClassWrapper( const core_tests_pigeontest::AllClassesWrapper& wrapper) override; core_tests_pigeontest::ErrorOr> ExtractNestedNullableString( From a92df554db7a4f8c1fbd6c3f369db076b3b20956 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Wed, 5 Jul 2023 18:33:47 -0700 Subject: [PATCH 13/14] cleaner and clearer --- packages/pigeon/CHANGELOG.md | 2 +- packages/pigeon/pigeons/core_tests.dart | 10 ++- .../AllDatatypesTest.java | 25 ++----- .../lib/integration_tests.dart | 67 +++++++------------ .../example/test_plugin/AllDatatypesTest.kt | 25 ++----- 5 files changed, 47 insertions(+), 82 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index b33a19dd8c2..4e941c00aad 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,6 +1,6 @@ ## 10.1.2 -* [swift] Fixes a crash when casting `NSNull` to an array. +* [swift] Fixes a crash when passing `null` for nested nullable classes. ## 10.1.1 diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 9339f03debe..ceb1de2f36a 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -10,7 +10,7 @@ enum AnEnum { three, } -// A class containing all supported types. +/// A class containing all supported types. class AllTypes { AllTypes({ this.aBool = false, @@ -43,7 +43,7 @@ class AllTypes { String aString; } -// A class containing all supported nullable types. +/// A class containing all supported nullable types. class AllNullableTypes { AllNullableTypes( this.aNullableBool, @@ -82,7 +82,11 @@ class AllNullableTypes { String? aNullableString; } -// A class for testing nested object handling. +/// A class for testing nested class handling. +/// +/// This is needed to test nested nullable and non-nullable classes, +/// `AllNullableTypes` is non-nullable here as it is easier to instantiate +/// than `AllTypes` when testing doesn't require both (ie. testing null classes). class AllClassesWrapper { AllClassesWrapper(this.allNullableTypes, this.allTypes); AllNullableTypes allNullableTypes; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java index ee1bc58a846..cba21e76f49 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java @@ -19,15 +19,11 @@ public class AllDatatypesTest { - boolean compareAllTypes(AllTypes firstTypes, AllTypes secondTypes) { - - if (firstTypes == null && secondTypes == null) { - return true; - } + void compareAllTypes(AllTypes firstTypes, AllTypes secondTypes) { + assertEquals(firstTypes == null, secondTypes == null); if (firstTypes == null || secondTypes == null) { - return false; + return; } - assertEquals(firstTypes.getABool(), secondTypes.getABool()); assertEquals(firstTypes.getAnInt(), secondTypes.getAnInt()); assertEquals(firstTypes.getAnInt64(), secondTypes.getAnInt64()); @@ -44,17 +40,12 @@ boolean compareAllTypes(AllTypes firstTypes, AllTypes secondTypes) { firstTypes.getAMap().values().toArray(), secondTypes.getAMap().values().toArray()); assertEquals(firstTypes.getAnEnum(), secondTypes.getAnEnum()); assertEquals(firstTypes.getAString(), secondTypes.getAString()); - - return true; } - boolean compareAllNullableTypes(AllNullableTypes firstTypes, AllNullableTypes secondTypes) { - - if (firstTypes == null && secondTypes == null) { - return true; - } + void compareAllNullableTypes(AllNullableTypes firstTypes, AllNullableTypes secondTypes) { + assertEquals(firstTypes == null, secondTypes == null); if (firstTypes == null || secondTypes == null) { - return false; + return; } assertEquals(firstTypes.getANullableBool(), secondTypes.getANullableBool()); assertEquals(firstTypes.getANullableInt(), secondTypes.getANullableInt()); @@ -77,8 +68,6 @@ boolean compareAllNullableTypes(AllNullableTypes firstTypes, AllNullableTypes se assertArrayEquals( firstTypes.getNullableMapWithObject().values().toArray(), secondTypes.getNullableMapWithObject().values().toArray()); - - return true; } @Test @@ -202,7 +191,7 @@ public void hasValues() { everything, (result) -> { didCall[0] = true; - assert (compareAllNullableTypes(everything, result)); + compareAllNullableTypes(everything, result); }); assertTrue(didCall[0]); } 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 73ed7aa07b4..0a22cbeb735 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 @@ -39,15 +39,11 @@ enum TargetGenerator { void runPigeonIntegrationTests(TargetGenerator targetGenerator) { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); - bool compareAllTypes(AllTypes? allTypesOne, AllTypes? allTypesTwo) { - if (allTypesOne == null && allTypesTwo == null) { - return true; - } - + void compareAllTypes(AllTypes? allTypesOne, AllTypes? allTypesTwo) { + expect(allTypesOne == null, allTypesTwo == null); if (allTypesOne == null || allTypesTwo == null) { - return false; + return; } - expect(allTypesOne.aBool, allTypesTwo.aBool); expect(allTypesOne.anInt, allTypesTwo.anInt); expect(allTypesOne.anInt64, allTypesTwo.anInt64); @@ -60,20 +56,14 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect(listEquals(allTypesOne.aList, allTypesTwo.aList), true); expect(mapEquals(allTypesOne.aMap, allTypesTwo.aMap), true); expect(allTypesOne.anEnum, allTypesTwo.anEnum); - - return true; } - bool compareAllNullableTypes(AllNullableTypes? allNullableTypesOne, + void compareAllNullableTypes(AllNullableTypes? allNullableTypesOne, AllNullableTypes? allNullableTypesTwo) { - if (allNullableTypesOne == null && allNullableTypesTwo == null) { - return true; - } - + expect(allNullableTypesOne == null, allNullableTypesTwo == null); if (allNullableTypesOne == null || allNullableTypesTwo == null) { - return false; + return; } - expect( allNullableTypesOne.aNullableBool, allNullableTypesTwo.aNullableBool); expect(allNullableTypesOne.aNullableInt, allNullableTypesTwo.aNullableInt); @@ -121,23 +111,18 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect( allNullableTypesOne.aNullableEnum, allNullableTypesTwo.aNullableEnum); } - - return true; } - bool compareAllClassesWrapper( + void compareAllClassesWrapper( AllClassesWrapper? wrapperOne, AllClassesWrapper? wrapperTwo) { - if (wrapperOne == null && wrapperTwo == null) { - return true; - } - + expect(wrapperOne == null, wrapperTwo == null); if (wrapperOne == null || wrapperTwo == null) { - return false; + return; } - return compareAllNullableTypes( - wrapperOne.allNullableTypes, wrapperTwo.allNullableTypes) && - compareAllTypes(wrapperOne.allTypes, wrapperTwo.allTypes); + compareAllNullableTypes( + wrapperOne.allNullableTypes, wrapperTwo.allNullableTypes); + compareAllTypes(wrapperOne.allTypes, wrapperTwo.allTypes); } final AllTypes genericAllTypes = AllTypes( @@ -200,7 +185,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); final AllTypes echoObject = await api.echoAllTypes(genericAllTypes); - expect(compareAllTypes(echoObject, genericAllTypes), true); + compareAllTypes(echoObject, genericAllTypes); }); testWidgets('all nullable datatypes serialize and deserialize correctly', @@ -209,8 +194,8 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes? echoObject = await api.echoAllNullableTypes(genericAllNullableTypes); - expect( - compareAllNullableTypes(echoObject, genericAllNullableTypes), true); + + compareAllNullableTypes(echoObject, genericAllNullableTypes); }); testWidgets('all null datatypes serialize and deserialize correctly', @@ -221,7 +206,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes? echoNullFilledClass = await api.echoAllNullableTypes(allTypesNull); - expect(compareAllNullableTypes(allTypesNull, echoNullFilledClass), true); + compareAllNullableTypes(allTypesNull, echoNullFilledClass); }); testWidgets('Classes with list of null serialize and deserialize correctly', @@ -234,8 +219,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes? echoNullFilledClass = await api.echoAllNullableTypes(nullableListTypes); - expect(compareAllNullableTypes(nullableListTypes, echoNullFilledClass), - true); + compareAllNullableTypes(nullableListTypes, echoNullFilledClass); }); testWidgets('Classes with map of null serialize and deserialize correctly', @@ -248,8 +232,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes? echoNullFilledClass = await api.echoAllNullableTypes(nullableListTypes); - expect(compareAllNullableTypes(nullableListTypes, echoNullFilledClass), - true); + compareAllNullableTypes(nullableListTypes, echoNullFilledClass); }); testWidgets('errors are returned correctly', (WidgetTester _) async { @@ -312,7 +295,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllClassesWrapper receivedClassWrapper = await api.echoClassWrapper(sentWrapper); - expect(compareAllClassesWrapper(sentWrapper, receivedClassWrapper), true); + compareAllClassesWrapper(sentWrapper, receivedClassWrapper); }); testWidgets('nested null classes can serialize and deserialize correctly', @@ -324,7 +307,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllClassesWrapper receivedClassWrapper = await api.echoClassWrapper(sentWrapper); - expect(compareAllClassesWrapper(sentWrapper, receivedClassWrapper), true); + compareAllClassesWrapper(sentWrapper, receivedClassWrapper); }); testWidgets( @@ -670,7 +653,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllTypes echoObject = await api.echoAsyncAllTypes(genericAllTypes); - expect(compareAllTypes(echoObject, genericAllTypes), true); + compareAllTypes(echoObject, genericAllTypes); }); testWidgets( @@ -680,8 +663,8 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes? echoObject = await api.echoAsyncNullableAllNullableTypes(genericAllNullableTypes); - expect( - compareAllNullableTypes(echoObject, genericAllNullableTypes), true); + + compareAllNullableTypes(echoObject, genericAllNullableTypes); }); testWidgets('all null datatypes async serialize and deserialize correctly', @@ -692,7 +675,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypes? echoNullFilledClass = await api.echoAsyncNullableAllNullableTypes(allTypesNull); - expect(compareAllNullableTypes(echoNullFilledClass, allTypesNull), true); + compareAllNullableTypes(echoNullFilledClass, allTypesNull); }); testWidgets('Int async serialize and deserialize correctly', @@ -1020,7 +1003,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllTypes echoObject = await api.callFlutterEchoAllTypes(genericAllTypes); - expect(compareAllTypes(echoObject, genericAllTypes), true); + compareAllTypes(echoObject, genericAllTypes); }); testWidgets( diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt index ca6e58418d4..09cedf4a2e2 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt @@ -14,15 +14,11 @@ import java.util.ArrayList internal class AllDatatypesTest: TestCase() { - fun compareAllTypes(firstTypes: AllTypes?, secondTypes: AllTypes?): Boolean { - - if (firstTypes == null && secondTypes == null) { - return true - } + fun compareAllTypes(firstTypes: AllTypes?, secondTypes: AllTypes?) { + assertEquals(firstTypes == null, secondTypes == null) if (firstTypes == null || secondTypes == null) { - return false + return } - assertEquals(firstTypes.aBool, secondTypes.aBool) assertEquals(firstTypes.anInt, secondTypes.anInt) assertEquals(firstTypes.anInt64, secondTypes.anInt64) @@ -35,18 +31,13 @@ internal class AllDatatypesTest: TestCase() { assertEquals(firstTypes.aList, secondTypes.aList) assertEquals(firstTypes.aMap, secondTypes.aMap) assertEquals(firstTypes.anEnum, secondTypes.anEnum) - - return true } - fun compareAllNullableTypes(firstTypes: AllNullableTypes?, secondTypes: AllNullableTypes?): Boolean { - if (firstTypes == null && secondTypes == null) { - return true - } + fun compareAllNullableTypes(firstTypes: AllNullableTypes?, secondTypes: AllNullableTypes?) { + assertEquals(firstTypes == null, secondTypes == null) if (firstTypes == null || secondTypes == null) { - return false + return } - assertEquals(firstTypes.aNullableBool, secondTypes.aNullableBool) assertEquals(firstTypes.aNullableInt, secondTypes.aNullableInt) assertEquals(firstTypes.aNullableDouble, secondTypes.aNullableDouble) @@ -58,8 +49,6 @@ internal class AllDatatypesTest: TestCase() { assertEquals(firstTypes.aNullableList, secondTypes.aNullableList) assertEquals(firstTypes.aNullableMap, secondTypes.aNullableMap) assertEquals(firstTypes.nullableMapWithObject, secondTypes.nullableMapWithObject) - - return true } @Test @@ -130,7 +119,7 @@ internal class AllDatatypesTest: TestCase() { var didCall = false api.echoAllNullableTypes(everything) { didCall = true - assertTrue(compareAllNullableTypes(everything, it)) + compareAllNullableTypes(everything, it) } assertTrue(didCall) From 2b9368e51fe46044f827fc4ca56afc762ce0ae3b Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Wed, 5 Jul 2023 22:07:50 -0700 Subject: [PATCH 14/14] gen --- .../CoreTests.java | 22 ++++++++++++++++--- .../ios/Classes/CoreTests.gen.h | 7 ++++++ .../macos/Classes/CoreTests.gen.h | 7 ++++++ .../lib/src/generated/core_tests.gen.dart | 7 ++++++ .../com/example/test_plugin/CoreTests.gen.kt | 22 ++++++++++++++++--- .../ios/Classes/CoreTests.gen.swift | 10 +++++++++ .../macos/Classes/CoreTests.gen.swift | 10 +++++++++ .../windows/pigeon/core_tests.gen.h | 10 +++++++++ 8 files changed, 89 insertions(+), 6 deletions(-) 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 46ae86da851..aa53e509c28 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 @@ -71,7 +71,11 @@ private AnEnum(final int index) { } } - /** Generated class from Pigeon that represents data sent in messages. */ + /** + * A class containing all supported types. + * + *

Generated class from Pigeon that represents data sent in messages. + */ public static final class AllTypes { private @NonNull Boolean aBool; @@ -388,7 +392,11 @@ ArrayList toList() { } } - /** Generated class from Pigeon that represents data sent in messages. */ + /** + * A class containing all supported nullable types. + * + *

Generated class from Pigeon that represents data sent in messages. + */ public static final class AllNullableTypes { private @Nullable Boolean aNullableBool; @@ -735,7 +743,15 @@ ArrayList toList() { } } - /** Generated class from Pigeon that represents data sent in messages. */ + /** + * A class for testing nested class handling. + * + *

This is needed to test nested nullable and non-nullable classes, `AllNullableTypes` is + * non-nullable here as it is easier to instantiate than `AllTypes` when testing doesn't require + * both (ie. testing null classes). + * + *

Generated class from Pigeon that represents data sent in messages. + */ public static final class AllClassesWrapper { private @NonNull AllNullableTypes allNullableTypes; 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 95b362e84e6..185e866273b 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 @@ -25,6 +25,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @class AllClassesWrapper; @class TestMessage; +/// A class containing all supported types. @interface AllTypes : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; @@ -54,6 +55,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, copy) NSString *aString; @end +/// A class containing all supported nullable types. @interface AllNullableTypes : NSObject + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool aNullableInt:(nullable NSNumber *)aNullableInt @@ -89,6 +91,11 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, copy, nullable) NSString *aNullableString; @end +/// A class for testing nested class handling. +/// +/// This is needed to test nested nullable and non-nullable classes, +/// `AllNullableTypes` is non-nullable here as it is easier to instantiate +/// than `AllTypes` when testing doesn't require both (ie. testing null classes). @interface AllClassesWrapper : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h index 95b362e84e6..185e866273b 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h @@ -25,6 +25,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @class AllClassesWrapper; @class TestMessage; +/// A class containing all supported types. @interface AllTypes : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; @@ -54,6 +55,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, copy) NSString *aString; @end +/// A class containing all supported nullable types. @interface AllNullableTypes : NSObject + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool aNullableInt:(nullable NSNumber *)aNullableInt @@ -89,6 +91,11 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, copy, nullable) NSString *aNullableString; @end +/// A class for testing nested class handling. +/// +/// This is needed to test nested nullable and non-nullable classes, +/// `AllNullableTypes` is non-nullable here as it is easier to instantiate +/// than `AllTypes` when testing doesn't require both (ie. testing null classes). @interface AllClassesWrapper : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; 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 94e63399dd2..3920cb36096 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 @@ -18,6 +18,7 @@ enum AnEnum { three, } +/// A class containing all supported types. class AllTypes { AllTypes({ required this.aBool, @@ -94,6 +95,7 @@ class AllTypes { } } +/// A class containing all supported nullable types. class AllNullableTypes { AllNullableTypes({ this.aNullableBool, @@ -188,6 +190,11 @@ class AllNullableTypes { } } +/// A class for testing nested class handling. +/// +/// This is needed to test nested nullable and non-nullable classes, +/// `AllNullableTypes` is non-nullable here as it is easier to instantiate +/// than `AllTypes` when testing doesn't require both (ie. testing null classes). class AllClassesWrapper { AllClassesWrapper({ required this.allNullableTypes, 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 06b6cfb25b5..0404656c16c 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 @@ -59,7 +59,11 @@ enum class AnEnum(val raw: Int) { } } -/** Generated class from Pigeon that represents data sent in messages. */ +/** + * A class containing all supported types. + * + * Generated class from Pigeon that represents data sent in messages. + */ data class AllTypes ( val aBool: Boolean, val anInt: Long, @@ -111,7 +115,11 @@ data class AllTypes ( } } -/** Generated class from Pigeon that represents data sent in messages. */ +/** + * A class containing all supported nullable types. + * + * Generated class from Pigeon that represents data sent in messages. + */ data class AllNullableTypes ( val aNullableBool: Boolean? = null, val aNullableInt: Long? = null, @@ -174,7 +182,15 @@ data class AllNullableTypes ( } } -/** Generated class from Pigeon that represents data sent in messages. */ +/** + * A class for testing nested class handling. + * + * This is needed to test nested nullable and non-nullable classes, + * `AllNullableTypes` is non-nullable here as it is easier to instantiate + * than `AllTypes` when testing doesn't require both (ie. testing null classes). + * + * Generated class from Pigeon that represents data sent in messages. + */ data class AllClassesWrapper ( val allNullableTypes: AllNullableTypes, val allTypes: AllTypes? = null 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 2328e419db4..a2dd43f5bce 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 @@ -44,6 +44,8 @@ enum AnEnum: Int { case three = 2 } +/// A class containing all supported types. +/// /// Generated class from Pigeon that represents data sent in messages. struct AllTypes { var aBool: Bool @@ -106,6 +108,8 @@ struct AllTypes { } } +/// A class containing all supported nullable types. +/// /// Generated class from Pigeon that represents data sent in messages. struct AllNullableTypes { var aNullableBool: Bool? = nil @@ -184,6 +188,12 @@ struct AllNullableTypes { } } +/// A class for testing nested class handling. +/// +/// This is needed to test nested nullable and non-nullable classes, +/// `AllNullableTypes` is non-nullable here as it is easier to instantiate +/// than `AllTypes` when testing doesn't require both (ie. testing null classes). +/// /// Generated class from Pigeon that represents data sent in messages. struct AllClassesWrapper { var allNullableTypes: AllNullableTypes 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 2328e419db4..a2dd43f5bce 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 @@ -44,6 +44,8 @@ enum AnEnum: Int { case three = 2 } +/// A class containing all supported types. +/// /// Generated class from Pigeon that represents data sent in messages. struct AllTypes { var aBool: Bool @@ -106,6 +108,8 @@ struct AllTypes { } } +/// A class containing all supported nullable types. +/// /// Generated class from Pigeon that represents data sent in messages. struct AllNullableTypes { var aNullableBool: Bool? = nil @@ -184,6 +188,12 @@ struct AllNullableTypes { } } +/// A class for testing nested class handling. +/// +/// This is needed to test nested nullable and non-nullable classes, +/// `AllNullableTypes` is non-nullable here as it is easier to instantiate +/// than `AllTypes` when testing doesn't require both (ie. testing null classes). +/// /// Generated class from Pigeon that represents data sent in messages. struct AllClassesWrapper { var allNullableTypes: AllNullableTypes 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 a6b6f37716c..67b0302938b 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 @@ -67,6 +67,8 @@ class ErrorOr { enum class AnEnum { one = 0, two = 1, three = 2 }; +// A class containing all supported types. +// // Generated class from Pigeon that represents data sent in messages. class AllTypes { public: @@ -145,6 +147,8 @@ class AllTypes { std::string a_string_; }; +// A class containing all supported nullable types. +// // Generated class from Pigeon that represents data sent in messages. class AllNullableTypes { public: @@ -260,6 +264,12 @@ class AllNullableTypes { std::optional a_nullable_string_; }; +// A class for testing nested class handling. +// +// This is needed to test nested nullable and non-nullable classes, +// `AllNullableTypes` is non-nullable here as it is easier to instantiate +// than `AllTypes` when testing doesn't require both (ie. testing null classes). +// // Generated class from Pigeon that represents data sent in messages. class AllClassesWrapper { public: