refactor tests into a separate file

This commit is contained in:
bunnie 2021-12-16 01:48:11 +08:00
parent 2ddbc224b2
commit dcad15284d
5 changed files with 44 additions and 18 deletions

View file

@ -22,4 +22,5 @@ locales = {path = "../../locales"}
utralib = { path = "../../utralib"}
[features]
default = []
ux_tests = []
default = ["ux_tests"]

View file

@ -23,7 +23,7 @@ impl Modals {
pub fn get_text_input(&self,
prompt: &str,
maybe_validator: Option<fn(TextEntryPayload, u32) -> Option<ValidatorErr> >,
maybe_validator: Option<fn(TextEntryPayload, u32) -> Option<ValidatorErr>>,
maybe_validator_op: Option<u32>,
) -> Result<TextEntryPayload, xous::Error> {
let validator = if let Some(validator) = maybe_validator {

View file

@ -64,7 +64,7 @@ fn xmain() -> ! {
let op = Arc::new(Mutex::new(RendererState::None));
// create a thread that just handles the redrawing requests
let redraw_handle = thread::spawn({
let _redraw_handle = thread::spawn({
let op = Arc::clone(&op);
move || {
// build the core data structure here
@ -202,6 +202,10 @@ fn xmain() -> ! {
}
});
if cfg!(feature = "ux_tests") {
tests::spawn_test();
}
loop {
let mut msg = xous::receive_message(modals_sid).unwrap();
log::debug!("message: {:?}", msg);

View file

@ -0,0 +1,34 @@
#![allow(dead_code)]
use std::thread;
use gam::*;
use xous_names::XousNames;
pub(crate) fn spawn_test() {
thread::spawn({
move || {
let xns = XousNames::new().unwrap();
// test the modal dialog box function
let modals = modals::Modals::new(&xns).unwrap();
log::info!("test text input");
match modals.get_text_input("Test input", Some(test_validator), None) {
Ok(text) => {
log::info!("Input: {}", text.0);
}
_ => {
log::error!("get_text_input failed");
}
}
log::info!("text input test done");
}
});
}
fn test_validator(input: TextEntryPayload, _opcode: u32) -> Option<xous_ipc::String::<256>> {
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"))
}
}

View file

@ -624,19 +624,6 @@ fn xmain() -> ! {
let sr_cid = xous::connect(pddb_sid).expect("couldn't create suspend callback connection");
let _susres = susres::Susres::new(&xns, api::Opcode::SuspendResume as u32, sr_cid).expect("couldn't create suspend/resume object");
// test the modal dialog box function
let modals = modals::Modals::new(&xns).unwrap();
log::info!("testing modals");
match modals.get_text_input("Test input", Some(test_validator), None) {
Ok(text) => {
log::info!("Input: {}", text.0);
}
_ => {
log::error!("get_text_input failed");
}
}
log::info!("done");
// our very own password modal. Password modals are precious and privately owned, to avoid
// other processes from crafting them.
let pw_sid = xous::create_server().expect("couldn't create a server for the password UX handler");
@ -649,7 +636,7 @@ fn xmain() -> ! {
)
}
});
/* just for testing
let request = BasisRequestPassword {
db_name: xous_ipc::String::<{crate::api::BASIS_NAME_LEN}>::from_str("test basis"),
plaintext_pw: None,
@ -658,7 +645,7 @@ fn xmain() -> ! {
buf.lend_mut(pw_cid, PwManagerOpcode::RequestPassword.to_u32().unwrap()).unwrap();
let ret = buf.to_original::<BasisRequestPassword, _>().unwrap();
log::info!("Got password: {:?}", ret.plaintext_pw);
*/
loop {
let msg = xous::receive_message(pddb_sid).unwrap();
match FromPrimitive::from_usize(msg.body.id()) {