ReactOS 0.4.17-dev-116-ga4b6fe9
env.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include "ntstatus.h"
#include "windef.h"
#include "winbase.h"
#include "winternl.h"
#include "wine/test.h"
Include dependency graph for env.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define check_string(params, str, expect, pos)   check_string_(__LINE__,params,str,expect,pos)
 
#define check_env_var(a, b)   check_env_var_(__LINE__, a, b)
 
#define query_env_var(a, b, c)   query_env_var_(__LINE__, a, b, c)
 

Functions

static NTSTATUS (WINAPI *pRtlMultiByteToUnicodeN)(LPWSTR dst
 
static const UNICODE_STRING const UNICODE_STRING const UNICODE_STRING const UNICODE_STRING const UNICODE_STRING const UNICODE_STRING const UNICODE_STRING const UNICODE_STRING *static void (WINAPI *pRtlDestroyProcessParameters)(RTL_USER_PROCESS_PARAMETERS *)
 
static void testQuery (void)
 
static void testExpand (void)
 
static void test_RtlExpandEnvironmentStrings (void)
 
static WCHARget_params_string (RTL_USER_PROCESS_PARAMETERS *params, UNICODE_STRING *str)
 
static SIZE_T get_env_length (const WCHAR *env)
 
static UINT_PTR align (UINT_PTR size, unsigned int alignment)
 
static UINT_PTR check_string_ (int line, RTL_USER_PROCESS_PARAMETERS *params, UNICODE_STRING *str, const UNICODE_STRING *expect, UINT_PTR pos)
 
static void test_process_params (void)
 
static NTSTATUS set_env_var (WCHAR **env, const WCHAR *var, const WCHAR *value)
 
static void check_env_var_ (int line, const char *var, const char *value)
 
static void test_RtlSetCurrentEnvironment (void)
 
static void query_env_var_ (int line, WCHAR *env, const WCHAR *var, const WCHAR *value)
 
static void test_RtlSetEnvironmentVariable (void)
 
 START_TEST (env)
 

Variables

static DWORD dstlen
 
static DWORD LPDWORD reslen
 
static DWORD LPDWORD LPCSTR src
 
static DWORD LPDWORD LPCSTR DWORD srclen
 
static PUNICODE_STRING
 
static WCHAR SIZE_T
 
static WCHAR WCHAR SIZE_T *static WCHAR WCHAR SIZE_T *static PULONG
 
static const UNICODE_STRING const UNICODE_STRING const UNICODE_STRING const UNICODE_STRING PWSTR
 
static voidinitial_env
 
static WCHAR small_env []
 

Macro Definition Documentation

◆ check_env_var

#define check_env_var (   a,
  b 
)    check_env_var_(__LINE__, a, b)

Definition at line 585 of file env.c.

◆ check_string

#define check_string (   params,
  str,
  expect,
  pos 
)    check_string_(__LINE__,params,str,expect,pos)

Definition at line 405 of file env.c.

◆ query_env_var

#define query_env_var (   a,
  b,
  c 
)    query_env_var_(__LINE__, a, b, c)

Definition at line 684 of file env.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 25 of file env.c.

Function Documentation

◆ align()

static UINT_PTR align ( UINT_PTR  size,
unsigned int  alignment 
)
static

Definition at line 370 of file env.c.

371{
372 return (size + (alignment - 1)) & ~(alignment - 1);
373}
_Check_return_ _Ret_maybenull_ _In_ size_t alignment
Definition: align.cpp:48
GLsizeiptr size
Definition: glext.h:5919

Referenced by check_string_(), and test_process_params().

◆ check_env_var_()

static void check_env_var_ ( int  line,
const char var,
const char value 
)
static

Definition at line 570 of file env.c.

571{
572 char buffer[20];
574 if (value)
575 {
576 ok_(__FILE__, line)(size == strlen(value), "wrong size %lu\n", size);
577 ok_(__FILE__, line)(!strcmp(buffer, value), "wrong value %s\n", debugstr_a(buffer));
578 }
579 else
580 {
581 ok_(__FILE__, line)(!size, "wrong size %lu\n", size);
582 ok_(__FILE__, line)(GetLastError() == ERROR_ENVVAR_NOT_FOUND, "got error %lu\n", GetLastError());
583 }
584}
#define ok_(x1, x2)
Definition: atltest.h:61
#define GetEnvironmentVariableA(x, y, z)
Definition: compat.h:754
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
#define debugstr_a
Definition: kernel32.h:31
const char * var
Definition: shader.c:5666
Definition: parser.c:49
Definition: pdh_main.c:96
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_ENVVAR_NOT_FOUND
Definition: winerror.h:383

◆ check_string_()

static UINT_PTR check_string_ ( int  line,
RTL_USER_PROCESS_PARAMETERS params,
UNICODE_STRING str,
const UNICODE_STRING expect,
UINT_PTR  pos 
)
static

Definition at line 375 of file env.c.

377{
378 if (expect)
379 {
380 ok_(__FILE__,line)( str->Length == expect->Length, "wrong length %u/%u\n",
381 str->Length, expect->Length );
382 ok_(__FILE__,line)( str->MaximumLength == expect->MaximumLength,
383 "wrong maxlength %u/%u\n", str->MaximumLength, expect->MaximumLength );
384 }
385 if (!str->MaximumLength)
386 {
387 ok_(__FILE__,line)( str->Buffer == NULL, "buffer not null %p\n", str->Buffer );
388 return pos;
389 }
390 if (expect)
391 ok_(__FILE__,line)( (UINT_PTR)str->Buffer == align(pos, sizeof(void *)) ||
392 broken( (UINT_PTR)str->Buffer == align(pos, 4) ), /* win7 */
393 "wrong buffer %Ix/%Ix\n", (UINT_PTR)str->Buffer, pos );
394 else /* initial params are not aligned */
395 ok_(__FILE__,line)( (UINT_PTR)str->Buffer == pos,
396 "wrong buffer %Ix/%Ix\n", (UINT_PTR)str->Buffer, pos );
397 if (str->Length < str->MaximumLength)
398 {
400 ok_(__FILE__,line)( !ptr[str->Length / sizeof(WCHAR)], "string not null-terminated %s\n",
401 wine_dbgstr_wn( ptr, str->MaximumLength / sizeof(WCHAR) ));
402 }
403 return (UINT_PTR)str->Buffer + str->MaximumLength;
404}
#define expect(EXPECTED, GOT)
Definition: SystemMenu.c:483
#define broken(x)
Definition: atltest.h:178
#define NULL
Definition: types.h:112
GLenum const GLfloat * params
Definition: glext.h:5645
static PVOID ptr
Definition: dispmode.c:27
static UINT_PTR align(UINT_PTR size, unsigned int alignment)
Definition: env.c:370
static WCHAR * get_params_string(RTL_USER_PROCESS_PARAMETERS *params, UNICODE_STRING *str)
Definition: env.c:357
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
short WCHAR
Definition: pedump.c:58
#define wine_dbgstr_wn
Definition: testlist.c:2
const WCHAR * str

