autocommit 2022-05-01 17:23:55 CEST
This commit is contained in:
parent
4373ed05bf
commit
e1d5bf0e5d
39 changed files with 1772 additions and 57 deletions
61
src/it/test_ifs/test_shm_buffer.rs
Normal file
61
src/it/test_ifs/test_shm_buffer.rs
Normal 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 {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue