Skip to content

Commit 26fbc0b

Browse files
committed
add tests max values from bytes and to bytes in DnsKey
1 parent 88644f8 commit 26fbc0b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/message/rdata/dnskey_rdata.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,37 @@ mod dnskey_rdata_test{
243243

244244
assert_eq!(Err("Format Error"), result);
245245
}
246+
247+
#[test]
248+
fn max_values_from_bytes_test(){
249+
let mut dnskey_rdata = DnskeyRdata::new();
250+
//Max value of 2 bytes is 65535 (16 ones in the 2 bytes)
251+
dnskey_rdata.set_flags(65535);
252+
dnskey_rdata.set_protocol(255);
253+
dnskey_rdata.set_algorithm(255);
254+
dnskey_rdata.set_public_key(vec![255, 255]);
255+
256+
let bytes_test: Vec<u8> = vec![255, 255, 255, 255, 255, 255];
257+
258+
if let Ok(result)= DnskeyRdata::from_bytes(&bytes_test, &bytes_test) {
259+
assert_eq!(dnskey_rdata, result);
260+
}
261+
else {
262+
assert!(false, "Error");
263+
}
264+
}
265+
266+
#[test]
267+
fn max_values_to_bytes_test(){
268+
let mut dnskey_rdata = DnskeyRdata::new();
269+
//Max value of 2 bytes is 65535 (16 ones in the 2 bytes)
270+
dnskey_rdata.set_flags(65535);
271+
dnskey_rdata.set_protocol(255);
272+
dnskey_rdata.set_algorithm(255);
273+
dnskey_rdata.set_public_key(vec![255, 255]);
274+
275+
let bytes_test: Vec<u8> = vec![255, 255, 255, 255, 255, 255];
276+
277+
assert_eq!(dnskey_rdata.to_bytes(), bytes_test);
278+
}
246279
}

0 commit comments

Comments
 (0)