proxy_getters_and_setters_test.dart 2.67 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Ian Hickson's avatar
Ian Hickson committed
2 3 4 5 6
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
7
import 'package:flutter_test/flutter_test.dart';
Ian Hickson's avatar
Ian Hickson committed
8 9 10

void main() {
  test('RenderConstrainedBox getters and setters', () {
11
    final RenderConstrainedBox box = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(height: 10.0));
12 13 14
    expect(box.additionalConstraints, const BoxConstraints(minHeight: 10.0, maxHeight: 10.0));
    box.additionalConstraints = const BoxConstraints.tightFor(width: 10.0);
    expect(box.additionalConstraints, const BoxConstraints(minWidth: 10.0, maxWidth: 10.0));
Ian Hickson's avatar
Ian Hickson committed
15 16 17
  });

  test('RenderLimitedBox getters and setters', () {
18
    final RenderLimitedBox box = RenderLimitedBox();
19 20
    expect(box.maxWidth, double.infinity);
    expect(box.maxHeight, double.infinity);
Ian Hickson's avatar
Ian Hickson committed
21 22 23 24 25 26 27
    box.maxWidth = 0.0;
    box.maxHeight = 1.0;
    expect(box.maxHeight, 1.0);
    expect(box.maxWidth, 0.0);
  });

  test('RenderAspectRatio getters and setters', () {
28
    final RenderAspectRatio box = RenderAspectRatio(aspectRatio: 1.0);
Ian Hickson's avatar
Ian Hickson committed
29 30 31 32 33 34 35 36
    expect(box.aspectRatio, 1.0);
    box.aspectRatio = 0.2;
    expect(box.aspectRatio, 0.2);
    box.aspectRatio = 1.2;
    expect(box.aspectRatio, 1.2);
  });

  test('RenderIntrinsicWidth getters and setters', () {
37
    final RenderIntrinsicWidth box = RenderIntrinsicWidth();
Ian Hickson's avatar
Ian Hickson committed
38 39 40 41 42 43 44 45 46
    expect(box.stepWidth, isNull);
    box.stepWidth = 10.0;
    expect(box.stepWidth, 10.0);
    expect(box.stepHeight, isNull);
    box.stepHeight = 10.0;
    expect(box.stepHeight, 10.0);
  });

  test('RenderOpacity getters and setters', () {
47
    final RenderOpacity box = RenderOpacity();
Ian Hickson's avatar
Ian Hickson committed
48 49 50 51 52 53
    expect(box.opacity, 1.0);
    box.opacity = 0.0;
    expect(box.opacity, 0.0);
  });

  test('RenderShaderMask getters and setters', () {
54
    Shader callback1(Rect bounds) {
55 56 57
      assert(false); // The test should not call this.
      const LinearGradient gradient = LinearGradient(colors: <Color>[Colors.red]);
      return gradient.createShader(Rect.zero);
58 59
    }
    Shader callback2(Rect bounds) {
60 61 62
      assert(false); // The test should not call this.
      const LinearGradient gradient = LinearGradient(colors: <Color>[Colors.blue]);
      return gradient.createShader(Rect.zero);
63
    }
64
    final RenderShaderMask box = RenderShaderMask(shaderCallback: callback1);
Ian Hickson's avatar
Ian Hickson committed
65 66 67 68 69 70 71 72
    expect(box.shaderCallback, equals(callback1));
    box.shaderCallback = callback2;
    expect(box.shaderCallback, equals(callback2));
    expect(box.blendMode, BlendMode.modulate);
    box.blendMode = BlendMode.colorBurn;
    expect(box.blendMode, BlendMode.colorBurn);
  });
}