| 1 | #![allow(dead_code)] |
| 2 | #[path = "../../experiments/rust-ui-memory-app/src/archive_ui.rs"] |
| 3 | mod archive_ui; |
| 4 | mod adapter { |
| 5 | include!("../../experiments/rust-ui-memory-app/src/archive_process.rs"); |
| 6 | |
| 7 | fn token(format: ui::Format, source_object: ui::SourceObject) -> ui::ListId { |
| 8 | ui::ListId { |
| 9 | catalog_version: 1, |
| 10 | format, |
| 11 | source_object, |
| 12 | archive_bytes: 33, |
| 13 | archive_sha256: [44; 32], |
| 14 | } |
| 15 | } |
| 16 | fn formats() -> [ui::Format; 5] { |
| 17 | [ |
| 18 | ui::Format::Zip, |
| 19 | ui::Format::Tar, |
| 20 | ui::Format::Gzip, |
| 21 | ui::Format::TarGzip, |
| 22 | ui::Format::SevenZip, |
| 23 | ] |
| 24 | } |
| 25 | #[test] |
| 26 | fn list_end_preserves_existing_tags_and_assigns_four_to_seven_zip() { |
| 27 | for (tag, format) in formats().into_iter().enumerate() { |
| 28 | let id = token( |
| 29 | format, |
| 30 | ui::SourceObject::Unix { |
| 31 | device: 11, |
| 32 | inode: 22, |
| 33 | }, |
| 34 | ); |
| 35 | let mut actual = Vec::new(); |
| 36 | codec::Writer::new(&mut actual, 99) |
| 37 | .send(&wire::Message::ListEnd { |
| 38 | entry_count: 7, |
| 39 | list_id: list_to_wire(id.clone()), |
| 40 | }) |
| 41 | .unwrap(); |
| 42 | let mut body = Vec::new(); |
| 43 | body.extend(7u32.to_le_bytes()); |
| 44 | body.extend(1u16.to_le_bytes()); |
| 45 | body.push(tag as u8); |
| 46 | body.push(1); |
| 47 | body.extend(11u64.to_le_bytes()); |
| 48 | body.extend(22u64.to_le_bytes()); |
| 49 | body.extend(33u64.to_le_bytes()); |
| 50 | body.extend([44; 32]); |
| 51 | let mut expected = Vec::from(*b"ZAW1"); |
| 52 | expected.extend(1u16.to_le_bytes()); |
| 53 | expected.extend(102u16.to_le_bytes()); |
| 54 | expected.extend((body.len() as u32).to_le_bytes()); |
| 55 | expected.extend([0; 4]); |
| 56 | expected.extend(99u64.to_le_bytes()); |
| 57 | expected.extend(0u64.to_le_bytes()); |
| 58 | expected.extend(body); |
| 59 | assert_eq!(actual, expected); |
| 60 | let (_, _, message) = codec::Reader::new(actual.as_slice()) |
| 61 | .read() |
| 62 | .unwrap() |
| 63 | .unwrap(); |
| 64 | match event_to_ui(message, None).unwrap() { |
| 65 | ui::Event::ListEnd { |
| 66 | entry_count, |
| 67 | list_id, |
| 68 | } => { |
| 69 | assert_eq!(entry_count, 7); |
| 70 | assert_eq!(list_id, id); |
| 71 | } |
| 72 | _ => panic!("목록 완료 응답이 아님"), |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | #[test] |
| 77 | fn extraction_roundtrip_preserves_both_platform_identities_and_all_formats() { |
| 78 | for source in [ |
| 79 | ui::SourceObject::Unix { |
| 80 | device: 11, |
| 81 | inode: 22, |
| 82 | }, |
| 83 | ui::SourceObject::Windows { |
| 84 | volume: 55, |
| 85 | file_id: [66; 16], |
| 86 | }, |
| 87 | ] { |
| 88 | for format in formats() { |
| 89 | let id = token(format, source.clone()); |
| 90 | assert_eq!(list_to_ui(list_to_wire(id.clone())), id); |
| 91 | let start = start_to_wire(ui::Start::Extract { |
| 92 | archive: PathBuf::from("input.7z"), |
| 93 | destination: PathBuf::from("output"), |
| 94 | selection: ui::Selection::EntryIds(vec![7]), |
| 95 | list_id: id.clone(), |
| 96 | gzip_output_name: if format == ui::Format::Gzip { |
| 97 | Some("content".into()) |
| 98 | } else { |
| 99 | None |
| 100 | }, |
| 101 | }); |
| 102 | let mut bytes = Vec::new(); |
| 103 | codec::Writer::new(&mut bytes, 99) |
| 104 | .send(&wire::Message::Start(start)) |
| 105 | .unwrap(); |
| 106 | assert_eq!(&bytes[6..8], &1u16.to_le_bytes()); |
| 107 | match codec::Reader::new(bytes.as_slice()) |
| 108 | .read() |
| 109 | .unwrap() |
| 110 | .unwrap() |
| 111 | .2 |
| 112 | { |
| 113 | wire::Message::Start(wire::Start { |
| 114 | action: |
| 115 | wire::Action::Extract { |
| 116 | list_id: Some(decoded), |
| 117 | selection, |
| 118 | .. |
| 119 | }, |
| 120 | .. |
| 121 | }) => { |
| 122 | assert_eq!(list_to_ui(decoded), id); |
| 123 | assert_eq!(selection, wire::Selection::EntryIds(vec![7])); |
| 124 | } |
| 125 | _ => panic!("압축 해제 요청이 아님"), |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | #[test] |
| 131 | fn disk_full_terminal_roundtrip_displays_space_guidance_and_preserves_cleanup() { |
| 132 | for (error, expected, guidance) in [ |
| 133 | ( |
| 134 | wire::ErrorCode::DiskFull, |
| 135 | ui::ErrorCode::DiskFull, |
| 136 | "디스크 여유 공간이 부족합니다. 공간을 확보한 뒤 다시 시도하세요", |
| 137 | ), |
| 138 | ( |
| 139 | wire::ErrorCode::Io, |
| 140 | ui::ErrorCode::Io, |
| 141 | "파일을 읽거나 쓰지 못했습니다. 파일과 폴더의 접근 권한을 확인하세요", |
| 142 | ), |
| 143 | ] { |
| 144 | let message = wire::Message::Terminal(wire::Terminal { |
| 145 | outcome: wire::Outcome::Failed, |
| 146 | error, |
| 147 | publication: wire::Publication::Partial, |
| 148 | created_count: 2, |
| 149 | retained_partial_count: 0, |
| 150 | durability: wire::Durability::Synced, |
| 151 | cleanup: wire::Cleanup::Complete, |
| 152 | detail: "internal path must not appear".into(), |
| 153 | }); |
| 154 | let mut frame = Vec::new(); |
| 155 | codec::Writer::new(&mut frame, 99).send(&message).unwrap(); |
| 156 | let (_, _, decoded) = codec::Reader::new(frame.as_slice()) |
| 157 | .read() |
| 158 | .unwrap() |
| 159 | .unwrap(); |
| 160 | let ui::Event::Terminal(terminal) = event_to_ui(decoded, None).unwrap() else { |
| 161 | panic!("종료 응답이 아님"); |
| 162 | }; |
| 163 | assert_eq!(terminal.error, Some(expected)); |
| 164 | assert_eq!(terminal.outcome, ui::Outcome::Failed); |
| 165 | assert_eq!(terminal.publication, ui::Publication::Partial); |
| 166 | assert_eq!(terminal.created_count, 2); |
| 167 | assert_eq!(terminal.retained_partial_count, 0); |
| 168 | assert_eq!(terminal.cleanup, ui::Cleanup::Complete); |
| 169 | let lines = ui::terminal_lines(&terminal); |
| 170 | assert!(lines.iter().any(|line| line == guidance)); |
| 171 | assert!(lines.iter().any(|line| line.contains("일부 파일 게시됨"))); |
| 172 | assert!(!lines.iter().any(|line| line.contains("internal path"))); |
| 173 | } |
| 174 | } |
| 175 | } |