2021-12-15 17:48:11 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
use std::thread;
|
|
|
|
|
use gam::*;
|
|
|
|
|
|
|
|
|
|
use xous_names::XousNames;
|
|
|
|
|
|
2021-12-16 16:32:44 +00:00
|
|
|
const RADIO_TEST: [&'static str; 4] = [
|
|
|
|
|
"zebra",
|
|
|
|
|
"cow",
|
|
|
|
|
"horse",
|
|
|
|
|
"cat",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const CHECKBOX_TEST: [&'static str; 5] = [
|
|
|
|
|
"happy",
|
|
|
|
|
"😃",
|
|
|
|
|
"安",
|
|
|
|
|
"peaceful",
|
|
|
|
|
"...something else!",
|
|
|
|
|
];
|
|
|
|
|
|
2022-03-29 19:40:11 +00:00
|
|
|
/// This is an integration test of the Modals crate. It creates two competing threads
|
|
|
|
|
/// that both try to throw up dialog boxes at the same time. Normally you *don't* want
|
|
|
|
|
/// to do that, but we should still handle that case gracefully since it does happen
|
|
|
|
|
/// sometimes.
|
|
|
|
|
///
|
|
|
|
|
/// Each thread will create a series of Modal primitives, including progess bars, notifications,
|
|
|
|
|
/// check boxes and radio boxes.
|
2021-12-15 17:48:11 +00:00
|
|
|
pub(crate) fn spawn_test() {
|
2021-12-16 17:55:36 +00:00
|
|
|
// spawn two threads that compete for modal resources, to test the interlocking mechanisms
|
2021-12-15 17:48:11 +00:00
|
|
|
thread::spawn({
|
|
|
|
|
move || {
|
|
|
|
|
let xns = XousNames::new().unwrap();
|
2021-12-16 13:39:49 +00:00
|
|
|
let modals = modals::Modals::new(&xns).unwrap();
|
|
|
|
|
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
|
|
|
|
|
2022-04-22 07:10:51 +00:00
|
|
|
// 0. multi-modal test
|
|
|
|
|
log::info!("modal data: {:#?}",
|
|
|
|
|
modals.alert_builder("Four items with maybe defaults. Press select to close.")
|
|
|
|
|
.field(Some("first".to_string()), None)
|
|
|
|
|
.field(Some("second".to_string()), None)
|
|
|
|
|
.field(None, None)
|
|
|
|
|
.field(Some("fourth".to_string()), None)
|
|
|
|
|
.build()
|
|
|
|
|
);
|
|
|
|
|
|
2022-03-29 19:40:11 +00:00
|
|
|
// 1. test progress bar
|
|
|
|
|
// The start and end items are deliberately structured to be not zero-indexed; the use of PDDB_LOC is just a
|
|
|
|
|
// convenient global constant.
|
2022-01-04 13:57:09 +00:00
|
|
|
modals.start_progress("Progress Quest", xous::PDDB_LOC, xous::PDDB_LOC + 64*1024*128, xous::PDDB_LOC).expect("couldn't raise progress bar");
|
2022-04-06 20:04:37 +00:00
|
|
|
for i in (xous::PDDB_LOC..xous::PDDB_LOC + 64*1024*128).step_by(64*1024*16) {
|
2021-12-16 13:39:49 +00:00
|
|
|
modals.update_progress(i).expect("couldn't update progress bar");
|
|
|
|
|
tt.sleep_ms(100).unwrap();
|
|
|
|
|
}
|
|
|
|
|
modals.finish_progress().expect("couldn't dismiss progress bar");
|
2021-12-15 17:48:11 +00:00
|
|
|
|
2022-03-29 19:40:11 +00:00
|
|
|
// 2. test check box
|
2022-04-23 22:28:02 +00:00
|
|
|
let items: Vec<&str> = CHECKBOX_TEST.iter().map(|s| s.to_owned()).collect();
|
|
|
|
|
modals.add_list(items).expect("couldn't build checkbox list");
|
2021-12-16 16:32:44 +00:00
|
|
|
match modals.get_checkbox("You can have it all:") {
|
|
|
|
|
Ok(things) => {
|
|
|
|
|
log::info!("The user picked {} things:", things.len());
|
|
|
|
|
for thing in things {
|
|
|
|
|
log::info!("{}", thing);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
_ => log::error!("get_checkbox failed"),
|
|
|
|
|
}
|
2022-04-23 22:28:02 +00:00
|
|
|
log::info!("Checkbox indices selected = {:?}", modals.get_check_index());
|
2021-12-16 16:32:44 +00:00
|
|
|
|
2022-03-29 19:40:11 +00:00
|
|
|
// 3. test notificatons
|
2021-12-16 17:55:36 +00:00
|
|
|
log::info!("testing notification");
|
2022-04-24 11:29:15 +00:00
|
|
|
modals.show_notification("This is a test!", None).expect("notification failed");
|
2021-12-16 17:55:36 +00:00
|
|
|
log::info!("notification test done");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
thread::spawn({
|
|
|
|
|
move || {
|
|
|
|
|
let xns = XousNames::new().unwrap();
|
|
|
|
|
let modals = modals::Modals::new(&xns).unwrap();
|
|
|
|
|
|
2022-03-29 19:40:11 +00:00
|
|
|
// 1. test radio box
|
2021-12-16 17:55:36 +00:00
|
|
|
for item in RADIO_TEST {
|
|
|
|
|
modals.add_list_item(item).expect("couldn't build radio item list");
|
|
|
|
|
}
|
|
|
|
|
match modals.get_radiobutton("Pick an animal") {
|
|
|
|
|
Ok(animal) => log::info!("{} was picked", animal),
|
|
|
|
|
_ => log::error!("get_radiobutton failed"),
|
|
|
|
|
}
|
2022-04-23 22:28:02 +00:00
|
|
|
log::info!("Radio index selected = {:?}", modals.get_radio_index().unwrap());
|
2021-12-16 17:55:36 +00:00
|
|
|
|
2022-03-29 19:40:11 +00:00
|
|
|
// 2. test the modal dialog box function
|
2021-12-15 17:48:11 +00:00
|
|
|
log::info!("test text input");
|
2022-04-13 13:49:31 +00:00
|
|
|
match modals
|
|
|
|
|
.alert_builder("Test input")
|
|
|
|
|
.field(None, Some(test_validator))
|
|
|
|
|
.build() {
|
2021-12-15 17:48:11 +00:00
|
|
|
Ok(text) => {
|
2022-04-13 13:49:31 +00:00
|
|
|
log::info!("Input: {}", text.content()[0].content);
|
2021-12-15 17:48:11 +00:00
|
|
|
}
|
|
|
|
|
_ => {
|
2021-12-16 16:32:44 +00:00
|
|
|
log::error!("get_text failed");
|
2021-12-15 17:48:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log::info!("text input test done");
|
2021-12-15 18:28:37 +00:00
|
|
|
|
2022-03-29 19:40:11 +00:00
|
|
|
// 3. test notificatons
|
2021-12-15 18:28:37 +00:00
|
|
|
log::info!("testing notification");
|
2022-04-24 11:29:15 +00:00
|
|
|
modals.show_notification("这是一个测验!", Some("这是一个测验!")).expect("notification failed");
|
2021-12-15 18:28:37 +00:00
|
|
|
log::info!("notification test done");
|
2022-04-08 04:16:15 +00:00
|
|
|
|
|
|
|
|
// 4. test qrcode
|
|
|
|
|
log::info!("testing qrcode");
|
2022-04-24 11:29:15 +00:00
|
|
|
modals.show_notification("Please contribute to xous-core", Some("https://github.com/betrusted-io/xous-core")).expect("qrcode failed");
|
2022-04-08 04:16:15 +00:00
|
|
|
log::info!("qrcode test done");
|
2021-12-15 17:48:11 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-13 13:49:31 +00:00
|
|
|
fn test_validator(input: TextEntryPayload) -> Option<xous_ipc::String::<256>> {
|
2021-12-15 17:48:11 +00:00
|
|
|
let text_str = input.as_str();
|
|
|
|
|
match text_str.parse::<u32>() {
|
|
|
|
|
Ok(_input_int) => None,
|
|
|
|
|
_ => return Some(xous_ipc::String::<256>::from_str("enter an integer value"))
|
|
|
|
|
}
|
|
|
|
|
}
|