team-ljyzipelo

공개
201줄6.8 KB
1// GNOME Wayland처럼 운영체제가 창 테두리를 그리지 않을 때 쓰는 자체 제목 표시줄 회귀 시험.
2
3fn frame_output(
4 ctx: &egui::Context,
5 app: &mut ArchiveApp,
6 events: Vec<egui::Event>,
7) -> egui::FullOutput {
8 let mut output = ctx.run_ui(
9 egui::RawInput {
10 screen_rect: Some(egui::Rect::from_min_size(
11 egui::Pos2::ZERO,
12 egui::vec2(1060.0, 720.0),
13 )),
14 events,
15 ..Default::default()
16 },
17 |ui| app.show(ui),
18 );
19 output.textures_delta.clear();
20 output
21}
22
23fn root_commands(output: &egui::FullOutput) -> Vec<egui::ViewportCommand> {
24 output
25 .viewport_output
26 .get(&egui::ViewportId::ROOT)
27 .map(|viewport| viewport.commands.clone())
28 .unwrap_or_default()
29}
30
31fn press_release(
32 ctx: &egui::Context,
33 app: &mut ArchiveApp,
34 point: egui::Pos2,
35) -> Vec<egui::ViewportCommand> {
36 frame_output(ctx, app, vec![egui::Event::PointerMoved(point)]);
37 let mut commands = Vec::new();
38 for pressed in [true, false] {
39 let output = frame_output(
40 ctx,
41 app,
42 vec![egui::Event::PointerButton {
43 pos: point,
44 button: egui::PointerButton::Primary,
45 pressed,
46 modifiers: egui::Modifiers::NONE,
47 }],
48 );
49 commands.extend(root_commands(&output));
50 }
51 commands
52}
53
54fn window_commands(commands: &[egui::ViewportCommand]) -> Vec<egui::ViewportCommand> {
55 // 제목 갱신은 매 프레임 나가므로 창 조작 명령만 비교함.
56 commands
57 .iter()
58 .filter(|command| !matches!(command, egui::ViewportCommand::Title(_)))
59 .cloned()
60 .collect()
61}
62
63#[test]
64fn custom_window_frame_shows_title_and_sends_window_commands() {
65 use zipelo_ui_memory_app::window_frame::TITLE_HEIGHT;
66 // 제목 표시줄 버튼 중심: 오른쪽 여백 6, 버튼 폭 34, 간격 4.
67 let close = egui::pos2(1060.0 - 6.0 - 17.0, TITLE_HEIGHT / 2.0);
68 let maximize = close - egui::vec2(38.0, 0.0);
69 let minimize = maximize - egui::vec2(38.0, 0.0);
70 for (point, expected) in [
71 (close, egui::ViewportCommand::Close),
72 (maximize, egui::ViewportCommand::Maximized(true)),
73 (minimize, egui::ViewportCommand::Minimized(true)),
74 ] {
75 let scratch = Folder::new();
76 let factory = FakeFactory::default();
77 let mut app = loaded(&scratch, &factory);
78 app.set_custom_frame(true);
79 let ctx = egui::Context::default();
80 let shown = labels(&frame_output(&ctx, &mut app, vec![]).shapes);
81 assert!(
82 shown
83 .iter()
84 .any(|(text, pos)| text.ends_with("sample.zip — Zipelo") && pos.y < TITLE_HEIGHT),
85 "제목 표시줄에 창 제목이 없음: {shown:?}"
86 );
87 assert_eq!(
88 window_commands(&press_release(&ctx, &mut app, point)),
89 [expected]
90 );
91 }
92
93 // 제목 표시줄을 끌면 운영체제 창 이동을 시작함.
94 let scratch = Folder::new();
95 let factory = FakeFactory::default();
96 let mut app = loaded(&scratch, &factory);
97 app.set_custom_frame(true);
98 let ctx = egui::Context::default();
99 let start = egui::pos2(300.0, TITLE_HEIGHT / 2.0);
100 frame_output(&ctx, &mut app, vec![egui::Event::PointerMoved(start)]);
101 let mut commands = root_commands(&frame_output(
102 &ctx,
103 &mut app,
104 vec![egui::Event::PointerButton {
105 pos: start,
106 button: egui::PointerButton::Primary,
107 pressed: true,
108 modifiers: egui::Modifiers::NONE,
109 }],
110 ));
111 for step in 1..=4 {
112 commands.extend(root_commands(&frame_output(
113 &ctx,
114 &mut app,
115 vec![egui::Event::PointerMoved(
116 start + egui::vec2(6.0 * step as f32, 0.0),
117 )],
118 )));
119 }
120 assert_eq!(
121 window_commands(&commands),
122 [egui::ViewportCommand::StartDrag]
123 );
124}
125
126#[test]
127fn default_window_frame_draws_no_title_bar_or_window_commands() {
128 let scratch = Folder::new();
129 let factory = FakeFactory::default();
130 let mut app = loaded(&scratch, &factory);
131 let ctx = egui::Context::default();
132 let shown = labels(&frame_output(&ctx, &mut app, vec![]).shapes);
133 assert!(
134 !shown
135 .iter()
136 .any(|(text, _)| text.ends_with(" — Zipelo")),
137 "운영체제가 테두리를 그릴 때는 제목 표시줄을 그리지 않아야 함"
138 );
139 let close = egui::pos2(1060.0 - 6.0 - 17.0, 19.0);
140 assert!(window_commands(&press_release(&ctx, &mut app, close)).is_empty());
141}
142
143fn drag_without_release(
144 ctx: &egui::Context,
145 app: &mut ArchiveApp,
146 start: egui::Pos2,
147) -> Vec<egui::ViewportCommand> {
148 frame_output(ctx, app, vec![egui::Event::PointerMoved(start)]);
149 let mut commands = root_commands(&frame_output(
150 ctx,
151 app,
152 vec![egui::Event::PointerButton {
153 pos: start,
154 button: egui::PointerButton::Primary,
155 pressed: true,
156 modifiers: egui::Modifiers::NONE,
157 }],
158 ));
159 for step in 1..=4 {
160 commands.extend(root_commands(&frame_output(
161 ctx,
162 app,
163 vec![egui::Event::PointerMoved(
164 start + egui::vec2(6.0 * step as f32, 0.0),
165 )],
166 )));
167 }
168 window_commands(&commands)
169}
170
171#[test]
172fn title_bar_drag_starts_again_when_the_system_swallowed_the_release() {
173 use zipelo_ui_memory_app::window_frame::TITLE_HEIGHT;
174 let scratch = Folder::new();
175 let factory = FakeFactory::default();
176 let mut app = loaded(&scratch, &factory);
177 app.set_custom_frame(true);
178 let ctx = egui::Context::default();
179 // GNOME Wayland는 창 이동이 끝나도 버튼 놓기를 앱에 보내지 않음.
180 let first = drag_without_release(&ctx, &mut app, egui::pos2(300.0, TITLE_HEIGHT / 2.0));
181 assert_eq!(first, [egui::ViewportCommand::StartDrag]);
182 let second = drag_without_release(&ctx, &mut app, egui::pos2(500.0, TITLE_HEIGHT / 2.0));
183 assert_eq!(second, [egui::ViewportCommand::StartDrag]);
184
185 // 이동을 넘긴 뒤 다음 프레임 입력에 버튼 놓기를 넣어 눌림 상태를 풀어야 함.
186 let mut raw = egui::RawInput::default();
187 eframe::App::raw_input_hook(&mut app, &ctx, &mut raw);
188 assert!(raw.events.iter().any(|event| matches!(
189 event,
190 egui::Event::PointerButton {
191 button: egui::PointerButton::Primary,
192 pressed: false,
193 ..
194 }
195 )));
196 frame_output(&ctx, &mut app, raw.events);
197 assert!(!ctx.input(|i| i.pointer.any_down()));
198 let mut again = egui::RawInput::default();
199 eframe::App::raw_input_hook(&mut app, &ctx, &mut again);
200 assert!(again.events.is_empty(), "놓기는 이동 한 번에 한 번만 넣어야 함");
201}