2013-10-23 13:27:31 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/tchar.h>
|
|
|
|
#include <winpr/environment.h>
|
|
|
|
|
|
|
|
int TestEnvironmentGetSetEB(int argc, char* argv[])
|
|
|
|
{
|
2019-04-05 14:17:24 +03:00
|
|
|
int rc = 0;
|
2013-10-31 01:56:44 +04:00
|
|
|
#ifndef _WIN32
|
2013-10-23 13:27:31 +04:00
|
|
|
char test[1024];
|
2019-04-05 14:17:24 +03:00
|
|
|
TCHAR* p = NULL;
|
2019-02-07 16:35:21 +03:00
|
|
|
DWORD length;
|
2013-10-23 13:27:31 +04:00
|
|
|
LPTCH lpszEnvironmentBlock = "SHELL=123\0test=1\0test1=2\0DISPLAY=WINPR_TEST_VALUE\0\0";
|
|
|
|
LPTCH lpszEnvironmentBlockNew = NULL;
|
2019-04-05 14:17:24 +03:00
|
|
|
rc = -1;
|
2014-02-14 13:59:10 +04:00
|
|
|
/* Get length of an variable */
|
2019-04-05 14:17:24 +03:00
|
|
|
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock, "DISPLAY", NULL, 0);
|
|
|
|
|
2014-02-14 13:59:10 +04:00
|
|
|
if (0 == length)
|
|
|
|
return -1;
|
2013-10-23 13:27:31 +04:00
|
|
|
|
2014-02-14 13:59:10 +04:00
|
|
|
/* Get the variable itself */
|
2013-10-23 13:27:31 +04:00
|
|
|
p = (LPSTR) malloc(length);
|
2019-04-05 14:17:24 +03:00
|
|
|
|
2015-04-03 17:21:01 +03:00
|
|
|
if (!p)
|
2019-04-05 14:17:24 +03:00
|
|
|
goto fail;
|
2015-04-03 17:21:01 +03:00
|
|
|
|
2019-04-05 14:17:24 +03:00
|
|
|
if (GetEnvironmentVariableEBA(lpszEnvironmentBlock, "DISPLAY", p, length) != length - 1)
|
|
|
|
goto fail;
|
2013-10-23 13:27:31 +04:00
|
|
|
|
2019-04-05 14:17:24 +03:00
|
|
|
printf("GetEnvironmentVariableA(WINPR_TEST_VARIABLE) = %s\n", p);
|
2013-10-23 13:27:31 +04:00
|
|
|
|
|
|
|
if (strcmp(p, "WINPR_TEST_VALUE") != 0)
|
2019-04-05 14:17:24 +03:00
|
|
|
goto fail;
|
2013-10-23 13:27:31 +04:00
|
|
|
|
2014-02-14 13:59:10 +04:00
|
|
|
/* Get length of an non-existing variable */
|
2019-04-05 14:17:24 +03:00
|
|
|
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock, "BLA", NULL, 0);
|
|
|
|
|
2014-02-14 13:59:10 +04:00
|
|
|
if (0 != length)
|
|
|
|
{
|
|
|
|
printf("Unset variable returned\n");
|
2019-04-05 14:17:24 +03:00
|
|
|
goto fail;
|
2014-02-14 13:59:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get length of an similar called variables */
|
2019-04-05 14:17:24 +03:00
|
|
|
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock, "XDISPLAY", NULL, 0);
|
|
|
|
|
2014-02-14 13:59:10 +04:00
|
|
|
if (0 != length)
|
|
|
|
{
|
|
|
|
printf("Similar named variable returned (XDISPLAY, length %d)\n", length);
|
2019-04-05 14:17:24 +03:00
|
|
|
goto fail;
|
2014-02-14 13:59:10 +04:00
|
|
|
}
|
2019-04-05 14:17:24 +03:00
|
|
|
|
|
|
|
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock, "DISPLAYX", NULL, 0);
|
|
|
|
|
2014-02-14 13:59:10 +04:00
|
|
|
if (0 != length)
|
|
|
|
{
|
|
|
|
printf("Similar named variable returned (DISPLAYX, length %d)\n", length);
|
2019-04-05 14:17:24 +03:00
|
|
|
goto fail;
|
2014-02-14 13:59:10 +04:00
|
|
|
}
|
2019-04-05 14:17:24 +03:00
|
|
|
|
|
|
|
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock, "DISPLA", NULL, 0);
|
|
|
|
|
2014-02-14 13:59:10 +04:00
|
|
|
if (0 != length)
|
|
|
|
{
|
|
|
|
printf("Similar named variable returned (DISPLA, length %d)\n", length);
|
2019-04-05 14:17:24 +03:00
|
|
|
goto fail;
|
2014-02-14 13:59:10 +04:00
|
|
|
}
|
2019-04-05 14:17:24 +03:00
|
|
|
|
|
|
|
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock, "ISPLAY", NULL, 0);
|
|
|
|
|
2014-02-14 13:59:10 +04:00
|
|
|
if (0 != length)
|
|
|
|
{
|
|
|
|
printf("Similar named variable returned (ISPLAY, length %d)\n", length);
|
2019-04-05 14:17:24 +03:00
|
|
|
goto fail;
|
2014-02-14 13:59:10 +04:00
|
|
|
}
|
2013-10-23 14:43:06 +04:00
|
|
|
|
2014-02-14 13:59:10 +04:00
|
|
|
/* Set variable in empty environment block */
|
2013-10-31 01:56:44 +04:00
|
|
|
if (SetEnvironmentVariableEBA(&lpszEnvironmentBlockNew, "test", "5"))
|
|
|
|
{
|
2019-04-05 14:17:24 +03:00
|
|
|
if (GetEnvironmentVariableEBA(lpszEnvironmentBlockNew, "test", test, 1023))
|
2013-10-31 01:56:44 +04:00
|
|
|
{
|
2019-04-05 14:17:24 +03:00
|
|
|
if (strcmp(test, "5") != 0)
|
|
|
|
goto fail;
|
2013-10-31 01:56:44 +04:00
|
|
|
}
|
|
|
|
else
|
2019-04-05 14:17:24 +03:00
|
|
|
goto fail;
|
2013-10-23 13:27:31 +04:00
|
|
|
}
|
2019-04-05 14:17:24 +03:00
|
|
|
|
2014-02-14 13:59:10 +04:00
|
|
|
/* Clear variable */
|
2013-10-31 01:56:44 +04:00
|
|
|
if (SetEnvironmentVariableEBA(&lpszEnvironmentBlockNew, "test", NULL))
|
|
|
|
{
|
2019-04-05 14:17:24 +03:00
|
|
|
if (GetEnvironmentVariableEBA(lpszEnvironmentBlockNew, "test", test, 1023))
|
|
|
|
goto fail;
|
2013-10-31 01:56:44 +04:00
|
|
|
else
|
|
|
|
{
|
2013-10-23 13:27:31 +04:00
|
|
|
// not found .. this is expected
|
|
|
|
}
|
|
|
|
}
|
2014-02-14 13:59:10 +04:00
|
|
|
|
2019-04-05 14:17:24 +03:00
|
|
|
free(lpszEnvironmentBlockNew);
|
2015-09-03 14:37:16 +03:00
|
|
|
lpszEnvironmentBlockNew = (LPTCH) calloc(1024, sizeof(TCHAR));
|
2019-04-05 14:17:24 +03:00
|
|
|
|
2015-04-03 17:21:01 +03:00
|
|
|
if (!lpszEnvironmentBlockNew)
|
2019-04-05 14:17:24 +03:00
|
|
|
goto fail;
|
2015-04-03 17:21:01 +03:00
|
|
|
|
2019-04-05 14:17:24 +03:00
|
|
|
memcpy(lpszEnvironmentBlockNew, lpszEnvironmentBlock, length);
|
2014-02-14 13:59:10 +04:00
|
|
|
|
|
|
|
/* Set variable in empty environment block */
|
|
|
|
if (SetEnvironmentVariableEBA(&lpszEnvironmentBlockNew, "test", "5"))
|
|
|
|
{
|
2019-04-05 14:17:24 +03:00
|
|
|
if (0 != GetEnvironmentVariableEBA(lpszEnvironmentBlockNew, "testr", test, 1023))
|
2014-02-14 13:59:10 +04:00
|
|
|
{
|
|
|
|
printf("GetEnvironmentVariableEBA returned unset variable\n");
|
2019-04-05 14:17:24 +03:00
|
|
|
goto fail;
|
2014-02-14 13:59:10 +04:00
|
|
|
}
|
2019-04-05 14:17:24 +03:00
|
|
|
|
|
|
|
if (GetEnvironmentVariableEBA(lpszEnvironmentBlockNew, "test", test, 1023))
|
2014-02-14 13:59:10 +04:00
|
|
|
{
|
2019-04-05 14:17:24 +03:00
|
|
|
if (strcmp(test, "5") != 0)
|
|
|
|
goto fail;
|
2014-02-14 13:59:10 +04:00
|
|
|
}
|
|
|
|
else
|
2019-04-05 14:17:24 +03:00
|
|
|
goto fail;
|
2014-02-14 13:59:10 +04:00
|
|
|
}
|
2013-10-23 13:27:31 +04:00
|
|
|
|
2019-04-05 14:17:24 +03:00
|
|
|
rc = 0;
|
|
|
|
fail:
|
|
|
|
free(p);
|
2013-10-23 13:27:31 +04:00
|
|
|
free(lpszEnvironmentBlockNew);
|
2013-10-31 01:56:44 +04:00
|
|
|
#endif
|
2019-04-05 14:17:24 +03:00
|
|
|
return rc;
|
2013-10-23 13:27:31 +04:00
|
|
|
}
|
|
|
|
|