| 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 | } |
| 110 | |
| 111 | #[test] |
| 112 | fn sevenzip_creation_adapter_preserves_paths_and_fixed_options() { |
| 113 | let source = std::env::current_dir().unwrap().join("원본"); |
| 114 | let output = source.with_file_name("결과.7z"); |
| 115 | let converted = start_to_wire(ui::Start::CreateSevenZip { |
| 116 | sources: vec![(source.clone(), "원본".into())], |
| 117 | output_file: output.clone(), |
| 118 | volume_size: None, |
| 119 | }); |
| 120 | match converted.action { |
| 121 | wire::Action::CreateSevenZip { |
| 122 | sources, |
| 123 | output_file, |
| 124 | method, |
| 125 | solid, |
| 126 | encryption, |
| 127 | volume_size, |
| 128 | } => { |
| 129 | assert_eq!(volume_size, None); |
| 130 | assert_eq!(sources[0].archive_name, "원본"); |
| 131 | assert_eq!( |
| 132 | sources[0].path, |
| 133 | wire::NativePath::from_path(&crate::archive_path::worker_path(&source)) |
| 134 | ); |
| 135 | assert_eq!( |
| 136 | output_file, |
| 137 | wire::NativePath::from_path(&crate::archive_path::worker_path(&output)) |
| 138 | ); |
| 139 | assert_eq!(method, wire::SevenZipMethod::Lzma2); |
| 140 | assert!(!solid); |
| 141 | assert_eq!(encryption, wire::Encryption::None); |
| 142 | } |
| 143 | other => panic!("잘못된 생성 형식: {other:?}"), |
| 144 | } |
| 145 | let converted = start_to_wire(ui::Start::CreateSevenZip { |
| 146 | sources: vec![(source, "원본".into())], |
| 147 | output_file: output, |
| 148 | volume_size: Some(700 * 1024 * 1024), |
| 149 | }); |
| 150 | assert!(matches!( |
| 151 | converted.action, |
| 152 | wire::Action::CreateSevenZip { |
| 153 | volume_size: Some(size), |
| 154 | .. |
| 155 | } if size == 700 * 1024 * 1024 |
| 156 | )); |
| 157 | } |