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**
11**
12**=========================================================*/
13
14/* Depends on SetEnvironmentVariableW (because we're implmenting the wide
15 version) and strcmp() */
16
17#define UNICODE
18#include <palsuite.h>
19
20int __cdecl main(int argc, char *argv[]) {
21
22 /* Define some buffers needed for the function */
23 WCHAR * pResultBuffer = NULL;
24 WCHAR SomeEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'};
25 WCHAR TheEnvironmentValue[] = {'T','E','S','T','\0'};
26 int size;
27
28 /*
29 * Initialize the PAL and return FAILURE if this fails
30 */
31
32 if(0 != (PAL_Initialize(argc, argv)))
33 {
34 return FAIL;
35 }
36
37 SetEnvironmentVariable(SomeEnvironmentVariable,
38 TheEnvironmentValue);
39
40
41 /* Normal case, PATH should fit into this buffer */
42 size = GetEnvironmentVariable(convert("PALTEST"), // Variable Name
43 pResultBuffer, // Buffer for Value
44 0); // Buffer size
45
46 pResultBuffer = (WCHAR*)malloc(size*sizeof(WCHAR));
47
48 GetEnvironmentVariable(convert("PALTEST"),
49 pResultBuffer,
50 size);
51
52 if(wcsncmp(pResultBuffer,convert("TEST"),wcslen(pResultBuffer) * 2) != 0)
53 {
54 Fail("ERROR: The value in the buffer should have been 'TEST' but was "
55 "really '%s'.",convertC(pResultBuffer));
56 }
57
58 free(pResultBuffer);
59
60 PAL_Terminate();
61 return PASS;
62}
63
64