1
0
Fork 0
forked from wry/wry

autocommit 2022-05-02 00:00:45 CEST

This commit is contained in:
Julian Orth 2022-05-02 00:00:45 +02:00
parent 04580c4aeb
commit 552c8a9950
8 changed files with 155 additions and 43 deletions

View file

@ -26,6 +26,7 @@ mod test_ifs;
mod test_logger; mod test_logger;
mod test_mem; mod test_mem;
mod test_transport; mod test_transport;
mod test_utils;
mod testrun; mod testrun;
mod tests; mod tests;
@ -64,6 +65,7 @@ struct ItRun {
} }
fn run_test(it_run: &ItRun, test: &'static dyn TestCase) { fn run_test(it_run: &ItRun, test: &'static dyn TestCase) {
log::info!("Running {}", test.name());
let dir = format!("{}/{}", it_run.path, test.name()); let dir = format!("{}/{}", it_run.path, test.name());
std::fs::create_dir_all(&dir).unwrap(); std::fs::create_dir_all(&dir).unwrap();
let log_path = format!("{}/log", dir); let log_path = format!("{}/log", dir);

View file

@ -2,6 +2,7 @@ use {
crate::{ crate::{
cli::screenshot::buf_to_qoi, cli::screenshot::buf_to_qoi,
client::Client, client::Client,
format::ARGB8888,
it::{ it::{
test_error::TestError, test_error::TestError,
test_ifs::{ test_ifs::{
@ -9,10 +10,13 @@ use {
test_registry::TestRegistry, test_shm::TestShm, test_xdg_base::TestXdgWmBase, test_registry::TestRegistry, test_shm::TestShm, test_xdg_base::TestXdgWmBase,
}, },
test_transport::TestTransport, test_transport::TestTransport,
test_utils::test_window::TestWindow,
testrun::TestRun, testrun::TestRun,
}, },
theme::Color,
utils::clonecell::CloneCell,
}, },
std::rc::Rc, std::{cell::Cell, rc::Rc},
}; };
pub struct TestClient { pub struct TestClient {
@ -27,19 +31,39 @@ pub struct TestClient {
} }
impl TestClient { impl TestClient {
#[allow(dead_code)]
pub fn error(&self, msg: &str) { pub fn error(&self, msg: &str) {
self.tran.error(msg) self.tran.error(msg)
} }
pub async fn sync(self: &Rc<Self>) { pub async fn sync(&self) {
self.tran.sync().await self.tran.sync().await
} }
#[allow(dead_code)]
pub async fn take_screenshot(&self) -> Result<Vec<u8>, TestError> { pub async fn take_screenshot(&self) -> Result<Vec<u8>, TestError> {
let dmabuf = self.jc.take_screenshot().await?; let dmabuf = self.jc.take_screenshot().await?;
let qoi = buf_to_qoi(&dmabuf); let qoi = buf_to_qoi(&dmabuf);
Ok(qoi) Ok(qoi)
} }
pub async fn create_window(&self) -> Result<Rc<TestWindow>, TestError> {
let surface = self.comp.create_surface().await?;
let shm = self.shm.create_pool(0)?;
let buffer = shm.create_buffer(0, 0, 0, 0, ARGB8888)?;
let xdg = self.xdg.create_xdg_surface(surface.id).await?;
let tl = xdg.create_toplevel().await?;
surface.commit();
self.sync().await;
Ok(Rc::new(TestWindow {
surface,
xdg,
tl,
shm,
buffer: CloneCell::new(buffer),
color: Cell::new(Color::from_rgba_straight(0, 0, 0, 0)),
}))
}
} }
impl Drop for TestClient { impl Drop for TestClient {

1
src/it/test_utils.rs Normal file
View file

@ -0,0 +1 @@
pub mod test_window;

View file

@ -0,0 +1,48 @@
use {
crate::{
format::ARGB8888,
it::{
test_error::TestError,
test_ifs::{
test_shm_buffer::TestShmBuffer, test_shm_pool::TestShmPool,
test_surface::TestSurface, test_xdg_surface::TestXdgSurface,
test_xdg_toplevel::TestXdgToplevel,
},
},
theme::Color,
utils::clonecell::CloneCell,
},
std::{cell::Cell, rc::Rc},
};
pub struct TestWindow {
pub surface: Rc<TestSurface>,
pub xdg: Rc<TestXdgSurface>,
pub tl: Rc<TestXdgToplevel>,
pub shm: Rc<TestShmPool>,
pub buffer: CloneCell<Rc<TestShmBuffer>>,
pub color: Cell<Color>,
}
impl TestWindow {
pub async fn map(&self) -> Result<(), TestError> {
let width = self.tl.width.get();
let height = self.tl.height.get();
let stride = width * 4;
let size = (stride * height) as usize;
self.shm.resize(size)?;
let buffer = self.shm.create_buffer(0, width, height, stride, ARGB8888)?;
buffer.fill(self.color.get());
self.surface.attach(buffer.id);
self.xdg.ack_configure(self.xdg.last_serial.get());
self.surface.commit();
self.buffer.set(buffer);
self.surface.tran.sync().await;
Ok(())
}
#[allow(dead_code)]
pub fn set_color(&self, r: u8, g: u8, b: u8, a: u8) {
self.color.set(Color::from_rgba_straight(r, g, b, a));
}
}

View file

@ -55,6 +55,7 @@ macro_rules! tassert_eq {
mod t0001_shm_formats; mod t0001_shm_formats;
mod t0002_window; mod t0002_window;
mod t0003_multi_window;
pub trait TestCase { pub trait TestCase {
fn name(&self) -> &'static str; fn name(&self) -> &'static str;
@ -62,5 +63,18 @@ pub trait TestCase {
} }
pub fn tests() -> Vec<&'static dyn TestCase> { pub fn tests() -> Vec<&'static dyn TestCase> {
vec![&t0001_shm_formats::Test, &t0002_window::Test] macro_rules! tests {
($($module:ident,)*) => {
vec![
$(
&$module::Test,
)*
]
}
}
tests! {
t0001_shm_formats,
t0002_window,
t0003_multi_window,
}
} }

View file

@ -1,8 +1,8 @@
use { use {
crate::{ crate::{
format::ARGB8888,
it::{test_error::TestError, testrun::TestRun}, it::{test_error::TestError, testrun::TestRun},
theme::Color, rect::Rect,
tree::Node,
}, },
std::rc::Rc, std::rc::Rc,
}; };
@ -14,43 +14,26 @@ async fn test(run: Rc<TestRun>) -> Result<(), TestError> {
run.backend.install_default(); run.backend.install_default();
let client = run.create_client().await?; let client = run.create_client().await?;
let surface = client.comp.create_surface().await?;
let xdg_surface = client.xdg.create_xdg_surface(surface.id).await?;
let xdg_toplevel = xdg_surface.create_toplevel().await?;
surface.commit();
client.sync().await;
{ let window = client.create_window().await?;
let pool = client.shm.create_pool(0)?; window.map().await?;
let buffer = pool.create_buffer(0, 0, 0, 0, ARGB8888)?;
xdg_surface.ack_configure(xdg_surface.last_serial.get());
surface.attach(buffer.id);
surface.commit();
client.sync().await;
}
tassert_eq!(xdg_toplevel.width.get(), 800); tassert_eq!(window.tl.width.get(), 800);
tassert!(xdg_toplevel.height.get() >= 500); tassert_eq!(
window.tl.height.get(),
600 - 2 * (run.state.theme.title_height.get() + 1)
);
{ tassert_eq!(
let pool = client window.tl.server.node_absolute_position(),
.shm Rect::new_sized(
.create_pool((xdg_toplevel.width.get() * xdg_toplevel.height.get() * 4) as _)?;
let buffer = pool.create_buffer(
0, 0,
xdg_toplevel.width.get(), 2 * (run.state.theme.title_height.get() + 1),
xdg_toplevel.height.get(), window.tl.width.get(),
xdg_toplevel.width.get() * 4, window.tl.height.get(),
ARGB8888, )
)?; .unwrap()
buffer.fill(Color::from_rgba_straight(255, 0, 0, 100)); );
xdg_surface.ack_configure(xdg_surface.last_serial.get());
surface.attach(buffer.id);
surface.commit();
}
let screenshot = client.take_screenshot().await?;
std::fs::write(format!("{}/screenshot.qoi", run.dir), screenshot)?;
Ok(()) Ok(())
} }

View file

@ -0,0 +1,38 @@
use {
crate::{
it::{test_error::TestError, testrun::TestRun},
rect::Rect,
tree::Node,
},
std::rc::Rc,
};
testcase!();
/// Create and map two surfaces
async fn test(run: Rc<TestRun>) -> Result<(), TestError> {
run.backend.install_default();
let client = run.create_client().await?;
let window = client.create_window().await?;
window.map().await?;
let window2 = client.create_window().await?;
window2.map().await?;
let otop = 2 * (run.state.theme.title_height.get() + 1);
let bw = run.state.theme.border_width.get();
tassert_eq!(
window.tl.server.node_absolute_position(),
Rect::new_sized(0, otop, (800 - bw) / 2, 600 - otop).unwrap()
);
tassert_eq!(
window2.tl.server.node_absolute_position(),
Rect::new_sized((800 - bw) / 2 + bw, otop, (800 - bw) / 2, 600 - otop).unwrap()
);
Ok(())
}

View file

@ -241,15 +241,17 @@ impl State {
pub fn map_tiled_on(self: &Rc<Self>, node: Rc<dyn ToplevelNode>, ws: &Rc<WorkspaceNode>) { pub fn map_tiled_on(self: &Rc<Self>, node: Rc<dyn ToplevelNode>, ws: &Rc<WorkspaceNode>) {
if let Some(c) = ws.container.get() { if let Some(c) = ws.container.get() {
let la = c.tl_last_active_child(); let la = c.clone().tl_last_active_child();
let lap = la let lap = la
.tl_data() .tl_data()
.parent .parent
.get() .get()
.unwrap() .and_then(|n| n.node_into_container());
.node_into_container() if let Some(lap) = lap {
.unwrap(); lap.add_child_after(la.tl_as_node(), node);
lap.add_child_after(la.tl_as_node(), node); } else {
c.append_child(node);
}
} else { } else {
let container = let container =
ContainerNode::new(self, &ws, ws.clone(), node, ContainerSplit::Horizontal); ContainerNode::new(self, &ws, ws.clone(), node, ContainerSplit::Horizontal);