1
0
Fork 0
forked from wry/wry

it: test region creation

This commit is contained in:
Julian Orth 2022-05-03 16:30:05 +02:00
parent 6af9d909b8
commit ae34a65efe
9 changed files with 179 additions and 35 deletions

View 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 {}