team-ljyzipelo

공개
553줄21 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 let expected = match scenario.name {
99 "preview-loading" => "미리보기를 불러오는 중입니다",
100 "preview-text" => "여행 준비 목록",
101 "preview-image" => "미리보기",
102 "preview-empty" => "빈 텍스트 파일입니다",
103 "preview-limit" => "미리보기 크기 또는 처리 한도를 초과했습니다",
104 "preview-damaged" => "파일이 손상됐거나 UTF-8 텍스트가 아닙니다",
105 "preview-unsupported" => "이 파일 형식은 미리보기를 지원하지 않습니다",
106 "resource-approval" => "큰 작업을 허용할까요?",
107 "resource-ratio" => "압축률이 매우 높습니다",
108 "resource-retry" => "한도를 늘려 다시 시도",
109 "resource-partial" => "저장 위치를 확인하세요",
110 "uninstall-windows" => "제거 전에 다른 앱을 선택하세요",
111 "uninstall-settings-error" => "Windows 설정을 열지 못했습니다",
112 "uninstall-ubuntu-missing" => "이전 앱을 복원할 수 없습니다",
113 "uninstall-ubuntu-unknown-user" => "사용자 기본 앱 설정은 변경하지 않습니다",
114 "conflict-choice" | "conflict-apply" | "gzip-conflict-choice" => {
115 "나머지 파일에도 같게 적용"
116 }
117 "extract-skipped" => "모든 파일을 건너뛰었습니다",
118 "extract-rename-failed" => "아무 파일도 풀지 않았습니다",
119 "extract-renamed" => "이름 바꿔 저장: 읽어주세요 (1).txt",
120 "empty" => "TAR.BZ2, TAR.XZ",
121 "tar-bz2" | "tar-xz" => "읽어주세요.txt",
122 "folder-empty" => "이 폴더는 비어 있습니다",
123 "dialog-error" => "파일 선택 창을 열 수 없습니다",
124 "extract-partial" => "일부 파일만 풀렸습니다",
125 "extract-uncertain" => "저장이 끝났는지 확인하지 못했습니다",
126 "extract-unsynced" => "파일을 디스크에 완전히 저장했는지 확인하지 못했습니다",
127 "source-changed" => "압축파일 다시 열기",
128 "gzip-conflict" => "다른 이름으로 저장",
129 "create-error" => "ZIP 파일을 만들지 못했습니다",
130 "password-create" => "암호 확인",
131 "folder" => "바다.jpg",
132 "search-empty" => "일치하는 항목이 없습니다",
133 "password" | "password-retry" => "암호",
134 "extract-complete" => "압축을 풀었습니다",
135 "extract-cancelled" => "작업을 취소했습니다",
136 "create-complete" => "ZIP 파일을 만들었습니다",
137 "create" | "create-encrypted" => "암호로 보호하기",
138 "unsupported" | "damaged" => "압축파일을 열지 못했습니다",
139 "conflict" => "압축을 풀지 못했습니다",
140 "close-confirm" => "닫",
141 _ => "읽어주세요.txt",
142 };
143 assert!(labels.contains(expected), "{}: {labels}", scenario.name);
144 if scenario.name == "extract-rename-failed" {
145 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
146 assert!(!labels.contains("이름 바꿔 저장:"), "{labels}");
147 }
148 if matches!(scenario.name, "tar-bz2" | "tar-xz") {
149 assert!(app.model.entries.iter().all(|entry| !entry.encrypted));
150 assert_eq!(
151 app.model.list_id.as_ref().unwrap().format,
152 zipelo_ui_memory_app::archive_ui::Format::Tar
153 );
154 }
155 if scenario.name == "many-items" {
156 assert_eq!(app.model.entries.len(), 505);
157 }
158 if matches!(scenario.name, "selection" | "marquee") {
159 assert_eq!(app.model.selected.len(), 4);
160 assert!(labels.contains("선택 2개"));
161 }
162 if scenario.name == "password-retry" {
163 assert_eq!(app.model.challenge.unwrap().1, 2);
164 }
165 }
166 }
167}
168
169#[test]
170fn command_line_catalog_and_errors_work_without_a_display() {
171 let run = |args: &[&str]| {
172 std::process::Command::new(env!("CARGO_BIN_EXE_zipelo-ui-memory-app"))
173 .args(args)
174 .env_remove("DISPLAY")
175 .env_remove("WAYLAND_DISPLAY")
176 .output()
177 .unwrap()
178 };
179 let listed = run(&["--list-ui-scenarios"]);
180 assert!(listed.status.success());
181 assert_eq!(
182 String::from_utf8(listed.stdout).unwrap(),
183 scenarios::listing()
184 );
185 for args in [vec!["--ui-scenario", "unknown"], vec!["--ui-scenario"]] {
186 let failed = run(&args);
187 assert!(!failed.status.success());
188 let stderr = String::from_utf8_lossy(&failed.stderr);
189 for scenario in SCENARIOS {
190 assert!(stderr.contains(scenario.name));
191 }
192 }
193}
194
195#[test]
196fn preview_ignores_password_submission() {
197 let ctx = egui::Context::default();
198 let mut preview = scenarios::Preview::new(scenarios::parse("password").unwrap().build(), &ctx);
199 for _ in 0..3 {
200 let mut output = ctx.run_ui(
201 egui::RawInput {
202 screen_rect: Some(egui::Rect::from_min_size(
203 egui::Pos2::ZERO,
204 egui::vec2(1060.0, 720.0),
205 )),
206 events: vec![
207 egui::Event::Text("화면 검토".into()),
208 egui::Event::Key {
209 key: egui::Key::Enter,
210 physical_key: None,
211 pressed: true,
212 repeat: false,
213 modifiers: egui::Modifiers::NONE,
214 },
215 ],
216 ..Default::default()
217 },
218 |ui| preview.0.show(ui),
219 );
220 output.textures_delta.clear();
221 }
222 assert_eq!(preview.0.model.challenge, Some((17, 1, false)));
223 assert!(preview.0.model.busy());
224}
225
226#[test]
227fn uninstall_previews_match_packaged_notices_and_do_not_start_jobs() {
228 let installer = include_str!("../../packaging/windows/rust/installer.nsi");
229 let prerm = include_str!("../../packaging/ubuntu/rust/prerm");
230 let helper = include_str!("../../packaging/ubuntu/rust/default-apps");
231 for (name, source, expected) in [
232 (
233 "uninstall-windows",
234 installer,
235 "직접 고른 기본 앱은 자동으로 바꾸지 않습니다.",
236 ),
237 (
238 "uninstall-settings-error",
239 installer,
240 "Windows 설정을 열지 못했습니다.",
241 ),
242 (
243 "uninstall-ubuntu-missing",
244 helper,
245 "이전 앱을 복원할 수 없습니다:",
246 ),
247 (
248 "uninstall-ubuntu-unknown-user",
249 prerm,
250 "제거를 요청한 사용자를 확인할 수 없어 사용자 기본 앱 설정은 변경하지 않습니다.",
251 ),
252 ] {
253 assert!(source.contains(expected));
254 let scenario = scenarios::parse(name).unwrap();
255 let ctx = egui::Context::default();
256 let mut preview = scenarios::Preview::new(scenario.build(), &ctx).with_scenario(scenario);
257 let mut output = ctx.run_ui(
258 egui::RawInput {
259 screen_rect: Some(egui::Rect::from_min_size(
260 egui::Pos2::ZERO,
261 egui::vec2(760.0, 540.0),
262 )),
263 events: vec![egui::Event::Key {
264 key: egui::Key::Enter,
265 physical_key: None,
266 pressed: true,
267 repeat: false,
268 modifiers: egui::Modifiers::NONE,
269 }],
270 ..Default::default()
271 },
272 |ui| preview.show(ui),
273 );
274 assert!(text(&output.shapes).contains(expected), "{name}");
275 assert!(!preview.0.model.busy());
276 assert!(preview.0.model.archive.is_none());
277 assert!(output.platform_output.commands.is_empty());
278 output.textures_delta.clear();
279 }
280}
281
282fn result_labels(
283 app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp,
284 size: egui::Vec2,
285) -> String {
286 let ctx = egui::Context::default();
287 let mut labels = String::new();
288 for _ in 0..3 {
289 let mut output = ctx.run_ui(
290 egui::RawInput {
291 screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)),
292 ..Default::default()
293 },
294 |ui| app.show(ui),
295 );
296 labels = text(&output.shapes);
297 output.textures_delta.clear();
298 }
299 labels
300}
301
302#[test]
303fn rename_without_created_output_never_claims_saved_name() {
304 use zipelo_ui_memory_app::archive_ui::*;
305 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
306 for disposition in [
307 None,
308 Some(Disposition::PartialRetained),
309 Some(Disposition::Removed),
310 Some(Disposition::CommitUncertain),
311 ] {
312 let mut app = scenarios::parse("extract-renamed").unwrap().build();
313 app.model.outputs = disposition
314 .into_iter()
315 .map(|d| ("읽어주세요 (1).txt".into(), d))
316 .collect();
317 app.model.terminal = Some(Terminal {
318 outcome: Outcome::Failed,
319 error: Some(ErrorCode::Io),
320 publication: if disposition.is_none() {
321 Publication::None
322 } else {
323 Publication::Uncertain
324 },
325 created_count: 0,
326 retained_partial_count: 0,
327 durability: Durability::NotApplicable,
328 cleanup: Cleanup::Complete,
329 });
330 let labels = result_labels(&mut app, size);
331 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
332 if disposition.is_none() {
333 assert!(labels.contains("아무 파일도 풀지 않았습니다"), "{labels}");
334 }
335 assert!(
336 !labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"),
337 "{labels}"
338 );
339 }
340 }
341}
342
343#[test]
344fn rename_saved_before_later_failure_remains_reported() {
345 use zipelo_ui_memory_app::archive_ui::*;
346 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
347 let mut app = scenarios::parse("extract-renamed").unwrap().build();
348 app.model.resolutions.push(Resolution {
349 entry_id: 2,
350 relative_name: "여행 일정 (1).pdf".into(),
351 choice: ConflictChoice::Rename,
352 });
353 app.model.terminal.as_mut().unwrap().outcome = Outcome::Failed;
354 app.model.terminal.as_mut().unwrap().error = Some(ErrorCode::Io);
355 app.model.terminal.as_mut().unwrap().publication = Publication::Partial;
356 let labels = result_labels(&mut app, size);
357 assert!(
358 labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"),
359 "{labels}"
360 );
361 assert!(
362 !labels.contains("이름 바꿔 저장: 여행 일정 (1).pdf"),
363 "{labels}"
364 );
365 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
366 }
367}
368
369fn resource_frame(
370 app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp,
371 ctx: &egui::Context,
372 events: Vec<egui::Event>,
373) -> Vec<egui::epaint::ClippedShape> {
374 let mut out = ctx.run_ui(
375 egui::RawInput {
376 screen_rect: Some(egui::Rect::from_min_size(
377 egui::Pos2::ZERO,
378 egui::vec2(760.0, 540.0),
379 )),
380 events,
381 ..Default::default()
382 },
383 |ui| app.show(ui),
384 );
385 out.textures_delta.clear();
386 out.shapes
387}
388fn find_resource_action(shapes: &[egui::epaint::ClippedShape], label: &str) -> egui::Pos2 {
389 fn find(s: &egui::Shape, label: &str) -> Option<egui::Pos2> {
390 match s {
391 egui::Shape::Text(t) if t.galley.text() == label => {
392 Some(t.pos + t.galley.rect.size() / 2.0)
393 }
394 egui::Shape::Vec(shapes) => shapes.iter().find_map(|s| find(s, label)),
395 _ => None,
396 }
397 }
398 shapes.iter().find_map(|s| find(&s.shape, label)).unwrap()
399}
400#[test]
401fn resource_dialog_requires_explicit_click_and_escape_cancels() {
402 for allow in [false, true] {
403 let ctx = egui::Context::default();
404 let mut app = scenarios::parse("resource-ratio").unwrap().build();
405 let mut shapes = Vec::new();
406 for _ in 0..3 {
407 shapes = resource_frame(&mut app, &ctx, vec![]);
408 }
409 assert!(text(&shapes).contains("미확인"));
410 resource_frame(
411 &mut app,
412 &ctx,
413 vec![egui::Event::Key {
414 key: egui::Key::Enter,
415 physical_key: None,
416 pressed: true,
417 repeat: false,
418 modifiers: Default::default(),
419 }],
420 );
421 assert!(app.model.resource.is_some());
422 if allow {
423 let point = find_resource_action(&shapes, "이 작업 허용");
424 resource_frame(
425 &mut app,
426 &ctx,
427 vec![
428 egui::Event::PointerMoved(point),
429 egui::Event::PointerButton {
430 pos: point,
431 button: egui::PointerButton::Primary,
432 pressed: true,
433 modifiers: Default::default(),
434 },
435 ],
436 );
437 resource_frame(
438 &mut app,
439 &ctx,
440 vec![egui::Event::PointerButton {
441 pos: point,
442 button: egui::PointerButton::Primary,
443 pressed: false,
444 modifiers: Default::default(),
445 }],
446 );
447 assert!(!app.model.cancellation_requested());
448 } else {
449 resource_frame(
450 &mut app,
451 &ctx,
452 vec![egui::Event::Key {
453 key: egui::Key::Escape,
454 physical_key: None,
455 pressed: true,
456 repeat: false,
457 modifiers: Default::default(),
458 }],
459 );
460 assert!(app.model.cancellation_requested());
461 }
462 assert!(app.model.resource.is_none());
463 }
464}
465#[test]
466fn partial_limit_result_never_offers_expanded_retry() {
467 let ctx = egui::Context::default();
468 let mut app = scenarios::parse("resource-partial").unwrap().build();
469 let mut shapes = Vec::new();
470 for _ in 0..3 {
471 shapes = resource_frame(&mut app, &ctx, vec![]);
472 }
473 assert!(!text(&shapes).contains("한도를 늘려 다시 시도"));
474 assert!(text(&shapes).contains("풀린 자료"));
475}
476
477#[test]
478fn preview_escape_discards_content_and_returns_to_list_without_changing_selection() {
479 for name in ["preview-text", "preview-image", "preview-loading"] {
480 let ctx = egui::Context::default();
481 let mut app = scenarios::parse(name).unwrap().build();
482 let selected = app.model.selected.clone();
483 for _ in 0..3 {
484 resource_frame(&mut app, &ctx, vec![]);
485 }
486 assert!(text(&resource_frame(&mut app, &ctx, vec![])).contains("미리보기"));
487 resource_frame(
488 &mut app,
489 &ctx,
490 vec![egui::Event::Key {
491 key: egui::Key::Escape,
492 physical_key: None,
493 pressed: true,
494 repeat: false,
495 modifiers: Default::default(),
496 }],
497 );
498 for _ in 0..3 {
499 resource_frame(&mut app, &ctx, vec![]);
500 }
501 assert!(app.model.preview.is_none());
502 assert_eq!(app.model.selected, selected);
503 if name == "preview-loading" {
504 assert!(app.model.cancellation_requested());
505 } else {
506 assert_eq!(
507 ctx.memory(|m| m.focused()),
508 Some(egui::Id::unique("archive-list"))
509 );
510 }
511 }
512}
513
514#[test]
515fn preview_image_respects_renderer_texture_limit() {
516 let ctx = egui::Context::default();
517 let mut app = scenarios::parse("preview-image").unwrap().build();
518 app.model.preview = Some(zipelo_ui_memory_app::archive_ui::Preview {
519 info: zipelo_ui_memory_app::archive_ui::PreviewInfo {
520 entry_id: 1,
521 format: zipelo_ui_memory_app::archive_ui::PreviewFormat::Rgba8,
522 width: 2048,
523 height: 1,
524 total_bytes: 8192,
525 },
526 data: vec![255; 8192],
527 });
528 let mut image_seen = false;
529 for _ in 0..3 {
530 let mut result = ctx.run_ui(
531 egui::RawInput {
532 max_texture_side: Some(1024),
533 screen_rect: Some(egui::Rect::from_min_size(
534 egui::Pos2::ZERO,
535 egui::vec2(760.0, 540.0),
536 )),
537 ..Default::default()
538 },
539 |ui| app.show(ui),
540 );
541 for (id, delta) in &result.textures_delta.set {
542 if *id == egui::TextureId::Managed(0) {
543 continue;
544 }
545 for image in delta {
546 assert!(image.image.size().iter().all(|n| *n <= 1024));
547 }
548 image_seen = true;
549 }
550 result.textures_delta.clear();
551 }
552 assert!(image_seen);
553}