Class: ZipOutputStreamTest
- Inherits:
-
MiniTest::Test
- Object
- MiniTest::Test
- ZipOutputStreamTest
show all
- Includes:
- AssertEntry
- Defined in:
- lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb
Constant Summary
collapse
- TEST_ZIP =
TestZipFile::TEST_ZIP2.clone
Instance Method Summary
collapse
assert_contents, #assert_entry, #assert_entryContents, #assert_entryContentsForStream, #assert_next_entry, #assert_stream_contents, #assert_test_zip_contents
Instance Method Details
#assert_i_o_error_in_closed_stream ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb', line 115
def assert_i_o_error_in_closed_stream
assert_raises(IOError) {
zos = ::Zip::OutputStream.new("test/data/generated/test_putOnClosedStream.zip")
zos.close
yield zos
}
end
|
#test_cannotOpenFile ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb', line 56
def test_cannotOpenFile
name = TestFiles::EMPTY_TEST_DIR
begin
::Zip::OutputStream.open(name)
rescue Exception
assert($!.kind_of?(Errno::EISDIR) || $!.kind_of?(Errno::EEXIST) || $!.kind_of?(Errno::EACCES), "Expected Errno::EISDIR (or on win/cygwin: Errno::EEXIST), but was: #{$!.class}")
end
end
|
#test_chained_put_into_next_entry ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb', line 98
def test_chained_put_into_next_entry
stored_text = "hello world in stored text"
stored_text2 = "with chain"
entry_name = "file1"
= "my comment"
::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos|
zos.put_next_entry(entry_name, , nil, ::Zip::Entry::STORED)
zos << stored_text << stored_text2
end
assert(File.read(TEST_ZIP.zip_name)[stored_text])
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
assert_equal(stored_text + stored_text2, zf.read(entry_name))
end
end
|
#test_new ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb', line 9
def test_new
zos = ::Zip::OutputStream.new(TEST_ZIP.zip_name)
zos. = TEST_ZIP.
write_test_zip(zos)
zos.close
assert_test_zip_contents(TEST_ZIP)
end
|
#test_open ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb', line 17
def test_open
::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos|
zos. = TEST_ZIP.
write_test_zip(zos)
end
assert_test_zip_contents(TEST_ZIP)
end
|
#test_put_next_entry ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb', line 68
def test_put_next_entry
stored_text = "hello world in stored text"
entry_name = "file1"
= "my comment"
::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos|
zos.put_next_entry(entry_name, , nil, ::Zip::Entry::STORED)
zos << stored_text
end
assert(File.read(TEST_ZIP.zip_name)[stored_text])
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
assert_equal(stored_text, zf.read(entry_name))
end
end
|
#test_put_next_entry_using_zip_entry_creates_entries_with_correct_timestamps ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb', line 83
def test_put_next_entry_using_zip_entry_creates_entries_with_correct_timestamps
file = ::File.open("test/data/file2.txt", "rb")
::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos|
zip_entry = ::Zip::Entry.new(zos, file.path, "", "", 0, 0, ::Zip::Entry::DEFLATED, 0, ::Zip::DOSTime.at(file.mtime))
zos.put_next_entry(zip_entry)
zos << file.read
end
::Zip::InputStream::open(TEST_ZIP.zip_name) do |io|
while (entry = io.get_next_entry)
assert(::Zip::DOSTime.at(file.mtime).dos_equals(::Zip::DOSTime.at(entry.mtime))) end
end
end
|
#test_write_buffer ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb', line 25
def test_write_buffer
io = ::StringIO.new('')
buffer = ::Zip::OutputStream.write_buffer(io) do |zos|
zos. = TEST_ZIP.
write_test_zip(zos)
end
File.open(TEST_ZIP.zip_name, 'wb') { |f| f.write buffer.string }
assert_test_zip_contents(TEST_ZIP)
end
|
#test_write_buffer_with_temp_file ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb', line 35
def test_write_buffer_with_temp_file
tmp_file = Tempfile.new('')
::Zip::OutputStream.write_buffer(tmp_file) do |zos|
zos. = TEST_ZIP.
write_test_zip(zos)
end
tmp_file.rewind
File.open(TEST_ZIP.zip_name, 'wb') { |f| f.write(tmp_file.read) }
tmp_file.unlink
assert_test_zip_contents(TEST_ZIP)
end
|
#test_writingToClosedStream ⇒ Object
50
51
52
53
54
|
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb', line 50
def test_writingToClosedStream
assert_i_o_error_in_closed_stream { |zos| zos << "hello world" }
assert_i_o_error_in_closed_stream { |zos| zos.puts "hello world" }
assert_i_o_error_in_closed_stream { |zos| zos.write "hello world" }
end
|
#write_test_zip(zos) ⇒ Object
123
124
125
126
127
128
|
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb', line 123
def write_test_zip(zos)
TEST_ZIP.entry_names.each do |entryName|
zos.put_next_entry(entryName)
File.open(entryName, "rb") { |f| zos.write(f.read) }
end
end
|