(tests) count tests added (#24)

Co-authored-by: Tobias Ottenweller <tobi@ottenweller.net>
Reviewed-on: #24
Co-authored-by: mice_on_drugs <tobi@ottenweller.net>
Co-committed-by: mice_on_drugs <tobi@ottenweller.net>
This commit is contained in:
mice_on_drugs 2022-05-08 19:18:04 +02:00 committed by ddidderr
parent a72e40d9cb
commit ce12fddbe9

View File

@ -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(())
}
}
} }
} }