team-ljyzipelo

공개
130줄4.6 KB
1#![allow(dead_code)]
2#[path = "../../experiments/rust-ui-memory-app/src/archive_ui.rs"]
3mod archive_ui;
4mod 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}