ReactOS  0.4.14-dev-342-gdc047f9
userenv.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "winreg.h"
#include "userenv.h"
#include "wine/test.h"
Include dependency graph for userenv.c:

Go to the source code of this file.

Classes

struct  profile_item
 

Macros

#define expect(EXPECTED, GOT)   ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
 
#define expect_env(EXPECTED, GOT, VAR)   ok((GOT)==(EXPECTED), "Expected %d, got %d for %s (%d)\n", (EXPECTED), (GOT), (VAR), j)
 
#define expect_gle(EXPECTED)   ok(GetLastError() == (EXPECTED), "Expected %d, got %d\n", (EXPECTED), GetLastError())
 

Functions

static BOOL (WINAPI *pIsWow64Process)(HANDLE
 
static BOOL get_env (const WCHAR *env, const char *var, char **result)
 
static void test_create_env (void)
 
static void test_get_profiles_dir (void)
 
static void test_get_user_profile_dir (void)
 
 START_TEST (userenv)
 

Variables

static PBOOL
 

Macro Definition Documentation

◆ expect

#define expect (   EXPECTED,
  GOT 
)    ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))

Definition at line 34 of file userenv.c.

◆ expect_env

#define expect_env (   EXPECTED,
  GOT,
  VAR 
)    ok((GOT)==(EXPECTED), "Expected %d, got %d for %s (%d)\n", (EXPECTED), (GOT), (VAR), j)

Definition at line 35 of file userenv.c.

◆ expect_gle

#define expect_gle (   EXPECTED)    ok(GetLastError() == (EXPECTED), "Expected %d, got %d\n", (EXPECTED), GetLastError())

Definition at line 36 of file userenv.c.

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pIsWow64Process)
static

◆ get_env()

static BOOL get_env ( const WCHAR env,
const char var,
char **  result 
)
static

Definition at line 46 of file userenv.c.

47 {
48  const WCHAR * p = env;
49  int envlen, varlen, buflen;
50  char buf[256];
51 
52  if (!env || !var || !result) return FALSE;
53 
54  varlen = strlen(var);
55  do
56  {
57  if (!WideCharToMultiByte( CP_ACP, 0, p, -1, buf, sizeof(buf), NULL, NULL )) buf[sizeof(buf)-1] = 0;
58  envlen = strlen(buf);
59  if (CompareStringA(GetThreadLocale(), NORM_IGNORECASE|LOCALE_USE_CP_ACP, buf, min(envlen, varlen), var, varlen) == CSTR_EQUAL)
60  {
61  if (buf[varlen] == '=')
62  {
63  buflen = strlen(buf);
64  *result = HeapAlloc(GetProcessHeap(), 0, buflen + 1);
65  if (!*result) return FALSE;
66  memcpy(*result, buf, buflen + 1);
67  return TRUE;
68  }
69  }
70  while (*p) p++;
71  p++;
72  } while (*p);
73  return FALSE;
74 }
#define TRUE
Definition: types.h:120
#define WideCharToMultiByte
Definition: compat.h:101
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define CP_ACP
Definition: compat.h:99
#define NORM_IGNORECASE
Definition: winnls.h:173
smooth NULL
Definition: ftsmooth.c:416
INT WINAPI CompareStringA(LCID lcid, DWORD flags, LPCSTR str1, INT len1, LPCSTR str2, INT len2)
Definition: lang.c:2299
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define CSTR_EQUAL
Definition: winnls.h:453
#define LOCALE_USE_CP_ACP
Definition: winnls.h:20
#define min(a, b)
Definition: monoChain.cc:55
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:168
GLfloat GLfloat p
Definition: glext.h:8902
GLuint64EXT * result
Definition: glext.h:11304
LCID WINAPI GetThreadLocale(void)
Definition: lang.c:1449

Referenced by test_create_env().

◆ START_TEST()

START_TEST ( userenv  )

Definition at line 404 of file userenv.c.

