summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp')
-rw-r--r--src/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp
new file mode 100644
index 0000000..b8e2f41
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp
@@ -0,0 +1,88 @@
+// 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: Check to see that fputs fails and returns EOF when called on
+** a closed file stream and a read-only file stream.
+**
+
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char **argv)
+{
+
+ FILE* TheFile;
+ char* StringOne = "FooBar";
+ int ret;
+
+ if (PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file with read/write access */
+
+ TheFile = fopen("TestFile", "w+");
+
+ if(TheFile == NULL)
+ {
+ Fail("ERROR: fopen failed to open the file 'TestFile' in read/write "
+ "mode.\n");
+ }
+
+ /* Then close that file we just opened */
+
+ if(fclose(TheFile) != 0)
+ {
+ Fail("ERROR: fclose failed to close the file.\n");
+ }
+
+ /* Check that calling fputs on this closed file stream fails. */
+
+ if((ret = fputs(StringOne, TheFile)) >= 0)
+ {
+ Fail("ERROR: fputs should have failed to write to a closed "
+ "file stream, but it didn't return a negative value.\n");
+ }
+
+ if(ret != EOF)
+ {
+ Fail("ERROR: fputs should have returned EOF on an error, but instead "
+ "returned %d.\n",ret);
+ }
+
+ /* Open a file as Readonly */
+
+ TheFile = fopen("TestFile", "r");
+
+ if(TheFile == NULL)
+ {
+ Fail("ERROR: fopen failed to open the file 'TestFile' in read/write "
+ "mode.\n");
+ }
+
+ /* Check that fputs fails when trying to write to a read-only stream */
+
+ if((ret = fputs(StringOne, TheFile)) >= 0)
+ {
+ Fail("ERROR: fputs should have failed to write to a read-only "
+ "file stream, but it didn't return a negative value.\n");
+ }
+
+ if(ret != EOF)
+ {
+ Fail("ERROR: fputs should have returned EOF when writing to a "
+ "read-only filestream, but instead "
+ "returned %d.\n",ret);
+ }
+
+ PAL_Terminate();
+ return PASS;
+}