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/SetFileAttributesW/test2 | |
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/SetFileAttributesW/test2')
4 files changed, 155 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/CMakeLists.txt new file mode 100644 index 0000000000..81fa02c1dd --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + SetFileAttributesW.c +) + +add_executable(paltest_setfileattributesw_test2 + ${SOURCES} +) + +add_dependencies(paltest_setfileattributesw_test2 coreclrpal) + +target_link_libraries(paltest_setfileattributesw_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/SetFileAttributesW.c b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/SetFileAttributesW.c new file mode 100644 index 0000000000..f657436845 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/SetFileAttributesW.c @@ -0,0 +1,121 @@ +// 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: SetFileAttributesW.c +** +** Purpose: Tests the PAL implementation of the SetFileAttributesW function +** Test that we can set the defined attributes aside from READONLY on a +** file, and that it doesn't return failure. Note, these attributes won't +** do anything to the file, however. +** +** +**===================================================================*/ + +#define UNICODE + +#include <palsuite.h> + +/* this cleanup method tries to revert the file back to its initial attributes */ +void do_cleanup(WCHAR* filename, DWORD attributes) +{ + DWORD result; + result = SetFileAttributes(filename, attributes); + if (result == 0) + { + Fail("ERROR:SetFileAttributesW returned 0,failure in the do_cleanup " + "method when trying to revert the file back to its initial attributes (%u)", GetLastError()); + } +} + +int __cdecl main(int argc, char **argv) +{ + DWORD TheResult; + DWORD initialAttr; + CHAR *FileName_Multibyte = "test_file"; + WCHAR FileName[MAX_PATH]; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + // Create the test file + FILE *testFile = fopen(FileName_Multibyte, "w"); + if (testFile == NULL) + { + Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName); + } + if (fputs("testing", testFile) == EOF) + { + Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName); + } + if (fclose(testFile) != 0) + { + Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName); + } + testFile = NULL; + + /* Make a wide character string for the file name */ + + MultiByteToWideChar(CP_ACP, + 0, + FileName_Multibyte, + -1, + FileName, + MAX_PATH); + + /* Get the initial attributes of the file */ + initialAttr = GetFileAttributesW(FileName); + + /* Try to set the file to HIDDEN */ + + TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_HIDDEN); + + if(TheResult == 0) + { + do_cleanup(FileName,initialAttr); + Fail("ERROR: SetFileAttributes returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_HIDDEN attribute. This should " + "not do anything in FreeBSD, but it shouldn't fail."); + } + + /* Try to set the file to ARCHIVE */ + + TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_ARCHIVE); + + if(TheResult == 0) + { + do_cleanup(FileName,initialAttr); + Fail("ERROR: SetFileAttributes returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_ARCHIVE attribute."); + } + + /* Try to set the file to SYSTEM */ + + TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_SYSTEM); + + if(TheResult == 0) + { + do_cleanup(FileName,initialAttr); + Fail("ERROR: SetFileAttributes returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_SYSTEM attribute."); + } + + /* Try to set the file to DIRECTORY */ + + TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_DIRECTORY); + + if(TheResult == 0) + { + do_cleanup(FileName,initialAttr); + Fail("ERROR: SetFileAttributes returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_DIRECTORY attribute."); + } + + do_cleanup(FileName,initialAttr); + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/test_file b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/test_file new file mode 100644 index 0000000000..18d630a34d --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/test_file @@ -0,0 +1 @@ +The File.
\ No newline at end of file diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/testinfo.dat b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/testinfo.dat new file mode 100644 index 0000000000..e3161a9bd6 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = file_io +Function = SetFileAttributesW +Name = Positive Test for SetFileAttributesW +TYPE = DEFAULT +EXE1 = setfileattributesw +Description += Test the SetFileAttributesW function += Try to set the attributes that are not valid in FreeBSD. These should += return success in either WIN32 or FreeBSD, just have no effect in FreeBSD. |