ReactOS 0.4.16-dev-1946-g52006dd
_mbsncat.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 _mbsncat
5 * COPYRIGHT: Copyright 2025 Doug Lyons <douglyons@douglyons.com>
6 * Copyright 2025 Stanislav Motylkov <x86corez@gmail.com>
7 */
8
9#include <apitest.h>
10#include <mbstring.h>
11#define WIN32_NO_STATUS
12#include <pseh/pseh2.h>
13#include <ndk/mmfuncs.h>
14
15typedef unsigned char *(__cdecl *PFN__mbsncat)(unsigned char*, const unsigned char*, size_t);
16
17#ifndef TEST_STATIC_CRT
19{
20 static PFN__mbsncat p__mbsncat;
22
23 p__mbsncat = (PFN__mbsncat)GetProcAddress(hdll, fname);
24 ok(p__mbsncat != NULL, "Failed to load %s from %s\n", fname, TEST_DLL_NAME);
25 return p__mbsncat;
26}
27#endif
28
30{
31 return ((GetVersion() & 0xFF) << 8) |
32 ((GetVersion() >> 8) & 0xFF);
33}
34
36{
37 unsigned char dest[16];
38 const unsigned char first[] = "dinosaur";
39 const unsigned char second[] = "duck";
40 unsigned char *s;
41 BOOL MsVcrt = FALSE, CrtDll = FALSE;
42
43#ifdef TEST_MSVCRT
44 MsVcrt = TRUE;
45#endif
46#ifdef TEST_CRTDLL
47 CrtDll = TRUE;
48#endif
49
50#ifndef TEST_STATIC_CRT
51 if (!func)
52 func = Init(fname);
53#endif
54 if (!func)
55 {
56 skip("Skipping tests, because %s is not available\n", fname);
57 return;
58 }
59
60 /* Test invalid arguments */
61 StartSeh()
62 s = func(NULL, NULL, 0);
64 ok(s == NULL, "Expected %s to return NULL, got %p\n", fname, s);
65
66 StartSeh()
67 s = func(NULL, NULL, 10);
68 EndSeh((CrtDll || (MsVcrt && GetWinVersion() <= 0x502)) ? STATUS_ACCESS_VIOLATION : STATUS_SUCCESS);
69 ok(s == NULL, "Expected %s to return NULL, got %p\n", fname, s);
70
71 memset(dest, 'X', sizeof(dest));
72 StartSeh()
73 s = func(dest, NULL, 0);
75 ok(s == dest, "Expected %s to return dest pointer, got %p\n", fname, s);
76 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
77
78 memset(dest, 'X', sizeof(dest));
79 StartSeh()
80 s = func(dest, second, 0);
82 ok(s == dest, "Expected %s to return dest pointer, got %p\n", fname, s);
83 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
84
85 memset(dest, 'X', sizeof(dest));
86 s = NULL;
87 StartSeh()
88 s = func(dest, NULL, 10);
89 EndSeh((CrtDll || (MsVcrt && GetWinVersion() <= 0x502)) ? STATUS_ACCESS_VIOLATION : STATUS_SUCCESS);
90 ok(s == NULL, "Expected %s to return NULL, got %p\n", fname, s);
91 ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
92
93 memset(dest, 'X', sizeof(dest));
94 dest[0] = '\0';
95 StartSeh()
96 s = func(dest, second, sizeof(second));
98 ok(s == dest, "Expected %s to return dest pointer, got %p\n", fname, s);
99 ok(!memcmp(dest, second, sizeof(second)),
100 "Expected the output buffer string to be \"duck\", got '%s'\n", dest);
101
102 /* Test source truncation behavior */
103 memset(dest, 'X', sizeof(dest));
104 memcpy(dest, first, sizeof(first));
105 s = func(dest, second, 0);
106 ok(s == dest, "Expected %s to return dest pointer, got %p\n", fname, s);
107 ok(!memcmp(dest, first, sizeof(first)),
108 "Expected the output buffer string to be \"dinosaur\", got '%s'\n", dest);
109
110 memset(dest, 'X', sizeof(dest));
111 memcpy(dest, first, sizeof(first));
112 s = func(dest, second, sizeof(second));
113 ok(s == dest, "Expected %s to return dest pointer, got %p\n", fname, s);
114 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
115 "Expected the output buffer string to be \"dinosaurduck\", got '%s'\n", dest);
116
117 memset(dest, 'X', sizeof(dest));
118 memcpy(dest, first, sizeof(first));
119 s = func(dest, second, sizeof(second) + 1);
120 ok(s == dest, "Expected %s to return dest pointer, got %p\n", fname, s);
121 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
122 "Expected the output buffer string to be \"dinosaurduck\", got '%s'\n", dest);
123
124 memset(dest, 'X', sizeof(dest));
125 memcpy(dest, first, sizeof(first));
126 s = func(dest, second, sizeof(second) - 1);
127 ok(s == dest, "Expected %s to return dest pointer, got %p\n", fname, s);
128 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
129 "Expected the output buffer string to be \"dinosaurduck\", got '%s'\n", dest);
130
131 memset(dest, 'X', sizeof(dest));
132 memcpy(dest, first, sizeof(first));
133 s = func(dest, second, sizeof(second) - 2);
134 ok(s == dest, "Expected %s to return dest pointer, got %p\n", fname, s);
135 ok(!memcmp(dest, "dinosaurduc", sizeof("dinosaurduc")),
136 "Expected the output buffer string to be \"dinosaurduc\", got '%s'\n", dest);
137
138 /* Test typical scenario */
139 memset(dest, 'X', sizeof(dest));
140 memcpy(dest, first, sizeof(first));
141 s = func(dest, second, sizeof(second) - 1);
142 ok(s == dest, "Expected %s to return dest pointer, got %p\n", fname, s);
143 ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
144 "Expected the output buffer string to be \"dinosaurduck\", got '%s'\n", dest);
145
146 /* TODO: Add some distinguishing tests (_mbsncat vs. _mbsnbcat) for concatenating chars vs. bytes,
147 * should probably be done with actual multibyte-character strings. */
148}
149
151{
152#ifndef TEST_STATIC_CRT
153 #define _mbsncat NULL
154#endif
155 mbsncat_PerformTests("_mbsncat", _mbsncat);
156}
unsigned char *(__cdecl * PFN__mbsncat)(unsigned char *, const unsigned char *, size_t)
Definition: _mbsncat.c:15
VOID mbsncat_PerformTests(_In_ LPSTR fname, _In_opt_ PFN__mbsncat func)
Definition: _mbsncat.c:35
#define _mbsncat
static USHORT GetWinVersion(VOID)
Definition: _mbsncat.c:29
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define __cdecl
Definition: accygwin.h:79
#define StartSeh()
Definition: apitest.h:93
#define EndSeh(ExpectedStatus)
Definition: apitest.h:99
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
DWORD WINAPI GetVersion(void)
Definition: version.c:1458
unsigned int BOOL
Definition: ntddk_ex.h:94
#define STATUS_ACCESS_VIOLATION
GLdouble s
Definition: gl.h:2039
GLenum func
Definition: glext.h:6028
const GLint * first
Definition: glext.h:5794
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define TEST_DLL_NAME
Definition: wsprintf.c:3
static char * dest
Definition: rtl.c:135
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
unsigned short USHORT
Definition: pedump.c:61
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
static PVOID hdll
Definition: shimdbg.c:126
char * LPSTR
Definition: xmlstorage.h:182