42 lines
1.7 KiB
Dart
42 lines
1.7 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:jj_mkvmaker/core/file_attributes.dart';
|
|
import 'package:path/path.dart' as p;
|
|
|
|
/// P3 보충: 숨김 · 읽기 전용 · 만든 때 (Windows GetFileAttributesExW) - 시험 파일에만 attrib 로 속성을 켜고 끝에 끈다
|
|
void main() {
|
|
late Directory tmp;
|
|
setUp(() => tmp = Directory.systemTemp.createTempSync('jj_attrs_'));
|
|
tearDown(() async {
|
|
if (Platform.isWindows) await Process.run('attrib', ['-h', '-r', '-s', p.join(tmp.path, '*'), '/s', '/d']);
|
|
tmp.deleteSync(recursive: true);
|
|
});
|
|
|
|
test('보통 파일: 속성 없음 · 만든 때는 지금 즈음', () {
|
|
final f = File(p.join(tmp.path, 'a.txt'))..writeAsStringSync('a');
|
|
final a = readFileAttributes(f.path)!;
|
|
expect(a.labels, isEmpty);
|
|
if (Platform.isWindows) {
|
|
expect(a.created, isNotNull);
|
|
expect(DateTime.now().difference(a.created!).inMinutes.abs(), lessThan(5));
|
|
}
|
|
});
|
|
|
|
test('숨김 · 읽기 전용 (Windows attrib) · 폴더', () async {
|
|
final f = File(p.join(tmp.path, 'b.txt'))..writeAsStringSync('b');
|
|
final d = Directory(p.join(tmp.path, 'd'))..createSync();
|
|
if (!Platform.isWindows) {
|
|
expect(readFileAttributes(p.join(tmp.path, '.hidden'))!.hidden, isTrue);
|
|
return;
|
|
}
|
|
await Process.run('attrib', ['+h', '+r', f.path]);
|
|
await Process.run('attrib', ['+h', d.path]);
|
|
final a = readFileAttributes(f.path)!;
|
|
expect((a.hidden, a.readOnly, a.system), (true, true, false));
|
|
expect(a.labels, ['숨김', '읽기 전용']);
|
|
expect(readFileAttributes(d.path)!.hidden, isTrue);
|
|
expect(readFileAttributes(p.join(tmp.path, '없음')), isNull);
|
|
});
|
|
}
|