From db20f3f1bb8595633a7e16c8900fd401a453a6b5 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 27 Dec 2016 16:46:08 +0900 Subject: Imported Upstream version 1.0.0.9127 --- .../file_io/CreateDirectoryW/test1/CMakeLists.txt | 2 +- .../CreateDirectoryW/test1/CreateDirectoryW.c | 347 --------------------- .../CreateDirectoryW/test1/CreateDirectoryW.cpp | 347 +++++++++++++++++++++ .../file_io/CreateDirectoryW/test2/CMakeLists.txt | 2 +- .../CreateDirectoryW/test2/createdirectoryw.c | 345 -------------------- .../CreateDirectoryW/test2/createdirectoryw.cpp | 345 ++++++++++++++++++++ 6 files changed, 694 insertions(+), 694 deletions(-) delete mode 100644 src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.c create mode 100644 src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.c create mode 100644 src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.cpp (limited to 'src/pal/tests/palsuite/file_io/CreateDirectoryW') diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CMakeLists.txt index 1981e37082..f8cb584cc6 100644 --- a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateDirectoryW.c + CreateDirectoryW.cpp ) add_executable(paltest_createdirectoryw_test1 diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.c b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.c deleted file mode 100644 index 9b020cc19c..0000000000 --- a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.c +++ /dev/null @@ -1,347 +0,0 @@ -// 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: CreateDirectoryW.c -** -** Purpose: Tests the PAL implementation of the CreateDirectoryW function. -** -** -**===================================================================*/ - -#include - - -/* apparently, under WIN32 the max path size is 248 but under - BSD it is _MAX_PATH */ -#if WIN32 -#define CREATE_MAX_PATH_SIZE 248 -#else -#define CREATE_MAX_PATH_SIZE _MAX_PATH -#endif - - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bRc = FALSE; - BOOL bSuccess = FALSE; - const int buf_size = CREATE_MAX_PATH_SIZE + 10; - char szDirName[CREATE_MAX_PATH_SIZE + 10]; - char buffer[CREATE_MAX_PATH_SIZE + 10]; - WCHAR* pTemp = NULL; - DWORD curDirLen; - DWORD curDirectory = 1024; - - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* directory does not exist */ - pTemp = convert("test_directory"); - bRc = CreateDirectoryW(pTemp, NULL); - free(pTemp); - if (bRc == FALSE) - { - Fail("CreateDirectoryW: Failed to create \"test_directory\"\n"); - } - - /* directory exists */ - pTemp = convert("test_directory"); - bRc = CreateDirectoryW(pTemp, NULL); - if (bRc == TRUE) - { - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - Fail("CreateDirectoryW: Succeeded creating the directory" - " \"test_directory\" when it exists already.\n"); - } - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - - /* long directory names (CREATE_MAX_PATH_SIZE - 1, CREATE_MAX_PATH_SIZE - and CREATE_MAX_PATH_SIZE + 1 characters - including terminating null char) */ - - curDirLen = GetCurrentDirectoryA(0, NULL); - - memset(szDirName, 0, buf_size); - memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - 2 - curDirLen); - pTemp = convert((LPSTR)szDirName); - bRc = CreateDirectoryW(pTemp, NULL); - if (bRc == FALSE) - { - free(pTemp); - Fail("CreateDirectoryW: Failed to create a directory" - " name (%d) chars long with the error code %ld\n", - CREATE_MAX_PATH_SIZE - 1, - GetLastError()); - } - else - { - - /* Check to see if it's possible to navigate to directory */ - GetCurrentDirectoryA(curDirectory, buffer); - bSuccess = SetCurrentDirectoryA(szDirName); - if(!bSuccess) - { - Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " - "navigate to the newly created directory with error " - "code %u.\n", GetLastError()); - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - Fail(""); - - } - - /* Set directory back to initial directory */ - bRc = SetCurrentDirectoryA(buffer); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " - "change the directory with error %u.\n", - GetLastError()); - } - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - } - - - memset(szDirName, 0, buf_size); - memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - 1 - curDirLen); - pTemp = convert(szDirName); - bRc = CreateDirectoryW(pTemp, NULL); - if (bRc == FALSE) - { - free(pTemp); - Fail("CreateDirectoryW: Failed to create a directory" - " name %d chars long with error code %ld\n", - strlen(szDirName), - GetLastError()); - } - else - { - /* Check to see if it's possible to navigate to directory */ - GetCurrentDirectoryA(curDirectory, buffer); - bSuccess = SetCurrentDirectoryA(szDirName); - if(!bSuccess) - { - Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " - "navigate to the newly created directory with error " - "code %u.\n", GetLastError()); - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - Fail(""); - } - - /* Set directory back to initial directory */ - bRc = SetCurrentDirectoryA(buffer); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " - "change the directory with error %u.\n", - GetLastError()); - } - - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - } - - memset(szDirName, 0, buf_size); - memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - curDirLen); - pTemp = convert(szDirName); - bRc = CreateDirectoryW(pTemp, NULL); - - if (bRc != FALSE) - { - RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - if (strlen(szDirName) > CREATE_MAX_PATH_SIZE) - { - free(pTemp); - Fail("CreateDirectoryW: Failed because it created a directory" - " name 1 character longer (%d chars) than the max dir size" - " allowed\n", - strlen(szDirName)); - } - } - - free(pTemp); - - /* long directory name CREATE_MAX_PATH_SIZE + 3 chars including "..\" - (real path length <= CREATE_MAX_PATH_SIZE) */ - memset(szDirName, 0, buf_size); - memset(szDirName, 'a', CREATE_MAX_PATH_SIZE + 3 - 1 - curDirLen); - szDirName[0] = '.'; - szDirName[1] = '.'; - szDirName[2] = '\\'; - pTemp = convert(szDirName); - bRc = CreateDirectoryW(pTemp, NULL); - if (bRc == FALSE) - { - free(pTemp); - Fail("CreateDirectoryW: Failed to create a directory name more " - "than %d chars long and its real path name is less " - "than %d chars\n", - CREATE_MAX_PATH_SIZE, - CREATE_MAX_PATH_SIZE); - } - else - { - /* Check to see if it's possible to navigate to directory */ - GetCurrentDirectoryA(curDirectory, buffer); - bSuccess = SetCurrentDirectoryA(szDirName); - if(!bSuccess) - { - Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " - "navigate to the newly created directory with error " - "code %u.\n", GetLastError()); - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - Fail(""); - } - - /* Set directory back to initial directory */ - bRc = SetCurrentDirectoryA(buffer); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " - "change the directory with error %u.\n", - GetLastError()); - } - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - } - - /* directories with dots */ - memset(szDirName, 0, 252); - sprintf(szDirName, ".dotDirectory"); - pTemp = convert(szDirName); - bRc = CreateDirectoryW(pTemp, NULL); - if (bRc == FALSE) - { - free(pTemp); - Fail("CreateDirectoryW: Failed to create a dot directory\n"); - } - else - { - /* Check to see if it's possible to navigate to directory */ - GetCurrentDirectoryA(curDirectory, buffer); - bSuccess = SetCurrentDirectoryA(szDirName); - if(!bSuccess) - { - Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " - "navigate to the newly created directory with error " - "code %u.\n", GetLastError()); - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - Fail(""); - } - - /* Set directory back to initial directory */ - bRc = SetCurrentDirectoryA(buffer); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " - "change the directory with error %u.\n", - GetLastError()); - } - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.cpp b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.cpp new file mode 100644 index 0000000000..bbaedda745 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.cpp @@ -0,0 +1,347 @@ +// 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: CreateDirectoryW.c +** +** Purpose: Tests the PAL implementation of the CreateDirectoryW function. +** +** +**===================================================================*/ + +#include + + +/* apparently, under WIN32 the max path size is 248 but under + BSD it is _MAX_PATH */ +#if WIN32 +#define CREATE_MAX_PATH_SIZE 248 +#else +#define CREATE_MAX_PATH_SIZE _MAX_PATH +#endif + + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bRc = FALSE; + BOOL bSuccess = FALSE; + const int buf_size = CREATE_MAX_PATH_SIZE + 10; + char szDirName[CREATE_MAX_PATH_SIZE + 10]; + char buffer[CREATE_MAX_PATH_SIZE + 10]; + WCHAR* pTemp = NULL; + DWORD curDirLen; + DWORD curDirectory = 1024; + + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* directory does not exist */ + pTemp = convert("test_directory"); + bRc = CreateDirectoryW(pTemp, NULL); + free(pTemp); + if (bRc == FALSE) + { + Fail("CreateDirectoryW: Failed to create \"test_directory\"\n"); + } + + /* directory exists */ + pTemp = convert("test_directory"); + bRc = CreateDirectoryW(pTemp, NULL); + if (bRc == TRUE) + { + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + Fail("CreateDirectoryW: Succeeded creating the directory" + " \"test_directory\" when it exists already.\n"); + } + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + + /* long directory names (CREATE_MAX_PATH_SIZE - 1, CREATE_MAX_PATH_SIZE + and CREATE_MAX_PATH_SIZE + 1 characters + including terminating null char) */ + + curDirLen = GetCurrentDirectoryA(0, NULL); + + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - 2 - curDirLen); + pTemp = convert((LPSTR)szDirName); + bRc = CreateDirectoryW(pTemp, NULL); + if (bRc == FALSE) + { + free(pTemp); + Fail("CreateDirectoryW: Failed to create a directory" + " name (%d) chars long with the error code %ld\n", + CREATE_MAX_PATH_SIZE - 1, + GetLastError()); + } + else + { + + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + Fail(""); + + } + + /* Set directory back to initial directory */ + bRc = SetCurrentDirectoryA(buffer); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " + "change the directory with error %u.\n", + GetLastError()); + } + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + } + + + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - 1 - curDirLen); + pTemp = convert(szDirName); + bRc = CreateDirectoryW(pTemp, NULL); + if (bRc == FALSE) + { + free(pTemp); + Fail("CreateDirectoryW: Failed to create a directory" + " name %d chars long with error code %ld\n", + strlen(szDirName), + GetLastError()); + } + else + { + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + Fail(""); + } + + /* Set directory back to initial directory */ + bRc = SetCurrentDirectoryA(buffer); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " + "change the directory with error %u.\n", + GetLastError()); + } + + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + } + + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - curDirLen); + pTemp = convert(szDirName); + bRc = CreateDirectoryW(pTemp, NULL); + + if (bRc != FALSE) + { + RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + if (strlen(szDirName) > CREATE_MAX_PATH_SIZE) + { + free(pTemp); + Fail("CreateDirectoryW: Failed because it created a directory" + " name 1 character longer (%d chars) than the max dir size" + " allowed\n", + strlen(szDirName)); + } + } + + free(pTemp); + + /* long directory name CREATE_MAX_PATH_SIZE + 3 chars including "..\" + (real path length <= CREATE_MAX_PATH_SIZE) */ + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE + 3 - 1 - curDirLen); + szDirName[0] = '.'; + szDirName[1] = '.'; + szDirName[2] = '\\'; + pTemp = convert(szDirName); + bRc = CreateDirectoryW(pTemp, NULL); + if (bRc == FALSE) + { + free(pTemp); + Fail("CreateDirectoryW: Failed to create a directory name more " + "than %d chars long and its real path name is less " + "than %d chars\n", + CREATE_MAX_PATH_SIZE, + CREATE_MAX_PATH_SIZE); + } + else + { + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + Fail(""); + } + + /* Set directory back to initial directory */ + bRc = SetCurrentDirectoryA(buffer); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " + "change the directory with error %u.\n", + GetLastError()); + } + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + } + + /* directories with dots */ + memset(szDirName, 0, 252); + sprintf_s(szDirName, _countof(szDirName), ".dotDirectory"); + pTemp = convert(szDirName); + bRc = CreateDirectoryW(pTemp, NULL); + if (bRc == FALSE) + { + free(pTemp); + Fail("CreateDirectoryW: Failed to create a dot directory\n"); + } + else + { + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + Fail(""); + } + + /* Set directory back to initial directory */ + bRc = SetCurrentDirectoryA(buffer); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " + "change the directory with error %u.\n", + GetLastError()); + } + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/CMakeLists.txt index aae4e7dc54..f8614ca5a6 100644 --- a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - createdirectoryw.c + createdirectoryw.cpp ) add_executable(paltest_createdirectoryw_test2 diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.c b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.c deleted file mode 100644 index 20fac5a879..0000000000 --- a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.c +++ /dev/null @@ -1,345 +0,0 @@ -// 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: createdirectoryw.c -** -** Purpose: Tests the PAL implementation of the CreateDirectoryW function. -** Test creating a directory in a directory path that does not exist. -** Test creating directory with trailing slashes. -** -** Depends on: -** RemoveDirectoryW. -** -** -**==========================================================================*/ - -#include - -#if WIN32 -WCHAR* szTestRootDir = NULL; -#endif - -WCHAR* szTestDir = NULL; -WCHAR* szTestSubDir = NULL; -WCHAR* szTest2SubDir = NULL; -WCHAR* szTest2SubDirWinSlash = NULL; -WCHAR* szTest2SubDirUnixSlash = NULL; - - -/* Free the memory allocated by convert(...) function*/ -static void CleanMemory(){ - -#if WIN32 - free(szTestRootDir); -#endif - - free( szTestDir); - free( szTestSubDir); - free( szTest2SubDir); - free( szTest2SubDirWinSlash); - free( szTest2SubDirUnixSlash); - -} - - -int main(int argc, char *argv[]) -{ - BOOL bRc = FALSE; - BOOL clean = TRUE; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* initialize strings */ - -#if WIN32 - szTestRootDir = convert("/at_root_directory_PALTEST"); -#endif - - szTestDir = convert("test_ directory"); - szTestSubDir = convert( - ".\\./././../test2/./../../////////createdirectoryw" - "\\\\/test2/test_ directory\\sub"); - szTest2SubDir = convert("test_ directory/sub\\sub_sub"); - szTest2SubDirWinSlash = convert("test_ directory/sub\\sub_sub\\\\"); - szTest2SubDirUnixSlash = convert("test_ directory/sub\\sub_sub///"); - - - /* Platform dependent cases:- - * test for WIN32, create directory at the root. - * using /directory_name format - */ -#if WIN32 - - bRc = CreateDirectoryW(szTestRootDir, NULL); - - if (bRc != TRUE) - { - - Trace("CreateDirectoryW: Failed creating the directory " - "\"%S\" with the error code %ld.\n", - szTestRootDir,GetLastError()); - CleanMemory(); - Fail(""); - } - - /*clean szTestRootDir */ - bRc = RemoveDirectoryW(szTestRootDir); - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestRootDir, - GetLastError()); - } - -#endif - - - /* - * create subdirectory "test_directory//sub//sub_sub" - * while parent directory does not exist. - */ - bRc = CreateDirectoryW(szTest2SubDir, NULL); - if (bRc == TRUE) - { - bRc = RemoveDirectoryW(szTest2SubDir); - - if (! bRc ) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTest2SubDir, - GetLastError()); - } - - Trace("CreateDirectoryW: Succeeded creating the directory\"%S\" while" - " its parent directory does not exists. It should fail.\n", - szTest2SubDir); - CleanMemory(); - Fail(""); - - } - - - /* create directory tree one by one - * first create "test_dir" - */ - bRc = CreateDirectoryW(szTestDir, NULL); - - - if (bRc != TRUE)/*failed creating the path*/ - { - - Trace("CreateDirectoryW: Failed creating the directory " - "\"%S\" with the error code %ld.\n", szTestDir,GetLastError()); - CleanMemory(); - Fail(""); - } - - /* create the sub directory test_directory//sub */ - bRc = CreateDirectoryW(szTestSubDir, NULL); - - if (bRc != TRUE)/*failed creating the path*/ - { - Trace("CreateDirectoryW: Failed creating the directory " - "\"%S\" with the error code %ld.\n", - szTestSubDir , GetLastError()); - - /* cleaning... remove parent directory */ - bRc = RemoveDirectoryW(szTestDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with an error code %ld.\n", - szTestDir, - GetLastError()); - } - CleanMemory(); - Fail(""); - } - - /* - * the director structure is test_directory//sub - * test creating directory " test_directory//sub//sub_sub" - */ - bRc = CreateDirectoryW(szTest2SubDir, NULL); - if (bRc != TRUE) - { - Trace("CreateDirectoryW: Failed creating the directory " - "\"%S\" with the error code %ld.\n", - szTest2SubDir , GetLastError()); - - /* remove parent directory test_directory//sub */ - bRc = RemoveDirectoryW(szTestSubDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestSubDir, - GetLastError()); - } - - /* remove parent directory test_directory */ - bRc = RemoveDirectoryW(szTestDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - CleanMemory(); - Fail(""); - - } - - /* Remove Directiry szTest2SubDir*/ - bRc = RemoveDirectoryW(szTest2SubDir); - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTest2SubDir, - GetLastError()); - } - - /* - * the director structure is test_directory//sub - * test creating directory " test_directory//sub//sub_sub\\\\" - */ - bRc = CreateDirectoryW(szTest2SubDirWinSlash, NULL); - if (bRc != TRUE) - { - Trace("CreateDirectoryW: Failed creating the directory " - "\"%S\" with the error code %ld.\n", - szTest2SubDirWinSlash , GetLastError()); - - /* remove parent directory test_directory//sub */ - bRc = RemoveDirectoryW(szTestSubDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestSubDir, - GetLastError()); - } - - /* remove parent directory test_directory */ - bRc = RemoveDirectoryW(szTestDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - CleanMemory(); - Fail(""); - - } - - /* Remove Directiry szTest2SubDirWinSlash */ - bRc = RemoveDirectoryW(szTest2SubDirWinSlash); - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTest2SubDirWinSlash, - GetLastError()); - } - - /* - * the director structure is test_directory//sub - * test creating directory " test_directory//sub//sub_sub///" - */ - bRc = CreateDirectoryW(szTest2SubDirUnixSlash, NULL); - if (bRc != TRUE) - { - Trace("CreateDirectoryW: Failed creating the directory " - "\"%S\" with the error code %ld.\n", - szTest2SubDirUnixSlash , GetLastError()); - - /* remove parent directory test_directory//sub */ - bRc = RemoveDirectoryW(szTestSubDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestSubDir, - GetLastError()); - } - - /* remove parent directory test_directory */ - bRc = RemoveDirectoryW(szTestDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - CleanMemory(); - Fail(""); - - } - - /* Remove Directiry szTest2SubDirUnixSlash.*/ - bRc = RemoveDirectoryW(szTest2SubDirUnixSlash); - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTest2SubDirUnixSlash, - GetLastError()); - } - - /*clean parent szTestSubDir */ - bRc = RemoveDirectoryW(szTestSubDir); - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestSubDir, - GetLastError()); - } - - /*clean parent szTestDir */ - bRc = RemoveDirectoryW(szTestDir); - - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - - if(! clean) - { - CleanMemory(); - Fail(""); - } - - CleanMemory(); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.cpp b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.cpp new file mode 100644 index 0000000000..20fac5a879 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.cpp @@ -0,0 +1,345 @@ +// 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: createdirectoryw.c +** +** Purpose: Tests the PAL implementation of the CreateDirectoryW function. +** Test creating a directory in a directory path that does not exist. +** Test creating directory with trailing slashes. +** +** Depends on: +** RemoveDirectoryW. +** +** +**==========================================================================*/ + +#include + +#if WIN32 +WCHAR* szTestRootDir = NULL; +#endif + +WCHAR* szTestDir = NULL; +WCHAR* szTestSubDir = NULL; +WCHAR* szTest2SubDir = NULL; +WCHAR* szTest2SubDirWinSlash = NULL; +WCHAR* szTest2SubDirUnixSlash = NULL; + + +/* Free the memory allocated by convert(...) function*/ +static void CleanMemory(){ + +#if WIN32 + free(szTestRootDir); +#endif + + free( szTestDir); + free( szTestSubDir); + free( szTest2SubDir); + free( szTest2SubDirWinSlash); + free( szTest2SubDirUnixSlash); + +} + + +int main(int argc, char *argv[]) +{ + BOOL bRc = FALSE; + BOOL clean = TRUE; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* initialize strings */ + +#if WIN32 + szTestRootDir = convert("/at_root_directory_PALTEST"); +#endif + + szTestDir = convert("test_ directory"); + szTestSubDir = convert( + ".\\./././../test2/./../../////////createdirectoryw" + "\\\\/test2/test_ directory\\sub"); + szTest2SubDir = convert("test_ directory/sub\\sub_sub"); + szTest2SubDirWinSlash = convert("test_ directory/sub\\sub_sub\\\\"); + szTest2SubDirUnixSlash = convert("test_ directory/sub\\sub_sub///"); + + + /* Platform dependent cases:- + * test for WIN32, create directory at the root. + * using /directory_name format + */ +#if WIN32 + + bRc = CreateDirectoryW(szTestRootDir, NULL); + + if (bRc != TRUE) + { + + Trace("CreateDirectoryW: Failed creating the directory " + "\"%S\" with the error code %ld.\n", + szTestRootDir,GetLastError()); + CleanMemory(); + Fail(""); + } + + /*clean szTestRootDir */ + bRc = RemoveDirectoryW(szTestRootDir); + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestRootDir, + GetLastError()); + } + +#endif + + + /* + * create subdirectory "test_directory//sub//sub_sub" + * while parent directory does not exist. + */ + bRc = CreateDirectoryW(szTest2SubDir, NULL); + if (bRc == TRUE) + { + bRc = RemoveDirectoryW(szTest2SubDir); + + if (! bRc ) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTest2SubDir, + GetLastError()); + } + + Trace("CreateDirectoryW: Succeeded creating the directory\"%S\" while" + " its parent directory does not exists. It should fail.\n", + szTest2SubDir); + CleanMemory(); + Fail(""); + + } + + + /* create directory tree one by one + * first create "test_dir" + */ + bRc = CreateDirectoryW(szTestDir, NULL); + + + if (bRc != TRUE)/*failed creating the path*/ + { + + Trace("CreateDirectoryW: Failed creating the directory " + "\"%S\" with the error code %ld.\n", szTestDir,GetLastError()); + CleanMemory(); + Fail(""); + } + + /* create the sub directory test_directory//sub */ + bRc = CreateDirectoryW(szTestSubDir, NULL); + + if (bRc != TRUE)/*failed creating the path*/ + { + Trace("CreateDirectoryW: Failed creating the directory " + "\"%S\" with the error code %ld.\n", + szTestSubDir , GetLastError()); + + /* cleaning... remove parent directory */ + bRc = RemoveDirectoryW(szTestDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with an error code %ld.\n", + szTestDir, + GetLastError()); + } + CleanMemory(); + Fail(""); + } + + /* + * the director structure is test_directory//sub + * test creating directory " test_directory//sub//sub_sub" + */ + bRc = CreateDirectoryW(szTest2SubDir, NULL); + if (bRc != TRUE) + { + Trace("CreateDirectoryW: Failed creating the directory " + "\"%S\" with the error code %ld.\n", + szTest2SubDir , GetLastError()); + + /* remove parent directory test_directory//sub */ + bRc = RemoveDirectoryW(szTestSubDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestSubDir, + GetLastError()); + } + + /* remove parent directory test_directory */ + bRc = RemoveDirectoryW(szTestDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + CleanMemory(); + Fail(""); + + } + + /* Remove Directiry szTest2SubDir*/ + bRc = RemoveDirectoryW(szTest2SubDir); + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTest2SubDir, + GetLastError()); + } + + /* + * the director structure is test_directory//sub + * test creating directory " test_directory//sub//sub_sub\\\\" + */ + bRc = CreateDirectoryW(szTest2SubDirWinSlash, NULL); + if (bRc != TRUE) + { + Trace("CreateDirectoryW: Failed creating the directory " + "\"%S\" with the error code %ld.\n", + szTest2SubDirWinSlash , GetLastError()); + + /* remove parent directory test_directory//sub */ + bRc = RemoveDirectoryW(szTestSubDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestSubDir, + GetLastError()); + } + + /* remove parent directory test_directory */ + bRc = RemoveDirectoryW(szTestDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + CleanMemory(); + Fail(""); + + } + + /* Remove Directiry szTest2SubDirWinSlash */ + bRc = RemoveDirectoryW(szTest2SubDirWinSlash); + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTest2SubDirWinSlash, + GetLastError()); + } + + /* + * the director structure is test_directory//sub + * test creating directory " test_directory//sub//sub_sub///" + */ + bRc = CreateDirectoryW(szTest2SubDirUnixSlash, NULL); + if (bRc != TRUE) + { + Trace("CreateDirectoryW: Failed creating the directory " + "\"%S\" with the error code %ld.\n", + szTest2SubDirUnixSlash , GetLastError()); + + /* remove parent directory test_directory//sub */ + bRc = RemoveDirectoryW(szTestSubDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestSubDir, + GetLastError()); + } + + /* remove parent directory test_directory */ + bRc = RemoveDirectoryW(szTestDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + CleanMemory(); + Fail(""); + + } + + /* Remove Directiry szTest2SubDirUnixSlash.*/ + bRc = RemoveDirectoryW(szTest2SubDirUnixSlash); + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTest2SubDirUnixSlash, + GetLastError()); + } + + /*clean parent szTestSubDir */ + bRc = RemoveDirectoryW(szTestSubDir); + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestSubDir, + GetLastError()); + } + + /*clean parent szTestDir */ + bRc = RemoveDirectoryW(szTestDir); + + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + + if(! clean) + { + CleanMemory(); + Fail(""); + } + + CleanMemory(); + + PAL_Terminate(); + return PASS; +} -- cgit v1.2.3