ReactOS  0.4.13-dev-259-g5ca9c9c
environ.c
Go to the documentation of this file.
1 /*
2  * Unit test suite for environment functions.
3  *
4  * Copyright 2002 Dmitry Timoshkov
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #include <stdarg.h>
22 
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "winnls.h"
28 
29 static CHAR string[MAX_PATH];
30 #define ok_w(res, format, szString) \
31 \
32  WideCharToMultiByte(CP_ACP, 0, szString, -1, string, MAX_PATH, NULL, NULL); \
33  ok(res, format, string);
34 
35 static BOOL (WINAPI *pGetComputerNameExA)(COMPUTER_NAME_FORMAT,LPSTR,LPDWORD);
36 static BOOL (WINAPI *pGetComputerNameExW)(COMPUTER_NAME_FORMAT,LPWSTR,LPDWORD);
37 static BOOL (WINAPI *pOpenProcessToken)(HANDLE,DWORD,PHANDLE);
38 static BOOL (WINAPI *pGetUserProfileDirectoryA)(HANDLE,LPSTR,LPDWORD);
39 
40 static void init_functionpointers(void)
41 {
42  HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
43  HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
44  HMODULE huserenv = LoadLibraryA("userenv.dll");
45 
46  pGetComputerNameExA = (void *)GetProcAddress(hkernel32, "GetComputerNameExA");
47  pGetComputerNameExW = (void *)GetProcAddress(hkernel32, "GetComputerNameExW");
48  pOpenProcessToken = (void *)GetProcAddress(hadvapi32, "OpenProcessToken");
49  pGetUserProfileDirectoryA = (void *)GetProcAddress(huserenv,
50  "GetUserProfileDirectoryA");
51 }
52 
53 static void test_Predefined(void)
54 {
55  char Data[1024];
57  char Env[sizeof(Data)];
58  DWORD EnvSize;
59  HANDLE Token;
60  BOOL NoErr;
61 
62  /*
63  * Check value of %USERPROFILE%, should be same as GetUserProfileDirectory()
64  * If this fails, your test environment is probably not set up
65  */
66  if (pOpenProcessToken == NULL || pGetUserProfileDirectoryA == NULL)
67  {
68  skip("Skipping USERPROFILE check\n");
69  return;
70  }
71  NoErr = pOpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &Token);
72  ok(NoErr, "Failed to open token, error %u\n", GetLastError());
73  DataSize = sizeof(Data);
74  NoErr = pGetUserProfileDirectoryA(Token, Data, &DataSize);
75  ok(NoErr, "Failed to get user profile dir, error %u\n", GetLastError());
76  if (NoErr)
77  {
78  EnvSize = GetEnvironmentVariableA("USERPROFILE", Env, sizeof(Env));
79  ok(EnvSize != 0 && EnvSize <= sizeof(Env),
80  "Failed to retrieve environment variable USERPROFILE, error %u\n",
81  GetLastError());
82  ok(strcmp(Data, Env) == 0,
83  "USERPROFILE env var %s doesn't match GetUserProfileDirectory %s\n",
84  Env, Data);
85  }
86  else
87  skip("Skipping USERPROFILE check, can't get user profile dir\n");
88  NoErr = CloseHandle(Token);
89  ok(NoErr, "Failed to close token, error %u\n", GetLastError());
90 }
91 
93 {
94  char buf[256];
95  BOOL ret;
96  DWORD ret_size;
97  static const char name[] = "SomeWildName";
98  static const char name_cased[] = "sOMEwILDnAME";
99  static const char value[] = "SomeWildValue";
100 
102  ok(ret == TRUE,
103  "unexpected error in SetEnvironmentVariableA, GetLastError=%d\n",
104  GetLastError());
105 
106  /* Try to retrieve the environment variable we just set */
107  ret_size = GetEnvironmentVariableA(name, NULL, 0);
108  ok(ret_size == strlen(value) + 1,
109  "should return length with terminating 0 ret_size=%d\n", ret_size);
110 
111  lstrcpyA(buf, "foo");
113  ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer\n");
114  ok(ret_size == strlen(value) + 1,
115  "should return length with terminating 0 ret_size=%d\n", ret_size);
116 
117  lstrcpyA(buf, "foo");
118  ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
119  ok(lstrcmpA(buf, value) == 0, "should touch the buffer\n");
120  ok(ret_size == strlen(value),
121  "should return length without terminating 0 ret_size=%d\n", ret_size);
122 
123  lstrcpyA(buf, "foo");
124  ret_size = GetEnvironmentVariableA(name_cased, buf, lstrlenA(value) + 1);
125  ok(lstrcmpA(buf, value) == 0, "should touch the buffer\n");
126  ok(ret_size == strlen(value),
127  "should return length without terminating 0 ret_size=%d\n", ret_size);
128 
129  /* Remove that environment variable */
130  ret = SetEnvironmentVariableA(name_cased, NULL);
131  ok(ret == TRUE, "should erase existing variable\n");
132 
133  lstrcpyA(buf, "foo");
134  ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
135  ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer\n");
136  ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
137  "should not find variable but ret_size=%d GetLastError=%d\n",
138  ret_size, GetLastError());
139 
140  /* Check behavior of SetEnvironmentVariableA(name, "") */
142  ok(ret == TRUE,
143  "unexpected error in SetEnvironmentVariableA, GetLastError=%d\n",
144  GetLastError());
145 
146  lstrcpyA(buf, "foo");
147  ret_size = GetEnvironmentVariableA(name_cased, buf, lstrlenA(value) + 1);
148  ok(lstrcmpA(buf, value) == 0, "should touch the buffer\n");
149  ok(ret_size == strlen(value),
150  "should return length without terminating 0 ret_size=%d\n", ret_size);
151 
152  ret = SetEnvironmentVariableA(name_cased, "");
153  ok(ret == TRUE,
154  "should not fail with empty value but GetLastError=%d\n", GetLastError());
155 
156  lstrcpyA(buf, "foo");
157  SetLastError(0);
158  ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
159  ok(ret_size == 0 &&
160  ((GetLastError() == 0 && lstrcmpA(buf, "") == 0) ||
162  "%s should be set to \"\" (NT) or removed (Win9x) but ret_size=%d GetLastError=%d and buf=%s\n",
163  name, ret_size, GetLastError(), buf);
164 
165  /* Test the limits */
166  ret_size = GetEnvironmentVariableA(NULL, NULL, 0);
168  "should not find variable but ret_size=%d GetLastError=%d\n",
169  ret_size, GetLastError());
170 
171  ret_size = GetEnvironmentVariableA(NULL, buf, lstrlenA(value) + 1);
173  "should not find variable but ret_size=%d GetLastError=%d\n",
174  ret_size, GetLastError());
175 
176  ret_size = GetEnvironmentVariableA("", buf, lstrlenA(value) + 1);
177  ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
178  "should not find variable but ret_size=%d GetLastError=%d\n",
179  ret_size, GetLastError());
180 }
181 
183 {
184  WCHAR buf[256];
185  BOOL ret;
186  DWORD ret_size;
187  static const WCHAR name[] = {'S','o','m','e','W','i','l','d','N','a','m','e',0};
188  static const WCHAR value[] = {'S','o','m','e','W','i','l','d','V','a','l','u','e',0};
189  static const WCHAR name_cased[] = {'s','O','M','E','w','I','L','D','n','A','M','E',0};
190  static const WCHAR empty_strW[] = { 0 };
191  static const WCHAR fooW[] = {'f','o','o',0};
192 
195  {
196  /* Must be Win9x which doesn't support the Unicode functions */
197  win_skip("SetEnvironmentVariableW is not implemented\n");
198  return;
199  }
200  ok(ret == TRUE,
201  "unexpected error in SetEnvironmentVariableW, GetLastError=%d\n",
202  GetLastError());
203 
204  /* Try to retrieve the environment variable we just set */
205  ret_size = GetEnvironmentVariableW(name, NULL, 0);
206  ok(ret_size == lstrlenW(value) + 1,
207  "should return length with terminating 0 ret_size=%d\n",
208  ret_size);
209 
210  lstrcpyW(buf, fooW);
212  ok_w(lstrcmpW(buf, fooW) == 0 ||
213  lstrlenW(buf) == 0, /* Vista */
214  "Expected untouched or empty buffer, got \"%s\"\n", buf);
215 
216  ok(ret_size == lstrlenW(value) + 1,
217  "should return length with terminating 0 ret_size=%d\n", ret_size);
218 
219  lstrcpyW(buf, fooW);
220  ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
221  ok(lstrcmpW(buf, value) == 0, "should touch the buffer\n");
222  ok(ret_size == lstrlenW(value),
223  "should return length without terminating 0 ret_size=%d\n", ret_size);
224 
225  lstrcpyW(buf, fooW);
226  ret_size = GetEnvironmentVariableW(name_cased, buf, lstrlenW(value) + 1);
227  ok(lstrcmpW(buf, value) == 0, "should touch the buffer\n");
228  ok(ret_size == lstrlenW(value),
229  "should return length without terminating 0 ret_size=%d\n", ret_size);
230 
231  /* Remove that environment variable */
232  ret = SetEnvironmentVariableW(name_cased, NULL);
233  ok(ret == TRUE, "should erase existing variable\n");
234 
235  lstrcpyW(buf, fooW);
236  ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
237  ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer\n");
238  ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
239  "should not find variable but ret_size=%d GetLastError=%d\n",
240  ret_size, GetLastError());
241 
242  /* Check behavior of SetEnvironmentVariableW(name, "") */
244  ok(ret == TRUE,
245  "unexpected error in SetEnvironmentVariableW, GetLastError=%d\n",
246  GetLastError());
247 
248  lstrcpyW(buf, fooW);
249  ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
250  ok(lstrcmpW(buf, value) == 0, "should touch the buffer\n");
251  ok(ret_size == lstrlenW(value),
252  "should return length without terminating 0 ret_size=%d\n", ret_size);
253 
254  ret = SetEnvironmentVariableW(name_cased, empty_strW);
255  ok(ret == TRUE, "should not fail with empty value but GetLastError=%d\n", GetLastError());
256 
257  lstrcpyW(buf, fooW);
258  ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
259  ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
260  "should not find variable but ret_size=%d GetLastError=%d\n",
261  ret_size, GetLastError());
262  ok(lstrcmpW(buf, empty_strW) == 0, "should copy an empty string\n");
263 
264  /* Test the limits */
265  ret_size = GetEnvironmentVariableW(NULL, NULL, 0);
266  ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
267  "should not find variable but ret_size=%d GetLastError=%d\n",
268  ret_size, GetLastError());
269 
270  if (0) /* Both tests crash on Vista */
271  {
272  ret_size = GetEnvironmentVariableW(NULL, buf, lstrlenW(value) + 1);
273  ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
274  "should not find variable but ret_size=%d GetLastError=%d\n",
275  ret_size, GetLastError());
276 
279  "should fail with NULL, NULL but ret=%d and GetLastError=%d\n",
280  ret, GetLastError());
281  }
282 }
283 
285 {
286  const char* value="Long long value";
287  const char* not_an_env_var="%NotAnEnvVar%";
288  char buf[256], buf1[256], buf2[0x8000];
289  DWORD ret_size, ret_size1;
290 
291  SetEnvironmentVariableA("EnvVar", value);
292 
293  ret_size = ExpandEnvironmentStringsA(NULL, buf1, sizeof(buf1));
294  ok(ret_size == 1 || ret_size == 0 /* Win9x */ || ret_size == 2 /* NT4 */,
295  "ExpandEnvironmentStrings returned %d\n", ret_size);
296 
297  /* Try to get the required buffer size 'the natural way' */
298  strcpy(buf, "%EnvVar%");
299  ret_size = ExpandEnvironmentStringsA(buf, NULL, 0);
300  ok(ret_size == strlen(value)+1 || /* win98 */
301  ret_size == (strlen(value)+1)*2 || /* NT4 */
302  ret_size == strlen(value)+2 || /* win2k, XP, win2k3 */
303  ret_size == 0 /* Win95 */,
304  "ExpandEnvironmentStrings returned %d instead of %d, %d or %d\n",
305  ret_size, lstrlenA(value)+1, lstrlenA(value)+2, 0);
306 
307  /* Again, side-stepping the Win95 bug */
308  ret_size = ExpandEnvironmentStringsA(buf, buf1, 0);
309  /* v5.1.2600.2945 (XP SP2) returns len + 2 here! */
310  ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2 ||
311  ret_size == (strlen(value)+1)*2 /* NT4 */,
312  "ExpandEnvironmentStrings returned %d instead of %d\n",
313  ret_size, lstrlenA(value)+1);
314 
315  /* Try with a buffer that's too small */
316  ret_size = ExpandEnvironmentStringsA(buf, buf1, 12);
317  /* v5.1.2600.2945 (XP SP2) returns len + 2 here! */
318  ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2 ||
319  ret_size == (strlen(value)+1)*2 /* NT4 */,
320  "ExpandEnvironmentStrings returned %d instead of %d\n",
321  ret_size, lstrlenA(value)+1);
322 
323  /* Try with a buffer of just the right size */
324  /* v5.1.2600.2945 (XP SP2) needs and returns len + 2 here! */
325  ret_size = ExpandEnvironmentStringsA(buf, buf1, ret_size);
326  ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2 ||
327  ret_size == (strlen(value)+1)*2 /* NT4 */,
328  "ExpandEnvironmentStrings returned %d instead of %d\n",
329  ret_size, lstrlenA(value)+1);
330  ok(!strcmp(buf1, value), "ExpandEnvironmentStrings returned [%s]\n", buf1);
331 
332  /* Try with an unset environment variable */
333  strcpy(buf, not_an_env_var);
334  ret_size = ExpandEnvironmentStringsA(buf, buf1, sizeof(buf1));
335  ok(ret_size == strlen(not_an_env_var)+1 ||
336  ret_size == (strlen(not_an_env_var)+1)*2 /* NT4 */,
337  "ExpandEnvironmentStrings returned %d instead of %d\n", ret_size, lstrlenA(not_an_env_var)+1);
338  ok(!strcmp(buf1, not_an_env_var), "ExpandEnvironmentStrings returned [%s]\n", buf1);
339 
340  /* test a large destination size */
341  strcpy(buf, "12345");
342  ret_size = ExpandEnvironmentStringsA(buf, buf2, sizeof(buf2));
343  ok(!strcmp(buf, buf2), "ExpandEnvironmentStrings failed %s vs %s. ret_size = %d\n", buf, buf2, ret_size);
344 
345  ret_size1 = GetWindowsDirectoryA(buf1,256);
346  ok ((ret_size1 >0) && (ret_size1<256), "GetWindowsDirectory Failed\n");
347  ret_size = ExpandEnvironmentStringsA("%SystemRoot%",buf,sizeof(buf));
349  {
350  ok(!strcmp(buf, buf1), "ExpandEnvironmentStrings failed %s vs %s. ret_size = %d\n", buf, buf1, ret_size);
351  }
352 
353  /* Try with a variable that references another */
354  SetEnvironmentVariableA("IndirectVar", "Foo%EnvVar%Bar");
355  strcpy(buf, "Indirect-%IndirectVar%-Indirect");
356  strcpy(buf2, "Indirect-Foo%EnvVar%Bar-Indirect");
357  ret_size = ExpandEnvironmentStringsA(buf, buf1, sizeof(buf1));
358  ok(ret_size == strlen(buf2)+1 ||
359  ret_size == (strlen(buf2)+1)*2 /* NT4 */,
360  "ExpandEnvironmentStrings returned %d instead of %d\n", ret_size, lstrlenA(buf2)+1);
361  ok(!strcmp(buf1, buf2), "ExpandEnvironmentStrings returned [%s]\n", buf1);
362  SetEnvironmentVariableA("IndirectVar", NULL);
363 
364  SetEnvironmentVariableA("EnvVar", NULL);
365 }
366 
367 static void test_GetComputerName(void)
368 {
369  DWORD size;
370  BOOL ret;
371  LPSTR name;
372  LPWSTR nameW;
373  DWORD error;
374  int name_len;
375 
376  size = 0;
377  ret = GetComputerNameA((LPSTR)0xdeadbeef, &size);
378  error = GetLastError();
379  ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameA should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error);
380 
381  /* Only Vista returns the computer name length as documented in the MSDN */
382  if (size != 0)
383  {
384  size++; /* nul terminating character */
385  name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
386  ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
388  ok(ret, "GetComputerNameA failed with error %d\n", GetLastError());
390  }
391 
393  name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
394  ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
396  ok(ret, "GetComputerNameA failed with error %d\n", GetLastError());
397  trace("computer name is \"%s\"\n", name);
398  name_len = strlen(name);
399  ok(size == name_len, "size should be same as length, name_len=%d, size=%d\n", name_len, size);
401 
402  size = 0;
403  SetLastError(0xdeadbeef);
404  ret = GetComputerNameW((LPWSTR)0xdeadbeef, &size);
405  error = GetLastError();
407  win_skip("GetComputerNameW is not implemented\n");
408  else
409  {
410  ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameW should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error);
411  size++; /* nul terminating character */
412  nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
413  ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
415  ok(ret, "GetComputerNameW failed with error %d\n", GetLastError());
417  }
418 }
419 
420 static void test_GetComputerNameExA(void)
421 {
422  DWORD size;
423  BOOL ret;
424  LPSTR name;
425  DWORD error;
426 
427  static const int MAX_COMP_NAME = 32767;
428 
429  if (!pGetComputerNameExA)
430  {
431  win_skip("GetComputerNameExA function not implemented\n");
432  return;
433  }
434 
435  size = 0;
436  ret = pGetComputerNameExA(ComputerNameDnsDomain, (LPSTR)0xdeadbeef, &size);
437  error = GetLastError();
438  ok(ret == 0, "Expected 0, got %d\n", ret);
439  ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
440 
441  /* size is not set in win2k */
442  if (size == 0)
443  {
444  win_skip("Win2k doesn't set the size\n");
445  size = MAX_COMP_NAME;
446  }
447  name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
448  ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
449  ret = pGetComputerNameExA(ComputerNameDnsDomain, name, &size);
450  ok(ret, "GetComputerNameExA(ComputerNameDnsDomain) failed with error %d\n", GetLastError());
451  trace("domain name is \"%s\"\n", name);
453 
454  size = 0;
455  ret = pGetComputerNameExA(ComputerNameDnsFullyQualified, (LPSTR)0xdeadbeef, &size);
456  error = GetLastError();
457  ok(ret == 0, "Expected 0, got %d\n", ret);
458  ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
459 
460  /* size is not set in win2k */
461  if (size == 0)
462  size = MAX_COMP_NAME;
463  name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
464  ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
465  ret = pGetComputerNameExA(ComputerNameDnsFullyQualified, name, &size);
466  ok(ret, "GetComputerNameExA(ComputerNameDnsFullyQualified) failed with error %d\n", GetLastError());
467  trace("fully qualified hostname is \"%s\"\n", name);
469 
470  size = 0;
471  ret = pGetComputerNameExA(ComputerNameDnsHostname, (LPSTR)0xdeadbeef, &size);
472  error = GetLastError();
473  ok(ret == 0, "Expected 0, got %d\n", ret);
474  ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
475 
476  /* size is not set in win2k */
477  if (size == 0)
478  size = MAX_COMP_NAME;
479  name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
480  ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
481  ret = pGetComputerNameExA(ComputerNameDnsHostname, name, &size);
482  ok(ret, "GetComputerNameExA(ComputerNameDnsHostname) failed with error %d\n", GetLastError());
483  trace("hostname is \"%s\"\n", name);
485 
486  size = 0;
487  ret = pGetComputerNameExA(ComputerNameNetBIOS, (LPSTR)0xdeadbeef, &size);
488  error = GetLastError();
489  ok(ret == 0, "Expected 0, got %d\n", ret);
490  ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
491 
492  /* size is not set in win2k */
493  if (size == 0)
494  size = MAX_COMP_NAME;
495  name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
496  ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
497  ret = pGetComputerNameExA(ComputerNameNetBIOS, name, &size);
498  ok(ret, "GetComputerNameExA(ComputerNameNetBIOS) failed with error %d\n", GetLastError());
499  trace("NetBIOS name is \"%s\"\n", name);
501 }
502 
503 static void test_GetComputerNameExW(void)
504 {
505  DWORD size;
506  BOOL ret;
507  LPWSTR nameW;
508  DWORD error;
509 
510  if (!pGetComputerNameExW)
511  {
512  win_skip("GetComputerNameExW function not implemented\n");
513  return;
514  }
515 
516  size = 0;
517  ret = pGetComputerNameExW(ComputerNameDnsDomain, (LPWSTR)0xdeadbeef, &size);
518  error = GetLastError();
519  ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
520  nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
521  ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
522  ret = pGetComputerNameExW(ComputerNameDnsDomain, nameW, &size);
523  ok(ret, "GetComputerNameExW(ComputerNameDnsDomain) failed with error %d\n", GetLastError());
525 
526  size = 0;
527  ret = pGetComputerNameExW(ComputerNameDnsFullyQualified, (LPWSTR)0xdeadbeef, &size);
528  error = GetLastError();
529  ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
530  nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
531  ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
532  ret = pGetComputerNameExW(ComputerNameDnsFullyQualified, nameW, &size);
533  ok(ret, "GetComputerNameExW(ComputerNameDnsFullyQualified) failed with error %d\n", GetLastError());
535 
536  size = 0;
537  ret = pGetComputerNameExW(ComputerNameDnsHostname, (LPWSTR)0xdeadbeef, &size);
538  error = GetLastError();
539  ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
540  nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
541  ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
542  ret = pGetComputerNameExW(ComputerNameDnsHostname, nameW, &size);
543  ok(ret, "GetComputerNameExW(ComputerNameDnsHostname) failed with error %d\n", GetLastError());
545 
546  size = 0;
547  ret = pGetComputerNameExW(ComputerNameNetBIOS, (LPWSTR)0xdeadbeef, &size);
548  error = GetLastError();
549  ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
550  nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
551  ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
552  ret = pGetComputerNameExW(ComputerNameNetBIOS, nameW, &size);
553  ok(ret, "GetComputerNameExW(ComputerNameNetBIOS) failed with error %d\n", GetLastError());
555 }
556 
558 {
560 
561  test_Predefined();
568 }
BOOL WINAPI SHIM_OBJ_NAME() GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
Definition: shimtest.c:21
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
DWORD WINAPI DECLSPEC_HOTPATCH GetEnvironmentVariableW(IN LPCWSTR lpName, IN LPWSTR lpBuffer, IN DWORD nSize)
Definition: environ.c:163
#define trace(...)
Definition: kmt_test.h:217
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
static LPDWORD
Definition: environ.c:35
static LPSTR
Definition: environ.c:35
#define error(str)
Definition: mkdosfs.c:1605
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
char CHAR
Definition: xmlstorage.h:175
static void test_GetSetEnvironmentVariableA(void)
Definition: environ.c:92
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID _Out_ PHANDLE Token
static HINSTANCE hkernel32
Definition: process.c:66
static DWORD
Definition: environ.c:37
int WINAPI lstrcmpA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:18
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:440
static void test_Predefined(void)
Definition: environ.c:53
char * LPSTR
Definition: xmlstorage.h:182
#define ERROR_ENVVAR_NOT_FOUND
Definition: winerror.h:261
#define lstrlenW
Definition: compat.h:407
static PHANDLE
Definition: environ.c:37
static ULONG EnvSize
Definition: dem.c:258
unsigned int BOOL
Definition: ntddk_ex.h:94
static void test_GetSetEnvironmentVariableW(void)
Definition: environ.c:182
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
DWORD WINAPI ExpandEnvironmentStringsA(IN LPCSTR lpSrc, IN LPSTR lpDst, IN DWORD nSize)
Definition: environ.c:399
static void test_GetComputerName(void)
Definition: environ.c:367
static const WCHAR nameW[]
Definition: main.c:46
static LPWSTR
Definition: environ.c:36
#define ok_w(res, format, szString)
Definition: environ.c:30
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define TOKEN_QUERY
Definition: setypes.h:874
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableA(IN LPCSTR lpName, IN LPCSTR lpValue)
Definition: environ.c:218
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:8
static const WCHAR fooW[]
Definition: locale.c:44
static PVOID Env
Definition: dem.c:259
unsigned long DWORD
Definition: ntddk_ex.h:95
PVOID HANDLE
Definition: typedefs.h:71
#define SetLastError(x)
Definition: compat.h:409
LPSTR WINAPI lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:100
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableW(IN LPCWSTR lpName, IN LPCWSTR lpValue)
Definition: environ.c:259
int ret
char ** environ
static void test_GetComputerNameExW(void)
Definition: environ.c:503
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
#define ERROR_MORE_DATA
Definition: dderror.h:13
START_TEST(environ)
Definition: environ.c:557
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:240
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define lstrcpyW
Definition: compat.h:406
UINT WINAPI GetWindowsDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2336
#define skip(...)
Definition: name.c:36
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static BOOL(WINAPI *pGetComputerNameExA)(COMPUTER_NAME_FORMAT
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define GetProcAddress(x, y)
Definition: compat.h:410
static void init_functionpointers(void)
Definition: environ.c:40
WCHAR * LPWSTR
Definition: xmlstorage.h:184
DWORD WINAPI DECLSPEC_HOTPATCH GetEnvironmentVariableA(IN LPCSTR lpName, IN LPSTR lpBuffer, IN DWORD nSize)
Definition: environ.c:28
#define win_skip
Definition: test.h:141
#define HeapFree(x, y, z)
Definition: compat.h:394
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
static void test_ExpandEnvironmentStringsA(void)
Definition: environ.c:284
static void test_GetComputerNameExA(void)
Definition: environ.c:420
GLuint const GLchar * name
Definition: glext.h:6031