team-ljyzipelo

공개
1,030줄36 KB
1use super::*;
2use std::{
3 collections::BTreeSet,
4 fs,
5 sync::atomic::{AtomicU64, Ordering},
6};
7use zipelo_ui_memory_app::archive_present::*;
8
9fn terminal() -> Terminal {
10 Terminal {
11 outcome: Outcome::Failed,
12 error: Some(ErrorCode::Io),
13 publication: Publication::Partial,
14 created_count: 1,
15 retained_partial_count: 0,
16 durability: Durability::Synced,
17 cleanup: Cleanup::Complete,
18 }
19}
20fn targets() -> BTreeSet<String> {
21 ["one.txt".into(), "two.txt".into()].into_iter().collect()
22}
23
24#[test]
25fn partial_extraction_requires_matching_file_reports() {
26 let t = terminal();
27 assert_eq!(
28 warnings(
29 Some(&t),
30 true,
31 Some(&targets()),
32 &BTreeSet::new(),
33 &[("one.txt".into(), Disposition::Created)]
34 ),
35 vec![PARTIAL]
36 );
37}
38#[test]
39fn all_saved_with_temporary_leftover_is_not_partial_extraction() {
40 let mut t = terminal();
41 t.retained_partial_count = 1;
42 t.cleanup = Cleanup::Failed;
43 let files = ["one.txt".into()].into_iter().collect();
44 assert_eq!(
45 warnings(
46 Some(&t),
47 true,
48 Some(&files),
49 &BTreeSet::new(),
50 &[
51 ("one.txt".into(), Disposition::Created),
52 ("temp".into(), Disposition::PartialRetained)
53 ]
54 ),
55 vec![LEFTOVERS]
56 );
57}
58#[test]
59fn leftover_without_file_reports_and_commit_uncertainty_are_unknown() {
60 let mut t = terminal();
61 t.created_count = 0;
62 t.retained_partial_count = 1;
63 for outputs in [
64 vec![("temp".into(), Disposition::PartialRetained)],
65 vec![("one.txt".into(), Disposition::CommitUncertain)],
66 ] {
67 assert!(
68 warnings(Some(&t), true, Some(&targets()), &BTreeSet::new(), &outputs)
69 .contains(&UNCERTAIN)
70 );
71 assert!(
72 !warnings(Some(&t), true, Some(&targets()), &BTreeSet::new(), &outputs)
73 .contains(&PARTIAL)
74 );
75 }
76}
77#[test]
78fn synchronization_and_cleanup_warnings_are_both_visible() {
79 let mut t = terminal();
80 t.created_count = 0;
81 t.durability = Durability::Unconfirmed;
82 t.cleanup = Cleanup::Failed;
83 let result = warnings(Some(&t), true, Some(&targets()), &BTreeSet::new(), &[]);
84 assert!(result.contains(&SYNC_WARNING));
85 assert!(result.contains(&CLEANUP_WARNING));
86}
87#[test]
88fn missing_terminal_exit_or_contradictory_reports_never_claim_unsaved() {
89 let mut t = terminal();
90 t.publication = Publication::None;
91 t.created_count = 0;
92 assert!(definitely_unsaved(Some(&t), true, &[]));
93 assert!(!definitely_unsaved(None, true, &[]));
94 assert!(!definitely_unsaved(Some(&t), false, &[]));
95 let reports = [("one.txt".into(), Disposition::Created)];
96 assert!(!definitely_unsaved(Some(&t), true, &reports));
97 assert!(
98 warnings(Some(&t), true, Some(&targets()), &BTreeSet::new(), &reports).contains(&UNCERTAIN)
99 );
100}
101#[test]
102fn unsafe_path_and_conflict_preserve_result_classification() {
103 for code in [ErrorCode::UnsafePath, ErrorCode::Conflict] {
104 let mut t = terminal();
105 t.error = Some(code);
106 assert_eq!(
107 warnings(
108 Some(&t),
109 true,
110 Some(&targets()),
111 &BTreeSet::new(),
112 &[("one.txt".into(), Disposition::Created)]
113 ),
114 vec![PARTIAL]
115 );
116 t.publication = Publication::Uncertain;
117 assert!(
118 warnings(Some(&t), true, Some(&targets()), &BTreeSet::new(), &[]).contains(&UNCERTAIN)
119 );
120 t.publication = Publication::None;
121 t.created_count = 0;
122 assert!(definitely_unsaved(Some(&t), true, &[]));
123 }
124}
125#[test]
126fn every_error_and_stage_has_user_facing_text() {
127 for code in [
128 ErrorCode::Integrity,
129 ErrorCode::UnsupportedFormat,
130 ErrorCode::UnsupportedFeature,
131 ErrorCode::WrongPassword,
132 ErrorCode::UnsafePath,
133 ErrorCode::Conflict,
134 ErrorCode::Limit,
135 ErrorCode::Io,
136 ErrorCode::DiskFull,
137 ErrorCode::Protocol,
138 ErrorCode::Internal,
139 ErrorCode::SourceChanged,
140 ErrorCode::InvalidRequest,
141 ] {
142 assert!(!error_text(code).is_empty());
143 assert!(!error_text(code).contains("작업자"));
144 }
145 assert_eq!(error_text(ErrorCode::Protocol), INTERNAL);
146 assert_eq!(error_text(ErrorCode::Internal), INTERNAL);
147 assert_eq!(progress_text(Stage::Decode, true), "압축하는 중");
148 assert_eq!(progress_text(Stage::Decode, false), "압축을 푸는 중");
149}
150#[test]
151fn file_targets_follow_requested_ids_without_expanding_directories() {
152 let entries = vec![
153 Entry {
154 id: 0,
155 name: "docs".into(),
156 kind: Kind::Directory,
157 bytes: None,
158 packed: None,
159 encrypted: false,
160 },
161 Entry {
162 id: 1,
163 name: "docs/one.txt".into(),
164 kind: Kind::File,
165 bytes: None,
166 packed: None,
167 encrypted: false,
168 },
169 Entry {
170 id: 2,
171 name: "docs-old/two.txt".into(),
172 kind: Kind::File,
173 bytes: None,
174 packed: None,
175 encrypted: false,
176 },
177 ];
178 assert_eq!(
179 target_files(&entries, &Selection::EntryIds(vec![0]), None),
180 Some(BTreeSet::new())
181 );
182 assert_eq!(
183 target_files(&entries, &Selection::EntryIds(vec![0, 2]), None),
184 Some(["docs-old/two.txt".into()].into_iter().collect())
185 );
186 assert_eq!(
187 target_files(&entries, &Selection::EntryIds(vec![1]), None),
188 Some(["docs/one.txt".into()].into_iter().collect())
189 );
190 assert_eq!(
191 target_files(&entries, &Selection::All, None),
192 Some(
193 ["docs/one.txt".into(), "docs-old/two.txt".into()]
194 .into_iter()
195 .collect()
196 )
197 );
198}
199
200#[test]
201fn directory_reports_allow_empty_and_mixed_archives_without_hiding_unknown_outputs() {
202 let directories = ["parent".into(), "parent/empty".into()]
203 .into_iter()
204 .collect();
205 let empty = BTreeSet::new();
206 let mut t = terminal();
207 t.outcome = Outcome::Completed;
208 t.error = None;
209 t.publication = Publication::Complete;
210 t.created_count = 2;
211 let reports = [
212 ("parent".into(), Disposition::Created),
213 ("parent/empty".into(), Disposition::Created),
214 ];
215 assert!(warnings(Some(&t), true, Some(&empty), &directories, &reports).is_empty());
216 t.created_count = 0;
217 assert!(warnings(Some(&t), true, Some(&empty), &directories, &[]).is_empty());
218 let files = ["parent/file.txt".into()].into_iter().collect();
219 t.created_count = 2;
220 let reports = [
221 ("parent".into(), Disposition::Created),
222 ("parent/file.txt".into(), Disposition::Created),
223 ];
224 assert!(warnings(Some(&t), true, Some(&files), &directories, &reports).is_empty());
225 t.created_count = 1;
226 assert!(
227 warnings(
228 Some(&t),
229 true,
230 Some(&files),
231 &directories,
232 &[("parent".into(), Disposition::Created)]
233 )
234 .contains(&UNCERTAIN)
235 );
236 assert!(
237 warnings(
238 Some(&t),
239 true,
240 Some(&empty),
241 &directories,
242 &[("unknown".into(), Disposition::Created)]
243 )
244 .contains(&UNCERTAIN)
245 );
246 t.publication = Publication::Uncertain;
247 assert!(
248 warnings(
249 Some(&t),
250 true,
251 Some(&empty),
252 &directories,
253 &[("parent".into(), Disposition::CommitUncertain)]
254 )
255 .contains(&UNCERTAIN)
256 );
257}
258
259#[test]
260fn directory_targets_include_selected_members_and_implicit_parents() {
261 let entries = [
262 Entry {
263 id: 0,
264 name: "top".into(),
265 kind: Kind::Directory,
266 bytes: None,
267 packed: None,
268 encrypted: false,
269 },
270 Entry {
271 id: 1,
272 name: "top/empty".into(),
273 kind: Kind::Directory,
274 bytes: None,
275 packed: None,
276 encrypted: false,
277 },
278 Entry {
279 id: 2,
280 name: "top/nested/file.txt".into(),
281 kind: Kind::File,
282 bytes: None,
283 packed: None,
284 encrypted: false,
285 },
286 Entry {
287 id: 3,
288 name: "other/empty".into(),
289 kind: Kind::Directory,
290 bytes: None,
291 packed: None,
292 encrypted: false,
293 },
294 ];
295 assert_eq!(
296 target_directories(&entries, &Selection::EntryIds(vec![0])),
297 ["top".into()].into_iter().collect()
298 );
299 assert_eq!(
300 target_directories(&entries, &Selection::EntryIds(vec![2])),
301 ["top".into(), "top/nested".into()].into_iter().collect()
302 );
303}
304
305#[test]
306fn duplicate_names_prevent_file_completion_assumptions() {
307 let entry = Entry {
308 id: 0,
309 name: "same.txt".into(),
310 kind: Kind::File,
311 bytes: None,
312 packed: None,
313 encrypted: false,
314 };
315 assert!(target_files(&[entry.clone(), entry], &Selection::All, None).is_none());
316 assert_eq!(
317 warnings(Some(&terminal()), true, None, &BTreeSet::new(), &[]),
318 vec![UNCERTAIN]
319 );
320}
321#[test]
322fn default_names_and_middle_truncation_preserve_unicode() {
323 for name in [
324 "자료.tar.gz",
325 "자료.tar.bz2",
326 "자료.TAR.BZ2",
327 "자료.TaR.xZ",
328 "자료.tar.xz",
329 ] {
330 assert_eq!(default_destination(&path(name)), path("자료"));
331 }
332 for name in [".tar.bz2", ".TAR.XZ"] {
333 assert_eq!(default_destination(&path(name)), path("압축 해제"));
334 }
335 assert_eq!(default_destination(&path("자료.zip")), path("자료"));
336 assert_eq!(middle_text("가나다라마바사아자차", 7), "가나다…아자차");
337 assert_eq!(bytes_text(21), "21 B");
338}
339
340static SCRATCH_ID: AtomicU64 = AtomicU64::new(0);
341pub(super) struct Folder(pub(super) PathBuf);
342impl Folder {
343 pub(super) fn new() -> Self {
344 let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../tests/rust-app-ui/runs");
345 fs::create_dir_all(&root).unwrap();
346 let path = root.join(format!(
347 "presentation-{}-{}",
348 std::process::id(),
349 SCRATCH_ID.fetch_add(1, Ordering::Relaxed)
350 ));
351 fs::create_dir(&path).unwrap();
352 Self(path.canonicalize().unwrap())
353 }
354}
355impl Drop for Folder {
356 fn drop(&mut self) {
357 fs::remove_dir_all(&self.0).unwrap();
358 }
359}
360
361#[test]
362fn automatic_destination_creation_and_failure_are_distinct() {
363 let scratch = Folder::new();
364 let output = scratch.0.join("output");
365 assert!(prepare_destination(&output, true).unwrap());
366 assert!(!prepare_destination(&output, true).unwrap());
367 assert!(prepare_destination(&scratch.0.join("missing/child"), true).is_err());
368 assert!(prepare_destination(&scratch.0.join("chosen-missing"), false).is_err());
369 let file = scratch.0.join("file");
370 fs::write(&file, "existing").unwrap();
371 assert!(prepare_destination(&file, true).is_err());
372 assert_eq!(fs::read_to_string(file).unwrap(), "existing");
373}
374#[test]
375fn only_new_empty_output_is_removed_and_nonempty_is_preserved() {
376 let scratch = Folder::new();
377 let empty = scratch.0.join("empty");
378 assert!(prepare_destination(&empty, true).unwrap());
379 remove_owned_empty(&empty);
380 assert!(!empty.exists());
381 let nonempty = scratch.0.join("nonempty");
382 assert!(prepare_destination(&nonempty, true).unwrap());
383 fs::write(nonempty.join("existing"), "keep").unwrap();
384 remove_owned_empty(&nonempty);
385 assert_eq!(
386 fs::read_to_string(nonempty.join("existing")).unwrap(),
387 "keep"
388 );
389 assert!(!prepare_destination(&scratch.0, false).unwrap());
390 assert!(scratch.0.is_dir());
391}
392#[cfg(unix)]
393#[test]
394fn browser_and_output_do_not_follow_symbolic_links() {
395 let scratch = Folder::new();
396 let link = scratch.0.join("link");
397 std::os::unix::fs::symlink(&scratch.0, &link).unwrap();
398 let rows = directory_entries(&scratch.0).unwrap();
399 assert!(rows.iter().any(|entry| entry.link && entry.path == link));
400 assert!(directory_entries(&link).is_err());
401 assert!(prepare_destination(&link, true).is_err());
402}
403
404#[cfg(feature = "ui")]
405mod widgets {
406 use super::*;
407 use crate::dialogs::TestDialogs;
408 use eframe::egui::{self, epaint::Shape};
409 use zipelo_ui_memory_app::{archive_dialog::Purpose, archive_screen::ArchiveApp};
410
411 fn labels(shapes: &[egui::epaint::ClippedShape]) -> Vec<(String, egui::Pos2)> {
412 fn walk(shape: &Shape, result: &mut Vec<(String, egui::Pos2)>) {
413 match shape {
414 Shape::Text(text) => result.push((
415 text.galley.job.text.clone(),
416 text.pos + text.galley.rect.size() / 2.0,
417 )),
418 Shape::Vec(shapes) => {
419 for shape in shapes {
420 walk(shape, result);
421 }
422 }
423 _ => {}
424 }
425 }
426 let mut result = Vec::new();
427 for shape in shapes {
428 walk(&shape.shape, &mut result);
429 }
430 result
431 }
432
433 fn render(
434 ctx: &egui::Context,
435 app: &mut ArchiveApp,
436 events: Vec<egui::Event>,
437 ) -> Vec<(String, egui::Pos2)> {
438 let mut output = ctx.run_ui(
439 egui::RawInput {
440 screen_rect: Some(egui::Rect::from_min_size(
441 egui::Pos2::ZERO,
442 egui::vec2(760.0, 540.0),
443 )),
444 events,
445 ..Default::default()
446 },
447 |ui| app.show(ui),
448 );
449 output.textures_delta.clear();
450 labels(&output.shapes)
451 }
452
453 fn click(ctx: &egui::Context, app: &mut ArchiveApp, label: &str) {
454 render(ctx, app, vec![]);
455 let point = render(ctx, app, vec![])
456 .into_iter()
457 .filter(|(text, _)| text == label)
458 .max_by(|a, b| a.1.y.total_cmp(&b.1.y))
459 .unwrap_or_else(|| panic!("항목 없음: {label}"))
460 .1;
461 for pressed in [true, false] {
462 render(
463 ctx,
464 app,
465 vec![
466 egui::Event::PointerMoved(point),
467 egui::Event::PointerButton {
468 pos: point,
469 button: egui::PointerButton::Primary,
470 pressed,
471 modifiers: egui::Modifiers::NONE,
472 },
473 ],
474 );
475 }
476 }
477
478 fn key(key: egui::Key) -> egui::Event {
479 egui::Event::Key {
480 key,
481 physical_key: None,
482 pressed: true,
483 repeat: false,
484 modifiers: egui::Modifiers::NONE,
485 }
486 }
487
488 fn text(ctx: &egui::Context, app: &mut ArchiveApp, id: &str, value: &str) {
489 ctx.memory_mut(|memory| memory.request_focus(egui::Id::unique(id)));
490 render(
491 ctx,
492 app,
493 vec![
494 egui::Event::Key {
495 key: egui::Key::A,
496 physical_key: None,
497 pressed: true,
498 repeat: false,
499 modifiers: egui::Modifiers::COMMAND,
500 },
501 egui::Event::Text(value.into()),
502 ],
503 );
504 }
505
506 fn loaded(scratch: &Folder, factory: &FakeFactory) -> ArchiveApp {
507 let mut app = ArchiveApp::new(
508 Box::new(factory.clone()),
509 Some(scratch.0.join("sample.zip")),
510 false,
511 );
512 pump(&mut app.model);
513 app.set_dialogs(Box::new(TestDialogs::default()));
514 app
515 }
516
517 fn policy_render(
518 ctx: &egui::Context,
519 app: &mut ArchiveApp,
520 events: Vec<egui::Event>,
521 ) -> Vec<(String, egui::Pos2)> {
522 let mut output = ctx.run_ui(
523 egui::RawInput {
524 screen_rect: Some(egui::Rect::from_min_size(
525 egui::Pos2::ZERO,
526 egui::vec2(1060.0, 720.0),
527 )),
528 events,
529 ..Default::default()
530 },
531 |ui| app.show(ui),
532 );
533 output.textures_delta.clear();
534 labels(&output.shapes)
535 }
536
537 fn policy_focus(ctx: &egui::Context, app: &mut ArchiveApp, label: &str) {
538 policy_render(ctx, app, vec![]);
539 for _ in 0..100 {
540 let shown = policy_render(ctx, app, vec![]);
541 let point = shown
542 .iter()
543 .rev()
544 .find(|(text, _)| text == label)
545 .unwrap_or_else(|| panic!("표시 없음: {label}"))
546 .1;
547 if ctx
548 .memory(|memory| memory.focused())
549 .and_then(|id| ctx.read_response(id))
550 .is_some_and(|response| response.rect.contains(point))
551 {
552 return;
553 }
554 policy_render(ctx, app, vec![key(egui::Key::Tab)]);
555 let mut released = key(egui::Key::Tab);
556 if let egui::Event::Key { pressed, .. } = &mut released {
557 *pressed = false;
558 }
559 policy_render(ctx, app, vec![released]);
560 }
561 panic!("키보드 초점 없음: {label}");
562 }
563
564 fn policy_click(ctx: &egui::Context, app: &mut ArchiveApp, label: &str) {
565 policy_render(ctx, app, vec![]);
566 let point = policy_render(ctx, app, vec![])
567 .iter()
568 .rev()
569 .find(|(text, _)| text == label)
570 .unwrap()
571 .1;
572 for pressed in [true, false] {
573 policy_render(
574 ctx,
575 app,
576 vec![
577 egui::Event::PointerMoved(point),
578 egui::Event::PointerButton {
579 pos: point,
580 button: egui::PointerButton::Primary,
581 pressed,
582 modifiers: egui::Modifiers::NONE,
583 },
584 ],
585 );
586 }
587 }
588
589 #[test]
590 fn destination_failure_sends_no_request_and_explains_folder_change() {
591 let scratch = Folder::new();
592 let factory = FakeFactory::default();
593 let mut app = loaded(&scratch, &factory);
594 let file = scratch.0.join("existing.txt");
595 fs::write(&file, "preserve").unwrap();
596 app.choose_destination(file.clone());
597 assert!(!app.begin_extract());
598 assert_eq!(factory.state.borrow().starts.len(), 1);
599 let ctx = egui::Context::default();
600 render(&ctx, &mut app, vec![]);
601 assert!(
602 render(&ctx, &mut app, vec![])
603 .iter()
604 .any(|(text, _)| text == FOLDER_ERROR)
605 );
606 assert_eq!(fs::read_to_string(file).unwrap(), "preserve");
607 }
608
609 #[test]
610 fn cancelling_removes_only_automatically_created_empty_folder() {
611 for case in ["automatic-empty", "automatic-nonempty", "chosen-empty"] {
612 let scratch = Folder::new();
613 let factory = FakeFactory::default();
614 let mut app = loaded(&scratch, &factory);
615 factory.state.borrow_mut().manual = true;
616 let destination = if case == "chosen-empty" {
617 let path = scratch.0.join("chosen");
618 fs::create_dir(&path).unwrap();
619 app.choose_destination(path.clone());
620 path
621 } else {
622 scratch.0.join("sample")
623 };
624 assert!(app.begin_extract());
625 if case == "automatic-nonempty" {
626 fs::write(destination.join("preserve"), "keep").unwrap();
627 }
628 {
629 let mut state = factory.state.borrow_mut();
630 state.frame(Event::Accepted { encryption: true });
631 state.finish(Outcome::Cancelled, Publication::None);
632 }
633 let ctx = egui::Context::default();
634 for _ in 0..30 {
635 render(&ctx, &mut app, vec![]);
636 }
637 assert!(!app.model.busy());
638 assert_eq!(destination.exists(), case != "automatic-empty");
639 }
640 }
641
642 #[test]
643 fn password_secondary_enter_does_not_submit_valid_input() {
644 for encrypt in [false, true] {
645 for label in ["보기", "숨기기", "취소"] {
646 let scratch = Folder::new();
647 let factory = FakeFactory::manual();
648 let mut app = ArchiveApp::new(Box::new(factory.clone()), None, false);
649 assert!(app.model.begin(
650 Start::CreateZip {
651 sources: vec![(scratch.0.join("source"), "source".into())],
652 output_file: scratch.0.join("output.zip"),
653 method: Method::Deflate,
654 aes256: true
655 },
656 &mut factory.clone()
657 ));
658 {
659 let mut worker = factory.state.borrow_mut();
660 worker.frame(Event::Accepted { encryption: true });
661 worker.frame(Event::PasswordRequired {
662 challenge_id: 17,
663 attempt: 1,
664 encrypt,
665 });
666 }
667 let ctx = egui::Context::default();
668 for _ in 0..12 {
669 policy_render(&ctx, &mut app, vec![]);
670 }
671 text(&ctx, &mut app, "archive-password-input", "fixture-secret");
672 if encrypt {
673 text(&ctx, &mut app, "archive-password-confirm", "fixture-secret");
674 }
675 if label == "숨기기" {
676 policy_click(&ctx, &mut app, "보기");
677 }
678 policy_focus(&ctx, &mut app, label);
679 policy_render(&ctx, &mut app, vec![key(egui::Key::Enter)]);
680 assert!(!factory.state.borrow().password_seen, "{label}");
681 assert_eq!(factory.state.borrow().starts.len(), 1);
682 }
683 }
684 }
685
686 #[test]
687 fn directory_only_extraction_displays_success() {
688 let scratch = Folder::new();
689 let factory = FakeFactory::default();
690 let mut app = loaded(&scratch, &factory);
691 app.model.entries = vec![Entry {
692 id: 0,
693 name: "empty".into(),
694 kind: Kind::Directory,
695 bytes: Some(0),
696 packed: None,
697 encrypted: false,
698 }];
699 factory.state.borrow_mut().manual = true;
700 assert!(app.begin_extract());
701 {
702 let mut worker = factory.state.borrow_mut();
703 worker.frame(Event::Accepted { encryption: false });
704 worker.frame(Event::Output {
705 entry_id: None,
706 relative_name: "empty".into(),
707 disposition: Disposition::Created,
708 });
709 worker.finish(Outcome::Completed, Publication::Complete);
710 }
711 let ctx = egui::Context::default();
712 for _ in 0..30 {
713 policy_render(&ctx, &mut app, vec![]);
714 }
715 let shown = policy_render(&ctx, &mut app, vec![]);
716 assert!(shown.iter().any(|(text, _)| text == "압축을 풀었습니다"));
717 assert!(!shown.iter().any(|(text, _)| text == UNCERTAIN));
718 }
719
720 #[test]
721 fn completed_results_keep_folder_action_and_distinguish_durability() {
722 for creating in [false, true] {
723 for durability in [
724 Durability::Synced,
725 Durability::Unconfirmed,
726 Durability::Failed,
727 ] {
728 let scratch = Folder::new();
729 let factory = FakeFactory::default();
730 let mut app = loaded(&scratch, &factory);
731 factory.state.borrow_mut().manual = true;
732 let ctx = egui::Context::default();
733 let name = if creating {
734 let source = scratch.0.join("source.txt");
735 fs::write(&source, b"source").unwrap();
736 app.add_sources(vec![source]);
737 policy_render(&ctx, &mut app, vec![]);
738 policy_click(&ctx, &mut app, "압축하기");
739 match factory.state.borrow().starts.last().unwrap() {
740 Start::CreateZip { output_file, .. } => output_file
741 .file_name()
742 .unwrap()
743 .to_str()
744 .unwrap()
745 .to_owned(),
746 _ => panic!("생성 요청 누락"),
747 }
748 } else {
749 assert!(app.begin_extract());
750 "읽어주세요.txt".to_owned()
751 };
752 {
753 let mut worker = factory.state.borrow_mut();
754 worker.frame(Event::Accepted { encryption: false });
755 worker.frame(Event::Output {
756 entry_id: None,
757 relative_name: name,
758 disposition: Disposition::Created,
759 });
760 worker.finish(Outcome::Completed, Publication::Complete);
761 for event in &mut worker.queue {
762 if let HostEvent::Frame {
763 event: Event::Terminal(terminal),
764 ..
765 } = event
766 {
767 terminal.durability = durability;
768 }
769 }
770 }
771 for _ in 0..30 {
772 policy_render(&ctx, &mut app, vec![]);
773 }
774 let shown = policy_render(&ctx, &mut app, vec![]);
775 let title = if creating {
776 "ZIP 파일을 만들었습니다"
777 } else {
778 "압축을 풀었습니다"
779 };
780 assert!(
781 shown.iter().any(|(text, _)| text == title),
782 "{durability:?}: {shown:?}"
783 );
784 assert!(shown.iter().any(|(text, _)| text == "폴더 열기"));
785 assert!(!shown.iter().any(|(text, _)| text == "다시 시도"));
786 assert!(!shown.iter().any(|(text, _)| text == SYNC_WARNING));
787 let sync_failed = if creating {
788 "파일을 디스크에 완전히 저장하지 못했습니다. 저장 위치 폴더를 확인하세요."
789 } else {
790 "파일을 디스크에 완전히 저장하지 못했습니다. 풀 위치 폴더를 확인하세요."
791 };
792 assert_eq!(
793 shown.iter().any(|(text, _)| text == sync_failed),
794 durability == Durability::Failed
795 );
796 policy_click(&ctx, &mut app, "자세히 보기");
797 let details = policy_render(&ctx, &mut app, vec![]);
798 assert_eq!(
799 details.iter().any(|(text, _)| text == SYNC_WARNING),
800 durability == Durability::Unconfirmed
801 );
802 policy_click(&ctx, &mut app, "자세히 닫기");
803 let closed = policy_render(&ctx, &mut app, vec![]);
804 assert!(!closed.iter().any(|(text, _)| text == SYNC_WARNING));
805 assert_eq!(
806 closed.iter().any(|(text, _)| text == sync_failed),
807 durability == Durability::Failed
808 );
809 assert!(closed.iter().any(|(text, _)| text == "폴더 열기"));
810 }
811 }
812 }
813
814 #[test]
815 fn durability_warning_visibility_matches_completed_failed_and_partial_results() {
816 for (outcome, publication, saved, expected_files) in [
817 (Outcome::Completed, Publication::Complete, 1, 1),
818 (Outcome::Failed, Publication::None, 0, 1),
819 (Outcome::Failed, Publication::Partial, 1, 2),
820 ] {
821 for durability in [
822 Durability::Synced,
823 Durability::Unconfirmed,
824 Durability::Failed,
825 ] {
826 let scratch = Folder::new();
827 let factory = FakeFactory::default();
828 let mut app = loaded(&scratch, &factory);
829 app.model.entries = (0..expected_files)
830 .map(|id| Entry {
831 id,
832 name: format!("{id}.txt"),
833 kind: Kind::File,
834 bytes: Some(1),
835 packed: None,
836 encrypted: false,
837 })
838 .collect();
839 factory.state.borrow_mut().manual = true;
840 assert!(app.begin_extract());
841 {
842 let mut worker = factory.state.borrow_mut();
843 worker.frame(Event::Accepted { encryption: false });
844 if saved > 0 {
845 worker.frame(Event::Output {
846 entry_id: Some(0),
847 relative_name: "0.txt".into(),
848 disposition: Disposition::Created,
849 });
850 }
851 worker.finish(outcome, publication);
852 for event in &mut worker.queue {
853 if let HostEvent::Frame {
854 event: Event::Terminal(terminal),
855 ..
856 } = event
857 {
858 terminal.created_count = saved;
859 terminal.durability = durability;
860 terminal.error = (outcome == Outcome::Failed).then_some(ErrorCode::Io);
861 }
862 }
863 }
864 let ctx = egui::Context::default();
865 for _ in 0..30 {
866 policy_render(&ctx, &mut app, vec![]);
867 }
868 let completed = outcome == Outcome::Completed;
869 let shown = policy_render(&ctx, &mut app, vec![]);
870 let warning = match durability {
871 Durability::Unconfirmed => Some(SYNC_WARNING),
872 Durability::Failed => Some(
873 "파일을 디스크에 완전히 저장하지 못했습니다. 풀 위치 폴더를 확인하세요.",
874 ),
875 _ => None,
876 };
877 let visible =
878 warning.is_some() && !(completed && durability == Durability::Unconfirmed);
879 assert_eq!(
880 shown.iter().any(|(text, _)| Some(text.as_str()) == warning),
881 visible,
882 "{outcome:?}/{publication:?}: {shown:?}"
883 );
884 assert_eq!(shown.iter().any(|(text, _)| text == "폴더 열기"), completed);
885 assert_eq!(
886 shown.iter().any(|(text, _)| text == "압축을 풀었습니다"),
887 completed
888 );
889 assert_eq!(
890 shown
891 .iter()
892 .any(|(text, _)| text == "압축을 풀지 못했습니다"),
893 !completed
894 );
895 assert_eq!(
896 shown.iter().any(|(text, _)| text == PARTIAL),
897 publication == Publication::Partial
898 );
899 policy_click(&ctx, &mut app, "자세히 보기");
900 let details = policy_render(&ctx, &mut app, vec![]);
901 assert_eq!(
902 details
903 .iter()
904 .filter(|(text, _)| Some(text.as_str()) == warning)
905 .count(),
906 usize::from(warning.is_some()),
907 "{outcome:?}/{publication:?}: {details:?}"
908 );
909 policy_click(&ctx, &mut app, "자세히 닫기");
910 let closed = policy_render(&ctx, &mut app, vec![]);
911 assert_eq!(
912 closed
913 .iter()
914 .any(|(text, _)| Some(text.as_str()) == warning),
915 visible
916 );
917 }
918 }
919 }
920 include!("toolbar.rs");
921 include!("long_layout.rs");
922 include!("explorer_selection.rs");
923 include!("window_frame.rs");
924 include!("work_window.rs");
925 include!("create_window.rs");
926}
927
928#[cfg(feature = "ui")]
929#[test]
930fn create_dialog_keeps_title_and_actions_visible_after_resize() {
931 use eframe::egui::{self, epaint::Shape};
932 use zipelo_ui_memory_app::archive_screen::ArchiveApp;
933 let scratch = Folder::new();
934 let mut app = ArchiveApp::new(Box::new(FakeFactory::default()), None, false);
935 fs::write(scratch.0.join("one.txt"), b"fixture").unwrap();
936 fs::create_dir(scratch.0.join("photos")).unwrap();
937 app.add_sources(vec![scratch.0.join("one.txt"), scratch.0.join("photos")]);
938 let ctx = egui::Context::default();
939 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
940 let mut texts = Vec::new();
941 for _ in 0..8 {
942 let mut output = ctx.run_ui(
943 egui::RawInput {
944 screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)),
945 ..Default::default()
946 },
947 |ui| app.show(ui),
948 );
949 output.textures_delta.clear();
950 fn walk(shape: &Shape, output: &mut Vec<(String, egui::Pos2)>) {
951 match shape {
952 Shape::Text(text) => output.push((
953 text.galley.job.text.clone(),
954 text.pos + text.galley.rect.size() / 2.0,
955 )),
956 Shape::Vec(shapes) => {
957 for shape in shapes {
958 walk(shape, output);
959 }
960 }
961 _ => {}
962 }
963 }
964 texts.clear();
965 for shape in &output.shapes {
966 walk(&shape.shape, &mut texts);
967 }
968 }
969 for label in ["ZIP 만들기", "압축하기", "취소"] {
970 let positions = texts
971 .iter()
972 .filter(|(text, _)| text == label)
973 .map(|(_, p)| p)
974 .collect::<Vec<_>>();
975 assert!(!positions.is_empty(), "{label}");
976 assert!(
977 positions.iter().all(|p| p.y >= 0.0 && p.y <= size.y),
978 "{label}: {positions:?}"
979 );
980 }
981 }
982}
983#[test]
984fn folder_open_command_preserves_shell_characters_as_one_argument() {
985 let path = path("한글 폴더 ; $(touch unexpected)");
986 let command = folder_command(&path);
987 assert_eq!(
988 command.get_program(),
989 if cfg!(windows) {
990 "explorer"
991 } else {
992 "xdg-open"
993 }
994 );
995 assert_eq!(
996 command.get_args().collect::<Vec<_>>(),
997 vec![path.as_os_str()]
998 );
999}
1000
1001#[test]
1002fn late_cancel_and_terminal_wait_use_finishing_text() {
1003 let mut model = Model::default();
1004 model.progress = Some((Stage::Decode, 1, Some(2), 0));
1005 assert_eq!(activity_text(&model, false), "압축을 푸는 중");
1006 model.cancel = Some(CancelStatus::Requested);
1007 assert_eq!(activity_text(&model, false), "취소하는 중...");
1008 for state in [CancelStatus::TooLate, CancelStatus::Finished] {
1009 model.cancel = Some(state);
1010 assert_eq!(activity_text(&model, false), "마무리하는 중");
1011 }
1012 model.cancel = Some(CancelStatus::Requested);
1013 model.terminal = Some(terminal());
1014 assert_eq!(activity_text(&model, false), "마무리하는 중");
1015}
1016#[test]
1017fn client_protocol_errors_hide_internal_terms_but_preserve_exit_uncertainty() {
1018 for error in [
1019 "작업 ID 한도에 도달했습니다",
1020 "작업자 응답 순서나 작업 ID가 일치하지 않습니다",
1021 "작업 승인 응답이 없습니다",
1022 "출력 보고 한도 초과",
1023 ] {
1024 assert_eq!(client_error_text(error), INTERNAL);
1025 }
1026 assert_eq!(
1027 client_error_text("작업자 종료 결과를 확인할 수 없습니다. 출력 상태를 확인하세요"),
1028 UNCONFIRMED_FINISH
1029 );
1030}