-
Notifications
You must be signed in to change notification settings - Fork 239
Expand file tree
/
Copy pathrender_resolution_test.dart
More file actions
152 lines (133 loc) · 4.08 KB
/
Copy pathrender_resolution_test.dart
File metadata and controls
152 lines (133 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import 'dart:io' as io;
import 'dart:ui' as ui;
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:rive/rive.dart';
import 'package:rive_native/rive_native.dart' as rive;
/// Tests for the [RenderResolution] plumbing in the rive package:
/// [RiveWidget] rejects the parameter on the shared-texture path (the surface
/// owns that allocation), and [RiveSurface]/[RivePanel] forward their policy
/// to the texture's widget host.
base class _FakeRenderTexture extends rive.RenderTexture {
rive.RenderResolution? lastWidgetResolution;
@override
int get textureId => -1;
@override
dynamic get nativeTexture => null;
@override
int get actualWidth => 0;
@override
int get actualHeight => 0;
@override
bool get isReady => false;
@override
bool get isDisposed => false;
@override
rive.Renderer get renderer => throw UnimplementedError();
@override
bool clear(Color color, [bool write = true]) => true;
@override
bool flush(double devicePixelRatio) => true;
@override
bool needsResize(int width, int height) => false;
@override
Future<void> makeRenderTexture(int width, int height) async {}
@override
Future<ui.Image> toImage() => throw UnimplementedError();
@override
Widget widget({
rive.RenderTexturePainter? painter,
rive.RenderResolution resolution = const rive.RenderResolution.display(),
Key? key,
}) {
lastWidgetResolution = resolution;
return SizedBox.shrink(key: key);
}
@override
void dispose() {}
}
SharedRenderTexture _makeShared(_FakeRenderTexture texture) =>
SharedRenderTexture(
texture: texture,
devicePixelRatio: 1.0,
backgroundColor: const Color(0x00000000),
panelKey: GlobalKey(),
);
void main() {
group('RiveWidget.renderResolution', () {
late File riveFile;
late RiveWidgetController controller;
setUp(() async {
final file = io.File('test/assets/rive_file_controller_test.riv');
riveFile = await File.decode(
await file.readAsBytes(),
riveFactory: Factory.flutter,
) as File;
controller = RiveWidgetController(riveFile);
});
tearDown(() {
controller.dispose();
riveFile.dispose();
});
test('asserts when combined with useSharedTexture', () {
expect(
() => RiveWidget(
controller: controller,
useSharedTexture: true,
renderResolution: const RenderResolution.layout(),
),
throwsAssertionError,
);
});
test('asserts when combined with an explicit sharedTexture', () {
final texture = _FakeRenderTexture();
final shared = _makeShared(texture);
addTearDown(shared.dispose);
expect(
() => RiveWidget(
controller: controller,
sharedTexture: shared,
renderResolution: const RenderResolution.fixed(64, 64),
),
throwsAssertionError,
);
});
test('constructs on the own-texture path', () {
expect(
() => RiveWidget(
controller: controller,
renderResolution: const RenderResolution.layout(scale: 0.5),
),
returnsNormally,
);
});
});
group('RiveSurface / RivePanel forwarding', () {
testWidgets('RiveSurface hands its renderResolution to the texture widget',
(tester) async {
final texture = _FakeRenderTexture();
final shared = _makeShared(texture);
addTearDown(shared.dispose);
await tester.pumpWidget(
RiveSurface(
sharedTexture: shared,
renderResolution: const RenderResolution.layout(scale: 0.5),
),
);
expect(
texture.lastWidgetResolution,
const RenderResolution.layout(scale: 0.5),
);
});
testWidgets('RiveSurface defaults to display', (tester) async {
final texture = _FakeRenderTexture();
final shared = _makeShared(texture);
addTearDown(shared.dispose);
await tester.pumpWidget(RiveSurface(sharedTexture: shared));
expect(
texture.lastWidgetResolution,
const RenderResolution.display(),
);
});
});
}