]>
Commit | Line | Data |
---|---|---|
52ad194e | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
81c58355 MB |
2 | |
3 | #include "log.h" | |
4 | #include "resolved-dns-packet.h" | |
bb4f798a | 5 | #include "tests.h" |
81c58355 MB |
6 | |
7 | static void test_dns_packet_new(void) { | |
8 | size_t i; | |
9 | _cleanup_(dns_packet_unrefp) DnsPacket *p2 = NULL; | |
10 | ||
11 | for (i = 0; i <= DNS_PACKET_SIZE_MAX; i++) { | |
12 | _cleanup_(dns_packet_unrefp) DnsPacket *p = NULL; | |
13 | ||
f5e65279 | 14 | assert_se(dns_packet_new(&p, DNS_PROTOCOL_DNS, i, DNS_PACKET_SIZE_MAX) == 0); |
81c58355 MB |
15 | |
16 | log_debug("dns_packet_new: %zu → %zu", i, p->allocated); | |
17 | assert_se(p->allocated >= MIN(DNS_PACKET_SIZE_MAX, i)); | |
f5e65279 MB |
18 | |
19 | if (i > DNS_PACKET_SIZE_START + 10 && i < DNS_PACKET_SIZE_MAX - 10) | |
20 | i = MIN(i * 2, DNS_PACKET_SIZE_MAX - 10); | |
81c58355 MB |
21 | } |
22 | ||
f5e65279 | 23 | assert_se(dns_packet_new(&p2, DNS_PROTOCOL_DNS, DNS_PACKET_SIZE_MAX + 1, DNS_PACKET_SIZE_MAX) == -EFBIG); |
81c58355 MB |
24 | } |
25 | ||
26 | int main(int argc, char **argv) { | |
bb4f798a | 27 | test_setup_logging(LOG_DEBUG); |
81c58355 MB |
28 | |
29 | test_dns_packet_new(); | |
30 | ||
31 | return 0; | |
32 | } |