ReactOS  0.4.15-dev-3291-gea4c1a0
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 
12 static
13 BOOLEAN
14 ReturnNtProduct(PDWORD ProductNtType)
15 {
16  LONG Result;
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 
72 {
73  BOOLEAN Ret;
74  DWORD ProductNtType;
75  NT_PRODUCT_TYPE ProductType = NtProductWinNt;
76 
77  /*
78  * Wrap the call in SEH. This ensures the testcase won't crash but also
79  * it proves to us that RtlGetNtProductType() throws an exception if a NULL
80  * argument is being passed to caller as output.
81  */
82  StartSeh()
85 
86  /* Query the product type normally from the Registry */
87  Ret = ReturnNtProduct(&ProductNtType);
88  if (!Ret)
89  {
90  ok(Ret, "Failed to query the product type value!\n");
91  }
92 
93  /* Now, get the product type from the NTDLL system call */
94  Ret = RtlGetNtProductType(&ProductType);
95  ok(Ret == TRUE, "Expected a valid product type value (and TRUE as returned success code) but got %u as status.\n", Ret);
96  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);
97 }
#define ERROR_SUCCESS
Definition: deptool.c:10
START_TEST(RtlGetNtProductType)
#define TRUE
Definition: types.h:120
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG _In_opt_ PVOID Data
Definition: wdfdevice.h:4527
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define StartSeh()
Definition: _sntprintf.h:16
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
static BOOLEAN ReturnNtProduct(PDWORD ProductNtType)
unsigned char BOOLEAN
_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
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFKEY * Key
Definition: wdfdevice.h:2654
BOOLEAN NTAPI RtlGetNtProductType(_Out_ PNT_PRODUCT_TYPE ProductType)
Definition: version.c:96
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
DWORD * PDWORD
Definition: pedump.c:68
enum _NT_PRODUCT_TYPE NT_PRODUCT_TYPE
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
BYTE * PBYTE
Definition: pedump.c:66
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17