Skip to content

Commit

Permalink
add integration tests for dot15d4-cat
Browse files Browse the repository at this point in the history
  • Loading branch information
thvdveld committed Jan 17, 2025
1 parent 7b585ed commit 7724693
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dot15d4-cat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ license = "MIT OR Apache-2.0"
[dependencies]
dot15d4-frame = { path = "../dot15d4-frame" }

colored = "2"
colored = "3"
clap = { version = "4.5.1", features = ["derive"] }
hex = "0.4.3"

[dev-dependencies]
strip-ansi-escapes = "0.2.1"

[[bin]]
name = "dot15d4"
path = "src/main.rs"
103 changes: 103 additions & 0 deletions dot15d4-cat/tests/parser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
use dot15d4_cat::FrameParser;

use strip_ansi_escapes::strip;

#[test]
fn enhanced_beacon() {
let input = "40ebcdabffff0100010001000100003f1188061a0e0000000000011c0001c800011b00";
let output = String::from_utf8(strip(FrameParser::parse_hex(input).unwrap())).unwrap();
assert_eq!(
output,
"Frame Control
frame type: Enhanced Beacon
security: 0
frame pending: 0
ack request: 0
pan id compression: 1
sequence number suppression: 1
information elements present: 1
dst addressing mode: Short
src addressing mode: Extended
frame version: 2 (Ieee802154_2020)
Addressing
dst pan id: abcd
dst addr: ff:ff (broadcast)
src addr: 00:01:00:01:00:01:00:01
Information Elements
Header Information Elements
HeaderTermination1
Payload Information Elements
MLME
TschSynchronization
ASN: 14, join metric: 0
TschTimeslot
slot ID: 0
ChannelHopping
sequence ID: 0
TschSlotframeAndLink
#slotframes: 0
"
);
}

#[test]
fn enhanced_ack() {
let input = "022e37cdab0200020002000200020fe18f";
let output = String::from_utf8(strip(FrameParser::parse_hex(input).unwrap())).unwrap();
assert_eq!(
output,
"Frame Control
frame type: Enhanced Ack
security: 0
frame pending: 0
ack request: 0
pan id compression: 0
sequence number suppression: 0
information elements present: 1
dst addressing mode: Extended
src addressing mode: Absent
frame version: 2 (Ieee802154_2020)
Sequence Number
sequence number: 55
Addressing
dst pan id: abcd
dst addr: 00:02:00:02:00:02:00:02
src addr: absent
Information Elements
Header Information Elements
TimeCorrection
-0.03ms, nack: 1
Payload
[]
"
);
}

#[test]
fn data_frame() {
let input = "41d801cdabffffc7d9b514004b12002b000000";
let output = String::from_utf8(strip(FrameParser::parse_hex(input).unwrap())).unwrap();
assert_eq!(
output,
"Frame Control
frame type: Data
security: 0
frame pending: 0
ack request: 0
pan id compression: 1
sequence number suppression: 0
information elements present: 0
dst addressing mode: Short
src addressing mode: Extended
frame version: 1 (Ieee802154_2006)
Sequence Number
sequence number: 1
Addressing
dst pan id: abcd
dst addr: ff:ff (broadcast)
src addr: 00:12:4b:00:14:b5:d9:c7
Payload
[2b, 0, 0, 0]
"
);
}

0 comments on commit 7724693

Please sign in to comment.