usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-wmemcmp.c
blob692fcb5e07fc47a95ab09c8dab0c618c4b908096
1 /* Test of wmemcmp() function.
2 Copyright (C) 2008-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>, 2023. */
19 #include <config.h>
21 #include <wchar.h>
23 #include "signature.h"
24 SIGNATURE_CHECK (wmemcmp, int, (const wchar_t *, const wchar_t *, size_t));
26 #include "macros.h"
28 int
29 main (int argc, char *argv[])
31 /* Test equal / not equal distinction. */
33 static const wchar_t input1[] = { 'f', 'o', 'o', 0 };
34 static const wchar_t input2[] = { 'f', 'o', 'o', 'b', 'a', 'r', 0 };
35 ASSERT (wmemcmp (input1, input2, 2) == 0);
36 ASSERT (wmemcmp (input1, input2, 3) == 0);
37 ASSERT (wmemcmp (input1, input2, 4) != 0);
40 static const wchar_t input1[] = { 'f', 'o', 'o', 0 };
41 static const wchar_t input2[] = { 'b', 'a', 'r', 0 };
42 ASSERT (wmemcmp (input1, input2, 1) != 0);
43 ASSERT (wmemcmp (input1, input2, 3) != 0);
46 /* Test less / equal / greater distinction. */
48 static const wchar_t input1[] = { 'f', 'o', 'o', 0 };
49 static const wchar_t input2[] = { 'm', 'o', 'o', 0 };
50 ASSERT (wmemcmp (input1, input2, 4) < 0);
51 ASSERT (wmemcmp (input2, input1, 4) > 0);
54 static const wchar_t input1[] = { 'o', 'o', 'm', 'p', 'h', 0 };
55 static const wchar_t input2[] = { 'o', 'o', 'p', 's', 0 };
56 ASSERT (wmemcmp (input1, input2, 3) < 0);
57 ASSERT (wmemcmp (input2, input1, 3) > 0);
60 static const wchar_t input1[] = { 'f', 'o', 'o', 0 };
61 static const wchar_t input2[] = { 'f', 'o', 'o', 'b', 'a', 'r', 0 };
62 ASSERT (wmemcmp (input1, input2, 4) < 0);
63 ASSERT (wmemcmp (input2, input1, 4) > 0);
66 /* ISO C requires wcscmp to work with all wchar_t values.
67 ISO C 17 ยง 7.29.4.4 says:
68 "Unless explicitly stated otherwise, the functions described in this
69 subclause order two wide characters the same way as two integers of
70 the underlying integer type designated by wchar_t." */
72 static const wchar_t input1[] = { (wchar_t) 0x76547654 };
73 static const wchar_t input2[] = { (wchar_t) 0x9abc9abc };
74 if ((wchar_t)-1 < 0)
76 /* wchar_t is signed. */
77 ASSERT (wmemcmp (input1, input2, 1) > 0);
78 ASSERT (wmemcmp (input2, input1, 1) < 0);
80 else
82 /* wchar_t is unsigned. */
83 ASSERT (wmemcmp (input1, input2, 1) < 0);
84 ASSERT (wmemcmp (input2, input1, 1) > 0);
88 static const wchar_t input1[] = { (wchar_t) 0x9abc9abc };
89 static const wchar_t input2[] = { (wchar_t) 0x9bdf9bdf };
90 ASSERT (wmemcmp (input1, input2, 1) < 0);
91 ASSERT (wmemcmp (input2, input1, 1) > 0);
94 return test_exit_status;