paint_image_test.dart 1.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// 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.

import 'dart:ui' as ui;

import 'package:flutter/painting.dart';

import 'package:test/test.dart';

class TestImage implements ui.Image {
  TestImage({ this.width, this.height });

14
  @override
15
  final int width;
16 17

  @override
18 19
  final int height;

20
  @override
21 22 23 24 25 26
  void dispose() { }
}

class TestCanvas implements Canvas {
  final List<Invocation> invocations = <Invocation>[];

27
  @override
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  void noSuchMethod(Invocation invocation) {
    invocations.add(invocation);
  }
}

void main() {
  test("Cover and align", () {
    TestImage image = new TestImage(width: 300, height: 300);
    TestCanvas canvas = new TestCanvas();
    paintImage(
      canvas: canvas,
      rect: new Rect.fromLTWH(50.0, 75.0, 200.0, 100.0),
      image: image,
      fit: ImageFit.cover,
      alignment: new FractionalOffset(0.0, 0.5)
    );

    Invocation command = canvas.invocations.firstWhere((Invocation invocation) {
      return invocation.memberName == #drawImageRect;
    });

    expect(command, isNotNull);
    expect(command.positionalArguments[0], equals(image));
    expect(command.positionalArguments[1], equals(new Rect.fromLTWH(0.0, 75.0, 300.0, 150.0)));
    expect(command.positionalArguments[2], equals(new Rect.fromLTWH(50.0, 75.0, 200.0, 100.0)));
  });
}