ReactOS 0.4.16-dev-1946-g52006dd
_mbsncat.c File Reference
#include <apitest.h>
#include <mbstring.h>
#include <pseh/pseh2.h>
#include <ndk/mmfuncs.h>
Include dependency graph for _mbsncat.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define _mbsncat   NULL
 

Typedefs

typedef unsigned char *(__cdeclPFN__mbsncat) (unsigned char *, const unsigned char *, size_t)
 

Functions

static PFN__mbsncat Init (_In_ LPSTR fname)
 
static USHORT GetWinVersion (VOID)
 
VOID mbsncat_PerformTests (_In_ LPSTR fname, _In_opt_ PFN__mbsncat func)
 
 START_TEST (_mbsncat)
 

Macro Definition Documentation

◆ _mbsncat

#define _mbsncat   NULL

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file _mbsncat.c.

Typedef Documentation

◆ PFN__mbsncat

typedef unsigned char *(__cdecl * PFN__mbsncat) (unsigned char *, const unsigned char *, size_t)

Definition at line 15 of file _mbsncat.c.

Function Documentation

◆ GetWinVersion()

static USHORT GetWinVersion ( VOID  )
static

Definition at line 29 of file _mbsncat.c.

30{
31 return ((GetVersion() & 0xFF) << 8) |
32 ((GetVersion() >> 8) & 0xFF);
33}
DWORD WINAPI GetVersion(void)
Definition: version.c:1458

Referenced by mbsncat_PerformTests().

◆ Init()

static PFN__mbsncat Init ( _In_ LPSTR  fname)
static

Definition at line 18 of file _mbsncat.c.

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}
unsigned char *(__cdecl * PFN__mbsncat)(unsigned char *, const unsigned char *, size_t)
Definition: _mbsncat.c:15
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define GetProcAddress(x, y)
Definition: compat.h:753
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define TEST_DLL_NAME
Definition: wsprintf.c:3
static PVOID hdll
Definition: shimdbg.c:126

◆ mbsncat_PerformTests()

VOID mbsncat_PerformTests ( _In_ LPSTR  fname,
_In_opt_ PFN__mbsncat  func 
)

Definition at line 35 of file _mbsncat.c.

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));
105 s = func(dest, second, 0);
106 ok(s == dest, "Expected %s to return dest pointer, got %p\n", fname, s);
108 "Expected the output buffer string to be \"dinosaur\", got '%s'\n", dest);
109
110 memset(dest, 'X', sizeof(dest));
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));
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));
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));
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));
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}
BOOLEAN Expected
static USHORT GetWinVersion(VOID)
Definition: _mbsncat.c:29
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define StartSeh()
Definition: apitest.h:93
#define EndSeh(ExpectedStatus)
Definition: apitest.h:99
#define skip(...)
Definition: atltest.h:64
return
Definition: dirsup.c:529
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define STATUS_ACCESS_VIOLATION
GLdouble s
Definition: gl.h:2039
GLenum func
Definition: glext.h:6028
GLdouble n
Definition: glext.h:7729
GLuint buffer
Definition: glext.h:5915
GLsizei const GLvoid * pointer
Definition: glext.h:5848
const GLint * first
Definition: glext.h:5794
GLfloat GLfloat p
Definition: glext.h:8902
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static char * dest
Definition: rtl.c:135
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( _mbsncat  )

Definition at line 150 of file _mbsncat.c.

151{
152#ifndef TEST_STATIC_CRT
153 #define _mbsncat NULL
154#endif
155 mbsncat_PerformTests("_mbsncat", _mbsncat);
156}
VOID mbsncat_PerformTests(_In_ LPSTR fname, _In_opt_ PFN__mbsncat func)
Definition: _mbsncat.c:35
#define _mbsncat