team-ljyzipelo

공개
659줄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-sevenzip" => "7z는 암호를 지원하지 않습니다",
144 "create-sevenzip-progress" => "파일을 저장하는 중",
145 "create-sevenzip-complete" => "7z 파일을 만들었습니다",
146 "create-sevenzip-error" => "7z 파일을 만들지 못했습니다",
147 "create-sevenzip-cancelled" => "작업을 취소했습니다",
148 "create-sevenzip-resource" => "큰 작업을 허용할까요?",
149 "create-error" => "ZIP 파일을 만들지 못했습니다",
150 "password-create" => "암호 확인",
151 "folder" => "바다.jpg",
152 "search-empty" => "일치하는 항목이 없습니다",
153 "password" | "password-retry" => "암호",
154 "extract-complete" => "압축을 풀었습니다",
155 "extract-cancelled" => "작업을 취소했습니다",
156 "create-complete" => "ZIP 파일을 만들었습니다",
157 "create" | "create-encrypted" => "암호로 보호하기",
158 "unsupported" | "damaged" => "압축파일을 열지 못했습니다",
159 "conflict" => "압축을 풀지 못했습니다",
160 "close-confirm" => "닫",
161 _ => "읽어주세요.txt",
162 };
163 assert!(labels.contains(expected), "{}: {labels}", scenario.name);
164 if scenario.name == "extract-rename-failed" {
165 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
166 assert!(!labels.contains("이름 바꿔 저장:"), "{labels}");
167 }
168 if matches!(scenario.name, "tar-bz2" | "tar-xz") {
169 assert!(app.model.entries.iter().all(|entry| !entry.encrypted));
170 assert_eq!(
171 app.model.list_id.as_ref().unwrap().format,
172 zipelo_ui_memory_app::archive_ui::Format::Tar
173 );
174 }
175 if scenario.name == "many-items" {
176 assert_eq!(app.model.entries.len(), 505);
177 }
178 if matches!(scenario.name, "selection" | "marquee") {
179 assert_eq!(app.model.selected.len(), 4);
180 assert!(labels.contains("선택 2개"));
181 }
182 if scenario.name == "password-retry" {
183 assert_eq!(app.model.challenge.unwrap().1, 2);
184 }
185 }
186 }
187}
188
189#[test]
190fn command_line_catalog_and_errors_work_without_a_display() {
191 let run = |args: &[&str]| {
192 std::process::Command::new(env!("CARGO_BIN_EXE_zipelo-ui-memory-app"))
193 .args(args)
194 .env_remove("DISPLAY")
195 .env_remove("WAYLAND_DISPLAY")
196 .output()
197 .unwrap()
198 };
199 let listed = run(&["--list-ui-scenarios"]);
200 assert!(listed.status.success());
201 assert_eq!(
202 String::from_utf8(listed.stdout).unwrap(),
203 scenarios::listing()
204 );
205 for args in [vec!["--ui-scenario", "unknown"], vec!["--ui-scenario"]] {
206 let failed = run(&args);
207 assert!(!failed.status.success());
208 let stderr = String::from_utf8_lossy(&failed.stderr);
209 for scenario in SCENARIOS {
210 assert!(stderr.contains(scenario.name));
211 }
212 }
213}
214
215#[test]
216fn preview_ignores_password_submission() {
217 let ctx = egui::Context::default();
218 let mut preview = scenarios::Preview::new(scenarios::parse("password").unwrap().build(), &ctx);
219 for _ in 0..3 {
220 let mut output = ctx.run_ui(
221 egui::RawInput {
222 screen_rect: Some(egui::Rect::from_min_size(
223 egui::Pos2::ZERO,
224 egui::vec2(1060.0, 720.0),
225 )),
226 events: vec![
227 egui::Event::Text("화면 검토".into()),
228 egui::Event::Key {
229 key: egui::Key::Enter,
230 physical_key: None,
231 pressed: true,
232 repeat: false,
233 modifiers: egui::Modifiers::NONE,
234 },
235 ],
236 ..Default::default()
237 },
238 |ui| preview.0.show(ui),
239 );
240 output.textures_delta.clear();
241 }
242 assert_eq!(preview.0.model.challenge, Some((17, 1, false)));
243 assert!(preview.0.model.busy());
244}
245
246#[test]
247fn uninstall_previews_match_packaged_notices_and_do_not_start_jobs() {
248 let installer = include_str!("../../packaging/windows/rust/installer.nsi");
249 let prerm = include_str!("../../packaging/ubuntu/rust/prerm");
250 let helper = include_str!("../../packaging/ubuntu/rust/default-apps");
251 for (name, source, expected) in [
252 (
253 "uninstall-windows",
254 installer,
255 "직접 고른 기본 앱은 자동으로 바꾸지 않습니다.",
256 ),
257 (
258 "uninstall-settings-error",
259 installer,
260 "Windows 설정을 열지 못했습니다.",
261 ),
262 (
263 "uninstall-ubuntu-missing",
264 helper,
265 "이전 앱을 복원할 수 없습니다:",
266 ),
267 (
268 "uninstall-ubuntu-unknown-user",
269 prerm,
270 "제거를 요청한 사용자를 확인할 수 없어 사용자 기본 앱 설정은 변경하지 않습니다.",
271 ),
272 ] {
273 assert!(source.contains(expected));
274 let scenario = scenarios::parse(name).unwrap();
275 let ctx = egui::Context::default();
276 let mut preview = scenarios::Preview::new(scenario.build(), &ctx).with_scenario(scenario);
277 let mut output = ctx.run_ui(
278 egui::RawInput {
279 screen_rect: Some(egui::Rect::from_min_size(
280 egui::Pos2::ZERO,
281 egui::vec2(760.0, 540.0),
282 )),
283 events: vec![egui::Event::Key {
284 key: egui::Key::Enter,
285 physical_key: None,
286 pressed: true,
287 repeat: false,
288 modifiers: egui::Modifiers::NONE,
289 }],
290 ..Default::default()
291 },
292 |ui| preview.show(ui),
293 );
294 assert!(text(&output.shapes).contains(expected), "{name}");
295 assert!(!preview.0.model.busy());
296 assert!(preview.0.model.archive.is_none());
297 assert!(output.platform_output.commands.is_empty());
298 output.textures_delta.clear();
299 }
300}
301
302fn result_labels(
303 app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp,
304 size: egui::Vec2,
305) -> String {
306 let ctx = egui::Context::default();
307 let mut labels = String::new();
308 for _ in 0..3 {
309 let mut output = ctx.run_ui(
310 egui::RawInput {
311 screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)),
312 ..Default::default()
313 },
314 |ui| app.show(ui),
315 );
316 labels = text(&output.shapes);
317 output.textures_delta.clear();
318 }
319 labels
320}
321
322#[test]
323fn rename_without_created_output_never_claims_saved_name() {
324 use zipelo_ui_memory_app::archive_ui::*;
325 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
326 for disposition in [
327 None,
328 Some(Disposition::PartialRetained),
329 Some(Disposition::Removed),
330 Some(Disposition::CommitUncertain),
331 ] {
332 let mut app = scenarios::parse("extract-renamed").unwrap().build();
333 app.model.outputs = disposition
334 .into_iter()
335 .map(|d| ("읽어주세요 (1).txt".into(), d))
336 .collect();
337 app.model.terminal = Some(Terminal {
338 outcome: Outcome::Failed,
339 error: Some(ErrorCode::Io),
340 publication: if disposition.is_none() {
341 Publication::None
342 } else {
343 Publication::Uncertain
344 },
345 created_count: 0,
346 retained_partial_count: 0,
347 durability: Durability::NotApplicable,
348 cleanup: Cleanup::Complete,
349 });
350 let labels = result_labels(&mut app, size);
351 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
352 if disposition.is_none() {
353 assert!(labels.contains("아무 파일도 풀지 않았습니다"), "{labels}");
354 }
355 assert!(
356 !labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"),
357 "{labels}"
358 );
359 }
360 }
361}
362
363#[test]
364fn rename_saved_before_later_failure_remains_reported() {
365 use zipelo_ui_memory_app::archive_ui::*;
366 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
367 let mut app = scenarios::parse("extract-renamed").unwrap().build();
368 app.model.resolutions.push(Resolution {
369 entry_id: 2,
370 relative_name: "여행 일정 (1).pdf".into(),
371 choice: ConflictChoice::Rename,
372 });
373 app.model.terminal.as_mut().unwrap().outcome = Outcome::Failed;
374 app.model.terminal.as_mut().unwrap().error = Some(ErrorCode::Io);
375 app.model.terminal.as_mut().unwrap().publication = Publication::Partial;
376 let labels = result_labels(&mut app, size);
377 assert!(
378 labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"),
379 "{labels}"
380 );
381 assert!(
382 !labels.contains("이름 바꿔 저장: 여행 일정 (1).pdf"),
383 "{labels}"
384 );
385 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
386 }
387}
388
389fn resource_frame(
390 app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp,
391 ctx: &egui::Context,
392 events: Vec<egui::Event>,
393) -> Vec<egui::epaint::ClippedShape> {
394 let mut out = ctx.run_ui(
395 egui::RawInput {
396 screen_rect: Some(egui::Rect::from_min_size(
397 egui::Pos2::ZERO,
398 egui::vec2(760.0, 540.0),
399 )),
400 events,
401 ..Default::default()
402 },
403 |ui| app.show(ui),
404 );
405 out.textures_delta.clear();
406 out.shapes
407}
408fn find_resource_action(shapes: &[egui::epaint::ClippedShape], label: &str) -> egui::Pos2 {
409 fn find(s: &egui::Shape, label: &str) -> Option<egui::Pos2> {
410 match s {
411 egui::Shape::Text(t) if t.galley.text() == label => {
412 Some(t.pos + t.galley.rect.size() / 2.0)
413 }
414 egui::Shape::Vec(shapes) => shapes.iter().find_map(|s| find(s, label)),
415 _ => None,
416 }
417 }
418 shapes.iter().find_map(|s| find(&s.shape, label)).unwrap()
419}
420#[test]
421fn resource_dialog_requires_explicit_click_and_escape_cancels() {
422 for allow in [false, true] {
423 let ctx = egui::Context::default();
424 let mut app = scenarios::parse("resource-ratio").unwrap().build();
425 let mut shapes = Vec::new();
426 for _ in 0..3 {
427 shapes = resource_frame(&mut app, &ctx, vec![]);
428 }
429 assert!(text(&shapes).contains("미확인"));
430 resource_frame(
431 &mut app,
432 &ctx,
433 vec![egui::Event::Key {
434 key: egui::Key::Enter,
435 physical_key: None,
436 pressed: true,
437 repeat: false,
438 modifiers: Default::default(),
439 }],
440 );
441 assert!(app.model.resource.is_some());
442 if allow {
443 let point = find_resource_action(&shapes, "이 작업 허용");
444 resource_frame(
445 &mut app,
446 &ctx,
447 vec![
448 egui::Event::PointerMoved(point),
449 egui::Event::PointerButton {
450 pos: point,
451 button: egui::PointerButton::Primary,
452 pressed: true,
453 modifiers: Default::default(),
454 },
455 ],
456 );
457 resource_frame(
458 &mut app,
459 &ctx,
460 vec![egui::Event::PointerButton {
461 pos: point,
462 button: egui::PointerButton::Primary,
463 pressed: false,
464 modifiers: Default::default(),
465 }],
466 );
467 assert!(!app.model.cancellation_requested());
468 } else {
469 resource_frame(
470 &mut app,
471 &ctx,
472 vec![egui::Event::Key {
473 key: egui::Key::Escape,
474 physical_key: None,
475 pressed: true,
476 repeat: false,
477 modifiers: Default::default(),
478 }],
479 );
480 assert!(app.model.cancellation_requested());
481 }
482 assert!(app.model.resource.is_none());
483 }
484}
485#[test]
486fn partial_limit_result_never_offers_expanded_retry() {
487 let ctx = egui::Context::default();
488 let mut app = scenarios::parse("resource-partial").unwrap().build();
489 let mut shapes = Vec::new();
490 for _ in 0..3 {
491 shapes = resource_frame(&mut app, &ctx, vec![]);
492 }
493 assert!(!text(&shapes).contains("한도를 늘려 다시 시도"));
494 assert!(text(&shapes).contains("풀린 자료"));
495}
496
497#[test]
498fn preview_escape_discards_content_and_returns_to_list_without_changing_selection() {
499 for name in ["preview-text", "preview-image", "preview-loading"] {
500 let ctx = egui::Context::default();
501 let mut app = scenarios::parse(name).unwrap().build();
502 let selected = app.model.selected.clone();
503 for _ in 0..3 {
504 resource_frame(&mut app, &ctx, vec![]);
505 }
506 assert!(text(&resource_frame(&mut app, &ctx, vec![])).contains("미리보기"));
507 resource_frame(
508 &mut app,
509 &ctx,
510 vec![egui::Event::Key {
511 key: egui::Key::Escape,
512 physical_key: None,
513 pressed: true,
514 repeat: false,
515 modifiers: Default::default(),
516 }],
517 );
518 for _ in 0..3 {
519 resource_frame(&mut app, &ctx, vec![]);
520 }
521 assert!(app.model.preview.is_none());
522 assert_eq!(app.model.selected, selected);
523 if name == "preview-loading" {
524 assert!(app.model.cancellation_requested());
525 } else {
526 assert_eq!(
527 ctx.memory(|m| m.focused()),
528 Some(egui::Id::unique("archive-list"))
529 );
530 }
531 }
532}
533
534#[test]
535fn preview_image_respects_renderer_texture_limit() {
536 let ctx = egui::Context::default();
537 let mut app = scenarios::parse("preview-image").unwrap().build();
538 app.model.preview = Some(zipelo_ui_memory_app::archive_ui::Preview {
539 info: zipelo_ui_memory_app::archive_ui::PreviewInfo {
540 entry_id: 1,
541 format: zipelo_ui_memory_app::archive_ui::PreviewFormat::Rgba8,
542 width: 2048,
543 height: 1,
544 total_bytes: 8192,
545 },
546 data: vec![255; 8192],
547 });
548 let mut image_seen = false;
549 for _ in 0..3 {
550 let mut result = ctx.run_ui(
551 egui::RawInput {
552 max_texture_side: Some(1024),
553 screen_rect: Some(egui::Rect::from_min_size(
554 egui::Pos2::ZERO,
555 egui::vec2(760.0, 540.0),
556 )),
557 ..Default::default()
558 },
559 |ui| app.show(ui),
560 );
561 for (id, delta) in &result.textures_delta.set {
562 if *id == egui::TextureId::Managed(0) {
563 continue;
564 }
565 for image in delta {
566 assert!(image.image.size().iter().all(|n| *n <= 1024));
567 }
568 image_seen = true;
569 }
570 result.textures_delta.clear();
571 }
572 assert!(image_seen);
573}
574
575#[test]
576fn split_errors_use_main_modal_without_native_child() {
577 for name in [
578 "split-first-volume",
579 "split-missing-volume",
580 "split-incomplete",
581 "split-unsupported",
582 ] {
583 let scenario = scenarios::parse(name).unwrap();
584 let mut app = scenario.build();
585 let ctx = egui::Context::default();
586 ctx.set_embed_viewports(false);
587 let mut labels = String::new();
588 for _ in 0..3 {
589 let mut output = ctx.run_ui(
590 egui::RawInput {
591 screen_rect: Some(egui::Rect::from_min_size(
592 egui::Pos2::ZERO,
593 egui::vec2(1060.0, 720.0),
594 )),
595 ..Default::default()
596 },
597 |ui| scenario.show(&mut app, ui),
598 );
599 labels = text(&output.shapes);
600 output.textures_delta.clear();
601 assert!(
602 output
603 .viewport_output
604 .keys()
605 .all(|id| *id == egui::ViewportId::ROOT),
606 "{name}"
607 );
608 }
609 assert!(labels.contains("작업 결과"), "{name}: {labels}");
610 }
611}
612
613#[test]
614fn excluded_split_errors_show_support_guidance_in_main_modal() {
615 use zipelo_ui_memory_app::archive_ui::ErrorCode;
616
617 for code in [ErrorCode::UnsupportedFeature, ErrorCode::UnsupportedFormat] {
618 for archive in ["sample.zip.001", "sample.z01", "sample.rar", "sample.7z"] {
619 let scenario = scenarios::parse("split-unsupported").unwrap();
620 let mut app = scenario.build();
621 let ctx = egui::Context::default();
622 ctx.set_embed_viewports(false);
623 let input = || egui::RawInput {
624 screen_rect: Some(egui::Rect::from_min_size(
625 egui::Pos2::ZERO,
626 egui::vec2(1060.0, 720.0),
627 )),
628 ..Default::default()
629 };
630 for _ in 0..3 {
631 let mut output = ctx.run_ui(input(), |ui| scenario.show(&mut app, ui));
632 output.textures_delta.clear();
633 }
634 assert_eq!(
635 app.model.terminal.as_ref().unwrap().error,
636 Some(ErrorCode::UnsupportedFeature)
637 );
638 app.model.terminal.as_mut().unwrap().error = Some(code);
639 app.model.archive = Some(archive.into());
640 let mut output = ctx.run_ui(input(), |ui| scenario.show(&mut app, ui));
641 let labels = text(&output.shapes);
642 output.textures_delta.clear();
643 if archive == "sample.7z" {
644 assert!(!labels.contains("분할 ZIP과 RAR"));
645 } else {
646 assert!(
647 labels.contains("분할 ZIP과 RAR"),
648 "{code:?} {archive}: {labels}"
649 );
650 assert!(
651 output
652 .viewport_output
653 .keys()
654 .all(|id| *id == egui::ViewportId::ROOT)
655 );
656 }
657 }
658 }
659}