Skip to content

Commit 5879295

Browse files
authored
[pigeon] More simple integration tests (#2950)
* add AnEnum to AllTypes * AllTypes AnEnum test * echo string * echo double * echo uint8list... swift broken * Forgot header again * caps * copy and paste is a good idea
1 parent ae1fd29 commit 5879295

File tree

11 files changed

+343
-6
lines changed

11 files changed

+343
-6
lines changed

packages/pigeon/pigeons/core_tests.dart

+20-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
import 'package:pigeon/pigeon.dart';
66

7+
enum AnEnum {
8+
one,
9+
two,
10+
three,
11+
}
12+
713
// A class containing all supported types.
814
class AllTypes {
915
bool? aBool;
@@ -21,6 +27,7 @@ class AllTypes {
2127
List<List<bool?>?>? nestedList;
2228
Map<String?, String?>? mapWithAnnotations;
2329
Map<String?, Object?>? mapWithObject;
30+
AnEnum? anEnum;
2431
}
2532

2633
// A class for testing nested object handling.
@@ -64,10 +71,22 @@ abstract class HostIntegrationCoreApi {
6471
@ObjCSelector('echoInt:')
6572
int echoInt(int anInt);
6673

67-
/// Returns the passed in boolean asynchronously.
74+
/// Returns passed in double.
75+
@ObjCSelector('echoDouble:')
76+
double echoDouble(double aDouble);
77+
78+
/// Returns the passed in boolean.
6879
@ObjCSelector('echoBool:')
6980
bool echoBool(bool aBool);
7081

82+
/// Returns the passed in string.
83+
@ObjCSelector('echoString:')
84+
String echoString(String aString);
85+
86+
/// Returns the passed in Uint8List.
87+
@ObjCSelector('echoUint8List:')
88+
Uint8List echoUint8List(Uint8List aUint8List);
89+
7190
// ========== Asyncronous method tests ==========
7291

7392
/// A no-op function taking no arguments and returning no value, to sanity

packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java

+15
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,26 @@ public Long echoInt(@NonNull Long anInt) {
6565
return anInt;
6666
}
6767

68+
@Override
69+
public Double echoDouble(@NonNull Double aDouble) {
70+
return aDouble;
71+
}
72+
6873
@Override
6974
public Boolean echoBool(@NonNull Boolean aBool) {
7075
return aBool;
7176
}
7277

78+
@Override
79+
public String echoString(@NonNull String aString) {
80+
return aString;
81+
}
82+
83+
@Override
84+
public byte[] echoUint8List(@NonNull byte[] aUint8List) {
85+
return aUint8List;
86+
}
87+
7388
@Override
7489
public void noopAsync(Result<Void> result) {
7590
result.success(null);

packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m

+15
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,25 @@ - (nullable NSNumber *)echoInt:(NSNumber *)anInt error:(FlutterError *_Nullable
6363
return anInt;
6464
}
6565

66+
- (nullable NSNumber *)echoDouble:(NSNumber *)aDouble
67+
error:(FlutterError *_Nullable *_Nonnull)error {
68+
return aDouble
69+
}
70+
6671
- (nullable NSNumber *)echoBool:(NSNumber *)aBool error:(FlutterError *_Nullable *_Nonnull)error {
6772
return aBool;
6873
}
6974

75+
- (nullable NSString *)echoString:(NSString *)aString
76+
error:(FlutterError *_Nullable *_Nonnull)error {
77+
return aString;
78+
}
79+
80+
- (nullable FlutterStandardTypedData *)echoUint8List:(FlutterStandardTypedData *)aUint8List
81+
error:(FlutterError *_Nullable *_Nonnull)error {
82+
return aUint8List;
83+
}
84+
7085
- (void)noopAsyncWithCompletion:(void (^)(FlutterError *_Nullable))completion {
7186
completion(nil);
7287
}

packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart

+103-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;
1111
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;
1212
import 'package:flutter/services.dart';
1313

14+
enum AnEnum {
15+
one,
16+
two,
17+
three,
18+
}
19+
1420
class AllTypes {
1521
AllTypes({
1622
this.aBool,
@@ -26,6 +32,7 @@ class AllTypes {
2632
this.nestedList,
2733
this.mapWithAnnotations,
2834
this.mapWithObject,
35+
this.anEnum,
2936
});
3037

3138
bool? aBool;
@@ -41,6 +48,7 @@ class AllTypes {
4148
List<List<bool?>?>? nestedList;
4249
Map<String?, String?>? mapWithAnnotations;
4350
Map<String?, Object?>? mapWithObject;
51+
AnEnum? anEnum;
4452

4553
Object encode() {
4654
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
@@ -57,6 +65,7 @@ class AllTypes {
5765
pigeonMap['nestedList'] = nestedList;
5866
pigeonMap['mapWithAnnotations'] = mapWithAnnotations;
5967
pigeonMap['mapWithObject'] = mapWithObject;
68+
pigeonMap['anEnum'] = anEnum?.index;
6069
return pigeonMap;
6170
}
6271

@@ -80,6 +89,9 @@ class AllTypes {
8089
?.cast<String?, String?>(),
8190
mapWithObject: (pigeonMap['mapWithObject'] as Map<Object?, Object?>?)
8291
?.cast<String?, Object?>(),
92+
anEnum: pigeonMap['anEnum'] != null
93+
? AnEnum.values[pigeonMap['anEnum']! as int]
94+
: null,
8395
);
8496
}
8597
}
@@ -347,7 +359,37 @@ class HostIntegrationCoreApi {
347359
}
348360
}
349361

350-
/// Returns the passed in boolean asynchronously.
362+
/// Returns passed in double.
363+
Future<double> echoDouble(double arg_aDouble) async {
364+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
365+
'dev.flutter.pigeon.HostIntegrationCoreApi.echoDouble', codec,
366+
binaryMessenger: _binaryMessenger);
367+
final Map<Object?, Object?>? replyMap =
368+
await channel.send(<Object?>[arg_aDouble]) as Map<Object?, Object?>?;
369+
if (replyMap == null) {
370+
throw PlatformException(
371+
code: 'channel-error',
372+
message: 'Unable to establish connection on channel.',
373+
);
374+
} else if (replyMap['error'] != null) {
375+
final Map<Object?, Object?> error =
376+
(replyMap['error'] as Map<Object?, Object?>?)!;
377+
throw PlatformException(
378+
code: (error['code'] as String?)!,
379+
message: error['message'] as String?,
380+
details: error['details'],
381+
);
382+
} else if (replyMap['result'] == null) {
383+
throw PlatformException(
384+
code: 'null-error',
385+
message: 'Host platform returned null value for non-null return value.',
386+
);
387+
} else {
388+
return (replyMap['result'] as double?)!;
389+
}
390+
}
391+
392+
/// Returns the passed in boolean.
351393
Future<bool> echoBool(bool arg_aBool) async {
352394
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
353395
'dev.flutter.pigeon.HostIntegrationCoreApi.echoBool', codec,
@@ -377,6 +419,66 @@ class HostIntegrationCoreApi {
377419
}
378420
}
379421

422+
/// Returns the passed in string.
423+
Future<String> echoString(String arg_aString) async {
424+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
425+
'dev.flutter.pigeon.HostIntegrationCoreApi.echoString', codec,
426+
binaryMessenger: _binaryMessenger);
427+
final Map<Object?, Object?>? replyMap =
428+
await channel.send(<Object?>[arg_aString]) as Map<Object?, Object?>?;
429+
if (replyMap == null) {
430+
throw PlatformException(
431+
code: 'channel-error',
432+
message: 'Unable to establish connection on channel.',
433+
);
434+
} else if (replyMap['error'] != null) {
435+
final Map<Object?, Object?> error =
436+
(replyMap['error'] as Map<Object?, Object?>?)!;
437+
throw PlatformException(
438+
code: (error['code'] as String?)!,
439+
message: error['message'] as String?,
440+
details: error['details'],
441+
);
442+
} else if (replyMap['result'] == null) {
443+
throw PlatformException(
444+
code: 'null-error',
445+
message: 'Host platform returned null value for non-null return value.',
446+
);
447+
} else {
448+
return (replyMap['result'] as String?)!;
449+
}
450+
}
451+
452+
/// Returns the passed in Uint8List.
453+
Future<Uint8List> echoUint8List(Uint8List arg_aUint8List) async {
454+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
455+
'dev.flutter.pigeon.HostIntegrationCoreApi.echoUint8List', codec,
456+
binaryMessenger: _binaryMessenger);
457+
final Map<Object?, Object?>? replyMap =
458+
await channel.send(<Object?>[arg_aUint8List]) as Map<Object?, Object?>?;
459+
if (replyMap == null) {
460+
throw PlatformException(
461+
code: 'channel-error',
462+
message: 'Unable to establish connection on channel.',
463+
);
464+
} else if (replyMap['error'] != null) {
465+
final Map<Object?, Object?> error =
466+
(replyMap['error'] as Map<Object?, Object?>?)!;
467+
throw PlatformException(
468+
code: (error['code'] as String?)!,
469+
message: error['message'] as String?,
470+
details: error['details'],
471+
);
472+
} else if (replyMap['result'] == null) {
473+
throw PlatformException(
474+
code: 'null-error',
475+
message: 'Host platform returned null value for non-null return value.',
476+
);
477+
} else {
478+
return (replyMap['result'] as Uint8List?)!;
479+
}
480+
}
481+
380482
/// A no-op function taking no arguments and returning no value, to sanity
381483
/// test basic asynchronous calling.
382484
Future<void> noopAsync() async {

packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart

+36-3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) {
6161
<bool>[true, false],
6262
<bool>[false, true]
6363
],
64+
anEnum: AnEnum.two,
6465
);
6566

6667
final AllTypes echoObject = await api.echoAllTypes(sentObject);
@@ -90,6 +91,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) {
9091
true);
9192
expect(
9293
mapEquals(echoObject.mapWithObject, sentObject.mapWithObject), true);
94+
expect(echoObject.anEnum, sentObject.anEnum);
9395
});
9496

