summaryrefslogtreecommitdiffstats
path: root/winpr/libwinpr/environment/test/TestEnvironmentGetEnvironmentStrings.c
blob: c5963998eb45f0725736eb184895abde9d1814ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/tchar.h>
#include <winpr/environment.h>

int TestEnvironmentGetEnvironmentStrings(int argc, char* argv[])
{
	int r = -1;
	TCHAR* p = NULL;
	size_t length = 0;
	LPTCH lpszEnvironmentBlock = NULL;

	WINPR_UNUSED(argc);
	WINPR_UNUSED(argv);

	lpszEnvironmentBlock = GetEnvironmentStrings();

	p = lpszEnvironmentBlock;

	while (p[0] && p[1])
	{
		const int rc = _sntprintf(NULL, 0, _T("%s\n"), p);
		if (rc < 1)
		{
			_tprintf(_T("test failed: return %d\n"), rc);
			goto fail;
		}
		length = _tcslen(p);
		if (length != (size_t)(rc - 1))
		{
			_tprintf(_T("test failed: length %") _T(PRIuz) _T(" != %d [%s]\n"), length, rc - 1, p);
			goto fail;
		}
		p += (length + 1);
	}

	r = 0;
fail:
	FreeEnvironmentStrings(lpszEnvironmentBlock);

	return r;
}