2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/package/tar_test_case'
|
2008-03-31 18:40:06 -04:00
|
|
|
require 'rubygems/package'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemPackageTarReaderEntry < Gem::Package::TarTestCase
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@contents = ('a'..'z').to_a.join * 100
|
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
@tar = String.new
|
2013-09-14 04:59:02 -04:00
|
|
|
@tar << tar_file_header("lib/foo", "", 0, @contents.size, Time.now)
|
2008-03-31 18:40:06 -04:00
|
|
|
@tar << @contents
|
|
|
|
@tar << "\0" * (512 - (@tar.size % 512))
|
|
|
|
|
|
|
|
@entry = util_entry @tar
|
|
|
|
end
|
|
|
|
|
2014-05-26 10:36:22 -04:00
|
|
|
def teardown
|
2014-07-01 12:18:43 -04:00
|
|
|
close_util_entry(@entry)
|
2014-05-26 10:36:22 -04:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2014-07-01 12:18:43 -04:00
|
|
|
def close_util_entry(entry)
|
|
|
|
entry.instance_variable_get(:@io).close!
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def test_bytes_read
|
|
|
|
assert_equal 0, @entry.bytes_read
|
|
|
|
|
|
|
|
@entry.getc
|
|
|
|
|
|
|
|
assert_equal 1, @entry.bytes_read
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_close
|
|
|
|
@entry.close
|
|
|
|
|
|
|
|
assert @entry.bytes_read
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
e = assert_raises IOError do @entry.eof? end
|
2008-03-31 18:40:06 -04:00
|
|
|
assert_equal 'closed Gem::Package::TarReader::Entry', e.message
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
e = assert_raises IOError do @entry.getc end
|
2008-03-31 18:40:06 -04:00
|
|
|
assert_equal 'closed Gem::Package::TarReader::Entry', e.message
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
e = assert_raises IOError do @entry.pos end
|
2008-03-31 18:40:06 -04:00
|
|
|
assert_equal 'closed Gem::Package::TarReader::Entry', e.message
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
e = assert_raises IOError do @entry.read end
|
2008-03-31 18:40:06 -04:00
|
|
|
assert_equal 'closed Gem::Package::TarReader::Entry', e.message
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
e = assert_raises IOError do @entry.rewind end
|
2008-03-31 18:40:06 -04:00
|
|
|
assert_equal 'closed Gem::Package::TarReader::Entry', e.message
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_closed_eh
|
|
|
|
@entry.close
|
|
|
|
|
|
|
|
assert @entry.closed?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_eof_eh
|
|
|
|
@entry.read
|
|
|
|
|
|
|
|
assert @entry.eof?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_full_name
|
|
|
|
assert_equal 'lib/foo', @entry.full_name
|
|
|
|
end
|
|
|
|
|
2011-01-31 22:11:34 -05:00
|
|
|
def test_full_name_null
|
|
|
|
@entry.header.prefix << "\000"
|
|
|
|
|
|
|
|
e = assert_raises Gem::Package::TarInvalidError do
|
|
|
|
@entry.full_name
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'tar is corrupt, name contains null byte', e.message
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def test_getc
|
|
|
|
assert_equal ?a, @entry.getc
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_directory_eh
|
|
|
|
assert_equal false, @entry.directory?
|
2014-07-01 12:18:43 -04:00
|
|
|
dir_ent = util_dir_entry
|
|
|
|
assert_equal true, dir_ent.directory?
|
|
|
|
ensure
|
|
|
|
close_util_entry(dir_ent) if dir_ent
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
def test_symlink_eh
|
|
|
|
assert_equal false, @entry.symlink?
|
|
|
|
symlink_ent = util_symlink_entry
|
|
|
|
assert_equal true, symlink_ent.symlink?
|
|
|
|
ensure
|
|
|
|
close_util_entry(symlink_ent) if symlink_ent
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def test_file_eh
|
|
|
|
assert_equal true, @entry.file?
|
2014-07-01 12:18:43 -04:00
|
|
|
dir_ent = util_dir_entry
|
|
|
|
assert_equal false, dir_ent.file?
|
|
|
|
ensure
|
|
|
|
close_util_entry(dir_ent) if dir_ent
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_pos
|
|
|
|
assert_equal 0, @entry.pos
|
|
|
|
|
|
|
|
@entry.getc
|
|
|
|
|
|
|
|
assert_equal 1, @entry.pos
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_read
|
|
|
|
assert_equal @contents, @entry.read
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_read_big
|
|
|
|
assert_equal @contents, @entry.read(@contents.size * 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_read_small
|
|
|
|
assert_equal @contents[0...100], @entry.read(100)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rewind
|
|
|
|
char = @entry.getc
|
|
|
|
|
|
|
|
@entry.rewind
|
|
|
|
|
|
|
|
assert_equal 0, @entry.pos
|
|
|
|
|
|
|
|
assert_equal char, @entry.getc
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|