Debian Codegraph @

gcc/testsuite/gm2/isolib/run/pass/seqappend.mod

raw
1 MODULE seqappend ;
2
3 FROM ChanConsts IMPORT OpenResults, old, raw, write, read ;
4 FROM IOChan IMPORT ChanId, RawWrite, RawRead ;
5 FROM SYSTEM IMPORT ADR;
6 FROM libc IMPORT exit, printf ;
7 FROM StrLib IMPORT StrEqual ;
8 IMPORT StreamFile;
9 IMPORT SeqFile;
10
11
12 PROCEDURE stress ;
13 VAR
14 cid : ChanId ;
15 res : OpenResults;
16 str : ARRAY [0..20] OF CHAR ;
17 actual: CARDINAL ;
18 code : INTEGER ;
19 BEGIN
20 code := 0 ;
21 str := '0123456789' ;
22
23 (* Open file and create data. *)
24 StreamFile.Open (cid, 'testdata', write+old+raw, res) ;
25 IF res = opened
26 THEN
27 (* Now write data creating new contents. *)
28 RawWrite (cid, ADR (str), 10) ;
29 StreamFile.Close(cid)
30 ELSE
31 printf ("failed to open file for write\n") ;
32 code := 2
33 END ;
34
35 str := 'abcdefghij' ;
36 (* Now attempt to append the alphabetic str. *)
37 SeqFile.OpenAppend (cid, 'testdata', write+old+raw, res) ;
38 IF res = opened
39 THEN
40 RawWrite (cid, ADR (str), 10);
41 SeqFile.Close (cid)
42 ELSE
43 printf ("failed to open file for append\n") ;
44 code := 3
45 END ;
46
47 (* And now test the file for the appended data. *)
48 StreamFile.Open (cid, 'testdata', read+raw, res) ;
49 IF res = opened
50 THEN
51 (* Now check the new contents for the appended data. *)
52 RawRead (cid, ADR (str), 20, actual) ;
53 IF actual # 20
54 THEN
55 printf ("short read occurred: %d...\n", actual) ;
56 code := 5
57 END ;
58 StreamFile.Close (cid) ;
59 str[20] := 0C ;
60 IF StrEqual (str, '0123456789abcdefghij')
61 THEN
62 printf ("append test passed\n")
63 ELSE
64 printf ("append test failed\n") ;
65 code := 1
66 END
67 ELSE
68 printf ("failed to open result file\n") ;
69 code := 4
70 END ;
71 exit (code)
72 END stress ;
73
74
75 BEGIN
76 stress
77 END seqappend.