Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ print_stderr = "deny"
opt-level = 2
debug = false

# cavalier_contours checks its own boolean's intermediate slices with debug assertions, and
# hostile Gerber input trips one (io's `gerber::tests::hostile_input_never_panics`). CI's `ci`
# profile and the release builds have no debug assertions, so the dev build leaves them out of
# this crate too.
[profile.dev.package.cavalier_contours]
debug-assertions = false

[profile.dev]
opt-level = 1
debug = "line-tables-only"
Expand Down
41 changes: 24 additions & 17 deletions crates/ui-egui/src/browser_canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,11 +1390,13 @@ mod tests {
for running in [false, true, false, true, false] {
let (_sender, receiver) = std::sync::mpsc::channel();
panel.trace_state.preview.lock().unwrap().running = running.then_some((1, 1, receiver));
let _ = h.ctx.run_ui(Default::default(), |ui| {
ui.set_width(320.0);
super::trace_rows(ui, &mut panel, 700.0);
positions.push(ui.next_widget_position());
});
h.ctx
.run_ui(Default::default(), |ui| {
ui.set_width(320.0);
super::trace_rows(ui, &mut panel, 700.0);
positions.push(ui.next_widget_position());
})
.drop_without_applying_deltas();
}
assert!(positions.windows(2).all(|pair| pair[0] == pair[1]), "preview status moved the controls: {positions:?}");
}
Expand All @@ -1409,12 +1411,14 @@ mod tests {
panel.trace_state.tolerances = vec![20.0; count];
super::activate(&mut panel, count - 1);
let mut size = None;
let _ = h.ctx.run_ui(Default::default(), |ui| {
ui.set_width(320.0);
let list = super::trace_rows(ui, &mut panel, 700.0);
// ScrollAreaOutput reports the pre-shrink viewport; measure the actual occupied UI as well.
size = Some((ui.min_rect().width(), ui.min_rect().height(), list.inner_rect.height(), list.content_size.y));
});
h.ctx
.run_ui(Default::default(), |ui| {
ui.set_width(320.0);
let list = super::trace_rows(ui, &mut panel, 700.0);
// ScrollAreaOutput reports the pre-shrink viewport; measure the actual occupied UI as well.
size = Some((ui.min_rect().width(), ui.min_rect().height(), list.inner_rect.height(), list.content_size.y));
})
.drop_without_applying_deltas();
let (width, height, viewport_height, content) = size.unwrap();
assert!(width <= 320.5, "{count} regions widened the panel to {width}");
let first = crate::scenario::rect_of("trace:remove:0").unwrap();
Expand Down Expand Up @@ -1476,11 +1480,13 @@ mod tests {
for elapsed in [None, Some(3.0), Some(250.0), Some(9999.0)] {
panel.trace_state.preview.lock().unwrap().compute_ms = elapsed;
let mut measured = None;
let _ = h.ctx.run_ui(Default::default(), |ui| {
ui.set_width(320.0);
super::trace_rows(ui, &mut panel, 700.0);
measured = Some(ui.min_rect());
});
h.ctx
.run_ui(Default::default(), |ui| {
ui.set_width(320.0);
super::trace_rows(ui, &mut panel, 700.0);
measured = Some(ui.min_rect());
})
.drop_without_applying_deltas();
let rect = measured.unwrap();
assert!(rect.width() <= 320.5);
if let Some(previous) = baseline {
Expand Down Expand Up @@ -1628,9 +1634,10 @@ mod tests {
assert_eq!(images[1].rgba, overlay.rgba);
let rect = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0));
let proj = crate::viewport::projection(&h.app, rect);
let output = h.ctx.run_ui(Default::default(), |ui| {
let mut output = h.ctx.run_ui(Default::default(), |ui| {
crate::ref_images::show(&h.app, ui, ui.painter(), &proj);
});
output.textures_delta.clear();
assert!(output.shapes.iter().filter(|s| matches!(s.shape, egui::Shape::Mesh(_))).count() >= 2);
// A changed selection cannot be painted with the old masks, even before the next poll.
h.app.tree.canvas_panel.as_mut().unwrap().points.remove(0);
Expand Down
6 changes: 4 additions & 2 deletions crates/ui-egui/src/prefs/pen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,11 @@ mod tests {
frame.push(event);
app.pointers.begin_frame(frame, &[]);
let ctx = crate::fonts::test_context();
let output = ctx.run_ui(Default::default(), |ui| {
let mut output = ctx.run_ui(Default::default(), |ui| {
super::device(&mut app, ui);
super::reports(&mut app, ui);
});
output.textures_delta.clear();
let texts: Vec<_> = output
.shapes
.iter()
Expand Down Expand Up @@ -419,7 +420,8 @@ mod tests {
assert_eq!(app.pen_detector.reply, None, "nothing requested on startup");
app.pen_detector.start();
let ctx = crate::fonts::test_context();
let output = ctx.run_ui(Default::default(), |ui| super::device(&mut app, ui));
let mut output = ctx.run_ui(Default::default(), |ui| super::device(&mut app, ui));
output.textures_delta.clear();
let texts: Vec<_> = output
.shapes
.iter()
Expand Down
3 changes: 2 additions & 1 deletion crates/ui-egui/src/render_workspace_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8975,7 +8975,8 @@ fn live_navigation_uses_the_shaded_preview_with_custom_environment_lighting() {
h.app.cam.yaw += 0.3;
live::hold_navigation(&mut h.app);
let rect = h.app.viewport.rect.unwrap();
let frame = h.ctx.run_ui(egui::RawInput { screen_rect: Some(rect), ..Default::default() }, |ui| show(&mut h.app, ui));
let mut frame = h.ctx.run_ui(egui::RawInput { screen_rect: Some(rect), ..Default::default() }, |ui| show(&mut h.app, ui));
frame.textures_delta.clear();
assert!(frame.shapes.iter().any(|shape| matches!(&shape.shape, egui::Shape::Callback(cb)
if cb.callback.downcast_ref::<egui_wgpu::Callback>().and_then(|cb| cb.downcast_ref::<solidcraft_viewport_egui::ViewportCallback>()).is_some())));
}
Expand Down
3 changes: 2 additions & 1 deletion crates/ui-kit/src/file_preview_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ fn the_grid_keeps_its_screen_coordinates_in_a_cropped_preview() {
let ctx = Context::default();
let screen = Rect::from_min_size(Pos2::ZERO, vec2(600., 360.));
let slot = Rect::from_min_size(pos2(350., 150.), vec2(160., 120.));
let frame = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), ..Default::default() }, |ui| {
let mut frame = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), ..Default::default() }, |ui| {
file_preview(ui, Id::unique("part"), slot, None, false, 1.);
});
let mut textures = std::collections::HashMap::new();
crate::test_support::textures_update(&mut textures, &frame.textures_delta);
frame.textures_delta.clear();
let full = crate::test_support::raster(&ctx, frame.shapes.clone(), frame.pixels_per_point, screen, &textures);
let crop = crate::test_support::raster(&ctx, frame.shapes, frame.pixels_per_point, slot, &textures);
let mut mismatches = 0;
Expand Down
39 changes: 23 additions & 16 deletions crates/ui-kit/src/window_chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,17 +880,20 @@ mod tests {
v.native_window = Some(main_window);
}
let (mut main, mut other) = (false, false);
let _ = ctx.run_ui(input, |ui| {
ctx.run_ui(input, |ui| {
drag_area(ui, bar);
main = ui.input(|i| i.pointer.any_pressed());
let mut child = RawInput { viewport_id: pop_out, screen_rect: Some(screen), ..Default::default() };
let info = egui::ViewportInfo { parent: Some(ViewportId::ROOT), native_window: Some(pop_out_window), ..Default::default() };
child.viewports.insert(pop_out, info);
let _ = ui.ctx().run_ui(child, |ui| {
drag_area(ui, bar);
other = ui.input(|i| i.pointer.any_pressed());
});
});
ui.ctx()
.run_ui(child, |ui| {
drag_area(ui, bar);
other = ui.input(|i| i.pointer.any_pressed());
})
.drop_without_applying_deltas();
})
.drop_without_applying_deltas();
(main, other)
};
assert_eq!(frame(), (false, false));
Expand Down Expand Up @@ -1132,18 +1135,21 @@ mod tests {
input
};
let (mut main, mut other) = (None, None);
let _ = ctx.run_ui(main_input(), |ui| {
ctx.run_ui(main_input(), |ui| {
drag_area(ui, bar);
let mut child =
RawInput { viewport_id: pop_out, screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(480.0, 320.0))), ..Default::default() };
let info = egui::ViewportInfo { parent: Some(ViewportId::ROOT), native_window: Some(pop_out_window), ..Default::default() };
child.viewports.insert(pop_out, info);
let _ = ui.ctx().run_ui(child, |ui| {
drag_area(ui, pop_out_bar);
other = bar_this_pass(ui.ctx());
});
ui.ctx()
.run_ui(child, |ui| {
drag_area(ui, pop_out_bar);
other = bar_this_pass(ui.ctx());
})
.drop_without_applying_deltas();
main = bar_this_pass(ui.ctx());
});
})
.drop_without_applying_deltas();
assert_eq!(other, Some(pop_out_bar), "the pop-out's own bar");
assert_eq!(main, Some(bar), "the main window's bar, not the pop-out's laid out after it");
let ppp = ctx.pixels_per_point();
Expand All @@ -1154,7 +1160,7 @@ mod tests {
// A window that lays out no bar this pass has none: last pass's bar is not this pass's.
// The pop-out, not drawn in this frame, keeps the bar of its own last pass.
let mut stale = Some(bar);
let _ = ctx.run_ui(main_input(), |ui| stale = bar_this_pass(ui.ctx()));
ctx.run_ui(main_input(), |ui| stale = bar_this_pass(ui.ctx())).drop_without_applying_deltas();
assert_eq!(stale, None);
assert_eq!(caption::hit(main_window, px(900.0), px(BAR / 2.0)), CaptionHit::Outside);
assert_eq!(caption::hit(pop_out_window, px(240.0), px(BAR / 2.0)), CaptionHit::Drag);
Expand Down Expand Up @@ -1280,7 +1286,7 @@ mod tests {
if let Some(v) = input.viewports.get_mut(&ViewportId::ROOT) {
v.native_window = Some(window);
}
let _ = ctx.run_ui(input, |ui| {
ctx.run_ui(input, |ui| {
// The view fills the window and takes clicks and drags.
ui.interact(ui.max_rect(), Id::unique("view"), Sense::click_and_drag());
let layer = |order, name: &'static str| LayerId::new(order, Id::unique(name));
Expand All @@ -1290,7 +1296,8 @@ mod tests {
let front = ui.new_child(egui::UiBuilder::new().layer_id(layer(Order::Foreground, "menu over the bar")).max_rect(ui.max_rect()));
front.interact(Rect::from_min_size(pos2(300.0, 0.0), vec2(200.0, 300.0)), Id::unique("menu row"), Sense::click());
}
});
})
.drop_without_applying_deltas();
};
let ppp = ctx.pixels_per_point();
let hit = |x: f32| caption::hit(window, (x * ppp) as i32, (BAR / 2.0 * ppp) as i32);
Expand All @@ -1312,7 +1319,7 @@ mod tests {
if let Some(v) = input.viewports.get_mut(&ViewportId::ROOT) {
v.native_window = Some(window);
}
let _ = ctx.run_ui(input, resize_zones);
ctx.run_ui(input, resize_zones).drop_without_applying_deltas();
}
ctx.read_response(Id::unique(("titlebar-resize", 0usize))).is_some()
};
Expand Down
3 changes: 2 additions & 1 deletion crates/viewport-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,14 @@ mod tests {
ctx.set_pixels_per_point(scale);
let card = Rect::from_min_size(origin, vec2(240.0, 160.0));
let radius = egui::CornerRadius { nw: if header { 0 } else { 8 }, ne: if header { 0 } else { 8 }, sw: 8, se: 8 };
let output = ctx.run_ui(egui::RawInput::default(), |ui| {
let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
let ctx = ui.ctx();
let painter = ctx.layer_painter(egui::LayerId::background());
let start = painter.add(egui::Shape::Noop);
painter.rect_filled(card, 0, egui::Color32::RED);
super::clip_card(&painter, start, card, radius);
});
output.textures_delta.clear();
let clips: Vec<_> =
output.shapes.iter().filter(|entry| matches!(entry.shape, egui::Shape::Rect(_))).map(|entry| entry.clip_rect).collect();
assert!(!clips.is_empty());
Expand Down
9 changes: 9 additions & 0 deletions crates/viewport-gpu/src/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,16 @@ fn shared(sharers: Sharers, policy: Policy) -> crate::Result<std::sync::Arc<Open
// (glibc). A thread that touched `HELD` before wgpu's thread-local destroyed wgpu's first, and
// the process aborted as the thread ended ("thread local panicked on drop", #10232). A poll
// takes the snatch lock, so wgpu's thread-local is in use before `HELD` and outlives it.
// On Metal, closing the queue waits for it inside an autorelease pool, and in a debug build
// objc2 records each pool in a thread-local of its own; a test thread that reused a device
// another opened had not used that one yet, and aborted the same way. Making a buffer opens
// a pool on Metal (and does nothing of the kind elsewhere), so objc2's thread-local outlives
// `HELD` too.
let _ = opened.1.poll(wgpu::PollType::Poll);
opened
.1
.create_buffer(&wgpu::BufferDescriptor { label: None, size: 4, usage: wgpu::BufferUsages::COPY_DST, mapped_at_creation: false })
.destroy();
HELD.with(|held| {
let mut held = held.borrow_mut();
if !held.iter().any(|mine| Arc::ptr_eq(mine, &opened)) {
Expand Down
3 changes: 2 additions & 1 deletion crates/window-gpu/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,8 @@ mod tests {
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(400.0, 300.0))), events, ..Default::default() };
let mut text = String::new();
let mut rect = egui::Rect::NOTHING;
let output = ctx.run_ui(raw, |ui| rect = ui.add(egui::TextEdit::singleline(&mut text).id(egui::Id::unique("text box"))).rect);
let mut output = ctx.run_ui(raw, |ui| rect = ui.add(egui::TextEdit::singleline(&mut text).id(egui::Id::unique("text box"))).rect);
output.textures_delta.clear();
(output, rect)
}

Expand Down
Loading