Debian Codegraph @

trip/addrtest1.rexx

raw
1 /*
2 * Generic test for ADDRESS WITH options.
3 * You need the program "cat" to run this script.
4 * The test gives some lines of debugging output.
5 *
6 * The test returns 1 and prints some lines to standard error in case of
7 * an error.
8 * The test returns 0 without any line written to stdardard error on success.
9 *
10 * An argument may be supplied for a queue's name.
11 *
12 * A good testing environment does the following tests, remove the redirection
13 * elements in case of errors and check the output:
14 * 1) "rexx addrtest1 >/dev/null"
15 * 2) "rexx addrtest1 SESSION >/dev/null"
16 * 3) "rexx addrtest1 local_queue >/dev/null"
17 * 4) "rexx addrtest1 SESSION@somewhere >/dev/null"
18 * 5) "rexx addrtest1 remote_queue@somewhere >/dev/null"
19 *
20 * If you supply ALL as the argument, each of the above tests is done.
21 */
22
23 parse upper arg q
24 if q = "ALL" then do
25 trace o
26 parse source . . script
27 call extcall script
28 call extcall script "SESSION"
29 call extcall script "local_queue"
30 call extcall script "SESSION@"
31 call extcall script "remote_queue@localhost"
32 exit 0
33 end
34
35 internal = 1
36
37 resultFIFO = "first line,second line,third line"
38 resultLIFO = "third line,second line,first line"
39 resultSTEMLIFO = "stem line 3,stem line 2,stem line 1"
40 resultSTEMFIFO = "stem line 1,stem line 2,stem line 3"
41 resultSTEMLIFOFIFO = resultSTEMLIFO || "," || resultSTEMFIFO
42
43 qn = q
44 if qn = "" then
45 qn = "(empty for default queue SESSION)"
46 say "--------------------------------------------"
47 say "Queue's name q is" qn
48 say "--------------------------------------------"
49
50 if q \= "" & q \= "SESSION" then do
51 /* sigh, no chance to force a special queue without deletion and without
52 * having a false queue.
53 */
54 if left( q, 8 ) \= "SESSION@" then do
55 call RxQueue 'D', q
56 call RxQueue 'C', q /* doesn't return a value for the first */
57 end
58 call RxQueue 'S', q
59 nq = RxQueue( 'G' )
60 say NNG nq
61 posat = pos( '@', q )
62 if posat = 0 then
63 posat = length( q ) + 1 /* if lengths are different */
64 else
65 internal = 0
66 if left( q, posat ) \= left( nq, posat ) then do
67 call oops "(setting the queue name to " || qn || ")"
68 exit 1
69 end
70 end
71
72 call info "Just QUEUE, then PULL"
73 call fillq
74 call showq "DELETE", resultFIFO
75
76 if internal then do
77 call info "LIFO> cat >LIFO"
78 call fillq
79 "LIFO> cat >LIFO"
80 call showq "DELETE", resultLIFO
81
82 call info "LIFO> cat >FIFO"
83 call fillq
84 "LIFO> cat >FIFO"
85 call showq "DELETE", resultFIFO
86 end
87
88 if q \= "" & q \= "SESSION" then
89 call RxQueue 'D', q
90
91 call info 'ADDRESS SYSTEM "cat" WITH INPUT LIFO "" OUTPUT FIFO q'
92 call fillq
93 ADDRESS SYSTEM "cat" WITH INPUT LIFO "" OUTPUT FIFO q
94 call showq "DELETE", resultFIFO, q
95
96 call info 'ADDRESS SYSTEM "cat" WITH INPUT LIFO "" OUTPUT APPEND FIFO q'
97 call fillq
98 ADDRESS SYSTEM "cat" WITH INPUT LIFO "" OUTPUT APPEND FIFO q
99 call showq "DELETE", resultFIFO, q
100
101 s.0 = 3
102 s.1 = "stem line 1"
103 s.2 = "stem line 2"
104 s.3 = "stem line 3"
105
106 call info 'ADDRESS SYSTEM "cat" WITH INPUT STEM s. OUTPUT LIFO q'
107 ADDRESS SYSTEM "cat" WITH INPUT STEM s. OUTPUT LIFO q
108 call showq "PERSIST", resultSTEMLIFO, q
109
110 call info 'ADDRESS SYSTEM "cat" WITH INPUT STEM s. OUTPUT APPEND FIFO q'
111 ADDRESS SYSTEM "cat" WITH INPUT STEM s. OUTPUT APPEND FIFO q
112 call showq "DELETE", resultSTEMLIFOFIFO, q
113
114 call info 'ADDRESS SYSTEM "echo Hello World" WITH OUTPUT FIFO q'
115 ADDRESS SYSTEM "echo Hello World" WITH OUTPUT FIFO q
116 call showq "DELETE", "Hello World", q
117
118 l1 = 'Line to stderr'
119 l2 = 'Line to stdout'
120 call info 'ADDRESS SYSTEM WITH OUTPUT APPEND STREAM "stdout" ERROR APPEND STREAM "stdout"'
121 ADDRESS SYSTEM WITH OUTPUT APPEND STREAM 'stdout' ERROR APPEND STREAM 'stdout'
122 call info 'ADDRESS SYSTEM "std"'
123 ADDRESS SYSTEM "std"
124 Say "If you don't see '"l1"' followed by '"l2"', there is a problem!"
125
126 call info 'ADDRESS SYSTEM WITH OUTPUT STREAM "junk" ERROR STREAM "junk"'
127 ADDRESS SYSTEM WITH OUTPUT STREAM 'junk' ERROR STREAM 'junk'
128 call info 'ADDRESS SYSTEM "std"'
129 ADDRESS SYSTEM "std"
130 line1 = Linein( 'junk' )
131 line2 = Linein( 'junk' )
132 Say "Line 1 from 'junk' is: '"line1"', should be: '"l1"'"
133 Say "Line 2 from 'junk' is: '"line2"', should be: '"l2"'"
134 ADDRESS SYSTEM "rm -f junk"
135 if line1 \= l1 | line2 \= l2 then
136 call oops lastaction
137
138 exit 0
139
140 info:
141 say ""
142 lastaction = arg(1)
143 say "Action:" lastaction
144 return
145
146 fillq: procedure
147 say ""
148 say "Action:" arg(1)
149 queue "first line"
150 queue "second line"
151 queue "third line"
152 return
153
154 showq: procedure expose lastaction
155 saved = ""
156 error = 0
157
158 /* chop the result string into single lines */
159 resStem = arg(2)
160 resStem.0 = 0
161 do while resStem \= ''
162 resStem.0 = resStem.0 + 1
163 h = resStem.0
164 parse var resStem resStem.h "," resStem
165 end
166
167 if arg(3) \= "" then do
168 saved = rxqueue('G')
169 call rxqueue 'S', arg(3)
170 say lastaction "(Queue" arg(3) || ", current is" saved || ")"
171 end
172 gotten = queued()
173 if gotten \= resStem.0 then
174 error = 1
175 do i = 1 to gotten
176 parse pull line
177 if line \= resStem.i then
178 error = 1
179 if arg(1) \= "DELETE" then
180 queue line
181 say line
182 end
183 if saved \= "" then do
184 call rxqueue 'S', saved
185 say "(current set back to" rxqueue('G') || ")"
186 end
187 if error then
188 call oops lastaction
189 return
190
191 oops: procedure
192 call lineout "<stderr>", "----------------------------------------"
193 call lineout "<stderr>", "Something's wrong in test" arg(1)
194 call lineout "<stderr>", "----------------------------------------"
195 call lineout "<stderr>", ""
196 exit 1
197 return
198
199 extcall: procedure
200 if arg() > 1 then
201 address REXX arg(1) WITH error stem err.
202 else
203 address REXX arg(1) arg(2) WITH error stem err.
204 if err.0 = 0 then
205 return
206 do i = 1 to err.0
207 call lineout "<stderr>", err.i
208 end
209 exit 1
210 return