ReactOS  0.4.13-dev-563-g0561610
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 
11 static
12 VOID
14 {
15 #ifdef KMT_USER_MODE
17  UNICODE_STRING String = RTL_CONSTANT_STRING(L"I am a string");
22  UNICODE_STRING ZeroLengthString;
24  ULONG LongPosition;
25 
26  RtlInitUnicodeString(&ZeroLengthString, NULL);
27 
28  /* Basic checks. Covered by Winetests */
29  Position = 123;
32  ok_eq_uint(Position, 6);
33 
34  Position = 123;
37  ok_eq_uint(Position, 10);
38 
39  Position = 123;
42  ok_eq_uint(Position, 2);
43 
44  Position = 123;
47  ok_eq_uint(Position, 24);
48 
49  /* Show that checks are case sensitive by default */
50  Position = 123;
53  ok_eq_uint(Position, 0);
54 
55  Position = 123;
58  ok_eq_uint(Position, 0);
59 
60  Position = 123;
63  ok_eq_uint(Position, 2);
64 
65  Position = 123;
68  ok_eq_uint(Position, 24);
69 
70  /* Show that 4 means case insensitive */
71  Position = 123;
74  ok_eq_uint(Position, 6);
75 
76  Position = 123;
79  ok_eq_uint(Position, 10);
80 
81  Position = 123;
84  ok_eq_uint(Position, 4);
85 
86  Position = 123;
89  ok_eq_uint(Position, 22);
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;
101  ok_eq_uint(Position, 0);
102 
103  Position = 123;
106  ok_eq_uint(Position, 0);
107 
108  Position = 123;
111  ok_eq_uint(Position, 0);
112 
113  /* NULL for SearchString */
114  Position = 123;
115  KmtStartSeh()
118  ok_eq_uint(Position, 0);
119 
120  /* NULL for SearchString and invalid flags */
121  Position = 123;
122  KmtStartSeh()
126  ok_eq_uint(Position, 0);
127  ok_eq_uint(Position, 0);
128 
129  /* NULL for SearchString with zero-length MatchString */
130  Position = 123;
131  KmtStartSeh()
132  Status = RtlFindCharInUnicodeString(0, NULL, &ZeroLengthString, &Position);
134  ok_eq_uint(Position, 0);
135 
136  /* NULL for MatchString */
137  Position = 123;
138  KmtStartSeh()
141  ok_eq_uint(Position, 0);
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;
148  KmtStartSeh()
149  Status = RtlFindCharInUnicodeString(0, &ZeroLengthString, NULL, &Position);
151  ok_eq_uint(Position, 0);
152 #endif
153 
154  /* NULL for MatchString and invalid flags */
155  Position = 123;
156  KmtStartSeh()
160  ok_eq_uint(Position, 0);
161 
162  /* NULL for Position */
163  KmtStartSeh()
167 
168  /* NULL for all three */
169  KmtStartSeh()
173 #endif
174 }
175 
176 static
177 VOID
179 {
181  UNICODE_STRING Lower;
182  UNICODE_STRING Upper;
183  PWCHAR Buffer;
184 
185  Buffer = KmtAllocateGuarded(sizeof(WCHAR));
186 
187  if (!KmtIsCheckedBuild)
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 }
BOOLEAN BOOLEAN VOID VOID BOOLEAN BOOLEAN PVOID KmtAllocateGuarded(SIZE_T SizeRequested)
#define ok_eq_ulong(value, expected)
#define TRUE
Definition: types.h:120
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
static COORD Position
Definition: mouse.c:34
LONG NTSTATUS
Definition: precomp.h:26
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
static WCHAR String[]
Definition: stringtable.c:55
uint16_t * PWCHAR
Definition: typedefs.h:54
START_TEST(RtlUnicodeString)
BOOLEAN KmtIsCheckedBuild
#define UNICODE_NULL
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
static VOID TestFindCharInUnicodeString(VOID)
#define STATUS_NOT_FOUND
Definition: shellext.h:67
__wchar_t WCHAR
Definition: xmlstorage.h:180
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
static const WCHAR L[]
Definition: oid.c:1250
static VOID TestUpcaseUnicodeString(VOID)
#define KmtStartSeh()
Definition: kmt_test.h:277
Status
Definition: gdiplustypes.h:24
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlFindCharInUnicodeString(_In_ ULONG Flags, _In_ PCUNICODE_STRING SearchString, _In_ PCUNICODE_STRING MatchString, _Out_ PUSHORT Position)
unsigned int ULONG
Definition: retypes.h:1
VOID KmtFreeGuarded(PVOID Pointer)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ok_eq_hex(value, expected)
#define ok_eq_uint(value, expected)
Definition: kmt_test.h:239
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2777
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
unsigned short * PUSHORT
Definition: retypes.h:2
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14