405 {
406  pIsWow64Process = (void*)GetProcAddress(GetModuleHandleA("kernel32.dll"), "IsWow64Process");
407 
408  test_create_env();
411 }
static void test_create_env(void)
Definition: userenv.c:76
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
static void test_get_user_profile_dir(void)
Definition: userenv.c:301
#define GetProcAddress(x, y)
Definition: compat.h:418
static void test_get_profiles_dir(void)
Definition: userenv.c:225

◆ test_create_env()

static void test_create_env ( void  )
static

Definition at line 76 of file userenv.c.

77 {
78  BOOL r, is_wow64 = FALSE;
79  HANDLE htok;
80  WCHAR * env[4];
81  char * st, systemroot[100];
82  int i, j;
83 
84  static const struct profile_item common_vars[] = {
85  { "ComSpec" },
86  { "COMPUTERNAME" },
87  { "NUMBER_OF_PROCESSORS" },
88  { "OS" },
89  { "PROCESSOR_ARCHITECTURE" },
90  { "PROCESSOR_IDENTIFIER" },
91  { "PROCESSOR_LEVEL" },
92  { "PROCESSOR_REVISION" },
93  { "SystemDrive" },
94  { "SystemRoot" },
95  { "windir" }
96  };
97  static const struct profile_item common_post_nt4_vars[] = {
98  { "ALLUSERSPROFILE" },
99  { "TEMP" },
100  { "TMP" },
101  { "CommonProgramFiles" },
102  { "ProgramFiles" },
103  { "PATH" },
104  { "USERPROFILE" }
105  };
106  static const struct profile_item common_win64_vars[] = {
107  { "ProgramW6432" },
108  { "CommonProgramW6432" }
109  };
110 
111  r = SetEnvironmentVariableA("WINE_XYZZY", "ZZYZX");
112  expect(TRUE, r);
113 
114  r = GetEnvironmentVariableA("SystemRoot", systemroot, sizeof(systemroot));
115  ok(r != 0, "GetEnvironmentVariable failed (%d)\n", GetLastError());
116 
117  r = SetEnvironmentVariableA("SystemRoot", "overwrite");
118  expect(TRUE, r);
119 
120  if (0)
121  {
122  /* Crashes on NT4 */
124  expect(FALSE, r);
125  }
126 
128  expect(TRUE, r);
129 
130  if (0)
131  {
132  /* Crashes on NT4 */
134  expect(FALSE, r);
135  }
136 
138  expect(TRUE, r);
139 
140  r = CreateEnvironmentBlock((LPVOID) &env[1], htok, FALSE);
141  expect(TRUE, r);
142 
144  expect(TRUE, r);
145 
146  r = CreateEnvironmentBlock((LPVOID) &env[3], htok, TRUE);
147  expect(TRUE, r);
148 
149  r = SetEnvironmentVariableA("SystemRoot", systemroot);
150  expect(TRUE, r);
151 
152  for(i=0; i<4; i++)
153  {
154  r = get_env(env[i], "SystemRoot", &st);
155  ok(!strcmp(st, "SystemRoot=overwrite"), "%s\n", st);
156  expect(TRUE, r);
157  HeapFree(GetProcessHeap(), 0, st);
158  }
159 
160  /* Test for common environment variables (NT4 and higher) */
161  for (i = 0; i < ARRAY_SIZE(common_vars); i++)
162  {
163  for (j = 0; j < 4; j++)
164  {
165  r = get_env(env[j], common_vars[i].name, &st);
166  expect_env(TRUE, r, common_vars[i].name);
167  if (r) HeapFree(GetProcessHeap(), 0, st);
168  }
169  }
170 
171  /* Test for common environment variables (post NT4) */
172  if (!GetEnvironmentVariableA("ALLUSERSPROFILE", NULL, 0))
173  {
174  win_skip("Some environment variables are not present on NT4\n");
175  }
176  else
177  {
178  for (i = 0; i < ARRAY_SIZE(common_post_nt4_vars); i++)
179  {
180  for (j = 0; j < 4; j++)
181  {
182  r = get_env(env[j], common_post_nt4_vars[i].name, &st);
183  expect_env(TRUE, r, common_post_nt4_vars[i].name);
184  if (r) HeapFree(GetProcessHeap(), 0, st);
185  }
186  }
187  }
188 
189  if(pIsWow64Process)
190  pIsWow64Process(GetCurrentProcess(), &is_wow64);
191  if (sizeof(void*)==8 || is_wow64)
192  {
193  for (i = 0; i < ARRAY_SIZE(common_win64_vars); i++)
194  {
195  for (j=0; j<4; j++)
196  {
197  r = get_env(env[j], common_win64_vars[i].name, &st);
198  ok(r || broken(!r)/* Vista,2k3,XP */, "Expected 1, got 0 for %s\n", common_win64_vars[i].name);
199  if (r) HeapFree(GetProcessHeap(), 0, st);
200  }
201  }
202  }
203 
204  r = get_env(env[0], "WINE_XYZZY", &st);
205  expect(FALSE, r);
206 
207  r = get_env(env[1], "WINE_XYZZY", &st);
208  expect(FALSE, r);
209 
210  r = get_env(env[2], "WINE_XYZZY", &st);
211  expect(TRUE, r);
212  if (r) HeapFree(GetProcessHeap(), 0, st);
213 
214  r = get_env(env[3], "WINE_XYZZY", &st);
215  expect(TRUE, r);
216  if (r) HeapFree(GetProcessHeap(), 0, st);
217 
218  for (i = 0; i < ARRAY_SIZE(env); i++)
219  {
221  expect(TRUE, r);
222  }
223 }
#define TRUE
Definition: types.h:120
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI CreateEnvironmentBlock(OUT LPVOID *lpEnvironment, IN HANDLE hToken, IN BOOL bInherit)
Definition: environment.c:505
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define GetProcessHeap()
Definition: compat.h:403
#define GetEnvironmentVariableA(x, y, z)
Definition: compat.h:419
#define TOKEN_QUERY
Definition: setypes.h:874
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define expect_env(EXPECTED, GOT, VAR)
Definition: userenv.c:35
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableA(IN LPCSTR lpName, IN LPCSTR lpValue)
Definition: environ.c:218
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
static BOOL is_wow64
Definition: loader.c:55
#define TOKEN_DUPLICATE
Definition: setypes.h:872
BOOL WINAPI DestroyEnvironmentBlock(IN LPVOID lpEnvironment)
Definition: environment.c:727
#define broken(x)
Definition: _sntprintf.h:21
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:168
Definition: name.c:36
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static BOOL get_env(const WCHAR *env, const char *var, char **result)
Definition: userenv.c:46
#define expect(EXPECTED, GOT)
Definition: userenv.c:34
#define win_skip
Definition: test.h:141
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by START_TEST().

◆ test_get_profiles_dir()

static void test_get_profiles_dir ( void  )
static

Definition at line 225 of file userenv.c.

226 {
227  static const char ProfileListA[] = "Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList";
228  static const char ProfilesDirectory[] = "ProfilesDirectory";
229  BOOL r;
230  DWORD cch, profiles_len;
231  LONG l;
232  HKEY key;
233  char *profiles_dir, *buf, small_buf[1];
234 
235  l = RegOpenKeyExA(HKEY_LOCAL_MACHINE, ProfileListA, 0, KEY_READ, &key);
236  ok(!l, "RegOpenKeyExA failed: %d\n", GetLastError());
237 
238  l = RegQueryValueExA(key, ProfilesDirectory, NULL, NULL, NULL, &cch);
239  if (l)
240  {
241  win_skip("No ProfilesDirectory value (NT4), skipping tests\n");
242  return;
243  }
244  buf = HeapAlloc(GetProcessHeap(), 0, cch);
245  RegQueryValueExA(key, ProfilesDirectory, NULL, NULL, (BYTE *)buf, &cch);
246  RegCloseKey(key);
247  profiles_len = ExpandEnvironmentStringsA(buf, NULL, 0);
248  profiles_dir = HeapAlloc(GetProcessHeap(), 0, profiles_len);
249  ExpandEnvironmentStringsA(buf, profiles_dir, profiles_len);
250  HeapFree(GetProcessHeap(), 0, buf);
251 
252  SetLastError(0xdeadbeef);
254  expect(FALSE, r);
256  SetLastError(0xdeadbeef);
258  expect(FALSE, r);
260  SetLastError(0xdeadbeef);
261  cch = 1;
262  r = GetProfilesDirectoryA(small_buf, &cch);
263  expect(FALSE, r);
265  /* MSDN claims the returned character count includes the NULL terminator
266  * when the buffer is too small, but that's not in fact what gets returned.
267  */
268  ok(cch == profiles_len - 1, "expected %d, got %d\n", profiles_len - 1, cch);
269  /* Allocate one more character than the return value to prevent a buffer
270  * overrun.
271  */
272  buf = HeapAlloc(GetProcessHeap(), 0, cch + 1);
274  /* Rather than a BOOL, the return value is also the number of characters
275  * stored in the buffer.
276  */
277  expect(profiles_len - 1, r);
278  ok(!strcmp(buf, profiles_dir), "expected %s, got %s\n", profiles_dir, buf);
279 
280  HeapFree(GetProcessHeap(), 0, buf);
281  HeapFree(GetProcessHeap(), 0, profiles_dir);
282 
283  SetLastError(0xdeadbeef);
285  expect(FALSE, r);
287 
288  cch = 0;
289  SetLastError(0xdeadbeef);
291  expect(FALSE, r);
293  ok(cch, "expected cch > 0\n");
294 
295  SetLastError(0xdeadbeef);
297  expect(FALSE, r);
299 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4023
BOOL WINAPI GetProfilesDirectoryA(_Out_ LPSTR lpProfileDir, _Inout_ LPDWORD lpcchSize)
Definition: profile.c:1453
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define KEY_READ
Definition: nt_native.h:1023
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3331
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define expect_gle(EXPECTED)
Definition: userenv.c:36
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:201
smooth NULL
Definition: ftsmooth.c:416
DWORD WINAPI ExpandEnvironmentStringsA(IN LPCSTR lpSrc, IN LPSTR lpDst, IN DWORD nSize)
Definition: environ.c:399
BOOL WINAPI GetProfilesDirectoryW(_Out_ LPWSTR lpProfilesDir, _Inout_ LPDWORD lpcchSize)
Definition: profile.c:1493
r l[0]
Definition: byte_order.h:167
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
HKEY key
Definition: reg.c:42
unsigned char BYTE
Definition: mem.h:68
#define ok(value,...)
Definition: atltest.h:57
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define expect(EXPECTED, GOT)
Definition: userenv.c:34
#define win_skip
Definition: test.h:141
#define HeapFree(x, y, z)
Definition: compat.h:402
Definition: path.c:42
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by START_TEST().

◆ test_get_user_profile_dir()

static void test_get_user_profile_dir ( void  )
static

Definition at line 301 of file userenv.c.

302 {
303  BOOL ret;
304  DWORD error, len;
305  HANDLE token;
306  char *dirA;
307  WCHAR *dirW;
308 
309  if (!GetEnvironmentVariableA( "ALLUSERSPROFILE", NULL, 0 ))
310  {
311  win_skip("Skipping tests on NT4\n");
312  return;
313  }
314 
316  ok(ret, "expected success %u\n", GetLastError());
317 
318  SetLastError( 0xdeadbeef );
320  error = GetLastError();
321  ok(!ret, "expected failure\n");
322  ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
323 
324  SetLastError( 0xdeadbeef );
326  error = GetLastError();
327  ok(!ret, "expected failure\n");
328  ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
329 
330  dirA = HeapAlloc( GetProcessHeap(), 0, 32 );
331  SetLastError( 0xdeadbeef );
333  error = GetLastError();
334  ok(!ret, "expected failure\n");
335  ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
336  HeapFree( GetProcessHeap(), 0, dirA );
337 
338  len = 0;
339  SetLastError( 0xdeadbeef );
341  error = GetLastError();
342  ok(!ret, "expected failure\n");
343  ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
344  ok(!len, "expected 0, got %u\n", len);
345 
346  len = 0;
347  dirA = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 32 );
348  SetLastError( 0xdeadbeef );
349  ret = GetUserProfileDirectoryA( token, dirA, &len );
350  error = GetLastError();
351  ok(!ret, "expected failure\n");
352  ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
353  ok(len, "expected len > 0\n");
354  HeapFree( GetProcessHeap(), 0, dirA );
355 
357  SetLastError( 0xdeadbeef );
358  ret = GetUserProfileDirectoryA( token, dirA, &len );
359  ok(ret, "expected success %u\n", GetLastError());
360  ok(len, "expected len > 0\n");
361  ok(lstrlenA( dirA ) == len - 1, "length mismatch %d != %d - 1\n", lstrlenA( dirA ), len );
362  trace("%s\n", dirA);
363  HeapFree( GetProcessHeap(), 0, dirA );
364 
365  SetLastError( 0xdeadbeef );
367  error = GetLastError();
368  ok(!ret, "expected failure\n");
369  todo_wine ok(error == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %u\n", error);
370 
371  SetLastError( 0xdeadbeef );
373  error = GetLastError();
374  ok(!ret, "expected failure\n");
375  ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
376 
377  dirW = HeapAlloc( GetProcessHeap(), 0, 32 );
378  SetLastError( 0xdeadbeef );
380  error = GetLastError();
381  ok(!ret, "expected failure\n");
382  ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
383  HeapFree( GetProcessHeap(), 0, dirW );
384 
385  len = 0;
386  SetLastError( 0xdeadbeef );
388  error = GetLastError();
389  ok(!ret, "expected failure\n");
390  ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
391  ok(len, "expected len > 0\n");
392 
393  dirW = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len * sizeof(WCHAR) );
394  SetLastError( 0xdeadbeef );
395  ret = GetUserProfileDirectoryW( token, dirW, &len );
396  ok(ret, "expected success %u\n", GetLastError());
397  ok(len, "expected len > 0\n");
398  ok(lstrlenW( dirW ) == len - 1, "length mismatch %d != %d - 1\n", lstrlenW( dirW ), len );
399  HeapFree( GetProcessHeap(), 0, dirW );
400 
401  CloseHandle( token );
402 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define CloseHandle
Definition: compat.h:406
#define error(str)
Definition: mkdosfs.c:1605
BOOL WINAPI GetUserProfileDirectoryW(_In_ HANDLE hToken, _Out_opt_ LPWSTR lpProfileDir, _Inout_ LPDWORD lpcchSize)
Definition: profile.c:1709
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define lstrlenW
Definition: compat.h:415
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:403
#define trace
Definition: atltest.h:70
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define GetEnvironmentVariableA(x, y, z)
Definition: compat.h:419
#define TOKEN_QUERY
Definition: setypes.h:874
BOOL WINAPI GetUserProfileDirectoryA(_In_ HANDLE hToken, _Out_opt_ LPSTR lpProfileDir, _Inout_ LPDWORD lpcchSize)
Definition: profile.c:1667
__wchar_t WCHAR
Definition: xmlstorage.h:180
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
int ret
#define todo_wine
Definition: test.h:154
GLenum GLsizei len
Definition: glext.h:6722
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define win_skip
Definition: test.h:141
#define HeapFree(x, y, z)
Definition: compat.h:402
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by START_TEST().

Variable Documentation

◆ PBOOL

Definition at line 38 of file userenv.c.