Class: ZipInputStreamTest

Inherits:
MiniTest::Test
  • Object
show all
Includes:
AssertEntry
Defined in:
lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb

Instance Method Summary collapse

Methods included from AssertEntry

assert_contents, #assert_entry, #assert_entryContents, #assert_entryContentsForStream, #assert_next_entry, #assert_stream_contents, #assert_test_zip_contents

Instance Method Details

#test_incomplete_reads_from_string_ioObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb', line 79

def test_incomplete_reads_from_string_io
  string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
  ::Zip::InputStream.open(string_io) do |zis|
    entry = zis.get_next_entry # longAscii.txt
    assert_equal(false, zis.eof?)
    assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
    assert zis.gets.length > 0
    assert_equal(false, zis.eof?)
    entry = zis.get_next_entry # empty.txt
    assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
    assert_equal(0, entry.size)
    assert_equal(nil, zis.gets)
    assert_equal(true, zis.eof?)
    entry = zis.get_next_entry # empty_chmod640.txt
    assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
    assert_equal(0, entry.size)
    assert_equal(nil, zis.gets)
    assert_equal(true, zis.eof?)
    entry = zis.get_next_entry # short.txt
    assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
    assert zis.gets.length > 0
    entry = zis.get_next_entry # longBinary.bin
    assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
    assert zis.gets.length > 0
  end
end

#test_incompleteReadsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb', line 52

def test_incompleteReads
  ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
      |zis|
    entry = zis.get_next_entry # longAscii.txt
    assert_equal(false, zis.eof?)
    assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
    assert zis.gets.length > 0
    assert_equal(false, zis.eof?)
    entry = zis.get_next_entry # empty.txt
    assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
    assert_equal(0, entry.size)
    assert_equal(nil, zis.gets)
    assert_equal(true, zis.eof?)
    entry = zis.get_next_entry # empty_chmod640.txt
    assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
    assert_equal(0, entry.size)
    assert_equal(nil, zis.gets)
    assert_equal(true, zis.eof?)
    entry = zis.get_next_entry # short.txt
    assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
    assert zis.gets.length > 0
    entry = zis.get_next_entry # longBinary.bin
    assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
    assert zis.gets.length > 0
  }
end

#test_mix_read_and_getsObject



147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb', line 147

def test_mix_read_and_gets
  ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
      |zis|
    zis.get_next_entry
    assert_equal("#!/usr/bin/env ruby", zis.gets.chomp)
    assert_equal(false, zis.eof?)
    assert_equal("", zis.gets.chomp)
    assert_equal(false, zis.eof?)
    assert_equal("$VERBOSE =", zis.read(10))
    assert_equal(false, zis.eof?)
  }
end

#test_newObject



6
7
8
9
10
11
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb', line 6

def test_new
  zis = ::Zip::InputStream.new(TestZipFile::TEST_ZIP2.zip_name)
  assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
  assert_equal(true, zis.eof?)
  zis.close
end

#test_open_string_io_with_blockObject



39
40
41
42
43
44
45
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb', line 39

def test_open_string_io_with_block
  string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
  ::Zip::InputStream.open(string_io) do |zis|
    assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
    assert_equal(true, zis.eof?)
  end
end

#test_open_string_io_without_blockObject



33
34
35
36
37
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb', line 33

def test_open_string_io_without_block
  string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
  zis = ::Zip::InputStream.open(string_io)
  assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
end

#test_openBufferWithBlockObject



26
27
28
29
30
31
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb', line 26

def test_openBufferWithBlock
  ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, "rb")) do |zis|
    assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
    assert_equal(true, zis.eof?)
  end
end

#test_openBufferWithoutBlockObject



47
48
49
50
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb', line 47

def test_openBufferWithoutBlock
  zis = ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
  assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
end

#test_openWithBlockObject



13
14
15
16
17
18
19
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb', line 13

def test_openWithBlock
  ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
      |zis|
    assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
    assert_equal(true, zis.eof?)
  }
end

#test_openWithoutBlockObject



21
22
23
24
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb', line 21

def test_openWithoutBlock
  zis = ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, "rb"))
  assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
end

#test_read_with_number_of_bytes_returns_nil_at_eofObject



106
107
108
109
110
111
112
113
114
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb', line 106

def test_read_with_number_of_bytes_returns_nil_at_eof
  ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
    entry = zis.get_next_entry # longAscii.txt
    zis.read(entry.size)
    assert_equal(true, zis.eof?)
    assert_nil(zis.read(1))
    assert_nil(zis.read(1))
  end
end

#test_rewindObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb', line 116

def test_rewind
  ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
      |zis|
    e = zis.get_next_entry
    assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], e.name)

    # Do a little reading
    buf = ""
    buf << zis.read(100)
    assert_equal(100, zis.pos)
    buf << (zis.gets || "")
    buf << (zis.gets || "")
    assert_equal(false, zis.eof?)

    zis.rewind

    buf2 = ""
    buf2 << zis.read(100)
    buf2 << (zis.gets || "")
    buf2 << (zis.gets || "")

    assert_equal(buf, buf2)

    zis.rewind
    assert_equal(false, zis.eof?)
    assert_equal(0, zis.pos)

    assert_entry(e.name, zis, e.name)
  }
end

#test_ungetcObject



160
161
162
163
164
165
166
167
168
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb', line 160

def test_ungetc
  ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
    zis.get_next_entry
    first_line = zis.gets.chomp
    first_line.reverse.bytes.each { |b| zis.ungetc(b) }
    assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
    assert_equal("$VERBOSE =", zis.read(10))
  end
end