Use Niri::insert_client() in tests
Browse files at this commit902222675af78b07d01b905fd3a76fc1df89e55eParent: ec434932 changed files +14 -16
- src/tests/client.rs +4 -14
- src/tests/fixture.rs +10 -2
src/tests/client.rsmodified+4 -14
| @@ -1,13 +1,11 @@ | |||
| 1 | use std::cmp::min; | 1 | use std::cmp::min; |
| 2 | use std::collections::HashMap; | 2 | use std::collections::HashMap; |
| 3 | -use std::ffi::OsStr; | 3 | +use std::fmt; |
| 4 | use std::fmt::Write as _; | 4 | use std::fmt::Write as _; |
| 5 | use std::os::unix::net::UnixStream; | 5 | use std::os::unix::net::UnixStream; |
| 6 | -use std::path::PathBuf; | ||
| 7 | use std::sync::atomic::{AtomicBool, Ordering}; | 6 | use std::sync::atomic::{AtomicBool, Ordering}; |
| 8 | use std::sync::Arc; | 7 | use std::sync::Arc; |
| 9 | use std::time::Duration; | 8 | use std::time::Duration; |
| 10 | -use std::{env, fmt}; | ||
| 11 | 9 | ||
| 12 | use calloop::EventLoop; | 10 | use calloop::EventLoop; |
| 13 | use calloop_wayland_source::WaylandSource; | 11 | use calloop_wayland_source::WaylandSource; |
| @@ -105,21 +103,13 @@ impl fmt::Display for Configure { | |||
| 105 | } | 103 | } |
| 106 | } | 104 | } |
| 107 | 105 | ||
| 108 | -fn connect(socket_name: &OsStr) -> Connection { | ||
| 109 | - let mut socket_path = PathBuf::from(env::var_os("XDG_RUNTIME_DIR").unwrap()); | ||
| 110 | - socket_path.push(socket_name); | ||
| 111 | - | ||
| 112 | - let stream = UnixStream::connect(socket_path).unwrap(); | ||
| 113 | - let backend = Backend::connect(stream).unwrap(); | ||
| 114 | - Connection::from_backend(backend) | ||
| 115 | -} | ||
| 116 | - | ||
| 117 | impl Client { | 106 | impl Client { |
| 118 | - pub fn new(socket_name: &OsStr) -> Self { | 107 | + pub fn new(stream: UnixStream) -> Self { |
| 119 | let id = ClientId::next(); | 108 | let id = ClientId::next(); |
| 120 | 109 | ||
| 121 | let event_loop = EventLoop::try_new().unwrap(); | 110 | let event_loop = EventLoop::try_new().unwrap(); |
| 122 | - let connection = connect(socket_name); | 111 | + let backend = Backend::connect(stream).unwrap(); |
| 112 | + let connection = Connection::from_backend(backend); | ||
| 123 | let queue = connection.new_event_queue(); | 113 | let queue = connection.new_event_queue(); |
| 124 | let qh = queue.handle(); | 114 | let qh = queue.handle(); |
| 125 | WaylandSource::new(connection.clone(), queue) | 115 | WaylandSource::new(connection.clone(), queue) |
src/tests/fixture.rsmodified+10 -2
| @@ -1,4 +1,5 @@ | |||
| 1 | use std::os::fd::AsFd as _; | 1 | use std::os::fd::AsFd as _; |
| 2 | +use std::os::unix::net::UnixStream; | ||
| 2 | use std::sync::atomic::Ordering; | 3 | use std::sync::atomic::Ordering; |
| 3 | use std::time::Duration; | 4 | use std::time::Duration; |
| 4 | 5 | ||
| @@ -9,7 +10,7 @@ use smithay::output::Output; | |||
| 9 | 10 | ||
| 10 | use super::client::{Client, ClientId}; | 11 | use super::client::{Client, ClientId}; |
| 11 | use super::server::Server; | 12 | use super::server::Server; |
| 12 | -use crate::niri::Niri; | 13 | +use crate::niri::{NewClient, Niri}; |
| 13 | 14 | ||
| 14 | pub struct Fixture { | 15 | pub struct Fixture { |
| 15 | pub event_loop: EventLoop<'static, State>, | 16 | pub event_loop: EventLoop<'static, State>, |
| @@ -88,7 +89,14 @@ impl Fixture { | |||
| 88 | } | 89 | } |
| 89 | 90 | ||
| 90 | pub fn add_client(&mut self) -> ClientId { | 91 | pub fn add_client(&mut self) -> ClientId { |
| 91 | - let client = Client::new(&self.state.server.state.niri.socket_name); | 92 | + let (sock1, sock2) = UnixStream::pair().unwrap(); |
| 93 | + self.niri().insert_client(NewClient { | ||
| 94 | + client: sock1, | ||
| 95 | + restricted: false, | ||
| 96 | + credentials_unknown: false, | ||
| 97 | + }); | ||
| 98 | + | ||
| 99 | + let client = Client::new(sock2); | ||
| 92 | let id = client.id; | 100 | let id = client.id; |
| 93 | 101 | ||
| 94 | let fd = client.event_loop.as_fd().try_clone_to_owned().unwrap(); | 102 | let fd = client.event_loop.as_fd().try_clone_to_owned().unwrap(); |