Class: ZipCentralDirectoryEntryTest

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

Instance Method Summary collapse

Instance Method Details

#test_read_from_streamObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/central_directory_entry_test.rb', line 5

def test_read_from_stream
  File.open("test/data/testDirectory.bin", "rb") {
      |file|
    entry = ::Zip::Entry.read_c_dir_entry(file)

    assert_equal("longAscii.txt", entry.name)
    assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
    assert_equal(106490, entry.size)
    assert_equal(3784, entry.compressed_size)
    assert_equal(0xfcd1799c, entry.crc)
    assert_equal("", entry.comment)

    entry = ::Zip::Entry.read_c_dir_entry(file)
    assert_equal("empty.txt", entry.name)
    assert_equal(::Zip::Entry::STORED, entry.compression_method)
    assert_equal(0, entry.size)
    assert_equal(0, entry.compressed_size)
    assert_equal(0x0, entry.crc)
    assert_equal("", entry.comment)

    entry = ::Zip::Entry.read_c_dir_entry(file)
    assert_equal("short.txt", entry.name)
    assert_equal(::Zip::Entry::STORED, entry.compression_method)
    assert_equal(6, entry.size)
    assert_equal(6, entry.compressed_size)
    assert_equal(0xbb76fe69, entry.crc)
    assert_equal("", entry.comment)

    entry = ::Zip::Entry.read_c_dir_entry(file)
    assert_equal("longBinary.bin", entry.name)
    assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
    assert_equal(1000024, entry.size)
    assert_equal(70847, entry.compressed_size)
    assert_equal(0x10da7d59, entry.crc)
    assert_equal('', entry.comment)

    entry = ::Zip::Entry.read_c_dir_entry(file)
    assert_equal(nil, entry)
# Fields that are not check by this test:
#          version made by                 2 bytes
#          version needed to extract       2 bytes
#          general purpose bit flag        2 bytes
#          last mod file time              2 bytes
#          last mod file date              2 bytes
#          compressed size                 4 bytes
#          uncompressed size               4 bytes
#          disk number start               2 bytes
#          internal file attributes        2 bytes
#          external file attributes        4 bytes
#          relative offset of local header 4 bytes

#          file name (variable size)
#          extra field (variable size)
#          file comment (variable size)

  }
end

#test_ReadEntryFromTruncatedZipFileObject



63
64
65
66
67
68
69
70
71
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/central_directory_entry_test.rb', line 63

def test_ReadEntryFromTruncatedZipFile
  fragment=""
  File.open("test/data/testDirectory.bin") { |f| fragment = f.read(12) } # cdir entry header is at least 46 bytes
  fragment.extend(IOizeString)
  entry = ::Zip::Entry.new
  entry.read_c_dir_entry(fragment)
  fail "ZipError expected"
rescue ::Zip::Error
end