usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-byteswap.c
blobdb0bd2f1dfd691559f882e5a28ddb55035ed200e
1 /* Test of <byteswap.h> substitute.
2 Copyright (C) 2007-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
19 #include <config.h>
21 #include <byteswap.h>
22 #include <stdint.h>
24 #include "macros.h"
26 /* Test bswap functions with constant values. */
27 static void
28 test_bswap_constant (void)
30 ASSERT (bswap_16 (UINT16_C (0x1234)) == UINT16_C (0x3412));
31 ASSERT (bswap_32 (UINT32_C (0x12345678)) == UINT32_C (0x78563412));
32 #ifdef UINT_LEAST64_MAX
33 ASSERT (bswap_64 (UINT64_C (0x1234567890ABCDEF))
34 == UINT64_C (0xEFCDAB9078563412));
35 #endif
38 /* Test that the bswap functions evaluate their arguments once. */
39 static void
40 test_bswap_eval_once (void)
42 uint_least16_t value_1 = 0;
43 ASSERT (bswap_16 (value_1++) == 0);
44 ASSERT (value_1 == 1);
46 uint_least32_t value_2 = 0;
47 ASSERT (bswap_32 (value_2++) == 0);
48 ASSERT (value_2 == 1);
50 #ifdef UINT_LEAST64_MAX
51 uint_least64_t value_3 = 0;
52 ASSERT (bswap_64 (value_3++) == 0);
53 ASSERT (value_3 == 1);
54 #endif
57 /* Test that the bswap functions accept floating-point arguments. */
58 static void
59 test_bswap_double (void)
61 ASSERT (bswap_16 (0.0) == 0);
62 ASSERT (bswap_32 (0.0) == 0);
63 #ifdef UINT_LEAST64_MAX
64 ASSERT (bswap_64 (0.0) == 0);
65 #endif
68 int
69 main (void)
71 test_bswap_constant ();
72 test_bswap_eval_once ();
73 test_bswap_double ();
75 return test_exit_status;