7f148c13ebc0e8699c1dcd4f65fc6ee02dc39630
[reactos.git] / modules / rostests / apitests / ntdll / RtlGetNtProductType.c
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 Bișoc George <fraizeraust99 at gmail dot com>
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
21 Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
22 L"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
23 0,
24 KEY_QUERY_VALUE,
25 &Key);
26 if (Result != ERROR_SUCCESS)
27 {
28 *ProductNtType = 0;
29 return FALSE;
30 }
31
32 Result = RegQueryValueExW(Key,
33 L"ProductType",
34 NULL,
35 NULL,
36 (PBYTE)&Data,
37 &Size);
38 if (Result != ERROR_SUCCESS)
39 {
40 RegCloseKey(Key);
41 *ProductNtType = 0;
42 return FALSE;
43 }
44
45 if (wcscmp(Data, L"WinNT") == 0)
46 {
47 *ProductNtType = NtProductWinNt;
48 RegCloseKey(Key);
49 return TRUE;
50 }
51
52 if (wcscmp(Data, L"LanmanNT") == 0)
53 {
54 *ProductNtType = NtProductLanManNt;
55 RegCloseKey(Key);
56 return TRUE;
57 }
58
59 if (wcscmp(Data, L"ServerNT") == 0)
60 {
61 *ProductNtType = NtProductServer;
62 RegCloseKey(Key);
63 return TRUE;
64 }
65
66 *ProductNtType = 0;
67 RegCloseKey(Key);
68 return FALSE;
69 }
70
71 START_TEST(RtlGetNtProductType)
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()
83 RtlGetNtProductType(NULL);
84 EndSeh(STATUS_ACCESS_VIOLATION);
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 }