~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/kernel32/tests/environ.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  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 
 38 static void init_functionpointers(void)
 39 {
 40     HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
 41 
 42     pGetComputerNameExA = (void *)GetProcAddress(hkernel32, "GetComputerNameExA");
 43     pGetComputerNameExW = (void *)GetProcAddress(hkernel32, "GetComputerNameExW");
 44 }
 45 
 46 static void test_GetSetEnvironmentVariableA(void)
 47 {
 48     char buf[256];
 49     BOOL ret;
 50     DWORD ret_size;
 51     static const char name[] = "SomeWildName";
 52     static const char name_cased[] = "sOMEwILDnAME";
 53     static const char value[] = "SomeWildValue";
 54 
 55     ret = SetEnvironmentVariableA(name, value);
 56     ok(ret == TRUE,
 57        "unexpected error in SetEnvironmentVariableA, GetLastError=%d\n",
 58        GetLastError());
 59 
 60     /* Try to retrieve the environment variable we just set */
 61     ret_size = GetEnvironmentVariableA(name, NULL, 0);
 62     ok(ret_size == strlen(value) + 1,
 63        "should return length with terminating 0 ret_size=%d\n", ret_size);
 64 
 65     lstrcpyA(buf, "foo");
 66     ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value));
 67     ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer\n");
 68     ok(ret_size == strlen(value) + 1,
 69        "should return length with terminating 0 ret_size=%d\n", ret_size);
 70 
 71     lstrcpyA(buf, "foo");
 72     ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
 73     ok(lstrcmpA(buf, value) == 0, "should touch the buffer\n");
 74     ok(ret_size == strlen(value),
 75        "should return length without terminating 0 ret_size=%d\n", ret_size);
 76 
 77     lstrcpyA(buf, "foo");
 78     ret_size = GetEnvironmentVariableA(name_cased, buf, lstrlenA(value) + 1);
 79     ok(lstrcmpA(buf, value) == 0, "should touch the buffer\n");
 80     ok(ret_size == strlen(value),
 81        "should return length without terminating 0 ret_size=%d\n", ret_size);
 82 
 83     /* Remove that environment variable */
 84     ret = SetEnvironmentVariableA(name_cased, NULL);
 85     ok(ret == TRUE, "should erase existing variable\n");
 86 
 87     lstrcpyA(buf, "foo");
 88     ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
 89     ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer\n");
 90     ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
 91        "should not find variable but ret_size=%d GetLastError=%d\n",
 92        ret_size, GetLastError());
 93 
 94     /* Check behavior of SetEnvironmentVariableA(name, "") */
 95     ret = SetEnvironmentVariableA(name, value);
 96     ok(ret == TRUE,
 97        "unexpected error in SetEnvironmentVariableA, GetLastError=%d\n",
 98        GetLastError());
 99 
