https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ae8c9a1fa2246b2d5b2c5…
commit ae8c9a1fa2246b2d5b2c583da413183c51e79b40
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Jan 2 21:09:32 2020 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Thu Jan 2 21:11:27 2020 +0100
[NTDLL_APITEST] Add a test for RtlValidateUnicodeString().
---
modules/rostests/apitests/ntdll/CMakeLists.txt | 1 +
.../apitests/ntdll/RtlValidateUnicodeString.c | 105 +++++++++++++++++++++
modules/rostests/apitests/ntdll/testlist.c | 2 +
3 files changed, 108 insertions(+)
diff --git a/modules/rostests/apitests/ntdll/CMakeLists.txt
b/modules/rostests/apitests/ntdll/CMakeLists.txt
index 0cce35587ed..64b147bdeec 100644
--- a/modules/rostests/apitests/ntdll/CMakeLists.txt
+++ b/modules/rostests/apitests/ntdll/CMakeLists.txt
@@ -65,6 +65,7 @@ list(APPEND SOURCE
RtlReAllocateHeap.c
RtlUnicodeStringToAnsiString.c
RtlUpcaseUnicodeStringToCountedOemString.c
+ RtlValidateUnicodeString.c
StackOverflow.c
SystemInfo.c
Timer.c
diff --git a/modules/rostests/apitests/ntdll/RtlValidateUnicodeString.c
b/modules/rostests/apitests/ntdll/RtlValidateUnicodeString.c
new file mode 100644
index 00000000000..8c900613d0e
--- /dev/null
+++ b/modules/rostests/apitests/ntdll/RtlValidateUnicodeString.c
@@ -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);
+}
diff --git a/modules/rostests/apitests/ntdll/testlist.c
b/modules/rostests/apitests/ntdll/testlist.c
index 9359f36808b..7624c3c23af 100644
--- a/modules/rostests/apitests/ntdll/testlist.c
+++ b/modules/rostests/apitests/ntdll/testlist.c
@@ -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 },