2 * Unit test suite for environment functions.
4 * Copyright 2002 Dmitry Timoshkov
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.
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.
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
23 #include "wine/test.h"
29 static CHAR string[MAX_PATH];
30 #define ok_w(res, format, szString) \
32 WideCharToMultiByte(CP_ACP, 0, szString, -1, string, MAX_PATH, NULL, NULL); \
33 ok(res, format, string);
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);
40 static void init_functionpointers(void)
42 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
43 HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
44 HMODULE huserenv = LoadLibraryA("userenv.dll");
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");
53 static void test_Predefined(void)
57 char Env[sizeof(Data)];
63 * Check value of %USERPROFILE%, should be same as GetUserProfileDirectory()
64 * If this fails, your test environment is probably not set up
66 if (pOpenProcessToken == NULL || pGetUserProfileDirectoryA == NULL)
68 skip("Skipping USERPROFILE check\n");
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());
78 EnvSize = GetEnvironmentVariableA("USERPROFILE", Env, sizeof(Env));
79 ok(EnvSize != 0 && EnvSize <= sizeof(Env),
80 "Failed to retrieve environment variable USERPROFILE, error %u\n",
82 ok(strcmp(Data, Env) == 0,
83 "USERPROFILE env var %s doesn't match GetUserProfileDirectory %s\n",
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());
92 static void test_GetSetEnvironmentVariableA(void)
97 static const char name[] = "SomeWildName";
98 static const char name_cased[] = "sOMEwILDnAME";
99 static const char value[] = "SomeWildValue";
101 ret = SetEnvironmentVariableA(name, value);
103 "unexpected error in SetEnvironmentVariableA, GetLastError=%d\n",
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);
111 lstrcpyA(buf, "foo");
112 ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value));
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);
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);
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);
129 /* Remove that environment variable */
130 ret = SetEnvironmentVariableA(name_cased, NULL);
131 ok(ret == TRUE, "should erase existing variable\n");
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());
140 /* Check behavior of SetEnvironmentVariableA(name, "") */
141 ret = SetEnvironmentVariableA(name, value);
143 "unexpected error in SetEnvironmentVariableA, GetLastError=%d\n",
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);
152 ret = SetEnvironmentVariableA(name_cased, "");
154 "should not fail with empty value but GetLastError=%d\n", GetLastError());
156 lstrcpyA(buf, "foo");
158 ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
160 ((GetLastError() == 0 && lstrcmpA(buf, "") == 0) ||
161 (GetLastError() == ERROR_ENVVAR_NOT_FOUND)),
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);
165 /* Test the limits */
166 ret_size = GetEnvironmentVariableA(NULL, NULL, 0);
167 ok(ret_size == 0 && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_ENVVAR_NOT_FOUND),
168 "should not find variable but ret_size=%d GetLastError=%d\n",
169 ret_size, GetLastError());
171 ret_size = GetEnvironmentVariableA(NULL, buf, lstrlenA(value) + 1);
172 ok(ret_size == 0 && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_ENVVAR_NOT_FOUND),
173 "should not find variable but ret_size=%d GetLastError=%d\n",
174 ret_size, GetLastError());
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());
182 static void test_GetSetEnvironmentVariableW(void)
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};
193 ret = SetEnvironmentVariableW(name, value);
194 if (ret == FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
196 /* Must be Win9x which doesn't support the Unicode functions */
197 win_skip("SetEnvironmentVariableW is not implemented\n");
201 "unexpected error in SetEnvironmentVariableW, GetLastError=%d\n",
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",
211 ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value));
212 ok_w(lstrcmpW(buf, fooW) == 0 ||
213 lstrlenW(buf) == 0, /* Vista */
214 "Expected untouched or empty buffer, got \"%s\"\n", buf);
216 ok(ret_size == lstrlenW(value) + 1,
217 "should return length with terminating 0 ret_size=%d\n", ret_size);
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);
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);
231 /* Remove that environment variable */
232 ret = SetEnvironmentVariableW(name_cased, NULL);
233 ok(ret == TRUE, "should erase existing variable\n");
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());
242 /* Check behavior of SetEnvironmentVariableW(name, "") */
243 ret = SetEnvironmentVariableW(name, value);
245 "unexpected error in SetEnvironmentVariableW, GetLastError=%d\n",
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);
254 ret = SetEnvironmentVariableW(name_cased, empty_strW);
255 ok(ret == TRUE, "should not fail with empty value but GetLastError=%d\n", GetLastError());
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");
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());
270 if (0) /* Both tests crash on Vista */
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());
277 ret = SetEnvironmentVariableW(NULL, NULL);
278 ok(ret == FALSE && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_ENVVAR_NOT_FOUND),
279 "should fail with NULL, NULL but ret=%d and GetLastError=%d\n",
280 ret, GetLastError());
284 static void test_ExpandEnvironmentStringsA(void)
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;
291 SetEnvironmentVariableA("EnvVar", value);
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);
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);
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);
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);
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);
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);
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);
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));
348 if (ERROR_ENVVAR_NOT_FOUND != GetLastError())
350 ok(!strcmp(buf, buf1), "ExpandEnvironmentStrings failed %s vs %s. ret_size = %d\n", buf, buf1, ret_size);
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, lstrlen(buf2)+1);
361 ok(!strcmp(buf1, buf2), "ExpandEnvironmentStrings returned [%s]\n", buf1);
362 SetEnvironmentVariableA("IndirectVar", NULL);
364 SetEnvironmentVariableA("EnvVar", NULL);
367 static void test_GetComputerName(void)
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);
381 /* Only Vista returns the computer name length as documented in the MSDN */
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());
387 ret = GetComputerNameA(name, &size);
388 ok(ret, "GetComputerNameA failed with error %d\n", GetLastError());
389 HeapFree(GetProcessHeap(), 0, name);
392 size = MAX_COMPUTERNAME_LENGTH + 1;
393 name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
394 ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
395 ret = GetComputerNameA(name, &size);
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);
400 HeapFree(GetProcessHeap(), 0, name);
403 SetLastError(0xdeadbeef);
404 ret = GetComputerNameW((LPWSTR)0xdeadbeef, &size);
405 error = GetLastError();
406 if (error == ERROR_CALL_NOT_IMPLEMENTED)
407 win_skip("GetComputerNameW is not implemented\n");
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());
414 ret = GetComputerNameW(nameW, &size);
415 ok(ret, "GetComputerNameW failed with error %d\n", GetLastError());
416 HeapFree(GetProcessHeap(), 0, nameW);
420 static void test_GetComputerNameExA(void)
427 static const int MAX_COMP_NAME = 32767;
429 if (!pGetComputerNameExA)
431 win_skip("GetComputerNameExA function not implemented\n");
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);
441 /* size is not set in win2k */
444 win_skip("Win2k doesn't set the size\n");
445 size = MAX_COMP_NAME;
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);
452 HeapFree(GetProcessHeap(), 0, name);
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);
460 /* size is not set in win2k */
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);
468 HeapFree(GetProcessHeap(), 0, name);
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);
476 /* size is not set in win2k */
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);
484 HeapFree(GetProcessHeap(), 0, name);
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);
492 /* size is not set in win2k */
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);
500 HeapFree(GetProcessHeap(), 0, name);
503 static void test_GetComputerNameExW(void)
510 if (!pGetComputerNameExW)
512 win_skip("GetComputerNameExW function not implemented\n");
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());
524 HeapFree(GetProcessHeap(), 0, nameW);
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());
534 HeapFree(GetProcessHeap(), 0, nameW);
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());
544 HeapFree(GetProcessHeap(), 0, nameW);
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());
554 HeapFree(GetProcessHeap(), 0, nameW);
559 init_functionpointers();
562 test_GetSetEnvironmentVariableA();
563 test_GetSetEnvironmentVariableW();
564 test_ExpandEnvironmentStringsA();
565 test_GetComputerName();
566 test_GetComputerNameExA();
567 test_GetComputerNameExW();