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

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

Version: ~ [ 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 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  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         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 */,
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)+2 || /* win2k, XP, win2k3 */
256        ret_size == 0 /* Win95 */,
257        "ExpandEnvironmentStrings returned %d instead of %d, %d or %d\n",
258        ret_size, lstrlenA(value)+1, lstrlenA(value)+2, 0);
259 
260     /* Again, side-stepping the Win95 bug */
261     ret_size = ExpandEnvironmentStringsA(buf, buf1, 0);
262     /* v5.1.2600.2945 (XP SP2) returns len + 2 here! */
263     ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2,
264        "ExpandEnvironmentStrings returned %d instead of %d\n",
265        ret_size, lstrlenA(value)+1);
266 
267     /* Try with a buffer that's too small */
268     ret_size = ExpandEnvironmentStringsA(buf, buf1, 12);
269     /* v5.1.2600.2945 (XP SP2) returns len + 2 here! */
270     ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2,
271        "ExpandEnvironmentStrings returned %d instead of %d\n",
272        ret_size, lstrlenA(value)+1);
273 
274     /* Try with a buffer of just the right size */
275     /* v5.1.2600.2945 (XP SP2) needs and returns len + 2 here! */
276     ret_size = ExpandEnvironmentStringsA(buf, buf1, ret_size);
277     ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2,
278        "ExpandEnvironmentStrings returned %d instead of %d\n",
279        ret_size, lstrlenA(value)+1);
280     ok(!strcmp(buf1, value), "ExpandEnvironmentStrings returned [%s]\n", buf1);
281 
282     /* Try with an unset environment variable */
283     strcpy(buf, not_an_env_var);
284     ret_size = ExpandEnvironmentStringsA(buf, buf1, sizeof(buf1));
285     ok(ret_size == strlen(not_an_env_var)+1, "ExpandEnvironmentStrings returned %d instead of %d\n", ret_size, lstrlenA(value)+1);
286     ok(!strcmp(buf1, not_an_env_var), "ExpandEnvironmentStrings returned [%s]\n", buf1);
287 
288     /* test a large destination size */
289     strcpy(buf, "12345");
290     ret_size = ExpandEnvironmentStringsA(buf, buf2, sizeof(buf2));
291     ok(!strcmp(buf, buf2), "ExpandEnvironmentStrings failed %s vs %s. ret_size = %d\n", buf, buf2, ret_size);
292 
293     ret_size1 = GetWindowsDirectoryA(buf1,256);
294     ok ((ret_size1 >0) && (ret_size1<256), "GetWindowsDirectory Failed\n");
295     ret_size = ExpandEnvironmentStringsA("%SystemRoot%",buf,sizeof(buf));
296     if (ERROR_ENVVAR_NOT_FOUND != GetLastError())
297     {
298         ok(!strcmp(buf, buf1), "ExpandEnvironmentStrings failed %s vs %s. ret_size = %d\n", buf, buf1, ret_size);
299     }
300 
301     /* Try with a variable that references another */
302     SetEnvironmentVariableA("IndirectVar", "Foo%EnvVar%Bar");
303     strcpy(buf, "Indirect-%IndirectVar%-Indirect");
304     strcpy(buf2, "Indirect-Foo%EnvVar%Bar-Indirect");
305     ret_size = ExpandEnvironmentStringsA(buf, buf1, sizeof(buf1));
306     ok(ret_size == strlen(buf2)+1, "ExpandEnvironmentStrings returned %d instead of %d\n", ret_size, lstrlen(buf2)+1);
307     ok(!strcmp(buf1, buf2), "ExpandEnvironmentStrings returned [%s]\n", buf1);
308     SetEnvironmentVariableA("IndirectVar", NULL);
309 
310     SetEnvironmentVariableA("EnvVar", NULL);
311 }
312 
313 static void test_GetComputerName(void)
314 {
315     DWORD size;
316     BOOL ret;
317     LPSTR name;
318     LPWSTR nameW;
319     DWORD error;
320     int name_len;
321 
322     size = 0;
323     ret = GetComputerNameA((LPSTR)0xdeadbeef, &size);
324     error = GetLastError();
325     todo_wine
326     ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameA should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error);
327 
328     /* Only Vista returns the computer name length as documented in the MSDN */
329     if (size != 0)
330     {
331         size++; /* nul terminating character */
332         name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
333         ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
334         ret = GetComputerNameA(name, &size);
335         ok(ret, "GetComputerNameA failed with error %d\n", GetLastError());
336         HeapFree(GetProcessHeap(), 0, name);
337     }
338 
339     size = MAX_COMPUTERNAME_LENGTH + 1;
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     trace("computer name is \"%s\"\n", name);
345     name_len = strlen(name);
346     ok(size == name_len, "size should be same as length, name_len=%d, size=%d\n", name_len, size);
347     HeapFree(GetProcessHeap(), 0, name);
348 
349     size = 0;
350     SetLastError(0xdeadbeef);
351     ret = GetComputerNameW((LPWSTR)0xdeadbeef, &size);
352     error = GetLastError();
353     if (error == ERROR_CALL_NOT_IMPLEMENTED)
354         skip("GetComputerNameW is not implemented\n");
355     else
356     {
357         todo_wine
358         ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameW should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error);
359         size++; /* nul terminating character */
360         nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
361         ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
362         ret = GetComputerNameW(nameW, &size);
363         ok(ret, "GetComputerNameW failed with error %d\n", GetLastError());
364         HeapFree(GetProcessHeap(), 0, nameW);
365     }
366 }
367 
368 static void test_GetComputerNameExA(void)
369 {
370     DWORD size;
371     BOOL ret;
372     LPSTR name;
373     DWORD error;
374 
375     static const int MAX_COMP_NAME = 32767;
376 
377     if (!pGetComputerNameExA)
378     {
379         skip("GetComputerNameExA function not implemented\n");
380         return;
381     }
382 
383     size = 0;
384     ret = pGetComputerNameExA(ComputerNameDnsDomain, (LPSTR)0xdeadbeef, &size);
385     error = GetLastError();
386     ok(ret == 0, "Expected 0, got %d\n", ret);
387     ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
388 
389     /* size is not set in win2k */
390     size = MAX_COMP_NAME;
391     name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
392     ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
393     ret = pGetComputerNameExA(ComputerNameDnsDomain, name, &size);
394     ok(ret, "GetComputerNameExA(ComputerNameDnsDomain) failed with error %d\n", GetLastError());
395     trace("domain name is \"%s\"\n", name);
396     HeapFree(GetProcessHeap(), 0, name);
397 
398     size = 0;
399     ret = pGetComputerNameExA(ComputerNameDnsFullyQualified, (LPSTR)0xdeadbeef, &size);
400     error = GetLastError();
401     ok(ret == 0, "Expected 0, got %d\n", ret);
402     ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
403 
404     /* size is not set in win2k */
405     size = MAX_COMP_NAME;
406     name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
407     ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
408     ret = pGetComputerNameExA(ComputerNameDnsFullyQualified, name, &size);
409     ok(ret, "GetComputerNameExA(ComputerNameDnsFullyQualified) failed with error %d\n", GetLastError());
410     trace("fully qualified hostname is \"%s\"\n", name);
411     HeapFree(GetProcessHeap(), 0, name);
412 
413     size = 0;
414     ret = pGetComputerNameExA(ComputerNameDnsHostname, (LPSTR)0xdeadbeef, &size);
415     error = GetLastError();
416     ok(ret == 0, "Expected 0, got %d\n", ret);
417     ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
418 
419     /* size is not set in win2k */
420     size = MAX_COMP_NAME;
421     name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
422     ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
423     ret = pGetComputerNameExA(ComputerNameDnsHostname, name, &size);
424     ok(ret, "GetComputerNameExA(ComputerNameDnsHostname) failed with error %d\n", GetLastError());
425     trace("hostname is \"%s\"\n", name);
426     HeapFree(GetProcessHeap(), 0, name);
427 
428     size = 0;
429     ret = pGetComputerNameExA(ComputerNameNetBIOS, (LPSTR)0xdeadbeef, &size);
430     error = GetLastError();
431     ok(ret == 0, "Expected 0, got %d\n", ret);
432     ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
433 
434     /* size is not set in win2k */
435     size = MAX_COMP_NAME;
436     name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
437     ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
438     ret = pGetComputerNameExA(ComputerNameNetBIOS, name, &size);
439     ok(ret, "GetComputerNameExA(ComputerNameNetBIOS) failed with error %d\n", GetLastError());
440     trace("NetBIOS name is \"%s\"\n", name);
441     HeapFree(GetProcessHeap(), 0, name);
442 }
443 
444 static void test_GetComputerNameExW(void)
445 {
446     DWORD size;
447     BOOL ret;
448     LPWSTR nameW;
449     DWORD error;
450 
451     if (!pGetComputerNameExW)
452     {
453         skip("GetComputerNameExW function not implemented\n");
454         return;
455     }
456 
457     size = 0;
458     ret = pGetComputerNameExW(ComputerNameDnsDomain, (LPWSTR)0xdeadbeef, &size);
459     error = GetLastError();
460     ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
461     nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
462     ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
463     ret = pGetComputerNameExW(ComputerNameDnsDomain, nameW, &size);
464     ok(ret, "GetComputerNameExW(ComputerNameDnsDomain) failed with error %d\n", GetLastError());
465     HeapFree(GetProcessHeap(), 0, nameW);
466 
467     size = 0;
468     ret = pGetComputerNameExW(ComputerNameDnsFullyQualified, (LPWSTR)0xdeadbeef, &size);
469     error = GetLastError();
470     ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
471     nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
472     ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
473     ret = pGetComputerNameExW(ComputerNameDnsFullyQualified, nameW, &size);
474     ok(ret, "GetComputerNameExW(ComputerNameDnsFullyQualified) failed with error %d\n", GetLastError());
475     HeapFree(GetProcessHeap(), 0, nameW);
476 
477     size = 0;
478     ret = pGetComputerNameExW(ComputerNameDnsHostname, (LPWSTR)0xdeadbeef, &size);
479     error = GetLastError();
480     ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
481     nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
482     ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
483     ret = pGetComputerNameExW(ComputerNameDnsHostname, nameW, &size);
484     ok(ret, "GetComputerNameExW(ComputerNameDnsHostname) failed with error %d\n", GetLastError());
485     HeapFree(GetProcessHeap(), 0, nameW);
486 
487     size = 0;
488     ret = pGetComputerNameExW(ComputerNameNetBIOS, (LPWSTR)0xdeadbeef, &size);
489     error = GetLastError();
490     ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
491     nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
492     ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
493     ret = pGetComputerNameExW(ComputerNameNetBIOS, nameW, &size);
494     ok(ret, "GetComputerNameExW(ComputerNameNetBIOS) failed with error %d\n", GetLastError());
495     HeapFree(GetProcessHeap(), 0, nameW);
496 }
497 
498 START_TEST(environ)
499 {
500     init_functionpointers();
501 
502     test_GetSetEnvironmentVariableA();
503     test_GetSetEnvironmentVariableW();
504     test_ExpandEnvironmentStringsA();
505     test_GetComputerName();
506     test_GetComputerNameExA();
507     test_GetComputerNameExW();
508 }
509 

~ [ 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.