summaryrefslogtreecommitdiff
path: root/src/rust/uci/mod.rs
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2022-02-05 03:22:35 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2022-02-05 03:22:35 +0000
commitccd1a5cf3558684cd0363667286f2703adf430b8 (patch)
treefde17de4790d899eb405be6e82bd82d795636369 /src/rust/uci/mod.rs
parent592d67591aae74dda6e91caa8dee2431ba93e955 (diff)
parent8167bdb490e62bbd0d3562bab7f6e9a64b8d9465 (diff)
downloaduwb-ccd1a5cf3558684cd0363667286f2703adf430b8.tar.gz
Merge "uci-rust: add a test case for deinitialization"
Diffstat (limited to 'src/rust/uci/mod.rs')
-rw-r--r--src/rust/uci/mod.rs33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/rust/uci/mod.rs b/src/rust/uci/mod.rs
index d9ed085..3fd4376 100644
--- a/src/rust/uci/mod.rs
+++ b/src/rust/uci/mod.rs
@@ -519,27 +519,44 @@ mod tests {
use crate::adaptation::MockUwbAdaptation;
use crate::event_manager::MockEventManager;
- #[test]
- fn test_driver() -> Result<()> {
+ fn setup_dispatcher(config_fn: fn(&mut Box<MockUwbAdaptation>)) -> Result<Dispatcher> {
// TODO: Remove this once we call it somewhere real.
logger::init(
- logger::Config::default().with_tag_on_device("uwb").with_min_level(log::Level::Error),
+ logger::Config::default().with_tag_on_device("uwb").with_min_level(log::Level::Debug),
);
let (rsp_sender, rsp_receiver) = mpsc::unbounded_channel::<HalCallback>();
let mut mock_adaptation = Box::new(MockUwbAdaptation::new(rsp_sender));
let mock_event_manager = MockEventManager::new();
- mock_adaptation.expect_hal_open(Ok(()));
- mock_adaptation.expect_core_initialization(Ok(()));
+ config_fn(&mut mock_adaptation);
- let mut dispatcher = Dispatcher::new_for_testing(
+ Dispatcher::new_for_testing(
mock_event_manager,
mock_adaptation as SyncUwbAdaptation,
rsp_receiver,
- )?;
+ )
+ }
+
+ #[test]
+ fn test_initialize() -> Result<()> {
+ let mut dispatcher = setup_dispatcher(|mock_adaptation| {
+ mock_adaptation.expect_hal_open(Ok(()));
+ mock_adaptation.expect_core_initialization(Ok(()));
+ })?;
+
dispatcher.send_jni_command(JNICommand::Enable)?;
- dispatcher.send_jni_command(JNICommand::UciGetDeviceInfo)?;
+ dispatcher.exit()?;
+ Ok(())
+ }
+
+ #[test]
+ fn test_deinitialize() -> Result<()> {
+ let mut dispatcher = setup_dispatcher(|mock_adaptation| {
+ mock_adaptation.expect_hal_close(Ok(()));
+ })?;
+
+ dispatcher.send_jni_command(JNICommand::Disable(true))?;
dispatcher.exit()?;
Ok(())
}