rubyzip 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubyzip might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/zip/file.rb +2 -1
- data/lib/zip/inflater.rb +15 -44
- data/lib/zip/ioextras/abstract_input_stream.rb +5 -1
- data/lib/zip/version.rb +1 -1
- data/test/alltests.rb +18 -0
- data/test/basic_zip_file_test.rb +64 -0
- data/test/central_directory_entry_test.rb +73 -0
- data/test/central_directory_test.rb +100 -0
- data/test/data/file1.txt +46 -0
- data/test/data/file1.txt.deflatedData +0 -0
- data/test/data/file2.txt +1504 -0
- data/test/data/file2.txt.other +0 -0
- data/test/data/globTest.zip +0 -0
- data/test/data/globTest/foo.txt +0 -0
- data/test/data/globTest/foo/bar/baz/foo.txt +0 -0
- data/test/data/globTest/food.txt +0 -0
- data/test/data/mimetype +1 -0
- data/test/data/notzippedruby.rb +7 -0
- data/test/data/rubycode.zip +0 -0
- data/test/data/rubycode2.zip +0 -0
- data/test/data/testDirectory.bin +0 -0
- data/test/data/zip64-sample.zip +0 -0
- data/test/data/zipWithDirs.zip +0 -0
- data/test/deflater_test.rb +62 -0
- data/test/dummy.txt +1 -0
- data/test/entry_set_test.rb +125 -0
- data/test/entry_test.rb +165 -0
- data/test/errors_test.rb +36 -0
- data/test/extra_field_test.rb +69 -0
- data/test/file_extract_directory_test.rb +55 -0
- data/test/file_extract_test.rb +90 -0
- data/test/file_split_test.rb +60 -0
- data/test/file_test.rb +568 -0
- data/test/filesystem/dir_iterator_test.rb +62 -0
- data/test/filesystem/directory_test.rb +131 -0
- data/test/filesystem/file_mutating_test.rb +100 -0
- data/test/filesystem/file_nonmutating_test.rb +505 -0
- data/test/filesystem/file_stat_test.rb +66 -0
- data/test/gentestfiles.rb +134 -0
- data/test/inflater_test.rb +14 -0
- data/test/input_stream_test.rb +170 -0
- data/test/ioextras/abstract_input_stream_test.rb +103 -0
- data/test/ioextras/abstract_output_stream_test.rb +106 -0
- data/test/ioextras/fake_io_test.rb +18 -0
- data/test/ioextrastest.rb +233 -0
- data/test/local_entry_test.rb +153 -0
- data/test/odt_test_fix.rb +30 -0
- data/test/output_stream_test.rb +114 -0
- data/test/pass_thru_compressor_test.rb +31 -0
- data/test/pass_thru_decompressor_test.rb +15 -0
- data/test/sample.odt +0 -0
- data/test/settings_test.rb +71 -0
- data/test/test_helper.rb +228 -0
- data/test/unicode_file_names_and_comments_test.rb +40 -0
- data/test/zip64_full_test.rb +49 -0
- data/test/zip64_support_test.rb +15 -0
- metadata +107 -3
File without changes
|
Binary file
|
File without changes
|
File without changes
|
File without changes
|
data/test/data/mimetype
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
application/epub+zip
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DeflaterTest < MiniTest::Unit::TestCase
|
4
|
+
include CrcTest
|
5
|
+
|
6
|
+
def test_outputOperator
|
7
|
+
txt = load_file("test/data/file2.txt")
|
8
|
+
deflate(txt, "deflatertest.bin")
|
9
|
+
inflatedTxt = inflate("deflatertest.bin")
|
10
|
+
assert_equal(txt, inflatedTxt)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_default_compression
|
14
|
+
txt = load_file("test/data/file2.txt")
|
15
|
+
|
16
|
+
Zip.default_compression = ::Zlib::BEST_COMPRESSION
|
17
|
+
deflate(txt, "compressiontest_best_compression.bin")
|
18
|
+
Zip.default_compression = ::Zlib::DEFAULT_COMPRESSION
|
19
|
+
deflate(txt, "compressiontest_default_compression.bin")
|
20
|
+
Zip.default_compression = ::Zlib::NO_COMPRESSION
|
21
|
+
deflate(txt, "compressiontest_no_compression.bin")
|
22
|
+
|
23
|
+
best = File.size("compressiontest_best_compression.bin")
|
24
|
+
default = File.size("compressiontest_default_compression.bin")
|
25
|
+
no = File.size("compressiontest_no_compression.bin")
|
26
|
+
|
27
|
+
assert(best < default)
|
28
|
+
assert(best < no)
|
29
|
+
assert(default < no)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
private
|
34
|
+
def load_file(fileName)
|
35
|
+
txt = nil
|
36
|
+
File.open(fileName, "rb") { |f| txt = f.read }
|
37
|
+
end
|
38
|
+
|
39
|
+
def deflate(data, fileName)
|
40
|
+
File.open(fileName, "wb") {
|
41
|
+
|file|
|
42
|
+
deflater = ::Zip::Deflater.new(file)
|
43
|
+
deflater << data
|
44
|
+
deflater.finish
|
45
|
+
assert_equal(deflater.size, data.size)
|
46
|
+
file << "trailing data for zlib with -MAX_WBITS"
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def inflate(fileName)
|
51
|
+
txt = nil
|
52
|
+
File.open(fileName, "rb") {
|
53
|
+
|file|
|
54
|
+
inflater = ::Zip::Inflater.new(file)
|
55
|
+
txt = inflater.sysread
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_crc
|
60
|
+
run_crc_test(::Zip::Deflater)
|
61
|
+
end
|
62
|
+
end
|
data/test/dummy.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
hello worldbingo
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ZipEntrySetTest < MiniTest::Unit::TestCase
|
4
|
+
ZIP_ENTRIES = [
|
5
|
+
::Zip::Entry.new("zipfile.zip", "name1", "comment1"),
|
6
|
+
::Zip::Entry.new("zipfile.zip", "name3", "comment1"),
|
7
|
+
::Zip::Entry.new("zipfile.zip", "name2", "comment1"),
|
8
|
+
::Zip::Entry.new("zipfile.zip", "name4", "comment1"),
|
9
|
+
::Zip::Entry.new("zipfile.zip", "name5", "comment1"),
|
10
|
+
::Zip::Entry.new("zipfile.zip", "name6", "comment1")
|
11
|
+
]
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@zipEntrySet = ::Zip::EntrySet.new(ZIP_ENTRIES)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_include
|
18
|
+
assert(@zipEntrySet.include?(ZIP_ENTRIES.first))
|
19
|
+
assert(!@zipEntrySet.include?(::Zip::Entry.new("different.zip", "different", "aComment")))
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_size
|
23
|
+
assert_equal(ZIP_ENTRIES.size, @zipEntrySet.size)
|
24
|
+
assert_equal(ZIP_ENTRIES.size, @zipEntrySet.length)
|
25
|
+
@zipEntrySet << ::Zip::Entry.new("a", "b", "c")
|
26
|
+
assert_equal(ZIP_ENTRIES.size + 1, @zipEntrySet.length)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_add
|
30
|
+
zes = ::Zip::EntrySet.new
|
31
|
+
entry1 = ::Zip::Entry.new("zf.zip", "name1")
|
32
|
+
entry2 = ::Zip::Entry.new("zf.zip", "name2")
|
33
|
+
zes << entry1
|
34
|
+
assert(zes.include?(entry1))
|
35
|
+
zes.push(entry2)
|
36
|
+
assert(zes.include?(entry2))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_delete
|
40
|
+
assert_equal(ZIP_ENTRIES.size, @zipEntrySet.size)
|
41
|
+
entry = @zipEntrySet.delete(ZIP_ENTRIES.first)
|
42
|
+
assert_equal(ZIP_ENTRIES.size - 1, @zipEntrySet.size)
|
43
|
+
assert_equal(ZIP_ENTRIES.first, entry)
|
44
|
+
|
45
|
+
entry = @zipEntrySet.delete(ZIP_ENTRIES.first)
|
46
|
+
assert_equal(ZIP_ENTRIES.size - 1, @zipEntrySet.size)
|
47
|
+
assert_nil(entry)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_each
|
51
|
+
# Used each instead each_with_index due the bug in jRuby
|
52
|
+
count = 0
|
53
|
+
@zipEntrySet.each do |entry|
|
54
|
+
assert(ZIP_ENTRIES.include?(entry))
|
55
|
+
count += 1
|
56
|
+
end
|
57
|
+
assert_equal(ZIP_ENTRIES.size, count)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_entries
|
61
|
+
assert_equal(ZIP_ENTRIES, @zipEntrySet.entries)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_entries_with_sort
|
65
|
+
::Zip.sort_entries = true
|
66
|
+
assert_equal(ZIP_ENTRIES.sort, @zipEntrySet.entries)
|
67
|
+
::Zip.sort_entries = false
|
68
|
+
assert_equal(ZIP_ENTRIES, @zipEntrySet.entries)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_compound
|
72
|
+
newEntry = ::Zip::Entry.new("zf.zip", "new entry", "new entry's comment")
|
73
|
+
assert_equal(ZIP_ENTRIES.size, @zipEntrySet.size)
|
74
|
+
@zipEntrySet << newEntry
|
75
|
+
assert_equal(ZIP_ENTRIES.size + 1, @zipEntrySet.size)
|
76
|
+
assert(@zipEntrySet.include?(newEntry))
|
77
|
+
|
78
|
+
@zipEntrySet.delete(newEntry)
|
79
|
+
assert_equal(ZIP_ENTRIES.size, @zipEntrySet.size)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_dup
|
83
|
+
copy = @zipEntrySet.dup
|
84
|
+
assert_equal(@zipEntrySet, copy)
|
85
|
+
|
86
|
+
# demonstrate that this is a deep copy
|
87
|
+
copy.entries[0].name = "a totally different name"
|
88
|
+
assert(@zipEntrySet != copy)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_parent
|
92
|
+
entries = [
|
93
|
+
::Zip::Entry.new("zf.zip", "a/"),
|
94
|
+
::Zip::Entry.new("zf.zip", "a/b/"),
|
95
|
+
::Zip::Entry.new("zf.zip", "a/b/c/")
|
96
|
+
]
|
97
|
+
entrySet = ::Zip::EntrySet.new(entries)
|
98
|
+
|
99
|
+
assert_equal(nil, entrySet.parent(entries[0]))
|
100
|
+
assert_equal(entries[0], entrySet.parent(entries[1]))
|
101
|
+
assert_equal(entries[1], entrySet.parent(entries[2]))
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_glob
|
105
|
+
res = @zipEntrySet.glob('name[2-4]')
|
106
|
+
assert_equal(3, res.size)
|
107
|
+
assert_equal(ZIP_ENTRIES[1, 3].sort, res.sort)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_glob2
|
111
|
+
entries = [
|
112
|
+
::Zip::Entry.new("zf.zip", "a/"),
|
113
|
+
::Zip::Entry.new("zf.zip", "a/b/b1"),
|
114
|
+
::Zip::Entry.new("zf.zip", "a/b/c/"),
|
115
|
+
::Zip::Entry.new("zf.zip", "a/b/c/c1")
|
116
|
+
]
|
117
|
+
entrySet = ::Zip::EntrySet.new(entries)
|
118
|
+
|
119
|
+
assert_equal(entries[0, 1], entrySet.glob("*"))
|
120
|
+
# assert_equal(entries[FIXME], entrySet.glob("**"))
|
121
|
+
# res = entrySet.glob('a*')
|
122
|
+
# assert_equal(entries.size, res.size)
|
123
|
+
# assert_equal(entrySet.map { |e| e.name }, res.map { |e| e.name })
|
124
|
+
end
|
125
|
+
end
|
data/test/entry_test.rb
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ZipEntryTest < MiniTest::Unit::TestCase
|
4
|
+
TEST_ZIPFILE = "someZipFile.zip"
|
5
|
+
TEST_COMMENT = "a comment"
|
6
|
+
TEST_COMPRESSED_SIZE = 1234
|
7
|
+
TEST_CRC = 325324
|
8
|
+
TEST_EXTRA = "Some data here"
|
9
|
+
TEST_COMPRESSIONMETHOD = ::Zip::Entry::DEFLATED
|
10
|
+
TEST_NAME = "entry name"
|
11
|
+
TEST_SIZE = 8432
|
12
|
+
TEST_ISDIRECTORY = false
|
13
|
+
TEST_TIME = Time.now
|
14
|
+
|
15
|
+
def test_constructorAndGetters
|
16
|
+
entry = ::Zip::Entry.new(TEST_ZIPFILE,
|
17
|
+
TEST_NAME,
|
18
|
+
TEST_COMMENT,
|
19
|
+
TEST_EXTRA,
|
20
|
+
TEST_COMPRESSED_SIZE,
|
21
|
+
TEST_CRC,
|
22
|
+
TEST_COMPRESSIONMETHOD,
|
23
|
+
TEST_SIZE,
|
24
|
+
TEST_TIME)
|
25
|
+
|
26
|
+
assert_equal(TEST_COMMENT, entry.comment)
|
27
|
+
assert_equal(TEST_COMPRESSED_SIZE, entry.compressed_size)
|
28
|
+
assert_equal(TEST_CRC, entry.crc)
|
29
|
+
assert_instance_of(::Zip::ExtraField, entry.extra)
|
30
|
+
assert_equal(TEST_COMPRESSIONMETHOD, entry.compression_method)
|
31
|
+
assert_equal(TEST_NAME, entry.name)
|
32
|
+
assert_equal(TEST_SIZE, entry.size)
|
33
|
+
assert_equal(TEST_TIME, entry.time)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_is_directoryAndIsFile
|
37
|
+
assert(::Zip::Entry.new(TEST_ZIPFILE, "hello").file?)
|
38
|
+
assert(!::Zip::Entry.new(TEST_ZIPFILE, "hello").directory?)
|
39
|
+
|
40
|
+
assert(::Zip::Entry.new(TEST_ZIPFILE, "dir/hello").file?)
|
41
|
+
assert(!::Zip::Entry.new(TEST_ZIPFILE, "dir/hello").directory?)
|
42
|
+
|
43
|
+
assert(::Zip::Entry.new(TEST_ZIPFILE, "hello/").directory?)
|
44
|
+
assert(!::Zip::Entry.new(TEST_ZIPFILE, "hello/").file?)
|
45
|
+
|
46
|
+
assert(::Zip::Entry.new(TEST_ZIPFILE, "dir/hello/").directory?)
|
47
|
+
assert(!::Zip::Entry.new(TEST_ZIPFILE, "dir/hello/").file?)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_equality
|
51
|
+
entry1 = ::Zip::Entry.new("file.zip", "name", "isNotCompared",
|
52
|
+
"something extra", 123, 1234,
|
53
|
+
::Zip::Entry::DEFLATED, 10000)
|
54
|
+
entry2 = ::Zip::Entry.new("file.zip", "name", "isNotComparedXXX",
|
55
|
+
"something extra", 123, 1234,
|
56
|
+
::Zip::Entry::DEFLATED, 10000)
|
57
|
+
entry3 = ::Zip::Entry.new("file.zip", "name2", "isNotComparedXXX",
|
58
|
+
"something extra", 123, 1234,
|
59
|
+
::Zip::Entry::DEFLATED, 10000)
|
60
|
+
entry4 = ::Zip::Entry.new("file.zip", "name2", "isNotComparedXXX",
|
61
|
+
"something extraXX", 123, 1234,
|
62
|
+
::Zip::Entry::DEFLATED, 10000)
|
63
|
+
entry5 = ::Zip::Entry.new("file.zip", "name2", "isNotComparedXXX",
|
64
|
+
"something extraXX", 12, 1234,
|
65
|
+
::Zip::Entry::DEFLATED, 10000)
|
66
|
+
entry6 = ::Zip::Entry.new("file.zip", "name2", "isNotComparedXXX",
|
67
|
+
"something extraXX", 12, 123,
|
68
|
+
::Zip::Entry::DEFLATED, 10000)
|
69
|
+
entry7 = ::Zip::Entry.new("file.zip", "name2", "isNotComparedXXX",
|
70
|
+
"something extraXX", 12, 123,
|
71
|
+
::Zip::Entry::STORED, 10000)
|
72
|
+
entry8 = ::Zip::Entry.new("file.zip", "name2", "isNotComparedXXX",
|
73
|
+
"something extraXX", 12, 123,
|
74
|
+
::Zip::Entry::STORED, 100000)
|
75
|
+
|
76
|
+
assert_equal(entry1, entry1)
|
77
|
+
assert_equal(entry1, entry2)
|
78
|
+
|
79
|
+
assert(entry2 != entry3)
|
80
|
+
assert(entry3 != entry4)
|
81
|
+
assert(entry4 != entry5)
|
82
|
+
assert(entry5 != entry6)
|
83
|
+
assert(entry6 != entry7)
|
84
|
+
assert(entry7 != entry8)
|
85
|
+
|
86
|
+
assert(entry7 != "hello")
|
87
|
+
assert(entry7 != 12)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_compare
|
91
|
+
assert_equal(0, (::Zip::Entry.new("zf.zip", "a") <=> ::Zip::Entry.new("zf.zip", "a")))
|
92
|
+
assert_equal(1, (::Zip::Entry.new("zf.zip", "b") <=> ::Zip::Entry.new("zf.zip", "a")))
|
93
|
+
assert_equal(-1, (::Zip::Entry.new("zf.zip", "a") <=> ::Zip::Entry.new("zf.zip", "b")))
|
94
|
+
|
95
|
+
entries = [
|
96
|
+
::Zip::Entry.new("zf.zip", "5"),
|
97
|
+
::Zip::Entry.new("zf.zip", "1"),
|
98
|
+
::Zip::Entry.new("zf.zip", "3"),
|
99
|
+
::Zip::Entry.new("zf.zip", "4"),
|
100
|
+
::Zip::Entry.new("zf.zip", "0"),
|
101
|
+
::Zip::Entry.new("zf.zip", "2")
|
102
|
+
]
|
103
|
+
|
104
|
+
entries.sort!
|
105
|
+
assert_equal("0", entries[0].to_s)
|
106
|
+
assert_equal("1", entries[1].to_s)
|
107
|
+
assert_equal("2", entries[2].to_s)
|
108
|
+
assert_equal("3", entries[3].to_s)
|
109
|
+
assert_equal("4", entries[4].to_s)
|
110
|
+
assert_equal("5", entries[5].to_s)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_parentAsString
|
114
|
+
entry1 = ::Zip::Entry.new("zf.zip", "aa")
|
115
|
+
entry2 = ::Zip::Entry.new("zf.zip", "aa/")
|
116
|
+
entry3 = ::Zip::Entry.new("zf.zip", "aa/bb")
|
117
|
+
entry4 = ::Zip::Entry.new("zf.zip", "aa/bb/")
|
118
|
+
entry5 = ::Zip::Entry.new("zf.zip", "aa/bb/cc")
|
119
|
+
entry6 = ::Zip::Entry.new("zf.zip", "aa/bb/cc/")
|
120
|
+
|
121
|
+
assert_equal(nil, entry1.parent_as_string)
|
122
|
+
assert_equal(nil, entry2.parent_as_string)
|
123
|
+
assert_equal("aa/", entry3.parent_as_string)
|
124
|
+
assert_equal("aa/", entry4.parent_as_string)
|
125
|
+
assert_equal("aa/bb/", entry5.parent_as_string)
|
126
|
+
assert_equal("aa/bb/", entry6.parent_as_string)
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_entry_name_cannot_start_with_slash
|
130
|
+
assert_raises(::Zip::EntryNameError) { ::Zip::Entry.new("zf.zip", "/hej/der") }
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_store_file_without_compression
|
134
|
+
File.delete('/tmp/no_compress.zip') if File.exists?('/tmp/no_compress.zip')
|
135
|
+
files = Dir[File.join('test/data/globTest', '**', '**')]
|
136
|
+
|
137
|
+
Zip.setup do |z|
|
138
|
+
z.write_zip64_support = false
|
139
|
+
end
|
140
|
+
|
141
|
+
zipfile = Zip::File.open('/tmp/no_compress.zip', Zip::File::CREATE)
|
142
|
+
mimetype_entry = Zip::Entry.new(zipfile, #@zipfile
|
143
|
+
'mimetype', #@name
|
144
|
+
'', #@comment
|
145
|
+
'', #@extra
|
146
|
+
0, #@compressed_size
|
147
|
+
0, #@crc
|
148
|
+
Zip::Entry::STORED) #@comppressed_method
|
149
|
+
|
150
|
+
zipfile.add(mimetype_entry, 'test/data/mimetype')
|
151
|
+
|
152
|
+
files.each do |file|
|
153
|
+
zipfile.add(file.sub("test/data/globTest/", ''), file)
|
154
|
+
end
|
155
|
+
zipfile.close
|
156
|
+
|
157
|
+
f= File.open('/tmp/no_compress.zip', 'rb')
|
158
|
+
first_100_bytes = f.read(100)
|
159
|
+
f.close
|
160
|
+
|
161
|
+
assert_match(/mimetypeapplication\/epub\+zip/, first_100_bytes)
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
end
|
data/test/errors_test.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class ErrorsTest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def test_rescue_legacy_zip_error
|
7
|
+
raise ::Zip::Error
|
8
|
+
rescue ::Zip::ZipError
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_rescue_legacy_zip_entry_exists_error
|
12
|
+
raise ::Zip::EntryExistsError
|
13
|
+
rescue ::Zip::ZipEntryExistsError
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_rescue_legacy_zip_destination_file_exists_error
|
17
|
+
raise ::Zip::DestinationFileExistsError
|
18
|
+
rescue ::Zip::ZipDestinationFileExistsError
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_rescue_legacy_zip_compression_method_error
|
22
|
+
raise ::Zip::CompressionMethodError
|
23
|
+
rescue ::Zip::ZipCompressionMethodError
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_rescue_legacy_zip_entry_name_error
|
27
|
+
raise ::Zip::EntryNameError
|
28
|
+
rescue ::Zip::ZipEntryNameError
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_rescue_legacy_zip_internal_error
|
32
|
+
raise ::Zip::InternalError
|
33
|
+
rescue ::Zip::ZipInternalError
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ZipExtraFieldTest < MiniTest::Unit::TestCase
|
4
|
+
def test_new
|
5
|
+
extra_pure = ::Zip::ExtraField.new("")
|
6
|
+
extra_withstr = ::Zip::ExtraField.new("foo")
|
7
|
+
assert_instance_of(::Zip::ExtraField, extra_pure)
|
8
|
+
assert_instance_of(::Zip::ExtraField, extra_withstr)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_unknownfield
|
12
|
+
extra = ::Zip::ExtraField.new("foo")
|
13
|
+
assert_equal(extra["Unknown"], "foo")
|
14
|
+
extra.merge("a")
|
15
|
+
assert_equal(extra["Unknown"], "fooa")
|
16
|
+
extra.merge("barbaz")
|
17
|
+
assert_equal(extra.to_s, "fooabarbaz")
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def test_merge
|
22
|
+
str = "UT\x5\0\x3\250$\r@Ux\0\0"
|
23
|
+
extra1 = ::Zip::ExtraField.new("")
|
24
|
+
extra2 = ::Zip::ExtraField.new(str)
|
25
|
+
assert(!extra1.member?("UniversalTime"))
|
26
|
+
assert(extra2.member?("UniversalTime"))
|
27
|
+
extra1.merge(str)
|
28
|
+
assert_equal(extra1["UniversalTime"].mtime, extra2["UniversalTime"].mtime)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_length
|
32
|
+
str = "UT\x5\0\x3\250$\r@Ux\0\0Te\0\0testit"
|
33
|
+
extra = ::Zip::ExtraField.new(str)
|
34
|
+
assert_equal(extra.local_size, extra.to_local_bin.size)
|
35
|
+
assert_equal(extra.c_dir_size, extra.to_c_dir_bin.size)
|
36
|
+
extra.merge("foo")
|
37
|
+
assert_equal(extra.local_size, extra.to_local_bin.size)
|
38
|
+
assert_equal(extra.c_dir_size, extra.to_c_dir_bin.size)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def test_to_s
|
43
|
+
str = "UT\x5\0\x3\250$\r@Ux\0\0Te\0\0testit"
|
44
|
+
extra = ::Zip::ExtraField.new(str)
|
45
|
+
assert_instance_of(String, extra.to_s)
|
46
|
+
|
47
|
+
s = extra.to_s
|
48
|
+
extra.merge("foo")
|
49
|
+
assert_equal(s.length + 3, extra.to_s.length)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_equality
|
53
|
+
str = "UT\x5\0\x3\250$\r@"
|
54
|
+
extra1 = ::Zip::ExtraField.new(str)
|
55
|
+
extra2 = ::Zip::ExtraField.new(str)
|
56
|
+
extra3 = ::Zip::ExtraField.new(str)
|
57
|
+
assert_equal(extra1, extra2)
|
58
|
+
|
59
|
+
extra2["UniversalTime"].mtime = ::Zip::DOSTime.now
|
60
|
+
assert(extra1 != extra2)
|
61
|
+
|
62
|
+
extra3.create("IUnix")
|
63
|
+
assert(extra1 != extra3)
|
64
|
+
|
65
|
+
extra1.create("IUnix")
|
66
|
+
assert_equal(extra1, extra3)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|