Skip to content

Commit 1ad4e6e

Browse files
committed
Tests: Create macro for simpler expression of attr_data
1 parent 566db62 commit 1ad4e6e

File tree

3 files changed

+45
-33
lines changed

3 files changed

+45
-33
lines changed

matter/tests/common/attributes.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ pub const ATTR_DATA_TAG_DATA: u8 = 2;
4949

5050
#[macro_export]
5151
macro_rules! attr_data {
52+
($endpoint:expr, $cluster:expr, $attr: expr, $data:expr) => {
53+
AttrResp::Data(AttrData {
54+
data_ver: None,
55+
path: AttrPath {
56+
endpoint: Some($endpoint),
57+
cluster: Some($cluster),
58+
attr: Some($attr as u16),
59+
..Default::default()
60+
},
61+
data: EncodeValue::Tlv(TLVElement::new(TagType::Context(ATTR_DATA_TAG_DATA), $data)),
62+
})
63+
};
64+
}
65+
66+
#[macro_export]
67+
macro_rules! attr_data_path {
5268
($path:expr, $data:expr) => {
5369
AttrResp::Data(AttrData {
5470
data_ver: None,

matter/tests/data_model/acl_and_dataver.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use matter::{
3434
};
3535

3636
use crate::{
37-
attr_data, attr_status,
37+
attr_data_path, attr_status,
3838
common::{
3939
attributes::*,
4040
echo_cluster::{self, ATTR_WRITE_DEFAULT_VALUE},
@@ -151,7 +151,7 @@ fn wc_read_attribute() {
151151

152152
// Test2: Only Single response as only single endpoint is allowed
153153
let input = &[AttrPath::new(&wc_att1)];
154-
let expected = &[attr_data!(ep0_att1, ElementType::U16(0x1234))];
154+
let expected = &[attr_data_path!(ep0_att1, ElementType::U16(0x1234))];
155155
handle_read_reqs(&mut im, peer, input, expected);
156156

157157
// Add ACL to allow our peer to only access endpoint 1
@@ -163,8 +163,8 @@ fn wc_read_attribute() {
163163
// Test3: Both responses are valid
164164
let input = &[AttrPath::new(&wc_att1)];
165165
let expected = &[
166-
attr_data!(ep0_att1, ElementType::U16(0x1234)),
167-
attr_data!(ep1_att1, ElementType::U16(0x1234)),
166+
attr_data_path!(ep0_att1, ElementType::U16(0x1234)),
167+
attr_data_path!(ep1_att1, ElementType::U16(0x1234)),
168168
];
169169
handle_read_reqs(&mut im, peer, input, expected);
170170
}
@@ -201,7 +201,7 @@ fn exact_read_attribute() {
201201

202202
// Test2: Only Single response as only single endpoint is allowed
203203
let input = &[AttrPath::new(&wc_att1)];
204-
let expected = &[attr_data!(ep0_att1, ElementType::U16(0x1234))];
204+
let expected = &[attr_data_path!(ep0_att1, ElementType::U16(0x1234))];
205205
handle_read_reqs(&mut im, peer, input, expected);
206206
}
207207

@@ -565,15 +565,15 @@ fn test_read_data_ver() {
565565
let input = &[AttrPath::new(&wc_ep_att1)];
566566

567567
let expected = &[
568-
attr_data!(
568+
attr_data_path!(
569569
GenericPath::new(
570570
Some(0),
571571
Some(echo_cluster::ID),
572572
Some(echo_cluster::Attributes::Att1 as u32)
573573
),
574574
ElementType::U16(0x1234)
575575
),
576-
attr_data!(
576+
attr_data_path!(
577577
GenericPath::new(
578578
Some(1),
579579
Some(echo_cluster::ID),
@@ -614,7 +614,7 @@ fn test_read_data_ver() {
614614
Some(TLVArray::Slice(&dataver_filter)),
615615
&mut out_buf,
616616
);
617-
let expected_only_one = &[attr_data!(
617+
let expected_only_one = &[attr_data_path!(
618618
GenericPath::new(
619619
Some(1),
620620
Some(echo_cluster::ID),

matter/tests/data_model/attributes.rs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use matter::{
3434
};
3535

3636
use crate::{
37-
attr_data, attr_status,
37+
attr_data, attr_data_path, attr_status,
3838
common::{attributes::*, echo_cluster, im_engine::im_engine},
3939
};
4040

@@ -95,9 +95,9 @@ fn test_read_success() {
9595
AttrPath::new(&ep1_attcustom),
9696
];
9797
let expected = &[
98-
attr_data!(ep0_att1, ElementType::U16(0x1234)),
99-
attr_data!(ep1_att2, ElementType::U16(0x5678)),
100-
attr_data!(
98+
attr_data_path!(ep0_att1, ElementType::U16(0x1234)),
99+
attr_data_path!(ep1_att2, ElementType::U16(0x5678)),
100+
attr_data_path!(
101101
ep1_attcustom,
102102
ElementType::U32(echo_cluster::ATTR_CUSTOM_VALUE)
103103
),
@@ -168,19 +168,15 @@ fn test_read_wc_endpoint_all_have_clusters() {
168168

169169
let expected = &[
170170
attr_data!(
171-
GenericPath::new(
172-
Some(0),
173-
Some(echo_cluster::ID),
174-
Some(echo_cluster::Attributes::Att1 as u32)
175-
),
171+
0,
172+
echo_cluster::ID,
173+
echo_cluster::Attributes::Att1,
176174
ElementType::U16(0x1234)
177175
),
178176
attr_data!(
179-
GenericPath::new(
180-
Some(1),
181-
Some(echo_cluster::ID),
182-
Some(echo_cluster::Attributes::Att1 as u32)
183-
),
177+
1,
178+
echo_cluster::ID,
179+
echo_cluster::Attributes::Att1,
184180
ElementType::U16(0x1234)
185181
),
186182
];
@@ -201,7 +197,7 @@ fn test_read_wc_endpoint_only_1_has_cluster() {
201197
);
202198
let input = &[AttrPath::new(&wc_ep_onoff)];
203199

204-
let expected = &[attr_data!(
200+
let expected = &[attr_data_path!(
205201
GenericPath::new(
206202
Some(1),
207203
Some(cluster_on_off::ID),
@@ -248,79 +244,79 @@ fn test_read_wc_endpoint_wc_attribute() {
248244
);
249245

250246
let expected = &[
251-
attr_data!(
247+
attr_data_path!(
252248
GenericPath::new(
253249
Some(0),
254250
Some(echo_cluster::ID),
255251
Some(GlobalElements::FeatureMap as u32),
256252
),
257253
ElementType::U8(0)
258254
),
259-
attr_data!(
255+
attr_data_path!(
260256
GenericPath::new(
261257
Some(0),
262258
Some(echo_cluster::ID),
263259
Some(GlobalElements::AttributeList as u32),
264260
),
265261
attr_list_tlvs.get_element_type()
266262
),
267-
attr_data!(
263+
attr_data_path!(
268264
GenericPath::new(
269265
Some(0),
270266
Some(echo_cluster::ID),
271267
Some(echo_cluster::Attributes::Att1 as u32),
272268
),
273269
ElementType::U16(0x1234)
274270
),
275-
attr_data!(
271+
attr_data_path!(
276272
GenericPath::new(
277273
Some(0),
278274
Some(echo_cluster::ID),
279275
Some(echo_cluster::Attributes::Att2 as u32),
280276
),
281277
ElementType::U16(0x5678)
282278
),
283-
attr_data!(
279+
attr_data_path!(
284280
GenericPath::new(
285281
Some(0),
286282
Some(echo_cluster::ID),
287283
Some(echo_cluster::Attributes::AttCustom as u32),
288284
),
289285
ElementType::U32(echo_cluster::ATTR_CUSTOM_VALUE)
290286
),
291-
attr_data!(
287+
attr_data_path!(
292288
GenericPath::new(
293289
Some(1),
294290
Some(echo_cluster::ID),
295291
Some(GlobalElements::FeatureMap as u32),
296292
),
297293
ElementType::U8(0)
298294
),
299-
attr_data!(
295+
attr_data_path!(
300296
GenericPath::new(
301297
Some(1),
302298
Some(echo_cluster::ID),
303299
Some(GlobalElements::AttributeList as u32),
304300
),
305301
attr_list_tlvs.get_element_type()
306302
),
307-
attr_data!(
303+
attr_data_path!(
308304
GenericPath::new(
309305
Some(1),
310306
Some(echo_cluster::ID),
311307
Some(echo_cluster::Attributes::Att1 as u32),
312308
),
313309
ElementType::U16(0x1234)
314310
),
315-
attr_data!(
311+
attr_data_path!(
316312
GenericPath::new(
317313
Some(1),
318314
Some(echo_cluster::ID),
319315
Some(echo_cluster::Attributes::Att2 as u32),
320316
),
321317
ElementType::U16(0x5678)
322318
),
323-
attr_data!(
319+
attr_data_path!(
324320
GenericPath::new(
325321
Some(1),
326322
Some(echo_cluster::ID),

0 commit comments

Comments
 (0)