2002-08-20 02:22:29 +02:00
|
|
|
/*
|
|
|
|
* Unit test suite for environment functions.
|
|
|
|
*
|
|
|
|
* Copyright 2002 Dmitry Timoshkov
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-08-20 02:22:29 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2002-08-20 02:22:29 +02:00
|
|
|
#include "wine/test.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-08-20 02:22:29 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
2008-08-29 04:14:11 +02:00
|
|
|
#include "winnls.h"
|
|
|
|
|
|
|
|
static CHAR string[MAX_PATH];
|
|
|
|
#define ok_w(res, format, szString) \
|
|
|
|
\
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, szString, -1, string, MAX_PATH, NULL, NULL); \
|
|
|
|
ok(res, format, string);
|
2002-08-20 02:22:29 +02:00
|
|
|
|
2008-04-16 22:36:09 +02:00
|
|
|
static BOOL (WINAPI *pGetComputerNameExA)(COMPUTER_NAME_FORMAT,LPSTR,LPDWORD);
|
|
|
|
static BOOL (WINAPI *pGetComputerNameExW)(COMPUTER_NAME_FORMAT,LPWSTR,LPDWORD);
|
|
|
|
|
|
|
|
static void init_functionpointers(void)
|
|
|
|
{
|
|
|
|
HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
|
|
|
|
|
|
|
|
pGetComputerNameExA = (void *)GetProcAddress(hkernel32, "GetComputerNameExA");
|
|
|
|
pGetComputerNameExW = (void *)GetProcAddress(hkernel32, "GetComputerNameExW");
|
|
|
|
}
|
|
|
|
|
2002-08-20 02:22:29 +02:00
|
|
|
static void test_GetSetEnvironmentVariableA(void)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
BOOL ret;
|
|
|
|
DWORD ret_size;
|
|
|
|
static const char name[] = "SomeWildName";
|
|
|
|
static const char name_cased[] = "sOMEwILDnAME";
|
|
|
|
static const char value[] = "SomeWildValue";
|
|
|
|
|
|
|
|
ret = SetEnvironmentVariableA(name, value);
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"unexpected error in SetEnvironmentVariableA, GetLastError=%d\n",
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
GetLastError());
|
2002-08-20 02:22:29 +02:00
|
|
|
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
/* Try to retrieve the environment variable we just set */
|
|
|
|
ret_size = GetEnvironmentVariableA(name, NULL, 0);
|
2002-12-18 03:22:51 +01:00
|
|
|
ok(ret_size == strlen(value) + 1,
|
2006-10-10 01:06:48 +02:00
|
|
|
"should return length with terminating 0 ret_size=%d\n", ret_size);
|
2002-08-20 02:22:29 +02:00
|
|
|
|
|
|
|
lstrcpyA(buf, "foo");
|
|
|
|
ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value));
|
2004-01-23 21:50:35 +01:00
|
|
|
ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer\n");
|
2002-12-18 03:22:51 +01:00
|
|
|
ok(ret_size == strlen(value) + 1,
|
2006-10-10 01:06:48 +02:00
|
|
|
"should return length with terminating 0 ret_size=%d\n", ret_size);
|
2002-08-20 02:22:29 +02:00
|
|
|
|
|
|
|
lstrcpyA(buf, "foo");
|
|
|
|
ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
|
2004-01-23 21:50:35 +01:00
|
|
|
ok(lstrcmpA(buf, value) == 0, "should touch the buffer\n");
|
2002-12-18 03:22:51 +01:00
|
|
|
ok(ret_size == strlen(value),
|
2006-10-10 01:06:48 +02:00
|
|
|
"should return length without terminating 0 ret_size=%d\n", ret_size);
|
2002-08-20 02:22:29 +02:00
|
|
|
|
|
|
|
lstrcpyA(buf, "foo");
|
|
|
|
ret_size = GetEnvironmentVariableA(name_cased, buf, lstrlenA(value) + 1);
|
2004-01-23 21:50:35 +01:00
|
|
|
ok(lstrcmpA(buf, value) == 0, "should touch the buffer\n");
|
2002-12-18 03:22:51 +01:00
|
|
|
ok(ret_size == strlen(value),
|
2006-10-10 01:06:48 +02:00
|
|
|
"should return length without terminating 0 ret_size=%d\n", ret_size);
|
2002-08-20 02:22:29 +02:00
|
|
|
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
/* Remove that environment variable */
|
|
|
|
ret = SetEnvironmentVariableA(name_cased, NULL);
|
2004-01-23 21:50:35 +01:00
|
|
|
ok(ret == TRUE, "should erase existing variable\n");
|
2002-08-20 02:22:29 +02:00
|
|
|
|
|
|
|
lstrcpyA(buf, "foo");
|
|
|
|
ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
|
2004-01-23 21:50:35 +01:00
|
|
|
ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer\n");
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
|
2006-10-10 01:06:48 +02:00
|
|
|
"should not find variable but ret_size=%d GetLastError=%d\n",
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ret_size, GetLastError());
|
2002-08-20 02:22:29 +02:00
|
|
|
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
/* Check behavior of SetEnvironmentVariableA(name, "") */
|
2002-08-20 02:22:29 +02:00
|
|
|
ret = SetEnvironmentVariableA(name, value);
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"unexpected error in SetEnvironmentVariableA, GetLastError=%d\n",
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
GetLastError());
|
|
|
|
|
|
|
|
lstrcpyA(buf, "foo");
|
|
|
|
ret_size = GetEnvironmentVariableA(name_cased, buf, lstrlenA(value) + 1);
|
2004-01-23 21:50:35 +01:00
|
|
|
ok(lstrcmpA(buf, value) == 0, "should touch the buffer\n");
|
2002-12-18 03:22:51 +01:00
|
|
|
ok(ret_size == strlen(value),
|
2006-10-10 01:06:48 +02:00
|
|
|
"should return length without terminating 0 ret_size=%d\n", ret_size);
|
2002-08-20 02:22:29 +02:00
|
|
|
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ret = SetEnvironmentVariableA(name_cased, "");
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"should not fail with empty value but GetLastError=%d\n", GetLastError());
|
2002-08-20 02:22:29 +02:00
|
|
|
|
|
|
|
lstrcpyA(buf, "foo");
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
SetLastError(0);
|
2002-08-20 02:22:29 +02:00
|
|
|
ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value) + 1);
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ok(ret_size == 0 &&
|
|
|
|
((GetLastError() == 0 && lstrcmpA(buf, "") == 0) ||
|
|
|
|
(GetLastError() == ERROR_ENVVAR_NOT_FOUND)),
|
2006-10-10 01:06:48 +02:00
|
|
|
"%s should be set to \"\" (NT) or removed (Win9x) but ret_size=%d GetLastError=%d and buf=%s\n",
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
name, ret_size, GetLastError(), buf);
|
|
|
|
|
|
|
|
/* Test the limits */
|
|
|
|
ret_size = GetEnvironmentVariableA(NULL, NULL, 0);
|
|
|
|
ok(ret_size == 0 && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_ENVVAR_NOT_FOUND),
|
2006-10-10 01:06:48 +02:00
|
|
|
"should not find variable but ret_size=%d GetLastError=%d\n",
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ret_size, GetLastError());
|
|
|
|
|
|
|
|
ret_size = GetEnvironmentVariableA(NULL, buf, lstrlenA(value) + 1);
|
|
|
|
ok(ret_size == 0 && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_ENVVAR_NOT_FOUND),
|
2006-10-10 01:06:48 +02:00
|
|
|
"should not find variable but ret_size=%d GetLastError=%d\n",
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ret_size, GetLastError());
|
|
|
|
|
|
|
|
ret_size = GetEnvironmentVariableA("", buf, lstrlenA(value) + 1);
|
|
|
|
ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
|
2006-10-10 01:06:48 +02:00
|
|
|
"should not find variable but ret_size=%d GetLastError=%d\n",
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ret_size, GetLastError());
|
2002-08-20 02:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_GetSetEnvironmentVariableW(void)
|
|
|
|
{
|
|
|
|
WCHAR buf[256];
|
|
|
|
BOOL ret;
|
|
|
|
DWORD ret_size;
|
|
|
|
static const WCHAR name[] = {'S','o','m','e','W','i','l','d','N','a','m','e',0};
|
|
|
|
static const WCHAR value[] = {'S','o','m','e','W','i','l','d','V','a','l','u','e',0};
|
|
|
|
static const WCHAR name_cased[] = {'s','O','M','E','w','I','L','D','n','A','M','E',0};
|
|
|
|
static const WCHAR empty_strW[] = { 0 };
|
|
|
|
static const WCHAR fooW[] = {'f','o','o',0};
|
|
|
|
|
|
|
|
ret = SetEnvironmentVariableW(name, value);
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
if (ret == FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
/* Must be Win9x which doesn't support the Unicode functions */
|
2007-03-20 17:11:54 +01:00
|
|
|
skip("SetEnvironmentVariableW is not implemented\n");
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"unexpected error in SetEnvironmentVariableW, GetLastError=%d\n",
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
GetLastError());
|
|
|
|
|
|
|
|
/* Try to retrieve the environment variable we just set */
|
|
|
|
ret_size = GetEnvironmentVariableW(name, NULL, 0);
|
|
|
|
ok(ret_size == lstrlenW(value) + 1,
|
2006-10-10 01:06:48 +02:00
|
|
|
"should return length with terminating 0 ret_size=%d\n",
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ret_size);
|
2002-08-20 02:22:29 +02:00
|
|
|
|
|
|
|
lstrcpyW(buf, fooW);
|
|
|
|
ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value));
|
2008-09-02 07:56:03 +02:00
|
|
|
ok_w(lstrcmpW(buf, fooW) == 0 ||
|
|
|
|
lstrlenW(buf) == 0, /* Vista */
|
|
|
|
"Expected untouched or empty buffer, got \"%s\"\n", buf);
|
2003-06-18 05:24:20 +02:00
|
|
|
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ok(ret_size == lstrlenW(value) + 1,
|
2006-10-10 01:06:48 +02:00
|
|
|
"should return length with terminating 0 ret_size=%d\n", ret_size);
|
2002-08-20 02:22:29 +02:00
|
|
|
|
|
|
|
lstrcpyW(buf, fooW);
|
|
|
|
ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
|
2004-01-23 21:50:35 +01:00
|
|
|
ok(lstrcmpW(buf, value) == 0, "should touch the buffer\n");
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ok(ret_size == lstrlenW(value),
|
2006-10-10 01:06:48 +02:00
|
|
|
"should return length without terminating 0 ret_size=%d\n", ret_size);
|
2002-08-20 02:22:29 +02:00
|
|
|
|
|
|
|
lstrcpyW(buf, fooW);
|
|
|
|
ret_size = GetEnvironmentVariableW(name_cased, buf, lstrlenW(value) + 1);
|
2004-01-23 21:50:35 +01:00
|
|
|
ok(lstrcmpW(buf, value) == 0, "should touch the buffer\n");
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ok(ret_size == lstrlenW(value),
|
2006-10-10 01:06:48 +02:00
|
|
|
"should return length without terminating 0 ret_size=%d\n", ret_size);
|
2002-08-20 02:22:29 +02:00
|
|
|
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
/* Remove that environment variable */
|
|
|
|
ret = SetEnvironmentVariableW(name_cased, NULL);
|
2004-01-23 21:50:35 +01:00
|
|
|
ok(ret == TRUE, "should erase existing variable\n");
|
2002-08-20 02:22:29 +02:00
|
|
|
|
|
|
|
lstrcpyW(buf, fooW);
|
|
|
|
ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
|
2004-01-23 21:50:35 +01:00
|
|
|
ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer\n");
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
|
2006-10-10 01:06:48 +02:00
|
|
|
"should not find variable but ret_size=%d GetLastError=%d\n",
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ret_size, GetLastError());
|
2002-08-20 02:22:29 +02:00
|
|
|
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
/* Check behavior of SetEnvironmentVariableW(name, "") */
|
2002-08-20 02:22:29 +02:00
|
|
|
ret = SetEnvironmentVariableW(name, value);
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"unexpected error in SetEnvironmentVariableW, GetLastError=%d\n",
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
GetLastError());
|
|
|
|
|
|
|
|
lstrcpyW(buf, fooW);
|
|
|
|
ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
|
2004-01-23 21:50:35 +01:00
|
|
|
ok(lstrcmpW(buf, value) == 0, "should touch the buffer\n");
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ok(ret_size == lstrlenW(value),
|
2006-10-10 01:06:48 +02:00
|
|
|
"should return length without terminating 0 ret_size=%d\n", ret_size);
|
2002-08-20 02:22:29 +02:00
|
|
|
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ret = SetEnvironmentVariableW(name_cased, empty_strW);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(ret == TRUE, "should not fail with empty value but GetLastError=%d\n", GetLastError());
|
2002-08-20 02:22:29 +02:00
|
|
|
|
|
|
|
lstrcpyW(buf, fooW);
|
|
|
|
ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value) + 1);
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
|
2006-10-10 01:06:48 +02:00
|
|
|
"should not find variable but ret_size=%d GetLastError=%d\n",
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ret_size, GetLastError());
|
2004-01-23 21:50:35 +01:00
|
|
|
ok(lstrcmpW(buf, empty_strW) == 0, "should copy an empty string\n");
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
|
|
|
|
/* Test the limits */
|
|
|
|
ret_size = GetEnvironmentVariableW(NULL, NULL, 0);
|
|
|
|
ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
|
2006-10-10 01:06:48 +02:00
|
|
|
"should not find variable but ret_size=%d GetLastError=%d\n",
|
SetEnvironmentVariableA(NULL, NULL) crashes on Win98 -> removed.
SetEnvironmentVariableA("", value) crashes on NT4 -> removed.
The behavior of SetEnvironmentVariableA("", "") varies to much ->
removed.
Test the behavior of SetEnvironmentVariable{A,W}(name, "") taking into
account the differences between Win9x and NT.
Test the behavior of GetEnvironmentVariable{A,W}(name, buf, 0).
Fix the error code checks to take into account the differences between
Win9x, NT4 and XP.
Skip the unicode tests if the first call returns
ERROR_CALL_NOT_IMPLEMENTED.
Whenever a test fails, print sufficient information (typically return
code and GetLastError()!) to let the developer figure out what is
wrong.
2002-11-30 20:02:22 +01:00
|
|
|
ret_size, GetLastError());
|
|
|
|
|
2007-06-23 16:40:58 +02:00
|
|
|
if (0) /* Both tests crash on Vista */
|
|
|
|
{
|
|
|
|
ret_size = GetEnvironmentVariableW(NULL, buf, lstrlenW(value) + 1);
|
|
|
|
ok(ret_size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND,
|
|
|
|
"should not find variable but ret_size=%d GetLastError=%d\n",
|
|
|
|
ret_size, GetLastError());
|
|
|
|
|
|
|
|
ret = SetEnvironmentVariableW(NULL, NULL);
|
|
|
|
ok(ret == FALSE && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_ENVVAR_NOT_FOUND),
|
|
|
|
"should fail with NULL, NULL but ret=%d and GetLastError=%d\n",
|
|
|
|
ret, GetLastError());
|
|
|
|
}
|
2002-08-20 02:22:29 +02:00
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_ExpandEnvironmentStringsA(void)
|
2005-03-10 18:15:39 +01:00
|
|
|
{
|
2008-01-11 09:52:16 +01:00
|
|
|
const char* value="Long long value";
|
|
|
|
const char* not_an_env_var="%NotAnEnvVar%";
|
2006-08-19 19:27:01 +02:00
|
|
|
char buf[256], buf1[256], buf2[0x8000];
|
2005-03-10 18:15:39 +01:00
|
|
|
DWORD ret_size, ret_size1;
|
|
|
|
|
2008-01-11 09:52:16 +01:00
|
|
|
SetEnvironmentVariableA("EnvVar", value);
|
|
|
|
|
|
|
|
ret_size = ExpandEnvironmentStringsA(NULL, buf1, sizeof(buf1));
|
|
|
|
ok(ret_size == 1 || ret_size == 0 /* Win9x */,
|
|
|
|
"ExpandEnvironmentStrings returned %d\n", ret_size);
|
|
|
|
|
|
|
|
/* Try to get the required buffer size 'the natural way' */
|
|
|
|
strcpy(buf, "%EnvVar%");
|
|
|
|
ret_size = ExpandEnvironmentStringsA(buf, NULL, 0);
|
2008-04-16 22:38:46 +02:00
|
|
|
ok(ret_size == strlen(value)+1 || /* win98 */
|
|
|
|
ret_size == strlen(value)+2 || /* win2k, XP, win2k3 */
|
|
|
|
ret_size == 0 /* Win95 */,
|
|
|
|
"ExpandEnvironmentStrings returned %d instead of %d, %d or %d\n",
|
|
|
|
ret_size, lstrlenA(value)+1, lstrlenA(value)+2, 0);
|
2008-01-11 09:52:16 +01:00
|
|
|
|
|
|
|
/* Again, side-stepping the Win95 bug */
|
|
|
|
ret_size = ExpandEnvironmentStringsA(buf, buf1, 0);
|
|
|
|
/* v5.1.2600.2945 (XP SP2) returns len + 2 here! */
|
|
|
|
ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2,
|
|
|
|
"ExpandEnvironmentStrings returned %d instead of %d\n",
|
2008-01-15 17:08:09 +01:00
|
|
|
ret_size, lstrlenA(value)+1);
|
2008-01-11 09:52:16 +01:00
|
|
|
|
|
|
|
/* Try with a buffer that's too small */
|
|
|
|
ret_size = ExpandEnvironmentStringsA(buf, buf1, 12);
|
|
|
|
/* v5.1.2600.2945 (XP SP2) returns len + 2 here! */
|
|
|
|
ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2,
|
|
|
|
"ExpandEnvironmentStrings returned %d instead of %d\n",
|
2008-01-15 17:08:09 +01:00
|
|
|
ret_size, lstrlenA(value)+1);
|
2008-01-11 09:52:16 +01:00
|
|
|
|
|
|
|
/* Try with a buffer of just the right size */
|
|
|
|
/* v5.1.2600.2945 (XP SP2) needs and returns len + 2 here! */
|
|
|
|
ret_size = ExpandEnvironmentStringsA(buf, buf1, ret_size);
|
|
|
|
ok(ret_size == strlen(value)+1 || ret_size == strlen(value)+2,
|
|
|
|
"ExpandEnvironmentStrings returned %d instead of %d\n",
|
2008-01-15 17:08:09 +01:00
|
|
|
ret_size, lstrlenA(value)+1);
|
2008-01-11 09:52:16 +01:00
|
|
|
ok(!strcmp(buf1, value), "ExpandEnvironmentStrings returned [%s]\n", buf1);
|
|
|
|
|
|
|
|
/* Try with an unset environment variable */
|
|
|
|
strcpy(buf, not_an_env_var);
|
|
|
|
ret_size = ExpandEnvironmentStringsA(buf, buf1, sizeof(buf1));
|
2008-01-15 17:08:09 +01:00
|
|
|
ok(ret_size == strlen(not_an_env_var)+1, "ExpandEnvironmentStrings returned %d instead of %d\n", ret_size, lstrlenA(value)+1);
|
2008-01-11 09:52:16 +01:00
|
|
|
ok(!strcmp(buf1, not_an_env_var), "ExpandEnvironmentStrings returned [%s]\n", buf1);
|
|
|
|
|
2006-08-19 19:27:01 +02:00
|
|
|
/* test a large destination size */
|
|
|
|
strcpy(buf, "12345");
|
|
|
|
ret_size = ExpandEnvironmentStringsA(buf, buf2, sizeof(buf2));
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(!strcmp(buf, buf2), "ExpandEnvironmentStrings failed %s vs %s. ret_size = %d\n", buf, buf2, ret_size);
|
2006-08-19 19:27:01 +02:00
|
|
|
|
2005-03-10 18:15:39 +01:00
|
|
|
ret_size1 = GetWindowsDirectoryA(buf1,256);
|
|
|
|
ok ((ret_size1 >0) && (ret_size1<256), "GetWindowsDirectory Failed\n");
|
2005-03-15 20:33:32 +01:00
|
|
|
ret_size = ExpandEnvironmentStringsA("%SystemRoot%",buf,sizeof(buf));
|
2008-01-23 15:16:53 +01:00
|
|
|
if (ERROR_ENVVAR_NOT_FOUND != GetLastError())
|
|
|
|
{
|
|
|
|
ok(!strcmp(buf, buf1), "ExpandEnvironmentStrings failed %s vs %s. ret_size = %d\n", buf, buf1, ret_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try with a variable that references another */
|
|
|
|
SetEnvironmentVariableA("IndirectVar", "Foo%EnvVar%Bar");
|
|
|
|
strcpy(buf, "Indirect-%IndirectVar%-Indirect");
|
|
|
|
strcpy(buf2, "Indirect-Foo%EnvVar%Bar-Indirect");
|
|
|
|
ret_size = ExpandEnvironmentStringsA(buf, buf1, sizeof(buf1));
|
2008-01-24 14:03:10 +01:00
|
|
|
ok(ret_size == strlen(buf2)+1, "ExpandEnvironmentStrings returned %d instead of %d\n", ret_size, lstrlen(buf2)+1);
|
2008-01-23 15:16:53 +01:00
|
|
|
ok(!strcmp(buf1, buf2), "ExpandEnvironmentStrings returned [%s]\n", buf1);
|
|
|
|
SetEnvironmentVariableA("IndirectVar", NULL);
|
2008-01-11 09:52:16 +01:00
|
|
|
|
|
|
|
SetEnvironmentVariableA("EnvVar", NULL);
|
2005-03-10 18:15:39 +01:00
|
|
|
}
|
|
|
|
|
2007-02-16 00:22:18 +01:00
|
|
|
static void test_GetComputerName(void)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
BOOL ret;
|
|
|
|
LPSTR name;
|
|
|
|
LPWSTR nameW;
|
|
|
|
DWORD error;
|
2007-03-03 04:03:53 +01:00
|
|
|
int name_len;
|
2007-02-16 00:22:18 +01:00
|
|
|
|
|
|
|
size = 0;
|
|
|
|
ret = GetComputerNameA((LPSTR)0xdeadbeef, &size);
|
|
|
|
error = GetLastError();
|
2007-03-16 02:39:11 +01:00
|
|
|
todo_wine
|
|
|
|
ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameA should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error);
|
2008-01-11 09:52:31 +01:00
|
|
|
|
|
|
|
/* Only Vista returns the computer name length as documented in the MSDN */
|
|
|
|
if (size != 0)
|
|
|
|
{
|
|
|
|
size++; /* nul terminating character */
|
|
|
|
name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
|
|
|
|
ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
|
|
|
|
ret = GetComputerNameA(name, &size);
|
|
|
|
ok(ret, "GetComputerNameA failed with error %d\n", GetLastError());
|
|
|
|
HeapFree(GetProcessHeap(), 0, name);
|
|
|
|
}
|
2007-02-16 00:22:18 +01:00
|
|
|
|
2007-03-03 04:03:53 +01:00
|
|
|
size = MAX_COMPUTERNAME_LENGTH + 1;
|
|
|
|
name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
|
|
|
|
ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
|
|
|
|
ret = GetComputerNameA(name, &size);
|
|
|
|
ok(ret, "GetComputerNameA failed with error %d\n", GetLastError());
|
|
|
|
trace("computer name is \"%s\"\n", name);
|
|
|
|
name_len = strlen(name);
|
|
|
|
ok(size == name_len, "size should be same as length, name_len=%d, size=%d\n", name_len, size);
|
|
|
|
HeapFree(GetProcessHeap(), 0, name);
|
|
|
|
|
2007-02-16 00:22:18 +01:00
|
|
|
size = 0;
|
2007-04-25 13:16:37 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2007-02-16 00:22:18 +01:00
|
|
|
ret = GetComputerNameW((LPWSTR)0xdeadbeef, &size);
|
|
|
|
error = GetLastError();
|
2007-04-25 13:16:37 +02:00
|
|
|
if (error == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
skip("GetComputerNameW is not implemented\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
todo_wine
|
|
|
|
ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameW should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error);
|
|
|
|
size++; /* nul terminating character */
|
|
|
|
nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
|
|
|
|
ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
|
|
|
|
ret = GetComputerNameW(nameW, &size);
|
|
|
|
ok(ret, "GetComputerNameW failed with error %d\n", GetLastError());
|
|
|
|
HeapFree(GetProcessHeap(), 0, nameW);
|
|
|
|
}
|
2008-04-16 22:36:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_GetComputerNameExA(void)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
BOOL ret;
|
|
|
|
LPSTR name;
|
|
|
|
DWORD error;
|
2007-02-16 00:22:18 +01:00
|
|
|
|
2008-04-16 22:37:09 +02:00
|
|
|
static const int MAX_COMP_NAME = 32767;
|
|
|
|
|
2007-02-16 00:22:18 +01:00
|
|
|
if (!pGetComputerNameExA)
|
|
|
|
{
|
2008-04-16 22:36:09 +02:00
|
|
|
skip("GetComputerNameExA function not implemented\n");
|
2007-02-16 00:22:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
ret = pGetComputerNameExA(ComputerNameDnsDomain, (LPSTR)0xdeadbeef, &size);
|
|
|
|
error = GetLastError();
|
2008-04-16 22:37:09 +02:00
|
|
|
ok(ret == 0, "Expected 0, got %d\n", ret);
|
|
|
|
ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
|
|
|
|
|
|
|
|
/* size is not set in win2k */
|
|
|
|
size = MAX_COMP_NAME;
|
2007-02-16 00:22:18 +01:00
|
|
|
name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
|
|
|
|
ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
|
|
|
|
ret = pGetComputerNameExA(ComputerNameDnsDomain, name, &size);
|
|
|
|
ok(ret, "GetComputerNameExA(ComputerNameDnsDomain) failed with error %d\n", GetLastError());
|
|
|
|
trace("domain name is \"%s\"\n", name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, name);
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
ret = pGetComputerNameExA(ComputerNameDnsFullyQualified, (LPSTR)0xdeadbeef, &size);
|
|
|
|
error = GetLastError();
|
2008-04-16 22:37:09 +02:00
|
|
|
ok(ret == 0, "Expected 0, got %d\n", ret);
|
|
|
|
ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
|
|
|
|
|
|
|
|
/* size is not set in win2k */
|
|
|
|
size = MAX_COMP_NAME;
|
2007-02-16 00:22:18 +01:00
|
|
|
name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
|
|
|
|
ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
|
|
|
|
ret = pGetComputerNameExA(ComputerNameDnsFullyQualified, name, &size);
|
|
|
|
ok(ret, "GetComputerNameExA(ComputerNameDnsFullyQualified) failed with error %d\n", GetLastError());
|
|
|
|
trace("fully qualified hostname is \"%s\"\n", name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, name);
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
ret = pGetComputerNameExA(ComputerNameDnsHostname, (LPSTR)0xdeadbeef, &size);
|
|
|
|
error = GetLastError();
|
2008-04-16 22:37:09 +02:00
|
|
|
ok(ret == 0, "Expected 0, got %d\n", ret);
|
|
|
|
ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
|
|
|
|
|
|
|
|
/* size is not set in win2k */
|
|
|
|
size = MAX_COMP_NAME;
|
2007-02-16 00:22:18 +01:00
|
|
|
name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
|
|
|
|
ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
|
|
|
|
ret = pGetComputerNameExA(ComputerNameDnsHostname, name, &size);
|
|
|
|
ok(ret, "GetComputerNameExA(ComputerNameDnsHostname) failed with error %d\n", GetLastError());
|
|
|
|
trace("hostname is \"%s\"\n", name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, name);
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
ret = pGetComputerNameExA(ComputerNameNetBIOS, (LPSTR)0xdeadbeef, &size);
|
|
|
|
error = GetLastError();
|
2008-04-16 22:37:09 +02:00
|
|
|
ok(ret == 0, "Expected 0, got %d\n", ret);
|
|
|
|
ok(error == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", error);
|
|
|
|
|
|
|
|
/* size is not set in win2k */
|
|
|
|
size = MAX_COMP_NAME;
|
2007-02-16 00:22:18 +01:00
|
|
|
name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
|
|
|
|
ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
|
|
|
|
ret = pGetComputerNameExA(ComputerNameNetBIOS, name, &size);
|
|
|
|
ok(ret, "GetComputerNameExA(ComputerNameNetBIOS) failed with error %d\n", GetLastError());
|
|
|
|
trace("NetBIOS name is \"%s\"\n", name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, name);
|
2008-04-16 22:36:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_GetComputerNameExW(void)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
BOOL ret;
|
|
|
|
LPWSTR nameW;
|
|
|
|
DWORD error;
|
2007-02-16 00:22:18 +01:00
|
|
|
|
|
|
|
if (!pGetComputerNameExW)
|
|
|
|
{
|
2008-04-16 22:36:09 +02:00
|
|
|
skip("GetComputerNameExW function not implemented\n");
|
2007-02-16 00:22:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
ret = pGetComputerNameExW(ComputerNameDnsDomain, (LPWSTR)0xdeadbeef, &size);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
|
|
|
|
nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
|
|
|
|
ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
|
|
|
|
ret = pGetComputerNameExW(ComputerNameDnsDomain, nameW, &size);
|
|
|
|
ok(ret, "GetComputerNameExW(ComputerNameDnsDomain) failed with error %d\n", GetLastError());
|
|
|
|
HeapFree(GetProcessHeap(), 0, nameW);
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
ret = pGetComputerNameExW(ComputerNameDnsFullyQualified, (LPWSTR)0xdeadbeef, &size);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
|
|
|
|
nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
|
|
|
|
ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
|
|
|
|
ret = pGetComputerNameExW(ComputerNameDnsFullyQualified, nameW, &size);
|
|
|
|
ok(ret, "GetComputerNameExW(ComputerNameDnsFullyQualified) failed with error %d\n", GetLastError());
|
|
|
|
HeapFree(GetProcessHeap(), 0, nameW);
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
ret = pGetComputerNameExW(ComputerNameDnsHostname, (LPWSTR)0xdeadbeef, &size);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
|
|
|
|
nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
|
|
|
|
ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
|
|
|
|
ret = pGetComputerNameExW(ComputerNameDnsHostname, nameW, &size);
|
|
|
|
ok(ret, "GetComputerNameExW(ComputerNameDnsHostname) failed with error %d\n", GetLastError());
|
|
|
|
HeapFree(GetProcessHeap(), 0, nameW);
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
ret = pGetComputerNameExW(ComputerNameNetBIOS, (LPWSTR)0xdeadbeef, &size);
|
|
|
|
error = GetLastError();
|
|
|
|
ok(!ret && error == ERROR_MORE_DATA, "GetComputerNameExW should have failed with ERROR_MORE_DATA instead of %d\n", error);
|
|
|
|
nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
|
|
|
|
ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
|
|
|
|
ret = pGetComputerNameExW(ComputerNameNetBIOS, nameW, &size);
|
|
|
|
ok(ret, "GetComputerNameExW(ComputerNameNetBIOS) failed with error %d\n", GetLastError());
|
|
|
|
HeapFree(GetProcessHeap(), 0, nameW);
|
|
|
|
}
|
|
|
|
|
2002-08-20 02:22:29 +02:00
|
|
|
START_TEST(environ)
|
|
|
|
{
|
2008-04-16 22:36:09 +02:00
|
|
|
init_functionpointers();
|
|
|
|
|
2002-08-20 02:22:29 +02:00
|
|
|
test_GetSetEnvironmentVariableA();
|
|
|
|
test_GetSetEnvironmentVariableW();
|
2005-03-10 18:15:39 +01:00
|
|
|
test_ExpandEnvironmentStringsA();
|
2007-02-16 00:22:18 +01:00
|
|
|
test_GetComputerName();
|
2008-04-16 22:36:09 +02:00
|
|
|
test_GetComputerNameExA();
|
|
|
|
test_GetComputerNameExW();
|
2002-08-20 02:22:29 +02:00
|
|
|
}
|