mirror of
https://github.com/flutter/flutter.git
synced 2026-02-13 14:21:39 +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
232 lines
6.4 KiB
Dart
232 lines
6.4 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:async';
|
||
import 'dart:typed_data';
|
||
import 'dart:ui' as ui show Image, ImageByteFormat;
|
||
|
||
import 'package:flutter/rendering.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
|
||
import 'rendering_tester.dart';
|
||
|
||
class SquareImage implements ui.Image {
|
||
@override
|
||
int get width => 10;
|
||
|
||
@override
|
||
int get height => 10;
|
||
|
||
@override
|
||
Future<ByteData> toByteData({ ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba }) async {
|
||
throw UnsupportedError('Cannot encode test image');
|
||
}
|
||
|
||
@override
|
||
String toString() => '[$width\u00D7$height]';
|
||
|
||
@override
|
||
void dispose() { }
|
||
}
|
||
|
||
class WideImage implements ui.Image {
|
||
@override
|
||
int get width => 20;
|
||
|
||
@override
|
||
int get height => 10;
|
||
|
||
@override
|
||
Future<ByteData> toByteData({ ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba }) async {
|
||
throw UnsupportedError('Cannot encode test image');
|
||
}
|
||
|
||
@override
|
||
String toString() => '[$width\u00D7$height]';
|
||
|
||
@override
|
||
void dispose() { }
|
||
}
|
||
|
||
class TallImage implements ui.Image {
|
||
@override
|
||
int get width => 10;
|
||
|
||
@override
|
||
int get height => 20;
|
||
|
||
@override
|
||
Future<ByteData> toByteData({ ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba }) async {
|
||
throw UnsupportedError('Cannot encode test image');
|
||
}
|
||
|
||
@override
|
||
String toString() => '[$width\u00D7$height]';
|
||
|
||
@override
|
||
void dispose() { }
|
||
}
|
||
|
||
void main() {
|
||
test('Image sizing', () {
|
||
RenderImage image;
|
||
|
||
image = RenderImage(image: SquareImage());
|
||
layout(image,
|
||
constraints: const BoxConstraints(
|
||
minWidth: 25.0,
|
||
minHeight: 25.0,
|
||
maxWidth: 100.0,
|
||
maxHeight: 100.0));
|
||
expect(image.size.width, equals(25.0));
|
||
expect(image.size.height, equals(25.0));
|
||
|
||
expect(image, hasAGoodToStringDeep);
|
||
expect(
|
||
image.toStringDeep(minLevel: DiagnosticLevel.info),
|
||
equalsIgnoringHashCodes(
|
||
'RenderImage#00000 relayoutBoundary=up2 NEEDS-PAINT\n'
|
||
' parentData: <none> (can use size)\n'
|
||
' constraints: BoxConstraints(25.0<=w<=100.0, 25.0<=h<=100.0)\n'
|
||
' size: Size(25.0, 25.0)\n'
|
||
' image: [10×10]\n'
|
||
' alignment: center\n'
|
||
' invertColors: false\n'
|
||
' filterQuality: low\n'
|
||
),
|
||
);
|
||
|
||
image = RenderImage(image: WideImage());
|
||
layout(image,
|
||
constraints: const BoxConstraints(
|
||
minWidth: 5.0,
|
||
minHeight: 30.0,
|
||
maxWidth: 100.0,
|
||
maxHeight: 100.0));
|
||
expect(image.size.width, equals(60.0));
|
||
expect(image.size.height, equals(30.0));
|
||
|
||
image = RenderImage(image: TallImage());
|
||
layout(image,
|
||
constraints: const BoxConstraints(
|
||
minWidth: 50.0,
|
||
minHeight: 5.0,
|
||
maxWidth: 75.0,
|
||
maxHeight: 75.0));
|
||
expect(image.size.width, equals(50.0));
|
||
expect(image.size.height, equals(75.0));
|
||
|
||
image = RenderImage(image: WideImage());
|
||
layout(image,
|
||
constraints: const BoxConstraints(
|
||
minWidth: 5.0,
|
||
minHeight: 5.0,
|
||
maxWidth: 100.0,
|
||
maxHeight: 100.0));
|
||
expect(image.size.width, equals(20.0));
|
||
expect(image.size.height, equals(10.0));
|
||
|
||
image = RenderImage(image: WideImage());
|
||
layout(image,
|
||
constraints: const BoxConstraints(
|
||
minWidth: 5.0,
|
||
minHeight: 5.0,
|
||
maxWidth: 16.0,
|
||
maxHeight: 16.0));
|
||
expect(image.size.width, equals(16.0));
|
||
expect(image.size.height, equals(8.0));
|
||
|
||
image = RenderImage(image: TallImage());
|
||
layout(image,
|
||
constraints: const BoxConstraints(
|
||
minWidth: 5.0,
|
||
minHeight: 5.0,
|
||
maxWidth: 16.0,
|
||
maxHeight: 16.0));
|
||
expect(image.size.width, equals(8.0));
|
||
expect(image.size.height, equals(16.0));
|
||
|
||
image = RenderImage(image: SquareImage());
|
||
layout(image,
|
||
constraints: const BoxConstraints(
|
||
minWidth: 4.0,
|
||
minHeight: 4.0,
|
||
maxWidth: 8.0,
|
||
maxHeight: 8.0));
|
||
expect(image.size.width, equals(8.0));
|
||
expect(image.size.height, equals(8.0));
|
||
|
||
image = RenderImage(image: WideImage());
|
||
layout(image,
|
||
constraints: const BoxConstraints(
|
||
minWidth: 20.0,
|
||
minHeight: 20.0,
|
||
maxWidth: 30.0,
|
||
maxHeight: 30.0));
|
||
expect(image.size.width, equals(30.0));
|
||
expect(image.size.height, equals(20.0));
|
||
|
||
image = RenderImage(image: TallImage());
|
||
layout(image,
|
||
constraints: const BoxConstraints(
|
||
minWidth: 20.0,
|
||
minHeight: 20.0,
|
||
maxWidth: 30.0,
|
||
maxHeight: 30.0));
|
||
expect(image.size.width, equals(20.0));
|
||
expect(image.size.height, equals(30.0));
|
||
});
|
||
|
||
test('Null image sizing', () {
|
||
RenderImage image;
|
||
|
||
image = RenderImage();
|
||
layout(image,
|
||
constraints: const BoxConstraints(
|
||
minWidth: 25.0,
|
||
minHeight: 25.0,
|
||
maxWidth: 100.0,
|
||
maxHeight: 100.0));
|
||
expect(image.size.width, equals(25.0));
|
||
expect(image.size.height, equals(25.0));
|
||
|
||
image = RenderImage(width: 50.0);
|
||
layout(image,
|
||
constraints: const BoxConstraints(
|
||
minWidth: 25.0,
|
||
minHeight: 25.0,
|
||
maxWidth: 100.0,
|
||
maxHeight: 100.0));
|
||
expect(image.size.width, equals(50.0));
|
||
expect(image.size.height, equals(25.0));
|
||
|
||
image = RenderImage(height: 50.0);
|
||
layout(image,
|
||
constraints: const BoxConstraints(
|
||
minWidth: 25.0,
|
||
minHeight: 25.0,
|
||
maxWidth: 100.0,
|
||
maxHeight: 100.0));
|
||
expect(image.size.width, equals(25.0));
|
||
expect(image.size.height, equals(50.0));
|
||
|
||
image = RenderImage(width: 100.0, height: 100.0);
|
||
layout(image,
|
||
constraints: const BoxConstraints(
|
||
minWidth: 25.0,
|
||
minHeight: 25.0,
|
||
maxWidth: 75.0,
|
||
maxHeight: 75.0));
|
||
expect(image.size.width, equals(75.0));
|
||
expect(image.size.height, equals(75.0));
|
||
});
|
||
|
||
test('update image colorBlendMode', () {
|
||
final RenderImage image = RenderImage();
|
||
expect(image.colorBlendMode, isNull);
|
||
image.colorBlendMode = BlendMode.color;
|
||
expect(image.colorBlendMode, BlendMode.color);
|
||
});
|
||
}
|