[APITEST:NTDLL]

Improve the code.

svn path=/trunk/; revision=57513
This commit is contained in:
Hermès Bélusca-Maïto 2012-10-07 12:46:44 +00:00
parent f527bc83ef
commit 02affbb318

View file

@ -16,7 +16,7 @@
#define COUNT_OF(x) (sizeof((x))/sizeof((x)[0])) #define COUNT_OF(x) (sizeof((x))/sizeof((x)[0]))
static struct TEST_CASES typedef struct _TEST_CASE
{ {
NTSTATUS Result; NTSTATUS Result;
UNICODE_STRING VariableName; UNICODE_STRING VariableName;
@ -24,7 +24,9 @@ static struct TEST_CASES
ULONG ValueBufferLength; ULONG ValueBufferLength;
ULONG MinimalExpectedReturnedLength; ULONG MinimalExpectedReturnedLength;
ULONG MaximalExpectedReturnedLength; ULONG MaximalExpectedReturnedLength;
} TestCases[] = } TEST_CASE, *PTEST_CASE;
static TEST_CASE TestCases[] =
{ {
// //
// Non-existent variable name. // Non-existent variable name.
@ -47,20 +49,18 @@ static struct TEST_CASES
{STATUS_SUCCESS , RTL_CONSTANT_STRING(L"LastKnownGood"), TRUE , MAX_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, static void Test_API(IN PTEST_CASE TestCase)
IN PUNICODE_STRING VariableName,
OUT PWSTR ValueBuffer,
IN ULONG ValueBufferLength,
IN OUT PULONG ReturnLength OPTIONAL)
{ {
NTSTATUS Status; NTSTATUS Status = STATUS_SUCCESS;
BOOLEAN WasEnabled; BOOLEAN WasEnabled = FALSE;
WCHAR ValueBuffer[MAX_BUFFER_LENGTH / sizeof(WCHAR)];
ULONG ReturnedLength = 0;
// //
// Adjust the privileges if asked for (we need to // Adjust the privileges if asked for (we need to
// have already administrator privileges to do so). // have already administrator privileges to do so).
// //
if (AdjustPrivileges) if (TestCase->AdjustPrivileges)
{ {
Status = RtlAdjustPrivilege(SE_SYSTEM_ENVIRONMENT_PRIVILEGE, Status = RtlAdjustPrivilege(SE_SYSTEM_ENVIRONMENT_PRIVILEGE,
TRUE, TRUE,
@ -72,12 +72,12 @@ static NTSTATUS Test_API(IN BOOLEAN AdjustPrivileges,
// //
// Get the system environment value and set the privilege back. // Get the system environment value and set the privilege back.
// //
Status = NtQuerySystemEnvironmentValue(VariableName, Status = NtQuerySystemEnvironmentValue(&TestCase->VariableName,
ValueBuffer, ValueBuffer,
ValueBufferLength, TestCase->ValueBufferLength,
ReturnLength); &ReturnedLength);
if (AdjustPrivileges) if (TestCase->AdjustPrivileges)
{ {
RtlAdjustPrivilege(SE_SYSTEM_ENVIRONMENT_PRIVILEGE, RtlAdjustPrivilege(SE_SYSTEM_ENVIRONMENT_PRIVILEGE,
WasEnabled, WasEnabled,
@ -85,34 +85,28 @@ static NTSTATUS Test_API(IN BOOLEAN AdjustPrivileges,
&WasEnabled); &WasEnabled);
} }
return Status; //
// Now check the results.
//
ok(Status == TestCase->Result,
"NtQuerySystemEnvironmentValue failed, returned 0x%08lx, expected 0x%08lx\n",
Status,
TestCase->Result);
ok( ((TestCase->MinimalExpectedReturnedLength <= ReturnedLength) && (ReturnedLength <= TestCase->MaximalExpectedReturnedLength)),
"Returned length %lu, expected between %lu and %lu\n",
ReturnedLength,
TestCase->MinimalExpectedReturnedLength,
TestCase->MaximalExpectedReturnedLength);
} }
START_TEST(NtQuerySystemEnvironmentValue) START_TEST(NtQuerySystemEnvironmentValue)
{ {
NTSTATUS Status;
WCHAR ValueBuffer[MAX_BUFFER_LENGTH / sizeof(WCHAR)];
ULONG ReturnedLength = 0;
ULONG i; ULONG i;
for (i = 0 ; i < COUNT_OF(TestCases) ; ++i) for (i = 0 ; i < COUNT_OF(TestCases) ; ++i)
{ {
Status = Test_API(TestCases[i].AdjustPrivileges, Test_API(&TestCases[i]);
&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);
} }
} }