2 * Unit test suite for userenv functions
4 * Copyright 2008 Google (Lei Zhang)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/test.h"
33 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
34 #define expect_env(EXPECTED,GOT,VAR) ok((GOT)==(EXPECTED), "Expected %d, got %d for %s (%d)\n", (EXPECTED), (GOT), (VAR), j)
42 /* Helper function for retrieving environment variables */
43 static BOOL
get_env(const WCHAR
* env
, const char * var
, char ** result
)
45 const WCHAR
* p
= env
;
46 int envlen
, varlen
, buflen
;
49 if (!env
|| !var
|| !result
) return FALSE
;
54 if (!WideCharToMultiByte( CP_ACP
, 0, p
, -1, buf
, sizeof(buf
), NULL
, NULL
)) buf
[sizeof(buf
)-1] = 0;
56 if (CompareStringA(GetThreadLocale(), NORM_IGNORECASE
|LOCALE_USE_CP_ACP
, buf
, min(envlen
, varlen
), var
, varlen
) == CSTR_EQUAL
)
58 if (buf
[varlen
] == '=')
61 *result
= HeapAlloc(GetProcessHeap(), 0, buflen
+ 1);
62 if (!*result
) return FALSE
;
63 memcpy(*result
, buf
, buflen
+ 1);
73 static void test_create_env(void)
81 static const struct profile_item common_vars
[] = {
82 { "ComSpec", { 1, 1, 0, 0 } },
83 { "COMPUTERNAME", { 1, 1, 1, 1 } },
84 { "NUMBER_OF_PROCESSORS", { 1, 1, 0, 0 } },
85 { "OS", { 1, 1, 0, 0 } },
86 { "PROCESSOR_ARCHITECTURE", { 1, 1, 0, 0 } },
87 { "PROCESSOR_IDENTIFIER", { 1, 1, 0, 0 } },
88 { "PROCESSOR_LEVEL", { 1, 1, 0, 0 } },
89 { "PROCESSOR_REVISION", { 1, 1, 0, 0 } },
90 { "SystemDrive", { 1, 1, 0, 0 } },
91 { "SystemRoot", { 1, 1, 0, 0 } },
92 { "windir", { 1, 1, 0, 0 } }
94 static const struct profile_item common_post_nt4_vars
[] = {
95 { "ALLUSERSPROFILE", { 1, 1, 0, 0 } },
96 { "TEMP", { 1, 1, 0, 0 } },
97 { "TMP", { 1, 1, 0, 0 } },
98 { "CommonProgramFiles", { 1, 1, 1, 1 } },
99 { "ProgramFiles", { 1, 1, 0, 0 } }
101 static const struct profile_item htok_vars
[] = {
102 { "PATH", { 1, 1, 0, 0 } },
103 { "USERPROFILE", { 1, 1, 0, 0 } }
106 r
= SetEnvironmentVariableA("WINE_XYZZY", "ZZYZX");
112 r
= CreateEnvironmentBlock(NULL
, NULL
, FALSE
);
116 r
= OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
|TOKEN_DUPLICATE
, &htok
);
122 r
= CreateEnvironmentBlock(NULL
, htok
, FALSE
);
126 r
= CreateEnvironmentBlock((LPVOID
) &env
[0], NULL
, FALSE
);
129 r
= CreateEnvironmentBlock((LPVOID
) &env
[1], htok
, FALSE
);
132 r
= CreateEnvironmentBlock((LPVOID
) &env
[2], NULL
, TRUE
);
135 r
= CreateEnvironmentBlock((LPVOID
) &env
[3], htok
, TRUE
);
138 /* Test for common environment variables (NT4 and higher) */
139 for (i
= 0; i
< sizeof(common_vars
)/sizeof(common_vars
[0]); i
++)
141 for (j
= 0; j
< 4; j
++)
143 r
= get_env(env
[j
], common_vars
[i
].name
, &st
);
144 if (common_vars
[i
].todo
[j
])
145 todo_wine
expect_env(TRUE
, r
, common_vars
[i
].name
);
147 expect_env(TRUE
, r
, common_vars
[i
].name
);
151 /* Test for common environment variables (post NT4) */
152 if (!GetEnvironmentVariableA("ALLUSERSPROFILE", NULL
, 0))
154 win_skip("Some environment variables are not present on NT4\n");
158 for (i
= 0; i
< sizeof(common_post_nt4_vars
)/sizeof(common_post_nt4_vars
[0]); i
++)
160 for (j
= 0; j
< 4; j
++)
162 r
= get_env(env
[j
], common_post_nt4_vars
[i
].name
, &st
);
163 if (common_post_nt4_vars
[i
].todo
[j
])
164 todo_wine
expect_env(TRUE
, r
, common_post_nt4_vars
[i
].name
);
166 expect_env(TRUE
, r
, common_post_nt4_vars
[i
].name
);
171 /* Test for environment variables with values that depends on htok */
172 for (i
= 0; i
< sizeof(htok_vars
)/sizeof(htok_vars
[0]); i
++)
174 for (j
= 0; j
< 4; j
++)
176 r
= get_env(env
[j
], htok_vars
[i
].name
, &st
);
177 if (htok_vars
[i
].todo
[j
])
178 todo_wine
expect_env(TRUE
, r
, htok_vars
[i
].name
);
180 expect_env(TRUE
, r
, htok_vars
[i
].name
);
184 r
= get_env(env
[0], "WINE_XYZZY", &st
);
186 r
= get_env(env
[1], "WINE_XYZZY", &st
);
188 r
= get_env(env
[2], "WINE_XYZZY", &st
);
190 r
= get_env(env
[3], "WINE_XYZZY", &st
);