mirror of
https://github.com/flutter/flutter.git
synced 2026-02-11 21:33:08 +08:00
* Update project.pbxproj files to say Flutter rather than Chromium Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright. * Update the copyright notice checker to require a standard notice on all files * Update copyrights on Dart files. (This was a mechanical commit.) * Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine. Some were already marked "The Flutter Authors", not clear why. Their dates have been normalized. Some were missing the blank line after the license. Some were randomly different in trivial ways for no apparent reason (e.g. missing the trailing period). * Clean up the copyrights in non-Dart files. (Manual edits.) Also, make sure templates don't have copyrights. * Fix some more ORGANIZATIONNAMEs
82 lines
2.6 KiB
Dart
82 lines
2.6 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.
|
|
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:flutter/services.dart';
|
|
import '../flutter_test_alternative.dart';
|
|
|
|
void checkEncoding<T>(MessageCodec<T> codec, T message, List<int> expectedBytes) {
|
|
final ByteData encoded = codec.encodeMessage(message);
|
|
expect(
|
|
encoded.buffer.asUint8List(0, encoded.lengthInBytes),
|
|
orderedEquals(expectedBytes),
|
|
);
|
|
}
|
|
|
|
void checkEncodeDecode<T>(MessageCodec<T> codec, T message) {
|
|
final ByteData encoded = codec.encodeMessage(message);
|
|
final T decoded = codec.decodeMessage(encoded);
|
|
if (message == null) {
|
|
expect(encoded, isNull);
|
|
expect(decoded, isNull);
|
|
} else {
|
|
expect(deepEquals(message, decoded), isTrue);
|
|
final ByteData encodedAgain = codec.encodeMessage(decoded);
|
|
expect(
|
|
encodedAgain.buffer.asUint8List(),
|
|
orderedEquals(encoded.buffer.asUint8List()),
|
|
);
|
|
}
|
|
}
|
|
|
|
bool deepEquals(dynamic valueA, dynamic valueB) {
|
|
if (valueA is TypedData)
|
|
return valueB is TypedData && deepEqualsTypedData(valueA, valueB);
|
|
if (valueA is List)
|
|
return valueB is List && deepEqualsList(valueA, valueB);
|
|
if (valueA is Map)
|
|
return valueB is Map && deepEqualsMap(valueA, valueB);
|
|
if (valueA is double && valueA.isNaN)
|
|
return valueB is double && valueB.isNaN;
|
|
return valueA == valueB;
|
|
}
|
|
|
|
bool deepEqualsTypedData(TypedData valueA, TypedData valueB) {
|
|
if (valueA is ByteData) {
|
|
return valueB is ByteData
|
|
&& deepEqualsList(
|
|
valueA.buffer.asUint8List(), valueB.buffer.asUint8List());
|
|
}
|
|
if (valueA is Uint8List)
|
|
return valueB is Uint8List && deepEqualsList(valueA, valueB);
|
|
if (valueA is Int32List)
|
|
return valueB is Int32List && deepEqualsList(valueA, valueB);
|
|
if (valueA is Int64List)
|
|
return valueB is Int64List && deepEqualsList(valueA, valueB);
|
|
if (valueA is Float64List)
|
|
return valueB is Float64List && deepEqualsList(valueA, valueB);
|
|
throw 'Unexpected typed data: $valueA';
|
|
}
|
|
|
|
bool deepEqualsList(List<dynamic> valueA, List<dynamic> valueB) {
|
|
if (valueA.length != valueB.length)
|
|
return false;
|
|
for (int i = 0; i < valueA.length; i++) {
|
|
if (!deepEquals(valueA[i], valueB[i]))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool deepEqualsMap(Map<dynamic, dynamic> valueA, Map<dynamic, dynamic> valueB) {
|
|
if (valueA.length != valueB.length)
|
|
return false;
|
|
for (final dynamic key in valueA.keys) {
|
|
if (!valueB.containsKey(key) || !deepEquals(valueA[key], valueB[key]))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|