From 60db6053bc2645cb2f49f345119bbb35bc437cc9 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 28 Nov 2023 17:25:27 +0800 Subject: [PATCH] add a feature for testing the UI on mtxchat when `test-chat-ui` is selected as a feature and mtxchat is selected as an app to build, this will override the mainloop of the `mtxchat` app and create a test dialog & present it, laying a framework for controlled debugging of the layout engine. --- apps/mtxchat/Cargo.toml | 1 + apps/mtxchat/src/main.rs | 5 +++++ apps/mtxchat/src/tests.rs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 apps/mtxchat/src/tests.rs diff --git a/apps/mtxchat/Cargo.toml b/apps/mtxchat/Cargo.toml index f4fcc7dd4..837e3bdd3 100644 --- a/apps/mtxchat/Cargo.toml +++ b/apps/mtxchat/Cargo.toml @@ -41,3 +41,4 @@ url = "2.2.2" [features] default = [] +test-chat-ui = [] diff --git a/apps/mtxchat/src/main.rs b/apps/mtxchat/src/main.rs index 0b7ea6ef3..04f1a29bd 100644 --- a/apps/mtxchat/src/main.rs +++ b/apps/mtxchat/src/main.rs @@ -2,6 +2,9 @@ #![cfg_attr(target_os = "none", no_main)] mod api; +#[cfg(feature="test-chat-ui")] +mod tests; + use api::*; use chat::{Chat, Event, POST_TEXT_MAX}; use gam::{MenuItem, MenuPayload}; @@ -97,6 +100,8 @@ fn wrapped_main() -> ! { let mut mtxchat = MtxChat::new(&chat); let mut first_focus = true; let mut user_post: Option = None; + #[cfg(feature="test-chat-ui")] + tests::test_ui(&chat); loop { let msg = xous::receive_message(sid).unwrap(); log::debug!("got message {:?}", msg); diff --git a/apps/mtxchat/src/tests.rs b/apps/mtxchat/src/tests.rs new file mode 100644 index 000000000..01f150bed --- /dev/null +++ b/apps/mtxchat/src/tests.rs @@ -0,0 +1,34 @@ +use chat::Chat; + +pub fn test_ui(chat: &Chat) { + let tt = ticktimer_server::Ticktimer::new().unwrap(); + let pddb = pddb::Pddb::new(); + // nuke any existing test dictionary, if it exists + pddb.delete_dict("tests.ui", None).ok(); + pddb.sync().ok(); + + // re-create the test room from scratch every time + chat.dialogue_set("tests.ui", Some("test_room")).expect("couldn't set dialog"); + + // generate a list of test posts that are repeatable each time + chat.post_add("alice", 1_700_000_000, "hello world!", None).ok(); + chat.post_add("bob", 1_700_000_002, "hi alice!", None).ok(); + + tt.sleep_ms(2000).ok(); + log::info!("triggering save"); + xous::send_message( + chat.cid(), + xous::Message::new_scalar(chat::ChatOp::DialogueSave as usize, 0, 0, 0, 0), + ) + .expect("failed to send new inbound msgs"); + + log::info!("sleep"); + tt.sleep_ms(5000).ok(); + log::info!("redraw"); + chat.redraw(); + + loop { + tt.sleep_ms(5000).ok(); + log::info!("test done, displaying result"); + } +}