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[])
|
|
|
|
{
|
2013-10-31 01:56:44 +04:00
|
|
|
#ifndef _WIN32
|
2013-10-23 13:27:31 +04:00
|
|
|
char test[1024];
|
|
|
|
TCHAR* p;
|
|
|
|
int length;
|
|
|
|
LPTCH lpszEnvironmentBlock = "SHELL=123\0test=1\0test1=2\0DISPLAY=WINPR_TEST_VALUE\0\0";
|
|
|
|
LPTCH lpszEnvironmentBlockNew = NULL;
|
|
|
|
|
|
|
|
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock,"DISPLAY", NULL, 0);
|
|
|
|
|
|
|
|
p = (LPSTR) malloc(length);
|
|
|
|
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock,"DISPLAY", p, length);
|
|
|
|
|
|
|
|
printf("GetEnvironmentVariableA(WINPR_TEST_VARIABLE) = %s\n" , p);
|
|
|
|
|
|
|
|
if (strcmp(p, "WINPR_TEST_VALUE") != 0)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(p);
|
|
|
|
|
2013-10-31 01:56:44 +04:00
|
|
|
lpszEnvironmentBlockNew = (LPTCH) malloc(1024);
|
2013-10-23 14:43:06 +04:00
|
|
|
memcpy(lpszEnvironmentBlockNew,lpszEnvironmentBlock,56);
|
|
|
|
|
2013-10-31 01:56:44 +04:00
|
|
|
if (SetEnvironmentVariableEBA(&lpszEnvironmentBlockNew, "test", "5"))
|
|
|
|
{
|
|
|
|
if (GetEnvironmentVariableEBA(lpszEnvironmentBlockNew,"test", test, 1023))
|
|
|
|
{
|
|
|
|
if (strcmp(test,"5") != 0)
|
|
|
|
{
|
2013-10-23 13:27:31 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2013-10-31 01:56:44 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-23 13:27:31 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-23 14:43:06 +04:00
|
|
|
//free(lpszEnvironmentBlockNew);
|
2013-10-23 13:27:31 +04:00
|
|
|
|
2013-10-31 01:56:44 +04:00
|
|
|
if (SetEnvironmentVariableEBA(&lpszEnvironmentBlockNew, "test", NULL))
|
|
|
|
{
|
|
|
|
if (GetEnvironmentVariableEBA(lpszEnvironmentBlockNew,"test", test, 1023))
|
|
|
|
{
|
2013-10-23 13:27:31 +04:00
|
|
|
return -1;
|
2013-10-31 01:56:44 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-23 13:27:31 +04:00
|
|
|
// not found .. this is expected
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(lpszEnvironmentBlockNew);
|
2013-10-31 01:56:44 +04:00
|
|
|
#endif
|
2013-10-23 13:27:31 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|