diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
commit | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch) | |
tree | 98110734c91668dfdbb126fcc0e15ddbd93738ca /src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.c | |
parent | fa45f57ed55137c75ac870356a1b8f76c84b229c (diff) | |
download | coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2 coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip |
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.c')
-rw-r--r-- | src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.c | 296 |
1 files changed, 296 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.c b/src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.c new file mode 100644 index 0000000000..2bb441e732 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.c @@ -0,0 +1,296 @@ +// 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: CreateDirectoryA.c +** +** Purpose: Tests the PAL implementation of the CreateDirectoryA function. +** +** Depends on: +** RemoveDirectoryW (since RemoveDirectoryA is unavailable) +** GetCurrentDirectoryA +** +** +**===================================================================*/ + +#include <palsuite.h> + + +/* 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[]) +{ + const char* szTestDir = {"test_directory"}; + const char* szDotDir = {".dotDirectory"}; + 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 */ + bRc = CreateDirectoryA(szTestDir, NULL); + if (bRc == FALSE) + { + Fail("CreateDirectoryA: Failed to create \"%s\" with error code %ld\n", + szTestDir, + GetLastError()); + } + + + /* directory exists should fail */ + bRc = CreateDirectoryA(szTestDir, NULL); + if (bRc == TRUE) + { + pTemp = convert((LPSTR)szTestDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + Fail("CreateDirectoryA: Succeeded creating the directory" + "\"%s\" when it exists already.\n", + szTestDir); + } + else + { + pTemp = convert((LPSTR)szTestDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + } + + + /* 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); + bRc = CreateDirectoryA(szDirName, NULL); + if (bRc == FALSE) + { + Fail("CreateDirectoryA: Failed to create a directory" + " name %d chars long with the 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) + { + Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + } + + /* Set directory back to initial directory */ + SetCurrentDirectoryA(buffer); + + pTemp = convert((LPSTR)szDirName); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szDirName, + GetLastError()); + } + } + + + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - 1 - curDirLen); + bRc = CreateDirectoryA(szDirName, NULL); + if (bRc == FALSE) + { + Fail("CreateDirectoryA: 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) + { + Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + } + + /* Set Directroy back to initial directory */ + SetCurrentDirectoryA(buffer); + + pTemp = convert(szDirName); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szDirName, + GetLastError()); + } + } + + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - curDirLen); + bRc = CreateDirectoryA(szDirName, NULL); + if (bRc != FALSE) + { + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + } + + /* set directory back to initial directory */ + SetCurrentDirectoryA(buffer); + + pTemp = convert(szDirName); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szDirName, + GetLastError()); + } + if (strlen(szDirName) > CREATE_MAX_PATH_SIZE) + { + Fail("CreateDirectoryA: Failed because it created a directory" + " name 1 character longer (%d chars) than the max dir size " + "allowed\n", + strlen(szDirName)); + } + } + + + /* 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] = '\\'; + bRc = CreateDirectoryA(szDirName, NULL); + if (bRc == FALSE) + { + Fail("CreateDirectoryA: Failed to create a directory name more " + "than %d chars long and its real path name is less " + "than %d chars, error %u\n", + CREATE_MAX_PATH_SIZE, + CREATE_MAX_PATH_SIZE, GetLastError()); + } + else + { + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + } + + /* set directory back to initial directory */ + SetCurrentDirectoryA(buffer); + + pTemp = convert(szDirName); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " + " \"%s\" with the error code %ld.\n", + szDirName, + GetLastError()); + } + } + + + /* directories with dots */ + memset(szDirName, 0, buf_size); + sprintf(szDirName, szDotDir); + bRc = CreateDirectoryA(szDirName, NULL); + if (bRc == FALSE) + { + Fail("CreateDirectoryA: Failed to create \"%s\" with error code %ld\n", + szDotDir, + GetLastError()); + } + else + { + + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + } + + /* set directory back to initial directory */ + SetCurrentDirectoryA(buffer); + + pTemp = convert((LPSTR)szDotDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " + " \"%s\" with the error code %ld.\n", + szDotDir, + GetLastError()); + } + } + + + PAL_Terminate(); + return PASS; +} |