class CheckZip

Public Instance Methods

test_all() click to toggle source
# File vendor/qwik/lib/qwik/act-archive.rb, line 337
    def test_all
      return if $0 != __FILE__          # Only for separated test.

      file = 'test.zip'
      time = Time.now - (60*60*24) # yesterday
      Zip::ZipOutputStream.open(file) {|zos|
        zos.put_next_entry('test/test.txt')
        zos.print('test')

#     Signature of Zip::ZipEntry.new()
#       new(zipfile = "", name = "", comment = "", extra = "",
#           compressed_size = 0, crc = 0,
#           compression_method = ZipEntry::DEFLATED, size = 0,
#           time = Time.now)

        e = Zip::ZipEntry.new('', 'test2.txt', '', '',
                              0, 0, 
                              Zip::ZipEntry::DEFLATED, 0, time)
        zos.put_next_entry(e)
        zos.print('test2')
      }

      zip = file.path.open {|f| f.read }
      assert_match(/\APK/, zip)
      assert_match(/test.txt/, zip)

      Zip::ZipInputStream.open(file) {|zis|
        e = zis.get_next_entry
        ok_eq('test/test.txt', e.name)
        ok_eq('test', zis.read)

        e = zis.get_next_entry
        ok_eq('test2.txt', e.name)
        ok_eq('test2', zis.read)

        # at parse_binary_dos_format() in zip/stdrubyext.rb,
        # 'second' should not be odd value
        # 86:     second = 2 * (       0b11111 & binaryDosTime)
        time_i = time.to_i / 2 * 2
        e_time_i = e.time.to_i / 2 * 2
        ok_eq(time_i, e_time_i)

        e = zis.get_next_entry
        ok_eq(nil, e)
      }

      file.path.unlink
    end