Count tests added.
This commit is contained in:
parent
d5de7a02d4
commit
67eb4973c4
136
src/proto.rs
136
src/proto.rs
@ -376,5 +376,141 @@ mod tests {
|
|||||||
Ok(())
|
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(())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user