summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/file_io/SetFileAttributesW
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/file_io/SetFileAttributesW')
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/CMakeLists.txt7
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/SetFileAttributesW.c167
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/test_file1
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/SetFileAttributesW.c121
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/test_file1
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/SetFileAttributesW.c57
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/SetFileAttributesW.c133
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/test_file1
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/testinfo.dat14
16 files changed, 619 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileAttributesW/CMakeLists.txt
new file mode 100644
index 0000000000..a3847f8ca9
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+add_subdirectory(test4)
+
diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/CMakeLists.txt
new file mode 100644
index 0000000000..35927b4b1d
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/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_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_setfileattributesw_test1 coreclrpal)
+
+target_link_libraries(paltest_setfileattributesw_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/SetFileAttributesW.c b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/SetFileAttributesW.c
new file mode 100644
index 0000000000..753c396d1f
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/SetFileAttributesW.c
@@ -0,0 +1,167 @@
+// 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 a file READONLY, and then that we're unable to
+** open that file with WRITE access. Then change it to NORMAL attributes, and
+** try to open it again -- it should work now.
+**
+** Depends:
+** CreateFile
+** CloseHandle
+**
+**
+**===================================================================*/
+
+/* According to the spec, only READONLY attribute can be set
+ in FreeBSD.
+*/
+
+#define UNICODE
+
+#include <palsuite.h>
+
+
+
+int __cdecl main(int argc, char **argv)
+{
+ DWORD TheResult;
+ HANDLE TheFile;
+ 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);
+
+
+ /* Try to set the file to Read-only */
+
+ TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_READONLY);
+
+ if(TheResult == 0)
+ {
+ Fail("ERROR: SetFileAttributes returned 0, failure, when trying "
+ "to set the FILE_ATTRIBUTE_READONLY attribute.");
+ }
+
+ /* Attempt to open this READONLY file with WRITE access,
+ The open should fail and the HANDLE should be invalid.
+ */
+
+ TheFile = CreateFile(
+ FileName, // file name
+ GENERIC_READ|GENERIC_WRITE, // access mode
+ 0, // share mode
+ NULL, // SD
+ OPEN_ALWAYS, // how to create
+ FILE_ATTRIBUTE_NORMAL, // file attributes
+ NULL // handle to template file
+ );
+
+ if(TheFile != INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Tried to open a file that was created as "
+ "READONLY with the GENERIC_WRITE access mode. This should"
+ " cause CreateFile to return an INVALID_HANDLE_VALUE.");
+ }
+
+ /* Try to open the file with READ access, this should be ok.
+ The HANDLE will be valid.
+ */
+
+ TheFile = CreateFile(
+ FileName, // file name
+ GENERIC_READ, // access mode
+ 0, // share mode
+ NULL, // SD
+ OPEN_ALWAYS, // how to create
+ FILE_ATTRIBUTE_NORMAL, // file attributes
+ NULL // handle to template file
+ );
+
+ if(TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Tried to open a file that was created as "
+ "READONLY with the GENERIC_READ access mode. This should"
+ " cause CreateFile to return an valid handle, but "
+ "INVALID_HANDLE_VALUE was returned!.");
+ }
+
+ /* Close that HANDLE */
+
+ TheResult = CloseHandle(TheFile);
+
+ if(TheResult == 0)
+ {
+ Fail("ERROR: CloseHandle failed. This tests relies upon it "
+ "working properly.");
+ }
+
+ /* Set the file to NORMAL */
+
+ TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_NORMAL);
+
+ if(TheResult == 0)
+ {
+ Fail("ERROR: SetFileAttributes returned 0, failure, when trying "
+ "to set the FILE_ATTRIBUTE_NORMAL attribute.");
+ }
+
+ /* To ensure that the set worked correctly, try to open the file
+ with WRITE access again -- this time it should succeed.
+ */
+
+ TheFile = CreateFile(
+ FileName, // file name
+ GENERIC_READ|GENERIC_WRITE, // access mode
+ 0, // share mode
+ NULL, // SD
+ OPEN_ALWAYS, // how to create
+ FILE_ATTRIBUTE_NORMAL, // file attributes
+ NULL // handle to template file
+ );
+
+ if(TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Tried to open a file that was created as "
+ "NORMAL with the GENERIC_WRITE access mode. This should"
+ " cause CreateFile to return an valid handle, but "
+ "INVALID_HANDLE_VALUE was returned!.");
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/test_file b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/test_file
new file mode 100644
index 0000000000..1b4bcfe1b5
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/test_file
@@ -0,0 +1 @@
+Don't delete me. I'm needed. The File. \ No newline at end of file
diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/testinfo.dat b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/testinfo.dat
new file mode 100644
index 0000000000..75cdc3b719
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/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. Set a file as READONLY and
+= attempt to open it with WRITE access, to ensure that this doesn't work.
+= Then switch to NORMAL attributes, and try again -- it should work.
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.
diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/CMakeLists.txt
new file mode 100644
index 0000000000..c2cdacb0d0
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/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_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_setfileattributesw_test3 coreclrpal)
+
+target_link_libraries(paltest_setfileattributesw_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/SetFileAttributesW.c b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/SetFileAttributesW.c
new file mode 100644
index 0000000000..8a8bafac68
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/SetFileAttributesW.c
@@ -0,0 +1,57 @@
+// 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 the function fails if the file doesn't exist..
+**
+**
+**===================================================================*/
+
+#define UNICODE
+
+#include <palsuite.h>
+
+
+int __cdecl main(int argc, char **argv)
+{
+ DWORD TheResult;
+ WCHAR FileName[MAX_PATH];
+
+ if (0 != PAL_Initialize(argc,argv))
+ {
+ return FAIL;
+ }
+
+ /* Make a wide character string for the file name */
+
+ MultiByteToWideChar(CP_ACP,
+ 0,
+ "no_file",
+ -1,
+ FileName,
+ MAX_PATH);
+
+
+ /* Try to set the file to NORMAL on a file that doesn't
+ exist.
+ */
+
+ TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_NORMAL);
+
+ if(TheResult != 0)
+ {
+ Fail("ERROR: SetFileAttributes returned non-zero0, success, when"
+ " trying to set the FILE_ATTRIBUTE_NORMAL attribute on a non "
+ "existant file. This should fail.");
+ }
+
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/testinfo.dat b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/testinfo.dat
new file mode 100644
index 0000000000..4b264898df
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/testinfo.dat
@@ -0,0 +1,13 @@
+# 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 the function on a file that doesn't exist. It should fail.
diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/CMakeLists.txt
new file mode 100644
index 0000000000..6a4aa8adc3
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/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_test4
+ ${SOURCES}
+)
+
+add_dependencies(paltest_setfileattributesw_test4 coreclrpal)
+
+target_link_libraries(paltest_setfileattributesw_test4
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/SetFileAttributesW.c b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/SetFileAttributesW.c
new file mode 100644
index 0000000000..bebadfa264
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/SetFileAttributesW.c
@@ -0,0 +1,133 @@
+// 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
+** Check that using two flags (READONLY and NORMAL) only sets the file
+** as READONLY, as MSDN notes that everything else overrides NORMAL.
+**
+** Depends:
+** CreateFile
+** CloseHandle
+**
+**
+**===================================================================*/
+
+#define UNICODE
+
+#include <palsuite.h>
+
+
+
+int __cdecl main(int argc, char **argv)
+{
+ DWORD TheResult;
+ HANDLE TheFile;
+ 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);
+
+
+ /* Try to set the file to Read-only|Normal ... It should
+ end up as Readonly, since this overrides Normal*/
+
+ TheResult = SetFileAttributes(FileName,
+ FILE_ATTRIBUTE_NORMAL|
+ FILE_ATTRIBUTE_READONLY);
+
+ if(TheResult == 0)
+ {
+ Fail("ERROR: SetFileAttributes returned 0, failure, when trying "
+ "to set the FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_NORMAL "
+ "attribute.");
+ }
+
+ /* Attempt to open this READONLY file with WRITE access,
+ The open should fail and the HANDLE should be invalid.
+ */
+
+ TheFile = CreateFile(
+ FileName, // file name
+ GENERIC_READ|GENERIC_WRITE, // access mode
+ 0, // share mode
+ NULL, // SD
+ OPEN_ALWAYS, // how to create
+ FILE_ATTRIBUTE_NORMAL, // file attributes
+ NULL // handle to template file
+ );
+
+ if(TheFile != INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Tried to open a file that was created as "
+ "READONLY with the GENERIC_WRITE access mode. This should"
+ " cause CreateFile to return an INVALID_HANDLE_VALUE.");
+ }
+
+ /* Try to open the file with READ access, this should be ok.
+ The HANDLE will be valid.
+ */
+
+ TheFile = CreateFile(
+ FileName, // file name
+ GENERIC_READ, // access mode
+ 0, // share mode
+ NULL, // SD
+ OPEN_ALWAYS, // how to create
+ FILE_ATTRIBUTE_NORMAL, // file attributes
+ NULL // handle to template file
+ );
+
+ if(TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Tried to open a file that was created as "
+ "READONLY with the GENERIC_READ access mode. This should"
+ " cause CreateFile to return an valid handle, but "
+ "INVALID_HANDLE_VALUE was returned!.");
+ }
+
+ /* Close that HANDLE */
+
+ TheResult = CloseHandle(TheFile);
+
+ if(TheResult == 0)
+ {
+ Fail("ERROR: CloseHandle failed. This tests relies upon it "
+ "working properly.");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/test_file b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/test_file
new file mode 100644
index 0000000000..1b4bcfe1b5
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/test_file
@@ -0,0 +1 @@
+Don't delete me. I'm needed. The File. \ No newline at end of file
diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/testinfo.dat b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/testinfo.dat
new file mode 100644
index 0000000000..75cdc3b719
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/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. Set a file as READONLY and
+= attempt to open it with WRITE access, to ensure that this doesn't work.
+= Then switch to NORMAL attributes, and try again -- it should work.