mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge pull request #18495
Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
commit
39ee24d40a
1 file changed
+25
-23
@@ -11,13 +11,13 @@ fn described(h: &Harness<'_, Box<PhotocraftApp>>) -> Value {
|
||||
/// Runs the app's frames until the develop of the settings in force has landed, and returns the dialog's
|
||||
/// description. The develop waits on the framework's queue until a request finishes it, as the agent entry
|
||||
/// point's `waitPreview` does.
|
||||
fn settled(h: &mut Harness<'_, Box<PhotocraftApp>>) -> Value {
|
||||
h.run_steps(2);
|
||||
fn settled(h: &mut Harness<'_, Box<PhotocraftApp>>, previous_revision: u64) -> Value {
|
||||
for _ in 0..2000 {
|
||||
craft::ui::runtime::pending::finish_jobs(&h.ctx, std::time::Duration::from_secs(30));
|
||||
h.run_steps(1);
|
||||
let now = described(h);
|
||||
if now["previewPending"] == false && !now["histogram"].is_null() {
|
||||
let advanced = now["previewRevision"].as_u64().is_some_and(|revision| revision > previous_revision);
|
||||
if advanced && now["previewPending"] == false && !now["histogram"].is_null() {
|
||||
return now;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||
@@ -25,35 +25,32 @@ fn settled(h: &mut Harness<'_, Box<PhotocraftApp>>) -> Value {
|
||||
panic!("the Camera Raw preview never finished");
|
||||
}
|
||||
|
||||
/// A control request, then the develop it asks for.
|
||||
fn request(h: &mut Harness<'_, Box<PhotocraftApp>>, params: Value) -> Value {
|
||||
fn request(h: &mut Harness<'_, Box<PhotocraftApp>>, params: Value) {
|
||||
let ctx = h.ctx.clone();
|
||||
let reply = camera_raw_ui::menu(h.state_mut(), &ctx, "filter.cameraRaw", ¶ms).unwrap().unwrap();
|
||||
if described(h).is_null() {
|
||||
return reply;
|
||||
}
|
||||
settled(h)
|
||||
camera_raw_ui::menu(h.state_mut(), &ctx, "filter.cameraRaw", ¶ms).unwrap().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn histogram_matches_visible_preview_at_all_supported_depths_and_cancel_commit_are_reversible() {
|
||||
let mut h = Harness::builder().with_step_dt(1.0 / 60.0).with_size(egui::vec2(1200.0, 800.0)).build_eframe(|cc| {
|
||||
PhotocraftApp::setup_context(&cc.egui_ctx, AppTheme::pro());
|
||||
PhotocraftApp::with_context(cc.egui_ctx.clone(), photocraft_engine::Session::new(), Default::default())
|
||||
});
|
||||
for mode in ["rgb", "grayscale"] {
|
||||
for depth in [8, 16, 32] {
|
||||
let mut h = Harness::builder().with_step_dt(1.0 / 60.0).with_size(egui::vec2(1200.0, 800.0)).build_eframe(move |cc| {
|
||||
PhotocraftApp::setup_context(&cc.egui_ctx, AppTheme::pro());
|
||||
let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), photocraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 16, "height": 8, "mode": mode, "depth": depth})).unwrap();
|
||||
app.run("layer.new.layer", json!({})).unwrap();
|
||||
app.run("edit.fill", json!({"color": "#808080"})).unwrap();
|
||||
app
|
||||
});
|
||||
h.run_steps(3);
|
||||
let app = h.state_mut();
|
||||
app.run("file.new", json!({"width": 16, "height": 8, "mode": mode, "depth": depth})).unwrap();
|
||||
app.run("layer.new.layer", json!({})).unwrap();
|
||||
app.run("edit.fill", json!({"color": "#808080"})).unwrap();
|
||||
h.run_steps(1);
|
||||
let original = h.state().session.active().unwrap().doc.clone();
|
||||
let steps = h.state().session.active().unwrap().history.past_len();
|
||||
let initial = request(&mut h, json!({}));
|
||||
request(&mut h, json!({}));
|
||||
let initial = settled(&mut h, 0);
|
||||
assert_eq!(initial["histogram"]["samples"], 128);
|
||||
let changed = request(&mut h, json!({"ui": {"set": {"exposure": 1.0}}}));
|
||||
assert_ne!(changed["histogram"]["red"], initial["histogram"]["red"]);
|
||||
request(&mut h, json!({"ui": {"set": {"exposure": 1.0}}}));
|
||||
let changed = settled(&mut h, initial["previewRevision"].as_u64().unwrap());
|
||||
assert_ne!(changed["histogram"]["red"], initial["histogram"]["red"], "{mode}/{depth}: exposure must change the histogram");
|
||||
assert_eq!(h.state().session.active().unwrap().history.past_len(), steps);
|
||||
request(&mut h, json!({"ui": {"cancel": true}}));
|
||||
assert!(std::sync::Arc::ptr_eq(&h.state().session.active().unwrap().doc, &original), "Cancel leaves the document alone");
|
||||
@@ -62,8 +59,13 @@ fn histogram_matches_visible_preview_at_all_supported_depths_and_cancel_commit_a
|
||||
h.state_mut().run("edit.undo", json!({})).unwrap();
|
||||
assert!(std::sync::Arc::ptr_eq(&h.state().session.active().unwrap().doc, &original));
|
||||
h.state_mut().run("edit.redo", json!({})).unwrap();
|
||||
let committed = request(&mut h, json!({}));
|
||||
request(&mut h, json!({}));
|
||||
let committed = settled(&mut h, 0);
|
||||
assert_eq!(committed["histogram"]["red"], changed["histogram"]["red"], "{mode}/{depth}: graph and committed pixels disagree");
|
||||
request(&mut h, json!({"ui": {"cancel": true}}));
|
||||
assert!(described(&h).is_null(), "{mode}/{depth}: Camera Raw must close");
|
||||
h.state_mut().run("file.close", json!({"discard": true})).unwrap();
|
||||
assert!(h.state().session.active().is_none(), "{mode}/{depth}: the next case needs a fresh document");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user