ReactOS 0.4.15-dev-8241-g63935f8
GetNetworkParams.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Tests for GetNetworkParams function
5 * PROGRAMMERS: Peter Hater
6 */
7
8#include <apitest.h>
9
10#define WIN32_NO_STATUS
11#include <iphlpapi.h>
12#include <winreg.h>
13
14#define ROSTESTDHCPHOST "testdhcproshost"
15#define ROSTESTDHCPDOMAIN "testrosdomain"
16
17static
18INT
20{
22 HKEY ParametersKey;
23 DWORD RegType;
24 DWORD RegSize = 0;
25
26 /* Open the database path key */
28 "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
29 0,
31 &ParametersKey);
32 if (ErrorCode == NO_ERROR)
33 {
34 /* Read the actual path */
35 ErrorCode = RegQueryValueExA(ParametersKey,
37 NULL,
38 &RegType,
39 NULL,
40 &RegSize);
41 if (RegSize)
42 {
43 /* Read the actual path */
44 ErrorCode = RegQueryValueExA(ParametersKey,
46 NULL,
47 &RegType,
49 &RegSize);
50 }
51
52 /* Close the key */
53 RegCloseKey(ParametersKey);
54 }
55 return ErrorCode;
56}
57
58static
59INT
61{
63 HKEY ParametersKey;
64
65 /* Open the database path key */
67 "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
68 0,
70 &ParametersKey);
71 if (ErrorCode == NO_ERROR)
72 {
73 /* Read the actual path */
74 ErrorCode = RegSetValueExA(ParametersKey,
76 0,
77 REG_SZ,
79 lstrlenA(Value) + 1);
80
81 /* Close the key */
82 RegCloseKey(ParametersKey);
83 }
84 return ErrorCode;
85}
86
87static
88INT
90{
92 HKEY ParametersKey;
93
94 /* Open the database path key */
96 "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
97 0,
99 &ParametersKey);
100 if (ErrorCode == NO_ERROR)
101 {
102 /* Read the actual path */
103 ErrorCode = RegDeleteValueA(ParametersKey, ValueName);
104
105 /* Close the key */
106 RegCloseKey(ParametersKey);
107 }
108 return ErrorCode;
109}
110
111static
112VOID
114{
115 DWORD len = 0;
117 CHAR OrigHostname[128];
118 CHAR OrigDomainName[128];
119 CHAR OrigDhcpHostname[128];
120 CHAR OrigDhcpDomainName[128];
121 BOOL OrigHostnameExists;
122 BOOL OrigDomainNameExists;
123 BOOL OrigDhcpHostnameExists;
124 BOOL OrigDhcpDomainNameExists;
125 PFIXED_INFO FixedInfo;
126 DWORD ApiReturn;
127
128 memset(OrigHostname, 0, sizeof(OrigHostname));
129 memset(OrigDomainName, 0, sizeof(OrigDomainName));
130 memset(OrigDhcpHostname, 0, sizeof(OrigDhcpHostname));
131 memset(OrigDhcpDomainName, 0, sizeof(OrigDhcpDomainName));
132 /* read current registry values */
133 ErrorCode = ReadRegistryValue("Hostname", OrigHostname);
134 ok(ErrorCode == ERROR_SUCCESS, "Failed to read registry key Hostname %d\n", ErrorCode);
135 OrigHostnameExists = ErrorCode == NO_ERROR;
136 ErrorCode = ReadRegistryValue("Domain", OrigDomainName);
137 ok(ErrorCode == ERROR_SUCCESS || ErrorCode == ERROR_FILE_NOT_FOUND, "Failed to read registry key DomainName %d\n", ErrorCode);
138 OrigDomainNameExists = ErrorCode == NO_ERROR;
139 ErrorCode = ReadRegistryValue("DhcpHostname", OrigDhcpHostname);
140 ok(ErrorCode == ERROR_SUCCESS || ErrorCode == ERROR_FILE_NOT_FOUND, "Failed to read registry key DhcpHostname %d\n", ErrorCode);
141 OrigDhcpHostnameExists = ErrorCode == NO_ERROR;
142 ErrorCode = ReadRegistryValue("DhcpDomain", OrigDhcpDomainName);
143 ok(ErrorCode == ERROR_SUCCESS || ErrorCode == ERROR_FILE_NOT_FOUND, "Failed to read registry key DhcpDomainName %d\n", ErrorCode);
144 OrigDhcpDomainNameExists = ErrorCode == NO_ERROR;
145
146 trace("Starting values:\n");
147 trace("Hostname: %s, exists %s\n", OrigHostname, OrigHostnameExists ? "yes" : "no");
148 trace("Domain: %s, exists %s\n", OrigDomainName, OrigDomainNameExists ? "yes" : "no");
149 trace("DhcpHostname: %s, exists %s\n", OrigDhcpHostnameExists ? OrigDhcpHostname : "", OrigDhcpHostnameExists ? "yes" : "no");
150 trace("DhcpDomain: %s, exists %s\n", OrigDhcpDomainNameExists ? OrigDhcpDomainName : "", OrigDhcpDomainNameExists ? "yes" : "no");
151
152 ApiReturn = GetNetworkParams(NULL, &len);
153 ok(ApiReturn == ERROR_BUFFER_OVERFLOW,
154 "GetNetworkParams returned %ld, expected ERROR_BUFFER_OVERFLOW\n",
155 ApiReturn);
156 if (ApiReturn != ERROR_BUFFER_OVERFLOW)
157 skip("Can't determine size of FIXED_INFO. Can't proceed\n");
158 FixedInfo = HeapAlloc(GetProcessHeap(), 0, len);
159 if (FixedInfo == NULL)
160 skip("FixedInfo is NULL. Can't proceed\n");
161
162 ApiReturn = GetNetworkParams(FixedInfo, &len);
163 ok(ApiReturn == NO_ERROR,
164 "GetNetworkParams(buf, &dwSize) returned %ld, expected NO_ERROR\n",
165 ApiReturn);
166 if (ApiReturn != NO_ERROR)
167 {
168 HeapFree(GetProcessHeap(), 0, FixedInfo);
169 skip("GetNetworkParams failed. Can't proceed\n");
170 }
171 ok(FixedInfo->HostName != NULL, "FixedInfo->HostName is NULL\n");
172 if (FixedInfo->HostName == NULL)
173 {
174 HeapFree(GetProcessHeap(), 0, FixedInfo);
175 skip("FixedInfo->HostName is NULL. Can't proceed\n");
176 }
177 if (OrigDhcpHostnameExists)
178 {
179 /* Windows doesn't honor DHCP option 12 even if RFC requires it if it is returned by DHCP server! */
180 //ok(strcmp(FixedInfo->HostName, OrigDhcpHostname) == 0, "FixedInfo->HostName is wrong '%s' != '%s'\n", FixedInfo->HostName, OrigDhcpHostname);
181 }
182 else
183 ok(strcmp(FixedInfo->HostName, OrigHostname) == 0, "FixedInfo->HostName is wrong '%s' != '%s'\n", FixedInfo->HostName, OrigHostname);
184 ok(FixedInfo->DomainName != NULL, "FixedInfo->DomainName is NULL\n");
185 if (FixedInfo->DomainName == NULL)
186 {
187 HeapFree(GetProcessHeap(), 0, FixedInfo);
188 skip("FixedInfo->DomainName is NULL. Can't proceed\n");
189 }
190 if(OrigDhcpDomainNameExists)
191 ok(strcmp(FixedInfo->DomainName, OrigDhcpDomainName) == 0, "FixedInfo->DomainName is wrong '%s' != '%s'\n", FixedInfo->DomainName, OrigDhcpDomainName);
192 else
193 ok(strcmp(FixedInfo->DomainName, OrigDomainName) == 0, "FixedInfo->DomainName is wrong '%s' != '%s'\n", FixedInfo->DomainName, OrigDomainName);
194 if (!OrigDhcpHostnameExists)
195 {
197 ok(ErrorCode == NO_ERROR, "Failed to write registry key DhcpHostname %d\n", ErrorCode);
198 }
199 else
200 {
201 ErrorCode = DeleteRegistryValue("DhcpHostname");
202 ok(ErrorCode == NO_ERROR, "Failed to remove registry key DhcpHostname %d\n", ErrorCode);
203 }
204 if (!OrigDhcpDomainNameExists)
205 {
207 ok(ErrorCode == NO_ERROR, "Failed to write registry key DhcpDomainName %d\n", ErrorCode);
208 }
209 else
210 {
211 ErrorCode = DeleteRegistryValue("DhcpDomain");
212 ok(ErrorCode == NO_ERROR, "Failed to remove registry key DhcpDomainName %d\n", ErrorCode);
213 }
214
215 HeapFree(GetProcessHeap(), 0, FixedInfo);
216 len = 0;
217 ApiReturn = GetNetworkParams(NULL, &len);
218 ok(ApiReturn == ERROR_BUFFER_OVERFLOW,
219 "GetNetworkParams returned %ld, expected ERROR_BUFFER_OVERFLOW\n",
220 ApiReturn);
221 if (ApiReturn != ERROR_BUFFER_OVERFLOW)
222 skip("Can't determine size of FIXED_INFO. Can't proceed\n");
223 FixedInfo = HeapAlloc(GetProcessHeap(), 0, len);
224 if (FixedInfo == NULL)
225 skip("FixedInfo is NULL. Can't proceed\n");
226 ApiReturn = GetNetworkParams(FixedInfo, &len);
227 ok(ApiReturn == NO_ERROR,
228 "GetNetworkParams(buf, &dwSize) returned %ld, expected NO_ERROR\n",
229 ApiReturn);
230 if (ApiReturn != NO_ERROR)
231 {
232 HeapFree(GetProcessHeap(), 0, FixedInfo);
233 skip("GetNetworkParams failed. Can't proceed\n");
234 }
235
236 /* restore registry values */
237 if (OrigDhcpHostnameExists)
238 ErrorCode = WriteRegistryValue("DhcpHostname", OrigDhcpHostname);
239 else
240 ErrorCode = DeleteRegistryValue("DhcpHostname");
241 ok(ErrorCode == NO_ERROR, "Failed to restore registry key DhcpHostname %d\n", ErrorCode);
242 if (OrigDhcpDomainNameExists)
243 ErrorCode = WriteRegistryValue("DhcpDomain", OrigDhcpDomainName);
244 else
245 ErrorCode = DeleteRegistryValue("DhcpDomain");
246 ok(ErrorCode == NO_ERROR, "Failed to restore registry key DhcpDomainName %d\n", ErrorCode);
247
248 ok(ApiReturn == NO_ERROR,
249 "GetNetworkParams(buf, &dwSize) returned %ld, expected NO_ERROR\n",
250 ApiReturn);
251 ok(FixedInfo->HostName != NULL, "FixedInfo->HostName is NULL\n");
252 if (FixedInfo->HostName == NULL)
253 skip("FixedInfo->HostName is NULL. Can't proceed\n");
254 if (!OrigDhcpHostnameExists)
255 {
256 /* Windows doesn't honor DHCP option 12 even if RFC requires it if it is returned by DHCP server! */
257 //ok(strcmp(FixedInfo->HostName, ROSTESTDHCPHOST) == 0, "FixedInfo->HostName is wrong '%s' != '%s'\n", FixedInfo->HostName, ROSTESTDHCPHOST);
258 }
259 else
260 ok(strcmp(FixedInfo->HostName, OrigHostname) == 0, "FixedInfo->HostName is wrong '%s' != '%s'\n", FixedInfo->HostName, OrigHostname);
261 ok(FixedInfo->DomainName != NULL, "FixedInfo->DomainName is NULL\n");
262 if (FixedInfo->DomainName == NULL)
263 skip("FixedInfo->DomainName is NULL. Can't proceed\n");
264 if (!OrigDhcpDomainNameExists)
265 ok(strcmp(FixedInfo->DomainName, ROSTESTDHCPDOMAIN) == 0, "FixedInfo->DomainName is wrong '%s' != '%s'\n", FixedInfo->DomainName, ROSTESTDHCPDOMAIN);
266 else
267 ok(strcmp(FixedInfo->DomainName, OrigDomainName) == 0, "FixedInfo->DomainName is wrong '%s' != '%s'\n", FixedInfo->DomainName, OrigDomainName);
268
269 HeapFree(GetProcessHeap(), 0, FixedInfo);
270}
271
273{
275}
static INT ReadRegistryValue(PCHAR ValueName, PCHAR Value)
#define ROSTESTDHCPHOST
#define ROSTESTDHCPDOMAIN
static INT WriteRegistryValue(PCHAR ValueName, PCHAR Value)
static VOID test_GetNetworkParams(VOID)
static INT DeleteRegistryValue(PCHAR ValueName)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define RegCloseKey(hKey)
Definition: registry.h:49
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4799
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3298
LONG WINAPI RegDeleteValueA(HKEY hKey, LPCSTR lpValueName)
Definition: reg.c:2287
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4009
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
#define REG_SZ
Definition: layer.c:22
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define KEY_READ
Definition: nt_native.h:1023
#define KEY_WRITE
Definition: nt_native.h:1031
#define memset(x, y, z)
Definition: compat.h:39
char HostName[MAX_HOSTNAME_LEN+4]
Definition: iptypes.h:81
char DomainName[MAX_DOMAIN_NAME_LEN+4]
Definition: iptypes.h:82
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
char CHAR
Definition: xmlstorage.h:175