Author: hbelusca
Date: Sun Oct  7 12:31:13 2012
New Revision: 57512

URL: http://svn.reactos.org/svn/reactos?rev=57512&view=rev
Log:
[APITEST:NTDLL]
Add a test for the NtQuerySystemEnvironmentValue API.
Tested successfully under Win2k3 SP1 and Win7.

Added:
    trunk/rostests/apitests/ntdll/NtQuerySystemEnvironmentValue.c   (with props)
Modified:
    trunk/rostests/apitests/ntdll/CMakeLists.txt
    trunk/rostests/apitests/ntdll/testlist.c

Modified: trunk/rostests/apitests/ntdll/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/CMakeLists.txt?rev=57512&r1=57511&r2=57512&view=diff
==============================================================================
--- trunk/rostests/apitests/ntdll/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/rostests/apitests/ntdll/CMakeLists.txt [iso-8859-1] Sun Oct  7 
12:31:13 2012
@@ -2,6 +2,7 @@
 list(APPEND SOURCE
     NtAllocateVirtualMemory.c
     NtFreeVirtualMemory.c
+    NtQuerySystemEnvironmentValue.c
     RtlBitmap.c
     RtlDetermineDosPathNameType.c
     RtlDoesFileExists.c

Added: trunk/rostests/apitests/ntdll/NtQuerySystemEnvironmentValue.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/NtQuerySystemEnvironmentValue.c?rev=57512&view=auto
==============================================================================
--- trunk/rostests/apitests/ntdll/NtQuerySystemEnvironmentValue.c (added)
+++ trunk/rostests/apitests/ntdll/NtQuerySystemEnvironmentValue.c [iso-8859-1] 
Sun Oct  7 12:31:13 2012
@@ -1,0 +1,119 @@
+/*
+ * PROJECT:         ReactOS API Tests
+ * LICENSE:         GPLv2+ - See COPYING in the top level directory
+ * PURPOSE:         Test for the NtQuerySystemEnvironmentValue.
+ * PROGRAMMER:      Hermès BÉLUSCA - MAÏTO <hermes.belu...@sfr.fr>
+ */
+
+#define WIN32_NO_STATUS
+#include <stdio.h>
+#include <wine/test.h>
+#include <ndk/ntndk.h>
+
+// Arbitrary-defined constants
+#define MIN_BUFFER_LENGTH 4L
+#define MAX_BUFFER_LENGTH 2048L
+
+#define COUNT_OF(x) (sizeof((x))/sizeof((x)[0]))
+
+static struct TEST_CASES
+{
+    NTSTATUS        Result;
+    UNICODE_STRING  VariableName;
+    BOOLEAN         AdjustPrivileges;
+    ULONG           ValueBufferLength;
+    ULONG           MinimalExpectedReturnedLength;
+    ULONG           MaximalExpectedReturnedLength;
+} TestCases[] =
+{
+    //
+    // Non-existent variable name.
+    //
+    {STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"NonExistent"),   FALSE, 
0, 0, 0},
+    {STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"NonExistent"),   FALSE, 
MIN_BUFFER_LENGTH, 0, 0},
+    {STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"NonExistent"),   FALSE, 
MAX_BUFFER_LENGTH, 0, 0},
+    {STATUS_UNSUCCESSFUL      , RTL_CONSTANT_STRING(L"NonExistent"),   TRUE , 
0, 0, 0},
+    {STATUS_UNSUCCESSFUL      , RTL_CONSTANT_STRING(L"NonExistent"),   TRUE , 
MIN_BUFFER_LENGTH, 0, 0},
+    {STATUS_UNSUCCESSFUL      , RTL_CONSTANT_STRING(L"NonExistent"),   TRUE , 
MAX_BUFFER_LENGTH, 0, 0},
+
+    //
+    // Existent variable name.
+    //
+    {STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"LastKnownGood"), FALSE, 
0, 0, 0},
+    {STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"LastKnownGood"), FALSE, 
MIN_BUFFER_LENGTH, 0, 0},
+    {STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"LastKnownGood"), FALSE, 
MAX_BUFFER_LENGTH, 0, 0},
+    {STATUS_BUFFER_OVERFLOW   , RTL_CONSTANT_STRING(L"LastKnownGood"), TRUE , 
0                , MIN_BUFFER_LENGTH, MAX_BUFFER_LENGTH},
+    {STATUS_BUFFER_OVERFLOW   , RTL_CONSTANT_STRING(L"LastKnownGood"), TRUE , 
MIN_BUFFER_LENGTH, MIN_BUFFER_LENGTH, MAX_BUFFER_LENGTH},
+    {STATUS_SUCCESS           , RTL_CONSTANT_STRING(L"LastKnownGood"), TRUE , 
MAX_BUFFER_LENGTH, MIN_BUFFER_LENGTH, MAX_BUFFER_LENGTH},
+};
+
+static NTSTATUS Test_API(IN  BOOLEAN AdjustPrivileges,
+                         IN  PUNICODE_STRING VariableName,
+                         OUT PWSTR ValueBuffer,
+                         IN  ULONG ValueBufferLength,
+                         IN  OUT PULONG ReturnLength OPTIONAL)
+{
+    NTSTATUS Status;
+    BOOLEAN  WasEnabled;
+
+    //
+    // Adjust the privileges if asked for (we need to
+    // have already administrator privileges to do so).
+    //
+    if (AdjustPrivileges)
+    {
+        Status = RtlAdjustPrivilege(SE_SYSTEM_ENVIRONMENT_PRIVILEGE,
+                                    TRUE,
+                                    FALSE,
+                                    &WasEnabled);
+        ok(NT_SUCCESS(Status), "RtlAdjustPrivilege failed : 0x%08lx\n", 
Status);
+    }
+
+    //
+    // Get the system environment value and set the privilege back.
+    //
+    Status = NtQuerySystemEnvironmentValue(VariableName,
+                                           ValueBuffer,
+                                           ValueBufferLength,
+                                           ReturnLength);
+
+    if (AdjustPrivileges)
+    {
+        RtlAdjustPrivilege(SE_SYSTEM_ENVIRONMENT_PRIVILEGE,
+                           WasEnabled,
+                           FALSE,
+                           &WasEnabled);
+    }
+
+    return Status;
+}
+
+START_TEST(NtQuerySystemEnvironmentValue)
+{
+    NTSTATUS Status;
+    WCHAR ValueBuffer[MAX_BUFFER_LENGTH / sizeof(WCHAR)];
+    ULONG ReturnedLength = 0;
+    ULONG i;
+
+    for (i = 0 ; i < COUNT_OF(TestCases) ; ++i)
+    {
+        Status = Test_API(TestCases[i].AdjustPrivileges,
+                          &TestCases[i].VariableName,
+                          ValueBuffer,
+                          TestCases[i].ValueBufferLength,
+                          &ReturnedLength);
+
+        ok(Status == TestCases[i].Result,
+           "NtQuerySystemEnvironmentValue failed, returned 0x%08lx, expected 
0x%08lx\n",
+           Status,
+           TestCases[i].Result);
+
+        ok( ((TestCases[i].MinimalExpectedReturnedLength <= ReturnedLength) && 
(ReturnedLength <= TestCases[i].MaximalExpectedReturnedLength)),
+            "Returned length %lu, expected between %lu and %lu\n",
+            ReturnedLength,
+            TestCases[i].MinimalExpectedReturnedLength,
+            TestCases[i].MaximalExpectedReturnedLength);
+    }
+}
+
+/* EOF */