◆ get_env_length()

static SIZE_T get_env_length ( const WCHAR env)
static

Definition at line 363 of file env.c.

364{
365 const WCHAR *end = env;
366 while (*end) end += wcslen(end) + 1;
367 return end + 1 - env;
368}
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:171
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
GLuint GLuint end
Definition: gl.h:1545

Referenced by test_process_params(), and test_RtlSetCurrentEnvironment().

◆ get_params_string()

static WCHAR * get_params_string ( RTL_USER_PROCESS_PARAMETERS params,
UNICODE_STRING str 
)
static

Definition at line 357 of file env.c.

358{
359 if (params->Flags & PROCESS_PARAMS_FLAG_NORMALIZED) return str->Buffer;
360 return (WCHAR *)((char *)params + (UINT_PTR)str->Buffer);
361}
#define PROCESS_PARAMS_FLAG_NORMALIZED
Definition: winternl.h:299

Referenced by check_string_().

◆ NTSTATUS()

static NTSTATUS ( WINAPI pRtlMultiByteToUnicodeN)
static

◆ query_env_var_()

static void query_env_var_ ( int  line,
WCHAR env,
const WCHAR var,
const WCHAR value 
)
static

Definition at line 663 of file env.c.

664{
665 UNICODE_STRING var_string, value_string;
666 WCHAR value_buffer[9];
668
669 RtlInitUnicodeString(&var_string, var);
670 value_string.Buffer = value_buffer;
671 value_string.MaximumLength = sizeof(value_buffer);
672
673 status = RtlQueryEnvironmentVariable_U(env, &var_string, &value_string);
674 if (value)
675 {
676 ok_(__FILE__, line)(!status, "got %#lx\n", status);
677 ok_(__FILE__, line)(value_string.Length/sizeof(WCHAR) == wcslen(value),
678 "wrong size %Iu\n", value_string.Length/sizeof(WCHAR));
679 ok_(__FILE__, line)(!wcscmp(value_string.Buffer, value), "wrong value %s\n", debugstr_w(value_string.Buffer));
680 }
681 else
682 ok_(__FILE__, line)(status == STATUS_VARIABLE_NOT_FOUND, "got %#lx\n", status);
683}
LONG NTSTATUS
Definition: precomp.h:26
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1972
#define debugstr_w
Definition: kernel32.h:32
NTSYSAPI NTSTATUS NTAPI RtlQueryEnvironmentVariable_U(_In_opt_ PWSTR Environment, _In_ PCUNICODE_STRING Name, _Out_ PUNICODE_STRING Value)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_VARIABLE_NOT_FOUND
Definition: ntstatus.h:586
USHORT MaximumLength
Definition: env_spec_w32.h:370
Definition: ps.c:97

◆ set_env_var()

static NTSTATUS set_env_var ( WCHAR **  env,
const WCHAR var,
const WCHAR value 
)
static

Definition at line 562 of file env.c.

563{
564 UNICODE_STRING var_string, value_string;
565 RtlInitUnicodeString(&var_string, var);
566 if (value) RtlInitUnicodeString(&value_string, value);
567 return RtlSetEnvironmentVariable(env, &var_string, value ? &value_string : NULL);
568}
NTSYSAPI NTSTATUS NTAPI RtlSetEnvironmentVariable(_In_z_ PWSTR *Environment, _In_ PUNICODE_STRING Name, _In_ PUNICODE_STRING Value)

Referenced by test_RtlSetCurrentEnvironment(), and test_RtlSetEnvironmentVariable().

◆ START_TEST()

START_TEST ( env  )

Definition at line 740 of file env.c.

741{
742 HMODULE mod = GetModuleHandleA("ntdll.dll");
743
744 initial_env = NtCurrentTeb()->Peb->ProcessParameters->Environment;
745
746 pRtlMultiByteToUnicodeN = (void *)GetProcAddress(mod,"RtlMultiByteToUnicodeN");
747 pRtlQueryEnvironmentVariable_U = (void*)GetProcAddress(mod, "RtlQueryEnvironmentVariable_U");
748 pRtlQueryEnvironmentVariable = (void*)GetProcAddress(mod, "RtlQueryEnvironmentVariable");
749 pRtlExpandEnvironmentStrings = (void*)GetProcAddress(mod, "RtlExpandEnvironmentStrings");
750 pRtlExpandEnvironmentStrings_U = (void*)GetProcAddress(mod, "RtlExpandEnvironmentStrings_U");
751 pRtlCreateProcessParameters = (void*)GetProcAddress(mod, "RtlCreateProcessParameters");
752 pRtlDestroyProcessParameters = (void*)GetProcAddress(mod, "RtlDestroyProcessParameters");
753
754 testQuery();
755 testExpand();
760}
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:68
static FN_RtlQueryEnvironmentVariable * pRtlQueryEnvironmentVariable
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
#define NtCurrentTeb
static void test_process_params(void)
Definition: env.c:407
static void testExpand(void)
Definition: env.c:175
static void test_RtlSetCurrentEnvironment(void)
Definition: env.c:587
static void test_RtlExpandEnvironmentStrings(void)
Definition: env.c:247
static void test_RtlSetEnvironmentVariable(void)
Definition: env.c:686
static void * initial_env
Definition: env.c:44
static void testQuery(void)
Definition: env.c:64

◆ test_process_params()

static void test_process_params ( void  )
static

Definition at line 407 of file env.c.

408{
409 static WCHAR empty[] = {0};
410 static const UNICODE_STRING empty_str = { 0, sizeof(empty), empty };
411 static const UNICODE_STRING null_str = { 0, 0, NULL };
412 static WCHAR exeW[] = {'c',':','\\','f','o','o','.','e','x','e',0};
413 static WCHAR dummyW[] = {'d','u','m','m','y','1',0};
414 static WCHAR dummy_dirW[MAX_PATH] = {'d','u','m','m','y','2',0};
415 static WCHAR dummy_env[] = {'a','=','b',0,'c','=','d',0,0};
416 UNICODE_STRING image = { sizeof(exeW) - sizeof(WCHAR), sizeof(exeW), exeW };
417 UNICODE_STRING dummy = { sizeof(dummyW) - sizeof(WCHAR), sizeof(dummyW), dummyW };
418 UNICODE_STRING dummy_dir = { 6*sizeof(WCHAR), sizeof(dummy_dirW), dummy_dirW };
420 RTL_USER_PROCESS_PARAMETERS *cur_params = NtCurrentTeb()->Peb->ProcessParameters;
421 SIZE_T size;
422 WCHAR *str;
424 NTSTATUS status = pRtlCreateProcessParameters( &params, &image, NULL, NULL, NULL, NULL,
425 NULL, NULL, NULL, NULL );
426 ok( !status, "failed %lx\n", status );
428 ok( size != ~(SIZE_T)0, "not a heap block %p\n", params );
429 ok( params->AllocationSize == params->Size,
430 "wrong AllocationSize %lx/%lx\n", params->AllocationSize, params->Size );
431 ok( params->Size < size || /* __REACTOS__ Win 2003: */ broken(params->Size == size), "wrong Size %lx/%Ix\n", params->Size, size);
432 ok( params->Flags == 0, "wrong Flags %lu\n", params->Flags );
433 ok( params->DebugFlags == 0, "wrong Flags %lu\n", params->DebugFlags );
434 ok( params->ConsoleHandle == 0, "wrong ConsoleHandle %p\n", params->ConsoleHandle );
435#ifdef __REACTOS__
436 if (GetEnvironmentVariableW(L"ROSAUTOTEST_DIR", NULL, 0))
437 ok( params->ConsoleFlags == 1, "wrong ConsoleFlags %lu\n", params->ConsoleFlags );
438 else
439#endif
440 ok( params->ConsoleFlags == 0, "wrong ConsoleFlags %lu\n", params->ConsoleFlags );
441 ok( params->hStdInput == 0, "wrong hStdInput %p\n", params->hStdInput );
442 ok( params->hStdOutput == 0, "wrong hStdOutput %p\n", params->hStdOutput );
443 ok( params->hStdError == 0, "wrong hStdError %p\n", params->hStdError );
444 ok( params->dwX == 0, "wrong dwX %lu\n", params->dwX );
445 ok( params->dwY == 0, "wrong dwY %lu\n", params->dwY );
446 ok( params->dwXSize == 0, "wrong dwXSize %lu\n", params->dwXSize );
447 ok( params->dwYSize == 0, "wrong dwYSize %lu\n", params->dwYSize );
448 ok( params->dwXCountChars == 0, "wrong dwXCountChars %lu\n", params->dwXCountChars );
449 ok( params->dwYCountChars == 0, "wrong dwYCountChars %lu\n", params->dwYCountChars );
450 ok( params->dwFillAttribute == 0, "wrong dwFillAttribute %lu\n", params->dwFillAttribute );
451 ok( params->dwFlags == 0, "wrong dwFlags %lu\n", params->dwFlags );
452 ok( params->wShowWindow == 0, "wrong wShowWindow %lu\n", params->wShowWindow );
453 pos = (UINT_PTR)params->CurrentDirectory.DosPath.Buffer;
454
455 ok( params->CurrentDirectory.DosPath.MaximumLength == MAX_PATH * sizeof(WCHAR),
456 "wrong length %x\n", params->CurrentDirectory.DosPath.MaximumLength );
457 pos = check_string( params, &params->CurrentDirectory.DosPath,
458 &cur_params->CurrentDirectory.DosPath, pos );
459 if (params->DllPath.MaximumLength)
460 pos = check_string( params, &params->DllPath, &cur_params->DllPath, pos );
461 else
462 pos = check_string( params, &params->DllPath, &null_str, pos );
463 pos = check_string( params, &params->ImagePathName, &image, pos );
464 pos = check_string( params, &params->CommandLine, &image, pos );
465 pos = check_string( params, &params->WindowTitle, &empty_str, pos );
466 pos = check_string( params, &params->Desktop, &empty_str, pos );
467 pos = check_string( params, &params->ShellInfo, &empty_str, pos );
468 pos = check_string( params, &params->RuntimeInfo, &null_str, pos );
469 pos = align(pos, 4);
470 ok( pos == params->Size || pos + 4 == params->Size,
471 "wrong pos %Ix/%lx\n", pos, params->Size );
472 pos = params->Size;
473 ok( (char *)params->Environment - (char *)params == (UINT_PTR)pos || broken(/* __REACTOS__ */ GetNTVersion() < _WIN32_WINNT_VISTA),
474 "wrong env %Ix/%Ix\n", (UINT_PTR)((char *)params->Environment - (char *)params), pos);
475 pos += get_env_length(params->Environment) * sizeof(WCHAR);
476 ok( align(pos, sizeof(void *)) == size ||
477 broken( align(pos, 4) == size ) || broken(/* __REACTOS__ */ GetNTVersion() < _WIN32_WINNT_VISTA), "wrong size %Ix/%Ix\n", pos, size );
478 ok( params->EnvironmentSize == size - ((char *)params->Environment - (char *)params) || broken(/* __REACTOS__ */ GetNTVersion() < _WIN32_WINNT_VISTA),
479 "wrong len %Ix/%Ix\n", params->EnvironmentSize,
480 size - ((char *)params->Environment - (char *)params) );
481 pRtlDestroyProcessParameters( params );
482
483 status = pRtlCreateProcessParameters( &params, &image, &dummy, &dummy, &dummy, dummy_env,
484 &dummy, &dummy, &dummy, &dummy );
485 ok( !status, "failed %lx\n", status );
487 ok( size != ~(SIZE_T)0, "not a heap block %p\n", params );
488 ok( params->AllocationSize == params->Size,
489 "wrong AllocationSize %lx/%lx\n", params->AllocationSize, params->Size );
490 ok( params->Size < size || broken(/* __REACTOS__ */ GetNTVersion() < _WIN32_WINNT_VISTA), "wrong Size %lx/%Ix\n", params->Size, size );
491 pos = (UINT_PTR)params->CurrentDirectory.DosPath.Buffer;
492
493 if (params->CurrentDirectory.DosPath.Length == dummy_dir.Length + sizeof(WCHAR))
494 {
495 /* win10 appends a backslash */
496 dummy_dirW[dummy_dir.Length / sizeof(WCHAR)] = '\\';
497 dummy_dir.Length += sizeof(WCHAR);
498 }
499 pos = check_string( params, &params->CurrentDirectory.DosPath, &dummy_dir, pos );
500 pos = check_string( params, &params->DllPath, &dummy, pos );
501 pos = check_string( params, &params->ImagePathName, &image, pos );
502 pos = check_string( params, &params->CommandLine, &dummy, pos );
503 pos = check_string( params, &params->WindowTitle, &dummy, pos );
504 pos = check_string( params, &params->Desktop, &dummy, pos );
505 pos = check_string( params, &params->ShellInfo, &dummy, pos );
506 pos = check_string( params, &params->RuntimeInfo, &dummy, pos );
507 pos = align(pos, 4);
508 ok( pos == params->Size || pos + 4 == params->Size,
509 "wrong pos %Ix/%lx\n", pos, params->Size );
510 pos = params->Size;
511 ok( (char *)params->Environment - (char *)params == pos || broken(/* __REACTOS__ */ GetNTVersion() < _WIN32_WINNT_VISTA),
512 "wrong env %Ix/%Ix\n", (UINT_PTR)((char *)params->Environment - (char *)params), pos);
513 pos += get_env_length(params->Environment) * sizeof(WCHAR);
514 ok( align(pos, sizeof(void *)) == size ||
515 broken( align(pos, 4) == size || broken(/* __REACTOS__ */ GetNTVersion() < _WIN32_WINNT_VISTA) ), "wrong size %Ix/%Ix\n", pos, size );
516 ok( params->EnvironmentSize == size - ((char *)params->Environment - (char *)params) || broken(/* __REACTOS__ */ GetNTVersion() < _WIN32_WINNT_VISTA),
517 "wrong len %Ix/%Ix\n", params->EnvironmentSize,
518 size - ((char *)params->Environment - (char *)params) );
519 pRtlDestroyProcessParameters( params );
520
521 /* also test the actual parameters of the current process */
522
523 ok( cur_params->Flags & PROCESS_PARAMS_FLAG_NORMALIZED, "current params not normalized\n" );
524#ifdef __REACTOS__
525 if ((GetNTVersion() < _WIN32_WINNT_VISTA) || is_reactos()) size = 0; else /* Win2003/ReactOS do not allocate this from the heap */
526#endif
527 size = HeapSize( GetProcessHeap(), 0, cur_params );
528 ok( size != ~(SIZE_T)0, "not a heap block %p\n", cur_params );
529 ok( cur_params->AllocationSize == cur_params->Size,
530 "wrong AllocationSize %lx/%lx\n", cur_params->AllocationSize, cur_params->Size );
531 ok( cur_params->Size == size, "wrong Size %lx/%Ix\n", cur_params->Size, size );
532
533 /* CurrentDirectory points outside the params, and DllPath may be null */
534 pos = (UINT_PTR)cur_params->DllPath.Buffer;
535 if (!pos) pos = (UINT_PTR)cur_params->ImagePathName.Buffer;
536 pos = check_string( cur_params, &cur_params->DllPath, NULL, pos );
537 pos = check_string( cur_params, &cur_params->ImagePathName, NULL, pos );
538 pos = check_string( cur_params, &cur_params->CommandLine, NULL, pos );
539 pos = check_string( cur_params, &cur_params->WindowTitle, NULL, pos );
540 pos = check_string( cur_params, &cur_params->Desktop, NULL, pos );
541 pos = check_string( cur_params, &cur_params->ShellInfo, NULL, pos );
542 pos = check_string( cur_params, &cur_params->RuntimeInfo, NULL, pos );
543 /* environment may follow */
544 str = (WCHAR *)pos;
545 if (pos - (UINT_PTR)cur_params < cur_params->Size) str += get_env_length(str);
546 ok( (char *)str == (char *)cur_params + cur_params->Size,
547 "wrong end ptr %p/%p\n", str, (char *)cur_params + cur_params->Size );
548
549 /* initial environment is a separate block */
550
551 ok( (char *)initial_env < (char *)cur_params || (char *)initial_env >= (char *)cur_params + size,
552 "initial environment inside block %p / %p\n", cur_params, initial_env );
553#ifdef __REACTOS__
554 if ((GetNTVersion() < _WIN32_WINNT_VISTA) || is_reactos()) size = 0; else /* Win2003/ReactOS does not allocate this from the heap */
555#endif
557 ok( size != ~(SIZE_T)0, "env is not a heap block %p / %p\n", cur_params, initial_env );
558 ok( cur_params->EnvironmentSize == size,
559 "wrong len %Ix/%Ix\n", cur_params->EnvironmentSize, size );
560}
#define GetNTVersion()
Definition: apitest.h:17
#define ok(value,...)
Definition: atltest.h:57
static const TCHAR empty_str[]
Definition: dialog.c:20
static const WCHAR empty[1]
Definition: string.c:47
#define GetProcessHeap()
Definition: compat.h:736
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
#define MAX_PATH
Definition: compat.h:34
#define L(x)
Definition: resources.c:13
if(dx< 0)
Definition: linetemp.h:194
static const WCHAR dummyW[]
Definition: directory.c:87
#define check_string(params, str, expect, pos)
Definition: env.c:405
static SIZE_T get_env_length(const WCHAR *env)
Definition: env.c:363
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
UNICODE_STRING DosPath
Definition: rtltypes.h:1362
UNICODE_STRING CommandLine
Definition: btrfs_drv.h:1902
UNICODE_STRING Desktop
Definition: winternl.h:287
UNICODE_STRING RuntimeInfo
Definition: winternl.h:289
UNICODE_STRING ImagePathName
Definition: btrfs_drv.h:1901
UNICODE_STRING WindowTitle
Definition: rtltypes.h:1573
UNICODE_STRING ShellInfo
Definition: rtltypes.h:1575
ULONG_PTR SIZE_T
Definition: typedefs.h:80
SIZE_T WINAPI HeapSize(HANDLE, DWORD, LPCVOID)

Referenced by START_TEST().

◆ test_RtlExpandEnvironmentStrings()

static void test_RtlExpandEnvironmentStrings ( void  )
static

Definition at line 247 of file env.c.

248{
249 int i;
250 WCHAR buf[256];
252 UNICODE_STRING us_src, us_dst, us_name, us_value;
253 static const struct test_info
254 {
255 const WCHAR *input;
256 const WCHAR *expected_str;
257 int count_in;
258 int expected_count_out;
259 } tests[] =
260 {
261 /* 0 */ { L"Long long value", L"abcdefghijklmnopqrstuv", 0, 16 },
262 /* 1 */ { L"Long long value", L"abcdefghijklmnopqrstuv", 1, 16 },
263 /* 2 */ { L"Long long value", L"Lbcdefghijklmnopqrstuv", 2, 16 },
264 /* 3 */ { L"Long long value", L"Locdefghijklmnopqrstuv", 3, 16 },
265 /* 4 */ { L"Long long value", L"Long long valuopqrstuv", 15, 16 },
266 /* 5 */ { L"Long long value", L"Long long value", 16, 16 },
267 /* 6 */ { L"Long long value", L"Long long value", 17, 16 },
268 /* 7 */ { L"%TVAR% long long", L"abcdefghijklmnopqrstuv", 0, 15 },
269 /* 8 */ { L"%TVAR% long long", L"", 1, 15 },
270 /* 9 */ { L"%TVAR% long long", L"", 2, 15 },
271 /* 10 */ { L"%TVAR% long long", L"", 4, 15 },
272 /* 11 */ { L"%TVAR% long long", L"WINE", 5, 15 },
273 /* 12 */ { L"%TVAR% long long", L"WINE fghijklmnopqrstuv", 6, 15 },
274 /* 13 */ { L"%TVAR% long long", L"WINE lghijklmnopqrstuv", 7, 15 },
275 /* 14 */ { L"%TVAR% long long", L"WINE long long", 15, 15 },
276 /* 15 */ { L"%TVAR% long long", L"WINE long long", 16, 15 },
277 /* 16 */ { L"%TVAR%%TVAR% long", L"", 4, 14 },
278 /* 17 */ { L"%TVAR%%TVAR% long", L"WINE", 5, 14 },
279 /* 18 */ { L"%TVAR%%TVAR% long", L"WINE", 6, 14 },
280 /* 19 */ { L"%TVAR%%TVAR% long", L"WINE", 8, 14 },
281 /* 20 */ { L"%TVAR%%TVAR% long", L"WINEWINE", 9, 14 },
282 /* 21 */ { L"%TVAR%%TVAR% long", L"WINEWINE jklmnopqrstuv", 10, 14 },
283 /* 22 */ { L"%TVAR%%TVAR% long", L"WINEWINE long", 14, 14 },
284 /* 23 */ { L"%TVAR%%TVAR% long", L"WINEWINE long", 15, 14 },
285 /* 24 */ { L"%TVAR% %TVAR% long", L"WINE", 5, 15 },
286 /* 25 */ { L"%TVAR% %TVAR% long", L"WINE ", 6, 15 },
287 /* 26 */ { L"%TVAR% %TVAR% long", L"WINE ", 8, 15 },
288 /* 27 */ { L"%TVAR% %TVAR% long", L"WINE ", 9, 15 },
289 /* 28 */ { L"%TVAR% %TVAR% long", L"WINE WINE", 10, 15 },
290 /* 29 */ { L"%TVAR% %TVAR% long", L"WINE WINE klmnopqrstuv", 11, 15 },
291 /* 30 */ { L"%TVAR% %TVAR% long", L"WINE WINE llmnopqrstuv", 12, 15 },
292 /* 31 */ { L"%TVAR% %TVAR% long", L"WINE WINE lonnopqrstuv", 14, 15 },
293 /* 32 */ { L"%TVAR% %TVAR% long", L"WINE WINE long", 15, 15 },
294 /* 33 */ { L"%TVAR% %TVAR% long", L"WINE WINE long", 16, 15 },
295 /* 34 */ { L"%TVAR2% long long", L"abcdefghijklmnopqrstuv", 1, 18 },
296 /* 35 */ { L"%TVAR2% long long", L"%bcdefghijklmnopqrstuv", 2, 18 },
297 /* 36 */ { L"%TVAR2% long long", L"%TVdefghijklmnopqrstuv", 4, 18 },
298 /* 37 */ { L"%TVAR2% long long", L"%TVAR2ghijklmnopqrstuv", 7, 18 },
299 /* 38 */ { L"%TVAR2% long long", L"%TVAR2%hijklmnopqrstuv", 8, 18 },
300 /* 39 */ { L"%TVAR2% long long", L"%TVAR2% ijklmnopqrstuv", 9, 18 },
301 /* 40 */ { L"%TVAR2% long long", L"%TVAR2% ljklmnopqrstuv", 10, 18 },
302 /* 41 */ { L"%TVAR2% long long", L"%TVAR2% long long", 18, 18 },
303 /* 42 */ { L"%TVAR2% long long", L"%TVAR2% long long", 19, 18 },
304 /* 43 */ { L"%TVAR long long", L"abcdefghijklmnopqrstuv", 1, 16 },
305 /* 44 */ { L"%TVAR long long", L"%bcdefghijklmnopqrstuv", 2, 16 },
306 /* 45 */ { L"%TVAR long long", L"%Tcdefghijklmnopqrstuv", 3, 16 },
307 /* 46 */ { L"%TVAR long long", L"%TVAR long lonopqrstuv", 15, 16 },
308 /* 47 */ { L"%TVAR long long", L"%TVAR long long", 16, 16 },
309 /* 48 */ { L"%TVAR long long", L"%TVAR long long", 17, 16 },
310 };
311
312 RtlInitUnicodeString(&us_name, L"TVAR");
313 RtlInitUnicodeString(&us_value, L"WINE");
314 status = RtlSetEnvironmentVariable(NULL, &us_name, &us_value);
315 ok(status == STATUS_SUCCESS, "RtlSetEnvironmentVariable failed with %lx\n", status);
316
317#ifdef __REACTOS__
318 if (pRtlExpandEnvironmentStrings != NULL)
319#endif
320 for (i = 0; i < ARRAY_SIZE(tests); i++)
321 {
322 const struct test_info *test = &tests[i];
323 SIZE_T out_len;
324 HRESULT expected_status = test->count_in >= test->expected_count_out ? STATUS_SUCCESS : STATUS_BUFFER_TOO_SMALL;
325
326 wcscpy(buf, L"abcdefghijklmnopqrstuv");
327 status = pRtlExpandEnvironmentStrings(NULL, (WCHAR*)test->input, wcslen(test->input), buf, test->count_in, &out_len);
328 ok(out_len == test->expected_count_out, "Test %d: got %Iu\n", i, out_len);
329 ok(status == expected_status, "Test %d: Expected status %lx, got %lx\n", i, expected_status, status);
330 ok(!wcscmp(buf, test->expected_str), "Test %d: got %s\n", i, debugstr_w(buf));
331 }
332
333 for (i = 0; i < ARRAY_SIZE(tests); i++)
334 {
335 const struct test_info *test = &tests[i];
336 DWORD out_len;
337 HRESULT expected_status = test->count_in >= test->expected_count_out ? STATUS_SUCCESS : STATUS_BUFFER_TOO_SMALL;
338
339 us_src.Length = wcslen(test->input) * sizeof(WCHAR);
340 us_src.MaximumLength = us_src.Length;
341 us_src.Buffer = (WCHAR*)test->input;
342
343 us_dst.Length = test->count_in * sizeof(WCHAR);
344 us_dst.MaximumLength = us_dst.Length;
345 us_dst.Buffer = buf;
346
347 wcscpy(buf, L"abcdefghijklmnopqrstuv");
348 status = pRtlExpandEnvironmentStrings_U(NULL, &us_src, &us_dst, &out_len);
349 ok(out_len / sizeof(WCHAR) == test->expected_count_out, "Test %d: got %lu\n", i, out_len);
350 ok(status == expected_status, "Test %d: Expected status %lx, got %lx\n", i, expected_status, status);
351 ok(!wcscmp(buf, test->expected_str), "Test %d: got %s\n", i, debugstr_w(buf));
352 }
354 ok(status == STATUS_SUCCESS, "RtlSetEnvironmentVariable failed with %lx\n", status);
355}
#define ARRAY_SIZE(A)
Definition: main.h:20
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLenum GLenum input
Definition: glext.h:9031
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
static struct test_info tests[]
#define test
Definition: rosglue.h:37
wcscpy
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69

Referenced by START_TEST().

◆ test_RtlSetCurrentEnvironment()

static void test_RtlSetCurrentEnvironment ( void  )
static

Definition at line 587 of file env.c.

588{
590 WCHAR *old_env, *env, *prev;
591 BOOL ret;
592 SIZE_T size;
593
595 ok(!status, "got %#lx\n", status);
596
597 ret = SetEnvironmentVariableA("testenv1", "heis");
598 ok(ret, "got error %lu\n", GetLastError());
599 ret = SetEnvironmentVariableA("testenv2", "dyo");
600 ok(ret, "got error %lu\n", GetLastError());
601
602 status = set_env_var(&env, L"testenv1", L"unus");
603 ok(!status, "got %#lx\n", status);
604 status = set_env_var(&env, L"testenv3", L"tres");
605 ok(!status, "got %#lx\n", status);
606
607 old_env = NtCurrentTeb()->Peb->ProcessParameters->Environment;
609 "got wrong size %Iu\n", NtCurrentTeb()->Peb->ProcessParameters->EnvironmentSize);
610#ifdef __REACTOS__
611 return; /* ReactOS does not allocate this from the heap */
612#endif
614 "got wrong size %Iu\n", NtCurrentTeb()->Peb->ProcessParameters->EnvironmentSize);
615
617 ok(prev == old_env, "got wrong previous env %p\n", prev);
618 ok(NtCurrentTeb()->Peb->ProcessParameters->Environment == env, "got wrong current env\n");
620 "got wrong size %Iu\n", NtCurrentTeb()->Peb->ProcessParameters->EnvironmentSize);
622 "got wrong size %Iu\n", NtCurrentTeb()->Peb->ProcessParameters->EnvironmentSize);
623
624 check_env_var("testenv1", "unus");
625 check_env_var("testenv2", NULL);
626 check_env_var("testenv3", "tres");
627 check_env_var("PATH", NULL);
628
629 env = HeapReAlloc( GetProcessHeap(), 0, env, HeapSize( GetProcessHeap(), 0, env) + 120 );
632 "got wrong size %Iu\n", NtCurrentTeb()->Peb->ProcessParameters->EnvironmentSize);
633
635 ok(NtCurrentTeb()->Peb->ProcessParameters->Environment == old_env, "got wrong current env\n");
637 "got wrong size %Iu\n", NtCurrentTeb()->Peb->ProcessParameters->EnvironmentSize);
639 "got wrong size %Iu\n", NtCurrentTeb()->Peb->ProcessParameters->EnvironmentSize);
640
641 check_env_var("testenv1", "heis");
642 check_env_var("testenv2", "dyo");
643 check_env_var("testenv3", NULL);
644
645 env = NtCurrentTeb()->Peb->ProcessParameters->Environment;
646 size = get_env_length(env) * sizeof(WCHAR);
648 "got wrong size %Iu\n", NtCurrentTeb()->Peb->ProcessParameters->EnvironmentSize );
649 ok( size == HeapSize( GetProcessHeap(), 0, env ),
650 "got wrong size %Iu / %Iu\n", size, HeapSize( GetProcessHeap(), 0, env ));
651
652 SetEnvironmentVariableA("testenv1", NULL);
653 SetEnvironmentVariableA("testenv2", NULL);
654
655 env = NtCurrentTeb()->Peb->ProcessParameters->Environment;
657 "got wrong size %Iu\n", NtCurrentTeb()->Peb->ProcessParameters->EnvironmentSize );
658 ok( size == HeapSize( GetProcessHeap(), 0, env ),
659 "got wrong size %Iu / %Iu\n", size, HeapSize( GetProcessHeap(), 0, env ));
660 ok( size > get_env_length(env) * sizeof(WCHAR), "got wrong size %Iu\n", size );
661}
#define FALSE
Definition: types.h:117
#define HeapReAlloc
Definition: compat.h:734
PPEB Peb
Definition: dllmain.c:27
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableA(IN LPCSTR lpName, IN LPCSTR lpValue)
Definition: environ.c:219
return ret
Definition: mutex.c:146
unsigned int BOOL
Definition: ntddk_ex.h:94
#define check_env_var(a, b)
Definition: env.c:585
static NTSTATUS set_env_var(WCHAR **env, const WCHAR *var, const WCHAR *value)
Definition: env.c:562
NTSYSAPI NTSTATUS NTAPI RtlCreateEnvironment(_In_ BOOLEAN Inherit, _Out_ PWSTR *Environment)
PRTL_USER_PROCESS_PARAMETERS ProcessParameters
Definition: btrfs_drv.h:1913
NTSYSAPI void WINAPI RtlSetCurrentEnvironment(PWSTR, PWSTR *)
Definition: env.c:263

Referenced by START_TEST().

◆ test_RtlSetEnvironmentVariable()

static void test_RtlSetEnvironmentVariable ( void  )
static

Definition at line 686 of file env.c.

687{
689 WCHAR *env;
690
692 ok(!status, "got %#lx\n", status);
693
694 status = set_env_var(&env, L"cat", L"dog");
695 ok(!status, "got %#lx\n", status);
696 query_env_var(env, L"cat", L"dog");
697
698 status = set_env_var(&env, L"cat", L"horse");
699 ok(!status, "got %#lx\n", status);
700 query_env_var(env, L"cat", L"horse");
701
702 status = set_env_var(&env, L"cat", NULL);
703 ok(!status, "got %#lx\n", status);
704 query_env_var(env, L"cat", NULL);
705
706 status = set_env_var(&env, L"cat", NULL);
707 ok(!status, "got %#lx\n", status);
708
709 status = set_env_var(&env, L"foo", L"meouw");
710 ok(!status, "got %#lx\n", status);
711 query_env_var(env, L"foo", L"meouw");
712
713 status = set_env_var(&env, L"fOo", NULL);
714 ok(!status, "got %#lx\n", status);
715 query_env_var(env, L"foo", NULL);
716
717 status = set_env_var(&env, L"horse", NULL);
718 ok(!status, "got %#lx\n", status);
719 query_env_var(env, L"horse", NULL);
720
721 status = set_env_var(&env, L"me=too", L"also");
722 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
723
724 status = set_env_var(&env, L"me", L"too=also");
725 ok(!status, "got %#lx\n", status);
726 query_env_var(env, L"me", L"too=also");
727
728 status = set_env_var(&env, L"=too", L"also");
729 ok(!status, "got %#lx\n", status);
730 query_env_var(env, L"=too", L"also");
731
732 status = set_env_var(&env, L"=", L"also");
733 ok(!status, "got %#lx\n", status);
734 query_env_var(env, L"=", L"also");
735
737 ok(!status, "got %#lx\n", status);
738}
#define query_env_var(a, b, c)
Definition: env.c:684
NTSYSAPI VOID NTAPI RtlDestroyEnvironment(_In_ PWSTR Environment)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

Referenced by START_TEST().

◆ testExpand()

static void testExpand ( void  )
static

Definition at line 175 of file env.c.

176{
177 static const struct test
178 {
179 const char *src;
180 const char *dst;
181 } tests[] =
182 {
183 {"hello%foo%world", "hellototoworld"},
184 {"hello%=oOH%world", "helloIIIworld"},
185 {"hello%foo", "hello%foo"},
186 {"hello%bar%world", "hello%bar%world"},
187 /*
188 * {"hello%foo%world%=oOH%eeck", "hellototoworldIIIeeck"},
189 * Interestingly enough, with a 8 WCHAR buffers, we get on 2k:
190 * helloIII
191 * so it seems like strings overflowing the buffer are written
192 * (truncated) but the write cursor is not advanced :-/
193 */
194 {NULL, NULL}
195 };
196
197 const struct test* test;
198 NTSTATUS nts;
199 UNICODE_STRING us_src, us_dst;
200 WCHAR src[256], dst[256], rst[256];
201 ULONG ul;
202
203 for (test = tests; test->src; test++)
204 {
205 pRtlMultiByteToUnicodeN(src, sizeof(src), NULL, test->src, strlen(test->src)+1);
206 pRtlMultiByteToUnicodeN(rst, sizeof(rst), NULL, test->dst, strlen(test->dst)+1);
207
208 us_src.Length = strlen(test->src) * sizeof(WCHAR);
209 us_src.MaximumLength = us_src.Length + 2;
210 us_src.Buffer = src;
211
212 us_dst.Length = 0;
213 us_dst.MaximumLength = 0;
214 us_dst.Buffer = NULL;
215
216 nts = pRtlExpandEnvironmentStrings_U(small_env, &us_src, &us_dst, &ul);
217 ok(nts == STATUS_BUFFER_TOO_SMALL, "Call failed (%lu)\n", nts);
218 ok(ul == strlen(test->dst) * sizeof(WCHAR) + sizeof(WCHAR),
219 "Wrong returned length for %s: %lu\n", test->src, ul );
220
221 us_dst.Length = 0;
222 us_dst.MaximumLength = sizeof(dst);
223 us_dst.Buffer = dst;
224
225 nts = pRtlExpandEnvironmentStrings_U(small_env, &us_src, &us_dst, &ul);
226 ok(nts == STATUS_SUCCESS, "Call failed (%lu)\n", nts);
227 ok(ul == us_dst.Length + sizeof(WCHAR),
228 "Wrong returned length for %s: %lu\n", test->src, ul);
229 ok(ul == strlen(test->dst) * sizeof(WCHAR) + sizeof(WCHAR),
230 "Wrong returned length for %s: %lu\n", test->src, ul);
231 ok(lstrcmpW(dst, rst) == 0, "Wrong result for %s: expecting %s\n",
232 test->src, test->dst);
233
234 us_dst.Length = 0;
235 us_dst.MaximumLength = 8 * sizeof(WCHAR);
236 us_dst.Buffer = dst;
237 dst[8] = '-';
238 nts = pRtlExpandEnvironmentStrings_U(small_env, &us_src, &us_dst, &ul);
239 ok(nts == STATUS_BUFFER_TOO_SMALL, "Call failed (%lu)\n", nts);
240 ok(ul == strlen(test->dst) * sizeof(WCHAR) + sizeof(WCHAR),
241 "Wrong returned length for %s (with buffer too small): %lu\n", test->src, ul);
242 ok(dst[8] == '-', "Writing too far in buffer (got %c/%d)\n", dst[8], dst[8]);
243 }
244
245}
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
static WCHAR small_env[]
Definition: env.c:46
static DWORD LPDWORD LPCSTR src
Definition: env.c:32
uint32_t ULONG
Definition: typedefs.h:59

Referenced by START_TEST().

◆ testQuery()

static void testQuery ( void  )
static

Definition at line 64 of file env.c.

65{
66 struct test
67 {
68 const char *var;
69 int len;
71 const char *val;
72 NTSTATUS alt;
73 };
74
75 static const struct test tests[] =
76 {
77 {"foo", 256, STATUS_SUCCESS, "toto"},
78 {"FoO", 256, STATUS_SUCCESS, "toto"},
79 {"foo=", 256, STATUS_VARIABLE_NOT_FOUND, NULL},
80 {"foo ", 256, STATUS_VARIABLE_NOT_FOUND, NULL},
81 {"foo", 1, STATUS_BUFFER_TOO_SMALL, "toto"},
82 {"foo", 3, STATUS_BUFFER_TOO_SMALL, "toto"},
83 {"foo", 4, STATUS_SUCCESS, "toto", STATUS_BUFFER_TOO_SMALL},
84 {"foo", 5, STATUS_SUCCESS, "toto"},
85 {"fooo", 256, STATUS_SUCCESS, "tutu"},
87 {"g", 256, STATUS_SUCCESS, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
88"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
89 {"sr=an", 256, STATUS_SUCCESS, "ouo", STATUS_VARIABLE_NOT_FOUND},
90 {"sr", 256, STATUS_SUCCESS, "an=ouo"},
91 {"=oOH", 256, STATUS_SUCCESS, "III"},
93 {"nul", 256, STATUS_SUCCESS, ""},
94 {NULL, 0, 0, NULL}
95 };
96
97 WCHAR bn[257];
98 WCHAR bv[257];
101 NTSTATUS nts;
102 SIZE_T name_length;
103 SIZE_T value_length;
104 SIZE_T return_length;
105 unsigned int i;
106
107 for (i = 0; tests[i].var; i++)
108 {
109 const struct test *test = &tests[i];
110 name.Length = strlen(test->var) * 2;
111 name.MaximumLength = name.Length + 2;
112 name.Buffer = bn;
113 value.Length = 0;
114 value.MaximumLength = test->len * 2;
115 value.Buffer = bv;
116 bv[test->len] = '@';
117
118 pRtlMultiByteToUnicodeN( bn, sizeof(bn), NULL, test->var, strlen(test->var)+1 );
119 nts = pRtlQueryEnvironmentVariable_U(small_env, &name, &value);
120 ok( nts == test->status || (test->alt && nts == test->alt),
121 "[%d]: Wrong status for '%s', expecting %lx got %lx\n",
122 i, test->var, test->status, nts );
123 if (nts == test->status) switch (nts)
124 {
125 case STATUS_SUCCESS:
126 pRtlMultiByteToUnicodeN( bn, sizeof(bn), NULL, test->val, strlen(test->val)+1 );
127 ok( value.Length == strlen(test->val) * sizeof(WCHAR), "Wrong length %d for %s\n",
128 value.Length, test->var );
129 ok((value.Length == strlen(test->val) * sizeof(WCHAR) && memcmp(bv, bn, value.Length) == 0) ||
130 lstrcmpW(bv, bn) == 0,
131 "Wrong result for %s/%d\n", test->var, test->len);
132 ok(bv[test->len] == '@', "Writing too far away in the buffer for %s/%d\n", test->var, test->len);
133 break;
135 ok( value.Length == strlen(test->val) * sizeof(WCHAR),
136 "Wrong returned length %d (too small buffer) for %s\n", value.Length, test->var );
137 break;
138 }
139 }
140
142 {
143 for (i = 0; tests[i].var; i++)
144 {
145 const struct test* test = &tests[i];
146 name_length = strlen(test->var);
147 value_length = test->len;
148 value.Buffer = bv;
149 bv[test->len] = '@';
150
151 pRtlMultiByteToUnicodeN(bn, sizeof(bn), NULL, test->var, strlen(test->var) + 1);
152 nts = pRtlQueryEnvironmentVariable(small_env, bn, name_length, bv, value_length, &return_length);
153 ok(nts == test->status || (test->alt && nts == test->alt),
154 "[%d]: Wrong status for '%s', expecting %lx got %lx\n",
155 i, test->var, test->status, nts);
156 if (nts == test->status) switch (nts)
157 {
158 case STATUS_SUCCESS:
159 pRtlMultiByteToUnicodeN(bn, sizeof(bn), NULL, test->val, strlen(test->val) + 1);
160 ok(return_length == strlen(test->val), "Wrong length %Id for %s\n",
161 return_length, test->var);
162 ok(!memcmp(bv, bn, return_length), "Wrong result for %s/%d\n", test->var, test->len);
163 ok(bv[test->len] == '@', "Writing too far away in the buffer for %s/%d\n", test->var, test->len);
164 break;
166 ok(return_length == (strlen(test->val) + 1),
167 "Wrong returned length %Id (too small buffer) for %s\n", return_length, test->var);
168 break;
169 }
170 }
171 }
172 else win_skip("RtlQueryEnvironmentVariable not available, skipping tests\n");
173}
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
GLuint GLfloat * val
Definition: glext.h:7180
GLenum GLsizei len
Definition: glext.h:6722
#define win_skip
Definition: minitest.h:67
Definition: name.c:39

Referenced by START_TEST().

◆ void()

Variable Documentation

◆ dstlen

DWORD dstlen

Definition at line 31 of file env.c.

◆ initial_env

void* initial_env
static

Definition at line 44 of file env.c.

Referenced by START_TEST(), and test_process_params().

◆ PULONG

Definition at line 36 of file env.c.

◆ PUNICODE_STRING

Definition at line 33 of file env.c.

◆ PWSTR

◆ reslen

DWORD LPDWORD reslen

Definition at line 31 of file env.c.

◆ SIZE_T

Definition at line 34 of file env.c.

◆ small_env

WCHAR small_env[]
static
Initial value:
= {'f','o','o','=','t','o','t','o',0,
'f','o','=','t','i','t','i',0,
'f','o','o','o','=','t','u','t','u',0,
's','r','=','a','n','=','o','u','o',0,
'g','=','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',0,
'=','o','O','H','=','I','I','I',0,
'n','u','l','=',0,
0}

Definition at line 46 of file env.c.

Referenced by testExpand(), and testQuery().

◆ src

Definition at line 32 of file env.c.

Referenced by testExpand().

◆ srclen

Definition at line 32 of file env.c.