ReactOS 0.4.16-dev-2206-gc56950d
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
29static 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
35static BOOL (WINAPI *pGetComputerNameExA)(COMPUTER_NAME_FORMAT,LPSTR,LPDWORD);
36static BOOL (WINAPI *pGetComputerNameExW)(COMPUTER_NAME_FORMAT,LPWSTR,LPDWORD);
37static BOOL (WINAPI *pGetUserProfileDirectoryA)(HANDLE,LPSTR,LPDWORD);
38static BOOL (WINAPI *pSetEnvironmentStringsW)(WCHAR *);
39
40static void init_functionpointers(void)
41{
42 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
43 HMODULE huserenv = LoadLibraryA("userenv.dll");
44
45 pGetComputerNameExA = (void *)GetProcAddress(hkernel32, "GetComputerNameExA");
46 pGetComputerNameExW = (void *)GetProcAddress(hkernel32, "GetComputerNameExW");
47 pSetEnvironmentStringsW = (void *)GetProcAddress(hkernel32, "SetEnvironmentStringsW");
48 pGetUserProfileDirectoryA = (void *)GetProcAddress(huserenv,
49 "GetUserProfileDirectoryA");
50}
51
52static void test_Predefined(void)
53{
54 char Data[1024];
56 char Env[sizeof(Data)];
59 BOOL NoErr;
60
61 /*
62 * Check value of %USERPROFILE%, should be same as GetUserProfileDirectory()
63 * If this fails, your test environment is probably not set up
64 */
65 if (pGetUserProfileDirectoryA == NULL)
66 {
67 skip("Skipping USERPROFILE check\n");
68 return;
69 }
71 ok(NoErr, "Failed to open token, error %lu\n", GetLastError());
72 DataSize = sizeof(Data);
73 NoErr = pGetUserProfileDirectoryA(Token, Data, &DataSize);
74 ok(NoErr, "Failed to get user profile dir, error %lu\n", GetLastError());
75 if (NoErr)
76 {
77 EnvSize = GetEnvironmentVariableA("USERPROFILE", Env, sizeof(Env));
78 ok(EnvSize != 0 && EnvSize <= sizeof(Env),
79 "Failed to retrieve environment variable USERPROFILE, error %lu\n",
80 GetLastError());
81 ok(strcmp(Data, Env) == 0,
82 "USERPROFILE env var %s doesn't match GetUserProfileDirectory %s\n",
83 Env, Data);
84 }
85 else
86 skip("Skipping USERPROFILE check, can't get user profile dir\n");
87 NoErr = CloseHandle(Token);
88 ok(NoErr, "Failed to close token, error %lu\n", GetLastError());
89}
90
92{
93 char buf[256];
94 BOOL ret;
95 DWORD ret_size;
96 static const char name[] = "SomeWildName";
97 static const char name_cased[] = "sOMEwILDnAME";
98 static const char value[] = "SomeWildValue";
99
101 ok(ret == TRUE,
102 "unexpected error in SetEnvironmentVariableA, GetLastError=%ld\n",
103 GetLastError());
104
105 /* Try to retrieve the environment variable we just set */
106 SetLastError(0xdeadbeef);
107 ret_size = GetEnvironmentVariableA(name, NULL, 0);
108 ok(ret_size == strlen(value) + 1,
109 "should return length with terminating 0 ret_size=%ld\n", ret_size);
110 ok(GetLastError() == 0xdeadbeef,
111 "should not fail with zero size but GetLastError=%ld\n", GetLastError());
112
113 lstrcpyA(buf, "foo");
115 ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer\n");
116 ok(ret_size == strlen(value) + 1,
117 "should return length with terminating 0 ret_size=%ld\n", ret_size);
118
119 lstrcpyA(buf, "foo");
120 ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
121 ok(lstrcmpA(buf, value) == 0, "should touch the buffer\n");
122 ok(ret_size == strlen(value),
123 "should return length without terminating 0 ret_size=%ld\n", ret_size);
124
125 lstrcpyA(buf, "foo");
126 ret_size = GetEnvironmentVariableA(name_cased, buf, lstrlenA(value) + 1);
127 ok(lstrcmpA(buf, value) == 0, "should touch the buffer\n");
128 ok(ret_size == strlen(value),
129 "should return length without terminating 0 ret_size=%ld\n", ret_size);
130
131 /* Remove that environment variable */
132 ret = SetEnvironmentVariableA(name_cased, NULL);
133 ok(ret == TRUE, "should erase existing variable\n");
134
135 lstrcpyA(buf, "foo");
136 SetLastError(0xdeadbeef);
137 ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
138 ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer\n");
139 ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
140 "should not find variable but ret_size=%ld GetLastError=%ld\n",
141 ret_size, GetLastError());
142
143 /* Check behavior of SetEnvironmentVariableA(name, "") */
145 ok(ret == TRUE,
146 "unexpected error in SetEnvironmentVariableA, GetLastError=%ld\n",
147 GetLastError());
148
149 lstrcpyA(buf, "foo");
150 ret_size = GetEnvironmentVariableA(name_cased, buf, lstrlenA(value) + 1);
151 ok(lstrcmpA(buf, value) == 0, "should touch the buffer\n");
152 ok(ret_size == strlen(value),
153 "should return length without terminating 0 ret_size=%ld\n", ret_size);
154
155 ret = SetEnvironmentVariableA(name_cased, "");
156 ok(ret == TRUE,
157 "should not fail with empty value but GetLastError=%ld\n", GetLastError());
158
159 lstrcpyA(buf, "foo");
160 SetLastError(0xdeadbeef);
161 ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
162 ok(ret_size == 0 &&
163 ((GetLastError() == 0xdeadbeef && lstrcmpA(buf, "") == 0) ||
165 "%s should be set to \"\" (NT) or removed (Win9x) but ret_size=%ld GetLastError=%ld and buf=%s\n",
166 name, ret_size, GetLastError(), buf);
167
168 SetLastError(0xdeadbeef);
169 ret_size = GetEnvironmentVariableA(name, NULL, 0);
170 ok(ret_size == 1 ||
171 broken(ret_size == 0), /* XP */
172 "should return 1 for empty string but ret_size=%ld GetLastError=%ld\n",
173 ret_size, GetLastError());
174 ok(GetLastError() == 0xdeadbeef ||
175 broken(GetLastError() == ERROR_MORE_DATA), /* XP */
176 "should not fail with zero size but GetLastError=%ld\n", GetLastError());
177
178 /* Test the limits */
179 SetLastError(0xdeadbeef);
180 ret_size = GetEnvironmentVariableA(NULL, NULL, 0);
182 "should not find variable but ret_size=%ld GetLastError=%ld\n",
183 ret_size, GetLastError());
184
185 SetLastError(0xdeadbeef);
186 ret_size = GetEnvironmentVariableA(NULL, buf, lstrlenA(value) + 1);
188 "should not find variable but ret_size=%ld GetLastError=%ld\n",
189 ret_size, GetLastError());
190
191 SetLastError(0xdeadbeef);
192 ret_size = GetEnvironmentVariableA("", buf, lstrlenA(value) + 1);
193 ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
194 "should not find variable but ret_size=%ld GetLastError=%ld\n",
195 ret_size, GetLastError());
196}
197
199{
200 WCHAR buf[256];
201 BOOL ret;
202 DWORD ret_size;
203 static const WCHAR name[] = {'S','o','m','e','W','i','l','d','N','a','m','e',0};
204 static const WCHAR value[] = {'S','o','m','e','W','i','l','d','V','a','l','u','e',0};
205 static const WCHAR name_cased[] = {'s','O','M','E','w','I','L','D','n','A','M','E',0};
206 static const WCHAR empty_strW[] = { 0 };
207 static const WCHAR fooW[] = {'f','o','o',0};
208
211 {
212 /* Must be Win9x which doesn't support the Unicode functions */
213 win_skip("SetEnvironmentVariableW is not implemented\n");
214 return;
215 }
216 ok(ret == TRUE,
217 "unexpected error in SetEnvironmentVariableW, GetLastError=%ld\n",
218 GetLastError());
219
220 /* Try to retrieve the environment variable we just set */
221 SetLastError(0xdeadbeef);
222 ret_size = GetEnvironmentVariableW(name, NULL, 0);
223 ok(ret_size == lstrlenW(value) + 1,
224 "should return length with terminating 0 ret_size=%ld\n",
225 ret_size);
226 ok(GetLastError() == 0xdeadbeef,
227 "should not fail with zero size but GetLastError=%ld\n", GetLastError());
228
229 lstrcpyW(buf, fooW);
231 ok_w(lstrcmpW(buf, fooW) == 0 ||
232 lstrlenW(buf) == 0, /* Vista */
233 "Expected untouched or empty buffer, got \"%s\"\n", buf);
234
235 ok(ret_size == lstrlenW(value) + 1,
236 "should return length with terminating 0 ret_size=%ld\n", ret_size);
237
238 lstrcpyW(buf, fooW);
239 ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
240 ok(lstrcmpW(buf, value) == 0, "should touch the buffer\n");
241 ok(ret_size == lstrlenW(value),
242 "should return length without terminating 0 ret_size=%ld\n", ret_size);
243
244 lstrcpyW(buf, fooW);
245 ret_size = GetEnvironmentVariableW(name_cased, buf, lstrlenW(value) + 1);
246 ok(lstrcmpW(buf, value) == 0, "should touch the buffer\n");
247 ok(ret_size == lstrlenW(value),
248 "should return length without terminating 0 ret_size=%ld\n", ret_size);
249
250 /* Remove that environment variable */
251 ret = SetEnvironmentVariableW(name_cased, NULL);
252 ok(ret == TRUE, "should erase existing variable\n");
253
254 lstrcpyW(buf, fooW);
255 SetLastError(0xdeadbeef);
256 ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
257 ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer\n");
258 ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
259 "should not find variable but ret_size=%ld GetLastError=%ld\n",
260 ret_size, GetLastError());
261
262 /* Check behavior of SetEnvironmentVariableW(name, "") */
264 ok(ret == TRUE,
265 "unexpected error in SetEnvironmentVariableW, GetLastError=%ld\n",
266 GetLastError());
267
268 lstrcpyW(buf, fooW);
269 ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
270 ok(lstrcmpW(buf, value) == 0, "should touch the buffer\n");
271 ok(ret_size == lstrlenW(value),
272 "should return length without terminating 0 ret_size=%ld\n", ret_size);
273
274 ret = SetEnvironmentVariableW(name_cased, empty_strW);
275 ok(ret == TRUE, "should not fail with empty value but GetLastError=%ld\n", GetLastError());
276
277 lstrcpyW(buf, fooW);
278 SetLastError(0xdeadbeef);
279 ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
280 ok(ret_size == 0 &&
281 ((GetLastError() == 0xdeadbeef && lstrcmpW(buf, empty_strW) == 0) ||
283 "should be set to \"\" (NT) or removed (Win9x) but ret_size=%ld GetLastError=%ld\n",
284 ret_size, GetLastError());
285 ok(lstrcmpW(buf, empty_strW) == 0, "should copy an empty string\n");
286
287 SetLastError(0xdeadbeef);
288 ret_size = GetEnvironmentVariableW(name, NULL, 0);
289 ok(ret_size == 1 ||
290 broken(ret_size == 0), /* XP */
291 "should return 1 for empty string but ret_size=%ld GetLastError=%ld\n",
292 ret_size, GetLastError());
293 ok(GetLastError() == 0xdeadbeef ||
294 broken(GetLastError() == ERROR_MORE_DATA), /* XP */
295 "should not fail with zero size but GetLastError=%ld\n", GetLastError());
296
297 /* Test the limits */
298 SetLastError(0xdeadbeef);
299 ret_size = GetEnvironmentVariableW(NULL, NULL, 0);
301 "should not find variable but ret_size=%ld GetLastError=%ld\n",
302 ret_size, GetLastError());
303
304 if (0) /* Both tests crash on Vista */
305 {
306 SetLastError(0xdeadbeef);
307 ret_size = GetEnvironmentVariableW(NULL, buf, lstrlenW(value) + 1);
308 ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
309 "should not find variable but ret_size=%ld GetLastError=%ld\n",
310 ret_size, GetLastError());
311
312 SetLastError(0xdeadbeef);
315 "should fail with NULL, NULL but ret=%d and GetLastError=%ld\n",
316 ret, GetLastError());
317 }
318}
319
321{
322 static const WCHAR nameW[] = {0x540D, 0x524D, 0};
323 static const char name[] = "\x96\xBC\x91\x4F";
324 static const WCHAR valueW[] = {0x5024, 0};
325 static const char value[] = "\x92\x6C";
326 WCHAR bufW[256];
327 char buf[256];
328 DWORD ret_size;
329 BOOL ret;
330
331 if (GetACP() != 932)
332 {
333 skip("GetACP() == %d, need 932 for A/W tests\n", GetACP());
334 return;
335 }
336
337 /* Write W, read A */
339 ok(ret == TRUE, "SetEnvironmentVariableW failed, last error %ld\n", GetLastError());
340
341 SetLastError(0xdeadbeef);
342 ret_size = GetEnvironmentVariableA(name, NULL, 0);
343 todo_wine ok(ret_size == lstrlenA(value) + 1, "expected ret_size %d, got %ld\n", lstrlenA(value) + 1, ret_size);
344 ok(GetLastError() == 0xdeadbeef, "expected last error 0xdeadbeef, got %ld\n", GetLastError());
345
346 lstrcpyA(buf, "foo");
347 SetLastError(0xdeadbeef);
348 ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
349 todo_wine ok(lstrcmpA(buf, value) == 0, "expected %s, got %s\n", debugstr_a(value), debugstr_a(buf));
350 todo_wine ok(ret_size == lstrlenA(value), "expected ret_size %d, got %ld\n", lstrlenA(value), ret_size);
351 ok(GetLastError() == 0xdeadbeef, "expected last error 0xdeadbeef, got %ld\n", GetLastError());
352
353 /* Write A, read A/W */
355 ok(ret == TRUE, "SetEnvironmentVariableW failed, last error %ld\n", GetLastError());
356
357 SetLastError(0xdeadbeef);
358 ret_size = GetEnvironmentVariableA(name, NULL, 0);
359 todo_wine ok(ret_size == lstrlenA(value) + 1, "expected ret_size %d, got %ld\n", lstrlenA(value) + 1, ret_size);
360 ok(GetLastError() == 0xdeadbeef, "expected last error 0xdeadbeef, got %ld\n", GetLastError());
361
362 lstrcpyA(buf, "foo");
363 SetLastError(0xdeadbeef);
364 ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
365 todo_wine ok(lstrcmpA(buf, value) == 0, "expected %s, got %s\n", debugstr_a(value), debugstr_a(buf));
366 todo_wine ok(ret_size == lstrlenA(value), "expected ret_size %d, got %ld\n", lstrlenA(value), ret_size);
367 ok(GetLastError() == 0xdeadbeef, "expected last error 0xdeadbeef, got %ld\n", GetLastError());
368
369 SetLastError(0xdeadbeef);
370 ret_size = GetEnvironmentVariableW(nameW, NULL, 0);
371 ok(ret_size == lstrlenW(valueW) + 1, "expected ret_size %d, got %ld\n", lstrlenW(valueW) + 1, ret_size);
372 ok(GetLastError() == 0xdeadbeef, "expected last error 0xdeadbeef, got %ld\n", GetLastError());
373
374 lstrcpyW(bufW, L"foo");
375 SetLastError(0xdeadbeef);
376 ret_size = GetEnvironmentVariableW(nameW, bufW, lstrlenW(valueW) + 1);
377 ok(ret_size == lstrlenW(valueW), "expected ret_size %d, got %ld\n", lstrlenW(valueW), ret_size);
378 ok(GetLastError() == 0xdeadbeef, "expected last error 0xdeadbeef, got %ld\n", GetLastError());
379 ok(lstrcmpW(bufW, valueW) == 0, "expected %s, got %s\n", debugstr_w(valueW), debugstr_w(bufW));
380}
381
383{
384 int i;
385 WCHAR buf[256];
386 DWORD ret;
388 static const struct test_info
389 {
390 const WCHAR *input;
391 const WCHAR *expected_str;
392 int count_in;
393 int expected_count_out;
394 } tests[] =
395 {
396 /* 0 */ { L"Long long value", L"abcdefghijklmnopqrstuv", 0, 16 },
397 /* 1 */ { L"Long long value", L"abcdefghijklmnopqrstuv", 1, 16 },
398 /* 2 */ { L"Long long value", L"Lbcdefghijklmnopqrstuv", 2, 16 },
399 /* 3 */ { L"Long long value", L"Locdefghijklmnopqrstuv", 3, 16 },
400 /* 4 */ { L"Long long value", L"Long long valuopqrstuv", 15, 16 },
401 /* 5 */ { L"Long long value", L"Long long value", 16, 16 },
402 /* 6 */ { L"Long long value", L"Long long value", 17, 16 },
403 /* 7 */ { L"%TVAR% long long", L"abcdefghijklmnopqrstuv", 0, 15 },
404#ifndef __REACTOS__
405 /* 8 */ { L"%TVAR% long long", L"", 1, 15 },
406 /* 9 */ { L"%TVAR% long long", L"", 2, 15 },
407 /* 10 */ { L"%TVAR% long long", L"", 4, 15 },
408#endif
409 /* 11 */ { L"%TVAR% long long", L"WINE", 5, 15 },
410 /* 12 */ { L"%TVAR% long long", L"WINE fghijklmnopqrstuv", 6, 15 },
411 /* 13 */ { L"%TVAR% long long", L"WINE lghijklmnopqrstuv", 7, 15 },
412 /* 14 */ { L"%TVAR% long long", L"WINE long long", 15, 15 },
413 /* 15 */ { L"%TVAR% long long", L"WINE long long", 16, 15 },
414#ifndef __REACTOS__
415 /* 16 */ { L"%TVAR%%TVAR% long", L"", 4, 14 },
416#endif
417 /* 17 */ { L"%TVAR%%TVAR% long", L"WINE", 5, 14 },
418 /* 18 */ { L"%TVAR%%TVAR% long", L"WINE", 6, 14 },
419#ifndef __REACTOS__
420 /* 19 */ { L"%TVAR%%TVAR% long", L"WINE", 8, 14 },
421#endif
422 /* 20 */ { L"%TVAR%%TVAR% long", L"WINEWINE", 9, 14 },
423 /* 21 */ { L"%TVAR%%TVAR% long", L"WINEWINE jklmnopqrstuv", 10, 14 },
424 /* 22 */ { L"%TVAR%%TVAR% long", L"WINEWINE long", 14, 14 },
425 /* 23 */ { L"%TVAR%%TVAR% long", L"WINEWINE long", 15, 14 },
426 /* 24 */ { L"%TVAR% %TVAR% long", L"WINE", 5, 15 },
427#ifndef __REACTOS__
428 /* 25 */ { L"%TVAR% %TVAR% long", L"WINE ", 6, 15 },
429 /* 26 */ { L"%TVAR% %TVAR% long", L"WINE ", 8, 15 },
430 /* 27 */ { L"%TVAR% %TVAR% long", L"WINE ", 9, 15 },
431#endif
432 /* 28 */ { L"%TVAR% %TVAR% long", L"WINE WINE", 10, 15 },
433 /* 29 */ { L"%TVAR% %TVAR% long", L"WINE WINE klmnopqrstuv", 11, 15 },
434 /* 30 */ { L"%TVAR% %TVAR% long", L"WINE WINE llmnopqrstuv", 12, 15 },
435 /* 31 */ { L"%TVAR% %TVAR% long", L"WINE WINE lonnopqrstuv", 14, 15 },
436 /* 32 */ { L"%TVAR% %TVAR% long", L"WINE WINE long", 15, 15 },
437 /* 33 */ { L"%TVAR% %TVAR% long", L"WINE WINE long", 16, 15 },
438 /* 34 */ { L"%TVAR2% long long", L"abcdefghijklmnopqrstuv", 1, 18 },
439 /* 35 */ { L"%TVAR2% long long", L"%bcdefghijklmnopqrstuv", 2, 18 },
440 /* 36 */ { L"%TVAR2% long long", L"%TVdefghijklmnopqrstuv", 4, 18 },
441 /* 37 */ { L"%TVAR2% long long", L"%TVAR2ghijklmnopqrstuv", 7, 18 },
442 /* 38 */ { L"%TVAR2% long long", L"%TVAR2%hijklmnopqrstuv", 8, 18 },
443 /* 39 */ { L"%TVAR2% long long", L"%TVAR2% ijklmnopqrstuv", 9, 18 },
444 /* 40 */ { L"%TVAR2% long long", L"%TVAR2% ljklmnopqrstuv", 10, 18 },
445 /* 41 */ { L"%TVAR2% long long", L"%TVAR2% long long", 18, 18 },
446 /* 42 */ { L"%TVAR2% long long", L"%TVAR2% long long", 19, 18 },
447 /* 43 */ { L"%TVAR long long", L"abcdefghijklmnopqrstuv", 1, 16 },
448 /* 44 */ { L"%TVAR long long", L"%bcdefghijklmnopqrstuv", 2, 16 },
449 /* 45 */ { L"%TVAR long long", L"%Tcdefghijklmnopqrstuv", 3, 16 },
450 /* 46 */ { L"%TVAR long long", L"%TVAR long lonopqrstuv", 15, 16 },
451 /* 47 */ { L"%TVAR long long", L"%TVAR long long", 16, 16 },
452 /* 48 */ { L"%TVAR long long", L"%TVAR long long", 17, 16 },
453 };
454
455 success = SetEnvironmentVariableW(L"TVAR", L"WINE");
456 ok(success, "SetEnvironmentVariableW failed with %ld\n", GetLastError());
457
458 SetLastError(0xdeadbeef);
459 ret = ExpandEnvironmentStringsW(L"Long long value", NULL, 0);
460 ok(ret == 16, "got %lu\n", ret);
461 ok(GetLastError() == 0xdeadbeef, "got last error %ld\n", GetLastError());
462
463 for (i = 0; i < ARRAY_SIZE(tests); i++)
464 {
465 const struct test_info *test = &tests[i];
466
467 SetLastError(0xdeadbeef);
468 wcscpy(buf, L"abcdefghijklmnopqrstuv");
469 ret = ExpandEnvironmentStringsW(test->input, buf, test->count_in);
470 ok(ret == test->expected_count_out, "Test %d: got %lu\n", i, ret);
471 ok(GetLastError() == 0xdeadbeef, "Test %d: got last error %ld\n", i, GetLastError());
472 ok(!wcscmp(buf, test->expected_str), "Test %d: got %s\n", i, debugstr_w(buf));
473 }
474
476 ok(success, "SetEnvironmentVariableW failed with %ld\n", GetLastError());
477}
478
480{
481 const char* value="Long long value";
482 const char* not_an_env_var="%NotAnEnvVar%";
483 char buf[256], buf1[256], buf2[0x8000];
484 DWORD ret_size, ret_size1;
485 int i;
486 DWORD ret;
488 static const struct test_info
489 {
490 const char *input;
491 const char *expected_str;
492 int count_in;
493 int expected_count_out;
494 } tests[] =
495 {
496 /* 0 */ { "Long long value", "", 0, 17 },
497 /* 1 */ { "Long long value", "", 1, 17 },
498 /* 2 */ { "Long long value", "", 2, 17 },
499 /* 3 */ { "Long long value", "", 3, 17 },
500 /* 4 */ { "Long long value", "", 15, 17 },
501 /* 5 */ { "Long long value", "", 16, 17 },
502 /* 6 */ { "Long long value", "Long long value", 17, 16 },
503 /* 7 */ { "%TVAR% long long", "", 0, 16 },
504 /* 8 */ { "%TVAR% long long", "", 1, 16 },
505 /* 9 */ { "%TVAR% long long", "", 2, 16 },
506 /* 10 */ { "%TVAR% long long", "", 4, 16 },
507 /* 11 */ { "%TVAR% long long", "", 5, 16 },
508 /* 12 */ { "%TVAR% long long", "", 6, 16 },
509 /* 13 */ { "%TVAR% long long", "", 7, 16 },
510 /* 14 */ { "%TVAR% long long", "", 15, 16 },
511 /* 15 */ { "%TVAR% long long", "WINE long long", 16, 15 },
512 /* 16 */ { "%TVAR%%TVAR% long", "", 4, 15 },
513 /* 17 */ { "%TVAR%%TVAR% long", "", 5, 15 },
514 /* 18 */ { "%TVAR%%TVAR% long", "", 6, 15 },
515 /* 19 */ { "%TVAR%%TVAR% long", "", 8, 15 },
516 /* 20 */ { "%TVAR%%TVAR% long", "", 9, 15 },
517 /* 21 */ { "%TVAR%%TVAR% long", "", 10, 15 },
518 /* 22 */ { "%TVAR%%TVAR% long", "", 14, 15 },
519 /* 23 */ { "%TVAR%%TVAR% long", "WINEWINE long", 15, 14 },
520 /* 24 */ { "%TVAR% %TVAR% long", "", 5, 16 },
521 /* 25 */ { "%TVAR% %TVAR% long", "", 6, 16 },
522 /* 26 */ { "%TVAR% %TVAR% long", "", 8, 16 },
523 /* 27 */ { "%TVAR% %TVAR% long", "", 9, 16 },
524 /* 28 */ { "%TVAR% %TVAR% long", "", 10, 16 },
525 /* 29 */ { "%TVAR% %TVAR% long", "", 11, 16 },
526 /* 30 */ { "%TVAR% %TVAR% long", "", 12, 16 },
527 /* 31 */ { "%TVAR% %TVAR% long", "", 14, 16 },
528 /* 32 */ { "%TVAR% %TVAR% long", "", 15, 16 },
529 /* 33 */ { "%TVAR% %TVAR% long", "WINE WINE long", 16, 15 },
530 /* 34 */ { "%TVAR2% long long", "", 1, 19 },
531 /* 35 */ { "%TVAR2% long long", "", 2, 19 },
532 /* 36 */ { "%TVAR2% long long", "", 4, 19 },
533 /* 37 */ { "%TVAR2% long long", "", 7, 19 },
534 /* 38 */ { "%TVAR2% long long", "", 8, 19 },
535 /* 39 */ { "%TVAR2% long long", "", 9, 19 },
536 /* 40 */ { "%TVAR2% long long", "", 10, 19 },
537 /* 41 */ { "%TVAR2% long long", "", 18, 19 },
538 /* 42 */ { "%TVAR2% long long", "%TVAR2% long long", 19, 18 },
539 /* 43 */ { "%TVAR long long", "", 1, 17 },
540 /* 44 */ { "%TVAR long long", "", 2, 17 },
541 /* 45 */ { "%TVAR long long", "", 3, 17 },
542 /* 46 */ { "%TVAR long long", "", 15, 17 },
543 /* 47 */ { "%TVAR long long", "", 16, 17 },
544 /* 48 */ { "%TVAR long long", "%TVAR long long", 17, 16 },
545 };
546
548
549 ret_size = ExpandEnvironmentStringsA(NULL, buf1, sizeof(buf1));
550 ok(ret_size == 1 || ret_size == 0 /* Win9x */ || ret_size == 2 /* NT4 */,
551 "ExpandEnvironmentStrings returned %ld\n", ret_size);
552
553 /* Try to get the required buffer size 'the natural way' */
554 strcpy(buf, "%EnvVar%");
555 ret_size = ExpandEnvironmentStringsA(buf, NULL, 0);
556 ok(ret_size == strlen(value)+1 || /* win98 */
557 ret_size == (strlen(value)+1)*2 || /* NT4 */
558 ret_size == strlen(value)+2 || /* win2k, XP, win2k3 */
559 ret_size == 0 /* Win95 */,
560 "ExpandEnvironmentStrings returned %ld instead of %d, %d or %d\n",
561 ret_size, lstrlenA(value)+1, lstrlenA(value)+2, 0);
562
563 /* Again, side-stepping the Win95 bug */
564 ret_size = ExpandEnvironmentStringsA(buf, buf1, 0);
565 /* v5.1.2600.2945 (XP SP2) returns len + 2 here! */
566 ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2 ||
567 ret_size == (strlen(value)+1)*2 /* NT4 */,
568 "ExpandEnvironmentStrings returned %ld instead of %d\n",
569 ret_size, lstrlenA(value)+1);
570
571 /* Try with a buffer that's too small */
572 ret_size = ExpandEnvironmentStringsA(buf, buf1, 12);
573 /* v5.1.2600.2945 (XP SP2) returns len + 2 here! */
574 ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2 ||
575 ret_size == (strlen(value)+1)*2 /* NT4 */,
576 "ExpandEnvironmentStrings returned %ld instead of %d\n",
577 ret_size, lstrlenA(value)+1);
578
579 /* Try with a buffer of just the right size */
580 /* v5.1.2600.2945 (XP SP2) needs and returns len + 2 here! */
581 ret_size = ExpandEnvironmentStringsA(buf, buf1, ret_size);
582 ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2 ||
583 ret_size == (strlen(value)+1)*2 /* NT4 */,
584 "ExpandEnvironmentStrings returned %ld instead of %d\n",
585 ret_size, lstrlenA(value)+1);
586 ok(!strcmp(buf1, value), "ExpandEnvironmentStrings returned [%s]\n", buf1);
587
588 /* Try with an unset environment variable */
589 strcpy(buf, not_an_env_var);
590 ret_size = ExpandEnvironmentStringsA(buf, buf1, sizeof(buf1));
591 ok(ret_size == strlen(not_an_env_var)+1 ||
592 ret_size == (strlen(not_an_env_var)+1)*2 /* NT4 */,
593 "ExpandEnvironmentStrings returned %ld instead of %d\n", ret_size, lstrlenA(not_an_env_var)+1);
594 ok(!strcmp(buf1, not_an_env_var), "ExpandEnvironmentStrings returned [%s]\n", buf1);
595
596 /* test a large destination size */
597 strcpy(buf, "12345");
598 ret_size = ExpandEnvironmentStringsA(buf, buf2, sizeof(buf2));
599 ok(!strcmp(buf, buf2), "ExpandEnvironmentStrings failed %s vs %s. ret_size = %ld\n", buf, buf2, ret_size);
600
601 SetLastError(0xdeadbeef);
602 ret_size1 = GetWindowsDirectoryA(buf1,256);
603 ok ((ret_size1 >0) && (ret_size1<256), "GetWindowsDirectory Failed\n");
604 ret_size = ExpandEnvironmentStringsA("%SystemRoot%",buf,sizeof(buf));
606 {
607 ok(!strcmp(buf, buf1), "ExpandEnvironmentStrings failed %s vs %s. ret_size = %ld\n", buf, buf1, ret_size);
608 }
609
610 /* Try with a variable that references another */
611 SetEnvironmentVariableA("IndirectVar", "Foo%EnvVar%Bar");
612 strcpy(buf, "Indirect-%IndirectVar%-Indirect");
613 strcpy(buf2, "Indirect-Foo%EnvVar%Bar-Indirect");
614 ret_size = ExpandEnvironmentStringsA(buf, buf1, sizeof(buf1));
615 ok(ret_size == strlen(buf2)+1 ||
616 ret_size == (strlen(buf2)+1)*2 /* NT4 */,
617 "ExpandEnvironmentStrings returned %ld instead of %d\n", ret_size, lstrlenA(buf2)+1);
618 ok(!strcmp(buf1, buf2), "ExpandEnvironmentStrings returned [%s]\n", buf1);
619 SetEnvironmentVariableA("IndirectVar", NULL);
620
621 SetEnvironmentVariableA("EnvVar", NULL);
622
623 success = SetEnvironmentVariableA("TVAR", "WINE");
624 ok(success, "SetEnvironmentVariableA failed with %ld\n", GetLastError());
625
626 SetLastError(0xdeadbeef);
627 ret = ExpandEnvironmentStringsW(L"Long long value", NULL, 0);
628 ok(ret == 16, "got %lu\n", ret);
629 ok(GetLastError() == 0xdeadbeef, "got last error %ld\n", GetLastError());
630
631 for (i = 0; i < ARRAY_SIZE(tests); i++)
632 {
633 const struct test_info *test = &tests[i];
634
635 SetLastError(0xdeadbeef);
636 strcpy(buf, "abcdefghijklmnopqrstuv");
637 ret = ExpandEnvironmentStringsA(test->input, buf, test->count_in);
638 ok(ret == test->expected_count_out, "Test %d: got %lu\n", i, ret);
639 ok(GetLastError() == 0xdeadbeef, "Test %d: got last error %ld\n", i, GetLastError());
640 ok(!strcmp(buf, test->expected_str), "Test %d: got %s\n", i, debugstr_a(buf));
641 }
642
644 ok(success, "SetEnvironmentVariableA failed with %ld\n", GetLastError());
645
646 if (GetACP() == 932) /* shift-jis */
647 {
648 const char *japanese_test = "\x88\xEA\x93\xF1\x8E\x4F\x8E\x6C\x8C\xDC\x98\x5A\x8E\xB5\x94\xAA\x8B\xE3"; /* Japanese Kanji for "one" to "nine", in shift-jis */
649 int japanese_len = strlen(japanese_test);
650
651 SetLastError(0xdeadbeef);
652 ret_size = ExpandEnvironmentStringsA(japanese_test, NULL, 0);
653 ok(GetLastError() == 0xdeadbeef, "got last error %ld\n", GetLastError());
654 ok(ret_size >= japanese_len, "Needed at least %d, got %lu\n", japanese_len, ret_size);
655
656 SetLastError(0xdeadbeef);
657 ret_size = ExpandEnvironmentStringsA(japanese_test, buf, ret_size);
658 ok(GetLastError() == 0xdeadbeef, "got last error %ld\n", GetLastError());
659 ok(ret_size >= japanese_len, "Needed at least %d, got %lu\n", japanese_len, ret_size);
660 ok(!strcmp(buf, japanese_test), "Got %s\n", debugstr_a(buf));
661
662 SetLastError(0xdeadbeef);
663 ret_size = ExpandEnvironmentStringsA(japanese_test, buf, japanese_len / 2); /* Buffer too small */
664 ok(GetLastError() == 0xdeadbeef, "got last error %ld\n", GetLastError());
665 ok(ret_size >= japanese_len, "Needed at least %d, got %lu\n", japanese_len, ret_size);
666 }
667 else
668 {
669 skip("Skipping japanese language tests\n");
670 }
671}
672
673static void test_GetComputerName(void)
674{
675 DWORD size;
676 BOOL ret;
677 LPSTR name;
679 DWORD error;
680 int name_len;
681
682 size = 0;
683 SetLastError(0xdeadbeef);
684 ret = GetComputerNameA((LPSTR)0xdeadbeef, &size);
686 ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameA should have failed with ERROR_BUFFER_OVERFLOW instead of %ld\n", error);
687
688 /* Only Vista returns the computer name length as documented in the MSDN */
689 if (size != 0)
690 {
691 size++; /* nul terminating character */
692 name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
693 ok(name != NULL, "HeapAlloc failed with error %ld\n", GetLastError());
695 ok(ret, "GetComputerNameA failed with error %ld\n", GetLastError());
697 }
698
700 name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
701 ok(name != NULL, "HeapAlloc failed with error %ld\n", GetLastError());
703 ok(ret, "GetComputerNameA failed with error %ld\n", GetLastError());
704 trace("computer name is \"%s\"\n", name);
705 name_len = strlen(name);
706 ok(size == name_len, "size should be same as length, name_len=%d, size=%ld\n", name_len, size);
708
709 size = 0;
710 SetLastError(0xdeadbeef);
711 ret = GetComputerNameW((LPWSTR)0xdeadbeef, &size);
714 win_skip("GetComputerNameW is not implemented\n");
715 else
716 {
717 ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameW should have failed with ERROR_BUFFER_OVERFLOW instead of %ld\n", error);
718 size++; /* nul terminating character */
719 nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
720 ok(nameW != NULL, "HeapAlloc failed with error %ld\n", GetLastError());
722 ok(ret, "GetComputerNameW failed with error %ld\n", GetLastError());
724 }
725}
726
727static void test_GetComputerNameExA(void)
728{
729 DWORD size;
730 BOOL ret;
731 LPSTR name;
732 DWORD error;
733
734 static const int MAX_COMP_NAME = 32767;
735
736 if (!pGetComputerNameExA)
737 {
738 win_skip("GetComputerNameExA function not implemented\n");
739 return;
740 }
741
742 size = 0;
743 SetLastError(0xdeadbeef);
744 ret = pGetComputerNameExA(ComputerNameDnsDomain, (LPSTR)0xdeadbeef, &size);
746 ok(ret == 0, "Expected 0, got %d\n", ret);
747 ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %ld\n", error);
748
749 /* size is not set in win2k */
750 if (size == 0)
751 {
752 win_skip("Win2k doesn't set the size\n");
753 size = MAX_COMP_NAME;
754 }
755 name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
756 ok(name != NULL, "HeapAlloc failed with error %ld\n", GetLastError());
757 ret = pGetComputerNameExA(ComputerNameDnsDomain, name, &size);
758 ok(ret, "GetComputerNameExA(ComputerNameDnsDomain) failed with error %ld\n", GetLastError());
759 trace("domain name is \"%s\"\n", name);
761
762 size = 0;
763 SetLastError(0xdeadbeef);
764 ret = pGetComputerNameExA(ComputerNameDnsFullyQualified, (LPSTR)0xdeadbeef, &size);
766 ok(ret == 0, "Expected 0, got %d\n", ret);
767 ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %ld\n", error);
768
769 /* size is not set in win2k */
770 if (size == 0)
771 size = MAX_COMP_NAME;
772 name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
773 ok(name != NULL, "HeapAlloc failed with error %ld\n", GetLastError());
774 ret = pGetComputerNameExA(ComputerNameDnsFullyQualified, name, &size);
775 ok(ret, "GetComputerNameExA(ComputerNameDnsFullyQualified) failed with error %ld\n", GetLastError());
776 trace("fully qualified hostname is \"%s\"\n", name);
778
779 size = 0;
780 SetLastError(0xdeadbeef);
781 ret = pGetComputerNameExA(ComputerNameDnsHostname, (LPSTR)0xdeadbeef, &size);
783 ok(ret == 0, "Expected 0, got %d\n", ret);
784 ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %ld\n", error);
785
786 /* size is not set in win2k */
787 if (size == 0)
788 size = MAX_COMP_NAME;
789 name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
790 ok(name != NULL, "HeapAlloc failed with error %ld\n", GetLastError());
791 ret = pGetComputerNameExA(ComputerNameDnsHostname, name, &size);
792 ok(ret, "GetComputerNameExA(ComputerNameDnsHostname) failed with error %ld\n", GetLastError());
793 trace("hostname is \"%s\"\n", name);
795
796 size = 0;
797 SetLastError(0xdeadbeef);
798 ret = pGetComputerNameExA(ComputerNameNetBIOS, (LPSTR)0xdeadbeef, &size);
800 ok(ret == 0, "Expected 0, got %d\n", ret);
801 ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %ld\n", error);
802
803 size = 0;
804 SetLastError(0xdeadbeef);
805 ret = pGetComputerNameExA(ComputerNameNetBIOS, NULL, &size);
807 ok(ret == 0, "Expected 0, got %d\n", ret);
808 ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %ld\n", error);
809
810 /* size is not set in win2k */
811 if (size == 0)
812 size = MAX_COMP_NAME;
813 name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
814 ok(name != NULL, "HeapAlloc failed with error %ld\n", GetLastError());
815 ret = pGetComputerNameExA(ComputerNameNetBIOS, name, &size);
816 ok(ret, "GetComputerNameExA(ComputerNameNetBIOS) failed with error %ld\n", GetLastError());
817 trace("NetBIOS name is \"%s\"\n", name);
819}
820
821static void test_GetComputerNameExW(void)
822{
823 DWORD size;
824 BOOL ret;
826 DWORD error;
827
828 if (!pGetComputerNameExW)
829 {
830 win_skip("GetComputerNameExW function not implemented\n");
831 return;
832 }
833
834 size = 0;
835 SetLastError(0xdeadbeef);
836 ret = pGetComputerNameExW(ComputerNameDnsDomain, (LPWSTR)0xdeadbeef, &size);
838 ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %ld\n", error);
839 nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
840 ok(nameW != NULL, "HeapAlloc failed with error %ld\n", GetLastError());
841 ret = pGetComputerNameExW(ComputerNameDnsDomain, nameW, &size);
842 ok(ret, "GetComputerNameExW(ComputerNameDnsDomain) failed with error %ld\n", GetLastError());
844
845 size = 0;
846 SetLastError(0xdeadbeef);
847 ret = pGetComputerNameExW(ComputerNameDnsFullyQualified, (LPWSTR)0xdeadbeef, &size);
849 ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %ld\n", error);
850 nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
851 ok(nameW != NULL, "HeapAlloc failed with error %ld\n", GetLastError());
852 ret = pGetComputerNameExW(ComputerNameDnsFullyQualified, nameW, &size);
853 ok(ret, "GetComputerNameExW(ComputerNameDnsFullyQualified) failed with error %ld\n", GetLastError());
855
856 size = 0;
857 SetLastError(0xdeadbeef);
858 ret = pGetComputerNameExW(ComputerNameDnsHostname, (LPWSTR)0xdeadbeef, &size);
860 ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %ld\n", error);
861 nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
862 ok(nameW != NULL, "HeapAlloc failed with error %ld\n", GetLastError());
863 ret = pGetComputerNameExW(ComputerNameDnsHostname, nameW, &size);
864 ok(ret, "GetComputerNameExW(ComputerNameDnsHostname) failed with error %ld\n", GetLastError());
866
867 size = 0;
868 SetLastError(0xdeadbeef);
869 ret = pGetComputerNameExW(ComputerNameNetBIOS, (LPWSTR)0xdeadbeef, &size);
871 ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %ld\n", error);
872 nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
873 ok(nameW != NULL, "HeapAlloc failed with error %ld\n", GetLastError());
874 ret = pGetComputerNameExW(ComputerNameNetBIOS, nameW, &size);
875 ok(ret, "GetComputerNameExW(ComputerNameNetBIOS) failed with error %ld\n", GetLastError());
877
878 size = 0;
879 SetLastError(0xdeadbeef);
880 ret = pGetComputerNameExW(ComputerNameNetBIOS, NULL, &size);
882 ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %ld\n", error);
883}
884
886{
887 PWCHAR env1;
888 PWCHAR env2;
889
890 env1 = GetEnvironmentStringsW();
891 env2 = GetEnvironmentStringsW();
892 ok(env1 != env2 ||
893 broken(env1 == env2), /* NT <= 5.1 */
894 "should return different copies\n");
897}
898
899#define copy_string(dst, src) memcpy(dst, src, sizeof(src))
900
901static void check_env_var_(int line, const char *var, const char *value)
902{
903 char buffer[20];
905 if (value)
906 {
907 ok_(__FILE__, line)(size == strlen(value), "wrong size %lu\n", size);
908 ok_(__FILE__, line)(!strcmp(buffer, value), "wrong value %s\n", debugstr_a(buffer));
909 }
910 else
911 {
912 ok_(__FILE__, line)(!size, "wrong size %lu\n", size);
913 ok_(__FILE__, line)(GetLastError() == ERROR_ENVVAR_NOT_FOUND, "got error %lu\n", GetLastError());
914 }
915}
916#define check_env_var(a, b) check_env_var_(__LINE__, a, b)
917
919{
920 static const WCHAR testenv[] = L"testenv1=unus\0testenv3=tres\0";
921 WCHAR env[200];
922 WCHAR *old_env;
923 BOOL ret;
924
925 if (!pSetEnvironmentStringsW)
926 {
927 win_skip("SetEnvironmentStringsW() is not available\n");
928 return;
929 }
930
931 ret = SetEnvironmentVariableA("testenv1", "heis");
932 ok(ret, "got error %lu\n", GetLastError());
933 ret = SetEnvironmentVariableA("testenv2", "dyo");
934 ok(ret, "got error %lu\n", GetLastError());
935
936 old_env = GetEnvironmentStringsW();
937
938 memcpy(env, testenv, sizeof(testenv));
939 ret = pSetEnvironmentStringsW(env);
940 ok(ret, "got error %lu\n", GetLastError());
941 ok(!memcmp(env, testenv, sizeof(testenv)), "input parameter should not be changed\n");
942
943 check_env_var("testenv1", "unus");
944 check_env_var("testenv2", NULL);
945 check_env_var("testenv3", "tres");
946 check_env_var("PATH", NULL);
947
948 ret = pSetEnvironmentStringsW(old_env);
949 ok(ret, "got error %lu\n", GetLastError());
950
951 check_env_var("testenv1", "heis");
952 check_env_var("testenv2", "dyo");
953 check_env_var("testenv3", NULL);
954
955 SetEnvironmentVariableA("testenv1", NULL);
956 SetEnvironmentVariableA("testenv2", NULL);
957
958 copy_string(env, L"testenv\0");
959 SetLastError(0xdeadbeef);
960 ret = pSetEnvironmentStringsW(env);
961 ok(!ret, "expected failure\n");
962 ok(GetLastError() == ERROR_INVALID_PARAMETER, "got error %lu\n", GetLastError());
963
964 copy_string(env, L"=unus\0");
965 SetLastError(0xdeadbeef);
966 ret = pSetEnvironmentStringsW(env);
967 ok(!ret, "expected failure\n");
968 ok(GetLastError() == ERROR_INVALID_PARAMETER, "got error %lu\n", GetLastError());
969
970 copy_string(env, L"one=two=three four=five\0");
971 ret = pSetEnvironmentStringsW(env);
972 ok(ret, "got error %lu\n", GetLastError());
973
974 check_env_var("one", "two=three four=five");
975
976 ret = pSetEnvironmentStringsW(old_env);
977 ok(ret, "got error %lu\n", GetLastError());
978 ret = FreeEnvironmentStringsW(old_env);
979 ok(ret, "got error %lu\n", GetLastError());
980}
981
983{
985
997}
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
#define ok_(x1, x2)
Definition: atltest.h:61
static const WCHAR nameW[]
Definition: main.c:49
#define ARRAY_SIZE(A)
Definition: main.h:20
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:171
#define ERROR_MORE_DATA
Definition: dderror.h:13
static PVOID Env
Definition: dem.c:259
static ULONG EnvSize
Definition: dem.c:258
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
#define SetLastError(x)
Definition: compat.h:752
#define GetProcAddress(x, y)
Definition: compat.h:753
#define HeapAlloc
Definition: compat.h:733
#define GetCurrentProcess()
Definition: compat.h:759
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define lstrcpyW
Definition: compat.h:749
#define GetEnvironmentVariableA(x, y, z)
Definition: compat.h:754
#define lstrlenW
Definition: compat.h:750
static const WCHAR valueW[]
Definition: object.c:48
DWORD WINAPI ExpandEnvironmentStringsA(IN LPCSTR lpSrc, IN LPSTR lpDst, IN DWORD nSize)
Definition: environ.c:400
BOOL WINAPI FreeEnvironmentStringsW(IN LPWSTR EnvironmentStrings)
Definition: environ.c:390
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableW(IN LPCWSTR lpName, IN LPCWSTR lpValue)
Definition: environ.c:260
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:520
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableA(IN LPCSTR lpName, IN LPCSTR lpValue)
Definition: environ.c:219
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
UINT WINAPI GetWindowsDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2337
UINT WINAPI GetACP(void)
Definition: locale.c:2023
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4246
int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4198
LPWSTR WINAPI DECLSPEC_HOTPATCH GetEnvironmentStringsW(void)
Definition: process.c:1538
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1972
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
#define environ
Definition: stdlib.h:285
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLenum GLenum input
Definition: glext.h:9031
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_w
Definition: kernel32.h:32
LPSTR WINAPI lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:100
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define win_skip
Definition: minitest.h:67
#define todo_wine
Definition: minitest.h:80
#define error(str)
Definition: mkdosfs.c:1605
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static struct test_info tests[]
const char * var
Definition: shader.c:5666
static void test_Predefined(void)
Definition: environ.c:52
static LPSTR
Definition: environ.c:35
#define ok_w(res, format, szString)
Definition: environ.c:30
static void test_GetComputerNameExA(void)
Definition: environ.c:727
static void test_ExpandEnvironmentStringsA(void)
Definition: environ.c:479
static void check_env_var_(int line, const char *var, const char *value)
Definition: environ.c:901
#define copy_string(dst, src)
Definition: environ.c:899
#define check_env_var(a, b)
Definition: environ.c:916
static void test_GetComputerNameExW(void)
Definition: environ.c:821
static void test_GetSetEnvironmentVariableW(void)
Definition: environ.c:198
static LPWSTR
Definition: environ.c:36
static void init_functionpointers(void)
Definition: environ.c:40
static void test_GetEnvironmentStringsW(void)
Definition: environ.c:885
static void test_ExpandEnvironmentStringsW(void)
Definition: environ.c:382
static void test_GetComputerName(void)
Definition: environ.c:673
static LPDWORD
Definition: environ.c:35
static void test_GetSetEnvironmentVariableA(void)
Definition: environ.c:91
static void test_GetSetEnvironmentVariableAW(void)
Definition: environ.c:320
static void test_SetEnvironmentStrings(void)
Definition: environ.c:918
static const WCHAR fooW[]
Definition: locale.c:50
static HINSTANCE hkernel32
Definition: process.c:68
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
#define BOOL
Definition: nt_native.h:43
#define test
Definition: rosglue.h:37
wcscpy
strcpy
Definition: string.h:131
BOOL WINAPI SHIM_OBJ_NAME() GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
Definition: shimtest.c:21
Definition: parser.c:49
Definition: name.c:39
const char * name
Definition: dispmode.c:360
PVOID HANDLE
Definition: typedefs.h:73
uint16_t * PWCHAR
Definition: typedefs.h:56
Definition: pdh_main.c:96
#define success(from, fromstr, to, tostr)
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:267
#define WINAPI
Definition: msvc.h:6
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:307
#define ERROR_ENVVAR_NOT_FOUND
Definition: winerror.h:383
#define TOKEN_QUERY
Definition: setypes.h:940
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
char * LPSTR
Definition: xmlstorage.h:182
char CHAR
Definition: xmlstorage.h:175