team-ljyzipelo

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