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