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"
|
|
|
|
|
|
|
|
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 */
|
|
|
|
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));
|
2004-01-23 21:50:35 +01:00
|
|
|
ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer\n");
|
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());
|
|
|
|
|
|
|
|
ret_size = GetEnvironmentVariableW(NULL, buf, lstrlenW(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());
|
|
|
|
|
|
|
|
ret = SetEnvironmentVariableW(NULL, NULL);
|
|
|
|
ok(ret == FALSE && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_ENVVAR_NOT_FOUND),
|
2006-10-10 01:06:48 +02:00
|
|
|
"should fail with NULL, NULL but ret=%d and 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, 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
|
|
|
{
|
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;
|
|
|
|
|
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));
|
2005-03-22 19:17:07 +01:00
|
|
|
if (ERROR_ENVVAR_NOT_FOUND == GetLastError())
|
|
|
|
return;
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(!strcmp(buf, buf1), "ExpandEnvironmentStrings failed %s vs %s. ret_size = %d\n", buf, buf1, ret_size);
|
2005-03-10 18:15:39 +01:00
|
|
|
}
|
|
|
|
|
2002-08-20 02:22:29 +02:00
|
|
|
START_TEST(environ)
|
|
|
|
{
|
|
|
|
test_GetSetEnvironmentVariableA();
|
|
|
|
test_GetSetEnvironmentVariableW();
|
2005-03-10 18:15:39 +01:00
|
|
|
test_ExpandEnvironmentStringsA();
|
2002-08-20 02:22:29 +02:00
|
|
|
}
|