Class: ZipLocalEntryTest
- Inherits:
-
MiniTest::Test
- Object
- MiniTest::Test
- ZipLocalEntryTest
- Defined in:
- lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb
Constant Summary collapse
- CEH_FILE =
'test/data/generated/centralEntryHeader.bin'- LEH_FILE =
'test/data/generated/localEntryHeader.bin'
Instance Method Summary collapse
- #teardown ⇒ Object
- #test_read64LocalOffset ⇒ Object
- #test_read_local_entryFromNonZipFile ⇒ Object
- #test_read_local_entryFromTruncatedZipFile ⇒ Object
- #test_read_local_entryHeaderOfFirstTestZipEntry ⇒ Object
- #test_readDateTime ⇒ Object
- #test_readLocalOffset ⇒ Object
- #test_rewriteLocalHeader64 ⇒ Object
- #test_write64Entry ⇒ Object
- #test_writeEntry ⇒ Object
- #test_writeEntryWithZip64 ⇒ Object
Instance Method Details
#teardown ⇒ Object
8 9 10 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb', line 8 def teardown ::Zip.write_zip64_support = false end |
#test_read64LocalOffset ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb', line 118 def test_read64LocalOffset ::Zip.write_zip64_support = true entry = ::Zip::Entry.new("file.zip", "entryName") entry.local_header_offset = 0x0123456789ABCDEF ::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) } read_entry = nil ::File.open(CEH_FILE, 'rb') { |f| read_entry = ::Zip::Entry.read_c_dir_entry(f) } compare_c_dir_entry_headers(entry, read_entry) end |
#test_read_local_entryFromNonZipFile ⇒ Object
39 40 41 42 43 44 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb', line 39 def test_read_local_entryFromNonZipFile ::File.open("test/data/file2.txt") { |file| assert_equal(nil, ::Zip::Entry.read_local_entry(file)) } end |
#test_read_local_entryFromTruncatedZipFile ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb', line 46 def test_read_local_entryFromTruncatedZipFile zipFragment="" ::File.open(TestZipFile::TEST_ZIP2.zip_name) { |f| zipFragment = f.read(12) } # local header is at least 30 bytes zipFragment.extend(IOizeString).reset entry = ::Zip::Entry.new entry.read_local_entry(zipFragment) fail "ZipError expected" rescue ::Zip::Error end |
#test_read_local_entryHeaderOfFirstTestZipEntry ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb', line 12 def test_read_local_entryHeaderOfFirstTestZipEntry ::File.open(TestZipFile::TEST_ZIP3.zip_name, "rb") do |file| entry = ::Zip::Entry.read_local_entry(file) assert_equal('', entry.comment) # Differs from windows and unix because of CR LF # assert_equal(480, entry.compressed_size) # assert_equal(0x2a27930f, entry.crc) # extra field is 21 bytes long # probably contains some unix attrutes or something # disabled: assert_equal(nil, entry.extra) assert_equal(::Zip::Entry::DEFLATED, entry.compression_method) assert_equal(TestZipFile::TEST_ZIP3.entry_names[0], entry.name) assert_equal(::File.size(TestZipFile::TEST_ZIP3.entry_names[0]), entry.size) assert(!entry.directory?) end end |
#test_readDateTime ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb', line 30 def test_readDateTime ::File.open("test/data/rubycode.zip", "rb") { |file| entry = ::Zip::Entry.read_local_entry(file) assert_equal("zippedruby1.rb", entry.name) assert_equal(::Zip::DOSTime.at(1019261638), entry.time) } end |
#test_readLocalOffset ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb', line 109 def test_readLocalOffset entry = ::Zip::Entry.new("file.zip", "entryName") entry.local_header_offset = 12345 ::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) } read_entry = nil ::File.open(CEH_FILE, 'rb') { |f| read_entry = ::Zip::Entry.read_c_dir_entry(f) } compare_c_dir_entry_headers(entry, read_entry) end |
#test_rewriteLocalHeader64 ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb', line 93 def test_rewriteLocalHeader64 ::Zip.write_zip64_support = true buf1 = StringIO.new entry = ::Zip::Entry.new("file.zip", "entryName") entry.write_local_entry(buf1) assert(entry.extra['Zip64'].nil?, "zip64 extra is unnecessarily present") buf2 = StringIO.new entry.size = 0x123456789ABCDEF0 entry.compressed_size = 0x0123456789ABCDEF entry.write_local_entry(buf2, true) refute_nil(entry.extra['Zip64']) refute_equal(buf1.size, 0) assert_equal(buf1.size, buf2.size) # it can't grow, or we'd clobber file data end |
#test_write64Entry ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb', line 81 def test_write64Entry ::Zip.write_zip64_support = true entry = ::Zip::Entry.new("bigfile.zip", "entryName", "my little equine", "malformed extra field because why not", 0x7766554433221100, 0xDEADBEEF, ::Zip::Entry::DEFLATED, 0x9988776655443322) write_to_file(LEH_FILE, CEH_FILE, entry) entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE) compare_local_entry_headers(entry, entryReadLocal) compare_c_dir_entry_headers(entry, entryReadCentral) end |
#test_writeEntry ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb', line 56 def test_writeEntry entry = ::Zip::Entry.new("file.zip", "entryName", "my little comment", "thisIsSomeExtraInformation", 100, 987654, ::Zip::Entry::DEFLATED, 400) write_to_file(LEH_FILE, CEH_FILE, entry) entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE) assert(entryReadCentral.extra['Zip64Placeholder'].nil?, 'zip64 placeholder should not be used in central directory') compare_local_entry_headers(entry, entryReadLocal) compare_c_dir_entry_headers(entry, entryReadCentral) end |
#test_writeEntryWithZip64 ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb', line 67 def test_writeEntryWithZip64 ::Zip.write_zip64_support = true entry = ::Zip::Entry.new("file.zip", "entryName", "my little comment", "thisIsSomeExtraInformation", 100, 987654, ::Zip::Entry::DEFLATED, 400) write_to_file(LEH_FILE, CEH_FILE, entry) entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE) assert(entryReadLocal.extra['Zip64Placeholder'], 'zip64 placeholder should be used in local file header') entryReadLocal.extra.delete('Zip64Placeholder') # it was removed when writing the c_dir_entry, so remove from compare assert(entryReadCentral.extra['Zip64Placeholder'].nil?, 'zip64 placeholder should not be used in central directory') compare_local_entry_headers(entry, entryReadLocal) compare_c_dir_entry_headers(entry, entryReadCentral) end |