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: Test #1 for the vfprintf function. A single, basic, test
10** case with no formatting.
11**
12**
13**==========================================================================*/
14
15
16
17#include <palsuite.h>
18#include "../vfprintf.h"
19
20int __cdecl main(int argc, char *argv[])
21{
22 FILE *fp;
23 char testfile[] = "testfile.txt";
24 char buf[256];
25 char checkstr[] = "hello world";
26 int ret;
27
28
29 if (PAL_Initialize(argc, argv))
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 ret = DoVfprintf(fp, "hello world");
40
41 if (ret != strlen(checkstr))
42 {
43 Fail("Expected vfprintf to return %d, got %d.\n",
44 strlen(checkstr), ret);
45
46 }
47
48 if ((fseek(fp, 0, SEEK_SET)) != 0)
49 {
50 Fail("ERROR: Fseek failed to set pointer to beginning of file\n" );
51 }
52
53 if ((fgets(buf, 100, fp)) == NULL)
54 {
55 Fail("ERROR: fgets failed\n");
56 }
57 if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0)
58 {
59 Fail("ERROR: expected %s, got %s\n", checkstr, buf);
60 }
61 if ((fclose(fp)) != 0)
62 {
63 Fail("ERROR: fclose failed to close \"%s\"\n", testfile);
64 }
65
66 PAL_Terminate();
67 return PASS;
68}
69