1
0
Fork 0
forked from wry/wry

it: test content type protocol

This commit is contained in:
Julian Orth 2024-04-02 21:25:49 +02:00
parent 3b0757ee53
commit fd056c5361
8 changed files with 149 additions and 2 deletions

View file

@ -0,0 +1,42 @@
use {
crate::{
it::{test_error::TestError, test_object::TestObject, test_transport::TestTransport},
wire::{wp_content_type_v1::*, WpContentTypeV1Id},
},
std::{cell::Cell, rc::Rc},
};
pub struct TestContentType {
pub id: WpContentTypeV1Id,
pub tran: Rc<TestTransport>,
pub destroyed: Cell<bool>,
}
impl TestContentType {
pub fn destroy(&self) -> Result<(), TestError> {
if !self.destroyed.replace(true) {
self.tran.send(Destroy { self_id: self.id })?;
}
Ok(())
}
pub fn set_content_type(&self, content_type: u32) -> Result<(), TestError> {
self.tran.send(SetContentType {
self_id: self.id,
content_type,
})?;
Ok(())
}
}
impl Drop for TestContentType {
fn drop(&mut self) {
let _ = self.destroy();
}
}
test_object! {
TestContentType, WpContentTypeV1;
}
impl TestObject for TestContentType {}

View file

@ -0,0 +1,65 @@
use {
crate::{
it::{
test_error::{TestError, TestResult},
test_ifs::{test_content_type::TestContentType, test_surface::TestSurface},
test_object::TestObject,
test_transport::TestTransport,
},
wire::{wp_content_type_manager_v1::*, WpContentTypeManagerV1Id},
},
std::{cell::Cell, rc::Rc},
};
pub struct TestContentTypeManager {
pub id: WpContentTypeManagerV1Id,
pub tran: Rc<TestTransport>,
pub destroyed: Cell<bool>,
}
impl TestContentTypeManager {
pub fn new(tran: &Rc<TestTransport>) -> Self {
Self {
id: tran.id(),
tran: tran.clone(),
destroyed: Cell::new(false),
}
}
pub fn destroy(&self) -> Result<(), TestError> {
if !self.destroyed.replace(true) {
self.tran.send(Destroy { self_id: self.id })?;
}
Ok(())
}
pub fn get_surface_content_type(
&self,
surface: &TestSurface,
) -> TestResult<Rc<TestContentType>> {
let obj = Rc::new(TestContentType {
id: self.tran.id(),
tran: self.tran.clone(),
destroyed: Cell::new(false),
});
self.tran.add_obj(obj.clone())?;
self.tran.send(GetSurfaceContentType {
self_id: self.id,
id: obj.id,
surface: surface.id,
})?;
Ok(obj)
}
}
impl Drop for TestContentTypeManager {
fn drop(&mut self) {
let _ = self.destroy();
}
}
test_object! {
TestContentTypeManager, WpContentTypeManagerV1;
}
impl TestObject for TestContentTypeManager {}

View file

@ -5,7 +5,8 @@ use {
it::{
test_error::TestError,
test_ifs::{
test_compositor::TestCompositor, test_cursor_shape_manager::TestCursorShapeManager,
test_compositor::TestCompositor, test_content_type_manager::TestContentTypeManager,
test_cursor_shape_manager::TestCursorShapeManager,
test_data_device_manager::TestDataDeviceManager,
test_ext_foreign_toplevel_list::TestExtForeignToplevelList,
test_jay_compositor::TestJayCompositor, test_shm::TestShm,
@ -43,6 +44,7 @@ pub struct TestRegistrySingletons {
pub wl_data_device_manager: u32,
pub wp_cursor_shape_manager_v1: u32,
pub wp_linux_drm_syncobj_manager_v1: u32,
pub wp_content_type_manager_v1: u32,
}
pub struct TestRegistry {
@ -62,6 +64,7 @@ pub struct TestRegistry {
pub data_device_manager: CloneCell<Option<Rc<TestDataDeviceManager>>>,
pub cursor_shape_manager: CloneCell<Option<Rc<TestCursorShapeManager>>>,
pub syncobj_manager: CloneCell<Option<Rc<TestSyncobjManager>>>,
pub content_type_manager: CloneCell<Option<Rc<TestContentTypeManager>>>,
pub seats: CopyHashMap<GlobalName, Rc<WlSeatGlobal>>,
}
@ -125,6 +128,7 @@ impl TestRegistry {
wl_data_device_manager,
wp_cursor_shape_manager_v1,
wp_linux_drm_syncobj_manager_v1,
wp_content_type_manager_v1,
};
self.singletons.set(Some(singletons.clone()));
Ok(singletons)
@ -190,6 +194,13 @@ impl TestRegistry {
1,
TestSyncobjManager
);
create_singleton!(
get_content_type_manager,
content_type_manager,
wp_content_type_manager_v1,
1,
TestContentTypeManager
);
pub fn bind<O: TestObject>(
&self,