1 /* Test of uN_cmp() functions.
2 Copyright (C) 2008-2020 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 Simon Josefsson and Bruno Haible <bruno@clisp.org>, 2010. */
22 /* Test equal / not equal distinction. */
23 void *page_boundary1
= zerosize_ptr ();
24 void *page_boundary2
= zerosize_ptr ();
25 if (page_boundary1
&& page_boundary2
)
26 ASSERT (U_CMP (page_boundary1
, page_boundary2
, 0) == 0);
28 static const UNIT input1
[] = { 'f', 'o', 'o', 0 };
29 static const UNIT input2
[] = { 'f', 'o', 'o', 'b', 'a', 'r', 0 };
30 ASSERT (U_CMP (input1
, input2
, 2) == 0);
31 ASSERT (U_CMP (input1
, input2
, 3) == 0);
32 ASSERT (U_CMP (input1
, input2
, 4) != 0);
35 static const UNIT input1
[] = { 'f', 'o', 'o', 0 };
36 static const UNIT input2
[] = { 'b', 'a', 'r', 0 };
37 ASSERT (U_CMP (input1
, input2
, 1) != 0);
38 ASSERT (U_CMP (input1
, input2
, 3) != 0);
41 /* Test less / equal / greater distinction. */
43 static const UNIT input1
[] = { 'f', 'o', 'o', 0 };
44 static const UNIT input2
[] = { 'm', 'o', 'o', 0 };
45 ASSERT (U_CMP (input1
, input2
, 4) < 0);
46 ASSERT (U_CMP (input2
, input1
, 4) > 0);
49 static const UNIT input1
[] = { 'o', 'o', 'm', 'p', 'h', 0 };
50 static const UNIT input2
[] = { 'o', 'o', 'p', 's', 0 };
51 ASSERT (U_CMP (input1
, input2
, 3) < 0);
52 ASSERT (U_CMP (input2
, input1
, 3) > 0);
55 static const UNIT input1
[] = { 'f', 'o', 'o', 0 };
56 static const UNIT input2
[] = { 'f', 'o', 'o', 'b', 'a', 'r', 0 };
57 ASSERT (U_CMP (input1
, input2
, 4) < 0);
58 ASSERT (U_CMP (input2
, input1
, 4) > 0);
61 /* Some old versions of memcmp were not 8-bit clean. */
63 static const UNIT input1
[] = { 0x40 };
64 static const UNIT input2
[] = { 0xC2 };
65 ASSERT (U_CMP (input1
, input2
, 1) < 0);
66 ASSERT (U_CMP (input2
, input1
, 1) > 0);
69 static const UNIT input1
[] = { 0xC2 };
70 static const UNIT input2
[] = { 0xC3 };
71 ASSERT (U_CMP (input1
, input2
, 1) < 0);
72 ASSERT (U_CMP (input2
, input1
, 1) > 0);
75 /* The Next x86 OpenStep bug shows up only when comparing 16 bytes
76 or more and with at least one buffer not starting on a 4-byte boundary.
77 William Lewis provided this test program. */
82 for (i
= 0; i
< 4; i
++)
87 for (j
= 0; j
< 8; j
++)
90 for (j
= 9; j
< 16; j
++)
92 for (j
= 0; j
< 8; j
++)
95 for (j
= 9; j
< 16; j
++)
97 ASSERT (U_CMP (a
, b
, 16) < 0);