diff --git a/src/it/test_ifs/test_callback.rs b/src/it/test_ifs/test_callback.rs index 61353831..0fa1163a 100644 --- a/src/it/test_ifs/test_callback.rs +++ b/src/it/test_ifs/test_callback.rs @@ -1,9 +1,7 @@ use { crate::{ it::{ - test_error::TestError, - test_object::{Deleted, TestObject}, - test_transport::TestTransport, + test_error::TestError, test_object::TestObject, test_transport::TestTransport, testrun::ParseFull, }, utils::buffd::MsgParser, @@ -17,7 +15,6 @@ pub struct TestCallback { pub tran: Rc, pub handler: Cell>>, pub done: Cell, - pub deleted: Deleted, } impl TestCallback { diff --git a/src/it/test_ifs/test_compositor.rs b/src/it/test_ifs/test_compositor.rs index cf03ac43..7bfc989a 100644 --- a/src/it/test_ifs/test_compositor.rs +++ b/src/it/test_ifs/test_compositor.rs @@ -3,7 +3,7 @@ use { it::{ test_error::TestError, test_ifs::{test_region::TestRegion, test_surface::TestSurface}, - test_object::{Deleted, TestObject}, + test_object::TestObject, test_transport::TestTransport, }, wire::{ @@ -17,17 +17,15 @@ use { pub struct TestCompositor { pub id: WlCompositorId, pub tran: Rc, - pub deleted: Deleted, } impl TestCompositor { pub async fn create_surface(&self) -> Result, TestError> { let id = self.tran.id(); - self.deleted.check()?; self.tran.send(CreateSurface { self_id: self.id, id, - }); + })?; self.tran.sync().await; let client = self.tran.get_client()?; let server = client.lookup(id)?; @@ -36,7 +34,6 @@ impl TestCompositor { tran: self.tran.clone(), server, destroyed: Cell::new(false), - deleted: Default::default(), }); self.tran.add_obj(surface.clone())?; Ok(surface) @@ -44,11 +41,10 @@ impl TestCompositor { pub async fn create_region(&self) -> Result, TestError> { let id = self.tran.id(); - self.deleted.check()?; self.tran.send(CreateRegion { self_id: self.id, id, - }); + })?; self.tran.sync().await; let client = self.tran.get_client()?; let server = client.lookup(id)?; @@ -57,7 +53,6 @@ impl TestCompositor { tran: self.tran.clone(), server, destroyed: Cell::new(false), - deleted: Default::default(), expected: Default::default(), }); self.tran.add_obj(region.clone())?; diff --git a/src/it/test_ifs/test_display.rs b/src/it/test_ifs/test_display.rs index 7de5d505..531beed9 100644 --- a/src/it/test_ifs/test_display.rs +++ b/src/it/test_ifs/test_display.rs @@ -1,9 +1,7 @@ use { crate::{ it::{ - test_error::TestError, - test_object::{Deleted, TestObject}, - test_transport::TestTransport, + test_error::TestError, test_object::TestObject, test_transport::TestTransport, testrun::ParseFull, }, object::ObjectId, @@ -16,7 +14,6 @@ use { pub struct TestDisplay { pub tran: Rc, pub id: WlDisplayId, - pub deleted: Deleted, } impl TestDisplay { @@ -38,7 +35,6 @@ impl TestDisplay { ); } Some(obj) => { - obj.deleted().set(); obj.on_remove(&self.tran); self.tran.obj_ids.borrow_mut().release(ev.id); } diff --git a/src/it/test_ifs/test_jay_compositor.rs b/src/it/test_ifs/test_jay_compositor.rs index 7fdb13c7..e01211e4 100644 --- a/src/it/test_ifs/test_jay_compositor.rs +++ b/src/it/test_ifs/test_jay_compositor.rs @@ -2,11 +2,8 @@ use { crate::{ client::ClientId, it::{ - test_error::TestError, - test_ifs::test_screenshot::TestJayScreenshot, - test_object::{Deleted, TestObject}, - test_transport::TestTransport, - testrun::ParseFull, + test_error::TestError, test_ifs::test_screenshot::TestJayScreenshot, + test_object::TestObject, test_transport::TestTransport, testrun::ParseFull, }, utils::buffd::MsgParser, wire::{ @@ -22,14 +19,12 @@ pub struct TestJayCompositor { pub id: JayCompositorId, pub tran: Rc, pub client_id: Cell>, - pub deleted: Deleted, } impl TestJayCompositor { pub async fn get_client_id(&self) -> Result { if self.client_id.get().is_none() { - self.deleted.check()?; - self.tran.send(GetClientId { self_id: self.id }); + self.tran.send(GetClientId { self_id: self.id })?; } self.tran.sync().await; match self.client_id.get() { @@ -42,13 +37,11 @@ impl TestJayCompositor { let js = Rc::new(TestJayScreenshot { id: self.tran.id(), result: Cell::new(None), - deleted: Default::default(), }); - self.deleted.check()?; self.tran.send(TakeScreenshot { self_id: self.id, id: js.id, - }); + })?; self.tran.add_obj(js.clone())?; self.tran.sync().await; match js.result.take() { diff --git a/src/it/test_ifs/test_region.rs b/src/it/test_ifs/test_region.rs index b2835447..aa7f5d6e 100644 --- a/src/it/test_ifs/test_region.rs +++ b/src/it/test_ifs/test_region.rs @@ -1,11 +1,7 @@ use { crate::{ ifs::wl_region::WlRegion, - it::{ - test_error::TestError, - test_object::{Deleted, TestObject}, - test_transport::TestTransport, - }, + it::{test_error::TestError, test_object::TestObject, test_transport::TestTransport}, rect::{Rect, RegionBuilder}, wire::{wl_region::*, WlRegionId}, }, @@ -19,22 +15,19 @@ pub struct TestRegion { pub id: WlRegionId, pub tran: Rc, pub destroyed: Cell, - pub deleted: Deleted, pub server: Rc, pub expected: RefCell, } impl TestRegion { pub fn destroy(&self) -> Result<(), TestError> { - self.deleted.check()?; if !self.destroyed.replace(true) { - self.tran.send(Destroy { self_id: self.id }); + self.tran.send(Destroy { self_id: self.id })?; } Ok(()) } pub fn add(&self, rect: Rect) -> Result<(), TestError> { - self.deleted.check()?; self.expected.borrow_mut().add(rect); self.tran.send(Add { self_id: self.id, @@ -42,12 +35,11 @@ impl TestRegion { y: rect.y1(), width: rect.width(), height: rect.height(), - }); + })?; Ok(()) } pub fn subtract(&self, rect: Rect) -> Result<(), TestError> { - self.deleted.check()?; self.expected.borrow_mut().sub(rect); self.tran.send(Subtract { self_id: self.id, @@ -55,7 +47,7 @@ impl TestRegion { y: rect.y1(), width: rect.width(), height: rect.height(), - }); + })?; Ok(()) } diff --git a/src/it/test_ifs/test_registry.rs b/src/it/test_ifs/test_registry.rs index b366d019..28410852 100644 --- a/src/it/test_ifs/test_registry.rs +++ b/src/it/test_ifs/test_registry.rs @@ -8,7 +8,7 @@ use { test_compositor::TestCompositor, test_jay_compositor::TestJayCompositor, test_shm::TestShm, test_xdg_base::TestXdgWmBase, }, - test_object::{Deleted, TestObject}, + test_object::TestObject, test_transport::TestTransport, testrun::ParseFull, }, @@ -41,7 +41,6 @@ pub struct TestRegistry { pub shm: CloneCell>>, pub xdg: CloneCell>>, pub seats: CopyHashMap>, - pub deleted: Deleted, } macro_rules! singleton { @@ -100,7 +99,6 @@ impl TestRegistry { id: self.tran.id(), tran: self.tran.clone(), client_id: Default::default(), - deleted: Default::default(), }); self.bind(&jc, singletons.jay_compositor, 1)?; self.jay_compositor.set(Some(jc.clone())); @@ -114,7 +112,6 @@ impl TestRegistry { let jc = Rc::new(TestCompositor { id: self.tran.id(), tran: self.tran.clone(), - deleted: Default::default(), }); self.bind(&jc, singletons.wl_compositor, 4)?; self.compositor.set(Some(jc.clone())); @@ -130,7 +127,6 @@ impl TestRegistry { tran: self.tran.clone(), formats: Default::default(), formats_awaited: Cell::new(false), - deleted: Default::default(), }); self.bind(&jc, singletons.wl_shm, 1)?; self.shm.set(Some(jc.clone())); @@ -145,7 +141,6 @@ impl TestRegistry { id: self.tran.id(), tran: self.tran.clone(), destroyed: Cell::new(false), - deleted: Default::default(), }); self.bind(&jc, singletons.xdg_wm_base, 3)?; self.xdg.set(Some(jc.clone())); @@ -158,14 +153,13 @@ impl TestRegistry { name: u32, version: u32, ) -> Result<(), TestError> { - self.deleted.check()?; self.tran.send(Bind { self_id: self.id, name, interface: obj.interface().name(), version, id: obj.id().into(), - }); + })?; self.tran.add_obj(obj.clone())?; Ok(()) } diff --git a/src/it/test_ifs/test_screenshot.rs b/src/it/test_ifs/test_screenshot.rs index 021b158f..e3d21d32 100644 --- a/src/it/test_ifs/test_screenshot.rs +++ b/src/it/test_ifs/test_screenshot.rs @@ -1,10 +1,6 @@ use { crate::{ - it::{ - test_error::TestError, - test_object::{Deleted, TestObject}, - testrun::ParseFull, - }, + it::{test_error::TestError, test_object::TestObject, testrun::ParseFull}, utils::buffd::MsgParser, wire::{jay_screenshot::*, JayScreenshotId}, }, @@ -14,7 +10,6 @@ use { pub struct TestJayScreenshot { pub id: JayScreenshotId, pub result: Cell>>, - pub deleted: Deleted, } impl TestJayScreenshot { diff --git a/src/it/test_ifs/test_shm.rs b/src/it/test_ifs/test_shm.rs index c0458d84..daf6c57a 100644 --- a/src/it/test_ifs/test_shm.rs +++ b/src/it/test_ifs/test_shm.rs @@ -1,12 +1,8 @@ use { crate::{ it::{ - test_error::TestError, - test_ifs::test_shm_pool::TestShmPool, - test_mem::TestMem, - test_object::{Deleted, TestObject}, - test_transport::TestTransport, - testrun::ParseFull, + test_error::TestError, test_ifs::test_shm_pool::TestShmPool, test_mem::TestMem, + test_object::TestObject, test_transport::TestTransport, testrun::ParseFull, }, utils::{buffd::MsgParser, clonecell::CloneCell, copyhashmap::CopyHashMap}, wire::{wl_shm::*, WlShmId}, @@ -19,7 +15,6 @@ pub struct TestShm { pub tran: Rc, pub formats: CopyHashMap, pub formats_awaited: Cell, - pub deleted: Deleted, } impl TestShm { @@ -37,15 +32,13 @@ impl TestShm { tran: self.tran.clone(), mem: CloneCell::new(mem.clone()), destroyed: Cell::new(false), - deleted: Default::default(), }); - self.deleted.check()?; self.tran.send(CreatePool { self_id: self.id, id: pool.id, fd: mem.fd.clone(), size: size as _, - }); + })?; self.tran.add_obj(pool.clone())?; Ok(pool) } diff --git a/src/it/test_ifs/test_shm_buffer.rs b/src/it/test_ifs/test_shm_buffer.rs index 1addf118..0c291faf 100644 --- a/src/it/test_ifs/test_shm_buffer.rs +++ b/src/it/test_ifs/test_shm_buffer.rs @@ -1,11 +1,8 @@ use { crate::{ it::{ - test_error::TestError, - test_mem::TestMem, - test_object::{Deleted, TestObject}, - test_transport::TestTransport, - testrun::ParseFull, + test_error::TestError, test_mem::TestMem, test_object::TestObject, + test_transport::TestTransport, testrun::ParseFull, }, theme::Color, utils::{buffd::MsgParser, windows::WindowsExt}, @@ -25,7 +22,6 @@ pub struct TestShmBuffer { pub mem: Rc, pub released: Cell, pub destroyed: Cell, - pub deleted: Deleted, } impl TestShmBuffer { @@ -43,8 +39,7 @@ impl TestShmBuffer { if self.destroyed.replace(true) { return Ok(()); } - self.deleted.check()?; - self.tran.send(Destroy { self_id: self.id }); + self.tran.send(Destroy { self_id: self.id })?; Ok(()) } diff --git a/src/it/test_ifs/test_shm_pool.rs b/src/it/test_ifs/test_shm_pool.rs index eeb57b03..8d4053f1 100644 --- a/src/it/test_ifs/test_shm_pool.rs +++ b/src/it/test_ifs/test_shm_pool.rs @@ -2,11 +2,8 @@ use { crate::{ format::Format, it::{ - test_error::TestError, - test_ifs::test_shm_buffer::TestShmBuffer, - test_mem::TestMem, - test_object::{Deleted, TestObject}, - test_transport::TestTransport, + test_error::TestError, test_ifs::test_shm_buffer::TestShmBuffer, test_mem::TestMem, + test_object::TestObject, test_transport::TestTransport, }, utils::clonecell::CloneCell, wire::{wl_shm_pool::*, WlShmPoolId}, @@ -19,7 +16,6 @@ pub struct TestShmPool { pub tran: Rc, pub mem: CloneCell>, pub destroyed: Cell, - pub deleted: Deleted, } impl TestShmPool { @@ -45,10 +41,8 @@ impl TestShmPool { mem, released: Cell::new(true), destroyed: Cell::new(false), - deleted: Default::default(), }); self.tran.add_obj(buffer.clone())?; - self.deleted.check()?; self.tran.send(CreateBuffer { self_id: self.id, id: buffer.id, @@ -57,18 +51,17 @@ impl TestShmPool { height, stride, format: format.wl_id.unwrap_or(format.drm), - }); + })?; Ok(buffer) } pub fn resize(&self, size: usize) -> Result<(), TestError> { let mem = self.mem.get().grow(size)?; self.mem.set(mem); - self.deleted.check()?; self.tran.send(Resize { self_id: self.id, size: size as _, - }); + })?; Ok(()) } @@ -76,8 +69,7 @@ impl TestShmPool { if self.destroyed.replace(true) { return Ok(()); } - self.deleted.check()?; - self.tran.send(Destroy { self_id: self.id }); + self.tran.send(Destroy { self_id: self.id })?; Ok(()) } } diff --git a/src/it/test_ifs/test_surface.rs b/src/it/test_ifs/test_surface.rs index 8e3c016c..837f7894 100644 --- a/src/it/test_ifs/test_surface.rs +++ b/src/it/test_ifs/test_surface.rs @@ -2,9 +2,7 @@ use { crate::{ ifs::wl_surface::WlSurface, it::{ - test_error::TestError, - test_object::{Deleted, TestObject}, - test_transport::TestTransport, + test_error::TestError, test_object::TestObject, test_transport::TestTransport, testrun::ParseFull, }, utils::buffd::MsgParser, @@ -18,32 +16,28 @@ pub struct TestSurface { pub tran: Rc, pub server: Rc, pub destroyed: Cell, - pub deleted: Deleted, } impl TestSurface { pub fn destroy(&self) -> Result<(), TestError> { if !self.destroyed.replace(true) { - self.deleted.check()?; - self.tran.send(Destroy { self_id: self.id }); + self.tran.send(Destroy { self_id: self.id })?; } Ok(()) } pub fn attach(&self, buffer_id: WlBufferId) -> Result<(), TestError> { - self.deleted.check()?; self.tran.send(Attach { self_id: self.id, buffer: buffer_id, x: 0, y: 0, - }); + })?; Ok(()) } pub fn commit(&self) -> Result<(), TestError> { - self.deleted.check()?; - self.tran.send(Commit { self_id: self.id }); + self.tran.send(Commit { self_id: self.id })?; Ok(()) } diff --git a/src/it/test_ifs/test_xdg_base.rs b/src/it/test_ifs/test_xdg_base.rs index ba8cff97..0ab5324c 100644 --- a/src/it/test_ifs/test_xdg_base.rs +++ b/src/it/test_ifs/test_xdg_base.rs @@ -1,11 +1,8 @@ use { crate::{ it::{ - test_error::TestError, - test_ifs::test_xdg_surface::TestXdgSurface, - test_object::{Deleted, TestObject}, - test_transport::TestTransport, - testrun::ParseFull, + test_error::TestError, test_ifs::test_xdg_surface::TestXdgSurface, + test_object::TestObject, test_transport::TestTransport, testrun::ParseFull, }, utils::buffd::MsgParser, wire::{xdg_wm_base::*, WlSurfaceId, XdgWmBaseId}, @@ -17,14 +14,12 @@ pub struct TestXdgWmBase { pub id: XdgWmBaseId, pub tran: Rc, pub destroyed: Cell, - pub deleted: Deleted, } impl TestXdgWmBase { pub fn destroy(&self) -> Result<(), TestError> { if !self.destroyed.replace(true) { - self.deleted.check()?; - self.tran.send(Destroy { self_id: self.id }); + self.tran.send(Destroy { self_id: self.id })?; } Ok(()) } @@ -34,12 +29,11 @@ impl TestXdgWmBase { surface: WlSurfaceId, ) -> Result, TestError> { let id = self.tran.id(); - self.deleted.check()?; self.tran.send(GetXdgSurface { self_id: self.id, id, surface, - }); + })?; self.tran.sync().await; let client = self.tran.get_client()?; let server = client.lookup(id)?; @@ -49,7 +43,6 @@ impl TestXdgWmBase { server, destroyed: Cell::new(false), last_serial: Cell::new(0), - deleted: Default::default(), }); self.tran.add_obj(xdg.clone())?; Ok(xdg) diff --git a/src/it/test_ifs/test_xdg_surface.rs b/src/it/test_ifs/test_xdg_surface.rs index a54939d3..17c2d6e7 100644 --- a/src/it/test_ifs/test_xdg_surface.rs +++ b/src/it/test_ifs/test_xdg_surface.rs @@ -2,11 +2,8 @@ use { crate::{ ifs::wl_surface::xdg_surface::XdgSurface, it::{ - test_error::TestError, - test_ifs::test_xdg_toplevel::TestXdgToplevel, - test_object::{Deleted, TestObject}, - test_transport::TestTransport, - testrun::ParseFull, + test_error::TestError, test_ifs::test_xdg_toplevel::TestXdgToplevel, + test_object::TestObject, test_transport::TestTransport, testrun::ParseFull, }, utils::buffd::MsgParser, wire::{xdg_surface::*, XdgSurfaceId}, @@ -20,25 +17,22 @@ pub struct TestXdgSurface { pub server: Rc, pub destroyed: Cell, pub last_serial: Cell, - pub deleted: Deleted, } impl TestXdgSurface { pub fn destroy(&self) -> Result<(), TestError> { if !self.destroyed.replace(true) { - self.deleted.check()?; - self.tran.send(Destroy { self_id: self.id }); + self.tran.send(Destroy { self_id: self.id })?; } Ok(()) } pub async fn create_toplevel(&self) -> Result, TestError> { let id = self.tran.id(); - self.deleted.check()?; self.tran.send(GetToplevel { self_id: self.id, id, - }); + })?; self.tran.sync().await; let client = self.tran.get_client()?; let server = client.lookup(id)?; @@ -47,7 +41,6 @@ impl TestXdgSurface { tran: self.tran.clone(), destroyed: Cell::new(false), server, - deleted: Default::default(), width: Cell::new(0), height: Cell::new(0), states: Default::default(), @@ -58,11 +51,10 @@ impl TestXdgSurface { } pub fn ack_configure(&self, serial: u32) -> Result<(), TestError> { - self.deleted.check()?; self.tran.send(AckConfigure { self_id: self.id, serial, - }); + })?; Ok(()) } diff --git a/src/it/test_ifs/test_xdg_toplevel.rs b/src/it/test_ifs/test_xdg_toplevel.rs index 9261a3ff..7f5b600e 100644 --- a/src/it/test_ifs/test_xdg_toplevel.rs +++ b/src/it/test_ifs/test_xdg_toplevel.rs @@ -2,9 +2,7 @@ use { crate::{ ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel, it::{ - test_error::TestError, - test_object::{Deleted, TestObject}, - test_transport::TestTransport, + test_error::TestError, test_object::TestObject, test_transport::TestTransport, testrun::ParseFull, }, utils::buffd::MsgParser, @@ -22,7 +20,6 @@ pub struct TestXdgToplevel { pub tran: Rc, pub destroyed: Cell, pub server: Rc, - pub deleted: Deleted, pub width: Cell, pub height: Cell, @@ -34,8 +31,7 @@ pub struct TestXdgToplevel { impl TestXdgToplevel { pub fn destroy(&self) -> Result<(), TestError> { if !self.destroyed.replace(true) { - self.deleted.check()?; - self.tran.send(Destroy { self_id: self.id }); + self.tran.send(Destroy { self_id: self.id })?; } Ok(()) } diff --git a/src/it/test_object.rs b/src/it/test_object.rs index db97aa0a..a19d32bd 100644 --- a/src/it/test_object.rs +++ b/src/it/test_object.rs @@ -4,7 +4,7 @@ use { object::{Interface, ObjectId}, utils::buffd::MsgParser, }, - std::{cell::Cell, rc::Rc}, + std::rc::Rc, }; macro_rules! test_object { @@ -14,10 +14,6 @@ macro_rules! test_object { self.id.into() } - fn deleted(&self) -> &Deleted { - &self.deleted - } - #[allow(unused_variables, unreachable_code)] fn handle_request( self: std::rc::Rc, @@ -41,25 +37,8 @@ macro_rules! test_object { }; } -#[derive(Default)] -pub struct Deleted(Cell); - -impl Deleted { - pub fn set(&self) { - self.0.set(true); - } - - pub fn check(&self) -> Result<(), TestError> { - match self.0.get() { - true => bail!("Object has already been deleted"), - _ => Ok(()), - } - } -} - pub trait TestObjectBase: 'static { fn id(&self) -> ObjectId; - fn deleted(&self) -> &Deleted; fn handle_request( self: Rc, request: u32, diff --git a/src/it/test_transport.rs b/src/it/test_transport.rs index c5637671..719479d1 100644 --- a/src/it/test_transport.rs +++ b/src/it/test_transport.rs @@ -55,12 +55,12 @@ impl TestTransport { shm: Default::default(), xdg: Default::default(), seats: Default::default(), - deleted: Default::default(), }); self.send(wl_display::GetRegistry { self_id: WL_DISPLAY_ID, registry: reg.id, - }); + }) + .unwrap(); let _ = self.add_obj(reg.clone()); reg } @@ -98,12 +98,12 @@ impl TestTransport { tran: self.clone(), handler: Cell::new(None), done: Cell::new(self.killed.get()), - deleted: Default::default(), }); self.send(wl_display::Sync { self_id: WL_DISPLAY_ID, callback: cb.id, - }); + }) + .unwrap(); let _ = self.add_obj(cb.clone()); futures_util::future::poll_fn(move |ctx| { if cb.done.get() { @@ -147,9 +147,16 @@ impl TestTransport { )); } - pub fn send(&self, msg: M) { + pub fn send(&self, msg: M) -> Result<(), TestError> { if self.killed.get() { - return; + return Ok(()); + } + let obj = match self.objects.get(&msg.id()) { + Some(obj) => obj, + _ => bail!("Object with id {} has already been deleted", msg.id()), + }; + if obj.interface().name() != msg.interface().name() { + bail!("Object with id {} has an incompatible interface", msg.id()); } let mut fds = vec![]; let mut swapchain = self.swapchain.borrow_mut(); @@ -160,6 +167,7 @@ impl TestTransport { swapchain.commit(); } self.flush_request.trigger(); + Ok(()) } } diff --git a/src/it/testrun.rs b/src/it/testrun.rs index 57fbfe9a..a9db48ea 100644 --- a/src/it/testrun.rs +++ b/src/it/testrun.rs @@ -73,7 +73,6 @@ impl TestRun { tran.add_obj(Rc::new(TestDisplay { tran: tran.clone(), id: WL_DISPLAY_ID, - deleted: Default::default(), }))?; tran.init(); let registry = tran.get_registry();