From: Eric Pouech epouech@codeweavers.com
Signed-off-by: Eric Pouech epouech@codeweavers.com --- dlls/msvcrt/tests/environ.c | 95 +++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)
diff --git a/dlls/msvcrt/tests/environ.c b/dlls/msvcrt/tests/environ.c index 22f697a12ea..54f8650db80 100644 --- a/dlls/msvcrt/tests/environ.c +++ b/dlls/msvcrt/tests/environ.c @@ -136,6 +136,55 @@ static void test__environ(void) break; } } + + /* force change in _environ[], seems like native needs a first update to set allocation per entry */ + _putenv( "__fish=cat" ); + _putenv( "__fish=" ); + if ((*p_environ)[0] && (*p_environ)[1]) + { + char *first = (*p_environ)[0]; + char *second = (*p_environ)[1]; + char *new_first; + char *equal; + size_t len = strlen(first); + + new_first = malloc( len + 1 + 1 ); + ok( new_first != NULL, "allocation failed\n" ); + strcpy( new_first, first ); + strcat( new_first, "A" ); + _putenv( new_first ); + + todo_wine + ok( second == (*p_environ)[1], "_environ[1] shouldn't have changed\n" ); + ok( !strcmp( new_first, (*p_environ)[0] ), "_environ[1] shouldn't have changed\n" ); + todo_wine + ok( !strcmp( second, (*p_environ)[1] ), "_environ[1] shouldn't have changed\n" ); + + /* msvcrt _environ isn't updated after direct kernel environ API */ + equal = strchr( new_first, '=' ); + if (equal) + { + BOOL ret; + const char* new_value; + size_t new_value_len; + + *equal = '\0'; + new_first[len] = 'B'; + ret = SetEnvironmentVariableA( new_first, equal + 1 ); + ok(ret, "SetEnvironmentVariableA failed: %lu\n", GetLastError()); + new_value = getenv(new_first); + new_value_len = strlen(new_value); + ok(!strcmp(&new_value[new_value_len - 1], "A"), "_environ[] shouldn't have been updated\n"); + *equal = '='; + } + + /* reset original value */ + new_first[len] = '\0'; + _putenv( new_first ); + + free( new_first ); + } + else skip( "Not enough env variables to run this test\n" ); }
static void test__wenviron(void) @@ -232,6 +281,52 @@ static void test__wenviron(void) break; } } + + if ((*p_wenviron)[0] && (*p_wenviron)[1]) + { + WCHAR *first = (*p_wenviron)[0]; + WCHAR *second = (*p_wenviron)[1]; + WCHAR *new_first; + WCHAR *equal; + size_t len = wcslen(first); + + new_first = malloc( (len + 1 + 1) * sizeof(WCHAR) ); + ok( new_first != NULL, "allocation failed\n" ); + wcscpy( new_first, first ); + wcscat( new_first, L"A" ); + _wputenv( new_first ); + + todo_wine + ok( second == (*p_wenviron)[1], "_wenviron[1] shouldn't have changed\n" ); + ok( !wcscmp( new_first, (*p_wenviron)[0] ), "_wenviron[1] shouldn't have changed\n" ); + todo_wine + ok( !wcscmp( second, (*p_wenviron)[1] ), "_wenviron[1] shouldn't have changed\n" ); + + /* msvcrt _environ isn't updated after direct kernel environ API */ + equal = wcschr( new_first, L'=' ); + if (equal) + { + BOOL ret; + const WCHAR* new_value; + size_t new_value_len; + + *equal = L'\0'; + new_first[len] = 'B'; + ret = SetEnvironmentVariableW( new_first, equal + 1 ); + ok(ret, "SetEnvironmentVariableW failed: %lu\n", GetLastError()); + new_value = _wgetenv(new_first); + new_value_len = wcslen(new_value); + ok(!wcscmp(&new_value[new_value_len - 1], L"A"), "_wenviron[] shouldn't have been updated\n"); + *equal = L'='; + } + + /* reset original value */ + new_first[len] = L'\0'; + _wputenv( new_first ); + + free( new_first ); + } + else skip( "Not enough env variables to run this test\n" ); }
static void test_environment_manipulation(void)