Index: rtl/RtlUnicodeString.c =================================================================== --- rtl/RtlUnicodeString.c (revision 60823) +++ rtl/RtlUnicodeString.c (working copy) @@ -173,7 +173,152 @@ #endif } + +static +VOID +TestRtlUpcaseUnicodeString(VOID) +{ + NTSTATUS Status; + LONG Comparison; + USHORT i; + + UNICODE_STRING StringUpcased; + UNICODE_STRING StringUpcasedRef; + UNICODE_STRING StringToUpcase; + UNICODE_STRING StringZeroed; + + WCHAR Max[UNICODE_STRING_MAX_BYTES]; + WCHAR MaxRef[UNICODE_STRING_MAX_BYTES]; + WCHAR StringBuffer[10]; + + UNICODE_STRING StringToUpcase2 = RTL_CONSTANT_STRING(L"aBcde"); + UNICODE_STRING StringUpcasedRef2 = RTL_CONSTANT_STRING(L"ABCDE0"); + +// TEST#1: Allocate buffer. + + RtlInitUnicodeString(&StringToUpcase, L" rEactOS rO#ks !!\"??"); + RtlInitUnicodeString(&StringUpcasedRef, L" REACTOS RO#KS !!\"??"); + RtlInitUnicodeString(&StringUpcased, L"ILOVETOEATDEADBEEF!!!"); + + Status = RtlUpcaseUnicodeString(&StringUpcased, &StringToUpcase, TRUE); + ok_eq_hex(Status, STATUS_SUCCESS); + + /*Check the API has Upcased correctly*/ + Comparison = RtlCompareUnicodeString(&StringUpcasedRef, &StringUpcased, FALSE); + ok_eq_long(Comparison, 0); + ok(StringUpcased.Length == 40, "Expected 40, StringUpcased.Length: %u \n", StringUpcased.Length); + ok(StringUpcased.MaximumLength == 40, "Expected 40, StringUpcased.MaximumLength: %u \n", StringUpcased.MaximumLength); + + /*Check the API didn't overwrite the original */ + ok_eq_wstr(StringToUpcase.Buffer, L" rEactOS rO#ks !!\"??"); + + RtlFreeUnicodeString(&StringUpcased); + +// TEST#2: Allocate UNICODE_STRING_MAX_CHARS buffer + + for (i = 0; i < UNICODE_STRING_MAX_CHARS-2; i++) + Max[i] = L'r'; + Max[UNICODE_STRING_MAX_CHARS-1] = L'\0'; + + for (i = 0; i < UNICODE_STRING_MAX_CHARS-2; i++) + MaxRef[i]= L'R'; + MaxRef[UNICODE_STRING_MAX_CHARS-1] = L'\0'; + RtlInitUnicodeString(&StringToUpcase, Max); + RtlInitUnicodeString(&StringUpcasedRef, MaxRef); + RtlInitUnicodeString(&StringUpcased, L"ILOVETOEATDEADBEEF!!!"); + + Status = RtlUpcaseUnicodeString(&StringUpcased, &StringToUpcase, TRUE); + ok_eq_hex(Status, STATUS_SUCCESS); + Comparison = RtlCompareUnicodeString(&StringUpcased, &StringUpcasedRef, FALSE); + ok_eq_long(Comparison, 0); + ok(StringUpcased.Length == UNICODE_STRING_MAX_BYTES-4, "Expected %u, StringUpcased.Length: %u \n", UNICODE_STRING_MAX_BYTES-4, StringUpcased.Length); + ok(StringUpcased.MaximumLength == UNICODE_STRING_MAX_BYTES-4, "Expected %u, StringUpcased.MaximumLength: %u \n", UNICODE_STRING_MAX_BYTES-4, StringUpcased.MaximumLength); + + /*Check the API didn't overwrite the original */ + ok_eq_wstr(StringToUpcase.Buffer, Max); + + RtlFreeUnicodeString(&StringUpcased); + +// TEST#3: Allocate UNICODE_STRING_MAX_CHARS + 5 buffer + + for (i = 0; i < UNICODE_STRING_MAX_CHARS+3; i++) + Max[i] = L'r'; + Max[UNICODE_STRING_MAX_CHARS+4] = L'\0'; + + for (i = 0; i < UNICODE_STRING_MAX_CHARS+3; i++) + MaxRef[i]= L'R'; + MaxRef[UNICODE_STRING_MAX_CHARS+4] = L'\0'; + RtlInitUnicodeString(&StringToUpcase, Max); + RtlInitUnicodeString(&StringUpcasedRef, MaxRef); + RtlInitUnicodeString(&StringUpcased, L"ILOVETOEATDEADBEEF!!!"); + + Status = RtlUpcaseUnicodeString(&StringUpcased, &StringToUpcase, TRUE); + ok_eq_hex(Status, STATUS_SUCCESS); + Comparison = RtlCompareUnicodeString(&StringUpcased, &StringUpcasedRef, FALSE); + ok_eq_long(Comparison, 0); + ok(StringUpcased.Length == UNICODE_STRING_MAX_BYTES - 2, "Expected %u, StringUpcased.Length: %u \n", UNICODE_STRING_MAX_BYTES - 2, StringUpcased.Length); + ok(StringUpcased.MaximumLength == UNICODE_STRING_MAX_BYTES - 2, "Expected %u, StringUpcased.MaximumLength: %u \n", UNICODE_STRING_MAX_BYTES - 2, StringUpcased.MaximumLength); + + //Check the API didn't overwrite the original + ok_eq_wstr(StringToUpcase.Buffer, Max); + + RtlFreeUnicodeString(&StringUpcased); + +// TEST#4: Allocate Buffer. RtlUpcaseUnicodeString accepts an empty UNICODE_STRING as StringToUpcase argument. + + RtlInitUnicodeString(&StringToUpcase, NULL); + RtlInitUnicodeString(&StringUpcased, L"ILOVETOEATDEADBEEF!!!"); + + Status = RtlUpcaseUnicodeString(&StringUpcased, &StringToUpcase, TRUE); + ok_eq_hex(Status, STATUS_SUCCESS); + ok(StringUpcased.Length == 0, "Expected zero, StringUpcased.Length: %u \n", StringUpcased.Length); + ok(StringUpcased.MaximumLength == 0, "Expected zero, StringUpcased.MaximumLength: %u \n", StringUpcased.MaximumLength); + + RtlFreeUnicodeString(&StringUpcased); + +// TEST#5: Don't allocate Buffer. RtlUpcaseUnicodeString accepts an empty UNICODE_STRING as StringToUpcase argument. + + + RtlInitUnicodeString(&StringToUpcase, NULL); + RtlInitUnicodeString(&StringUpcased, L"ILOVETOEATDEADBEEF!!!"); + + Status = RtlUpcaseUnicodeString(&StringUpcased, &StringToUpcase, FALSE); + ok_eq_hex(Status, STATUS_SUCCESS); + ok(StringUpcased.Length == 0, "Expected zero, StringUpcased.Length: %u \n", StringUpcased.Length); + ok(StringUpcased.MaximumLength == 44, "Expected zero, StringUpcased.MaximumLength: %u \n", StringUpcased.MaximumLength); + + RtlFreeUnicodeString(&StringUpcased); + + +// TEST#6: RtlUpcaseUnicodeString doesn't accept NULL as StringToUpcase argument. + + RtlInitUnicodeString(&StringUpcased, L"ILOVETOEATDEADBEEF!!!"); + KmtStartSeh() + Status = RtlUpcaseUnicodeString(&StringUpcased, NULL, TRUE); + KmtEndSeh(STATUS_ACCESS_VIOLATION); + + RtlFreeUnicodeString(&StringUpcased); + + +// PTEST#7: Don't allocate buffer. Also RtlUpcaseUnicodeString doesnt NULL terminate the StringUpcased + RtlInitEmptyUnicodeString(&StringZeroed, StringBuffer, sizeof(StringBuffer)); + RtlAppendUnicodeToString(&StringZeroed, L"000000"); + + Status = RtlUpcaseUnicodeString(&StringZeroed, &StringToUpcase2, FALSE); + ok_eq_hex(Status, STATUS_SUCCESS); + Comparison = RtlCompareUnicodeString(&StringZeroed, &StringUpcasedRef2, FALSE); + + //Why comparison is -2? + ok_eq_long(Comparison, 0); + ok_eq_wstr(StringZeroed.Buffer, StringUpcasedRef2.Buffer); + + /*Check the API didn't overwrite the original */ + ok_eq_wstr(StringToUpcase2.Buffer, L"aBcde"); + +} + START_TEST(RtlUnicodeString) { TestFindCharInUnicodeString(); + TestRtlUpcaseUnicodeString(); }