ReactOS 0.4.16-dev-1875-g3000d45
_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
15
16/*
17 * cmp functions can either return 1/-1 or the actual difference between the
18 * first two differing characters.
19 * On Win2003, both crtdll and msvcrt always return 1/-1.
20 * On Win10, msvcrt returns the diff, crtdll returns 1/-1.
21 */
22#ifdef TEST_CRTDLL
23#define RETURN_DIFF 0
24#elif defined(TEST_MSVCRT) && defined(_WIN64)
25#define RETURN_DIFF 0
26#else
27#define RETURN_DIFF (g_WinVersion >= _WIN32_WINNT_VISTA)
28#endif
29
30#define DIFF_RETURN(sign, absolute) (sign (RETURN_DIFF ? absolute : 1))
31
33{
34 int ret;
35
37 g_WinVersion = (Version & 0xFF) << 8 | (Version & 0xFF00) >> 8;
38
39 /* Zero length always returns true */
40 ret = _mbsncmp(NULL, NULL, 0);
41 ok(ret == 0, "ret = %d\n", ret);
42
43 ret = _mbsncmp((const unsigned char *)"a", (const unsigned char *)"c", 0);
44 ok(ret == 0, "ret = %d\n", ret);
45
46 /* No null checks - length 1 crashes */
47 StartSeh()
48 (void)_mbsncmp((const unsigned char *)"a", NULL, 1);
50
51 StartSeh()
52 (void)_mbsncmp(NULL, (const unsigned char *)"c", 1);
54
55 /* Strings longer than or equal to length */
56 ret = _mbsncmp((const unsigned char *)"a", (const unsigned char *)"c", 1);
58
59 ret = _mbsncmp((const unsigned char *)"a", (const unsigned char *)"a", 1);
60 ok_eq_int(ret, 0);
61
62 ret = _mbsncmp((const unsigned char *)"ab", (const unsigned char *)"aB", 1);
63 ok_eq_int(ret, 0);
64
65 ret = _mbsncmp((const unsigned char *)"aa", (const unsigned char *)"ac", 2);
67
68 /* Length longer than one of the strings */
69 ret = _mbsncmp((const unsigned char *)"a", (const unsigned char *)"ac", 2);
70 ok_eq_int(ret, DIFF_RETURN(-, 'c'));
71
72 ret = _mbsncmp((const unsigned char *)"aa", (const unsigned char *)"a", 2);
73 ok_eq_int(ret, DIFF_RETURN(+, 'a'));
74
75 ret = _mbsncmp((const unsigned char *)"ab", (const unsigned char *)"ab", 100);
76 ok_eq_int(ret, 0);
77}
#define DIFF_RETURN(sign, absolute)
Definition: _mbsncmp.c:30
ULONG g_WinVersion
Definition: _mbsncmp.c:14
#define StartSeh()
Definition: apitest.h:95
#define ok_eq_int(value, expected)
Definition: apitest.h:119
#define EndSeh(ExpectedStatus)
Definition: apitest.h:101
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
DWORD WINAPI GetVersion(void)
Definition: version.c:1458
return ret
Definition: mutex.c:146
#define STATUS_ACCESS_VIOLATION
_Check_return_ _CRTIMP int __cdecl _mbsncmp(_In_z_ const unsigned char *_Str1, _In_z_ const unsigned char *_Str2, _In_ size_t _MaxCount)
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469