diff options
Diffstat (limited to 'src/pal/tests/palsuite/c_runtime/ferror')
9 files changed, 217 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/c_runtime/ferror/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ferror/CMakeLists.txt new file mode 100644 index 0000000000..ef14ea5352 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ferror/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) + diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ferror/test1/CMakeLists.txt new file mode 100644 index 0000000000..2ab12b5db3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ferror/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_ferror_test1 + ${SOURCES} +) + +add_dependencies(paltest_ferror_test1 coreclrpal) + +target_link_libraries(paltest_ferror_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test1/test1.c b/src/pal/tests/palsuite/c_runtime/ferror/test1/test1.c new file mode 100644 index 0000000000..516f2531ed --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ferror/test1/test1.c @@ -0,0 +1,74 @@ +// 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 ferror function. +** +** Depends: +** fopen +** fread +** fclose +** +** +** +**===================================================================*/ + +#include <palsuite.h> + +int __cdecl main(int argc, char **argv) +{ + const char filename[] = "testfile"; + char buffer[128]; + FILE * fp = NULL; + int result; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Open a file in READ mode */ + + if((fp = fopen(filename, "r")) == NULL) + { + Fail("Unable to open a file for reading. Is the file " + "in the directory? It should be."); + } + + /* Read 10 characters from the file. The file has 15 + characters in it. + */ + + if((result = fread(buffer,1,10,fp)) == 0) + { + Fail("ERROR: Zero characters read from the file. It should have " + "read 10 character in from a 15 character file."); + } + + if(ferror(fp) != 0) + { + Fail("ERROR: ferror returned a value not equal to 0. The read " + "operation shouldn't have caused an error, and ferror should " + "return 0 still."); + } + + /* + Close the open file and end the test. + */ + + if(fclose(fp) != 0) + { + Fail("ERROR: fclose failed when trying to close a file pointer. " + "This test depends on fclose working properly."); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test1/testfile b/src/pal/tests/palsuite/c_runtime/ferror/test1/testfile new file mode 100644 index 0000000000..273c1a9ffd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ferror/test1/testfile @@ -0,0 +1 @@ +This is a test.
\ No newline at end of file diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/ferror/test1/testinfo.dat new file mode 100644 index 0000000000..32e55a3b0d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ferror/test1/testinfo.dat @@ -0,0 +1,16 @@ +# 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 = ferror +Name = Positive Test for ferror +TYPE = DEFAULT +EXE1 = test1 +Description += Tests the PAL implementation of the ferror function. += Open a file, and read some characters. Check that ferror states that += no error has occurred. Then close the file pointer. Attempt to read += some more. Check ferror now, and it should indicate that an error has += occurred. diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ferror/test2/CMakeLists.txt new file mode 100644 index 0000000000..077dde0bc6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ferror/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_ferror_test2 + ${SOURCES} +) + +add_dependencies(paltest_ferror_test2 coreclrpal) + +target_link_libraries(paltest_ferror_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test2/test2.c b/src/pal/tests/palsuite/c_runtime/ferror/test2/test2.c new file mode 100644 index 0000000000..fdf9e032c8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ferror/test2/test2.c @@ -0,0 +1,69 @@ +// 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: Open a read-only file and attempt to write some data to it. +** Check to ensure that an ferror occurs. +** +** Depends: +** fopen +** fwrite +** fclose +** +** +** +**===================================================================*/ + +#include <palsuite.h> + +int __cdecl main(int argc, char **argv) +{ + const char filename[] = "testfile"; + FILE * fp = NULL; + int result; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Open a file in READONLY mode */ + + if((fp = fopen(filename, "r")) == NULL) + { + Fail("Unable to open a file for reading."); + } + + /* Attempt to write 14 characters to the file. */ + + if((result = fwrite("This is a test",1,14,fp)) != 0) + { + Fail("ERROR: %d characters written. 0 characters should " + "have been written, since this file is read-only.", result); + } + + if(ferror(fp) == 0) + { + Fail("ERROR: ferror should have generated an error when " + "write was called on a read-only file. But, it " + "retured 0, indicating no error.\n"); + } + + /* Close the file. */ + + if(fclose(fp) != 0) + { + Fail("ERROR: fclose failed when trying to close a file pointer. " + "This test depends on fclose working properly."); + } + + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test2/testfile b/src/pal/tests/palsuite/c_runtime/ferror/test2/testfile new file mode 100644 index 0000000000..0135842a03 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ferror/test2/testfile @@ -0,0 +1 @@ +This is a test file. This needs to be kept in CVS.
\ No newline at end of file diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/ferror/test2/testinfo.dat new file mode 100644 index 0000000000..d724a4c4e7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ferror/test2/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 = C Runtime +Function = ferror +Name = Positive Test for ferror, call write on a readonly file. +TYPE = DEFAULT +EXE1 = test2 +Description += Open a read-only file and attempt to write some data to it. += Check to ensure that an ferror occurs. |