| 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: test2.c |
| 8 | ** |
| 9 | ** Purpose: Create environment variables that differ only in Case, and |
| 10 | ** verify that the BSD operating system treats the variables |
| 11 | ** differently. |
| 12 | ** |
| 13 | ** |
| 14 | **===================================================================*/ |
| 15 | |
| 16 | #include <palsuite.h> |
| 17 | |
| 18 | int __cdecl main(int argc, char **argv) |
| 19 | { |
| 20 | #if WIN32 |
| 21 | |
| 22 | return PASS; |
| 23 | |
| 24 | #else |
| 25 | |
| 26 | const char* FirstVariable = "PalTestingEnvironmentVariable=The value" ; |
| 27 | const char* SecondVariable = "PALTESTINGEnvironmentVariable=Different value" ; |
| 28 | const char* FirstVarName = "PalTestingEnvironmentVariable" ; |
| 29 | const char* SecondVarName = "PALTESTINGEnvironmentVariable" ; |
| 30 | const char* FirstVarValue = "The value" ; |
| 31 | const char* SecondVarValue = "Different value" ; |
| 32 | char* result; |
| 33 | |
| 34 | |
| 35 | if (0 != (PAL_Initialize(argc, argv))) |
| 36 | { |
| 37 | return FAIL; |
| 38 | } |
| 39 | |
| 40 | /* Use _putenv to set the environment variables. This ensures that the |
| 41 | variables we're testing with are always present. |
| 42 | */ |
| 43 | if(_putenv(FirstVariable) != 0) |
| 44 | { |
| 45 | Fail("ERROR: _putenv failed to set an environment variable that " |
| 46 | "getenv will be using for testing.\n" ); |
| 47 | } |
| 48 | |
| 49 | if(_putenv(SecondVariable) != 0) |
| 50 | { |
| 51 | Fail("ERROR: _putenv failed to set an environment variable that " |
| 52 | "getenv will be using for testing.\n" ); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /* Call getenv -- ensure it doesn't return NULL and the string it returns |
| 57 | is the value we set above. Also make sure that each environment variable, |
| 58 | differing only by case, returns it's own value. |
| 59 | */ |
| 60 | |
| 61 | result = getenv(FirstVarName); |
| 62 | if(result == NULL) |
| 63 | { |
| 64 | Fail("ERROR: The result of getenv on a valid Environment Variable " |
| 65 | "was NULL, which indicates the environment varaible was not " |
| 66 | "found.\n" ); |
| 67 | } |
| 68 | |
| 69 | if(strcmp(result, FirstVarValue) != 0) |
| 70 | { |
| 71 | Fail("ERROR: The value obtained by getenv() was not equal to the " |
| 72 | "correct value of the environment variable. The correct " |
| 73 | "value is '%s' and the function returned '%s'.\n" , |
| 74 | FirstVarValue, |
| 75 | result); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | result = getenv(SecondVarName); |
| 80 | if(result == NULL) |
| 81 | { |
| 82 | Fail("ERROR: The result of getenv on a valid Environment Variable " |
| 83 | "was NULL, which indicates the environment varaible was not " |
| 84 | "found.\n" ); |
| 85 | } |
| 86 | |
| 87 | if(strcmp(result, SecondVarValue) != 0) |
| 88 | { |
| 89 | Fail("ERROR: The value obtained by getenv() was not equal to the " |
| 90 | "correct value of the environment variable. The correct " |
| 91 | "value is '%s' and the function returned '%s'.\n" , |
| 92 | SecondVarValue, |
| 93 | result); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | PAL_Terminate(); |
| 98 | return PASS; |
| 99 | |
| 100 | #endif |
| 101 | } |
| 102 | |