1
0
Fork 0
forked from wry/wry

it: test xdg-activation

This commit is contained in:
Julian Orth 2024-04-02 15:03:24 +02:00
parent 91022cd1c8
commit 6fe6b1b491
16 changed files with 239 additions and 23 deletions

View file

@ -0,0 +1,56 @@
use {
crate::{
it::{
test_error::TestError, test_object::TestObject, test_transport::TestTransport,
testrun::ParseFull,
},
utils::buffd::MsgParser,
wire::{xdg_activation_token_v1::*, XdgActivationTokenV1Id},
},
std::{cell::Cell, rc::Rc},
};
pub struct TestXdgActivationToken {
pub id: XdgActivationTokenV1Id,
pub tran: Rc<TestTransport>,
pub destroyed: Cell<bool>,
pub token: Cell<Option<String>>,
}
impl TestXdgActivationToken {
pub fn destroy(&self) -> Result<(), TestError> {
if !self.destroyed.replace(true) {
self.tran.send(Destroy { self_id: self.id })?;
}
Ok(())
}
pub async fn commit(&self) -> Result<String, TestError> {
self.tran.send(Commit { self_id: self.id })?;
self.tran.sync().await;
match self.token.take() {
Some(t) => Ok(t),
_ => bail!("Server did not send a token"),
}
}
fn handle_done(&self, parser: MsgParser<'_, '_>) -> Result<(), TestError> {
let ev = Done::parse_full(parser)?;
self.token.set(Some(ev.token.to_string()));
Ok(())
}
}
test_object! {
TestXdgActivationToken, XdgActivationTokenV1;
DONE => handle_done,
}
impl TestObject for TestXdgActivationToken {}
impl Drop for TestXdgActivationToken {
fn drop(&mut self) {
let _ = self.destroy();
}
}