-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
221 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright © SixtyFPS GmbH <info@slint.dev> | ||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.2 OR LicenseRef-Slint-commercial | ||
|
||
fn main() { | ||
#[cfg(feature = "system-testing")] | ||
{ | ||
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); | ||
let proto_file = std::path::PathBuf::from(::std::env::var("CARGO_MANIFEST_DIR").unwrap()) | ||
.join("slint_systest.proto"); | ||
let config_builder = pb_rs::ConfigBuilder::new(&[proto_file], None, Some(&out_dir), &[]) | ||
.unwrap() | ||
.headers(false); | ||
pb_rs::types::FileDescriptor::run(&config_builder.build()).unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright © SixtyFPS GmbH <info@slint.dev> | ||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.2 OR LicenseRef-Slint-commercial | ||
|
||
syntax = "proto3"; | ||
|
||
message RequestWindowListMessage { | ||
} | ||
|
||
message RequestToAUT { | ||
oneof msg { | ||
RequestWindowListMessage request_window_list = 1; | ||
} | ||
} | ||
|
||
message WindowDetails { | ||
// Can add information such as size | ||
} | ||
|
||
message WindowListResponse { | ||
map<uint64, WindowDetails> windows = 1; | ||
} | ||
|
||
message AUTResponse { | ||
oneof msg { | ||
WindowListResponse window_list = 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Copyright © SixtyFPS GmbH <info@slint.dev> | ||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.2 OR LicenseRef-Slint-commercial | ||
|
||
use i_slint_core::debug_log; | ||
//use i_slint_core::api::invoke_from_event_loop; | ||
use i_slint_core::api::EventLoopError; | ||
//use i_slint_core::platform::WindowAdapter; | ||
//use std::cell::RefCell; | ||
//use std::rc::Rc; | ||
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; | ||
use quick_protobuf::{MessageRead, MessageWrite}; | ||
use smol::io::AsyncReadExt; | ||
use smol::io::AsyncWriteExt; | ||
use std::io::Cursor; | ||
|
||
#[allow(non_snake_case, unused_imports, non_camel_case_types)] | ||
mod proto { | ||
include!(concat!(env!("OUT_DIR"), "/slint_systest.rs")); | ||
} | ||
|
||
/* | ||
struct TestingClient { | ||
windows: RefCell<slab::Slab<Rc<dyn WindowAdapter>>>, | ||
} | ||
impl TestingClient { | ||
fn new() -> Self { | ||
todo!() | ||
} | ||
fn window_shown(self: Rc<Self>, adapter: Rc<dyn WindowAdapter>) { | ||
let id = self.windows.borrow_mut().insert(adapter); | ||
let _ = invoke_from_event_loop(move || eprintln!("{id}")); | ||
} | ||
} | ||
*/ | ||
|
||
async fn message_loop( | ||
server_addr: String, | ||
mut message_callback: impl FnMut( | ||
proto::mod_RequestToAUT::OneOfmsg, | ||
) -> Option<proto::mod_AUTResponse::OneOfmsg>, | ||
) { | ||
let mut stream = match smol::net::TcpStream::connect(server_addr.clone()).await { | ||
Ok(stream) => stream, | ||
Err(err) => { | ||
eprintln!("Error connecting to Slint test server at {server_addr}: {}", err); | ||
return; | ||
} | ||
}; | ||
debug_log!("Connected to test server"); | ||
|
||
loop { | ||
let mut message_size_buf = vec![0; 4]; | ||
let mut n = stream | ||
.read(&mut message_size_buf) | ||
.await | ||
.expect("Unable to read request header from AUT connection"); | ||
if n != 4 { | ||
panic!("fatal: unexpected AUT message header: received {n} expected 4") | ||
} | ||
let message_size: usize = | ||
Cursor::new(message_size_buf).read_u32::<BigEndian>().unwrap() as usize; | ||
let mut message_buf = Vec::with_capacity(message_size); | ||
message_buf.resize(message_size, 0); | ||
n = stream | ||
.read(&mut message_buf) | ||
.await | ||
.expect("Unable to read request data from AUT connection"); | ||
if n != message_size { | ||
panic!("fatal: unexpected AUT message body: received {n} expected {message_size}"); | ||
} | ||
|
||
let message = proto::RequestToAUT::from_reader( | ||
&mut quick_protobuf::reader::BytesReader::from_bytes(&message_buf), | ||
&mut message_buf, | ||
) | ||
.expect("Unable to de-serialize AUT request message"); | ||
let Some(response) = message_callback(message.msg) else { continue }; | ||
let response = proto::AUTResponse { msg: response }; | ||
let mut size_header = Vec::new(); | ||
size_header.write_u32::<BigEndian>(response.get_size() as u32).unwrap(); | ||
stream.write_all(&size_header).await.expect("Unable to write AUT response header"); | ||
let mut message_body = Vec::new(); | ||
response.write_message(&mut quick_protobuf::Writer::new(&mut message_body)).unwrap(); | ||
stream.write_all(&message_body).await.expect("Unable to write AUT response body"); | ||
} | ||
} | ||
|
||
pub fn init() -> Result<(), EventLoopError> { | ||
let Ok(server_addr) = std::env::var("SLINT_TEST_SERVER") else { | ||
return Ok(()); | ||
}; | ||
debug_log!("Attempting to connect to testing server at {server_addr}"); | ||
|
||
i_slint_core::future::spawn_local(async move { | ||
message_loop(server_addr, |request| { | ||
match request { | ||
proto::mod_RequestToAUT::OneOfmsg::request_window_list(..) => { | ||
proto::mod_AUTResponse::OneOfmsg::window_list(proto::WindowListResponse { | ||
windows: [(0, proto::WindowDetails::default())].into_iter().collect(), | ||
}) | ||
} | ||
proto::mod_RequestToAUT::OneOfmsg::None => return None, | ||
} | ||
.into() | ||
}) | ||
.await; | ||
})?; | ||
|
||
/* | ||
let Some(client) = TestingClient::connect() else { | ||
return Ok(()); | ||
}; | ||
i_slint_core::context::set_window_shown_hook(Some(Box::new(move |adapter| { | ||
client.window_shown(adapter); | ||
})))?; | ||
*/ | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters