|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#include <stdio.h>
|
|
Packit |
1fb8d4 |
#include <winpr/crt.h>
|
|
Packit |
1fb8d4 |
#include <winpr/tchar.h>
|
|
Packit |
1fb8d4 |
#include <winpr/environment.h>
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
int TestEnvironmentGetSetEB(int argc, char* argv[])
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
int rc = 0;
|
|
Packit |
1fb8d4 |
#ifndef _WIN32
|
|
Packit |
1fb8d4 |
char test[1024];
|
|
Packit Service |
5a9772 |
TCHAR* p = NULL;
|
|
Packit Service |
5a9772 |
DWORD length;
|
|
Packit |
1fb8d4 |
LPTCH lpszEnvironmentBlock = "SHELL=123\0test=1\0test1=2\0DISPLAY=WINPR_TEST_VALUE\0\0";
|
|
Packit |
1fb8d4 |
LPTCH lpszEnvironmentBlockNew = NULL;
|
|
Packit Service |
5a9772 |
rc = -1;
|
|
Packit |
1fb8d4 |
/* Get length of an variable */
|
|
Packit Service |
5a9772 |
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock, "DISPLAY", NULL, 0);
|
|
Packit Service |
5a9772 |
|
|
Packit |
1fb8d4 |
if (0 == length)
|
|
Packit |
1fb8d4 |
return -1;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Get the variable itself */
|
|
Packit Service |
5a9772 |
p = (LPSTR)malloc(length);
|
|
Packit Service |
5a9772 |
|
|
Packit |
1fb8d4 |
if (!p)
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
|
|
Packit Service |
5a9772 |
if (GetEnvironmentVariableEBA(lpszEnvironmentBlock, "DISPLAY", p, length) != length - 1)
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
|
|
Packit Service |
5a9772 |
printf("GetEnvironmentVariableA(WINPR_TEST_VARIABLE) = %s\n", p);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
if (strcmp(p, "WINPR_TEST_VALUE") != 0)
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Get length of an non-existing variable */
|
|
Packit Service |
5a9772 |
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock, "BLA", NULL, 0);
|
|
Packit Service |
5a9772 |
|
|
Packit |
1fb8d4 |
if (0 != length)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
printf("Unset variable returned\n");
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Get length of an similar called variables */
|
|
Packit Service |
5a9772 |
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock, "XDISPLAY", NULL, 0);
|
|
Packit Service |
5a9772 |
|
|
Packit |
1fb8d4 |
if (0 != length)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
printf("Similar named variable returned (XDISPLAY, length %d)\n", length);
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
}
|
|
Packit Service |
5a9772 |
|
|
Packit Service |
5a9772 |
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock, "DISPLAYX", NULL, 0);
|
|
Packit Service |
5a9772 |
|
|
Packit |
1fb8d4 |
if (0 != length)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
printf("Similar named variable returned (DISPLAYX, length %d)\n", length);
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
}
|
|
Packit Service |
5a9772 |
|
|
Packit Service |
5a9772 |
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock, "DISPLA", NULL, 0);
|
|
Packit Service |
5a9772 |
|
|
Packit |
1fb8d4 |
if (0 != length)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
printf("Similar named variable returned (DISPLA, length %d)\n", length);
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
}
|
|
Packit Service |
5a9772 |
|
|
Packit Service |
5a9772 |
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock, "ISPLAY", NULL, 0);
|
|
Packit Service |
5a9772 |
|
|
Packit |
1fb8d4 |
if (0 != length)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
printf("Similar named variable returned (ISPLAY, length %d)\n", length);
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Set variable in empty environment block */
|
|
Packit |
1fb8d4 |
if (SetEnvironmentVariableEBA(&lpszEnvironmentBlockNew, "test", "5"))
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
if (GetEnvironmentVariableEBA(lpszEnvironmentBlockNew, "test", test, 1023))
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
if (strcmp(test, "5") != 0)
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
else
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
}
|
|
Packit Service |
5a9772 |
|
|
Packit |
1fb8d4 |
/* Clear variable */
|
|
Packit |
1fb8d4 |
if (SetEnvironmentVariableEBA(&lpszEnvironmentBlockNew, "test", NULL))
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
if (GetEnvironmentVariableEBA(lpszEnvironmentBlockNew, "test", test, 1023))
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
else
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
// not found .. this is expected
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
}
|
|
Packit Service |
5a9772 |
|
|
Packit |
1fb8d4 |
free(lpszEnvironmentBlockNew);
|
|
Packit Service |
5a9772 |
lpszEnvironmentBlockNew = (LPTCH)calloc(1024, sizeof(TCHAR));
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
if (!lpszEnvironmentBlockNew)
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
|
|
Packit Service |
5a9772 |
memcpy(lpszEnvironmentBlockNew, lpszEnvironmentBlock, length);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Set variable in empty environment block */
|
|
Packit |
1fb8d4 |
if (SetEnvironmentVariableEBA(&lpszEnvironmentBlockNew, "test", "5"))
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
if (0 != GetEnvironmentVariableEBA(lpszEnvironmentBlockNew, "testr", test, 1023))
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
printf("GetEnvironmentVariableEBA returned unset variable\n");
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
}
|
|
Packit Service |
5a9772 |
|
|
Packit Service |
5a9772 |
if (GetEnvironmentVariableEBA(lpszEnvironmentBlockNew, "test", test, 1023))
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
if (strcmp(test, "5") != 0)
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
else
|
|
Packit Service |
5a9772 |
goto fail;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit Service |
5a9772 |
rc = 0;
|
|
Packit Service |
5a9772 |
fail:
|
|
Packit Service |
5a9772 |
free(p);
|
|
Packit |
1fb8d4 |
free(lpszEnvironmentBlockNew);
|
|
Packit |
1fb8d4 |
#endif
|
|
Packit Service |
5a9772 |
return rc;
|
|
Packit |
1fb8d4 |
}
|