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/CopyFileA/test1/CopyFileA.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/CopyFileA/test1/CopyFileA.c')
-rw-r--r-- | src/pal/tests/palsuite/file_io/CopyFileA/test1/CopyFileA.c | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/CopyFileA/test1/CopyFileA.c b/src/pal/tests/palsuite/file_io/CopyFileA/test1/CopyFileA.c new file mode 100644 index 0000000000..bfea85b7cb --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CopyFileA/test1/CopyFileA.c @@ -0,0 +1,159 @@ +// 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: CopyFileA.c +** +** Purpose: Tests the PAL implementation of the CopyFileA function +** +** +**===================================================================*/ + +/* + 1. copy an existing file to existing with overwrite true + 2. copy an existing file to existing with overwrite false + 3. copy an existing file to non-existant with overwrite true + 4. copy an existing file to non-existant with overwrite false + 5. copy non-existant file to existing with overwrite true + 6. copy non-existant file to existing with overwrite false + 7. copy non-existant file to non-existant with overwrite true + 8. copy non-existant file to non-existant with overwrite false +*/ + +#include <palsuite.h> + +struct TESTS{ + char* lpSource; + char* lpDestination; + BOOL bFailIfExists; + int nResult; + }; + + +int __cdecl main(int argc, char *argv[]) +{ + char szSrcExisting[] = {"src_existing.tmp"}; + char szSrcNonExistant[] = {"src_non-existant.tmp"}; + char szDstExisting[] = {"dst_existing.tmp"}; + char szDstNonExistant[] = {"dst_non-existant.tmp"}; + BOOL bRc = TRUE; + BOOL bSuccess = TRUE; + FILE* tempFile = NULL; + int i; + struct TESTS testCase[] = + { + {szSrcExisting, szDstExisting, FALSE, 1}, + {szSrcExisting, szDstExisting, TRUE, 0}, + {szSrcExisting, szDstNonExistant, FALSE, 1}, + {szSrcExisting, szDstNonExistant, TRUE, 1}, + {szSrcNonExistant, szDstExisting, FALSE, 0}, + {szSrcNonExistant, szDstExisting, TRUE, 0}, + {szSrcNonExistant, szDstNonExistant, FALSE, 0}, + {szSrcNonExistant, szDstNonExistant, TRUE, 0} + }; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create the src_existing file */ + tempFile = fopen(szSrcExisting, "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "CopyFileA test file: src_existing.tmp\n"); + fclose(tempFile); + } + else + { + Fail("CopyFileA: ERROR-> Couldn't create \"src_existing.tmp\" with " + "error %ld\n", + GetLastError()); + } + + /* create the dst_existing file */ + tempFile = fopen(szDstExisting, "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "CopyFileA test file: dst_existing.tmp\n"); + fclose(tempFile); + } + else + { + Fail("CopyFileA: ERROR-> Couldn't create \"dst_existing.tmp\" with " + "error %ld\n", + GetLastError()); + } + + + + for (i = 0; i < (sizeof(testCase) / sizeof(struct TESTS)); i++) + { + bRc = CopyFileA(testCase[i].lpSource, + testCase[i].lpDestination, + testCase[i].bFailIfExists); + if (!bRc) + { + if (testCase[i].nResult == 1) + { + Trace("CopyFileA: FAILED: %s -> %s with bFailIfExists = %d " + "with error %ld\n", + testCase[i].lpSource, + testCase[i].lpDestination, + testCase[i].bFailIfExists, + GetLastError()); + bSuccess = FALSE; + } + } + else + { + if (testCase[i].nResult == 0) + { + Trace("CopyFileA: FAILED: %s -> %s with bFailIfExists = %d\n", + testCase[i].lpSource, + testCase[i].lpDestination, + testCase[i].bFailIfExists); + bSuccess = FALSE; + } + else + { + /* verify the file was moved */ + if (GetFileAttributesA(testCase[i].lpDestination) == -1) + { + Trace("CopyFileA: GetFileAttributes of destination file " + "failed with error code %ld. \n", + GetLastError()); + bSuccess = FALSE; + } + else if (GetFileAttributesA(testCase[i].lpSource) == -1) + { + Trace("CopyFileA: GetFileAttributes of source file " + "failed with error code %ld. \n", + GetLastError()); + bSuccess = FALSE; + } + else + { + /* verify attributes of destination file to source file*/ + if(GetFileAttributes(testCase[i].lpSource) != + GetFileAttributes(testCase[i].lpDestination)) + { + Trace("CopyFileA : The file attributes of the " + "destination file do not match the file " + "attributes of the source file.\n"); + bSuccess = FALSE; + } + } + } + } + /* delete file file but don't worry if it fails */ + DeleteFileA(szDstNonExistant); + } + + int exitCode = bSuccess ? PASS : FAIL; + PAL_TerminateEx(exitCode); + return exitCode; +} |