9597
testWidgets('errors are returned correctly', (WidgetTester _) async {
@@ -143,9 +145,18 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) {
143145
(WidgetTester _) async {
144146
final HostIntegrationCoreApi api = HostIntegrationCoreApi();
145147

146-
const int inInt = -13;
147-
final int anInt = await api.echoInt(inInt);
148-
expect(anInt, inInt);
148+
const int sentInt = -13;
149+
final int receivedInt = await api.echoInt(sentInt);
150+
expect(receivedInt, sentInt);
151+
});
152+
153+
testWidgets('Doubles serialize and deserialize correctly',
154+
(WidgetTester _) async {
155+
final HostIntegrationCoreApi api = HostIntegrationCoreApi();
156+
157+
const double sentDouble = 2.0694;
158+
final double receivedDouble = await api.echoDouble(sentDouble);
159+
expect(receivedDouble, sentDouble);
149160
});
150161

151162
testWidgets('booleans serialize and deserialize correctly',
@@ -157,6 +168,28 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) {
157168
expect(receivedBool, sentBool);
158169
}
159170
});
171+
172+
testWidgets('strings serialize and deserialize correctly',
173+
(WidgetTester _) async {
174+
final HostIntegrationCoreApi api = HostIntegrationCoreApi();
175+
const String sentString = "I'm a computer";
176+
final String receivedString = await api.echoString(sentString);
177+
expect(receivedString, sentString);
178+
});
179+
180+
// TODO(stuartmorgan): Enable these once they work for all generators;
181+
// currently at least Swift is broken.
182+
// TODO(tarrinneal): Finish tests for int lists once issue solved.
183+
// See https://github.com/flutter/flutter/issues/115906
184+
// testWidgets('Uint8List serialize and deserialize correctly',
185+
// (WidgetTester _) async {
186+
// final HostIntegrationCoreApi api = HostIntegrationCoreApi();
187+
// final List<int> data = [102, 111, 114, 116, 121, 45, 116, 119, 111, 0];
188+
// final Uint8List sentUint8List = Uint8List.fromList(data);
189+
// final Uint8List receivedUint8List =
190+
// await api.echoUint8List(sentUint8List);
191+
// expect(receivedUint8List, sentUint8List);
192+
// });
160193
});
161194

162195
group('Host async API tests', () {

0 commit comments

Comments
 (0)