copy_stream: enough to get this working under MRI 1.8
[ruby_io_splice.git] / test / test_io_splice_in_full.rb
blob44263516caabfb802089619e0cc6a380461e712e
1 # -*- encoding: binary -*-
2 require 'test/unit'
3 require 'tempfile'
4 $-w = true
5 require 'io/splice'
6 Thread.abort_on_exception = true
8 class Test_IO_Splice_In_Full < Test::Unit::TestCase
9   def test_splice_in_full
10     rd, wr = IO.pipe
11     tmp = Tempfile.new 'splice-read'
12     Thread.new do
13       111.times do
14         sleep 0.002
15         wr.write "HIHIHI"
16       end
17     end
18     nr = IO.splice rd, nil, tmp, nil, 666, IO::Splice::WAITALL
19     assert_equal 666, nr
20     tmp.rewind
21     assert_equal "HIHIHI" * 111, tmp.read
22   end
24   def test_tee_in_full
25     rd, wr = IO.pipe
26     a, b = IO.pipe
27     thr = Thread.new { a.read(666) }
28     Thread.new do
29       111.times do
30         sleep 0.001
31         wr.syswrite "HIHIHI"
32       end
33     end
34     nr = IO.tee rd, b, 666, IO::Splice::WAITALL
35     assert_equal 666, nr
36     thr.join
37     assert_equal "HIHIHI" * 111, thr.value
38   end
39 end if defined?(RUBY_ENGINE)