[NTDLL_APITEST] Add a test for RtlValidateUnicodeString().

This commit is contained in:
Hermès Bélusca-Maïto 2020-01-02 21:09:32 +01:00
parent 0d745e0698
commit ae8c9a1fa2
No known key found for this signature in database
GPG Key ID: 3B2539C65E7B93D0
3 changed files with 108 additions and 0 deletions

View File

@ -65,6 +65,7 @@ list(APPEND SOURCE
RtlReAllocateHeap.c
RtlUnicodeStringToAnsiString.c
RtlUpcaseUnicodeStringToCountedOemString.c
RtlValidateUnicodeString.c
StackOverflow.c
SystemInfo.c
Timer.c

View File

@ -0,0 +1,105 @@
/*
* PROJECT: ReactOS API Tests
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Test for RtlValidateUnicodeString
* COPYRIGHT: Copyright 2020 Hermes Belusca-Maito
*/
#include "precomp.h"
START_TEST(RtlValidateUnicodeString)
{
NTSTATUS Status;
UNICODE_STRING String;
UNICODE_STRING ValidString = RTL_CONSTANT_STRING(L"My Wild String!");
/* Start with a valid Unicode string */
String = ValidString;
/* Non-zero flags are unsupported! */
Status = RtlValidateUnicodeString(0, &String);
ok(Status == STATUS_SUCCESS, "Status = 0x%lx\n", Status);
Status = RtlValidateUnicodeString(1, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
Status = RtlValidateUnicodeString(0xdeadbeef, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
/* Empty string is allowed. Test also the flags. */
RtlInitEmptyUnicodeString(&String, NULL, 0);
Status = RtlValidateUnicodeString(0, &String);
ok(Status == STATUS_SUCCESS, "Status = 0x%lx\n", Status);
Status = RtlValidateUnicodeString(1, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
Status = RtlValidateUnicodeString(0xdeadbeef, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
// With a non-NULL but empty buffer, and zero lengths.
String.Buffer = L"";
Status = RtlValidateUnicodeString(0, &String);
ok(Status == STATUS_SUCCESS, "Status = 0x%lx\n", Status);
Status = RtlValidateUnicodeString(1, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
Status = RtlValidateUnicodeString(0xdeadbeef, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
// With a non-NULL but empty buffer, and zero Length, non-zero MaximumLength.
String.Buffer = L"";
String.Length = 0;
Status = RtlValidateUnicodeString(0, &String);
ok(Status == STATUS_SUCCESS, "Status = 0x%lx\n", Status);
Status = RtlValidateUnicodeString(1, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
Status = RtlValidateUnicodeString(0xdeadbeef, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
/* NULL pointer is also allowed! Test also the flags. */
Status = RtlValidateUnicodeString(0, NULL);
ok(Status == STATUS_SUCCESS, "Status = 0x%lx\n", Status);
Status = RtlValidateUnicodeString(1, NULL);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
Status = RtlValidateUnicodeString(0xdeadbeef, NULL);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
/*
* Now test invalid strings.
*/
// NULL buffer but non-zero lengths.
String = ValidString;
String.Buffer = NULL;
Status = RtlValidateUnicodeString(0, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
// NULL buffer, zero Length, non-zero MaximumLength.
String = ValidString;
String.Buffer = NULL;
String.Length = 0;
Status = RtlValidateUnicodeString(0, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
// NULL buffer, non-zero Length, zero MaximumLength.
String = ValidString;
String.Buffer = NULL;
String.MaximumLength = 0;
Status = RtlValidateUnicodeString(0, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
// Non-NULL buffer, non-zero Length, zero MaximumLength.
String = ValidString;
String.MaximumLength = 0;
Status = RtlValidateUnicodeString(0, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
/* Non-NULL buffer, odd lengths */
String = ValidString;
String.Length--; // Length was already >= 2 so it remains > 0.
Status = RtlValidateUnicodeString(0, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
String = ValidString;
String.MaximumLength--; // MaximumLength was already >= 2 so it remains > 0.
Status = RtlValidateUnicodeString(0, &String);
ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
}

View File

@ -64,6 +64,7 @@ extern void func_RtlQueryTimeZoneInformation(void);
extern void func_RtlReAllocateHeap(void);
extern void func_RtlUnicodeStringToAnsiString(void);
extern void func_RtlUpcaseUnicodeStringToCountedOemString(void);
extern void func_RtlValidateUnicodeString(void);
extern void func_StackOverflow(void);
extern void func_TimerResolution(void);
@ -130,6 +131,7 @@ const struct test winetest_testlist[] =
{ "RtlReAllocateHeap", func_RtlReAllocateHeap },
{ "RtlUnicodeStringToAnsiString", func_RtlUnicodeStringToAnsiString },
{ "RtlUpcaseUnicodeStringToCountedOemString", func_RtlUpcaseUnicodeStringToCountedOemString },
{ "RtlValidateUnicodeString", func_RtlValidateUnicodeString },
{ "StackOverflow", func_StackOverflow },
{ "TimerResolution", func_TimerResolution },