team-ljyzipelo

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