| 1 | use super::*; |
| 2 | |
| 3 | #[test] |
| 4 | fn conflict_adapter_preserves_sizes_names_ids_and_choices() { |
| 5 | let required = || wire::Message::ConflictRequired { |
| 6 | challenge_id: 53, |
| 7 | entry_id: 7, |
| 8 | relative_name: "사진/기록.txt".into(), |
| 9 | incoming_size: u64::MAX, |
| 10 | existing_size: 1 << 34, |
| 11 | }; |
| 12 | match event_to_ui(required(), Some(wire::ActionKind::Extract)).unwrap() { |
| 13 | ui::Event::ConflictRequired(c) => { |
| 14 | assert_eq!(c.challenge_id, 53); |
| 15 | assert_eq!(c.entry_id, 7); |
| 16 | assert_eq!(c.relative_name, "사진/기록.txt"); |
| 17 | assert_eq!(c.incoming_size, u64::MAX); |
| 18 | assert_eq!(c.existing_size, 1 << 34); |
| 19 | } |
| 20 | _ => panic!("충돌 요청 변환 누락"), |
| 21 | } |
| 22 | for expected in [ |
| 23 | None, |
| 24 | Some(wire::ActionKind::List), |
| 25 | Some(wire::ActionKind::CreateZip), |
| 26 | ] { |
| 27 | assert!(event_to_ui(required(), expected).is_err()); |
| 28 | } |
| 29 | for choice in [ |
| 30 | ui::ConflictChoice::Overwrite, |
| 31 | ui::ConflictChoice::Skip, |
| 32 | ui::ConflictChoice::Rename, |
| 33 | ] { |
| 34 | match event_to_ui( |
| 35 | wire::Message::ConflictResolved { |
| 36 | entry_id: 7, |
| 37 | relative_name: "사진/기록 (1).txt".into(), |
| 38 | choice: conflict_to_wire(choice), |
| 39 | }, |
| 40 | Some(wire::ActionKind::Extract), |
| 41 | ) |
| 42 | .unwrap() |
| 43 | { |
| 44 | ui::Event::ConflictResolved(r) => { |
| 45 | assert_eq!(r.choice, choice); |
| 46 | assert_eq!(r.entry_id, 7); |
| 47 | assert_eq!(r.relative_name, "사진/기록 (1).txt"); |
| 48 | } |
| 49 | _ => panic!("충돌 결과 변환 누락"), |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | #[test] |
| 55 | fn split_list_id_adapter_round_trip_preserves_manifest_and_logical_input() { |
| 56 | let id = ui::ListId { |
| 57 | catalog_version: 2, |
| 58 | format: ui::Format::SevenZip, |
| 59 | source_object: ui::SourceObject::SplitSevenZip { |
| 60 | manifest_sha256: [0xa5; 32], |
| 61 | }, |
| 62 | archive_bytes: u64::MAX, |
| 63 | archive_sha256: [0x5a; 32], |
| 64 | }; |
| 65 | let wire_id = list_to_wire(id.clone()); |
| 66 | assert!(wire_id.valid()); |
| 67 | assert_eq!(list_to_ui(wire_id), id); |
| 68 | } |
| 69 | #[test] |
| 70 | fn volume_problem_adapter_preserves_native_filename_and_rejects_other_actions() { |
| 71 | for volume in [ |
| 72 | wire::NativePath::Unix(vec![0xff, 46, 55, 122]), |
| 73 | wire::NativePath::Windows(vec![0xd800, 46, 55, 122]), |
| 74 | ] { |
| 75 | for action in [ |
| 76 | Some(wire::ActionKind::List), |
| 77 | Some(wire::ActionKind::Extract), |
| 78 | Some(wire::ActionKind::Preview), |
| 79 | Some(wire::ActionKind::CreateZip), |
| 80 | None, |
| 81 | ] { |
| 82 | let event = event_to_ui( |
| 83 | wire::Message::VolumeProblem { |
| 84 | reason: wire::VolumeProblemReason::MissingVolume, |
| 85 | volume: volume.clone(), |
| 86 | }, |
| 87 | action, |
| 88 | ); |
| 89 | if matches!( |
| 90 | action, |
| 91 | Some(wire::ActionKind::List | wire::ActionKind::Extract) |
| 92 | ) { |
| 93 | match event.unwrap() { |
| 94 | ui::Event::VolumeProblem(problem) => { |
| 95 | assert_eq!(problem.volume, volume); |
| 96 | assert_eq!(problem.reason, wire::VolumeProblemReason::MissingVolume); |
| 97 | } |
| 98 | _ => panic!("조각 오류 변환 누락"), |
| 99 | } |
| 100 | } else { |
| 101 | assert!(event.is_err()); |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | assert_eq!( |
| 106 | error_to_ui(wire::ErrorCode::MissingVolume), |
| 107 | Some(ui::ErrorCode::MissingVolume) |
| 108 | ); |
| 109 | } |