54 lines
2.7 KiB
Dart
54 lines
2.7 KiB
Dart
// ai_local_engine.dart 약속 시험: 실제 프로세스 (Windows cmd.exe) 와 실제 PNG 로 입력 · 출력 · 오류를 본다.
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:image/image.dart' as img;
|
|
import 'package:jj_mkvmaker/app/ai_local_engine.dart';
|
|
import 'package:jj_mkvmaker/services/image_ai.dart';
|
|
|
|
void main() {
|
|
final cmd = Platform.environment['ComSpec'] ?? r'C:\Windows\System32\cmd.exe';
|
|
|
|
test('runSdCli: 저장했다고 하면 0 이 아닌 코드여도 성공 · 마지막 줄들을 돌려준다', () async {
|
|
if (!Platform.isWindows) return markTestSkipped('Windows 전용 (cmd.exe)');
|
|
// "images saved" 줄은 진행 (저장 단계) 으로 읽혀 마지막 줄들에는 들지 않는다
|
|
final tail = await runSdCli(cmd, ['/c', 'echo first&& echo 2 images saved&& exit 1']);
|
|
expect(tail, contains('first'));
|
|
});
|
|
|
|
test('runSdCli: 저장 없이 0 이 아닌 코드 → 쉬운 말 · 원문은 detail', () async {
|
|
if (!Platform.isWindows) return markTestSkipped('Windows 전용 (cmd.exe)');
|
|
await expectLater(
|
|
runSdCli(cmd, ['/c', 'echo [E] boom&& exit 3']),
|
|
throwsA(isA<ImageAiException>()
|
|
.having((e) => e.message, 'message', sdExitMessage(3))
|
|
.having((e) => e.detail, 'detail', contains('[E] boom'))));
|
|
});
|
|
|
|
test('runSdCli: 치명 줄이 있으면 0 으로 끝나도 실패 · onStart 로 프로세스를 넘긴다', () async {
|
|
if (!Platform.isWindows) return markTestSkipped('Windows 전용 (cmd.exe)');
|
|
Process? started;
|
|
await expectLater(runSdCli(cmd, ['/c', 'echo new_sd_ctx_t failed'], onStart: (p) => started = p),
|
|
throwsA(isA<ImageAiException>().having((e) => e.detail, 'detail', contains('new_sd_ctx_t failed'))));
|
|
expect(started, isNotNull);
|
|
});
|
|
|
|
test('sizeMatches · isSdFatalLine · sdCliLibName · sdExitMessage', () {
|
|
final png = img.encodePng(img.Image(width: 7, height: 5));
|
|
expect(sizeMatches(png, 7, 5), isTrue);
|
|
expect(sizeMatches(png, 5, 7), isFalse);
|
|
expect(isSdFatalLine('[E] Upscale Failed'), isTrue);
|
|
expect(isSdFatalLine('[I] sampling completed'), isFalse);
|
|
expect(sdCliLibName('Features : fp asimd fphp asimddp\nFeatures : fp asimd fphp asimddp'), 'libsdcli.so');
|
|
expect(sdCliLibName('Features : fp asimd fphp asimddp\nFeatures : fp asimd'), 'libsdcli_v80.so');
|
|
expect(sdCliLibName(''), 'libsdcli_v80.so');
|
|
expect(sdExitMessage(-4), contains('CPU'));
|
|
expect(sdExitMessage(7), contains('7'));
|
|
});
|
|
|
|
test('SdDevice.key = 실행 파일 폴더 이름:backend', () {
|
|
expect(SdDevice(['', 'ai', 'engine-vulkan', 'sd-cli.exe'].join(Platform.pathSeparator), 'vulkan0', 'GPU').key,
|
|
'engine-vulkan:vulkan0');
|
|
});
|
|
}
|