team-ljyzipelo

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