1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*============================================================================
6**
7** Source: test1.c
8**
9** Purpose: Tests to see that fflush is working properly. Flushes a couple
10** buffers and checks the return value. Can't figure out a way to test
11** and ensure it is really dropping the buffers, since the system
12** does this automatically most of the time ...
13**
14**
15**==========================================================================*/
16
17/* This function is really tough to test. Right now it just tests
18 a bunch of return values. No solid way to ensure that it is really
19 flushing a buffer or not -- might have to be a manual test someday.
20*/
21
22#include <palsuite.h>
23
24
25int __cdecl main(int argc, char **argv)
26{
27
28 int TheReturn;
29 FILE* TheFile;
30 FILE* AnotherFile = NULL;
31
32 PAL_Initialize(argc,argv);
33
34 TheFile = fopen("theFile","w+");
35
36 if(TheFile == NULL)
37 {
38 Fail("ERROR: fopen failed. Test depends on this function.");
39 }
40
41 TheReturn = fwrite("foo",3,3,TheFile);
42
43 if(TheReturn != 3)
44 {
45 Fail("ERROR: fwrite failed. Test depends on this function.");
46 }
47
48 /* Test to see that FlushFileBuffers returns a success value */
49 TheReturn = fflush(TheFile);
50
51 if(TheReturn != 0)
52 {
53 Fail("ERROR: The fflush function returned non-zero, which "
54 "indicates failure, when trying to flush a buffer.");
55 }
56
57 /* Test to see that FlushFileBuffers returns a success value */
58 TheReturn = fflush(NULL);
59
60 if(TheReturn != 0)
61 {
62 Fail("ERROR: The fflush function returned non-zero, which "
63 "indicates failure, when trying to flush all buffers.");
64 }
65
66 /* Test to see that FlushFileBuffers returns a success value */
67 TheReturn = fflush(AnotherFile);
68
69 if(TheReturn != 0)
70 {
71 Fail("ERROR: The fflush function returned non-zero, which "
72 "indicates failure, when trying to flush a stream not "
73 "associated with a file.");
74 }
75
76 PAL_Terminate();
77 return PASS;
78}
79
80
81