* PROJECT: ReactOS kernel-mode tests
* LICENSE: GPLv2+ - See COPYING in the top level directory
* PURPOSE: Kernel-Mode Test Suite Runtime library unicode string functions test
- * PROGRAMMER: Thomas Faber <thfabba@gmx.de>
+ * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
*/
#define KMT_EMULATE_KERNEL
#include <kmt_test.h>
-#define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
-#define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok_eq_hex(ExceptionStatus, ExpectedStatus)
-
static
VOID
TestFindCharInUnicodeString(VOID)
{
#ifdef KMT_USER_MODE
- NTSTATUS ExceptionStatus;
NTSTATUS Status;
UNICODE_STRING String = RTL_CONSTANT_STRING(L"I am a string");
UNICODE_STRING Chars = RTL_CONSTANT_STRING(L"a");
Status = RtlFindCharInUnicodeString(7, &String, &Chars4, &Position);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_uint(Position, 22);
-
+
/* Show that Position is USHORT */
LongPosition = 0x55555555;
Status = RtlFindCharInUnicodeString(8, &String, &String, (PUSHORT)&LongPosition);
/* NULL for SearchString */
Position = 123;
- StartSeh()
+ KmtStartSeh()
Status = RtlFindCharInUnicodeString(0, NULL, &String, &Position);
- EndSeh(STATUS_ACCESS_VIOLATION);
+ KmtEndSeh(STATUS_ACCESS_VIOLATION);
ok_eq_uint(Position, 0);
-
+
/* NULL for SearchString and invalid flags */
Position = 123;
- StartSeh()
+ KmtStartSeh()
Status = RtlFindCharInUnicodeString(8, NULL, &String, &Position);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
ok_eq_uint(Position, 0);
ok_eq_uint(Position, 0);
/* NULL for SearchString with zero-length MatchString */
Position = 123;
- StartSeh()
+ KmtStartSeh()
Status = RtlFindCharInUnicodeString(0, NULL, &ZeroLengthString, &Position);
- EndSeh(STATUS_ACCESS_VIOLATION);
+ KmtEndSeh(STATUS_ACCESS_VIOLATION);
ok_eq_uint(Position, 0);
/* NULL for MatchString */
Position = 123;
- StartSeh()
+ KmtStartSeh()
Status = RtlFindCharInUnicodeString(0, &String, NULL, &Position);
- EndSeh(STATUS_ACCESS_VIOLATION);
+ KmtEndSeh(STATUS_ACCESS_VIOLATION);
ok_eq_uint(Position, 0);
/* This crashes in Windows, but not in ROS. I see no reason to add
#if 0
/* NULL for MatchString with zero-length SearchString */
Position = 123;
- StartSeh()
+ KmtStartSeh()
Status = RtlFindCharInUnicodeString(0, &ZeroLengthString, NULL, &Position);
- EndSeh(STATUS_ACCESS_VIOLATION);
+ KmtEndSeh(STATUS_ACCESS_VIOLATION);
ok_eq_uint(Position, 0);
#endif
-
+
/* NULL for MatchString and invalid flags */
Position = 123;
- StartSeh()
+ KmtStartSeh()
Status = RtlFindCharInUnicodeString(8, &String, NULL, &Position);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
ok_eq_uint(Position, 0);
/* NULL for Position */
- StartSeh()
+ KmtStartSeh()
Status = RtlFindCharInUnicodeString(0, &String, &String, NULL);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
/* NULL for all three */
- StartSeh()
+ KmtStartSeh()
Status = RtlFindCharInUnicodeString(0, NULL, NULL, NULL);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
#endif
}
+static
+VOID
+TestUpcaseUnicodeString(VOID)
+{
+ NTSTATUS Status;
+ UNICODE_STRING Lower;
+ UNICODE_STRING Upper;
+ PWCHAR Buffer;
+
+ Buffer = KmtAllocateGuarded(sizeof(WCHAR));
+
+ if (!KmtIsCheckedBuild)
+ {
+ RtlInitEmptyUnicodeString(&Lower, NULL, 0);
+ RtlFillMemory(&Upper, sizeof(Upper), 0x55);
+ Status = RtlUpcaseUnicodeString(&Upper, &Lower, TRUE);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ ok_eq_uint(Upper.Length, 0);
+ ok_eq_uint(Upper.MaximumLength, 0);
+ ok(Upper.Buffer != NULL, "Buffer = %p\n", Upper.Buffer);
+ RtlFreeUnicodeString(&Upper);
+
+ RtlInitEmptyUnicodeString(&Lower, Buffer, 0);
+ RtlFillMemory(&Upper, sizeof(Upper), 0x55);
+ Status = RtlUpcaseUnicodeString(&Upper, &Lower, TRUE);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ ok_eq_uint(Upper.Length, 0);
+ ok_eq_uint(Upper.MaximumLength, 0);
+ ok(Upper.Buffer != NULL, "Buffer = %p\n", Upper.Buffer);
+ RtlFreeUnicodeString(&Upper);
+
+ RtlInitEmptyUnicodeString(&Lower, Buffer, sizeof(WCHAR));
+ Buffer[0] = UNICODE_NULL;
+ RtlFillMemory(&Upper, sizeof(Upper), 0x55);
+ Status = RtlUpcaseUnicodeString(&Upper, &Lower, TRUE);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ ok_eq_uint(Upper.Length, 0);
+ ok_eq_uint(Upper.MaximumLength, 0);
+ ok(Upper.Buffer != NULL, "Buffer = %p\n", Upper.Buffer);
+ RtlFreeUnicodeString(&Upper);
+ }
+
+ RtlInitEmptyUnicodeString(&Lower, Buffer, sizeof(WCHAR));
+ Lower.Length = sizeof(WCHAR);
+ Buffer[0] = UNICODE_NULL;
+ RtlFillMemory(&Upper, sizeof(Upper), 0x55);
+ Status = RtlUpcaseUnicodeString(&Upper, &Lower, TRUE);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ ok_eq_uint(Upper.Length, sizeof(WCHAR));
+ ok_eq_uint(Upper.MaximumLength, sizeof(WCHAR));
+ ok(Upper.Buffer != NULL, "Buffer = %p\n", Upper.Buffer);
+ ok_eq_hex(Upper.Buffer[0], UNICODE_NULL);
+ RtlFreeUnicodeString(&Upper);
+
+ RtlInitEmptyUnicodeString(&Lower, Buffer, sizeof(WCHAR));
+ Lower.Length = sizeof(WCHAR);
+ Buffer[0] = 'a';
+ RtlFillMemory(&Upper, sizeof(Upper), 0x55);
+ Status = RtlUpcaseUnicodeString(&Upper, &Lower, TRUE);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ ok_eq_uint(Upper.Length, sizeof(WCHAR));
+ ok_eq_uint(Upper.MaximumLength, sizeof(WCHAR));
+ ok(Upper.Buffer != NULL, "Buffer = %p\n", Upper.Buffer);
+ ok_eq_hex(Upper.Buffer[0], 'A');
+ RtlFreeUnicodeString(&Upper);
+
+ RtlInitUnicodeString(&Lower, L"a");
+ RtlFillMemory(&Upper, sizeof(Upper), 0x55);
+ Status = RtlUpcaseUnicodeString(&Upper, &Lower, TRUE);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ ok_eq_uint(Upper.Length, sizeof(WCHAR));
+ ok_eq_uint(Upper.MaximumLength, sizeof(WCHAR));
+ ok(Upper.Buffer != NULL, "Buffer = %p\n", Upper.Buffer);
+ ok_eq_hex(Upper.Buffer[0], 'A');
+ RtlFreeUnicodeString(&Upper);
+
+ KmtFreeGuarded(Buffer);
+}
+
START_TEST(RtlUnicodeString)
{
TestFindCharInUnicodeString();
+ TestUpcaseUnicodeString();
}