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 | #define UNICODE |
15 | #include <palsuite.h> |
16 | |
17 | #define BUFFER_SIZE 5000 |
18 | #define SMALL_BUFFER_SIZE 5 |
19 | |
20 | int __cdecl main(int argc, char *argv[]) |
21 | { |
22 | |
23 | /* Define some buffers needed for the function */ |
24 | WCHAR pResultBuffer[BUFFER_SIZE]; |
25 | WCHAR pSmallBuffer[SMALL_BUFFER_SIZE]; |
26 | |
27 | /* A place to stash the returned values */ |
28 | int ReturnValueForNonExisting, ReturnValueForNull; |
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 | /* This variable doesn't exist, it should return 0 */ |
40 | ReturnValueForNonExisting = |
41 | GetEnvironmentVariable(convert("NonExistingVariable" ), |
42 | pSmallBuffer, |
43 | SMALL_BUFFER_SIZE); |
44 | |
45 | if(ReturnValueForNonExisting != 0) |
46 | { |
47 | Fail("ERROR: The return should have been 0, but it was %d. The " |
48 | "function attempted to get an Environment Variable that doesn't " |
49 | "exist and should return 0 as a result.\n" , |
50 | ReturnValueForNonExisting); |
51 | } |
52 | |
53 | |
54 | /* Passing a NULL string should return 0 */ |
55 | ReturnValueForNull = GetEnvironmentVariable(NULL, |
56 | pResultBuffer, |
57 | BUFFER_SIZE); |
58 | |
59 | if(ReturnValueForNull != 0) |
60 | { |
61 | Fail("ERROR: The return should have been 0, but it was %d. The " |
62 | "function attempted to get a NULL pointer and should return 0 " |
63 | "as a result.\n" ,ReturnValueForNull); |
64 | } |
65 | |
66 | |
67 | PAL_Terminate(); |
68 | return PASS; |
69 | } |
70 | |
71 | |
72 | |