Gitea CI / Check code and tests (pull_request) Failing after 8s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 1s
172 lines
5.4 KiB
Dart
172 lines
5.4 KiB
Dart
import 'package:cutdex/errors/app_failure.dart';
|
|
|
|
import '../support/creation_names.dart';
|
|
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:cutdex/workspace/persistence/project_workspace.dart';
|
|
import 'package:cutdex_core/editor.dart';
|
|
import 'package:cutdex_core/project.dart';
|
|
import 'package:cutdex_native_flutter/cutdex_native_flutter.dart';
|
|
import 'package:cutdex_core/timeline/model.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
const channel = MethodChannel('prepared-workspace-test');
|
|
late Directory directory;
|
|
late ProjectWorkspace workspace;
|
|
late String projectId;
|
|
late Map<String, Object?> response;
|
|
var probes = 0;
|
|
setUp(() async {
|
|
probes = 0;
|
|
response = {
|
|
'duration': {'numerator': '64737467444', 'denominator': 10000000},
|
|
'videoTrackCount': 1,
|
|
'audioTrackCount': 1,
|
|
'videoTrackIds': [0],
|
|
'audioTrackIds': [1],
|
|
'audioTracks': [
|
|
{
|
|
'start': {'numerator': '1', 'denominator': 3},
|
|
'duration': {'numerator': '2', 'denominator': 3},
|
|
},
|
|
],
|
|
'isProtected': false,
|
|
};
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(channel, (call) async {
|
|
if (call.method == 'request') {
|
|
final request = jsonDecode(
|
|
(call.arguments as Map)['request'] as String,
|
|
);
|
|
expect(request['method'], 'probe');
|
|
} else {
|
|
expect(call.method, 'probe');
|
|
}
|
|
probes++;
|
|
return call.method == 'request'
|
|
? jsonEncode({'value': response})
|
|
: response;
|
|
});
|
|
directory = await Directory.systemTemp.createTemp('cutdex-prepared-media-');
|
|
workspace = ProjectWorkspace(
|
|
creationNames: testCreationNames,
|
|
runtime: CutdexRuntime(channel: channel),
|
|
);
|
|
await workspace.open(
|
|
'${directory.path}/Test.cutdex',
|
|
name: 'Prepared media',
|
|
);
|
|
projectId = workspace.project!.info.id;
|
|
final source = await File('${directory.path}/source.mpg').writeAsBytes([0]);
|
|
await workspace.project!.saveAsset(
|
|
AssetDocument(
|
|
id: 'media',
|
|
name: 'Source',
|
|
storage: AssetStorage.external,
|
|
location: source.uri.toString(),
|
|
),
|
|
);
|
|
});
|
|
tearDown(() async {
|
|
await workspace.close();
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(channel, null);
|
|
await directory.delete(recursive: true);
|
|
});
|
|
|
|
test(
|
|
'ordinary insertion keeps the same MPG duration and original audio timing',
|
|
() async {
|
|
final prepared = await workspace.prepareMedia(projectId, 'media');
|
|
expect(TimelineClock.standard.toTicks(prepared.duration), 9135751405697);
|
|
expect(prepared.kind, EditorMediaKind.video);
|
|
expect(prepared.hasAudio, isTrue);
|
|
expect(prepared.audioTracks.single.start.toMap(), {
|
|
'numerator': '1',
|
|
'denominator': 3,
|
|
});
|
|
expect(prepared.audioTracks.single.duration.toMap(), {
|
|
'numerator': '2',
|
|
'denominator': 3,
|
|
});
|
|
expect(probes, 1);
|
|
expect(await File('${directory.path}/source.mpg').readAsBytes(), [0]);
|
|
},
|
|
);
|
|
|
|
test('ordinary audio-only insertion uses the validated audio kind', () async {
|
|
response = {...response, 'videoTrackCount': 0, 'videoTrackIds': <int>[]};
|
|
final prepared = await workspace.prepareMedia(projectId, 'media');
|
|
expect(prepared.kind, EditorMediaKind.audio);
|
|
expect(prepared.hasAudio, isTrue);
|
|
expect(prepared.audioTracks, hasLength(1));
|
|
});
|
|
|
|
test(
|
|
'ordinary image insertion keeps five seconds without native probing',
|
|
() async {
|
|
final asset = (await workspace.project!.listAssets()).single;
|
|
await workspace.project!.saveAsset(
|
|
AssetDocument(
|
|
id: asset.id,
|
|
name: asset.name,
|
|
storage: asset.storage,
|
|
location: asset.location,
|
|
metadata: {'kind': 'image'},
|
|
),
|
|
);
|
|
final prepared = await workspace.prepareMedia(projectId, 'media');
|
|
expect(prepared.kind, EditorMediaKind.image);
|
|
expect(prepared.duration, RationalTime.seconds(5));
|
|
expect(prepared.hasAudio, isFalse);
|
|
expect(prepared.audioTracks, isEmpty);
|
|
expect(probes, 0);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'ordinary insertion rejects overflowing duration with the shared error',
|
|
() async {
|
|
response = {
|
|
...response,
|
|
'duration': {'numerator': '9223372036854775807', 'denominator': 1},
|
|
};
|
|
await expectLater(
|
|
workspace.prepareMedia(projectId, 'media'),
|
|
throwsA(
|
|
isA<AppException>().having(
|
|
(error) => error.failure.code,
|
|
'code',
|
|
AppErrorCode.mediaDurationOutOfRange,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'ordinary insertion rejects sub-tick duration and protected media',
|
|
() async {
|
|
final original = response;
|
|
response = {
|
|
...original,
|
|
'duration': {'numerator': '1', 'denominator': 0xffffffff},
|
|
};
|
|
await expectLater(
|
|
workspace.prepareMedia(projectId, 'media'),
|
|
throwsStateError,
|
|
);
|
|
response = {...original, 'isProtected': true};
|
|
await expectLater(
|
|
workspace.prepareMedia(projectId, 'media'),
|
|
throwsStateError,
|
|
);
|
|
},
|
|
);
|
|
}
|