flutter_flutter/packages/flutter/test/services/message_codecs_vm_test.dart
Michael Goderbauer 5491c8c146
Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
2024-12-19 20:06:21 +00:00

115 lines
3.1 KiB
Dart

// Copyright 2014 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.
@TestOn('!chrome')
library;
import 'dart:typed_data';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'message_codecs_testing.dart';
void main() {
group('JSON message codec', () {
const MessageCodec<dynamic> json = JSONMessageCodec();
test('should encode and decode big numbers', () {
checkEncodeDecode<dynamic>(json, 9223372036854775807);
checkEncodeDecode<dynamic>(json, -9223372036854775807);
});
test('should encode and decode list with a big number', () {
final List<dynamic> message = <dynamic>[
// ignore: avoid_js_rounded_ints, since we check for round-tripping, the actual value doesn't matter!
-7000000000000000007,
];
checkEncodeDecode<dynamic>(json, message);
});
});
group('Standard message codec', () {
const MessageCodec<dynamic> standard = StandardMessageCodec();
test('should encode integers correctly at boundary cases', () {
checkEncoding<dynamic>(standard, -0x7fffffff - 1, <int>[3, 0x00, 0x00, 0x00, 0x80]);
checkEncoding<dynamic>(standard, -0x7fffffff - 2, <int>[
4,
0xff,
0xff,
0xff,
0x7f,
0xff,
0xff,
0xff,
0xff,
]);
checkEncoding<dynamic>(standard, 0x7fffffff, <int>[3, 0xff, 0xff, 0xff, 0x7f]);
checkEncoding<dynamic>(standard, 0x7fffffff + 1, <int>[
4,
0x00,
0x00,
0x00,
0x80,
0x00,
0x00,
0x00,
0x00,
]);
checkEncoding<dynamic>(standard, -0x7fffffffffffffff - 1, <int>[
4,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x80,
]);
checkEncoding<dynamic>(standard, -0x7fffffffffffffff - 2, <int>[
4,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0x7f,
]);
checkEncoding<dynamic>(standard, 0x7fffffffffffffff, <int>[
4,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0x7f,
]);
checkEncoding<dynamic>(standard, 0x7fffffffffffffff + 1, <int>[
4,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x80,
]);
});
test('should encode and decode big numbers', () {
checkEncodeDecode<dynamic>(standard, 9223372036854775807);
checkEncodeDecode<dynamic>(standard, -9223372036854775807);
});
test('should encode and decode a list containing big numbers', () {
final List<dynamic> message = <dynamic>[
-7000000000000000007, // ignore: avoid_js_rounded_ints, browsers are skipped below
Int64List.fromList(<int>[-0x7fffffffffffffff - 1, 0, 0x7fffffffffffffff]),
];
checkEncodeDecode<dynamic>(standard, message);
});
}, skip: isBrowser); // [intended] Javascript can't handle the big integer literals used here.
}