diff --git a/src/proto.rs b/src/proto.rs index ca6510a..f0c8f9b 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -376,5 +376,141 @@ mod tests { Ok(()) } } + + mod query_count { + use super::super::super::*; + + #[test] + fn zero() -> Result<(), DNSParseError> { + let dns_query = [ + 0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ]; + let parse_result = DNSHeader::from_udp_datagram(&dns_query); + assert_eq!(parse_result?.query_count, 0); + Ok(()) + } + + #[test] + fn one() -> Result<(), DNSParseError> { + let dns_query = [ + 0xff, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ]; + let parse_result = DNSHeader::from_udp_datagram(&dns_query); + assert_eq!(parse_result?.query_count, 1); + Ok(()) + } + + #[test] + fn max_value() -> Result<(), DNSParseError> { + let dns_query = [ + 0xff, 0x00, 0x80, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ]; + let parse_result = DNSHeader::from_udp_datagram(&dns_query); + assert_eq!(parse_result?.query_count, 65535); + Ok(()) + } + } + + mod answer_count { + use super::super::super::*; + + #[test] + fn zero() -> Result<(), DNSParseError> { + let dns_query = [ + 0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ]; + let parse_result = DNSHeader::from_udp_datagram(&dns_query); + assert_eq!(parse_result?.answer_count, 0); + Ok(()) + } + + #[test] + fn one() -> Result<(), DNSParseError> { + let dns_query = [ + 0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + ]; + let parse_result = DNSHeader::from_udp_datagram(&dns_query); + assert_eq!(parse_result?.answer_count, 1); + Ok(()) + } + + #[test] + fn max_value() -> Result<(), DNSParseError> { + let dns_query = [ + 0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + ]; + let parse_result = DNSHeader::from_udp_datagram(&dns_query); + assert_eq!(parse_result?.answer_count, 65535); + Ok(()) + } + } + + mod name_server_count { + use super::super::super::*; + + #[test] + fn zero() -> Result<(), DNSParseError> { + let dns_query = [ + 0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ]; + let parse_result = DNSHeader::from_udp_datagram(&dns_query); + assert_eq!(parse_result?.name_server_count, 0); + Ok(()) + } + + #[test] + fn one() -> Result<(), DNSParseError> { + let dns_query = [ + 0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + ]; + let parse_result = DNSHeader::from_udp_datagram(&dns_query); + assert_eq!(parse_result?.name_server_count, 1); + Ok(()) + } + + #[test] + fn max_value() -> Result<(), DNSParseError> { + let dns_query = [ + 0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, + ]; + let parse_result = DNSHeader::from_udp_datagram(&dns_query); + assert_eq!(parse_result?.name_server_count, 65535); + Ok(()) + } + } + + mod additional_count { + use super::super::super::*; + + #[test] + fn zero() -> Result<(), DNSParseError> { + let dns_query = [ + 0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ]; + let parse_result = DNSHeader::from_udp_datagram(&dns_query); + assert_eq!(parse_result?.additional_count, 0); + Ok(()) + } + + #[test] + fn one() -> Result<(), DNSParseError> { + let dns_query = [ + 0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + ]; + let parse_result = DNSHeader::from_udp_datagram(&dns_query); + assert_eq!(parse_result?.additional_count, 1); + Ok(()) + } + + #[test] + fn max_value() -> Result<(), DNSParseError> { + let dns_query = [ + 0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + ]; + let parse_result = DNSHeader::from_udp_datagram(&dns_query); + assert_eq!(parse_result?.additional_count, 65535); + Ok(()) + } + } } }