Skip to content

Commit

Permalink
Fix skwasm's canvasDrawArc declaration and write tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
eyebrowsoffire committed Apr 13, 2023
1 parent f5dab1b commit 415aa70
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
Expand Up @@ -108,7 +108,7 @@ external void canvasDrawCircle(
CanvasHandle canvas, double x, double y, double radius, PaintHandle paint);

@Native<Void Function(CanvasHandle, RawRect, Float, Float, Bool, PaintHandle)>(
symbol: 'canvas_drawCircle', isLeaf: true)
symbol: 'canvas_drawArc', isLeaf: true)
external void canvasDrawArc(
CanvasHandle canvas,
RawRect rect,
Expand Down
74 changes: 74 additions & 0 deletions lib/web_ui/test/ui/canvas_curves_golden_test.dart
@@ -0,0 +1,74 @@
// Copyright 2013 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:math' as math;

import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/ui.dart';
import 'package:web_engine_tester/golden_tester.dart';

import 'utils.dart';

void main() {
internalBootstrapBrowserTest(() => testMain);
}

Future<void> testMain() async {
setUpUiTest();

const Rect region = Rect.fromLTWH(0, 0, 300, 300);

test('draw arc', () async {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder, region);
canvas.drawArc(
const Rect.fromLTRB(100, 100, 200, 200),
math.pi / 3.0,
4.0 * math.pi / 3.0,
false,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 3.0
..color = const Color(0xFFFF00FF)
);

await drawPictureUsingCurrentRenderer(recorder.endRecording());

await matchGoldenFile('ui_canvas_draw_arc.png', region: region);
});

test('draw circle', () async {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder, region);
canvas.drawCircle(
const Offset(150, 150),
50,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 3.0
..color = const Color(0xFFFF0000)
);

await drawPictureUsingCurrentRenderer(recorder.endRecording());

await matchGoldenFile('ui_canvas_draw_circle.png', region: region);
});

test('draw oval', () async {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder, region);
canvas.drawOval(
const Rect.fromLTRB(100, 125, 200, 175),
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 3.0
..color = const Color(0xFF00FFFF)
);

await drawPictureUsingCurrentRenderer(recorder.endRecording());

await matchGoldenFile('ui_canvas_draw_oval.png', region: region);
});
}

0 comments on commit 415aa70

Please sign in to comment.