100     lstrcpyA(buf, "foo");
101     ret_size = GetEnvironmentVariableA(name_cased, buf, lstrlenA(value) + 1);
102     ok(lstrcmpA(buf, value) == 0, "should touch the buffer\n");
103     ok(ret_size == strlen(value),
104        "should return length without terminating 0 ret_size=%d\n", ret_size);
105 
106     ret = SetEnvironmentVariableA(name_cased, "");
107     ok(ret == TRUE,
108        "should not fail with empty value but GetLastError=%d\n", GetLastError());
109 
110     lstrcpyA(buf, "foo");
111     SetLastError(0);
112     ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
113     ok(ret_size == 0 &&
114        ((GetLastError() == 0 && lstrcmpA(buf, "") == 0) ||
115         (GetLastError() == ERROR_ENVVAR_NOT_FOUND)),
116        "%s should be set to \"\" (NT) or removed (Win9x) but ret_size=%d GetLastError=%d and buf=%s\n",
117        name, ret_size, GetLastError(), buf);
118 
119     /* Test the limits */
120     ret_size = GetEnvironmentVariableA(NULL, NULL, 0);
121     ok(ret_size == 0 && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_ENVVAR_NOT_FOUND),
122        "should not find variable but ret_size=%d GetLastError=%d\n",
123        ret_size, GetLastError());
124 
125     ret_size = GetEnvironmentVariableA(NULL, buf, lstrlenA(value) + 1);
126     ok(ret_size == 0 && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_ENVVAR_NOT_FOUND),
127        "should not find variable but ret_size=%d GetLastError=%d\n",
128        ret_size, GetLastError());
129 
130     ret_size = GetEnvironmentVariableA("", buf, lstrlenA(value) + 1);
131     ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
132        "should not find variable but ret_size=%d GetLastError=%d\n",
133        ret_size, GetLastError());
134 }
135 
136 static void test_GetSetEnvironmentVariableW(void)
137 {
138     WCHAR buf[256];
139     BOOL ret;
140     DWORD ret_size;
141     static const WCHAR name[] = {'S','o','m','e','W','i','l','d','N','a','m','e',0};
142     static const WCHAR value[] = {'S','o','m','e','W','i','l','d','V','a','l','u','e',0};
143     static const WCHAR name_cased[] = {'s','O','M','E','w','I','L','D','n','A','M','E',0};
144     static const WCHAR empty_strW[] = { 0 };
145     static const WCHAR fooW[] = {'f','o','o',0};
146 
147     ret = SetEnvironmentVariableW(name, value);
148     if (ret == FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
149     {
150         /* Must be Win9x which doesn't support the Unicode functions */
151         win_skip("SetEnvironmentVariableW is not implemented\n");
152         return;
153     }
154     ok(ret == TRUE,
155        "unexpected error in SetEnvironmentVariableW, GetLastError=%d\n",
156        GetLastError());
157 
158     /* Try to retrieve the environment variable we just set */
159     ret_size = GetEnvironmentVariableW(name, NULL, 0);
160     ok(ret_size == lstrlenW(value) + 1,
161        "should return length with terminating 0 ret_size=%d\n",
162        ret_size);
163 
164     lstrcpyW(buf, fooW);
165     ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value));
166     ok_w(lstrcmpW(buf, fooW) == 0 ||
167          lstrlenW(buf) == 0, /* Vista */
168          "Expected untouched or empty buffer, got \"%s\"\n", buf);
169 
170     ok(ret_size == lstrlenW(value) + 1,
171        "should return length with terminating 0 ret_size=%d\n", ret_size);
172 
173     lstrcpyW(buf, fooW);
174     ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
175     ok(lstrcmpW(buf, value) == 0, "should touch the buffer\n");
176     ok(ret_size == lstrlenW(value),
177        "should return length without terminating 0 ret_size=%d\n", ret_size);
178 
179     lstrcpyW(buf, fooW);
180     ret_size = GetEnvironmentVariableW(name_cased, buf, lstrlenW(value) + 1);
181     ok(lstrcmpW(buf, value) == 0, "should touch the buffer\n");
182     ok(ret_size == lstrlenW(value),
183        "should return length without terminating 0 ret_size=%d\n", ret_size);
184 
185     /* Remove that environment variable */
186     ret = SetEnvironmentVariableW(name_cased, NULL);
187     ok(ret == TRUE, "should erase existing variable\n");
188 
189     lstrcpyW(buf, fooW);
190     ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
191     ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer\n");
192     ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
193        "should not find variable but ret_size=%d GetLastError=%d\n",
194        ret_size, GetLastError());
195 
196     /* Check behavior of SetEnvironmentVariableW(name, "") */
197     ret = SetEnvironmentVariableW(name, value);
198     ok(ret == TRUE,
199        "unexpected error in SetEnvironmentVariableW, GetLastError=%d\n",
200        GetLastError());
201 
202     lstrcpyW(buf, fooW);
203     ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
204     ok(lstrcmpW(buf, value) == 0, "should touch the buffer\n");
205     ok(ret_size == lstrlenW(value),
206        "should return length without terminating 0 ret_size=%d\n", ret_size);
207 
208     ret = SetEnvironmentVariableW(name_cased, empty_strW);
209     ok(ret == TRUE, "should not fail with empty value but GetLastError=%d\n", GetLastError());
210 
211     lstrcpyW(buf, fooW);
212     ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
213     ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
214        "should not find variable but ret_size=%d GetLastError=%d\n",
215        ret_size, GetLastError());
216     ok(lstrcmpW(buf, empty_strW) == 0, "should copy an empty string\n");
217 
218     /* Test the limits */
219     ret_size = GetEnvironmentVariableW(NULL, NULL, 0);
220     ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
221        "should not find variable but ret_size=%d GetLastError=%d\n",
222        ret_size, GetLastError());
223 
224     if (0) /* Both tests crash on Vista */
225     {
226         ret_size = GetEnvironmentVariableW(NULL, buf, lstrlenW(value) + 1);
227         ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
228            "should not find variable but ret_size=%d GetLastError=%d\n",
229            ret_size, GetLastError());
230 
231         ret = SetEnvironmentVariableW(NULL, NULL);
232         ok(ret == FALSE && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_ENVVAR_NOT_FOUND),
233            "should fail with NULL, NULL but ret=%d and GetLastError=%d\n",
234            ret, GetLastError());
235     }
236 }
237 
238 static void test_ExpandEnvironmentStringsA(void)
239 {
240     const char* value="Long long value";
241     const char* not_an_env_var="%NotAnEnvVar%";
242     char buf[256], buf1[256], buf2[0x8000];
243     DWORD ret_size, ret_size1;
244 
245     SetEnvironmentVariableA("EnvVar", value);
246 
247     ret_size = ExpandEnvironmentStringsA(NULL, buf1, sizeof(buf1));
248     ok(ret_size == 1 || ret_size == 0 /* Win9x */ || ret_size == 2 /* NT4 */,
249        "ExpandEnvironmentStrings returned %d\n", ret_size);
250 
251     /* Try to get the required buffer size 'the natural way' */
252     strcpy(buf, "%EnvVar%");
253     ret_size = ExpandEnvironmentStringsA(buf, NULL, 0);
254     ok(ret_size == strlen(value)+1 || /* win98 */
255        ret_size == (strlen(value)+1)*2 || /* NT4 */
256        ret_size == strlen(value)+2 || /* win2k, XP, win2k3 */
257        ret_size == 0 /* Win95 */,
258        "ExpandEnvironmentStrings returned %d instead of %d, %d or %d\n",
259        ret_size, lstrlenA(value)+1, lstrlenA(value)+2, 0);
260 
261     /* Again, side-stepping the Win95 bug */
262     ret_size = ExpandEnvironmentStringsA(buf, buf1, 0);
263     /* v5.1.2600.2945 (XP SP2) returns len + 2 here! */
264     ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2 ||
265        ret_size == (strlen(value)+1)*2 /* NT4 */,
266        "ExpandEnvironmentStrings returned %d instead of %d\n",
267        ret_size, lstrlenA(value)+1);
268 
269     /* Try with a buffer that's too small */
270     ret_size = ExpandEnvironmentStringsA(buf, buf1, 12);
271     /* v5.1.2600.2945 (XP SP2) returns len + 2 here! */
272     ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2 ||
273        ret_size == (strlen(value)+1)*2 /* NT4 */,
274        "ExpandEnvironmentStrings returned %d instead of %d\n",
275        ret_size, lstrlenA(value)+1);
276 
277     /* Try with a buffer of just the right size */
278     /* v5.1.2600.2945 (XP SP2) needs and returns len + 2 here! */
279     ret_size = ExpandEnvironmentStringsA(buf, buf1, ret_size);
280     ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2 ||
281        ret_size == (strlen(value)+1)*2 /* NT4 */,
282        "ExpandEnvironmentStrings returned %d instead of %d\n",
283        ret_size, lstrlenA(value)+1);
284     ok(!strcmp(buf1, value), "ExpandEnvironmentStrings returned [%s]\n", buf1);
285 
286     /* Try with an unset environment variable */
287     strcpy(buf, not_an_env_var);
288     ret_size = ExpandEnvironmentStringsA(buf, buf1, sizeof(buf1));
289     ok(ret_size == strlen(not_an_env_var)+1 ||
290        ret_size == (strlen(not_an_env_var)+1)*2 /* NT4 */,
291        "ExpandEnvironmentStrings returned %d instead of %d\n", ret_size, lstrlenA(not_an_env_var)+1);
292     ok(!strcmp(buf1, not_an_env_var), "ExpandEnvironmentStrings returned [%s]\n", buf1);
293 
294     /* test a large destination size */
295     strcpy(buf, "12345");
296     ret_size = ExpandEnvironmentStringsA(buf, buf2, sizeof(buf2));
297     ok(!strcmp(buf, buf2), "ExpandEnvironmentStrings failed %s vs %s. ret_size = %d\n", buf, buf2, ret_size);
298 
299     ret_size1 = GetWindowsDirectoryA(buf1,256);
300     ok ((ret_size1 >0) && (ret_size1<256), "GetWindowsDirectory Failed\n");
301     ret_size = ExpandEnvironmentStringsA("%SystemRoot%",buf,sizeof(buf));
302     if (ERROR_ENVVAR_NOT_FOUND != GetLastError())
303     {
304         ok(!strcmp(buf, buf1), "ExpandEnvironmentStrings failed %s vs %s. ret_size = %d\n", buf, buf1, ret_size);
305     }
306 
307     /* Try with a variable that references another */
308     SetEnvironmentVariableA("IndirectVar", "Foo%EnvVar%Bar");
309     strcpy(buf, "Indirect-%IndirectVar%-Indirect");
310     strcpy(buf2, "Indirect-Foo%EnvVar%Bar-Indirect");
311     ret_size = ExpandEnvironmentStringsA(buf, buf1, sizeof(buf1));
312     ok(ret_size == strlen(buf2)+1 ||
313        ret_size == (strlen(buf2)+1)*2 /* NT4 */,
314        "ExpandEnvironmentStrings returned %d instead of %d\n", ret_size, lstrlen(buf2)+1);
315     ok(!strcmp(buf1, buf2), "ExpandEnvironmentStrings returned [%s]\n", buf1);
316     SetEnvironmentVariableA("IndirectVar", NULL);
317 
318     SetEnvironmentVariableA("EnvVar", NULL);
319 }
320 
321 static void test_GetComputerName(void)
322 {
323     DWORD size;
324     BOOL ret;
325     LPSTR name;
326     LPWSTR nameW;
327     DWORD error;
328     int name_len;
329 
330     size = 0;
331     ret = GetComputerNameA((LPSTR)0xdeadbeef, &size);
332     error = GetLastError();
333     todo_wine
334     ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameA should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error);
335 
336     /* Only Vista returns the computer name length as documented in the MSDN */
337     if (size != 0)
338     {
339         size++; /* nul terminating character */
340         name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
341         ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
342         ret = GetComputerNameA(name, &size);
343         ok(ret, "GetComputerNameA failed with error %d\n", GetLastError());
344         HeapFree(GetProcessHeap(), 0, name);
345     }
346 
347     size = MAX_COMPUTERNAME_LENGTH + 1;
348     name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
349     ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
350     ret = GetComputerNameA(name, &size);
351     ok(ret, "GetComputerNameA failed with error %d\n", GetLastError());
352     trace("computer name is \"%s\"\n", name);
353     name_len = strlen(name);
354     ok(size == name_len, "size should be same as length, name_len=%d, size=%d\n", name_len, size);
355     HeapFree(GetProcessHeap(), 0, name);
356 
357     size = 0;
358     SetLastError(0xdeadbeef);
359     ret = GetComputerNameW((LPWSTR)0xdeadbeef, &size);
360     error = GetLastError();
361     if (error == ERROR_CALL_NOT_IMPLEMENTED)
362         win_skip("GetComputerNameW is not implemented\n");
363     else
364     {
365         todo_wine
366         ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameW should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error);
367         size++; /* nul terminating character */
368         nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
369         ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
370         ret = GetComputerNameW(nameW, &size);
371         ok(ret, "GetComputerNameW failed with error %d\n", GetLastError());
372         HeapFree(GetProcessHeap(), 0, nameW);
373     }
374 }
375 
376 static void test_GetComputerNameExA(void)
377 {
378     DWORD size;
379     BOOL ret;
380     LPSTR name;
381     DWORD error;
382 
383     static const int MAX_COMP_NAME = 32767;
384 
385     if (!pGetComputerNameExA)
386     {
387         win_skip("GetComputerNameExA function not implemented\n");
388         return;
389     }
390 
391     size = 0;
392     ret = pGetComputerNameExA(ComputerNameDnsDomain, (LPSTR)0xdeadbeef, &size);
393     error = GetLastError();
394     ok(ret == 0, "Expected 0, got %d\n", ret);
395     ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
396 
397     /* size is not set in win2k */
398     size = MAX_COMP_NAME;
399     name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
400     ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
401     ret = pGetComputerNameExA(ComputerNameDnsDomain, name, &size);
402     ok(ret, "GetComputerNameExA(ComputerNameDnsDomain) failed with error %d\n", GetLastError());
403     trace("domain name is \"%s\"\n", name);
404     HeapFree(GetProcessHeap(), 0, name);
405 
406     size = 0;
407     ret = pGetComputerNameExA(ComputerNameDnsFullyQualified, (LPSTR)0xdeadbeef, &size);
408     error = GetLastError();
409     ok(ret == 0, "Expected 0, got %d\n", ret);
410     ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
411 
412     /* size is not set in win2k */
413     size = MAX_COMP_NAME;
414     name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
415     ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
416     ret = pGetComputerNameExA(ComputerNameDnsFullyQualified, name, &size);
417     ok(ret, "GetComputerNameExA(ComputerNameDnsFullyQualified) failed with error %d\n", GetLastError());
418     trace("fully qualified hostname is \"%s\"\n", name);
419     HeapFree(GetProcessHeap(), 0, name);
420 
421     size = 0;
422     ret = pGetComputerNameExA(ComputerNameDnsHostname, (LPSTR)0xdeadbeef, &size);
423     error = GetLastError();
424     ok(ret == 0, "Expected 0, got %d\n", ret);
425     ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
426 
427     /* size is not set in win2k */
428     size = MAX_COMP_NAME;
429     name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
430     ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
431     ret = pGetComputerNameExA(ComputerNameDnsHostname, name, &size);
432     ok(ret, "GetComputerNameExA(ComputerNameDnsHostname) failed with error %d\n", GetLastError());
433     trace("hostname is \"%s\"\n", name);
434     HeapFree(GetProcessHeap(), 0, name);
435 
436     size = 0;
437     ret = pGetComputerNameExA(ComputerNameNetBIOS, (LPSTR)0xdeadbeef, &size);
438     error = GetLastError();
439     ok(ret == 0, "Expected 0, got %d\n", ret);
440     ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
441 
442     /* size is not set in win2k */
443     size = MAX_COMP_NAME;
444     name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
445     ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
446     ret = pGetComputerNameExA(ComputerNameNetBIOS, name, &size);
447     ok(ret, "GetComputerNameExA(ComputerNameNetBIOS) failed with error %d\n", GetLastError());
448     trace("NetBIOS name is \"%s\"\n", name);
449     HeapFree(GetProcessHeap(), 0, name);
450 }
451 
452 static void test_GetComputerNameExW(void)
453 {
454     DWORD size;
455     BOOL ret;
456     LPWSTR nameW;
457     DWORD error;
458 
459     if (!pGetComputerNameExW)
460     {
461         win_skip("GetComputerNameExW function not implemented\n");
462         return;
463     }
464 
465     size = 0;
466     ret = pGetComputerNameExW(ComputerNameDnsDomain, (LPWSTR)0xdeadbeef, &size);
467     error = GetLastError();
468     ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
469     nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
470     ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
471     ret = pGetComputerNameExW(ComputerNameDnsDomain, nameW, &size);
472     ok(ret, "GetComputerNameExW(ComputerNameDnsDomain) failed with error %d\n", GetLastError());
473     HeapFree(GetProcessHeap(), 0, nameW);
474 
475     size = 0;
476     ret = pGetComputerNameExW(ComputerNameDnsFullyQualified, (LPWSTR)0xdeadbeef, &size);
477     error = GetLastError();
478     ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
479     nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
480     ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
481     ret = pGetComputerNameExW(ComputerNameDnsFullyQualified, nameW, &size);
482     ok(ret, "GetComputerNameExW(ComputerNameDnsFullyQualified) failed with error %d\n", GetLastError());
483     HeapFree(GetProcessHeap(), 0, nameW);
484 
485     size = 0;
486     ret = pGetComputerNameExW(ComputerNameDnsHostname, (LPWSTR)0xdeadbeef, &size);
487     error = GetLastError();
488     ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
489     nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
490     ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
491     ret = pGetComputerNameExW(ComputerNameDnsHostname, nameW, &size);
492     ok(ret, "GetComputerNameExW(ComputerNameDnsHostname) failed with error %d\n", GetLastError());
493     HeapFree(GetProcessHeap(), 0, nameW);
494 
495     size = 0;
496     ret = pGetComputerNameExW(ComputerNameNetBIOS, (LPWSTR)0xdeadbeef, &size);
497     error = GetLastError();
498     ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
499     nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
500     ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
501     ret = pGetComputerNameExW(ComputerNameNetBIOS, nameW, &size);
502     ok(ret, "GetComputerNameExW(ComputerNameNetBIOS) failed with error %d\n", GetLastError());
503     HeapFree(GetProcessHeap(), 0, nameW);
504 }
505 
506 START_TEST(environ)
507 {
508     init_functionpointers();
509 
510     test_GetSetEnvironmentVariableA();
511     test_GetSetEnvironmentVariableW();
512     test_ExpandEnvironmentStringsA();
513     test_GetComputerName();
514     test_GetComputerNameExA();
515     test_GetComputerNameExW();
516 }
517 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.