Commit d336f1fe authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

ntdll/tests: Add tests for NtQueryLicenseKey.

parent 72a41c50
......@@ -130,6 +130,7 @@ static NTSTATUS (WINAPI * pNtCreateKey)( PHANDLE retkey, ACCESS_MASK access, con
ULONG TitleIndex, const UNICODE_STRING *class, ULONG options,
PULONG dispos );
static NTSTATUS (WINAPI * pNtQueryKey)(HANDLE,KEY_INFORMATION_CLASS,PVOID,ULONG,PULONG);
static NTSTATUS (WINAPI * pNtQueryLicenseValue)(const UNICODE_STRING *,ULONG *,PVOID,ULONG,ULONG *);
static NTSTATUS (WINAPI * pNtQueryValueKey)(HANDLE,const UNICODE_STRING *,KEY_VALUE_INFORMATION_CLASS,void *,DWORD,DWORD *);
static NTSTATUS (WINAPI * pNtSetValueKey)(HANDLE, const PUNICODE_STRING, ULONG,
ULONG, const void*, ULONG );
......@@ -191,6 +192,10 @@ static BOOL InitFunctionPtrs(void)
NTDLL_GET_PROC(RtlZeroMemory)
NTDLL_GET_PROC(RtlpNtQueryValueKey)
NTDLL_GET_PROC(RtlOpenCurrentUser)
/* optional functions */
pNtQueryLicenseValue = (void *)GetProcAddress(hntdll, "NtQueryLicenseValue");
return TRUE;
}
#undef NTDLL_GET_PROC
......@@ -645,6 +650,180 @@ static void test_NtDeleteKey(void)
ok(status == STATUS_SUCCESS, "NtDeleteKey Failed: 0x%08x\n", status);
}
static void test_NtQueryLicenseKey(void)
{
static const WCHAR emptyW[] = {'E','M','P','T','Y',0};
UNICODE_STRING name;
WORD buffer[32];
NTSTATUS status;
ULONG type, len;
DWORD value;
if (!pNtQueryLicenseValue)
{
skip("NtQueryLicenseValue not found, skipping tests\n");
return;
}
type = 0xdead;
len = 0xbeef;
memset(&name, 0, sizeof(name));
status = pNtQueryLicenseValue(&name, &type, buffer, sizeof(buffer), &len);
ok(status == STATUS_INVALID_PARAMETER, "NtQueryLicenseValue returned %08x, expected STATUS_INVALID_PARAMETER\n", status);
ok(type == 0xdead, "expected unmodified value for type, got %u\n", type);
ok(len == 0xbeef, "expected unmodified value for len, got %u\n", len);
/* test with empty key */
pRtlCreateUnicodeStringFromAsciiz(&name, "");
type = 0xdead;
len = 0xbeef;
status = pNtQueryLicenseValue(NULL, &type, buffer, sizeof(buffer), &len);
ok(status == STATUS_INVALID_PARAMETER, "NtQueryLicenseValue returned %08x, expected STATUS_INVALID_PARAMETER\n", status);
ok(type == 0xdead, "expected unmodified value for type, got %u\n", type);
ok(len == 0xbeef, "expected unmodified value for len, got %u\n", len);
type = 0xdead;
status = pNtQueryLicenseValue(&name, &type, buffer, sizeof(buffer), NULL);
ok(status == STATUS_INVALID_PARAMETER, "NtQueryLicenseValue returned %08x, expected STATUS_INVALID_PARAMETER\n", status);
ok(type == 0xdead, "expected unmodified value for type, got %u\n", type);
len = 0xbeef;
status = pNtQueryLicenseValue(&name, NULL, buffer, sizeof(buffer), &len);
ok(status == STATUS_INVALID_PARAMETER, "NtQueryLicenseValue returned %08x, expected STATUS_INVALID_PARAMETER\n", status);
ok(len == 0xbeef, "expected unmodified value for len, got %u\n", len);
type = 0xdead;
len = 0xbeef;
status = pNtQueryLicenseValue(&name, &type, buffer, sizeof(buffer), &len);
ok(status == STATUS_INVALID_PARAMETER, "NtQueryLicenseValue returned %08x, expected STATUS_INVALID_PARAMETER\n", status);
ok(type == 0xdead, "expected unmodified value for type, got %u\n", type);
ok(len == 0xbeef, "expected unmodified value for len, got %u\n", len);
pRtlFreeUnicodeString(&name);
/* test with nonexistent licence key */
pRtlCreateUnicodeStringFromAsciiz(&name, "Nonexistent-License-Value");
type = 0xdead;
len = 0xbeef;
status = pNtQueryLicenseValue(NULL, &type, buffer, sizeof(buffer), &len);
ok(status == STATUS_INVALID_PARAMETER, "NtQueryLicenseValue returned %08x, expected STATUS_INVALID_PARAMETER\n", status);
ok(type == 0xdead, "expected unmodified value for type, got %u\n", type);
ok(len == 0xbeef, "expected unmodified value for len, got %u\n", len);
type = 0xdead;
status = pNtQueryLicenseValue(&name, &type, buffer, sizeof(buffer), NULL);
ok(status == STATUS_INVALID_PARAMETER, "NtQueryLicenseValue returned %08x, expected STATUS_INVALID_PARAMETER\n", status);
ok(type == 0xdead, "expected unmodified value for type, got %u\n", type);
len = 0xbeef;
status = pNtQueryLicenseValue(&name, NULL, buffer, sizeof(buffer), &len);
ok(status == STATUS_OBJECT_NAME_NOT_FOUND, "NtQueryLicenseValue returned %08x, expected STATUS_OBJECT_NAME_NOT_FOUND\n", status);
ok(len == 0xbeef, "expected unmodified value for len, got %u\n", len);
type = 0xdead;
len = 0xbeef;
status = pNtQueryLicenseValue(&name, &type, buffer, sizeof(buffer), &len);
ok(status == STATUS_OBJECT_NAME_NOT_FOUND, "NtQueryLicenseValue unexpected suceeded\n");
ok(type == 0xdead, "expected unmodified value for type, got %u\n", type);
ok(len == 0xbeef, "expected unmodified value for len, got %u\n", len);
pRtlFreeUnicodeString(&name);
/* test with REG_SZ license key */
pRtlCreateUnicodeStringFromAsciiz(&name, "Kernel-MUI-Language-Allowed");
type = 0xdead;
len = 0xbeef;
status = pNtQueryLicenseValue(NULL, &type, buffer, sizeof(buffer), &len);
ok(status == STATUS_INVALID_PARAMETER, "NtQueryLicenseValue returned %08x, expected STATUS_INVALID_PARAMETER\n", status);
ok(type == 0xdead, "expected unmodified value for type, got %u\n", type);
ok(len == 0xbeef, "expected unmodified value for len, got %u\n", len);
type = 0xdead;
status = pNtQueryLicenseValue(&name, &type, buffer, sizeof(buffer), NULL);
ok(status == STATUS_INVALID_PARAMETER, "NtQueryLicenseValue returned %08x, expected STATUS_INVALID_PARAMETER\n", status);
ok(type == 0xdead, "expected unmodified value for type, got %u\n", type);
type = 0xdead;
len = 0;
status = pNtQueryLicenseValue(&name, &type, buffer, 0, &len);
ok(status == STATUS_BUFFER_TOO_SMALL, "NtQueryLicenseValue returned %08x, expected STATUS_BUFFER_TOO_SMALL\n", status);
ok(type == REG_SZ, "expected type = REG_SZ, got %u\n", type);
ok(len == sizeof(emptyW), "expected len = %u, got %u\n", (DWORD)sizeof(emptyW), len);
len = 0;
status = pNtQueryLicenseValue(&name, NULL, buffer, 0, &len);
ok(status == STATUS_BUFFER_TOO_SMALL, "NtQueryLicenseValue returned %08x, expected STATUS_BUFFER_TOO_SMALL\n", status);
ok(len == sizeof(emptyW), "expected len = %u, got %u\n", (DWORD)sizeof(emptyW), len);
type = 0xdead;
len = 0;
memset(buffer, 0x11, sizeof(buffer));
status = pNtQueryLicenseValue(&name, &type, buffer, sizeof(buffer), &len);
ok(status == STATUS_SUCCESS, "NtQueryLicenseValue returned %08x, expected STATUS_SUCCESS\n", status);
ok(type == REG_SZ, "expected type = REG_SZ, got %u\n", type);
ok(len == sizeof(emptyW), "expected len = %u, got %u\n", (DWORD)sizeof(emptyW), len);
ok(!memcmp(buffer, emptyW, sizeof(emptyW)), "unexpected buffer content\n");
type = 0xdead;
len = 0;
memset(buffer, 0x11, sizeof(buffer));
status = pNtQueryLicenseValue(&name, &type, buffer, 2, &len);
ok(status == STATUS_BUFFER_TOO_SMALL, "NtQueryLicenseValue returned %08x, expected STATUS_BUFFER_TOO_SMALL\n", status);
ok(type == REG_SZ, "expected type REG_SZ, got %u\n", type);
ok(len == sizeof(emptyW), "expected len = %u, got %u\n", (DWORD)sizeof(emptyW), len);
ok(buffer[0] == 0x1111, "expected buffer[0] = 0x1111, got %u\n", buffer[0]);
pRtlFreeUnicodeString(&name);
/* test with REG_DWORD license key */
pRtlCreateUnicodeStringFromAsciiz(&name, "Kernel-MUI-Number-Allowed");
type = 0xdead;
len = 0xbeef;
status = pNtQueryLicenseValue(NULL, &type, &value, sizeof(value), &len);
ok(status == STATUS_INVALID_PARAMETER, "NtQueryLicenseValue returned %08x, expected STATUS_INVALID_PARAMETER\n", status);
ok(type == 0xdead, "expected unmodified value for type, got %u\n", type);
ok(len == 0xbeef, "expected unmodified value for len, got %u\n", len);
type = 0xdead;
status = pNtQueryLicenseValue(&name, &type, &value, sizeof(value), NULL);
ok(status == STATUS_INVALID_PARAMETER, "NtQueryLicenseValue returned %08x, expected STATUS_INVALID_PARAMETER\n", status);
ok(type == 0xdead, "expected unmodified value for type, got %u\n", type);
type = 0xdead;
len = 0;
status = pNtQueryLicenseValue(&name, &type, &value, 0, &len);
ok(status == STATUS_BUFFER_TOO_SMALL, "NtQueryLicenseValue returned %08x, expected STATUS_BUFFER_TOO_SMALL\n", status);
ok(type == REG_DWORD, "expected type = REG_DWORD, got %u\n", type);
ok(len == sizeof(value), "expected len = %u, got %u\n", (DWORD)sizeof(value), len);
len = 0;
status = pNtQueryLicenseValue(&name, NULL, &value, 0, &len);
ok(status == STATUS_BUFFER_TOO_SMALL, "NtQueryLicenseValue returned %08x, expected STATUS_BUFFER_TOO_SMALL\n", status);
ok(len == sizeof(value), "expected len = %u, got %u\n", (DWORD)sizeof(value), len);
type = 0xdead;
len = 0;
value = 0xdeadbeef;
status = pNtQueryLicenseValue(&name, &type, &value, sizeof(value), &len);
ok(status == STATUS_SUCCESS, "NtQueryLicenseValue returned %08x, expected STATUS_SUCCESS\n", status);
ok(type == REG_DWORD, "expected type = REG_DWORD, got %u\n", type);
ok(len == sizeof(value), "expected len = %u, got %u\n", (DWORD)sizeof(value), len);
ok(value != 0xdeadbeef, "expected value != 0xdeadbeef\n");
type = 0xdead;
len = 0;
status = pNtQueryLicenseValue(&name, &type, &value, 2, &len);
ok(status == STATUS_BUFFER_TOO_SMALL, "NtQueryLicenseValue returned %08x, expected STATUS_BUFFER_TOO_SMALL\n", status);
ok(type == REG_DWORD, "expected type REG_DWORD, got %u\n", type);
ok(len == sizeof(value), "expected len = %u, got %u\n", (DWORD)sizeof(value), len);
pRtlFreeUnicodeString(&name);
}
static void test_RtlpNtQueryValueKey(void)
{
NTSTATUS status;
......@@ -1346,6 +1525,7 @@ START_TEST(reg)
test_RtlpNtQueryValueKey();
test_NtFlushKey();
test_NtQueryKey();
test_NtQueryLicenseKey();
test_NtQueryValueKey();
test_long_value_name();
test_NtDeleteKey();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment