team-ljyzipelo

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