From fd056c53616f5578c772c157acf7e42b38965e57 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Tue, 2 Apr 2024 21:25:49 +0200 Subject: [PATCH] it: test content type protocol --- src/ifs/wl_surface.rs | 2 +- src/it/test_ifs.rs | 2 + src/it/test_ifs/test_content_type.rs | 42 +++++++++++++ src/it/test_ifs/test_content_type_manager.rs | 65 ++++++++++++++++++++ src/it/test_ifs/test_registry.rs | 13 +++- src/it/test_transport.rs | 1 + src/it/tests.rs | 1 + src/it/tests/t0032_content_type.rs | 25 ++++++++ 8 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 src/it/test_ifs/test_content_type.rs create mode 100644 src/it/test_ifs/test_content_type_manager.rs create mode 100644 src/it/tests/t0032_content_type.rs diff --git a/src/ifs/wl_surface.rs b/src/ifs/wl_surface.rs index 29d09a86..236c2177 100644 --- a/src/ifs/wl_surface.rs +++ b/src/ifs/wl_surface.rs @@ -246,7 +246,7 @@ pub struct WlSurface { tearing: Cell, version: u32, pub has_content_type_manager: Cell, - content_type: Cell>, + pub content_type: Cell>, pub drm_feedback: CopyHashMap>, sync_obj_surface: CloneCell>>, destroyed: Cell, diff --git a/src/it/test_ifs.rs b/src/it/test_ifs.rs index 6b4c9896..5a9283d5 100644 --- a/src/it/test_ifs.rs +++ b/src/it/test_ifs.rs @@ -1,6 +1,8 @@ mod test_buffer; pub mod test_callback; pub mod test_compositor; +pub mod test_content_type; +pub mod test_content_type_manager; pub mod test_cursor_shape_device; pub mod test_cursor_shape_manager; pub mod test_data_device; diff --git a/src/it/test_ifs/test_content_type.rs b/src/it/test_ifs/test_content_type.rs new file mode 100644 index 00000000..541f3ac8 --- /dev/null +++ b/src/it/test_ifs/test_content_type.rs @@ -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, + pub destroyed: Cell, +} + +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 {} diff --git a/src/it/test_ifs/test_content_type_manager.rs b/src/it/test_ifs/test_content_type_manager.rs new file mode 100644 index 00000000..5089c56e --- /dev/null +++ b/src/it/test_ifs/test_content_type_manager.rs @@ -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, + pub destroyed: Cell, +} + +impl TestContentTypeManager { + pub fn new(tran: &Rc) -> 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> { + 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 {} diff --git a/src/it/test_ifs/test_registry.rs b/src/it/test_ifs/test_registry.rs index 98332137..a093c59b 100644 --- a/src/it/test_ifs/test_registry.rs +++ b/src/it/test_ifs/test_registry.rs @@ -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>>, pub cursor_shape_manager: CloneCell>>, pub syncobj_manager: CloneCell>>, + pub content_type_manager: CloneCell>>, pub seats: CopyHashMap>, } @@ -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( &self, diff --git a/src/it/test_transport.rs b/src/it/test_transport.rs index 630e8805..6a76936f 100644 --- a/src/it/test_transport.rs +++ b/src/it/test_transport.rs @@ -64,6 +64,7 @@ impl TestTransport { data_device_manager: Default::default(), cursor_shape_manager: Default::default(), syncobj_manager: Default::default(), + content_type_manager: Default::default(), seats: Default::default(), }); self.send(wl_display::GetRegistry { diff --git a/src/it/tests.rs b/src/it/tests.rs index 6dd4aec4..cfb51ecf 100644 --- a/src/it/tests.rs +++ b/src/it/tests.rs @@ -62,6 +62,7 @@ mod t0028_top_level_restacking; mod t0029_double_click_float; mod t0030_cursor_shape; mod t0031_syncobj; +mod t0032_content_type; pub trait TestCase: Sync { fn name(&self) -> &'static str; diff --git a/src/it/tests/t0032_content_type.rs b/src/it/tests/t0032_content_type.rs new file mode 100644 index 00000000..f8b460d2 --- /dev/null +++ b/src/it/tests/t0032_content_type.rs @@ -0,0 +1,25 @@ +use { + crate::{ + ifs::wp_content_type_v1::ContentType, + it::{test_error::TestResult, testrun::TestRun}, + }, + std::rc::Rc, +}; + +testcase!(); + +async fn test(run: Rc) -> TestResult { + let _ds = run.create_default_setup().await?; + + let client = run.create_client().await?; + let surface = client.comp.create_surface().await?; + let ctm = client.registry.get_content_type_manager().await?; + let ct = ctm.get_surface_content_type(&surface)?; + ct.set_content_type(2)?; + surface.commit()?; + client.sync().await; + + tassert_eq!(surface.server.content_type.get(), Some(ContentType::Video)); + + Ok(()) +}