43 lines
2.0 KiB
Dart
43 lines
2.0 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:crypto/crypto.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:jj_mkvmaker/core/remote_thumbs.dart';
|
|
import 'package:jj_mkvmaker/core/thumb_cache.dart';
|
|
import 'package:path/path.dart' as p;
|
|
|
|
/// 관리자 지시 (10/21, 28 지적): 보관함에 넣은 파일의 썸네일 캐시 (탐색기 동영상 · 빠른 보기 큰 것 · 원격) 와 메모리 기억을 지운다
|
|
void main() {
|
|
late Directory tmp;
|
|
setUp(() => tmp = Directory.systemTemp.createTempSync('jj_thumbcache_'));
|
|
tearDown(() => tmp.deleteSync(recursive: true));
|
|
|
|
test('그 경로 · 크기 · 바뀐 때의 캐시만 지움 (작은 것 · |640 · 원격) · 다른 파일 것은 그대로 · 메모리 기억도 잊음', () async {
|
|
final when = DateTime(2026, 10, 21, 14, 5);
|
|
File cache(String dir, String key) => File(p.join(tmp.path, dir, '${md5.convert(utf8.encode(key))}.jpg'));
|
|
const path = r'C:\사진\비밀.mp4';
|
|
final mine = [
|
|
cache('jj_thumbs', '$path|500|${when.millisecondsSinceEpoch}'),
|
|
cache('jj_thumbs', '$path|500|${when.millisecondsSinceEpoch}|640'),
|
|
cache('jj_rthumbs', '$path|500|${when.millisecondsSinceEpoch}'),
|
|
];
|
|
final other = cache('jj_thumbs', r'C:\사진\다른.mp4|500|' '${when.millisecondsSinceEpoch}');
|
|
for (final f in [...mine, other]) {
|
|
f
|
|
..createSync(recursive: true)
|
|
..writeAsBytesSync([1, 2, 3]);
|
|
}
|
|
// 원격 썸네일의 키 꼴과 같은지 (같은 이름으로 찾을 수 있어야 함)
|
|
expect(RemoteThumbs.keyOf(path, 500, when), thumbCacheKeys(path, 500, when).first);
|
|
final forgot = <String>[];
|
|
void hook(String x) => forgot.add(x);
|
|
thumbMemoryForgetters.add(hook);
|
|
addTearDown(() => thumbMemoryForgetters.remove(hook));
|
|
expect(await removeThumbCaches(tmp.path, path, 500, when), 3);
|
|
expect(mine.where((f) => f.existsSync()), isEmpty);
|
|
expect(other.existsSync(), isTrue);
|
|
expect(forgot, [path]);
|
|
});
|
|
}
|