summaryrefslogtreecommitdiff
path: root/PACE/tests/Stdio_Test.c
blob: 1133d3281d641ffea8ec01bc7ec63721b561e805 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* $Id$ -*- C -*- */

/* ===================================================================== */
/*                                                                       */
/* = FILENAME                                                            */
/*    Stdio_Test.c                                                       */
/*                                                                       */
/* =  DESCRIPTION                                                        */
/*     Testing the platform for POSIX standard I/O. This is not meant    */
/*     to be an exhaustive test at this point but more a sanity check    */
/*     that PACE works (at least somewhat) as advertised.                */
/*     This program creates/opens a temporary file, writes to the file,  */
/*     reads from the file to make sure it's what was written, and       */
/*     then closes/deletes the file.                                     */
/*                                                                       */
/* = AUTHOR                                                              */
/*    Joe Hoffert <joeh@cs.wustl.edu>                                    */
/*                                                                       */
/* ===================================================================== */

#include "pace/stdio.h"
#include "pace/unistd.h"
#include "pace/string.h"

const char * filename = "temp";
const char * mode = "w+";
const char * string1 = "line 1\n";
const char * success = "SUCCEEDED";
const char * failure = "***FAILED***";

#if PACE_LYNXOS != 0x300
int
main (int argc, char **argv)
{
  /* Test creating/opening a file. */
  PACE_FILE *file;
  int retval;
  char* retval2;
  char buffer[256];

  file = pace_fopen (filename,
                     mode);
  if (file == 0)
    {
      printf("pace_fopen %s\n", failure);
      return -1;
    }

  /* Test writing to a file. */
  retval = pace_fputs (string1,
                       file);
  if (retval == EOF)
    {
      printf("pace_fputs %s\n", failure);
      return -1;
    }

  /* Test flushing a file. */
  retval = pace_fflush (file);
  if (retval != 0)
    {
      printf("pace_fflush %s\n", failure);
      return -1;
    }

  /* Test seeking in a file. */
  retval = pace_fseek (file,
                       0,
                       0);
  if (retval != 0)
    {
      printf("pace_fseek %s\n", failure);
      return -1;
    }

  /* Test reading from a file. */
  retval2 = pace_fgets (buffer,
                        sizeof(buffer),
                        file);
  if (retval2 == 0)
    {
      printf("pace_fgets %s\n", failure);
      return -1;
    }

  if (pace_strcmp(buffer, string1) != 0)
    {
      printf("strcmp of pace_fgets %s\n", failure);
      return -1;
    }

  /* Test closing a file. */
  retval = pace_fclose (file);
  if (retval != 0)
    {
      printf("pace_fclose %s\n", failure);
      return -1;
    }


  /* uncomment this line to pause the program to test the size
   * of the exe Cntr-Alt-Del and then look at the task manager to
   *  find the size
  pace_sleep (20);
   */

  PACE_UNUSED_ARG (argc);
  PACE_UNUSED_ARG (argv);
  return 0;
}
#else
int
main (int argc, char **argv)
{
  printf("PACE does not support LynxOS 3.0.0.\n");
}
#endif /* PACE_LYNXOS == 0x300 */