diff options
Diffstat (limited to 'src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3')
3 files changed, 181 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/CMakeLists.txt new file mode 100644 index 0000000000..159f574abe --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test3.c +) + +add_executable(paltest_setenvironmentvariablea_test3 + ${SOURCES} +) + +add_dependencies(paltest_setenvironmentvariablea_test3 coreclrpal) + +target_link_libraries(paltest_setenvironmentvariablea_test3 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/test3.c b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/test3.c new file mode 100644 index 0000000000..fa24275da7 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/test3.c @@ -0,0 +1,144 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================ +** Source : test3.c +** +** Purpose: Test for SetEnvironmentVariableA() function +** Create environment variables that differ only +** in case and verify that they return the appropriate +** value on the BSD environment. +** +** +===========================================================*/ + +#include <palsuite.h> + +int __cdecl main(int argc, char *argv[]) +{ + +#if WIN32 + + return PASS; + +#else + + /* Define some buffers needed for the function */ + char * pResultBuffer = NULL; + + char FirstEnvironmentVariable[] = {"PALTEST"}; + char FirstEnvironmentValue[] = {"FIRST"}; + + char SecondEnvironmentVariable[] = {"paltest"}; + char SecondEnvironmentValue[] = {"SECOND"}; + + DWORD size = 0; + BOOL bRc = TRUE; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Set the first environment variable */ + bRc = SetEnvironmentVariableA(FirstEnvironmentVariable, + FirstEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", + GetLastError()); + } + + /* Set the second environment Variable */ + bRc = SetEnvironmentVariableA(SecondEnvironmentVariable, + SecondEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", + GetLastError()); + } + + + /* Normal case, PATH should fit into this buffer */ + size = GetEnvironmentVariableA(FirstEnvironmentVariable, + pResultBuffer, + 0); + + /* increase size to account for the null char at the end */ + size = size + 1; + + pResultBuffer = malloc(sizeof(char)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try to retrieve the value of the first environment variable */ + GetEnvironmentVariable(FirstEnvironmentVariable, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + free(pResultBuffer); + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the strings to see that the correct variable was returned */ + if(strcmp(pResultBuffer,FirstEnvironmentValue) != 0) + { + Trace("ERROR: The value in the buffer should have been '%s' but " + "was really '%s'.\n",FirstEnvironmentValue, pResultBuffer); + free(pResultBuffer); + Fail(""); + } + + free(pResultBuffer); + + /* Reallocate the memory for the string */ + pResultBuffer = malloc(sizeof(char)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try retrieving the value of the first variable, even though the + second variable has the same spelling and only differs in case */ + GetEnvironmentVariable(SecondEnvironmentVariable, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the two strings to confirm that the right value is returned */ + if(strcmp(pResultBuffer,SecondEnvironmentValue) != 0) + { + Trace("ERROR: The value in the buffer should have been '%s' but " + "was really '%s'.\n",SecondEnvironmentValue,pResultBuffer); + free(pResultBuffer); + Fail(""); + } + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; + +#endif +} diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/testinfo.dat new file mode 100644 index 0000000000..05076bb376 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/testinfo.dat @@ -0,0 +1,18 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Miscellaneous +Function = SetEnvironmentVariableA +Name = Return value test of SetEnvironmentVariableA +TYPE = DEFAULT +EXE1 = test3 +Description += Test creating environment variables that differ only += by case and check that they are treated as separate += variables in the BSD operating system. + + + + |