https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3a33ab96380c1ed213a083e490027a11ca5fbb58

commit 3a33ab96380c1ed213a083e490027a11ca5fbb58
Author: Pierre Schweitzer <pie...@reactos.org>
AuthorDate: Mon Oct 16 22:04:22 2017 +0200

    [NTDLL_APITEST] Add simple tests for RtlUnicodeStringToAnsiString() that 
were used to test the kernel32 regression
---
 modules/rostests/apitests/ntdll/CMakeLists.txt     |  1 +
 .../apitests/ntdll/RtlUnicodeStringToAnsiString.c  | 52 ++++++++++++++++++++++
 modules/rostests/apitests/ntdll/testlist.c         |  2 +
 3 files changed, 55 insertions(+)

diff --git a/modules/rostests/apitests/ntdll/CMakeLists.txt 
b/modules/rostests/apitests/ntdll/CMakeLists.txt
index 7a56d74a85..23da6c5570 100644
--- a/modules/rostests/apitests/ntdll/CMakeLists.txt
+++ b/modules/rostests/apitests/ntdll/CMakeLists.txt
@@ -50,6 +50,7 @@ list(APPEND SOURCE
     RtlNtPathNameToDosPathName.c
     RtlpEnsureBufferSize.c
     RtlReAllocateHeap.c
+    RtlUnicodeStringToAnsiString.c
     RtlUpcaseUnicodeStringToCountedOemString.c
     StackOverflow.c
     SystemInfo.c
diff --git a/modules/rostests/apitests/ntdll/RtlUnicodeStringToAnsiString.c 
b/modules/rostests/apitests/ntdll/RtlUnicodeStringToAnsiString.c
new file mode 100644
index 0000000000..a517299568
--- /dev/null
+++ b/modules/rostests/apitests/ntdll/RtlUnicodeStringToAnsiString.c
@@ -0,0 +1,52 @@
+/*
+ * PROJECT:         ReactOS API tests
+ * LICENSE:         LGPLv2.1+ - See COPYING.LIB in the top level directory
+ * PURPOSE:         Test for RtlUnicodeStringToAnsiString
+ * PROGRAMMERS:     Pierre Schweitzer <pie...@reactos.org>
+ */
+
+#include <apitest.h>
+#include <ndk/rtlfuncs.h>
+
+START_TEST(RtlUnicodeStringToAnsiString)
+{
+    WCHAR BufferU[10];
+    CHAR BufferA[10];
+    UNICODE_STRING StringU;
+    ANSI_STRING StringA;
+    NTSTATUS Status;
+    DWORD i;
+
+    memset(BufferU, 0xAA, sizeof(BufferU));
+    memset(BufferA, 0xAA, sizeof(BufferA));
+
+    BufferU[0] = L'A';
+    BufferU[1] = UNICODE_NULL;
+
+    StringU.Buffer = BufferU;
+    StringU.MaximumLength = 10 * sizeof(WCHAR);
+
+    RtlInitUnicodeString(&StringU, BufferU);
+    ok(StringU.Length == 1 * sizeof(WCHAR), "Invalid size: %d\n", 
StringU.Length);
+    ok(StringU.MaximumLength == 2 * sizeof(WCHAR), "Invalid size: %d\n", 
StringU.MaximumLength);
+    ok(StringU.Buffer == BufferU, "Invalid buffer: %p\n", StringU.Buffer);
+
+    StringA.Buffer = BufferA;
+    StringA.MaximumLength = 10 * sizeof(CHAR);
+
+    Status = RtlUnicodeStringToAnsiString(&StringA, &StringU, FALSE);
+    ok(NT_SUCCESS(Status), "RtlUnicodeStringToAnsiString failed: %lx\n", 
Status);
+    ok(StringA.Length == 1 * sizeof(CHAR), "Invalid size: %d\n", 
StringA.Length);
+    ok(StringA.MaximumLength == 10 * sizeof(CHAR), "Invalid size: %d\n", 
StringA.MaximumLength);
+    ok(StringA.Buffer == BufferA, "Invalid buffer: %p\n", StringA.Buffer);
+
+    for (i = 0; i < 10; ++i)
+    {
+        if (BufferA[i] == 0)
+        {
+            break;
+        }
+    }
+
+    ok(i != 10, "String was not null terminated!\n");
+}
diff --git a/modules/rostests/apitests/ntdll/testlist.c 
b/modules/rostests/apitests/ntdll/testlist.c
index 8b4f8f657d..f17f87267c 100644
--- a/modules/rostests/apitests/ntdll/testlist.c
+++ b/modules/rostests/apitests/ntdll/testlist.c
@@ -54,6 +54,7 @@ extern void func_RtlMemoryStream(void);
 extern void func_RtlNtPathNameToDosPathName(void);
 extern void func_RtlpEnsureBufferSize(void);
 extern void func_RtlReAllocateHeap(void);
+extern void func_RtlUnicodeStringToAnsiString(void);
 extern void func_RtlUpcaseUnicodeStringToCountedOemString(void);
 extern void func_StackOverflow(void);
 extern void func_TimerResolution(void);
@@ -111,6 +112,7 @@ const struct test winetest_testlist[] =
     { "RtlNtPathNameToDosPathName",     func_RtlNtPathNameToDosPathName },
     { "RtlpEnsureBufferSize",           func_RtlpEnsureBufferSize },
     { "RtlReAllocateHeap",              func_RtlReAllocateHeap },
+    { "RtlUnicodeStringToAnsiString",   func_RtlUnicodeStringToAnsiString },
     { "RtlUpcaseUnicodeStringToCountedOemString", 
func_RtlUpcaseUnicodeStringToCountedOemString },
     { "StackOverflow",                  func_StackOverflow },
     { "TimerResolution",                func_TimerResolution },

Reply via email to