team-ljyzipelo

공개
258줄9.4 KB
1#![allow(dead_code)]
2#[path = "../../experiments/rust-ui-memory-app/src/archive_ui.rs"]
3mod archive_ui;
4use zipelo_ui_memory_app::archive_path;
5mod adapter {
6 include!("../../experiments/rust-ui-memory-app/src/archive_process.rs");
7
8 #[cfg(windows)]
9 #[test]
10 fn all_worker_path_fields_use_the_same_safe_drive_conversion() {
11 use std::path::{Path, PathBuf};
12 let input = PathBuf::from(r"\\?\C:\fixture\archive.zip");
13 let output = PathBuf::from(r"\\?\C:\fixture\output");
14 let expected_input = Path::new(r"C:\fixture\archive.zip");
15 let expected_output = Path::new(r"C:\fixture\output");
16 let wire::Action::List { archive } = start_to_wire(ui::Start::List {
17 archive: input.clone(),
18 })
19 .action
20 else {
21 panic!("목록 요청 누락")
22 };
23 assert_eq!(archive.to_path().unwrap(), expected_input);
24 let wire::Action::Extract {
25 archive,
26 destination,
27 ..
28 } = start_to_wire(ui::Start::Extract {
29 archive: input.clone(),
30 destination: output.clone(),
31 selection: ui::Selection::All,
32 list_id: token(
33 ui::Format::Zip,
34 ui::SourceObject::Windows {
35 volume: 1,
36 file_id: [2; 16],
37 },
38 ),
39 gzip_output_name: None,
40 })
41 .action
42 else {
43 panic!("추출 요청 누락")
44 };
45 assert_eq!(archive.to_path().unwrap(), expected_input);
46 assert_eq!(destination.to_path().unwrap(), expected_output);
47 for aes256 in [false, true] {
48 let wire::Action::CreateZip {
49 sources,
50 output_file,
51 encryption,
52 ..
53 } = start_to_wire(ui::Start::CreateZip {
54 sources: vec![(input.clone(), "source.txt".into())],
55 output_file: output.clone(),
56 method: ui::Method::Deflate,
57 aes256,
58 })
59 .action
60 else {
61 panic!("생성 요청 누락")
62 };
63 assert_eq!(sources[0].path.to_path().unwrap(), expected_input);
64 assert_eq!(output_file.to_path().unwrap(), expected_output);
65 assert_eq!(
66 encryption,
67 if aes256 {
68 wire::Encryption::Aes256
69 } else {
70 wire::Encryption::None
71 }
72 );
73 }
74 for text in [
75 r"\\?\UNC\server\share\one.zip",
76 r"\\server\share\one.zip",
77 r"\\?\C:\a\..\one.zip",
78 ] {
79 let wire::Action::List { archive } = start_to_wire(ui::Start::List {
80 archive: text.into(),
81 })
82 .action
83 else {
84 panic!("목록 요청 누락")
85 };
86 assert!(archive.to_path().is_err());
87 }
88 }
89
90 fn token(format: ui::Format, source_object: ui::SourceObject) -> ui::ListId {
91 ui::ListId {
92 catalog_version: 1,
93 format,
94 source_object,
95 archive_bytes: 33,
96 archive_sha256: [44; 32],
97 }
98 }
99 fn formats() -> [ui::Format; 5] {
100 [
101 ui::Format::Zip,
102 ui::Format::Tar,
103 ui::Format::Gzip,
104 ui::Format::TarGzip,
105 ui::Format::SevenZip,
106 ]
107 }
108 #[test]
109 fn list_end_preserves_existing_tags_and_assigns_four_to_seven_zip() {
110 for (tag, format) in formats().into_iter().enumerate() {
111 let id = token(
112 format,
113 ui::SourceObject::Unix {
114 device: 11,
115 inode: 22,
116 },
117 );
118 let mut actual = Vec::new();
119 codec::Writer::new(&mut actual, 99)
120 .send(&wire::Message::ListEnd {
121 entry_count: 7,
122 list_id: list_to_wire(id.clone()),
123 })
124 .unwrap();
125 let mut body = Vec::new();
126 body.extend(7u32.to_le_bytes());
127 body.extend(1u16.to_le_bytes());
128 body.push(tag as u8);
129 body.push(1);
130 body.extend(11u64.to_le_bytes());
131 body.extend(22u64.to_le_bytes());
132 body.extend(33u64.to_le_bytes());
133 body.extend([44; 32]);
134 let mut expected = Vec::from(*b"ZAW1");
135 expected.extend(1u16.to_le_bytes());
136 expected.extend(102u16.to_le_bytes());
137 expected.extend((body.len() as u32).to_le_bytes());
138 expected.extend([0; 4]);
139 expected.extend(99u64.to_le_bytes());
140 expected.extend(0u64.to_le_bytes());
141 expected.extend(body);
142 assert_eq!(actual, expected);
143 let (_, _, message) = codec::Reader::new(actual.as_slice())
144 .read()
145 .unwrap()
146 .unwrap();
147 match event_to_ui(message, None).unwrap() {
148 ui::Event::ListEnd {
149 entry_count,
150 list_id,
151 } => {
152 assert_eq!(entry_count, 7);
153 assert_eq!(list_id, id);
154 }
155 _ => panic!("목록 완료 응답이 아님"),
156 }
157 }
158 }
159 #[test]
160 fn extraction_roundtrip_preserves_both_platform_identities_and_all_formats() {
161 for source in [
162 ui::SourceObject::Unix {
163 device: 11,
164 inode: 22,
165 },
166 ui::SourceObject::Windows {
167 volume: 55,
168 file_id: [66; 16],
169 },
170 ] {
171 for format in formats() {
172 let id = token(format, source.clone());
173 assert_eq!(list_to_ui(list_to_wire(id.clone())), id);
174 let start = start_to_wire(ui::Start::Extract {
175 archive: PathBuf::from("input.7z"),
176 destination: PathBuf::from("output"),
177 selection: ui::Selection::EntryIds(vec![7]),
178 list_id: id.clone(),
179 gzip_output_name: if format == ui::Format::Gzip {
180 Some("content".into())
181 } else {
182 None
183 },
184 });
185 let mut bytes = Vec::new();
186 codec::Writer::new(&mut bytes, 99)
187 .send(&wire::Message::Start(start))
188 .unwrap();
189 assert_eq!(&bytes[6..8], &1u16.to_le_bytes());
190 match codec::Reader::new(bytes.as_slice())
191 .read()
192 .unwrap()
193 .unwrap()
194 .2
195 {
196 wire::Message::Start(wire::Start {
197 action:
198 wire::Action::Extract {
199 list_id: Some(decoded),
200 selection,
201 ..
202 },
203 ..
204 }) => {
205 assert_eq!(list_to_ui(decoded), id);
206 assert_eq!(selection, wire::Selection::EntryIds(vec![7]));
207 }
208 _ => panic!("압축 해제 요청이 아님"),
209 }
210 }
211 }
212 }
213 #[test]
214 fn disk_full_terminal_roundtrip_displays_space_guidance_and_preserves_cleanup() {
215 for (error, expected, guidance) in [
216 (
217 wire::ErrorCode::DiskFull,
218 ui::ErrorCode::DiskFull,
219 "디스크 여유 공간이 부족합니다. 공간을 확보한 뒤 다시 시도하세요",
220 ),
221 (
222 wire::ErrorCode::Io,
223 ui::ErrorCode::Io,
224 "파일을 읽거나 쓰지 못했습니다. 파일과 폴더의 접근 권한을 확인하세요",
225 ),
226 ] {
227 let message = wire::Message::Terminal(wire::Terminal {
228 outcome: wire::Outcome::Failed,
229 error,
230 publication: wire::Publication::Partial,
231 created_count: 2,
232 retained_partial_count: 0,
233 durability: wire::Durability::Synced,
234 cleanup: wire::Cleanup::Complete,
235 detail: "internal path must not appear".into(),
236 });
237 let mut frame = Vec::new();
238 codec::Writer::new(&mut frame, 99).send(&message).unwrap();
239 let (_, _, decoded) = codec::Reader::new(frame.as_slice())
240 .read()
241 .unwrap()
242 .unwrap();
243 let ui::Event::Terminal(terminal) = event_to_ui(decoded, None).unwrap() else {
244 panic!("종료 응답이 아님");
245 };
246 assert_eq!(terminal.error, Some(expected));
247 assert_eq!(terminal.outcome, ui::Outcome::Failed);
248 assert_eq!(terminal.publication, ui::Publication::Partial);
249 assert_eq!(terminal.created_count, 2);
250 assert_eq!(terminal.retained_partial_count, 0);
251 assert_eq!(terminal.cleanup, ui::Cleanup::Complete);
252 let lines = ui::terminal_lines(&terminal);
253 assert!(lines.iter().any(|line| line == guidance));
254 assert!(lines.iter().any(|line| line.contains("일부 파일 게시됨")));
255 assert!(!lines.iter().any(|line| line.contains("internal path")));
256 }
257 }
258}