ReactOS  0.4.15-dev-3181-g4acf100
NtQueryValueKey.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API Tests
3  * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE: Test for NtQueryValueKey
5  * COPYRIGHT: Copyright 2020 Thomas Faber (thomas.faber@reactos.org)
6  */
7 
8 #include "precomp.h"
9 #include <winreg.h>
10 
12 {
15  UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
20  ULONG InfoLength;
22  const WCHAR *StringData;
23  ULONG StringLength;
24 
26  &KeyName,
28  NULL,
29  NULL);
33  if (!NT_SUCCESS(Status))
34  {
35  skip("Test key unavailable\n");
36  return;
37  }
38 
39  /* Specify zero-size buffer, get the length */
40  ResultLength = 0x55555555;
42  &ValueName,
44  NULL,
45  0,
46  &ResultLength);
49  "Invalid result length %lu\n", ResultLength);
51  {
52  skip("Result length %lu too small\n", ResultLength);
53  goto Exit;
54  }
55  InfoLength = ResultLength;
56  Info = RtlAllocateHeap(RtlGetProcessHeap(),
57  0,
58  InfoLength + 4);
59  if (Info == NULL)
60  {
61  skip("Could not alloc %lu bytes\n", InfoLength);
62  goto Exit;
63  }
64 
65  /* Successful call */
67  &ValueName,
69  Info,
70  InfoLength,
71  &ResultLength);
73  ok_int(ResultLength, InfoLength);
74 
75  ok_int(Info->Type, REG_SZ);
76  StringLength = InfoLength - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, Data);
77  ok_int(Info->DataLength, StringLength);
78 
79  StringData = (PWCHAR)Info->Data;
80  ok(Info->DataLength >= 5 * sizeof(WCHAR), "DataLength %lu is too small for path\n", Info->DataLength);
81  if (Info->DataLength >= 5 * sizeof(WCHAR))
82  {
83  trace("SystemRoot: %.*ls\n", (int)(Info->DataLength / sizeof(WCHAR) - 1), StringData);
84  ok(StringData[0] >= 'A' && StringData[0] <= 'Z', "Data[0] = %x\n", StringData[0]);
85  ok(StringData[1] == ':', "Data[1] = %x\n", StringData[1]);
86  ok(StringData[2] == '\\', "Data[2] = %x\n", StringData[2]);
87  ok(iswalnum(StringData[3]), "Data[3] = %x\n", StringData[3]);
88  ok(StringData[Info->DataLength / sizeof(WCHAR) - 1] == UNICODE_NULL,
89  "Data[%lu] = %x\n", Info->DataLength / sizeof(WCHAR) - 1, StringData[Info->DataLength / sizeof(WCHAR) - 1]);
90  }
91 
92  /* If the buffer isn't 64 bit aligned, the data won't be, either */
93  InfoUnaligned = (PVOID)((PUCHAR)Info + 4);
95  &ValueName,
97  InfoUnaligned,
98  InfoLength,
99  &ResultLength);
101  ok_int(ResultLength, InfoLength);
102  ok_int(InfoUnaligned->Type, REG_SZ);
103  StringData = (PWCHAR)InfoUnaligned->Data;
104  ok(InfoUnaligned->DataLength >= 2 * sizeof(WCHAR), "DataLength %lu is too small for path\n", InfoUnaligned->DataLength);
105  if (InfoUnaligned->DataLength >= 2 * sizeof(WCHAR))
106  {
107  ok(StringData[1] == ':', "Data[1] = %x\n", StringData[1]);
108  }
109 
110  RtlFreeHeap(RtlGetProcessHeap(), 0, Info);
111 
112 Exit:
115 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
uint16_t * PWCHAR
Definition: typedefs.h:56
#define ok_hex(expression, result)
Definition: atltest.h:94
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:683
#define UNICODE_NULL
#define iswalnum(_c)
Definition: ctype.h:671
#define ok_int(expression, result)
Definition: atltest.h:134
void * PVOID
Definition: retypes.h:9
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static void Exit(void)
Definition: sock.c:1331
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3398
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
static const WCHAR L[]
Definition: oid.c:1250
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define ok(value,...)
Definition: atltest.h:57
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
START_TEST(NtQueryValueKey)
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define REG_SZ
Definition: layer.c:22