ReactOS 0.4.15-dev-8028-g8e799e2
_mbsncmp.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Tests for _mbsncmp
5 * COPYRIGHT: Copyright 2024 Thomas Faber (thomas.faber@reactos.org)
6 */
7
8#include <apitest.h>
9#include <mbstring.h>
10#define WIN32_NO_STATUS
11#include <pseh/pseh2.h>
12#include <ndk/mmfuncs.h>
13
14/*
15 * cmp functions can either return 1/-1 or the actual difference between the
16 * first two differing characters.
17 * On Win2003, both crtdll and msvcrt always return 1/-1.
18 * On Win10, msvcrt returns the diff, crtdll returns 1/-1.
19 */
20#ifdef TEST_CRTDLL
21#define RETURN_DIFF 0
22#else
23#define RETURN_DIFF (GetVersion() >= 0x0600)
24#endif
25
26#define DIFF_RETURN(sign, absolute) (sign (RETURN_DIFF ? absolute : 1))
27
29{
30 int ret;
31
32 /* Zero length always returns true */
33 ret = _mbsncmp(NULL, NULL, 0);
34 ok(ret == 0, "ret = %d\n", ret);
35
36 ret = _mbsncmp((const unsigned char *)"a", (const unsigned char *)"c", 0);
37 ok(ret == 0, "ret = %d\n", ret);
38
39 /* No null checks - length 1 crashes */
40 StartSeh()
41 (void)_mbsncmp((const unsigned char *)"a", NULL, 1);
43
44 StartSeh()
45 (void)_mbsncmp(NULL, (const unsigned char *)"c", 1);
47
48 /* Strings longer than or equal to length */
49 ret = _mbsncmp((const unsigned char *)"a", (const unsigned char *)"c", 1);
50 ok(ret == DIFF_RETURN(-, 2), "ret = %d\n", ret);
51
52 ret = _mbsncmp((const unsigned char *)"a", (const unsigned char *)"a", 1);
53 ok(ret == 0, "ret = %d\n", ret);
54
55 ret = _mbsncmp((const unsigned char *)"ab", (const unsigned char *)"aB", 1);
56 ok(ret == 0, "ret = %d\n", ret);
57
58 ret = _mbsncmp((const unsigned char *)"aa", (const unsigned char *)"ac", 2);
59 ok(ret == DIFF_RETURN(-, 2), "ret = %d\n", ret);
60
61 /* Length longer than one of the strings */
62 ret = _mbsncmp((const unsigned char *)"a", (const unsigned char *)"ac", 2);
63 ok(ret == DIFF_RETURN(-, 'c'), "ret = %d\n", ret);
64
65 ret = _mbsncmp((const unsigned char *)"aa", (const unsigned char *)"a", 2);
66 ok(ret == DIFF_RETURN(+, 'a'), "ret = %d\n", ret);
67
68 ret = _mbsncmp((const unsigned char *)"ab", (const unsigned char *)"ab", 100);
69 ok(ret == 0, "ret = %d\n", ret);
70}
#define DIFF_RETURN(sign, absolute)
Definition: _mbsncmp.c:26
#define StartSeh()
Definition: _sntprintf.h:16
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
_Check_return_ _CRTIMP int __cdecl _mbsncmp(_In_z_ const unsigned char *_Str1, _In_z_ const unsigned char *_Str2, _In_ size_t _MaxCount)
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
int ret