summaryrefslogtreecommitdiffstats
path: root/winpr/libwinpr/environment/test/TestEnvironmentGetEnvironmentStrings.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--winpr/libwinpr/environment/test/TestEnvironmentGetEnvironmentStrings.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/winpr/libwinpr/environment/test/TestEnvironmentGetEnvironmentStrings.c b/winpr/libwinpr/environment/test/TestEnvironmentGetEnvironmentStrings.c
new file mode 100644
index 0000000..c596399
--- /dev/null
+++ b/winpr/libwinpr/environment/test/TestEnvironmentGetEnvironmentStrings.c
@@ -0,0 +1,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;
+}