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: 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
22int __cdecl main(int argc, char *argv[])
23{
24 FILE *fp;
25 char testfile[] = "testfile.txt";
26
27 WCHAR *outstr;
28 char checkstr[] = "hello world";
29 char buf[256];
30
31 if (PAL_Initialize(argc, argv) != 0)
32 {
33 return(FAIL);
34 }
35
36 outstr = convert(checkstr);
37 if ((fp = fopen(testfile, "w+")) == NULL)
38 {
39 Fail("ERROR: fopen failed to create \"%s\"\n", testfile);
40 }
41
42 if ((fwprintf(fp, outstr)) < 0)
43 {
44 Fail("ERROR: fwprintf failed to print to \"%s\"\n", testfile);
45 }
46
47 if ((fseek( fp, 0, SEEK_SET)) != 0)
48 {
49 Fail("ERROR: Fseek failed to set pointer to beginning of file\n" );
50 }
51
52
53 if ((fgets( buf, 100, fp )) == NULL)
54 {
55 Fail("ERROR: fgets failed\n");
56 }
57
58 if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0)
59 {
60 Fail("ERROR: expected %s, got %s\n", checkstr, buf);
61 }
62
63
64 if ((fclose( fp )) != 0)
65 {
66 Fail("ERROR: fclose failed to close \"%s\"\n", testfile);
67 }
68
69 PAL_Terminate();
70 return PASS;
71}
72