2008-04-30 03:09:24 +02:00
|
|
|
/*
|
|
|
|
* Unit test suite for userenv functions
|
|
|
|
*
|
|
|
|
* Copyright 2008 Google (Lei Zhang)
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2008-05-01 02:38:05 +02:00
|
|
|
#include <stdio.h>
|
2008-04-30 03:09:24 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2008-05-01 02:38:05 +02:00
|
|
|
#include "winnls.h"
|
2008-04-30 03:09:24 +02:00
|
|
|
|
|
|
|
#include "userenv.h"
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
|
|
|
#define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
|
2008-05-01 02:38:05 +02:00
|
|
|
#define expect_env(EXPECTED,GOT,VAR) ok((GOT)==(EXPECTED), "Expected %d, got %d for %s (%d)\n", (EXPECTED), (GOT), (VAR), j)
|
|
|
|
|
|
|
|
struct profile_item
|
|
|
|
{
|
|
|
|
const char * name;
|
|
|
|
const int todo[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Helper function for retrieving environment variables */
|
|
|
|
static BOOL get_env(const WCHAR * env, const char * var, char ** result)
|
|
|
|
{
|
|
|
|
const WCHAR * p = env;
|
|
|
|
int envlen, varlen, buflen;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
if (!env || !var || !result) return FALSE;
|
|
|
|
|
|
|
|
varlen = strlen(var);
|
|
|
|
do
|
|
|
|
{
|
2009-08-19 19:50:06 +02:00
|
|
|
if (!WideCharToMultiByte( CP_ACP, 0, p, -1, buf, sizeof(buf), NULL, NULL )) buf[sizeof(buf)-1] = 0;
|
|
|
|
envlen = strlen(buf);
|
2008-06-04 00:04:00 +02:00
|
|
|
if (CompareStringA(GetThreadLocale(), NORM_IGNORECASE|LOCALE_USE_CP_ACP, buf, min(envlen, varlen), var, varlen) == CSTR_EQUAL)
|
2008-05-01 02:38:05 +02:00
|
|
|
{
|
|
|
|
if (buf[varlen] == '=')
|
|
|
|
{
|
|
|
|
buflen = strlen(buf);
|
|
|
|
*result = HeapAlloc(GetProcessHeap(), 0, buflen + 1);
|
|
|
|
if (!*result) return FALSE;
|
|
|
|
memcpy(*result, buf, buflen + 1);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2009-08-19 19:50:06 +02:00
|
|
|
while (*p) p++;
|
|
|
|
p++;
|
2008-05-01 02:38:05 +02:00
|
|
|
} while (*p);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-04-30 03:09:24 +02:00
|
|
|
|
|
|
|
static void test_create_env(void)
|
|
|
|
{
|
|
|
|
BOOL r;
|
|
|
|
HANDLE htok;
|
2008-10-21 21:54:01 +02:00
|
|
|
WCHAR * env[4];
|
2008-05-01 02:38:05 +02:00
|
|
|
char * st;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
static const struct profile_item common_vars[] = {
|
|
|
|
{ "ComSpec", { 1, 1, 0, 0 } },
|
|
|
|
{ "COMPUTERNAME", { 1, 1, 1, 1 } },
|
|
|
|
{ "NUMBER_OF_PROCESSORS", { 1, 1, 0, 0 } },
|
|
|
|
{ "OS", { 1, 1, 0, 0 } },
|
|
|
|
{ "PROCESSOR_ARCHITECTURE", { 1, 1, 0, 0 } },
|
|
|
|
{ "PROCESSOR_IDENTIFIER", { 1, 1, 0, 0 } },
|
|
|
|
{ "PROCESSOR_LEVEL", { 1, 1, 0, 0 } },
|
|
|
|
{ "PROCESSOR_REVISION", { 1, 1, 0, 0 } },
|
|
|
|
{ "SystemDrive", { 1, 1, 0, 0 } },
|
|
|
|
{ "SystemRoot", { 1, 1, 0, 0 } },
|
2008-10-21 22:06:33 +02:00
|
|
|
{ "windir", { 1, 1, 0, 0 } }
|
|
|
|
};
|
|
|
|
static const struct profile_item common_post_nt4_vars[] = {
|
|
|
|
{ "ALLUSERSPROFILE", { 1, 1, 0, 0 } },
|
2009-01-25 17:30:01 +01:00
|
|
|
{ "TEMP", { 1, 1, 0, 0 } },
|
|
|
|
{ "TMP", { 1, 1, 0, 0 } },
|
2008-10-21 22:06:33 +02:00
|
|
|
{ "CommonProgramFiles", { 1, 1, 1, 1 } },
|
2008-10-21 21:54:01 +02:00
|
|
|
{ "ProgramFiles", { 1, 1, 0, 0 } }
|
2008-05-01 02:38:05 +02:00
|
|
|
};
|
2008-05-01 02:39:07 +02:00
|
|
|
static const struct profile_item htok_vars[] = {
|
|
|
|
{ "PATH", { 1, 1, 0, 0 } },
|
2008-10-21 21:54:01 +02:00
|
|
|
{ "USERPROFILE", { 1, 1, 0, 0 } }
|
2008-05-01 02:39:07 +02:00
|
|
|
};
|
2008-04-30 03:09:24 +02:00
|
|
|
|
2008-05-01 02:45:21 +02:00
|
|
|
r = SetEnvironmentVariableA("WINE_XYZZY", "ZZYZX");
|
|
|
|
expect(TRUE, r);
|
|
|
|
|
2008-09-21 20:59:46 +02:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* Crashes on NT4 */
|
|
|
|
r = CreateEnvironmentBlock(NULL, NULL, FALSE);
|
|
|
|
expect(FALSE, r);
|
|
|
|
}
|
2008-04-30 03:09:24 +02:00
|
|
|
|
|
|
|
r = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY|TOKEN_DUPLICATE, &htok);
|
|
|
|
expect(TRUE, r);
|
|
|
|
|
2008-09-21 20:59:46 +02:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* Crashes on NT4 */
|
|
|
|
r = CreateEnvironmentBlock(NULL, htok, FALSE);
|
|
|
|
expect(FALSE, r);
|
|
|
|
}
|
2008-04-30 03:09:24 +02:00
|
|
|
|
2008-10-21 21:54:01 +02:00
|
|
|
r = CreateEnvironmentBlock((LPVOID) &env[0], NULL, FALSE);
|
2008-05-01 02:38:05 +02:00
|
|
|
expect(TRUE, r);
|
|
|
|
|
2008-10-21 21:54:01 +02:00
|
|
|
r = CreateEnvironmentBlock((LPVOID) &env[1], htok, FALSE);
|
2008-04-30 03:19:05 +02:00
|
|
|
expect(TRUE, r);
|
2008-05-01 02:38:05 +02:00
|
|
|
|
2008-10-21 21:54:01 +02:00
|
|
|
r = CreateEnvironmentBlock((LPVOID) &env[2], NULL, TRUE);
|
2008-05-01 02:38:05 +02:00
|
|
|
expect(TRUE, r);
|
|
|
|
|
2008-10-21 21:54:01 +02:00
|
|
|
r = CreateEnvironmentBlock((LPVOID) &env[3], htok, TRUE);
|
2008-05-01 02:38:05 +02:00
|
|
|
expect(TRUE, r);
|
|
|
|
|
2008-10-21 22:06:33 +02:00
|
|
|
/* Test for common environment variables (NT4 and higher) */
|
2008-10-21 21:54:01 +02:00
|
|
|
for (i = 0; i < sizeof(common_vars)/sizeof(common_vars[0]); i++)
|
2008-05-01 02:38:05 +02:00
|
|
|
{
|
2008-10-21 21:54:01 +02:00
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
{
|
|
|
|
r = get_env(env[j], common_vars[i].name, &st);
|
|
|
|
if (common_vars[i].todo[j])
|
|
|
|
todo_wine expect_env(TRUE, r, common_vars[i].name);
|
|
|
|
else
|
|
|
|
expect_env(TRUE, r, common_vars[i].name);
|
|
|
|
}
|
2008-05-01 02:38:05 +02:00
|
|
|
}
|
2008-05-01 02:39:07 +02:00
|
|
|
|
2008-10-21 22:06:33 +02:00
|
|
|
/* Test for common environment variables (post NT4) */
|
|
|
|
if (!GetEnvironmentVariableA("ALLUSERSPROFILE", NULL, 0))
|
|
|
|
{
|
|
|
|
win_skip("Some environment variables are not present on NT4\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < sizeof(common_post_nt4_vars)/sizeof(common_post_nt4_vars[0]); i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
{
|
|
|
|
r = get_env(env[j], common_post_nt4_vars[i].name, &st);
|
|
|
|
if (common_post_nt4_vars[i].todo[j])
|
|
|
|
todo_wine expect_env(TRUE, r, common_post_nt4_vars[i].name);
|
|
|
|
else
|
|
|
|
expect_env(TRUE, r, common_post_nt4_vars[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-01 02:39:07 +02:00
|
|
|
/* Test for environment variables with values that depends on htok */
|
2008-10-21 21:54:01 +02:00
|
|
|
for (i = 0; i < sizeof(htok_vars)/sizeof(htok_vars[0]); i++)
|
2008-05-01 02:39:07 +02:00
|
|
|
{
|
2008-10-21 21:54:01 +02:00
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
{
|
|
|
|
r = get_env(env[j], htok_vars[i].name, &st);
|
|
|
|
if (htok_vars[i].todo[j])
|
|
|
|
todo_wine expect_env(TRUE, r, htok_vars[i].name);
|
|
|
|
else
|
|
|
|
expect_env(TRUE, r, htok_vars[i].name);
|
|
|
|
}
|
2008-05-01 02:39:07 +02:00
|
|
|
}
|
2008-05-01 02:45:21 +02:00
|
|
|
|
2008-10-21 21:54:01 +02:00
|
|
|
r = get_env(env[0], "WINE_XYZZY", &st);
|
2008-05-01 02:45:21 +02:00
|
|
|
expect(FALSE, r);
|
2008-10-21 21:54:01 +02:00
|
|
|
r = get_env(env[1], "WINE_XYZZY", &st);
|
2008-05-01 02:45:21 +02:00
|
|
|
expect(FALSE, r);
|
2008-10-21 21:54:01 +02:00
|
|
|
r = get_env(env[2], "WINE_XYZZY", &st);
|
2008-05-01 02:45:21 +02:00
|
|
|
expect(TRUE, r);
|
2008-10-21 21:54:01 +02:00
|
|
|
r = get_env(env[3], "WINE_XYZZY", &st);
|
2008-05-01 02:45:21 +02:00
|
|
|
expect(TRUE, r);
|
2008-04-30 03:09:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(userenv)
|
|
|
|
{
|
|
|
|
test_create_env();
|
|
|
|
}
|