ReactOS 0.4.15-dev-8236-g99f0937
_mbsstr.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 _mbsstr
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 unsigned char *haystack;
17 unsigned char *ret;
18
19 /* NULL pointers are not handled */
20 StartSeh()
23
24 StartSeh()
25 haystack = (unsigned char *)"hello";
28
29 StartSeh()
30 haystack = (unsigned char *)"";
33
34 /* Empty needle returns haystack, empty haystack returns NULL... */
35 haystack = (unsigned char *)"hello";
36 ret = _mbsstr(haystack, (const unsigned char *)"");
37 ok(ret == haystack, "ret = %p, haystack = %p\n", ret, haystack);
38
39 haystack = (unsigned char *)"";
40 ret = _mbsstr(haystack, (const unsigned char *)"a");
41 ok(ret == NULL, "ret = %p, haystack = %p\n", ret, haystack);
42
43 /* ... but if both are empty, behavior differs */
44 haystack = (unsigned char *)"";
45 ret = _mbsstr(haystack, (const unsigned char *)"");
46#ifdef TEST_CRTDLL
47 ok(ret == NULL, "ret = %p, haystack = %p\n", ret, haystack);
48#else
49 ok(ret == haystack, "ret = %p, haystack = %p\n", ret, haystack);
50#endif
51
52 /* Simple "found" cases */
53 haystack = (unsigned char *)"abcdefg";
54 ret = _mbsstr(haystack, (const unsigned char *)"abc");
55 ok(ret == haystack, "ret = %p, haystack = %p\n", ret, haystack);
56
57 haystack = (unsigned char *)"abcdefg";
58 ret = _mbsstr(haystack, (const unsigned char *)"g");
59 ok(ret == haystack + 6, "ret = %p, haystack = %p\n", ret, haystack);
60
61 haystack = (unsigned char *)"abcdefg";
62 ret = _mbsstr(haystack, (const unsigned char *)"abcdefg");
63 ok(ret == haystack, "ret = %p, haystack = %p\n", ret, haystack);
64
65 /* Simple "not found" cases */
66 haystack = (unsigned char *)"abcdefg";
67 ret = _mbsstr(haystack, (const unsigned char *)"h");
68 ok(ret == NULL, "ret = %p, haystack = %p\n", ret, haystack);
69
70 haystack = (unsigned char *)"abcdefg";
71 ret = _mbsstr(haystack, (const unsigned char *)"gh");
72 ok(ret == NULL, "ret = %p, haystack = %p\n", ret, haystack);
73
74 haystack = (unsigned char *)"abcdefg";
75 ret = _mbsstr(haystack, (const unsigned char *)"abcD");
76 ok(ret == NULL, "ret = %p, haystack = %p\n", ret, haystack);
77
78 /* Needle longer than haystack */
79 haystack = (unsigned char *)"abcdefg";
80 ret = _mbsstr(haystack, (const unsigned char *)"abcdefgh");
81 ok(ret == NULL, "ret = %p, haystack = %p\n", ret, haystack);
82
83 haystack = (unsigned char *)"abcdefg";
84 ret = _mbsstr(haystack, (const unsigned char *)"xxxxxxxx");
85 ok(ret == NULL, "ret = %p, haystack = %p\n", ret, haystack);
86}
87
#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 _CONST_RETURN unsigned char *__cdecl _mbsstr(_In_z_ const unsigned char *_Str, _In_z_ const unsigned char *_Substr)
static const char haystack[]
Definition: editor.c:145
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
int ret