sparc: Use existing macros to avoid code duplication
[glibc.git] / resolv / tst-inet_aton_exact.c
blob2c586bc1c51548e9badd5c2c0bfa1ea9128e389d
1 /* Test internal legacy IPv4 text-to-address function __inet_aton_exact.
2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <arpa/inet.h>
20 #include <support/check.h>
22 static int
23 do_test (void)
25 struct in_addr addr = { };
27 TEST_COMPARE (__inet_aton_exact ("192.0.2.1", &addr), 1);
28 TEST_COMPARE (ntohl (addr.s_addr), 0xC0000201);
30 TEST_COMPARE (__inet_aton_exact ("192.000.002.010", &addr), 1);
31 TEST_COMPARE (ntohl (addr.s_addr), 0xC0000208);
32 TEST_COMPARE (__inet_aton_exact ("0xC0000234", &addr), 1);
33 TEST_COMPARE (ntohl (addr.s_addr), 0xC0000234);
35 /* Trailing content is not accepted. */
36 TEST_COMPARE (__inet_aton_exact ("192.0.2.2X", &addr), 0);
37 TEST_COMPARE (__inet_aton_exact ("192.0.2.3 Y", &addr), 0);
38 TEST_COMPARE (__inet_aton_exact ("192.0.2.4\nZ", &addr), 0);
39 TEST_COMPARE (__inet_aton_exact ("192.0.2.5\tT", &addr), 0);
40 TEST_COMPARE (__inet_aton_exact ("192.0.2.6 Y", &addr), 0);
41 TEST_COMPARE (__inet_aton_exact ("192.0.2.7\n", &addr), 0);
42 TEST_COMPARE (__inet_aton_exact ("192.0.2.8\t", &addr), 0);
44 return 0;
47 #include <support/test-driver.c>