summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/c_runtime/fopen
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
commit4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch)
tree98110734c91668dfdbb126fcc0e15ddbd93738ca /src/pal/tests/palsuite/c_runtime/fopen
parentfa45f57ed55137c75ac870356a1b8f76c84b229c (diff)
downloadcoreclr-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/c_runtime/fopen')
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/CMakeLists.txt10
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test1/test1.c82
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test1/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test2/test2.c65
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test2/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test3/test3.c66
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test3/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test4/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test4/test4.c82
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test4/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test5/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test5/test5.c78
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test5/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test6/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test6/test6.c131
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test6/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test7/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test7/test7.c117
-rw-r--r--src/pal/tests/palsuite/c_runtime/fopen/test7/testinfo.dat15
22 files changed, 869 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/CMakeLists.txt
new file mode 100644
index 0000000000..19ee487a6a
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+add_subdirectory(test4)
+add_subdirectory(test5)
+add_subdirectory(test6)
+add_subdirectory(test7)
+
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test1/CMakeLists.txt
new file mode 100644
index 0000000000..6578c43659
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test1.c
+)
+
+add_executable(paltest_fopen_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_fopen_test1 coreclrpal)
+
+target_link_libraries(paltest_fopen_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fopen/test1/test1.c
new file mode 100644
index 0000000000..565b4eb77d
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test1/test1.c
@@ -0,0 +1,82 @@
+// 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: test1.c
+**
+** Purpose: Tests the PAL implementation of the fopen function.
+** This test simply attempts to open a number of files
+** with different modes. It checks to ensure a valid
+** file pointer is returned. It doesn't do any checking
+** to ensure the mode is really what it claims. And checks
+** for a NULL pointer when attempts to open a directory.
+**
+
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+struct testCase
+{
+ int CorrectResult;
+ char mode[20];
+};
+
+int __cdecl main(int argc, char **argv)
+{
+
+ FILE *fp;
+ char name[128];
+ int i;
+
+ struct testCase testCases[] =
+ {
+ {0, "r"}, {1, "w"}, {1, "a"},
+ {0, "r+"}, {1, "w+"}, {1, "a+"},
+ {1, "wt"}, {1, "wb"}, {1, "wS"},
+ {1, "w+c"}, {1, "w+n"}, {1, "wR"},
+ {1, "wT"}, {0, "tw"}
+ };
+
+ if (PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+
+
+ for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++)
+ {
+ strcpy(name,"testfiles");
+ strcat(name,testCases[i].mode);
+
+ fp = fopen(name,testCases[i].mode);
+
+ if ((fp == 0 && testCases[i].CorrectResult != 0) ||
+ (testCases[i].CorrectResult == 0 && fp != 0) )
+ {
+ Fail("ERROR: fopen returned incorrectly "
+ "opening a file in %s mode. Perhaps it opened a "
+ "read only file which didn't exist and returned a correct "
+ "pointer?",testCases[i].mode);
+ }
+
+ memset(name, '\0', 128);
+
+ }
+
+ /* When attempt to open a directory fopen should returned NULL */
+ if ( fopen(".", "r") != NULL)
+ {
+ Fail("ERROR: fopen returned non-NULL when trying to open a directory"
+ " the returned value was %d\n", fp);
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
+
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/fopen/test1/testinfo.dat
new file mode 100644
index 0000000000..d9908549ea
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test1/testinfo.dat
@@ -0,0 +1,15 @@
+# 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 = C Runtime
+Function = fopen
+Name = Positive Test for fopen
+TYPE = DEFAULT
+EXE1 = test1
+Description
+= This test simply attempts to open a number of files with different
+= modes. It checks to ensure a valid file pointer is returned. It
+= doesn't do any checking to ensure the mode is really what it claims.
+= Checks for returned value when attempts to open a directory.
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test2/CMakeLists.txt
new file mode 100644
index 0000000000..4458ed21d8
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test2.c
+)
+
+add_executable(paltest_fopen_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_fopen_test2 coreclrpal)
+
+target_link_libraries(paltest_fopen_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test2/test2.c b/src/pal/tests/palsuite/c_runtime/fopen/test2/test2.c
new file mode 100644
index 0000000000..4026efe89a
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test2/test2.c
@@ -0,0 +1,65 @@
+// 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: test2.c
+**
+** Purpose: Tests the PAL implementation of the fopen function.
+** Test to ensure that you can write to a 'w' mode file.
+** And that you can't read from a 'w' mode file.
+**
+** Depends:
+** fprintf
+** fseek
+** fgets
+**
+
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char **argv)
+{
+
+ FILE *fp;
+ char buffer[128];
+
+ if (PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+
+ if( (fp = fopen( "testfile", "w" )) == NULL )
+ {
+ Fail( "ERROR: The file failed to open with 'w' mode.\n" );
+ }
+
+ /* Test that you can write */
+ if(fprintf(fp,"%s","some text") <= 0)
+ {
+ Fail("ERROR: Attempted to WRITE to a file opened with 'w' mode "
+ "but fprintf failed. Either fopen or fprintf have problems.");
+ }
+
+ if(fseek(fp, 0, SEEK_SET))
+ {
+ Fail("ERROR: fseek failed, and this test depends on it.");
+ }
+
+ /* Test that you can't read */
+ if(fgets(buffer,10,fp) != NULL)
+ {
+ Fail("ERROR: Tried to READ from a file with only 'w' mode set. "
+ "This should fail, but fgets didn't return NULL. Either "
+ "fgets or fopen is broken.");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
+
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/fopen/test2/testinfo.dat
new file mode 100644
index 0000000000..4c1a0095f8
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test2/testinfo.dat
@@ -0,0 +1,15 @@
+# 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 = C Runtime
+Function = fopen
+Name = Positive Test for fopen
+TYPE = DEFAULT
+EXE1 = test2
+Description
+= Test to ensure that you can write to a 'w' mode file. And that you can't
+= read from a 'w' mode file.
+
+
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test3/CMakeLists.txt
new file mode 100644
index 0000000000..2c80f72ae7
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test3.c
+)
+
+add_executable(paltest_fopen_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_fopen_test3 coreclrpal)
+
+target_link_libraries(paltest_fopen_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test3/test3.c b/src/pal/tests/palsuite/c_runtime/fopen/test3/test3.c
new file mode 100644
index 0000000000..f3af42dc8a
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test3/test3.c
@@ -0,0 +1,66 @@
+// 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: test3.c
+**
+** Purpose: Tests the PAL implementation of the fopen function.
+** Test to ensure that you can write to a 'w+' mode file.
+** And that you can read from a 'w+' mode file.
+**
+** Depends:
+** fprintf
+** fseek
+** fgets
+**
+
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char **argv)
+{
+
+ FILE *fp;
+ char buffer[128];
+
+ if (PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+
+ /* Open a file with 'w+' mode */
+ if( (fp = fopen( "testfile", "w+" )) == NULL )
+ {
+ Fail( "ERROR: The file failed to open with 'w+' mode.\n" );
+ }
+
+ /* Write some text to the file */
+ if(fprintf(fp,"%s","some text") <= 0)
+ {
+ Fail("ERROR: Attempted to WRITE to a file opened with 'w+' mode "
+ "but fprintf failed. Either fopen or fprintf have problems.");
+ }
+
+ if(fseek(fp, 0, SEEK_SET))
+ {
+ Fail("ERROR: fseek failed, and this test depends on it.");
+ }
+
+ /* Attempt to read from the 'w+' only file, should pass */
+ if(fgets(buffer,10,fp) == NULL)
+ {
+ Fail("ERROR: Tried to READ from a file with 'w+' mode set. "
+ "This should succeed, but fgets returned NULL. Either fgets "
+ "or fopen is broken.");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
+
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/fopen/test3/testinfo.dat
new file mode 100644
index 0000000000..c458c1196a
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test3/testinfo.dat
@@ -0,0 +1,15 @@
+# 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 = C Runtime
+Function = fopen
+Name = Positive Test for fopen
+TYPE = DEFAULT
+EXE1 = test3
+Description
+= Test to ensure that you can write to a 'w+' mode file. And that you can
+= read from a 'w+' mode file.
+
+
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test4/CMakeLists.txt
new file mode 100644
index 0000000000..92e0ef0bd8
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test4/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test4.c
+)
+
+add_executable(paltest_fopen_test4
+ ${SOURCES}
+)
+
+add_dependencies(paltest_fopen_test4 coreclrpal)
+
+target_link_libraries(paltest_fopen_test4
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test4/test4.c b/src/pal/tests/palsuite/c_runtime/fopen/test4/test4.c
new file mode 100644
index 0000000000..04683d52c5
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test4/test4.c
@@ -0,0 +1,82 @@
+// 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: test4.c
+**
+** Purpose: Tests the PAL implementation of the fopen function.
+** Test to ensure that you can't write to a 'r' mode file.
+** And that you can read from a 'r' mode file.
+**
+** Depends:
+** fprintf
+** fclose
+** fgets
+**
+
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char **argv)
+{
+
+ FILE *fp;
+ char buffer[128];
+
+ if (PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+
+ /* Open a file with 'w' mode */
+ if( (fp = fopen( "testfile", "w" )) == NULL )
+ {
+ Fail( "ERROR: The file failed to open with 'w' mode.\n" );
+ }
+
+ /* Write some text to the file */
+ if(fprintf(fp,"%s","some text") <= 0)
+ {
+ Fail("ERROR: Attempted to WRITE to a file opened with 'w' mode "
+ "but fprintf failed. Either fopen or fprintf have problems.");
+ }
+
+ if(fclose(fp))
+ {
+ Fail("ERROR: Attempted to close a file, but fclose failed. "
+ "This test depends upon it.");
+ }
+
+ /* Open a file with 'r' mode */
+ if( (fp = fopen( "testfile", "r" )) == NULL )
+ {
+ Fail( "ERROR: The file failed to open with 'r' mode.\n" );
+ }
+
+ /* Attempt to read from the 'r' only file, should pass */
+ if(fgets(buffer,10,fp) == NULL)
+ {
+ Fail("ERROR: Tried to READ from a file with 'r' mode set. "
+ "This should succeed, but fgets returned NULL. Either fgets "
+ "or fopen is broken.");
+ }
+
+ /* Write some text to the file */
+ if(fprintf(fp,"%s","some text") > 0)
+ {
+ Fail("ERROR: Attempted to WRITE to a file opened with 'r' mode "
+ "but fprintf succeeded It should have failed. "
+ "Either fopen or fprintf have problems.");
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
+
+
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test4/testinfo.dat b/src/pal/tests/palsuite/c_runtime/fopen/test4/testinfo.dat
new file mode 100644
index 0000000000..a1ecaf959b
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test4/testinfo.dat
@@ -0,0 +1,15 @@
+# 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 = C Runtime
+Function = fopen
+Name = Positive Test for fopen
+TYPE = DEFAULT
+EXE1 = test4
+Description
+= Test to ensure that you can't write to a 'r' mode file. And that you can
+= read from a 'r' mode file.
+
+
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test5/CMakeLists.txt
new file mode 100644
index 0000000000..82529b9aab
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test5/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test5.c
+)
+
+add_executable(paltest_fopen_test5
+ ${SOURCES}
+)
+
+add_dependencies(paltest_fopen_test5 coreclrpal)
+
+target_link_libraries(paltest_fopen_test5
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test5/test5.c b/src/pal/tests/palsuite/c_runtime/fopen/test5/test5.c
new file mode 100644
index 0000000000..0a760314e1
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test5/test5.c
@@ -0,0 +1,78 @@
+// 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: test5.c
+**
+** Purpose: Tests the PAL implementation of the fopen function.
+** Test to ensure that you can write to a 'r+' mode file.
+** And that you can read from a 'r+' mode file.
+**
+** Depends:
+** fprintf
+** fclose
+** fgets
+** fseek
+**
+
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char **argv)
+{
+
+ FILE *fp;
+ char buffer[128];
+
+ if (PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+
+ /* Open a file with 'w' mode */
+ if( (fp = fopen( "testfile", "w" )) == NULL )
+ {
+ Fail( "ERROR: The file failed to open with 'w' mode.\n" );
+ }
+
+ if(fclose(fp))
+ {
+ Fail("ERROR: Attempted to close a file, but fclose failed. "
+ "This test depends upon it.");
+ }
+
+ if( (fp = fopen( "testfile", "r+" )) == NULL )
+ {
+ Fail( "ERROR: The file failed to open with 'r+' mode.\n" );
+ }
+
+ /* Write some text to the file */
+ if(fprintf(fp,"%s","some text") <= 0)
+ {
+ Fail("ERROR: Attempted to WRITE to a file opened with 'r+' mode "
+ "but fprintf failed. Either fopen or fprintf have problems.");
+ }
+
+ if(fseek(fp, 0, SEEK_SET))
+ {
+ Fail("ERROR: fseek failed, and this test depends on it.");
+ }
+
+ /* Attempt to read from the 'r+' only file, should pass */
+ if(fgets(buffer,10,fp) == NULL)
+ {
+ Fail("ERROR: Tried to READ from a file with 'r+' mode set. "
+ "This should succeed, but fgets returned NULL. Either fgets "
+ "or fopen is broken.");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
+
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test5/testinfo.dat b/src/pal/tests/palsuite/c_runtime/fopen/test5/testinfo.dat
new file mode 100644
index 0000000000..8f8f5d950b
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test5/testinfo.dat
@@ -0,0 +1,15 @@
+# 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 = C Runtime
+Function = fopen
+Name = Positive Test for fopen
+TYPE = DEFAULT
+EXE1 = test5
+Description
+= Test to ensure that you can write to a 'r+' mode file. And that you can
+= read from a 'r+' mode file.
+
+
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test6/CMakeLists.txt
new file mode 100644
index 0000000000..9a01cfb9a8
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test6/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test6.c
+)
+
+add_executable(paltest_fopen_test6
+ ${SOURCES}
+)
+
+add_dependencies(paltest_fopen_test6 coreclrpal)
+
+target_link_libraries(paltest_fopen_test6
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test6/test6.c b/src/pal/tests/palsuite/c_runtime/fopen/test6/test6.c
new file mode 100644
index 0000000000..03b6067fdd
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test6/test6.c
@@ -0,0 +1,131 @@
+// 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: test6.c
+**
+** Purpose: Tests the PAL implementation of the fopen function.
+** Test to ensure that you can write to an 'a' mode file.
+** And that you can't read from a 'a' mode file. Also ensure
+** that you can use fseek and still write to the end of a file.
+**
+** Depends:
+** fprintf
+** fgets
+** fseek
+** fclose
+**
+
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char **argv)
+{
+
+ FILE *fp;
+ char buffer[128];
+
+ if (PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+
+ /* Open a file with 'a+' mode */
+ if( (fp = fopen( "testfile", "a" )) == NULL )
+ {
+ Fail( "ERROR: The file failed to open with 'a' mode.\n" );
+ }
+
+ /* Write some text to the file */
+ if(fprintf(fp,"%s","some text") <= 0)
+ {
+ Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode "
+ "but fprintf failed. Either fopen or fprintf have problems.");
+ }
+
+ if(fseek(fp, 0, SEEK_SET))
+ {
+ Fail("ERROR: fseek failed, and this test depends on it.");
+ }
+
+ /* Attempt to read from the 'a' only file, should fail */
+ if(fgets(buffer,10,fp) != NULL)
+ {
+ Fail("ERROR: Tried to READ from a file with 'a' mode set. "
+ "This should fail, but fgets returned success. Either fgets "
+ "or fopen is broken.");
+ }
+
+
+ /* Attempt to write to a file after using 'a' and fseek */
+ fp = fopen("testfile2", "a");
+ if(fp == NULL)
+ {
+ Fail("ERROR: The file failed to be created with 'a' mode.\n");
+ }
+
+ /* write text to the file initially */
+ if(fprintf(fp,"%s","abcd") <= 0)
+ {
+ Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode "
+ "but fprintf failed. Either fopen or fprintf have problems.\n");
+ }
+
+ /* set the pointer to the front of the file */
+ if(fseek(fp, 0, SEEK_SET))
+ {
+ Fail("ERROR: fseek failed, and this test depends on it.\n");
+ }
+
+ /* using 'a' should still write to the end of the file, not the front */
+ if(fputs("efgh",fp) < 0)
+ {
+ Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode "
+ "but fputs failed.\n");
+ }
+
+ /* set the pointer to the front of the file */
+ if(fseek(fp, 0, SEEK_SET))
+ {
+ Fail("ERROR: fseek failed, and this test depends on it.\n");
+ }
+
+ /* a file with 'a' mode can only write, so close the file before reading */
+ if(fclose(fp))
+ {
+ Fail("ERROR: fclose failed when it should have succeeded.\n");
+ }
+
+ /* open the file again to read */
+ fp = fopen("testfile2","r");
+ if(fp == NULL)
+ {
+ Fail("ERROR: fopen failed to open the file using 'r' mode");
+ }
+
+ /* Attempt to read from the 'a' only file, should succeed */
+ if(fgets(buffer,10,fp) == NULL)
+ {
+ Fail("ERROR: Tried to READ from a file with 'a' mode set. "
+ "This should pass, but fgets returned failure. Either fgets "
+ "or fopen is broken.\n");
+ }
+
+ /* Compare what was read and what should have been in the file */
+ if(memcmp(buffer,"abcdefgh",8))
+ {
+ Fail("ERROR: The string read should have equaled 'abcdefgh' "
+ "but instead it is %s\n", buffer);
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
+
+
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test6/testinfo.dat b/src/pal/tests/palsuite/c_runtime/fopen/test6/testinfo.dat
new file mode 100644
index 0000000000..5edd94416d
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test6/testinfo.dat
@@ -0,0 +1,15 @@
+# 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 = C Runtime
+Function = fopen
+Name = Positive Test for fopen
+TYPE = DEFAULT
+EXE1 = test6
+Description
+= Test to ensure that you can write to a 'a' mode file. And that you can't
+= read from a 'a' mode file.
+
+
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test7/CMakeLists.txt
new file mode 100644
index 0000000000..168a5aff53
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test7/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test7.c
+)
+
+add_executable(paltest_fopen_test7
+ ${SOURCES}
+)
+
+add_dependencies(paltest_fopen_test7 coreclrpal)
+
+target_link_libraries(paltest_fopen_test7
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test7/test7.c b/src/pal/tests/palsuite/c_runtime/fopen/test7/test7.c
new file mode 100644
index 0000000000..3ef8602ddb
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test7/test7.c
@@ -0,0 +1,117 @@
+// 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: test7.c
+**
+** Purpose: Tests the PAL implementation of the fopen function.
+** Test to ensure that you can write to an 'a+' mode file.
+** And that you can read from a 'a+' mode file. Also ensure
+** that you can use fseek and still write to the end of a file.
+**
+** Depends:
+** fprintf
+** fgets
+** fseek
+** fclose
+**
+
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char **argv)
+{
+
+ FILE *fp;
+ char buffer[128];
+
+ if (PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+
+ /* Open a file with 'a+' mode */
+ if( (fp = fopen( "testfile", "a+" )) == NULL )
+ {
+ Fail( "ERROR: The file failed to open with 'a+' mode.\n" );
+ }
+
+ /* Write some text to the file */
+ if(fprintf(fp,"%s","some text") <= 0)
+ {
+ Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode "
+ "but fprintf failed. Either fopen or fprintf have problems.\n");
+ }
+
+ if(fseek(fp, 0, SEEK_SET))
+ {
+ Fail("ERROR: fseek failed, and this test depends on it.\n");
+ }
+
+ /* Attempt to read from the 'a+' only file, should succeed */
+ if(fgets(buffer,10,fp) == NULL)
+ {
+ Fail("ERROR: Tried to READ from a file with 'a+' mode set. "
+ "This should pass, but fgets returned failure. Either fgets "
+ "or fopen is broken.\n");
+ }
+
+
+ /* Attempt to write to a file after using 'a+' and fseek */
+ fp = fopen("testfile2", "a+");
+ if(fp == NULL)
+ {
+ Fail("ERROR: The file failed to be created with 'a+' mode.\n");
+ }
+
+ /* write text to the file initially */
+ if(fprintf(fp,"%s","abcd") <= 0)
+ {
+ Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode "
+ "but fprintf failed. Either fopen or fprintf have problems.\n");
+ }
+
+ /* set the pointer to the front of the file */
+ if(fseek(fp, 0, SEEK_SET))
+ {
+ Fail("ERROR: fseek failed, and this test depends on it.\n");
+ }
+
+ /* using 'a+' should still write to the end of the file, not the front */
+ if(fputs("efgh",fp) < 0)
+ {
+ Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode "
+ "but fputs failed.\n");
+ }
+
+ /* set the pointer to the front of the file */
+ if(fseek(fp, 0, SEEK_SET))
+ {
+ Fail("ERROR: fseek failed, and this test depends on it.\n");
+ }
+
+ /* Attempt to read from the 'a+' only file, should succeed */
+ if(fgets(buffer,10,fp) == NULL)
+ {
+ Fail("ERROR: Tried to READ from a file with 'a+' mode set. "
+ "This should pass, but fgets returned failure. Either fgets "
+ "or fopen is broken.\n");
+ }
+
+ /* Compare what was read and what should have been in the file */
+ if(memcmp(buffer,"abcdefgh",8))
+ {
+ Fail("ERROR: The string read should have equaled 'abcdefgh' "
+ "but instead it is %s\n", buffer);
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
+
diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test7/testinfo.dat b/src/pal/tests/palsuite/c_runtime/fopen/test7/testinfo.dat
new file mode 100644
index 0000000000..e4bc99c910
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fopen/test7/testinfo.dat
@@ -0,0 +1,15 @@
+# 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 = C Runtime
+Function = fopen
+Name = Positive Test for fopen
+TYPE = DEFAULT
+EXE1 = test7
+Description
+= Test to ensure that you can write to a 'a+' mode file. And that you can
+= read from a 'a+' mode file.
+
+