4#include <winpr/tchar.h>
5#include <winpr/environment.h>
6#include <winpr/error.h>
8#define TEST_NAME "WINPR_TEST_VARIABLE"
9#define TEST_VALUE "WINPR_TEST_VALUE"
10int TestEnvironmentSetEnvironmentVariable(
int argc,
char* argv[])
14 LPSTR lpBuffer = NULL;
20 SetEnvironmentVariableA(TEST_NAME, TEST_VALUE);
21 nSize = GetEnvironmentVariableA(TEST_NAME, NULL, 0);
24 if (nSize != strnlen(TEST_VALUE,
sizeof(TEST_VALUE)) + 1)
26 printf(
"GetEnvironmentVariableA not found error\n");
30 lpBuffer = (LPSTR)malloc(nSize);
35 nSize = GetEnvironmentVariableA(TEST_NAME, lpBuffer, nSize);
37 if (nSize != strnlen(TEST_VALUE,
sizeof(TEST_VALUE)))
39 printf(
"GetEnvironmentVariableA wrong size returned\n");
43 if (strcmp(lpBuffer, TEST_VALUE) != 0)
45 printf(
"GetEnvironmentVariableA returned value doesn't match\n");
49 nSize = GetEnvironmentVariableA(
"__xx__notset_", lpBuffer, nSize);
50 error = GetLastError();
52 if (0 != nSize || ERROR_ENVVAR_NOT_FOUND != error)
54 printf(
"GetEnvironmentVariableA not found error\n");
59 SetEnvironmentVariableA(TEST_NAME, NULL);
60 nSize = GetEnvironmentVariableA(TEST_VALUE, NULL, 0);
64 printf(
"SetEnvironmentVariableA failed to clear variable\n");