diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-01-27 08:15:51 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-01-27 08:16:09 +0300 |
| commit | 902222675af78b07d01b905fd3a76fc1df89e55e (patch) | |
| tree | 34289d664b4a5a22e80c62a5bc784121296ede64 /src/tests | |
| parent | ec43493522b82907943b4f5371d2c24d238f2c3c (diff) | |
| download | niri-902222675af78b07d01b905fd3a76fc1df89e55e.tar.gz niri-902222675af78b07d01b905fd3a76fc1df89e55e.tar.bz2 niri-902222675af78b07d01b905fd3a76fc1df89e55e.zip | |
Use Niri::insert_client() in tests
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/client.rs | 18 | ||||
| -rw-r--r-- | src/tests/fixture.rs | 12 |
2 files changed, 14 insertions, 16 deletions
diff --git a/src/tests/client.rs b/src/tests/client.rs index 4ab3d989..531db72c 100644 --- a/src/tests/client.rs +++ b/src/tests/client.rs @@ -1,13 +1,11 @@ use std::cmp::min; use std::collections::HashMap; -use std::ffi::OsStr; +use std::fmt; use std::fmt::Write as _; use std::os::unix::net::UnixStream; -use std::path::PathBuf; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::time::Duration; -use std::{env, fmt}; use calloop::EventLoop; use calloop_wayland_source::WaylandSource; @@ -105,21 +103,13 @@ impl fmt::Display for Configure { } } -fn connect(socket_name: &OsStr) -> Connection { - let mut socket_path = PathBuf::from(env::var_os("XDG_RUNTIME_DIR").unwrap()); - socket_path.push(socket_name); - - let stream = UnixStream::connect(socket_path).unwrap(); - let backend = Backend::connect(stream).unwrap(); - Connection::from_backend(backend) -} - impl Client { - pub fn new(socket_name: &OsStr) -> Self { + pub fn new(stream: UnixStream) -> Self { let id = ClientId::next(); let event_loop = EventLoop::try_new().unwrap(); - let connection = connect(socket_name); + let backend = Backend::connect(stream).unwrap(); + let connection = Connection::from_backend(backend); let queue = connection.new_event_queue(); let qh = queue.handle(); WaylandSource::new(connection.clone(), queue) diff --git a/src/tests/fixture.rs b/src/tests/fixture.rs index 6485fab8..f7bef77d 100644 --- a/src/tests/fixture.rs +++ b/src/tests/fixture.rs @@ -1,4 +1,5 @@ use std::os::fd::AsFd as _; +use std::os::unix::net::UnixStream; use std::sync::atomic::Ordering; use std::time::Duration; @@ -9,7 +10,7 @@ use smithay::output::Output; use super::client::{Client, ClientId}; use super::server::Server; -use crate::niri::Niri; +use crate::niri::{NewClient, Niri}; pub struct Fixture { pub event_loop: EventLoop<'static, State>, @@ -88,7 +89,14 @@ impl Fixture { } pub fn add_client(&mut self) -> ClientId { - let client = Client::new(&self.state.server.state.niri.socket_name); + let (sock1, sock2) = UnixStream::pair().unwrap(); + self.niri().insert_client(NewClient { + client: sock1, + restricted: false, + credentials_unknown: false, + }); + + let client = Client::new(sock2); let id = client.id; let fd = client.event_loop.as_fd().try_clone_to_owned().unwrap(); |
