Tests: Create macro for simpler expression of attr_data

This commit is contained in:
Kedar Sovani 2023-02-28 08:46:09 +05:30
parent 566db62404
commit 1ad4e6ebc3
3 changed files with 45 additions and 33 deletions

View file

@ -49,6 +49,22 @@ pub const ATTR_DATA_TAG_DATA: u8 = 2;
#[macro_export]
macro_rules! attr_data {
($endpoint:expr, $cluster:expr, $attr: expr, $data:expr) => {
AttrResp::Data(AttrData {
data_ver: None,
path: AttrPath {
endpoint: Some($endpoint),
cluster: Some($cluster),
attr: Some($attr as u16),
..Default::default()
},
data: EncodeValue::Tlv(TLVElement::new(TagType::Context(ATTR_DATA_TAG_DATA), $data)),
})
};
}
#[macro_export]
macro_rules! attr_data_path {
($path:expr, $data:expr) => {
AttrResp::Data(AttrData {
data_ver: None,

View file

@ -34,7 +34,7 @@ use matter::{
};
use crate::{
attr_data, attr_status,
attr_data_path, attr_status,
common::{
attributes::*,
echo_cluster::{self, ATTR_WRITE_DEFAULT_VALUE},
@ -151,7 +151,7 @@ fn wc_read_attribute() {
// Test2: Only Single response as only single endpoint is allowed
let input = &[AttrPath::new(&wc_att1)];
let expected = &[attr_data!(ep0_att1, ElementType::U16(0x1234))];
let expected = &[attr_data_path!(ep0_att1, ElementType::U16(0x1234))];
handle_read_reqs(&mut im, peer, input, expected);
// Add ACL to allow our peer to only access endpoint 1
@ -163,8 +163,8 @@ fn wc_read_attribute() {
// Test3: Both responses are valid
let input = &[AttrPath::new(&wc_att1)];
let expected = &[
attr_data!(ep0_att1, ElementType::U16(0x1234)),
attr_data!(ep1_att1, ElementType::U16(0x1234)),
attr_data_path!(ep0_att1, ElementType::U16(0x1234)),
attr_data_path!(ep1_att1, ElementType::U16(0x1234)),
];
handle_read_reqs(&mut im, peer, input, expected);
}
@ -201,7 +201,7 @@ fn exact_read_attribute() {
// Test2: Only Single response as only single endpoint is allowed
let input = &[AttrPath::new(&wc_att1)];
let expected = &[attr_data!(ep0_att1, ElementType::U16(0x1234))];
let expected = &[attr_data_path!(ep0_att1, ElementType::U16(0x1234))];
handle_read_reqs(&mut im, peer, input, expected);
}
@ -565,7 +565,7 @@ fn test_read_data_ver() {
let input = &[AttrPath::new(&wc_ep_att1)];
let expected = &[
attr_data!(
attr_data_path!(
GenericPath::new(
Some(0),
Some(echo_cluster::ID),
@ -573,7 +573,7 @@ fn test_read_data_ver() {
),
ElementType::U16(0x1234)
),
attr_data!(
attr_data_path!(
GenericPath::new(
Some(1),
Some(echo_cluster::ID),
@ -614,7 +614,7 @@ fn test_read_data_ver() {
Some(TLVArray::Slice(&dataver_filter)),
&mut out_buf,
);
let expected_only_one = &[attr_data!(
let expected_only_one = &[attr_data_path!(
GenericPath::new(
Some(1),
Some(echo_cluster::ID),

View file

@ -34,7 +34,7 @@ use matter::{
};
use crate::{
attr_data, attr_status,
attr_data, attr_data_path, attr_status,
common::{attributes::*, echo_cluster, im_engine::im_engine},
};
@ -95,9 +95,9 @@ fn test_read_success() {
AttrPath::new(&ep1_attcustom),
];
let expected = &[
attr_data!(ep0_att1, ElementType::U16(0x1234)),
attr_data!(ep1_att2, ElementType::U16(0x5678)),
attr_data!(
attr_data_path!(ep0_att1, ElementType::U16(0x1234)),
attr_data_path!(ep1_att2, ElementType::U16(0x5678)),
attr_data_path!(
ep1_attcustom,
ElementType::U32(echo_cluster::ATTR_CUSTOM_VALUE)
),
@ -168,19 +168,15 @@ fn test_read_wc_endpoint_all_have_clusters() {
let expected = &[
attr_data!(
GenericPath::new(
Some(0),
Some(echo_cluster::ID),
Some(echo_cluster::Attributes::Att1 as u32)
),
0,
echo_cluster::ID,
echo_cluster::Attributes::Att1,
ElementType::U16(0x1234)
),
attr_data!(
GenericPath::new(
Some(1),
Some(echo_cluster::ID),
Some(echo_cluster::Attributes::Att1 as u32)
),
1,
echo_cluster::ID,
echo_cluster::Attributes::Att1,
ElementType::U16(0x1234)
),
];
@ -201,7 +197,7 @@ fn test_read_wc_endpoint_only_1_has_cluster() {
);
let input = &[AttrPath::new(&wc_ep_onoff)];
let expected = &[attr_data!(
let expected = &[attr_data_path!(
GenericPath::new(
Some(1),
Some(cluster_on_off::ID),
@ -248,7 +244,7 @@ fn test_read_wc_endpoint_wc_attribute() {
);
let expected = &[
attr_data!(
attr_data_path!(
GenericPath::new(
Some(0),
Some(echo_cluster::ID),
@ -256,7 +252,7 @@ fn test_read_wc_endpoint_wc_attribute() {
),
ElementType::U8(0)
),
attr_data!(
attr_data_path!(
GenericPath::new(
Some(0),
Some(echo_cluster::ID),
@ -264,7 +260,7 @@ fn test_read_wc_endpoint_wc_attribute() {
),
attr_list_tlvs.get_element_type()
),
attr_data!(
attr_data_path!(
GenericPath::new(
Some(0),
Some(echo_cluster::ID),
@ -272,7 +268,7 @@ fn test_read_wc_endpoint_wc_attribute() {
),
ElementType::U16(0x1234)
),
attr_data!(
attr_data_path!(
GenericPath::new(
Some(0),
Some(echo_cluster::ID),
@ -280,7 +276,7 @@ fn test_read_wc_endpoint_wc_attribute() {
),
ElementType::U16(0x5678)
),
attr_data!(
attr_data_path!(
GenericPath::new(
Some(0),
Some(echo_cluster::ID),
@ -288,7 +284,7 @@ fn test_read_wc_endpoint_wc_attribute() {
),
ElementType::U32(echo_cluster::ATTR_CUSTOM_VALUE)
),
attr_data!(
attr_data_path!(
GenericPath::new(
Some(1),
Some(echo_cluster::ID),
@ -296,7 +292,7 @@ fn test_read_wc_endpoint_wc_attribute() {
),
ElementType::U8(0)
),
attr_data!(
attr_data_path!(
GenericPath::new(
Some(1),
Some(echo_cluster::ID),
@ -304,7 +300,7 @@ fn test_read_wc_endpoint_wc_attribute() {
),
attr_list_tlvs.get_element_type()
),
attr_data!(
attr_data_path!(
GenericPath::new(
Some(1),
Some(echo_cluster::ID),
@ -312,7 +308,7 @@ fn test_read_wc_endpoint_wc_attribute() {
),
ElementType::U16(0x1234)
),
attr_data!(
attr_data_path!(
GenericPath::new(
Some(1),
Some(echo_cluster::ID),
@ -320,7 +316,7 @@ fn test_read_wc_endpoint_wc_attribute() {
),
ElementType::U16(0x5678)
),
attr_data!(
attr_data_path!(
GenericPath::new(
Some(1),
Some(echo_cluster::ID),