team-ljyzipelo

공개
653줄25 KB
1#![cfg(debug_assertions)]
2
3use eframe::egui;
4use std::{collections::BTreeSet, ffi::OsString};
5use zipelo_ui_memory_app::archive_screen::scenarios::{self, Launch, SCENARIOS};
6
7#[test]
8fn every_name_round_trips_and_listing_has_no_duplicates() {
9 let names: BTreeSet<_> = SCENARIOS.iter().map(|s| s.name).collect();
10 assert_eq!(names.len(), SCENARIOS.len());
11 for scenario in SCENARIOS {
12 assert_eq!(scenarios::parse(scenario.name), Ok(*scenario));
13 assert!(scenarios::listing().contains(scenario.description));
14 assert!(
15 include_str!("../../docs/ui-scenario-guide.md")
16 .contains(&format!("- {}:", scenario.name))
17 );
18 assert_eq!(
19 scenarios::launch(vec!["--ui-scenario".into(), scenario.name.into()]),
20 Ok(Launch::Scenario(*scenario)),
21 );
22 }
23 assert_eq!(
24 scenarios::launch(vec!["--list-ui-scenarios".into()]),
25 Ok(Launch::List)
26 );
27}
28
29#[test]
30fn unknown_missing_and_conflicting_arguments_are_rejected_with_catalog() {
31 for args in [
32 vec!["--ui-scenario", "missing"],
33 vec!["--ui-scenario"],
34 vec!["--ui-scenario", "archive", "file.zip"],
35 vec!["--list-ui-scenarios", "file.zip"],
36 vec!["--ui-fixture", "--ui-scenario", "archive"],
37 ] {
38 let error = scenarios::launch(args.into_iter().map(OsString::from).collect()).unwrap_err();
39 for scenario in SCENARIOS {
40 assert!(error.contains(scenario.name));
41 }
42 }
43 let original = vec![OsString::from("압축 자료.zip")];
44 assert_eq!(
45 scenarios::launch(original.clone()),
46 Ok(Launch::Normal(original))
47 );
48}
49
50fn text(shapes: &[egui::epaint::ClippedShape]) -> String {
51 fn collect(shape: &egui::Shape, result: &mut String) {
52 match shape {
53 egui::Shape::Text(t) => {
54 result.push_str(t.galley.text());
55 result.push('\n');
56 }
57 egui::Shape::Vec(shapes) => {
58 for shape in shapes {
59 collect(shape, result);
60 }
61 }
62 _ => {}
63 }
64 }
65 let mut result = String::new();
66 for shape in shapes {
67 collect(&shape.shape, &mut result);
68 }
69 result
70}
71
72#[test]
73fn every_listed_scenario_draws_and_keeps_its_expected_screen() {
74 for scenario in SCENARIOS {
75 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
76 let ctx = egui::Context::default();
77 let mut app = scenario.build();
78 let mut labels = String::new();
79 for _ in 0..3 {
80 let mut output = ctx.run_ui(
81 egui::RawInput {
82 screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)),
83 ..Default::default()
84 },
85 |ui| scenario.show(&mut app, ui),
86 );
87 assert!(!output.shapes.is_empty(), "{}", scenario.name);
88 labels = text(&output.shapes);
89 output.textures_delta.clear();
90 }
91 assert!(
92 app.model.error.is_none(),
93 "{}: {:?}",
94 scenario.name,
95 app.model.error
96 );
97 assert!(app.model.input_error.is_none(), "{}", scenario.name);
98 if scenario.name == "split-archive" {
99 assert!(app.model.list_id.as_ref().unwrap().is_split());
100 assert!(!app.model.can_preview());
101 }
102 let expected = match scenario.name {
103 "split-archive" => "읽어주세요.txt",
104 "split-first-volume" => "첫 조각 여행.7z.001을 선택해 다시 여세요.",
105 "split-missing-volume" => "여행.7z.003 조각이 없습니다",
106 "split-incomplete" => "분할 묶음이 불완전하거나 손상됐습니다",
107 "split-unsupported" => "분할 ZIP과 RAR",
108 "split-source-changed" => "원본 파일이 바뀌었습니다",
109 "preview-implicit-folder" => "자료",
110 "preview-catalog-approval" | "preview-catalog-bytes-approval" => {
111 "큰 작업을 허용할까요?"
112 }
113 "preview-loading" => "미리보기를 불러오는 중입니다",
114 "preview-text" => "여행 준비 목록",
115 "preview-image" => "미리보기",
116 "preview-empty" => "빈 텍스트 파일입니다",
117 "preview-limit" => "미리보기 크기 또는 처리 한도를 초과했습니다",
118 "preview-damaged" => "파일이 손상됐거나 UTF-8 텍스트가 아닙니다",
119 "preview-unsupported" => "이 파일 형식은 미리보기를 지원하지 않습니다",
120 "resource-approval" => "큰 작업을 허용할까요?",
121 "resource-ratio" => "압축률이 매우 높습니다",
122 "resource-retry" => "한도를 늘려 다시 시도",
123 "resource-partial" => "저장 위치를 확인하세요",
124 "uninstall-windows" => "제거 전에 다른 앱을 선택하세요",
125 "uninstall-settings-error" => "Windows 설정을 열지 못했습니다",
126 "uninstall-ubuntu-missing" => "이전 앱을 복원할 수 없습니다",
127 "uninstall-ubuntu-unknown-user" => "사용자 기본 앱 설정은 변경하지 않습니다",
128 "conflict-choice" | "conflict-apply" | "gzip-conflict-choice" => {
129 "나머지 파일에도 같게 적용"
130 }
131 "extract-skipped" => "모든 파일을 건너뛰었습니다",
132 "extract-rename-failed" => "아무 파일도 풀지 않았습니다",
133 "extract-renamed" => "이름 바꿔 저장: 읽어주세요 (1).txt",
134 "empty" => "TAR.BZ2, TAR.XZ",
135 "tar-bz2" | "tar-xz" => "읽어주세요.txt",
136 "folder-empty" => "이 폴더는 비어 있습니다",
137 "dialog-error" => "파일 선택 창을 열 수 없습니다",
138 "extract-partial" => "일부 파일만 풀렸습니다",
139 "extract-uncertain" => "저장이 끝났는지 확인하지 못했습니다",
140 "extract-unsynced" => "파일을 디스크에 완전히 저장했는지 확인하지 못했습니다",
141 "source-changed" => "압축파일 다시 열기",
142 "gzip-conflict" => "다른 이름으로 저장",
143 "create-error" => "ZIP 파일을 만들지 못했습니다",
144 "password-create" => "암호 확인",
145 "folder" => "바다.jpg",
146 "search-empty" => "일치하는 항목이 없습니다",
147 "password" | "password-retry" => "암호",
148 "extract-complete" => "압축을 풀었습니다",
149 "extract-cancelled" => "작업을 취소했습니다",
150 "create-complete" => "ZIP 파일을 만들었습니다",
151 "create" | "create-encrypted" => "암호로 보호하기",
152 "unsupported" | "damaged" => "압축파일을 열지 못했습니다",
153 "conflict" => "압축을 풀지 못했습니다",
154 "close-confirm" => "닫",
155 _ => "읽어주세요.txt",
156 };
157 assert!(labels.contains(expected), "{}: {labels}", scenario.name);
158 if scenario.name == "extract-rename-failed" {
159 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
160 assert!(!labels.contains("이름 바꿔 저장:"), "{labels}");
161 }
162 if matches!(scenario.name, "tar-bz2" | "tar-xz") {
163 assert!(app.model.entries.iter().all(|entry| !entry.encrypted));
164 assert_eq!(
165 app.model.list_id.as_ref().unwrap().format,
166 zipelo_ui_memory_app::archive_ui::Format::Tar
167 );
168 }
169 if scenario.name == "many-items" {
170 assert_eq!(app.model.entries.len(), 505);
171 }
172 if matches!(scenario.name, "selection" | "marquee") {
173 assert_eq!(app.model.selected.len(), 4);
174 assert!(labels.contains("선택 2개"));
175 }
176 if scenario.name == "password-retry" {
177 assert_eq!(app.model.challenge.unwrap().1, 2);
178 }
179 }
180 }
181}
182
183#[test]
184fn command_line_catalog_and_errors_work_without_a_display() {
185 let run = |args: &[&str]| {
186 std::process::Command::new(env!("CARGO_BIN_EXE_zipelo-ui-memory-app"))
187 .args(args)
188 .env_remove("DISPLAY")
189 .env_remove("WAYLAND_DISPLAY")
190 .output()
191 .unwrap()
192 };
193 let listed = run(&["--list-ui-scenarios"]);
194 assert!(listed.status.success());
195 assert_eq!(
196 String::from_utf8(listed.stdout).unwrap(),
197 scenarios::listing()
198 );
199 for args in [vec!["--ui-scenario", "unknown"], vec!["--ui-scenario"]] {
200 let failed = run(&args);
201 assert!(!failed.status.success());
202 let stderr = String::from_utf8_lossy(&failed.stderr);
203 for scenario in SCENARIOS {
204 assert!(stderr.contains(scenario.name));
205 }
206 }
207}
208
209#[test]
210fn preview_ignores_password_submission() {
211 let ctx = egui::Context::default();
212 let mut preview = scenarios::Preview::new(scenarios::parse("password").unwrap().build(), &ctx);
213 for _ in 0..3 {
214 let mut output = ctx.run_ui(
215 egui::RawInput {
216 screen_rect: Some(egui::Rect::from_min_size(
217 egui::Pos2::ZERO,
218 egui::vec2(1060.0, 720.0),
219 )),
220 events: vec![
221 egui::Event::Text("화면 검토".into()),
222 egui::Event::Key {
223 key: egui::Key::Enter,
224 physical_key: None,
225 pressed: true,
226 repeat: false,
227 modifiers: egui::Modifiers::NONE,
228 },
229 ],
230 ..Default::default()
231 },
232 |ui| preview.0.show(ui),
233 );
234 output.textures_delta.clear();
235 }
236 assert_eq!(preview.0.model.challenge, Some((17, 1, false)));
237 assert!(preview.0.model.busy());
238}
239
240#[test]
241fn uninstall_previews_match_packaged_notices_and_do_not_start_jobs() {
242 let installer = include_str!("../../packaging/windows/rust/installer.nsi");
243 let prerm = include_str!("../../packaging/ubuntu/rust/prerm");
244 let helper = include_str!("../../packaging/ubuntu/rust/default-apps");
245 for (name, source, expected) in [
246 (
247 "uninstall-windows",
248 installer,
249 "직접 고른 기본 앱은 자동으로 바꾸지 않습니다.",
250 ),
251 (
252 "uninstall-settings-error",
253 installer,
254 "Windows 설정을 열지 못했습니다.",
255 ),
256 (
257 "uninstall-ubuntu-missing",
258 helper,
259 "이전 앱을 복원할 수 없습니다:",
260 ),
261 (
262 "uninstall-ubuntu-unknown-user",
263 prerm,
264 "제거를 요청한 사용자를 확인할 수 없어 사용자 기본 앱 설정은 변경하지 않습니다.",
265 ),
266 ] {
267 assert!(source.contains(expected));
268 let scenario = scenarios::parse(name).unwrap();
269 let ctx = egui::Context::default();
270 let mut preview = scenarios::Preview::new(scenario.build(), &ctx).with_scenario(scenario);
271 let mut output = ctx.run_ui(
272 egui::RawInput {
273 screen_rect: Some(egui::Rect::from_min_size(
274 egui::Pos2::ZERO,
275 egui::vec2(760.0, 540.0),
276 )),
277 events: vec![egui::Event::Key {
278 key: egui::Key::Enter,
279 physical_key: None,
280 pressed: true,
281 repeat: false,
282 modifiers: egui::Modifiers::NONE,
283 }],
284 ..Default::default()
285 },
286 |ui| preview.show(ui),
287 );
288 assert!(text(&output.shapes).contains(expected), "{name}");
289 assert!(!preview.0.model.busy());
290 assert!(preview.0.model.archive.is_none());
291 assert!(output.platform_output.commands.is_empty());
292 output.textures_delta.clear();
293 }
294}
295
296fn result_labels(
297 app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp,
298 size: egui::Vec2,
299) -> String {
300 let ctx = egui::Context::default();
301 let mut labels = String::new();
302 for _ in 0..3 {
303 let mut output = ctx.run_ui(
304 egui::RawInput {
305 screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)),
306 ..Default::default()
307 },
308 |ui| app.show(ui),
309 );
310 labels = text(&output.shapes);
311 output.textures_delta.clear();
312 }
313 labels
314}
315
316#[test]
317fn rename_without_created_output_never_claims_saved_name() {
318 use zipelo_ui_memory_app::archive_ui::*;
319 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
320 for disposition in [
321 None,
322 Some(Disposition::PartialRetained),
323 Some(Disposition::Removed),
324 Some(Disposition::CommitUncertain),
325 ] {
326 let mut app = scenarios::parse("extract-renamed").unwrap().build();
327 app.model.outputs = disposition
328 .into_iter()
329 .map(|d| ("읽어주세요 (1).txt".into(), d))
330 .collect();
331 app.model.terminal = Some(Terminal {
332 outcome: Outcome::Failed,
333 error: Some(ErrorCode::Io),
334 publication: if disposition.is_none() {
335 Publication::None
336 } else {
337 Publication::Uncertain
338 },
339 created_count: 0,
340 retained_partial_count: 0,
341 durability: Durability::NotApplicable,
342 cleanup: Cleanup::Complete,
343 });
344 let labels = result_labels(&mut app, size);
345 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
346 if disposition.is_none() {
347 assert!(labels.contains("아무 파일도 풀지 않았습니다"), "{labels}");
348 }
349 assert!(
350 !labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"),
351 "{labels}"
352 );
353 }
354 }
355}
356
357#[test]
358fn rename_saved_before_later_failure_remains_reported() {
359 use zipelo_ui_memory_app::archive_ui::*;
360 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
361 let mut app = scenarios::parse("extract-renamed").unwrap().build();
362 app.model.resolutions.push(Resolution {
363 entry_id: 2,
364 relative_name: "여행 일정 (1).pdf".into(),
365 choice: ConflictChoice::Rename,
366 });
367 app.model.terminal.as_mut().unwrap().outcome = Outcome::Failed;
368 app.model.terminal.as_mut().unwrap().error = Some(ErrorCode::Io);
369 app.model.terminal.as_mut().unwrap().publication = Publication::Partial;
370 let labels = result_labels(&mut app, size);
371 assert!(
372 labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"),
373 "{labels}"
374 );
375 assert!(
376 !labels.contains("이름 바꿔 저장: 여행 일정 (1).pdf"),
377 "{labels}"
378 );
379 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
380 }
381}
382
383fn resource_frame(
384 app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp,
385 ctx: &egui::Context,
386 events: Vec<egui::Event>,
387) -> Vec<egui::epaint::ClippedShape> {
388 let mut out = ctx.run_ui(
389 egui::RawInput {
390 screen_rect: Some(egui::Rect::from_min_size(
391 egui::Pos2::ZERO,
392 egui::vec2(760.0, 540.0),
393 )),
394 events,
395 ..Default::default()
396 },
397 |ui| app.show(ui),
398 );
399 out.textures_delta.clear();
400 out.shapes
401}
402fn find_resource_action(shapes: &[egui::epaint::ClippedShape], label: &str) -> egui::Pos2 {
403 fn find(s: &egui::Shape, label: &str) -> Option<egui::Pos2> {
404 match s {
405 egui::Shape::Text(t) if t.galley.text() == label => {
406 Some(t.pos + t.galley.rect.size() / 2.0)
407 }
408 egui::Shape::Vec(shapes) => shapes.iter().find_map(|s| find(s, label)),
409 _ => None,
410 }
411 }
412 shapes.iter().find_map(|s| find(&s.shape, label)).unwrap()
413}
414#[test]
415fn resource_dialog_requires_explicit_click_and_escape_cancels() {
416 for allow in [false, true] {
417 let ctx = egui::Context::default();
418 let mut app = scenarios::parse("resource-ratio").unwrap().build();
419 let mut shapes = Vec::new();
420 for _ in 0..3 {
421 shapes = resource_frame(&mut app, &ctx, vec![]);
422 }
423 assert!(text(&shapes).contains("미확인"));
424 resource_frame(
425 &mut app,
426 &ctx,
427 vec![egui::Event::Key {
428 key: egui::Key::Enter,
429 physical_key: None,
430 pressed: true,
431 repeat: false,
432 modifiers: Default::default(),
433 }],
434 );
435 assert!(app.model.resource.is_some());
436 if allow {
437 let point = find_resource_action(&shapes, "이 작업 허용");
438 resource_frame(
439 &mut app,
440 &ctx,
441 vec![
442 egui::Event::PointerMoved(point),
443 egui::Event::PointerButton {
444 pos: point,
445 button: egui::PointerButton::Primary,
446 pressed: true,
447 modifiers: Default::default(),
448 },
449 ],
450 );
451 resource_frame(
452 &mut app,
453 &ctx,
454 vec![egui::Event::PointerButton {
455 pos: point,
456 button: egui::PointerButton::Primary,
457 pressed: false,
458 modifiers: Default::default(),
459 }],
460 );
461 assert!(!app.model.cancellation_requested());
462 } else {
463 resource_frame(
464 &mut app,
465 &ctx,
466 vec![egui::Event::Key {
467 key: egui::Key::Escape,
468 physical_key: None,
469 pressed: true,
470 repeat: false,
471 modifiers: Default::default(),
472 }],
473 );
474 assert!(app.model.cancellation_requested());
475 }
476 assert!(app.model.resource.is_none());
477 }
478}
479#[test]
480fn partial_limit_result_never_offers_expanded_retry() {
481 let ctx = egui::Context::default();
482 let mut app = scenarios::parse("resource-partial").unwrap().build();
483 let mut shapes = Vec::new();
484 for _ in 0..3 {
485 shapes = resource_frame(&mut app, &ctx, vec![]);
486 }
487 assert!(!text(&shapes).contains("한도를 늘려 다시 시도"));
488 assert!(text(&shapes).contains("풀린 자료"));
489}
490
491#[test]
492fn preview_escape_discards_content_and_returns_to_list_without_changing_selection() {
493 for name in ["preview-text", "preview-image", "preview-loading"] {
494 let ctx = egui::Context::default();
495 let mut app = scenarios::parse(name).unwrap().build();
496 let selected = app.model.selected.clone();
497 for _ in 0..3 {
498 resource_frame(&mut app, &ctx, vec![]);
499 }
500 assert!(text(&resource_frame(&mut app, &ctx, vec![])).contains("미리보기"));
501 resource_frame(
502 &mut app,
503 &ctx,
504 vec![egui::Event::Key {
505 key: egui::Key::Escape,
506 physical_key: None,
507 pressed: true,
508 repeat: false,
509 modifiers: Default::default(),
510 }],
511 );
512 for _ in 0..3 {
513 resource_frame(&mut app, &ctx, vec![]);
514 }
515 assert!(app.model.preview.is_none());
516 assert_eq!(app.model.selected, selected);
517 if name == "preview-loading" {
518 assert!(app.model.cancellation_requested());
519 } else {
520 assert_eq!(
521 ctx.memory(|m| m.focused()),
522 Some(egui::Id::unique("archive-list"))
523 );
524 }
525 }
526}
527
528#[test]
529fn preview_image_respects_renderer_texture_limit() {
530 let ctx = egui::Context::default();
531 let mut app = scenarios::parse("preview-image").unwrap().build();
532 app.model.preview = Some(zipelo_ui_memory_app::archive_ui::Preview {
533 info: zipelo_ui_memory_app::archive_ui::PreviewInfo {
534 entry_id: 1,
535 format: zipelo_ui_memory_app::archive_ui::PreviewFormat::Rgba8,
536 width: 2048,
537 height: 1,
538 total_bytes: 8192,
539 },
540 data: vec![255; 8192],
541 });
542 let mut image_seen = false;
543 for _ in 0..3 {
544 let mut result = ctx.run_ui(
545 egui::RawInput {
546 max_texture_side: Some(1024),
547 screen_rect: Some(egui::Rect::from_min_size(
548 egui::Pos2::ZERO,
549 egui::vec2(760.0, 540.0),
550 )),
551 ..Default::default()
552 },
553 |ui| app.show(ui),
554 );
555 for (id, delta) in &result.textures_delta.set {
556 if *id == egui::TextureId::Managed(0) {
557 continue;
558 }
559 for image in delta {
560 assert!(image.image.size().iter().all(|n| *n <= 1024));
561 }
562 image_seen = true;
563 }
564 result.textures_delta.clear();
565 }
566 assert!(image_seen);
567}
568
569#[test]
570fn split_errors_use_main_modal_without_native_child() {
571 for name in [
572 "split-first-volume",
573 "split-missing-volume",
574 "split-incomplete",
575 "split-unsupported",
576 ] {
577 let scenario = scenarios::parse(name).unwrap();
578 let mut app = scenario.build();
579 let ctx = egui::Context::default();
580 ctx.set_embed_viewports(false);
581 let mut labels = String::new();
582 for _ in 0..3 {
583 let mut output = ctx.run_ui(
584 egui::RawInput {
585 screen_rect: Some(egui::Rect::from_min_size(
586 egui::Pos2::ZERO,
587 egui::vec2(1060.0, 720.0),
588 )),
589 ..Default::default()
590 },
591 |ui| scenario.show(&mut app, ui),
592 );
593 labels = text(&output.shapes);
594 output.textures_delta.clear();
595 assert!(
596 output
597 .viewport_output
598 .keys()
599 .all(|id| *id == egui::ViewportId::ROOT),
600 "{name}"
601 );
602 }
603 assert!(labels.contains("작업 결과"), "{name}: {labels}");
604 }
605}
606
607#[test]
608fn excluded_split_errors_show_support_guidance_in_main_modal() {
609 use zipelo_ui_memory_app::archive_ui::ErrorCode;
610
611 for code in [ErrorCode::UnsupportedFeature, ErrorCode::UnsupportedFormat] {
612 for archive in ["sample.zip.001", "sample.z01", "sample.rar", "sample.7z"] {
613 let scenario = scenarios::parse("split-unsupported").unwrap();
614 let mut app = scenario.build();
615 let ctx = egui::Context::default();
616 ctx.set_embed_viewports(false);
617 let input = || egui::RawInput {
618 screen_rect: Some(egui::Rect::from_min_size(
619 egui::Pos2::ZERO,
620 egui::vec2(1060.0, 720.0),
621 )),
622 ..Default::default()
623 };
624 for _ in 0..3 {
625 let mut output = ctx.run_ui(input(), |ui| scenario.show(&mut app, ui));
626 output.textures_delta.clear();
627 }
628 assert_eq!(
629 app.model.terminal.as_ref().unwrap().error,
630 Some(ErrorCode::UnsupportedFeature)
631 );
632 app.model.terminal.as_mut().unwrap().error = Some(code);
633 app.model.archive = Some(archive.into());
634 let mut output = ctx.run_ui(input(), |ui| scenario.show(&mut app, ui));
635 let labels = text(&output.shapes);
636 output.textures_delta.clear();
637 if archive == "sample.7z" {
638 assert!(!labels.contains("분할 ZIP과 RAR"));
639 } else {
640 assert!(
641 labels.contains("분할 ZIP과 RAR"),
642 "{code:?} {archive}: {labels}"
643 );
644 assert!(
645 output
646 .viewport_output
647 .keys()
648 .all(|id| *id == egui::ViewportId::ROOT)
649 );
650 }
651 }
652 }
653}