| 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 (fprintf) |
| 8 | ** |
| 9 | ** Purpose: A single, basic, test case with no formatting. |
| 10 | ** Test modeled after the sprintf series. |
| 11 | ** |
| 12 | |
| 13 | ** |
| 14 | **==========================================================================*/ |
| 15 | |
| 16 | #include <palsuite.h> |
| 17 | |
| 18 | /* |
| 19 | * Depends on memcmp, strlen, fopen, fgets, fseek and fclose. |
| 20 | */ |
| 21 | |
| 22 | int __cdecl main(int argc, char *argv[]) |
| 23 | { |
| 24 | FILE *fp; |
| 25 | char testfile[] = "testfile.txt" ; |
| 26 | char checkstr[] = "hello world" ; |
| 27 | char buf[256]; |
| 28 | |
| 29 | if (PAL_Initialize(argc, argv) != 0) |
| 30 | { |
| 31 | return(FAIL); |
| 32 | } |
| 33 | |
| 34 | if ((fp = fopen(testfile, "w+" )) == NULL) |
| 35 | { |
| 36 | Fail("ERROR: fopen failed to create \"%s\"\n" , testfile); |
| 37 | } |
| 38 | |
| 39 | if ((fprintf(fp, "hello world" )) < 0) |
| 40 | { |
| 41 | Fail("ERROR: fprintf failed to print to \"%s\"\n" , testfile); |
| 42 | } |
| 43 | |
| 44 | if ((fseek( fp, 0, SEEK_SET)) != 0) |
| 45 | |
| 46 | { |
| 47 | |
| 48 | Fail("ERROR: Fseek failed to set pointer to beginning of file\n" ); |
| 49 | |
| 50 | } |
| 51 | |
| 52 | |
| 53 | |
| 54 | if ((fgets( buf, 100, fp )) == NULL) |
| 55 | |
| 56 | { |
| 57 | |
| 58 | Fail("ERROR: fgets failed\n" ); |
| 59 | |
| 60 | } |
| 61 | |
| 62 | |
| 63 | if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) |
| 64 | { |
| 65 | Fail("ERROR: expected %s, got %s\n" , checkstr, buf); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | |
| 70 | if ((fclose( fp )) != 0) |
| 71 | |
| 72 | { |
| 73 | |
| 74 | Fail("ERROR: fclose failed to close \"%s\"\n" , testfile); |
| 75 | |
| 76 | } |
| 77 | |
| 78 | PAL_Terminate(); |
| 79 | return PASS; |
| 80 | } |
| 81 | |