From 13ea55228029d8a6002d00075302ed26d4031f93 Mon Sep 17 00:00:00 2001 From: Kedar Sovani Date: Wed, 4 Jan 2023 12:21:52 +0530 Subject: [PATCH] Tests: Make a provision to override 'Exchange' in the im_engine --- matter/tests/common/im_engine.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/matter/tests/common/im_engine.rs b/matter/tests/common/im_engine.rs index 1d1ac38..22dc68d 100644 --- a/matter/tests/common/im_engine.rs +++ b/matter/tests/common/im_engine.rs @@ -58,6 +58,10 @@ pub struct ImEngine { pub dm: DataModel, pub acl_mgr: Arc, pub im: Box, + // By default, a new exchange is created for every run, if you wish to instead using a specific + // exchange, set this variable. This is helpful in situations where you have to run multiple + // actions in the same transaction (exchange) + pub exch: Option, } pub struct ImInput<'a> { @@ -111,12 +115,19 @@ impl ImEngine { let im = Box::new(InteractionModel::new(Box::new(dm.clone()))); - Self { dm, acl_mgr, im } + Self { + dm, + acl_mgr, + im, + exch: None, + } } /// Run a transaction through the interaction model engine pub fn process(&mut self, input: &ImInput, data_out: &mut [u8]) -> usize { - let mut exch = Exchange::new(1, 0, exchange::Role::Responder); + let mut new_exch = Exchange::new(1, 0, exchange::Role::Responder); + // Choose whether to use a new exchange, or use the one from the ImEngine configuration + let mut exch = self.exch.as_mut().unwrap_or_else(|| &mut new_exch); let mut sess_mgr: SessionMgr = Default::default();