2020-02-16 09:21:29 +03:00
|
|
|
# frozen_string_literal: true
|
2016-08-29 08:47:09 +03:00
|
|
|
require 'test/unit'
|
|
|
|
|
2017-09-03 15:35:27 +03:00
|
|
|
if defined?(OpenSSL)
|
|
|
|
|
2016-11-05 10:10:05 +03:00
|
|
|
module OpenSSL::TestEOF
|
2021-04-16 02:53:47 +03:00
|
|
|
def test_getbyte_eof
|
|
|
|
open_file("") {|f| assert_nil f.getbyte }
|
|
|
|
end
|
|
|
|
|
2016-08-29 08:47:09 +03:00
|
|
|
def test_eof_0
|
|
|
|
open_file("") {|f|
|
|
|
|
assert_equal("", f.read(0))
|
|
|
|
assert_equal("", f.read(0))
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_equal("", f.read(0))
|
|
|
|
assert_equal("", f.read(0))
|
|
|
|
}
|
|
|
|
open_file("") {|f|
|
|
|
|
assert_nil(f.read(1))
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_nil(f.read(1))
|
|
|
|
}
|
|
|
|
open_file("") {|f|
|
2020-02-16 09:21:29 +03:00
|
|
|
s = +"x"
|
2016-08-29 08:47:09 +03:00
|
|
|
assert_equal("", f.read(nil, s))
|
|
|
|
assert_equal("", s)
|
|
|
|
}
|
|
|
|
open_file("") {|f|
|
2020-02-16 09:21:29 +03:00
|
|
|
s = +"x"
|
2016-08-29 08:47:09 +03:00
|
|
|
assert_nil(f.read(10, s))
|
|
|
|
assert_equal("", s)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_eof_0_rw
|
|
|
|
return unless respond_to? :open_file_rw
|
|
|
|
open_file_rw("") {|f|
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_equal(0, f.syswrite(""))
|
|
|
|
assert_equal("", f.read)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_eof_1
|
|
|
|
open_file("a") {|f|
|
|
|
|
assert_equal("", f.read(0))
|
|
|
|
assert_equal("a", f.read(1))
|
|
|
|
assert_equal("" , f.read(0))
|
|
|
|
assert_equal("" , f.read(0))
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_equal("", f.read(0))
|
|
|
|
assert_equal("", f.read(0))
|
|
|
|
}
|
|
|
|
open_file("a") {|f|
|
|
|
|
assert_equal("a", f.read(1))
|
|
|
|
assert_nil(f.read(1))
|
|
|
|
}
|
|
|
|
open_file("a") {|f|
|
|
|
|
assert_equal("a", f.read(2))
|
|
|
|
assert_nil(f.read(1))
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_nil(f.read(1))
|
|
|
|
}
|
|
|
|
open_file("a") {|f|
|
|
|
|
assert_equal("a", f.read)
|
|
|
|
assert_nil(f.read(1))
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_nil(f.read(1))
|
|
|
|
}
|
|
|
|
open_file("a") {|f|
|
|
|
|
assert_equal("a", f.read(2))
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_equal("", f.read)
|
|
|
|
}
|
|
|
|
open_file("a") {|f|
|
|
|
|
assert_equal("a", f.read)
|
|
|
|
assert_equal("", f.read(0))
|
|
|
|
}
|
|
|
|
open_file("a") {|f|
|
2020-02-16 09:21:29 +03:00
|
|
|
s = +"x"
|
2016-08-29 08:47:09 +03:00
|
|
|
assert_equal("a", f.read(nil, s))
|
|
|
|
assert_equal("a", s)
|
|
|
|
}
|
|
|
|
open_file("a") {|f|
|
2020-02-16 09:21:29 +03:00
|
|
|
s = +"x"
|
2016-08-29 08:47:09 +03:00
|
|
|
assert_equal("a", f.read(10, s))
|
|
|
|
assert_equal("a", s)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_eof_2
|
|
|
|
open_file("") {|f|
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_predicate(f, :eof?)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_eof_3
|
|
|
|
open_file("") {|f|
|
|
|
|
assert_predicate(f, :eof?)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
module Seek
|
|
|
|
def open_file_seek(content, pos)
|
|
|
|
open_file(content) do |f|
|
|
|
|
f.seek(pos)
|
|
|
|
yield f
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_eof_0_seek
|
|
|
|
open_file_seek("", 10) {|f|
|
|
|
|
assert_equal(10, f.pos)
|
|
|
|
assert_equal("", f.read(0))
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_equal("", f.read(0))
|
|
|
|
assert_equal("", f.read)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_eof_1_seek
|
|
|
|
open_file_seek("a", 10) {|f|
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_equal("", f.read)
|
|
|
|
}
|
|
|
|
open_file_seek("a", 1) {|f|
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_equal("", f.read)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-09-03 15:35:27 +03:00
|
|
|
|
|
|
|
end
|