debug_test.dart 4.79 KB
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/foundation.dart';
6 7 8 9
import 'package:flutter/rendering.dart';
import 'package:test/test.dart';
import 'package:vector_math/vector_math_64.dart';

10
import 'mock_canvas.dart';
11
import 'rendering_tester.dart';
12

13
void main() {
14
  test('Describe transform control test', () {
15 16
    final Matrix4 identity = new Matrix4.identity();
    final List<String> description = debugDescribeTransform(identity);
17 18 19 20 21 22 23
    expect(description, equals(<String>[
      '  [0] 1.0,0.0,0.0,0.0',
      '  [1] 0.0,1.0,0.0,0.0',
      '  [2] 0.0,0.0,1.0,0.0',
      '  [3] 0.0,0.0,0.0,1.0',
    ]));
  });
24

25 26 27 28 29 30 31
  test('transform property test', () {
    final Matrix4 transform = new Matrix4.diagonal3(new Vector3.all(2.0));
    final TransformProperty simple = new TransformProperty(
      'transform',
      transform,
    );
    expect(simple.name, equals('transform'));
32
    expect(simple.value, same(transform));
33
    expect(
34
      simple.toString(parentConfiguration: sparseTextConfiguration),
35 36
      equals(
        'transform:\n'
37 38 39 40
        '  [0] 2.0,0.0,0.0,0.0\n'
        '  [1] 0.0,2.0,0.0,0.0\n'
        '  [2] 0.0,0.0,2.0,0.0\n'
        '  [3] 0.0,0.0,0.0,1.0',
41 42
      ),
    );
43 44 45 46
    expect(
      simple.toString(parentConfiguration: singleLineTextConfiguration),
      equals('transform: [2.0,0.0,0.0,0.0; 0.0,2.0,0.0,0.0; 0.0,0.0,2.0,0.0; 0.0,0.0,0.0,1.0]'),
    );
47 48 49 50 51 52

    final TransformProperty nullProperty = new TransformProperty(
      'transform',
      null,
    );
    expect(nullProperty.name, equals('transform'));
53
    expect(nullProperty.value, isNull);
54 55 56 57 58 59 60
    expect(nullProperty.toString(), equals('transform: null'));

    final TransformProperty hideNull = new TransformProperty(
      'transform',
      null,
      defaultValue: null,
    );
61
    expect(hideNull.value, isNull);
62 63 64
    expect(hideNull.toString(), equals('transform: null'));
  });

65 66 67
  test('debugPaintPadding', () {
    expect((Canvas canvas) {
      debugPaintPadding(canvas, new Rect.fromLTRB(10.0, 10.0, 20.0, 20.0), null);
68
    }, paints..rect(color: const Color(0x90909090)));
69 70
    expect((Canvas canvas) {
      debugPaintPadding(canvas, new Rect.fromLTRB(10.0, 10.0, 20.0, 20.0), new Rect.fromLTRB(11.0, 11.0, 19.0, 19.0));
71
    }, paints..path(color: const Color(0x900090FF))..path(color: const Color(0xFF0090FF)));
72 73
    expect((Canvas canvas) {
      debugPaintPadding(canvas, new Rect.fromLTRB(10.0, 10.0, 20.0, 20.0), new Rect.fromLTRB(15.0, 15.0, 15.0, 15.0));
74
    }, paints..rect(rect: new Rect.fromLTRB(10.0, 10.0, 20.0, 20.0), color: const Color(0x90909090)));
75
  });
Ian Hickson's avatar
Ian Hickson committed
76 77 78 79 80

  test('debugPaintPadding from render objects', () {
    debugPaintSizeEnabled = true;
    RenderSliver s;
    RenderBox b;
81
    final RenderViewport root = new RenderViewport(
82
      crossAxisDirection: AxisDirection.right,
Ian Hickson's avatar
Ian Hickson committed
83 84 85
      offset: new ViewportOffset.zero(),
      children: <RenderSliver>[
        s = new RenderSliverPadding(
86
          padding: const EdgeInsets.all(10.0),
Ian Hickson's avatar
Ian Hickson committed
87 88
          child: new RenderSliverToBoxAdapter(
            child: b = new RenderPadding(
89
              padding: const EdgeInsets.all(10.0),
Ian Hickson's avatar
Ian Hickson committed
90 91 92 93 94 95
            ),
          ),
        ),
      ],
    );
    layout(root);
96
    expect(b.debugPaint, paints..rect(color: const Color(0xFF00FFFF))..rect(color: const Color(0x90909090)));
Ian Hickson's avatar
Ian Hickson committed
97 98
    expect(b.debugPaint, isNot(paints..path()));
    expect(s.debugPaint, paints..circle(hasMaskFilter: true)..line(hasMaskFilter: true)..path(hasMaskFilter: true)..path(hasMaskFilter: true)
99
                               ..path(color: const Color(0x900090FF))..path(color: const Color(0xFF0090FF)));
Ian Hickson's avatar
Ian Hickson committed
100 101 102 103 104 105 106
    expect(s.debugPaint, isNot(paints..rect()));
    debugPaintSizeEnabled = false;
  });

  test('debugPaintPadding from render objects', () {
    debugPaintSizeEnabled = true;
    RenderSliver s;
107
    final RenderBox b = new RenderPadding(
108
      padding: const EdgeInsets.all(10.0),
Adam Barth's avatar
Adam Barth committed
109
      child: new RenderViewport(
110
        crossAxisDirection: AxisDirection.right,
Ian Hickson's avatar
Ian Hickson committed
111 112 113
        offset: new ViewportOffset.zero(),
        children: <RenderSliver>[
          s = new RenderSliverPadding(
114
            padding: const EdgeInsets.all(10.0),
Ian Hickson's avatar
Ian Hickson committed
115 116 117 118 119
          ),
        ],
      ),
    );
    layout(b);
120
    expect(s.debugPaint, paints..rect(color: const Color(0x90909090)));
Ian Hickson's avatar
Ian Hickson committed
121
    expect(s.debugPaint, isNot(paints..circle(hasMaskFilter: true)..line(hasMaskFilter: true)..path(hasMaskFilter: true)..path(hasMaskFilter: true)
122 123 124
                                     ..path(color: const Color(0x900090FF))..path(color: const Color(0xFF0090FF))));
    expect(b.debugPaint, paints..rect(color: const Color(0xFF00FFFF))..path(color: const Color(0x900090FF))..path(color: const Color(0xFF0090FF)));
    expect(b.debugPaint, isNot(paints..rect(color: const Color(0x90909090))));
Ian Hickson's avatar
Ian Hickson committed
125 126
    debugPaintSizeEnabled = false;
  });
127
}