Propchange: trunk/rostests/apitests/ntdll/NtQuerySystemEnvironmentValue.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/rostests/apitests/ntdll/testlist.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/testlist.c?rev=57512&r1=57511&r2=57512&view=diff
==============================================================================
--- trunk/rostests/apitests/ntdll/testlist.c [iso-8859-1] (original)
+++ trunk/rostests/apitests/ntdll/testlist.c [iso-8859-1] Sun Oct  7 12:31:13 
2012
@@ -7,6 +7,7 @@
 
 extern void func_NtAllocateVirtualMemory(void);
 extern void func_NtFreeVirtualMemory(void);
+extern void func_NtQuerySystemEnvironmentValue(void);
 extern void func_NtSystemInformation(void);
 extern void func_RtlBitmap(void);
 extern void func_RtlDetermineDosPathNameType(void);
@@ -25,6 +26,7 @@
 {
     { "NtAllocateVirtualMemory",        func_NtAllocateVirtualMemory },
     { "NtFreeVirtualMemory",            func_NtFreeVirtualMemory },
+    { "NtQuerySystemEnvironmentValue",  func_NtQuerySystemEnvironmentValue },
     { "NtSystemInformation",            func_NtSystemInformation },
     { "RtlBitmapApi",                   func_RtlBitmap },
     { "RtlDetermineDosPathNameType",    func_RtlDetermineDosPathNameType },


Reply via email to