-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathrtmppublisher_test.dart
116 lines (92 loc) · 2.97 KB
/
rtmppublisher_test.dart
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
// Copyright 2019 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 'package:camera_with_rtmp/new/camera.dart';
import 'package:camera_with_rtmp/new/src/camera_testing.dart';
import 'package:camera_with_rtmp/new/src/common/native_texture.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('Camera', () {
final List<MethodCall> log = <MethodCall>[];
setUpAll(() {
CameraTesting.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
log.add(methodCall);
switch (methodCall.method) {
case 'NativeTexture#allocate':
return 15;
}
throw ArgumentError.value(
methodCall.method,
'methodCall.method',
'No method found for',
);
});
});
setUp(() {
log.clear();
CameraTesting.nextHandle = 0;
});
group('$CameraController', () {
test('Initializing a second controller closes the first', () {
final MockCameraDescription description = MockCameraDescription();
final MockCameraConfigurator configurator = MockCameraConfigurator();
final CameraController controller1 =
CameraController.customConfigurator(
description: description,
configurator: configurator,
);
controller1.initialize();
final CameraController controller2 =
CameraController.customConfigurator(
description: description,
configurator: configurator,
);
controller2.initialize();
expect(
() => controller1.start(),
throwsA(isInstanceOf<AssertionError>()),
);
expect(
() => controller1.stop(),
throwsA(isInstanceOf<AssertionError>()),
);
expect(controller1.isDisposed, isTrue);
});
});
group('$NativeTexture', () {
test('allocate', () async {
final NativeTexture texture = await NativeTexture.allocate();
expect(texture.textureId, 15);
expect(log, <Matcher>[
isMethodCall(
'$NativeTexture#allocate',
arguments: <String, dynamic>{'textureHandle': 0},
)
]);
});
});
});
}
class MockCameraDescription extends CameraDescriptionNew {
@override
LensDirection get direction => LensDirection.unknown;
@override
String get name => 'none';
}
class MockCameraConfigurator extends CameraConfigurator {
@override
Future<int> addPreviewTexture() => Future<int>.value(7);
@override
Future<void> dispose() => Future<void>.value();
@override
Future<void> initialize() => Future<void>.value();
@override
int get previewTextureId => 7;
@override
Future<void> start() => Future<void>.value();
@override
Future<void> stop() => Future<void>.value();
}