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 | ** Pass a nonexisting environment variable and a null to |
11 | ** the function to check return values. |
12 | ** |
13 | ** |
14 | **=========================================================*/ |
15 | |
16 | #include <palsuite.h> |
17 | |
18 | #define BUFFER_SIZE 5000 |
19 | #define SMALL_BUFFER_SIZE 5 |
20 | |
21 | int __cdecl main(int argc, char *argv[]) |
22 | { |
23 | |
24 | int ReturnValueForNonExisting = 0; |
25 | int ReturnValueForNull = 0; |
26 | |
27 | char pResultBuffer[BUFFER_SIZE]; |
28 | char pSmallBuffer[SMALL_BUFFER_SIZE]; |
29 | |
30 | if(0 != (PAL_Initialize(argc, argv))) |
31 | { |
32 | return FAIL; |
33 | } |
34 | |
35 | /* This variable doesn't exist, it should return 0 */ |
36 | ReturnValueForNonExisting = GetEnvironmentVariable("NonExistingVariable" , |
37 | pSmallBuffer, |
38 | SMALL_BUFFER_SIZE); |
39 | |
40 | if(ReturnValueForNonExisting != 0) |
41 | { |
42 | Fail("ERROR: The return should have been 0, but it was %d. " |
43 | "The function attempted to get an Environment Variable that " |
44 | "doesn't exist and should return 0 as a result.\n" , |
45 | ReturnValueForNonExisting); |
46 | } |
47 | |
48 | |
49 | /* Passing a NULL string should return 0 */ |
50 | ReturnValueForNull = GetEnvironmentVariable(NULL, |
51 | pResultBuffer, |
52 | BUFFER_SIZE); |
53 | |
54 | if(ReturnValueForNull != 0) |
55 | { |
56 | Fail("ERROR: The return should have been 0, but it was %d. " |
57 | "The function attempted to get a NULL pointer and should return " |
58 | "0 as a result.\n" ,ReturnValueForNull); |
59 | |
60 | } |
61 | |
62 | PAL_Terminate(); |
63 | return PASS; |
64 | } |
65 | |
66 | |
67 | |
68 | |