ReactOS 0.4.15-dev-7842-g558ab78
NtQuerySystemEnvironmentValue.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for the NtQuerySystemEnvironmentValue.
5 * PROGRAMMER: Hermès BÉLUSCA - MAÏTO <hermes.belusca@sfr.fr>
6 */
7
8#include "precomp.h"
9
10// Arbitrary-defined constants
11#define MIN_BUFFER_LENGTH 4L
12#define MAX_BUFFER_LENGTH 2048L
13
14#define COUNT_OF(x) (sizeof((x))/sizeof((x)[0]))
15
16typedef struct _TEST_CASE
17{
25
27{
28 //
29 // Non-existent variable name.
30 //
31 {STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"NonExistent"), FALSE, 0, 0, 0},
34 {STATUS_UNSUCCESSFUL , RTL_CONSTANT_STRING(L"NonExistent"), TRUE , 0, 0, 0},
37
38 //
39 // Existent variable name.
40 //
41 {STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"LastKnownGood"), FALSE, 0, 0, 0},
47};
48
49static void Test_API(IN ULONG TestNumber,
51{
53 BOOLEAN WasEnabled = FALSE;
54 WCHAR ValueBuffer[MAX_BUFFER_LENGTH / sizeof(WCHAR)];
56
57 //
58 // Adjust the privileges if asked for (we need to
59 // have already administrator privileges to do so).
60 //
61 if (TestCase->AdjustPrivileges)
62 {
64 TRUE,
65 FALSE,
66 &WasEnabled);
67 ok(NT_SUCCESS(Status), "RtlAdjustPrivilege(%lu) failed : 0x%08lx\n", TestNumber, Status);
68 }
69
70 //
71 // Get the system environment value and set the privilege back.
72 //
74 ValueBuffer,
75 TestCase->ValueBufferLength,
77
78 if (TestCase->AdjustPrivileges)
79 {
81 WasEnabled,
82 FALSE,
83 &WasEnabled);
84 }
85
86 //
87 // Now check the results.
88 //
89 ok(Status == TestCase->Result,
90 "NtQuerySystemEnvironmentValue(%lu) failed : returned 0x%08lx, expected 0x%08lx\n",
91 TestNumber,
92 Status,
93 TestCase->Result);
94
95 ok( ((TestCase->MinimalExpectedReturnedLength <= ReturnedLength) && (ReturnedLength <= TestCase->MaximalExpectedReturnedLength)),
96 "NtQuerySystemEnvironmentValue(%lu) failed : returned length %lu, expected between %lu and %lu\n",
97 TestNumber,
99 TestCase->MinimalExpectedReturnedLength,
100 TestCase->MaximalExpectedReturnedLength);
101}
102
104{
105 ULONG i;
106
107 for (i = 0 ; i < COUNT_OF(TestCases) ; ++i)
108 {
109 Test_API(i, &TestCases[i]);
110 }
111}
112
113/* EOF */
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
struct _TEST_CASE TEST_CASE
static TEST_CASE TestCases[]
#define MIN_BUFFER_LENGTH
static void Test_API(IN ULONG TestNumber, IN PTEST_CASE TestCase)
#define MAX_BUFFER_LENGTH
#define COUNT_OF(x)
struct _TEST_CASE * PTEST_CASE
unsigned char BOOLEAN
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:188
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define SE_SYSTEM_ENVIRONMENT_PRIVILEGE
Definition: security.c:676
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
NTSTATUS NTAPI NtQuerySystemEnvironmentValue(IN PUNICODE_STRING VariableName, OUT PWSTR ValueBuffer, IN ULONG ValueBufferLength, IN OUT PULONG ReturnLength OPTIONAL)
Definition: sysinfo.c:385
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
UNICODE_STRING VariableName
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
__wchar_t WCHAR
Definition: xmlstorage.h:180