Count tests added.

This commit is contained in:
Tobias Ottenweller 2022-05-08 19:12:36 +02:00
parent d5de7a02d4
commit 67eb4973c4

View File

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