1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*============================================================
6**
7** Source : test.c
8**
9** Purpose: Test for GetEnvironmentStringsW() function
10**
11**
12**=========================================================*/
13
14/* Depends on SetEnvironmentVariable(), wcsstr() and wcslen() */
15
16#define UNICODE
17#include <palsuite.h>
18
19int __cdecl main(int argc, char *argv[]) {
20
21 LPWSTR CapturedEnvironmentStrings = NULL;
22 LPWSTR EnviroStringReturned = NULL;
23 WCHAR EnvironmentVariableBuffer[] =
24 {'P','A','L','T','E','S','T','I','N','G','\0'};
25 WCHAR EnvironmentValueBuffer[] = {'T','e','s','t','i','n','g','\0'};
26
27 /*
28 * Initialize the PAL and return FAILURE if this fails
29 */
30
31 if(0 != (PAL_Initialize(argc, argv)))
32 {
33 return FAIL;
34 }
35
36 /* This test depends on SetEnvironmentVariableW working.
37 We need to set a variable so we can test and ensure it's there
38 when we get them back
39 */
40
41 SetEnvironmentVariable(EnvironmentVariableBuffer,EnvironmentValueBuffer);
42
43 CapturedEnvironmentStrings = GetEnvironmentStrings();
44
45 /* If it's pointing to NULL, it failed. */
46 if(CapturedEnvironmentStrings == NULL) {
47 Fail("The function returned a pointer to NULL, which it shouldn't do. "
48 "It should point to a block of Environment Strings.\n");
49 }
50
51 /* Now that we've grabbed the list of envrionment strings, go through
52 each one, and check for a match to 'PALTESTING'. If this is missing
53 it's not pointing at the environment block.
54 */
55
56 while(*CapturedEnvironmentStrings != 0)
57 {
58 EnviroStringReturned = wcsstr(CapturedEnvironmentStrings,
59 EnvironmentVariableBuffer);
60 CapturedEnvironmentStrings += wcslen(CapturedEnvironmentStrings)+1;
61 if(EnviroStringReturned != NULL)
62 {
63 break;
64 }
65 }
66
67 if(EnviroStringReturned == NULL)
68 {
69 Fail("The memory block returned was searched, but nothing was found to "
70 "prove this was really the environment block. Either this "
71 "function, SetEnvironmentVariable or wcsstr() is broken.\n");
72 }
73
74
75 PAL_Terminate();
76 return PASS;
77}
78
79
80
81
82