2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2016 Joyent, Inc.
17 * General tests for wcsncasecmp(). Test to make sure that the following are
20 * o Two identical strings are equal
21 * o Two strings with the same contents are equal
22 * o Case insensitive in ASCII works
23 * o Basic cases where strings aren't equal
24 * o An ASCII string that would compare greater due to case is properly less
25 * o Comparing with zero characters succeeds even if different strings
26 * o Characters in a locale / language that don't have a notion of case are
35 #include <sys/debug.h>
42 const char *str
= "kefka";
43 const char *caps
= "KEFKA";
44 const char *less
= "celes";
45 const char *more
= "terra";
46 const char *hikari
= "光";
47 const char *awake
= "目覚め";
48 size_t len
= strlen(str
);
51 * Start in en_US.UTF-8, which the test suites deps guarantee is
54 (void) setlocale(LC_ALL
, "en_US.UTF-8");
55 (void) memset(a
, 'a', sizeof (a
));
56 (void) memset(b
, 'b', sizeof (b
));
58 ret
= mbstowcs(a
, str
, len
);
59 VERIFY3U(ret
, ==, len
);
60 ret
= mbstowcs(b
, str
, len
);
61 VERIFY3U(ret
, ==, len
);
63 VERIFY0(wcsncasecmp(a
, a
, len
));
64 VERIFY0(wcsncasecmp(a
, b
, len
));
66 ret
= mbstowcs(b
, caps
, len
);
67 VERIFY3U(ret
, ==, len
);
68 VERIFY0(wcsncasecmp(a
, b
, len
));
70 ret
= mbstowcs(b
, less
, len
);
71 VERIFY3U(ret
, ==, len
);
72 VERIFY3S(wcsncasecmp(a
, b
, len
), >, 0);
74 ret
= mbstowcs(b
, more
, len
);
75 VERIFY3U(ret
, ==, len
);
76 VERIFY3S(wcsncasecmp(a
, b
, len
), <, 0);
78 ret
= mbstowcs(a
, caps
, len
);
79 VERIFY3U(ret
, ==, len
);
80 ret
= mbstowcs(b
, less
, len
);
81 VERIFY3U(ret
, ==, len
);
82 VERIFY3S(wcsncmp(a
, b
, len
), <, 0);
83 VERIFY3S(wcsncasecmp(a
, b
, len
), >, 0);
85 VERIFY3S(wcsncasecmp(a
, b
, 0), ==, 0);
88 * This locale is also guaranteed by the test suite.
90 (void) setlocale(LC_ALL
, "ja_JP.UTF-8");
91 ret
= mbstowcs(a
, hikari
, sizeof (a
));
93 ret
= mbstowcs(b
, hikari
, sizeof (b
));
95 VERIFY3S(wcsncasecmp(a
, b
, 1), ==, 0);
97 ret
= mbstowcs(b
, awake
, sizeof (b
));
99 VERIFY3S(wcsncasecmp(a
, b
, 1), !=, 0);