-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #455 from betrusted-io/mtxchat-layout-tests
WIP: Mtxchat layout refactor
- Loading branch information
Showing
14 changed files
with
639 additions
and
219 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,42 @@ | ||
[package] | ||
name = "chat-test" | ||
version = "0.1.0" | ||
authors = ["bunnie <[email protected]>"] | ||
edition = "2021" | ||
description = "Chat UI test routines" | ||
|
||
# Dependency versions enforced by Cargo.lock. | ||
[dependencies] | ||
log = "0.4.14" | ||
num-derive = { version = "0.3.3", default-features = false} | ||
num-traits = { version = "0.2.14", default-features = false} | ||
xous = "0.9.54" | ||
xous-ipc = "0.9.54" | ||
log-server = { package = "xous-api-log", version = "0.1.50" } | ||
ticktimer-server = { package = "xous-api-ticktimer", version = "0.9.50" } | ||
xous-names = { package = "xous-api-names", version = "0.9.52" } | ||
gam = { path = "../../services/gam" } | ||
graphics-server = { path = "../../services/graphics-server" } | ||
trng = { path = "../../services/trng"} | ||
locales = { path = "../../locales"} | ||
ime-plugin-api = { path = "../../services/ime-plugin-api"} | ||
ime-plugin-shell = { path = "../../services/ime-plugin-shell"} | ||
content-plugin-api = { path = "../../services/content-plugin-api"} # all content canvas providers must provide this API | ||
codec = { path = "../../services/codec"} | ||
com = { path = "../../services/com"} | ||
com_rs = { git = "https://github.com/betrusted-io/com_rs", rev = "891bdd3ca8e41f81510d112483e178aea3e3a921" } | ||
llio = { path = "../../services/llio"} | ||
net = { path = "../../services/net" } | ||
pddb = { path = "../../services/pddb" } | ||
# new dependencies for mtxcli | ||
chat = { path = "../../libs/chat" } | ||
modals = { path = "../../services/modals" } | ||
percent-encoding = "2.2" | ||
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} | ||
serde = { version = "1.0", features = [ "derive" ] } | ||
tls = { path = "../../libs/tls" } | ||
ureq = { version = "2.7.1", features = ["json"] } | ||
url = "2.2.2" | ||
|
||
[features] | ||
default = [] |
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,5 @@ | ||
# chat-test | ||
|
||
Routines for testing aspects of the chat application APIs. | ||
|
||
Not suitable for human consumption, side effects include confusion, frustration, and panic attacks. |
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,32 @@ | ||
#[allow(dead_code)] | ||
pub(crate) const SERVER_NAME_MTXCHAT: &str = "_Matrix chat_"; | ||
|
||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] | ||
pub enum ChatTestOp { | ||
/// chat ui event | ||
Event = 0, | ||
/// menu item click | ||
Menu, | ||
/// chat ui user post | ||
Post, | ||
/// chat ui keystroke | ||
Rawkeys, | ||
/// exit the application | ||
Quit, | ||
} | ||
|
||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] | ||
pub enum MenuOp { | ||
Login, | ||
Logout, | ||
Noop, | ||
Room, | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub struct Msg { | ||
pub type_: String, | ||
pub body: Option<String>, | ||
pub sender: Option<String>, | ||
pub ts: Option<u64>, | ||
} |
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,112 @@ | ||
#![cfg_attr(target_os = "none", no_std)] | ||
#![cfg_attr(target_os = "none", no_main)] | ||
|
||
mod api; | ||
mod tests; | ||
|
||
use api::*; | ||
use chat::{Chat, Event, POST_TEXT_MAX}; | ||
use num_traits::*; | ||
use xous_ipc::Buffer; | ||
|
||
fn main() -> ! { | ||
let stack_size = 1024 * 1024; | ||
std::thread::Builder::new() | ||
.stack_size(stack_size) | ||
.spawn(wrapped_main) | ||
.unwrap() | ||
.join() | ||
.unwrap() | ||
} | ||
|
||
fn wrapped_main() -> ! { | ||
log_server::init_wait().unwrap(); | ||
log::set_max_level(log::LevelFilter::Info); | ||
log::info!("my PID is {}", xous::process::id()); | ||
|
||
const HEAP_LARGER_LIMIT: usize = 2048 * 1024; | ||
let new_limit = HEAP_LARGER_LIMIT; | ||
let result = xous::rsyscall(xous::SysCall::AdjustProcessLimit( | ||
xous::Limits::HeapMaximum as usize, | ||
0, | ||
new_limit, | ||
)); | ||
|
||
if let Ok(xous::Result::Scalar2(1, current_limit)) = result { | ||
xous::rsyscall(xous::SysCall::AdjustProcessLimit( | ||
xous::Limits::HeapMaximum as usize, | ||
current_limit, | ||
new_limit, | ||
)) | ||
.unwrap(); | ||
log::info!("Heap limit increased to: {}", new_limit); | ||
} else { | ||
panic!("Unsupported syscall!"); | ||
} | ||
|
||
let xns = xous_names::XousNames::new().unwrap(); | ||
let sid = xns | ||
.register_name(SERVER_NAME_MTXCHAT, None) | ||
.expect("can't register server"); | ||
log::trace!("registered with NS -- {:?}", sid); | ||
|
||
let chat = Chat::new( | ||
gam::APP_NAME_CHAT_TEST, | ||
gam::APP_MENU_0_CHAT_TEST, | ||
Some(xous::connect(sid).unwrap()), | ||
Some(ChatTestOp::Post as usize), | ||
Some(ChatTestOp::Event as usize), | ||
Some(ChatTestOp::Rawkeys as usize), | ||
); | ||
// not used yet, but probably will use in the future | ||
let _cid = xous::connect(sid).unwrap(); | ||
|
||
tests::test_ui(&chat); | ||
loop { | ||
let msg = xous::receive_message(sid).unwrap(); | ||
log::debug!("got message {:?}", msg); | ||
match FromPrimitive::from_usize(msg.body.id()) { | ||
Some(ChatTestOp::Event) => { | ||
log::info!("got Chat UI Event"); | ||
xous::msg_scalar_unpack!(msg, event_code, _, _, _, { | ||
match FromPrimitive::from_usize(event_code) { | ||
Some(Event::Focus) => { | ||
chat.redraw(); | ||
} | ||
_ => (), | ||
} | ||
}); | ||
} | ||
Some(ChatTestOp::Menu) => { | ||
log::info!("got Chat Menu Click"); | ||
xous::msg_scalar_unpack!(msg, menu_code, _, _, _, { | ||
let code: Option<MenuOp> = FromPrimitive::from_usize(menu_code); | ||
log::info!("Got menu code {:?}", code); | ||
}); | ||
} | ||
Some(ChatTestOp::Post) => { | ||
let buffer = | ||
unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; | ||
let s = buffer | ||
.to_original::<xous_ipc::String<{ POST_TEXT_MAX }>, _>() | ||
.unwrap(); | ||
if s.len() > 0 { | ||
// capture input instead of calling here, so message can drop and calling server is released | ||
log::info!("got Post {:?}", s.to_string()); | ||
} | ||
} | ||
Some(ChatTestOp::Rawkeys) => log::info!("got rawkeys"), | ||
Some(ChatTestOp::Quit) => { | ||
log::error!("got Quit"); | ||
break; | ||
} | ||
_ => (), | ||
} | ||
} | ||
// clean up our program | ||
log::error!("main loop exit, destroying servers"); | ||
xns.unregister_server(sid).unwrap(); | ||
xous::destroy_server(sid).unwrap(); | ||
log::trace!("quitting"); | ||
xous::terminate_process(0) | ||
} |
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,30 @@ | ||
use chat::Chat; | ||
|
||
pub fn test_ui(chat: &Chat) { | ||
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(); | ||
for i in 0..5 { | ||
chat.post_add("alice", 1_700_000_005 + i*4, &format!("alice sez {}", i), None).ok(); | ||
chat.post_add("bob", 1_700_000_006 + i*4, &format!("bob sez {}", i), None).ok(); | ||
chat.post_add("trent", 1_700_000_007 + i*4, &format!("trent sez {}", i), None).ok(); | ||
} | ||
chat.post_add("alice", 1_700_001_000, "eom", None).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!("test setup done"); | ||
} |
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
Oops, something went wrong.