diff options
Diffstat (limited to 'src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW')
19 files changed, 731 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/CMakeLists.txt new file mode 100644 index 0000000000..7c20179353 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) +add_subdirectory(test3) +add_subdirectory(test4) +add_subdirectory(test5) +add_subdirectory(test6) + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/CMakeLists.txt new file mode 100644 index 0000000000..567c992461 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test.c +) + +add_executable(paltest_getenvironmentvariablew_test1 + ${SOURCES} +) + +add_dependencies(paltest_getenvironmentvariablew_test1 coreclrpal) + +target_link_libraries(paltest_getenvironmentvariablew_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/test.c new file mode 100644 index 0000000000..6c764509d0 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/test.c @@ -0,0 +1,79 @@ +// 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 : test.c +** +** Purpose: Test for GetEnvironmentVariable() function +** +** +**=========================================================*/ + +#define UNICODE +#include <palsuite.h> + +int __cdecl main(int argc, char *argv[]) +{ + + /* Define some buffers needed for the function */ + WCHAR * pResultBuffer = NULL; + int size = 0; + + /* A place to stash the returned values */ + int ReturnValueForLargeBuffer = 0; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Recieve and allocate the correct amount of memory for the buffer */ + size = ReturnValueForLargeBuffer = + GetEnvironmentVariable(convert("PATH"), + pResultBuffer, + 0); + + pResultBuffer = malloc(size*sizeof(WCHAR)); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer. " + "Can't properly exec test case without this.\n"); + } + + + /* Normal case, PATH should fit into this buffer */ + ReturnValueForLargeBuffer = GetEnvironmentVariable(convert("PATH"), + pResultBuffer, + size); + free(pResultBuffer); + + /* Ensure that it returned a positive value */ + if(ReturnValueForLargeBuffer <= 0) + { + Fail("The return was %d, which indicates that the function failed.\n", + ReturnValueForLargeBuffer); + } + + /* Ensure that it succeeded and copied the correct number of characters. + If this is true, then the return value should be one less of the + size of the buffer. (Doesn't include that NULL byte) + */ + if(ReturnValueForLargeBuffer != size-1) + { + Fail("The value returned was %d when it should have been %d. This " + "should be the number of characters copied, " + "minus the NULL byte.\n", ReturnValueForLargeBuffer, size-1); + } + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/testinfo.dat new file mode 100644 index 0000000000..467f2b7b94 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/testinfo.dat @@ -0,0 +1,16 @@ +# 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 = GetEnvironmentVariableW +Name = Return value test for GetEnvironmentVariableW +TYPE = DEFAULT +EXE1 = test +Description += Assign a properly sized buffer and get an environment variable, += check to ensure it returns the correct values. + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/CMakeLists.txt new file mode 100644 index 0000000000..7234f61ed3 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test.c +) + +add_executable(paltest_getenvironmentvariablew_test2 + ${SOURCES} +) + +add_dependencies(paltest_getenvironmentvariablew_test2 coreclrpal) + +target_link_libraries(paltest_getenvironmentvariablew_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/test.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/test.c new file mode 100644 index 0000000000..6fa753c8d3 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/test.c @@ -0,0 +1,56 @@ +// 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 : test.c +** +** Purpose: Test for GetEnvironmentVariable() function +** +** +**=========================================================*/ + +#define UNICODE + +#include <palsuite.h> + +#define SMALL_BUFFER_SIZE 1 + +int __cdecl main(int argc, char *argv[]) +{ + + WCHAR pSmallBuffer[SMALL_BUFFER_SIZE]; + + /* A place to stash the returned values */ + int ReturnValueForSmallBuffer; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* PATH won't fit in this buffer, it should return how many characters + it needs + */ + + ReturnValueForSmallBuffer = GetEnvironmentVariable(convert("PATH"), + pSmallBuffer, + SMALL_BUFFER_SIZE); + + if(ReturnValueForSmallBuffer <= 0) + { + Fail("The return value was %d when it should have been greater " + "than 0. This should return the number of characters needed " + "to contained the contents of PATH in a buffer.\n", + ReturnValueForSmallBuffer); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/testinfo.dat new file mode 100644 index 0000000000..372f5af316 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/testinfo.dat @@ -0,0 +1,16 @@ +# 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 = GetEnvironmentVariableW +Name = Return value test on GetEnvironmentVariableW +TYPE = DEFAULT +EXE1 = test +Description += Pass a small buffer to GetEnvironmentVariableW += to ensure it returns the size it requires. + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/CMakeLists.txt new file mode 100644 index 0000000000..bafd75e52e --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test.c +) + +add_executable(paltest_getenvironmentvariablew_test3 + ${SOURCES} +) + +add_dependencies(paltest_getenvironmentvariablew_test3 coreclrpal) + +target_link_libraries(paltest_getenvironmentvariablew_test3 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/test.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/test.c new file mode 100644 index 0000000000..03781e723f --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/test.c @@ -0,0 +1,71 @@ +// 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 : test.c +** +** Purpose: Test for GetEnvironmentVariable() function +** +** +**=========================================================*/ + +#define UNICODE +#include <palsuite.h> + +#define BUFFER_SIZE 5000 +#define SMALL_BUFFER_SIZE 5 + +int __cdecl main(int argc, char *argv[]) +{ + + /* Define some buffers needed for the function */ + WCHAR pResultBuffer[BUFFER_SIZE]; + WCHAR pSmallBuffer[SMALL_BUFFER_SIZE]; + + /* A place to stash the returned values */ + int ReturnValueForNonExisting, ReturnValueForNull; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* This variable doesn't exist, it should return 0 */ + ReturnValueForNonExisting = + GetEnvironmentVariable(convert("NonExistingVariable"), + pSmallBuffer, + SMALL_BUFFER_SIZE); + + if(ReturnValueForNonExisting != 0) + { + Fail("ERROR: The return should have been 0, but it was %d. The " + "function attempted to get an Environment Variable that doesn't " + "exist and should return 0 as a result.\n", + ReturnValueForNonExisting); + } + + + /* Passing a NULL string should return 0 */ + ReturnValueForNull = GetEnvironmentVariable(NULL, + pResultBuffer, + BUFFER_SIZE); + + if(ReturnValueForNull != 0) + { + Fail("ERROR: The return should have been 0, but it was %d. The " + "function attempted to get a NULL pointer and should return 0 " + "as a result.\n",ReturnValueForNull); + } + + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/testinfo.dat new file mode 100644 index 0000000000..d41c19c908 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/testinfo.dat @@ -0,0 +1,16 @@ +# 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 = GetEnvironmentVariableW +Name = Return value test for GetEnvironmentVariableW +TYPE = DEFAULT +EXE1 = test +Description += Pass a nonexisting environment variable and a null to the function += to check return values. + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/CMakeLists.txt new file mode 100644 index 0000000000..f870bd6b22 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test.c +) + +add_executable(paltest_getenvironmentvariablew_test4 + ${SOURCES} +) + +add_dependencies(paltest_getenvironmentvariablew_test4 coreclrpal) + +target_link_libraries(paltest_getenvironmentvariablew_test4 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/test.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/test.c new file mode 100644 index 0000000000..b5894efc6e --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/test.c @@ -0,0 +1,63 @@ +// 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 : test.c +** +** Purpose: Test for GetEnvironmentVariable() function +** +** +**=========================================================*/ + +/* Depends on SetEnvironmentVariableW (because we're implmenting the wide + version) and strcmp() */ + +#define UNICODE +#include <palsuite.h> + +int __cdecl main(int argc, char *argv[]) { + + /* Define some buffers needed for the function */ + WCHAR * pResultBuffer = NULL; + WCHAR SomeEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; + WCHAR TheEnvironmentValue[] = {'T','E','S','T','\0'}; + int size; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + SetEnvironmentVariable(SomeEnvironmentVariable, + TheEnvironmentValue); + + + /* Normal case, PATH should fit into this buffer */ + size = GetEnvironmentVariable(convert("PALTEST"), // Variable Name + pResultBuffer, // Buffer for Value + 0); // Buffer size + + pResultBuffer = malloc(size*sizeof(WCHAR)); + + GetEnvironmentVariable(convert("PALTEST"), + pResultBuffer, + size); + + if(wcsncmp(pResultBuffer,convert("TEST"),wcslen(pResultBuffer) * 2) != 0) + { + Fail("ERROR: The value in the buffer should have been 'TEST' but was " + "really '%s'.",convertC(pResultBuffer)); + } + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/testinfo.dat new file mode 100644 index 0000000000..64204fa698 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/testinfo.dat @@ -0,0 +1,16 @@ +# 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 = GetEnvironmentVariableW +Name = Positive Test for GetEnvironmentVariableW +TYPE = DEFAULT +EXE1 = test +Description += Set an Environment Variable, then use GetEnvironmentVariable += to retrieve it -- ensure that it retrieves properly. + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/CMakeLists.txt new file mode 100644 index 0000000000..ab44781279 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test5.c +) + +add_executable(paltest_getenvironmentvariablew_test5 + ${SOURCES} +) + +add_dependencies(paltest_getenvironmentvariablew_test5 coreclrpal) + +target_link_libraries(paltest_getenvironmentvariablew_test5 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/test5.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/test5.c new file mode 100644 index 0000000000..58eba3a380 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/test5.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 : test5.c +** +** Purpose: Test for GetEnvironmentVariableW() 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 */ + WCHAR * pResultBuffer = NULL; + + WCHAR FirstEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; + WCHAR FirstEnvironmentValue[] = {'F','I','R','S','T','\0'}; + + WCHAR SecondEnvironmentVariable[] = {'p','a','l','t','e','s','t','\0'}; + WCHAR SecondEnvironmentValue[] = {'S','E','C','O','N','D','\0'}; + + 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 = SetEnvironmentVariableW(FirstEnvironmentVariable, + FirstEnvironmentValue); + + 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 = GetEnvironmentVariableW(FirstEnvironmentVariable, + pResultBuffer, + 0); + + /* To account for the nul character at the end of the string */ + size = size + 1; + + pResultBuffer = malloc(sizeof(WCHAR)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try to retrieve the value of the first environment variable */ + GetEnvironmentVariableW(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(wcsncmp(pResultBuffer,FirstEnvironmentValue,wcslen(pResultBuffer)) != 0) + { + free(pResultBuffer); + Fail("ERROR: The value in the buffer should have been '%S' but " + "was really '%S'.\n",FirstEnvironmentValue, pResultBuffer); + } + + free(pResultBuffer); + + /* Set the second environment Variable */ + bRc = SetEnvironmentVariableW(SecondEnvironmentVariable, + SecondEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", + GetLastError()); + } + + /* Reallocate the memory for the string */ + pResultBuffer = malloc(sizeof(WCHAR)*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 */ + GetEnvironmentVariableW(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 two strings to confirm that the right value is returned */ + if(wcsncmp(pResultBuffer,FirstEnvironmentValue,wcslen(pResultBuffer)) != 0) + { + free(pResultBuffer); + Fail("ERROR: The value in the buffer should have been '%S' but " + "was really '%S'.\n",FirstEnvironmentValue,pResultBuffer); + } + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; + +#endif +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/testinfo.dat new file mode 100644 index 0000000000..cbc214e8ca --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/testinfo.dat @@ -0,0 +1,17 @@ +# 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 = GetEnvironmentVariableW +Name = Positive Test for GetEnvironmentVariableW +TYPE = DEFAULT +EXE1 = test5 +Description += Set an Environment Variable, then use GetEnvironmentVariable += to retrieve it. Then set another environment variable that differs += from the original variable only by case and verify that += GetEnvironmnetVariable returns the correct value. + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/CMakeLists.txt new file mode 100644 index 0000000000..e504c8323a --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test6.c +) + +add_executable(paltest_getenvironmentvariablew_test6 + ${SOURCES} +) + +add_dependencies(paltest_getenvironmentvariablew_test6 coreclrpal) + +target_link_libraries(paltest_getenvironmentvariablew_test6 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/test6.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/test6.c new file mode 100644 index 0000000000..85f31be9c2 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/test6.c @@ -0,0 +1,99 @@ +// 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 : test6.c +** +** Purpose: Test for GetEnvironmentVariableW() 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 + + /* Define some buffers needed for the function */ + WCHAR * pResultBuffer = NULL; + + WCHAR FirstEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; + WCHAR FirstEnvironmentValue[] = {'F','I','R','S','T','\0'}; + + WCHAR ModifiedEnvironmentVariable[] = {'p','a','l','t','e','s','t','\0'}; + + 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 = SetEnvironmentVariableW(FirstEnvironmentVariable, + FirstEnvironmentValue); + + 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 = GetEnvironmentVariableW(ModifiedEnvironmentVariable, + pResultBuffer, + 0); + + /* To account for the nul character at the end of the string */ + size = size + 1; + + pResultBuffer = malloc(sizeof(WCHAR)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try to retrieve the value of the first environment variable */ + GetEnvironmentVariableW(ModifiedEnvironmentVariable, + 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(wcsncmp(pResultBuffer,FirstEnvironmentValue,wcslen(pResultBuffer)) != 0) + { + free(pResultBuffer); + Fail("ERROR: The value in the buffer should have been '%S' but " + "was really '%S'.\n",FirstEnvironmentValue, pResultBuffer); + } + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; + + +#else + + return PASS; +#endif +} diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/testinfo.dat new file mode 100644 index 0000000000..fad1ad69a6 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/testinfo.dat @@ -0,0 +1,15 @@ +# 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 = GetEnvironmentVariableW +Name = Positive Test for GetEnvironmentVariableW +TYPE = DEFAULT +EXE1 = test6 +Description += Set an Environment Variable, then use GetEnvironmentVariable += to retrieve the Variable, using a name that differs only in += Case. In Windows this should not affect the return value += of the function. |