2 # Copyright (C) 2006-2007, The Perl Foundation.
7 use lib qw( . lib ../lib ../../lib );
9 use Parrot::Test tests => 6;
13 t/pmc/parrotio.t - test the ParrotIO PMC
17 % prove t/pmc/parrotio.t
21 Tests the ParrotIO PMC.
25 # L<PDD22/I\/O PMC API/=item new>
26 pir_output_is( <<'CODE', <<'OUT', 'new' );
29 say "ok 1 - $P0 = new 'ParrotIO'"
32 ok 1 - $P0 = new 'ParrotIO'
35 # L<PDD22/I\/O PMC API/=item open.*=item close>
36 pir_output_is( <<'CODE', <<'OUT', 'open and close - synchronous', todo => 'not yet implemented' );
40 say 'ok 1 - $P0.open($S1)'
43 say 'ok 2 - $P0.close()'
45 $P0.open('README', 'rw')
46 say 'ok 3 - $P0.open($S1, $S2) # rw mode'
50 say 'ok 4 - $P0.open()'
58 $P0.open('bad_file', 'r')
62 $P0.open('new_file', 'w')
63 say 'ok 6 - $P0.open($S1, $S2) # new file, write mode succeeds'
68 say 'ok 5 - $P0.open($S1) # with bad file'
75 ok 3 - $P0.open($S1, $S2) # rw mode
77 ok 5 - $P0.open($S1) # with bad file
78 ok 6 - $P0.open($S1, $S2) # new file, write mode succeeds
81 # RT#46827 test open file, close file, delete file, reopen previously opened stream
83 # RT#46829 cleanup 'new_file' in previous test; which is todo'd, so the
84 # file isn't even being *generated* yet.
87 skip 'no asynch calls yet' => 1;
89 pir_output_is( <<'CODE', <<'OUT', 'open and close - asynchronous' );
91 $P1 = # RT#46831 create a callback here
95 say 'ok 1 - $P0.open($S1)'
98 say 'ok 2 - $P0.close($P1)'
100 $P0.open('README', 'rw')
101 say 'ok 3 - $P0.open($S1, $S2)'
105 say 'ok 4 - $P0.open()'
113 ok 3 - $P0.open($S1, $S2)
118 # L<PDD22/I\/O PMC API/=item print.*=item readline>
120 <<'CODE', <<'OUT', 'print, read, and readline - synchronous', todo => 'not yet implemented' );
122 load_bytecode 'String/Utils.pbc'
124 chomp = get_global ['String';'Utils'], 'chomp'
129 $S0 = $P0.read(14) # bytes
130 if $S0 == 'This is Parrot' goto ok_1
133 say 'ok 1 - $S0 = $P1.read($I2)'
135 $S0 = $P0.read(9) # bytes
136 if $S0 == ', version' goto ok_2
139 say 'ok 2 - $S0 = $P1.read($I2) # again on same stream'
143 $P0.print("squawk\n")
147 say 'ok 3 - $P0.print(${I,N,S,P}1)'
151 if $S0 == '123456.789000squawk' goto ok_4
154 say 'ok 4 - $S0 = $P1.readline($I2)'
158 if $S0 == '42' goto ok_5
161 say 'ok 5 - $S0 = $P1.readline($I2) # again on same stream'
164 ok 1 - $S0 = $P1.read($I2)
165 ok 2 - $S0 = $P1.read($I2) # again on same stream
166 ok 3 - $P0.print(${I,N,S,P}1)
167 ok 4 - $S0 = $P1.readline($I2)
168 ok 5 - $S0 = $P1.readline($I2) # again on same stream
171 # RT#46833 test reading/writing code points once supported
173 # RT#46835 test reading long chunks, eof, and across newlines
175 # RT#46837 pir_output_is( <<'CODE', <<'OUT', 'print, read, and readline - asynchronous', todo => 'not yet implemented' );
177 # L<PDD22/I\/O PMC API/=item record_separator>
178 pir_output_is( <<'CODE', <<'OUT', 'record_separator', todo => 'not yet implemented' );
182 $S0 = $P0.record_separator()
183 if $S0 == "\n" goto ok_1
186 say 'ok 1 - $S0 = $P1.record_separator() # default'
189 $P0.record_separator($S99)
190 $S0 = $P0.record_separator()
191 if $S0 == $S99 goto ok_2
194 say 'ok 2 - $P0.record_separator($S1)'
197 $S0 = $P0.record_separator()
202 if $S0 == '123abc' goto ok_3
205 say 'ok 3 - $P0.record_separator() # .readline works as expected'
208 ok 1 - $S0 = $P1.record_separator() # default
209 ok 2 - $P0.record_separator($S1)
210 ok 3 - $P0.record_separator() # .readline works as expected
213 # L<PDD22/I\/O PMC API/=item buffer_type>
214 pir_output_is( <<'CODE', <<'OUT', 'buffer_type', todo => 'not yet implemented' );
216 .include 'io_buffer_types.pasm'
220 $P0.buffer_type('unbuffered')
221 $I0 = $P0.buffer_type()
222 if $I0 == PIO_NONBUF goto ok_1
225 say 'ok 1 - $I0 = $P1.buffer_type() # PIO_NONBUF'
227 $P0.buffer_type(PIO_NONBUF)
228 $S0 = $P0.buffer_type()
229 if $S0 == 'unbuffered' goto ok_2
232 say 'ok 2 - $S0 = $P1.buffer_type() # PIO_NONBUF'
234 $P0.buffer_type('line-buffered')
235 $I0 = $P0.buffer_type()
236 if $I0 == PIO_LINEBUF goto ok_3
239 say 'ok 3 - $I0 = $P1.buffer_type() # PIO_LINEBUF'
241 $P0.buffer_type(PIO_LINEBUF)
242 $S0 = $P0.buffer_type()
243 if $S0 == 'line-buffered' goto ok_4
246 say 'ok 4 - $S0 = $P1.buffer_type() # PIO_LINEBUF'
248 $P0.buffer_type('full-buffered')
249 $I0 = $P0.buffer_type()
250 if $I0 == PIO_FULLBUF goto ok_5
253 say 'ok 5 - $I0 = $P1.buffer_type() # PIO_FULLBUF'
255 $P0.buffer_type(PIO_FULLBUF)
256 $S0 = $P0.buffer_type()
257 if $S0 == 'full-buffered' goto ok_6
260 say 'ok 6 - $S0 = $P1.buffer_type() # PIO_FULLBUF'
263 ok 1 - $I0 = $P1.buffer_type() # PIO_NONBUF
264 ok 2 - $S0 = $P1.buffer_type() # PIO_NONBUF
265 ok 3 - $I0 = $P1.buffer_type() # PIO_LINEBUF
266 ok 4 - $S0 = $P1.buffer_type() # PIO_LINEBUF
267 ok 5 - $I0 = $P1.buffer_type() # PIO_FULLBUF
268 ok 6 - $S0 = $P1.buffer_type() # PIO_FULLBUF
271 # RT#46839 test effects of buffer_type, not just set/get
274 # L<PDD22/I\/O PMC API/=item buffer_size>
275 # NOTES: try setting positive, zero, negative int
276 # perform print and read ops
277 # change buffer size while it contains data
278 # try with all 'buffer_type' modes
281 # L<PDD22/I\/O PMC API/=item get_fd>
282 # NOTES: this is going to be platform dependent
286 # cperl-indent-level: 4
289 # vim: expandtab shiftwidth=4: