1
0
Fork 0
forked from wry/wry

autocommit 2022-05-01 17:23:55 CEST

This commit is contained in:
Julian Orth 2022-05-01 17:23:55 +02:00
parent 4373ed05bf
commit e1d5bf0e5d
39 changed files with 1772 additions and 57 deletions

View file

@ -0,0 +1,61 @@
use {
crate::{
it::{
test_error::TestError, test_mem::TestMem, test_object::TestObject,
test_transport::TestTransport, testrun::ParseFull,
},
utils::buffd::MsgParser,
wire::{wl_buffer::*, WlBufferId},
},
std::{
cell::Cell,
ops::{Deref, Range},
rc::Rc,
},
};
pub struct TestShmBuffer {
pub id: WlBufferId,
pub transport: Rc<TestTransport>,
pub range: Range<usize>,
pub mem: Rc<TestMem>,
pub released: Cell<bool>,
pub destroyed: Cell<bool>,
}
impl TestShmBuffer {
pub fn destroy(&self) {
if self.destroyed.replace(true) {
return;
}
self.transport.send(Destroy { self_id: self.id });
}
fn handle_release(&self, parser: MsgParser<'_, '_>) -> Result<(), TestError> {
let _ev = Release::parse_full(parser)?;
self.released.set(true);
Ok(())
}
}
impl Deref for TestShmBuffer {
type Target = [Cell<u8>];
fn deref(&self) -> &Self::Target {
&self.mem[self.range.clone()]
}
}
impl Drop for TestShmBuffer {
fn drop(&mut self) {
self.destroy();
}
}
test_object! {
TestShmBuffer, WlBuffer;
RELEASE => handle_release,
}
impl TestObject for TestShmBuffer {}