ReactOS 0.4.15-dev-5829-g6b6a045
RtlGetNtProductType.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Tests for the RtlGetNtProductType API
5 * COPYRIGHT: Copyright 2020 George Bișoc <george.bisoc@reactos.org>
6 */
7
8#include "precomp.h"
9#include <winbase.h>
10#include <winreg.h>
11
12static
14ReturnNtProduct(PDWORD ProductNtType)
15{
17 HKEY Key;
18 WCHAR Data[20];
19 DWORD Size = sizeof(Data);
20
22 L"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
23 0,
25 &Key);
26 if (Result != ERROR_SUCCESS)
27 {
28 *ProductNtType = 0;
29 return FALSE;
30 }
31
33 L"ProductType",
34 NULL,
35 NULL,
36 (PBYTE)&Data,
37 &Size);
38 if (Result != ERROR_SUCCESS)
39 {
41 *ProductNtType = 0;
42 return FALSE;
43 }
44
45 if (wcscmp(Data, L"WinNT") == 0)
46 {
47 *ProductNtType = NtProductWinNt;
49 return TRUE;
50 }
51
52 if (wcscmp(Data, L"LanmanNT") == 0)
53 {
54 *ProductNtType = NtProductLanManNt;
56 return TRUE;
57 }
58
59 if (wcscmp(Data, L"ServerNT") == 0)
60 {
61 *ProductNtType = NtProductServer;
63 return TRUE;
64 }
65
66 *ProductNtType = 0;
68 return FALSE;
69}
70
71static
74{
75 PWSTR ProductTypeString;
77 HKEY Key;
79
80 if (NtProductType == NtProductWinNt)
81 {
82 ProductTypeString = L"WinNT";
83 }
84 else if (NtProductType == NtProductLanManNt)
85 {
86 ProductTypeString = L"LanmanNT";
87 }
88 else if (NtProductType == NtProductServer)
89 {
90 ProductTypeString = L"ServerNT";
91 }
92 else
93 {
94 ok(FALSE, "Passed invalid product type to CHangeNtProduct: %lu", NtProductType);
95 }
96
98 L"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
99 0,
101 &Key);
102 if (Result != ERROR_SUCCESS)
103 {
104 ok(FALSE, "RegOpenKeyExW failed with 0x%lx\n", Result);
105 return FALSE;
106 }
107
108 dwSize = ((DWORD)wcslen(ProductTypeString) + 1) * sizeof(WCHAR);
110 L"ProductType",
111 0,
112 REG_SZ,
113 (PBYTE)ProductTypeString,
114 dwSize);
115 if (Result != ERROR_SUCCESS)
116 {
117 ok(FALSE, "RegSetValueExW failed with 0x%lx\n", Result);
119 return FALSE;
120 }
121
123 return TRUE;
124}
125
127{
128 BOOLEAN Ret;
129 DWORD ProductNtType;
130 NT_PRODUCT_TYPE ProductType = NtProductWinNt, ProductType2;
131
132 /*
133 * Wrap the call in SEH. This ensures the testcase won't crash but also
134 * it proves to us that RtlGetNtProductType() throws an exception if a NULL
135 * argument is being passed to caller as output.
136 */
137 StartSeh()
140
141 /* Query the product type normally from the Registry */
142 Ret = ReturnNtProduct(&ProductNtType);
143 if (!Ret)
144 {
145 ok(Ret, "Failed to query the product type value!\n");
146 }
147
148 /* Now, get the product type from the NTDLL system call */
149 Ret = RtlGetNtProductType(&ProductType);
150 ok(Ret == TRUE, "Expected a valid product type value (and TRUE as returned success code) but got %u as status.\n", Ret);
151 ok(ProductNtType == ProductType, "Expected the product type value to be the same but got %lu (original value pointed by RtlGetNtProductType() is %d).\n", ProductNtType, ProductType);
152
153 /* Change product type in the registry */
155 ok_char(RtlGetNtProductType(&ProductType2), TRUE);
156 ok_long(ProductType2, ProductType);
157
159 ok_char(RtlGetNtProductType(&ProductType2), TRUE);
160 ok_long(ProductType2, ProductType);
161
163 ok_char(RtlGetNtProductType(&ProductType2), TRUE);
164 ok_long(ProductType2, ProductType);
165
166 ok_char(ChangeNtProductType(ProductType), TRUE);
167}
unsigned char BOOLEAN
static BOOLEAN ChangeNtProductType(DWORD NtProductType)
static BOOLEAN ReturnNtProduct(PDWORD ProductNtType)
#define StartSeh()
Definition: _sntprintf.h:16
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
#define ok_long(expression, result)
Definition: atltest.h:133
#define ok(value,...)
Definition: atltest.h:57
#define ok_char(expression, result)
Definition: atltest.h:122
#define START_TEST(x)
Definition: atltest.h:75
#define RegCloseKey(hKey)
Definition: registry.h:47
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOLEAN NTAPI RtlGetNtProductType(_Out_ PNT_PRODUCT_TYPE ProductType)
Definition: version.c:96
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3356
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4900
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4121
enum _NT_PRODUCT_TYPE NT_PRODUCT_TYPE
@ NtProductWinNt
Definition: shellpath.c:64
@ NtProductLanManNt
Definition: shellpath.c:65
@ NtProductServer
Definition: shellpath.c:66
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define DWORD
Definition: nt_native.h:44
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
DWORD * PDWORD
Definition: pedump.c:68
long LONG
Definition: pedump.c:60
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
uint16_t * PWSTR
Definition: typedefs.h:56
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
__wchar_t WCHAR
Definition: xmlstorage.h:180