]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/test-resolved-packet.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / resolve / test-resolved-packet.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
751ca3f1
ZJS
2/***
3 This file is part of systemd
4
5 Copyright 2017 Zbigniew Jędrzejewski-Szmek
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19***/
20
21#include "log.h"
22#include "resolved-dns-packet.h"
23
24static void test_dns_packet_new(void) {
25 size_t i;
46a58596 26 _cleanup_(dns_packet_unrefp) DnsPacket *p2 = NULL;
751ca3f1 27
46a58596 28 for (i = 0; i <= DNS_PACKET_SIZE_MAX; i++) {
751ca3f1
ZJS
29 _cleanup_(dns_packet_unrefp) DnsPacket *p = NULL;
30
51027656 31 assert_se(dns_packet_new(&p, DNS_PROTOCOL_DNS, i, DNS_PACKET_SIZE_MAX) == 0);
751ca3f1
ZJS
32
33 log_debug("dns_packet_new: %zu → %zu", i, p->allocated);
34 assert_se(p->allocated >= MIN(DNS_PACKET_SIZE_MAX, i));
86d06089
ZJS
35
36 if (i > DNS_PACKET_SIZE_START + 10 && i < DNS_PACKET_SIZE_MAX - 10)
37 i = MIN(i * 2, DNS_PACKET_SIZE_MAX - 10);
751ca3f1 38 }
46a58596 39
51027656 40 assert_se(dns_packet_new(&p2, DNS_PROTOCOL_DNS, DNS_PACKET_SIZE_MAX + 1, DNS_PACKET_SIZE_MAX) == -EFBIG);
751ca3f1
ZJS
41}
42
43int main(int argc, char **argv) {
44
45 log_set_max_level(LOG_DEBUG);
46 log_parse_environment();
47 log_open();
48
49 test_dns_packet_new();
50
51 return 0;
52}