it: test region creation
This commit is contained in:
parent
6af9d909b8
commit
ae34a65efe
9 changed files with 179 additions and 35 deletions
|
|
@ -2,11 +2,14 @@ use {
|
|||
crate::{
|
||||
it::{
|
||||
test_error::TestError,
|
||||
test_ifs::test_surface::TestSurface,
|
||||
test_ifs::{test_region::TestRegion, test_surface::TestSurface},
|
||||
test_object::{Deleted, TestObject},
|
||||
test_transport::TestTransport,
|
||||
},
|
||||
wire::{wl_compositor::CreateSurface, WlCompositorId},
|
||||
wire::{
|
||||
wl_compositor::{CreateRegion, CreateSurface},
|
||||
WlCompositorId,
|
||||
},
|
||||
},
|
||||
std::{cell::Cell, rc::Rc},
|
||||
};
|
||||
|
|
@ -38,6 +41,28 @@ impl TestCompositor {
|
|||
self.tran.add_obj(surface.clone())?;
|
||||
Ok(surface)
|
||||
}
|
||||
|
||||
pub async fn create_region(&self) -> Result<Rc<TestRegion>, 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)?;
|
||||
let region = Rc::new(TestRegion {
|
||||
id,
|
||||
tran: self.tran.clone(),
|
||||
server,
|
||||
destroyed: Cell::new(false),
|
||||
deleted: Default::default(),
|
||||
expected: Default::default(),
|
||||
});
|
||||
self.tran.add_obj(region.clone())?;
|
||||
Ok(region)
|
||||
}
|
||||
}
|
||||
|
||||
test_object! {
|
||||
|
|
|
|||
81
src/it/test_ifs/test_region.rs
Normal file
81
src/it/test_ifs/test_region.rs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
use {
|
||||
crate::{
|
||||
ifs::wl_region::WlRegion,
|
||||
it::{
|
||||
test_error::TestError,
|
||||
test_object::{Deleted, TestObject},
|
||||
test_transport::TestTransport,
|
||||
},
|
||||
rect::{Rect, RegionBuilder},
|
||||
wire::{wl_region::*, WlRegionId},
|
||||
},
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
rc::Rc,
|
||||
},
|
||||
};
|
||||
|
||||
pub struct TestRegion {
|
||||
pub id: WlRegionId,
|
||||
pub tran: Rc<TestTransport>,
|
||||
pub destroyed: Cell<bool>,
|
||||
pub deleted: Deleted,
|
||||
pub server: Rc<WlRegion>,
|
||||
pub expected: RefCell<RegionBuilder>,
|
||||
}
|
||||
|
||||
impl TestRegion {
|
||||
pub fn destroy(&self) -> Result<(), TestError> {
|
||||
self.deleted.check()?;
|
||||
if !self.destroyed.replace(true) {
|
||||
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,
|
||||
x: rect.x1(),
|
||||
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,
|
||||
x: rect.x1(),
|
||||
y: rect.y1(),
|
||||
width: rect.width(),
|
||||
height: rect.height(),
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn check(&self) -> Result<(), TestError> {
|
||||
self.tran.sync().await;
|
||||
let expected = self.expected.borrow_mut().get();
|
||||
let actual = self.server.region();
|
||||
tassert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TestRegion {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
test_object! {
|
||||
TestRegion, WlRegion;
|
||||
}
|
||||
|
||||
impl TestObject for TestRegion {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue