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 GetEnvironmentVariable() function
10** Set an Environment Variable, then use GetEnvironmentVariable to
11** retrieve it -- ensure that it retrieves properly.
12**
13**
14**=========================================================*/
15
16/* Depends on SetEnvironmentVariableW (because we're implmenting
17 the wide version) and strcmp()
18*/
19
20#include <palsuite.h>
21
22int __cdecl main(int argc, char *argv[]) {
23
24 /* Define some buffers needed for the function */
25 char * pResultBuffer = NULL;
26 WCHAR SomeEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'};
27 WCHAR TheEnvironmentValue[] = {'T','E','S','T','\0'};
28 int size = 0;
29
30 /*
31 * Initialize the PAL and return FAILURE if this fails
32 */
33
34 if(0 != (PAL_Initialize(argc, argv)))
35 {
36 return FAIL;
37 }
38
39 SetEnvironmentVariableW(SomeEnvironmentVariable,
40 TheEnvironmentValue);
41
42
43 /* Normal case, PATH should fit into this buffer */
44 size = GetEnvironmentVariable("PALTEST", // Variable Name
45 pResultBuffer, // Buffer for Value
46 0); // Buffer size
47
48 pResultBuffer = (char*)malloc(size);
49 if ( pResultBuffer == NULL )
50 {
51 Fail("ERROR: Failed to allocate memory for pResultBuffer pointer. "
52 "Can't properly exec test case without this.\n");
53 }
54
55
56 GetEnvironmentVariable("PALTEST",
57 pResultBuffer,
58 size);
59
60 if(strcmp(pResultBuffer,"TEST") != 0)
61 {
62 free(pResultBuffer);
63 Fail("ERROR: The value in the buffer should have been 'TEST' but "
64 "was really '%s'.\n",pResultBuffer);
65
66 }
67
68 free(pResultBuffer);
69
70 PAL_Terminate();
71 return PASS;
72}
73
74
75
76