ReactOS 0.4.16-dev-197-g92996da
RtlUnicodeString.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite Runtime library unicode string functions test
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8#define KMT_EMULATE_KERNEL
9#include <kmt_test.h>
10
11static
12VOID
14{
15#ifdef KMT_USER_MODE
22 UNICODE_STRING ZeroLengthString;
24 ULONG LongPosition;
25
26 RtlInitUnicodeString(&ZeroLengthString, NULL);
27
28 /* Basic checks. Covered by Winetests */
29 Position = 123;
33
34 Position = 123;
38
39 Position = 123;
43
44 Position = 123;
48
49 /* Show that checks are case sensitive by default */
50 Position = 123;
54
55 Position = 123;
59
60 Position = 123;
64
65 Position = 123;
69
70 /* Show that 4 means case insensitive */
71 Position = 123;
75
76 Position = 123;
80
81 Position = 123;
85
86 Position = 123;
90
91 /* Show that Position is USHORT */
92 LongPosition = 0x55555555;
93 Status = RtlFindCharInUnicodeString(8, &String, &String, (PUSHORT)&LongPosition);
95 ok_eq_ulong(LongPosition, 0x55550000UL);
96
97 /* Invalid flags */
98 Position = 123;
102
103 Position = 123;
107
108 Position = 123;
112
113 /* NULL for SearchString */
114 Position = 123;
119
120 /* NULL for SearchString and invalid flags */
121 Position = 123;
128
129 /* NULL for SearchString with zero-length MatchString */
130 Position = 123;
132 Status = RtlFindCharInUnicodeString(0, NULL, &ZeroLengthString, &Position);
135
136 /* NULL for MatchString */
137 Position = 123;
142
143 /* This crashes in Windows, but not in ROS. I see no reason to add
144 * additional code or redesign the function to replicate that */
145#if 0
146 /* NULL for MatchString with zero-length SearchString */
147 Position = 123;
149 Status = RtlFindCharInUnicodeString(0, &ZeroLengthString, NULL, &Position);
152#endif
153
154 /* NULL for MatchString and invalid flags */
155 Position = 123;
161
162 /* NULL for Position */
167
168 /* NULL for all three */
173#endif
174}
175
176static
177VOID
179{
181 UNICODE_STRING Lower;
182 UNICODE_STRING Upper;
184
186
188 {
189 RtlInitEmptyUnicodeString(&Lower, NULL, 0);
190 RtlFillMemory(&Upper, sizeof(Upper), 0x55);
191 Status = RtlUpcaseUnicodeString(&Upper, &Lower, TRUE);
193 ok_eq_uint(Upper.Length, 0);
194 ok_eq_uint(Upper.MaximumLength, 0);
195 ok(Upper.Buffer != NULL, "Buffer = %p\n", Upper.Buffer);
196 RtlFreeUnicodeString(&Upper);
197
198 RtlInitEmptyUnicodeString(&Lower, Buffer, 0);
199 RtlFillMemory(&Upper, sizeof(Upper), 0x55);
200 Status = RtlUpcaseUnicodeString(&Upper, &Lower, TRUE);
202 ok_eq_uint(Upper.Length, 0);
203 ok_eq_uint(Upper.MaximumLength, 0);
204 ok(Upper.Buffer != NULL, "Buffer = %p\n", Upper.Buffer);
205 RtlFreeUnicodeString(&Upper);
206
207 RtlInitEmptyUnicodeString(&Lower, Buffer, sizeof(WCHAR));
208 Buffer[0] = UNICODE_NULL;
209 RtlFillMemory(&Upper, sizeof(Upper), 0x55);
210 Status = RtlUpcaseUnicodeString(&Upper, &Lower, TRUE);
212 ok_eq_uint(Upper.Length, 0);
213 ok_eq_uint(Upper.MaximumLength, 0);
214 ok(Upper.Buffer != NULL, "Buffer = %p\n", Upper.Buffer);
215 RtlFreeUnicodeString(&Upper);
216 }
217
218 RtlInitEmptyUnicodeString(&Lower, Buffer, sizeof(WCHAR));
219 Lower.Length = sizeof(WCHAR);
220 Buffer[0] = UNICODE_NULL;
221 RtlFillMemory(&Upper, sizeof(Upper), 0x55);
222 Status = RtlUpcaseUnicodeString(&Upper, &Lower, TRUE);
224 ok_eq_uint(Upper.Length, sizeof(WCHAR));
225 ok_eq_uint(Upper.MaximumLength, sizeof(WCHAR));
226 ok(Upper.Buffer != NULL, "Buffer = %p\n", Upper.Buffer);
227 ok_eq_hex(Upper.Buffer[0], UNICODE_NULL);
228 RtlFreeUnicodeString(&Upper);
229
230 RtlInitEmptyUnicodeString(&Lower, Buffer, sizeof(WCHAR));
231 Lower.Length = sizeof(WCHAR);
232 Buffer[0] = 'a';
233 RtlFillMemory(&Upper, sizeof(Upper), 0x55);
234 Status = RtlUpcaseUnicodeString(&Upper, &Lower, TRUE);
236 ok_eq_uint(Upper.Length, sizeof(WCHAR));
237 ok_eq_uint(Upper.MaximumLength, sizeof(WCHAR));
238 ok(Upper.Buffer != NULL, "Buffer = %p\n", Upper.Buffer);
239 ok_eq_hex(Upper.Buffer[0], 'A');
240 RtlFreeUnicodeString(&Upper);
241
242 RtlInitUnicodeString(&Lower, L"a");
243 RtlFillMemory(&Upper, sizeof(Upper), 0x55);
244 Status = RtlUpcaseUnicodeString(&Upper, &Lower, TRUE);
246 ok_eq_uint(Upper.Length, sizeof(WCHAR));
247 ok_eq_uint(Upper.MaximumLength, sizeof(WCHAR));
248 ok(Upper.Buffer != NULL, "Buffer = %p\n", Upper.Buffer);
249 ok_eq_hex(Upper.Buffer[0], 'A');
250 RtlFreeUnicodeString(&Upper);
251
253}
254
256{
259}
static VOID TestFindCharInUnicodeString(VOID)
static VOID TestUpcaseUnicodeString(VOID)
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok_eq_ulong(value, expected)
Definition: apitest.h:63
#define ok_eq_uint(value, expected)
Definition: apitest.h:61
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
Status
Definition: gdiplustypes.h:25
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
#define KmtStartSeh()
Definition: kmt_test.h:282
VOID KmtFreeGuarded(PVOID Pointer)
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:288
BOOLEAN BOOLEAN VOID VOID BOOLEAN BOOLEAN PVOID KmtAllocateGuarded(SIZE_T SizeRequested)
BOOLEAN KmtIsCheckedBuild
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define UNICODE_NULL
NTSTATUS NTAPI RtlFindCharInUnicodeString(_In_ ULONG Flags, _In_ PCUNICODE_STRING SearchString, _In_ PCUNICODE_STRING MatchString, _Out_ PUSHORT Position)
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_NOT_FOUND
Definition: shellext.h:72
USHORT MaximumLength
Definition: env_spec_w32.h:370
static COORD Position
Definition: mouse.c:34
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint16_t * PUSHORT
Definition: typedefs.h:56
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
__wchar_t WCHAR
Definition: xmlstorage.h:180