summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gm2/isolib/run/pass/testreadint.mod
blob: 54073fdaf8bc248aa9dafa04a893d46982b89bd4 (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
MODULE testreadint ;

FROM ChanConsts IMPORT OpenResults, old, read, write ;
FROM IOChan IMPORT ChanId ;
FROM StdChans IMPORT StdOutChan ;
IMPORT StreamFile ;
FROM TextIO IMPORT SkipLine, WriteLn, WriteString ;
FROM WholeIO IMPORT ReadCard, ReadInt, WriteCard, WriteInt ;
FROM libc IMPORT printf, exit ;


CONST
   TestFileName = "testdata" ;


PROCEDURE Assert (condition: BOOLEAN; name, result: ARRAY OF CHAR) ;
BEGIN
   IF NOT condition
   THEN
      code := 1 ;
      printf ("assert failed, procedure: %s failed to read number: %s\n", name, result)
   END
END Assert ;


PROCEDURE StressReadInt ;
VAR
   in,
   out   : ChanId ;
   result: OpenResults ;
   int   : INTEGER ;
   card  : CARDINAL ;
BEGIN
   (* Create a new file and use WriteCard to populate the file.  *)
   printf ("creating test file: %s\n", TestFileName) ;

   StreamFile.Open (out, TestFileName, write+old, result);
   IF result = opened
   THEN
      WriteString (out, ' ') ;
      WriteCard (out, 123, 3) ;
      WriteLn (out) ;
      WriteCard (out, 456, 3) ;
      WriteLn (out) ;
      StreamFile.Close (out)
   ELSE
      printf ("unable to create: %s\n", TestFileName) ;
      exit (1)
   END ;

   (* Now attempt to read the data using ReadCard.  *)
   printf ("reading test file using ReadCard: %s\n", TestFileName) ;
   StreamFile.Open (in, TestFileName, read, result) ;
   IF result = opened
   THEN
      ReadCard (in, card) ;
      printf ("first cardinal: %d\n", card) ;
      Assert (card = 123, "ReadCard", "123") ;
      SkipLine (in) ;
      ReadCard (in, card) ;
      printf ("second cardinal: %d\n", card) ;
      Assert (card = 456, "ReadCard", "456") ;
      StreamFile.Close (in)
   END ;

   (* Now attempt to read the data using ReadInt.  *)
   printf ("reading test file using ReadInt: %s\n", TestFileName) ;
   StreamFile.Open (in, TestFileName, read, result) ;
   IF result = opened
   THEN
      ReadInt (in, int) ;
      printf ("first integer: %d\n", int) ;
      Assert (int = 123, "ReadInt", "123") ;
      SkipLine (in) ;
      ReadInt (in, int) ;
      printf ("second integer: %d\n", int) ;
      Assert (int = 456, "ReadInt", "456") ;
      StreamFile.Close (in)
   END
END StressReadInt ;


VAR
   code: INTEGER ;
BEGIN
   code := 0 ;
   StressReadInt ;
   exit (code)
END testreadint.