Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
172 lines
5.3 KiB
Dart
172 lines
5.3 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_sdk/editor.dart';
|
|
import 'package:cutdex_sdk/project.dart';
|
|
import 'package:cutdex_sdk/runtime.dart';
|
|
import 'package:cutdex_sdk/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,
|
|
);
|
|
},
|
|
);
|
|
}
|