Migrate integration_tests/channels to null safety (#84145)
This commit is contained in:
parent
aaff32902e
commit
c077278431
@ -19,7 +19,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TestApp extends StatefulWidget {
|
class TestApp extends StatefulWidget {
|
||||||
const TestApp({Key key}) : super(key: key);
|
const TestApp({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<TestApp> createState() => _TestAppState();
|
State<TestApp> createState() => _TestAppState();
|
||||||
@ -155,7 +155,7 @@ class _TestAppState extends State<TestApp> {
|
|||||||
() => basicJsonMessageToUnknownChannel(),
|
() => basicJsonMessageToUnknownChannel(),
|
||||||
() => basicStandardMessageToUnknownChannel(),
|
() => basicStandardMessageToUnknownChannel(),
|
||||||
];
|
];
|
||||||
Future<TestStepResult> _result;
|
Future<TestStepResult>? _result;
|
||||||
int _step = 0;
|
int _step = 0;
|
||||||
|
|
||||||
void _executeNextStep() {
|
void _executeNextStep() {
|
||||||
|
@ -42,22 +42,22 @@ class ExtendedStandardMessageCodec extends StandardMessageCodec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<TestStepResult> basicBinaryHandshake(ByteData message) async {
|
Future<TestStepResult> basicBinaryHandshake(ByteData? message) async {
|
||||||
const BasicMessageChannel<ByteData> channel =
|
const BasicMessageChannel<ByteData?> channel =
|
||||||
BasicMessageChannel<ByteData>(
|
BasicMessageChannel<ByteData?>(
|
||||||
'binary-msg',
|
'binary-msg',
|
||||||
BinaryCodec(),
|
BinaryCodec(),
|
||||||
);
|
);
|
||||||
return _basicMessageHandshake<ByteData>(
|
return _basicMessageHandshake<ByteData?>(
|
||||||
'Binary >${toString(message)}<', channel, message);
|
'Binary >${toString(message)}<', channel, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<TestStepResult> basicStringHandshake(String message) async {
|
Future<TestStepResult> basicStringHandshake(String? message) async {
|
||||||
const BasicMessageChannel<String> channel = BasicMessageChannel<String>(
|
const BasicMessageChannel<String?> channel = BasicMessageChannel<String?>(
|
||||||
'string-msg',
|
'string-msg',
|
||||||
StringCodec(),
|
StringCodec(),
|
||||||
);
|
);
|
||||||
return _basicMessageHandshake<String>('String >$message<', channel, message);
|
return _basicMessageHandshake<String?>('String >$message<', channel, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<TestStepResult> basicJsonHandshake(dynamic message) async {
|
Future<TestStepResult> basicJsonHandshake(dynamic message) async {
|
||||||
@ -80,8 +80,8 @@ Future<TestStepResult> basicStandardHandshake(dynamic message) async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<TestStepResult> basicBinaryMessageToUnknownChannel() async {
|
Future<TestStepResult> basicBinaryMessageToUnknownChannel() async {
|
||||||
const BasicMessageChannel<ByteData> channel =
|
const BasicMessageChannel<ByteData?> channel =
|
||||||
BasicMessageChannel<ByteData>(
|
BasicMessageChannel<ByteData?>(
|
||||||
'binary-unknown',
|
'binary-unknown',
|
||||||
BinaryCodec(),
|
BinaryCodec(),
|
||||||
);
|
);
|
||||||
@ -89,7 +89,7 @@ Future<TestStepResult> basicBinaryMessageToUnknownChannel() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<TestStepResult> basicStringMessageToUnknownChannel() async {
|
Future<TestStepResult> basicStringMessageToUnknownChannel() async {
|
||||||
const BasicMessageChannel<String> channel = BasicMessageChannel<String>(
|
const BasicMessageChannel<String?> channel = BasicMessageChannel<String?>(
|
||||||
'string-unknown',
|
'string-unknown',
|
||||||
StringCodec(),
|
StringCodec(),
|
||||||
);
|
);
|
||||||
@ -122,11 +122,11 @@ Future<TestStepResult> basicStandardMessageToUnknownChannel() async {
|
|||||||
/// the original message.
|
/// the original message.
|
||||||
Future<TestStepResult> _basicMessageHandshake<T>(
|
Future<TestStepResult> _basicMessageHandshake<T>(
|
||||||
String description,
|
String description,
|
||||||
BasicMessageChannel<T> channel,
|
BasicMessageChannel<T?> channel,
|
||||||
T message,
|
T message,
|
||||||
) async {
|
) async {
|
||||||
final List<dynamic> received = <dynamic>[];
|
final List<dynamic> received = <dynamic>[];
|
||||||
channel.setMessageHandler((T message) async {
|
channel.setMessageHandler((T? message) async {
|
||||||
received.add(message);
|
received.add(message);
|
||||||
return message;
|
return message;
|
||||||
});
|
});
|
||||||
@ -150,7 +150,7 @@ Future<TestStepResult> _basicMessageHandshake<T>(
|
|||||||
/// Sends a message on a channel that no one listens on.
|
/// Sends a message on a channel that no one listens on.
|
||||||
Future<TestStepResult> _basicMessageToUnknownChannel<T>(
|
Future<TestStepResult> _basicMessageToUnknownChannel<T>(
|
||||||
String description,
|
String description,
|
||||||
BasicMessageChannel<T> channel,
|
BasicMessageChannel<T?> channel,
|
||||||
) async {
|
) async {
|
||||||
dynamic messageEcho = nothing;
|
dynamic messageEcho = nothing;
|
||||||
dynamic error = nothing;
|
dynamic error = nothing;
|
||||||
|
@ -44,12 +44,9 @@ class TestStepResult {
|
|||||||
return const TestStepResult('Executing', nothing, TestStatus.pending);
|
return const TestStepResult('Executing', nothing, TestStatus.pending);
|
||||||
case ConnectionState.done:
|
case ConnectionState.done:
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
return snapshot.data;
|
return snapshot.data!;
|
||||||
} else {
|
|
||||||
final TestStepResult result = snapshot.error as TestStepResult;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
break;
|
return snapshot.error! as TestStepResult;
|
||||||
default:
|
default:
|
||||||
throw 'Unsupported state ${snapshot.connectionState}';
|
throw 'Unsupported state ${snapshot.connectionState}';
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ name: channels
|
|||||||
description: Integration test for platform channels.
|
description: Integration test for platform channels.
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.0.0-dev.68.0 <3.0.0"
|
sdk: ">=2.12.0 <3.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
|
@ -7,7 +7,7 @@ import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('channel suite', () {
|
group('channel suite', () {
|
||||||
FlutterDriver driver;
|
late FlutterDriver driver;
|
||||||
|
|
||||||
setUpAll(() async {
|
setUpAll(() async {
|
||||||
driver = await FlutterDriver.connect();
|
driver = await FlutterDriver.connect();
|
||||||
@ -28,7 +28,7 @@ void main() {
|
|||||||
}, timeout: const Timeout(Duration(minutes: 1)));
|
}, timeout: const Timeout(Duration(minutes: 1)));
|
||||||
|
|
||||||
tearDownAll(() async {
|
tearDownAll(() async {
|
||||||
driver?.close();
|
driver.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ class JSONMethodCodec implements MethodCodec {
|
|||||||
&& (decoded[1] == null || decoded[1] is String))
|
&& (decoded[1] == null || decoded[1] is String))
|
||||||
throw PlatformException(
|
throw PlatformException(
|
||||||
code: decoded[0] as String,
|
code: decoded[0] as String,
|
||||||
message: decoded[1] as String,
|
message: decoded[1] as String?,
|
||||||
details: decoded[2],
|
details: decoded[2],
|
||||||
);
|
);
|
||||||
if (decoded.length == 4
|
if (decoded.length == 4
|
||||||
@ -163,9 +163,9 @@ class JSONMethodCodec implements MethodCodec {
|
|||||||
&& (decoded[3] == null || decoded[3] is String))
|
&& (decoded[3] == null || decoded[3] is String))
|
||||||
throw PlatformException(
|
throw PlatformException(
|
||||||
code: decoded[0] as String,
|
code: decoded[0] as String,
|
||||||
message: decoded[1] as String,
|
message: decoded[1] as String?,
|
||||||
details: decoded[2],
|
details: decoded[2],
|
||||||
stacktrace: decoded[3] as String,
|
stacktrace: decoded[3] as String?,
|
||||||
);
|
);
|
||||||
throw FormatException('Invalid envelope: $decoded');
|
throw FormatException('Invalid envelope: $decoded');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user