Skip to content
Browse files

Revert "Started converting to RSpec"

This reverts commit c36359d.
  • Loading branch information...
1 parent c36359d commit 8f64fe10351e8e2d3a9dce357c8a20e83d197a9b @aussiegeek aussiegeek committed Jan 7, 2011
View
8 Rakefile
@@ -11,11 +11,3 @@ Rake::TestTask.new(:test) do |test|
Dir.chdir File.join(File.dirname(__FILE__), 'test')
end
-require 'rspec/core'
-require 'rspec/core/rake_task'
-RSpec::Core::RakeTask.new(:spec) do |spec|
- spec.verbose = true
- spec.pattern = FileList['spec/**/*_spec.rb']
-end
-
-task :default => :spec
View
13 lib/zip/compressor.rb
@@ -1,4 +1,17 @@
module Zip
+
+ VERSION = '0.9.4'
+
+ RUBY_MINOR_VERSION = RUBY_VERSION.split(".")[1].to_i
+
+ RUNNING_ON_WINDOWS = Config::CONFIG['host_os'] =~ /^win|mswin/i
+
+ # Ruby 1.7.x compatibility
+ # In ruby 1.6.x and 1.8.0 reading from an empty stream returns
+ # an empty string the first time and then nil.
+ # not so in 1.7.x
+ EMPTY_FILE_RETURNS_EMPTY_STRING_FIRST = RUBY_MINOR_VERSION != 7
+
class Compressor #:nodoc:all
def finish
end
View
7 rubyzip.gemspec
@@ -9,11 +9,6 @@ spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.summary = "rubyzip is a ruby module for reading and writing zip files"
s.files = Dir.glob("{samples,lib}/**/*.rb") + %w{ README NEWS TODO Rakefile }
- s.licenses = ["MIT"]
- s.test_files = Dir.glob("spec/**/*.rb")
s.require_path = 'lib'
s.required_ruby_version = '>= 1.8.6'
-
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
- s.add_development_dependency(%q<rspec>, ["~> 2.2.0"])
-end
+end
View
BIN spec/centralEntryHeader.bin
Binary file not shown.
View
46 spec/data/file1.txt
@@ -1,46 +0,0 @@
-
-AUTOMAKE_OPTIONS = gnu
-
-EXTRA_DIST = test.zip
-
-CXXFLAGS= -g
-
-noinst_LIBRARIES = libzipios.a
-
-bin_PROGRAMS = test_zip test_izipfilt test_izipstream
-# test_flist
-
-libzipios_a_SOURCES = backbuffer.h fcol.cpp fcol.h \
- fcol_common.h fcolexceptions.cpp fcolexceptions.h \
- fileentry.cpp fileentry.h flist.cpp \
- flist.h flistentry.cpp flistentry.h \
- flistscanner.h ifiltstreambuf.cpp ifiltstreambuf.h \
- inflatefilt.cpp inflatefilt.h izipfilt.cpp \
- izipfilt.h izipstream.cpp izipstream.h \
- zipfile.cpp zipfile.h ziphead.cpp \
- ziphead.h flistscanner.ll
-
-# test_flist_SOURCES = test_flist.cpp
-
-test_izipfilt_SOURCES = test_izipfilt.cpp
-
-test_izipstream_SOURCES = test_izipstream.cpp
-
-test_zip_SOURCES = test_zip.cpp
-
-# Notice that libzipios.a is not specified as -L. -lzipios
-# If it was, automake would not include it as a dependency.
-
-# test_flist_LDADD = libzipios.a
-
-test_izipfilt_LDADD = libzipios.a -lz
-
-test_zip_LDADD = libzipios.a -lz
-
-test_izipstream_LDADD = libzipios.a -lz
-
-
-
-flistscanner.cc : flistscanner.ll
- $(LEX) -+ -PFListScanner -o$@ $^
-
View
BIN spec/data/file1.txt.deflatedData
Binary file not shown.
View
1,504 spec/data/file2.txt
@@ -1,1504 +0,0 @@
-#!/usr/bin/env ruby
-
-$VERBOSE = true
-
-require 'rubyunit'
-require 'zip'
-
-include Zip
-
-Dir.chdir "test"
-
-class AbstractInputStreamTest < RUNIT::TestCase
- # AbstractInputStream subclass that provides a read method
-
- TEST_LINES = [ "Hello world#{$/}",
- "this is the second line#{$/}",
- "this is the last line"]
- TEST_STRING = TEST_LINES.join
- class TestAbstractInputStream
- include AbstractInputStream
- def initialize(aString)
- @contents = aString
- @readPointer = 0
- end
-
- def read(charsToRead)
- retVal=@contents[@readPointer, charsToRead]
- @readPointer+=charsToRead
- return retVal
- end
-
- def produceInput
- read(100)
- end
-
- def inputFinished?
- @contents[@readPointer] == nil
- end
- end
-
- def setup
- @io = TestAbstractInputStream.new(TEST_STRING)
- end
-
- def test_gets
- assert_equals(TEST_LINES[0], @io.gets)
- assert_equals(TEST_LINES[1], @io.gets)
- assert_equals(TEST_LINES[2], @io.gets)
- assert_equals(nil, @io.gets)
- end
-
- def test_getsMultiCharSeperator
- assert_equals("Hell", @io.gets("ll"))
- assert_equals("o world#{$/}this is the second l", @io.gets("d l"))
- end
-
- def test_each_line
- lineNumber=0
- @io.each_line {
- |line|
- assert_equals(TEST_LINES[lineNumber], line)
- lineNumber+=1
- }
- end
-
- def test_readlines
- assert_equals(TEST_LINES, @io.readlines)
- end
-
- def test_readline
- test_gets
- begin
- @io.readline
- fail "EOFError expected"
- rescue EOFError
- end
- end
-end
-
-class ZipEntryTest < RUNIT::TestCase
- TEST_ZIPFILE = "someZipFile.zip"
- TEST_COMMENT = "a comment"
- TEST_COMPRESSED_SIZE = 1234
- TEST_CRC = 325324
- TEST_EXTRA = "Some data here"
- TEST_COMPRESSIONMETHOD = ZipEntry::DEFLATED
- TEST_NAME = "entry name"
- TEST_SIZE = 8432
- TEST_ISDIRECTORY = false
-
- def test_constructorAndGetters
- entry = ZipEntry.new(TEST_ZIPFILE,
- TEST_NAME,
- TEST_COMMENT,
- TEST_EXTRA,
- TEST_COMPRESSED_SIZE,
- TEST_CRC,
- TEST_COMPRESSIONMETHOD,
- TEST_SIZE)
-
- assert_equals(TEST_COMMENT, entry.comment)
- assert_equals(TEST_COMPRESSED_SIZE, entry.compressedSize)
- assert_equals(TEST_CRC, entry.crc)
- assert_equals(TEST_EXTRA, entry.extra)
- assert_equals(TEST_COMPRESSIONMETHOD, entry.compressionMethod)
- assert_equals(TEST_NAME, entry.name)
- assert_equals(TEST_SIZE, entry.size)
- assert_equals(TEST_ISDIRECTORY, entry.isDirectory)
- end
-
- def test_equality
- entry1 = ZipEntry.new("file.zip", "name", "isNotCompared",
- "something extra", 123, 1234,
- ZipEntry::DEFLATED, 10000)
- entry2 = ZipEntry.new("file.zip", "name", "isNotComparedXXX",
- "something extra", 123, 1234,
- ZipEntry::DEFLATED, 10000)
- entry3 = ZipEntry.new("file.zip", "name2", "isNotComparedXXX",
- "something extra", 123, 1234,
- ZipEntry::DEFLATED, 10000)
- entry4 = ZipEntry.new("file.zip", "name2", "isNotComparedXXX",
- "something extraXX", 123, 1234,
- ZipEntry::DEFLATED, 10000)
- entry5 = ZipEntry.new("file.zip", "name2", "isNotComparedXXX",
- "something extraXX", 12, 1234,
- ZipEntry::DEFLATED, 10000)
- entry6 = ZipEntry.new("file.zip", "name2", "isNotComparedXXX",
- "something extraXX", 12, 123,
- ZipEntry::DEFLATED, 10000)
- entry7 = ZipEntry.new("file.zip", "name2", "isNotComparedXXX",
- "something extraXX", 12, 123,
- ZipEntry::STORED, 10000)
- entry8 = ZipEntry.new("file.zip", "name2", "isNotComparedXXX",
- "something extraXX", 12, 123,
- ZipEntry::STORED, 100000)
-
- assert_equals(entry1, entry1)
- assert_equals(entry1, entry2)
-
- assert(entry2 != entry3)
- assert(entry3 != entry4)
- assert(entry4 != entry5)
- assert(entry5 != entry6)
- assert(entry6 != entry7)
- assert(entry7 != entry8)
-
- assert(entry7 != "hello")
- assert(entry7 != 12)
- end
-end
-
-module IOizeString
- attr_reader :tell
-
- def read(count = nil)
- @tell ||= 0
- count = size unless count
- retVal = slice(@tell, count)
- @tell += count
- return retVal
- end
-
- def seek(index, offset)
- @tell ||= 0
- case offset
- when IO::SEEK_END
- newPos = size + index
- when IO::SEEK_SET
- newPos = index
- when IO::SEEK_CUR
- newPos = @tell + index
- else
- raise "Error in test method IOizeString::seek"
- end
- if (newPos < 0 || newPos >= size)
- raise Errno::EINVAL
- else
- @tell=newPos
- end
- end
-
- def reset
- @tell = 0
- end
-end
-
-class ZipLocalEntryTest < RUNIT::TestCase
- def test_readLocalEntryHeaderOfFirstTestZipEntry
- File.open(TestZipFile::TEST_ZIP3.zipName) {
- |file|
- entry = ZipEntry.readLocalEntry(file)
-
- assert_equal("", entry.comment)
- # Differs from windows and unix because of CR LF
- # assert_equal(480, entry.compressedSize)
- # 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(ZipEntry::DEFLATED, entry.compressionMethod)
- assert_equal(TestZipFile::TEST_ZIP3.entryNames[0], entry.name)
- assert_equal(File.size(TestZipFile::TEST_ZIP3.entryNames[0]), entry.size)
- assert(! entry.isDirectory)
- }
- end
-
- def test_readLocalEntryFromNonZipFile
- File.open("ziptest.rb") {
- |file|
- assert_equals(nil, ZipEntry.readLocalEntry(file))
- }
- end
-
- def test_readLocalEntryFromTruncatedZipFile
- zipFragment=""
- File.open(TestZipFile::TEST_ZIP2.zipName) { |f| zipFragment = f.read(12) } # local header is at least 30 bytes
- zipFragment.extend(IOizeString).reset
- entry = ZipEntry.new
- entry.readLocalEntry(zipFragment)
- fail "ZipError expected"
- rescue ZipError
- end
-
- def test_writeEntry
- entry = ZipEntry.new("file.zip", "entryName", "my little comment",
- "thisIsSomeExtraInformation", 100, 987654,
- ZipEntry::DEFLATED, 400)
- writeToFile("localEntryHeader.bin", "centralEntryHeader.bin", entry)
- entryReadLocal, entryReadCentral = readFromFile("localEntryHeader.bin", "centralEntryHeader.bin")
- compareLocalEntryHeaders(entry, entryReadLocal)
- compareCDirEntryHeaders(entry, entryReadCentral)
- end
-
- private
- def compareLocalEntryHeaders(entry1, entry2)
- assert_equals(entry1.compressedSize , entry2.compressedSize)
- assert_equals(entry1.crc , entry2.crc)
- assert_equals(entry1.extra , entry2.extra)
- assert_equals(entry1.compressionMethod, entry2.compressionMethod)
- assert_equals(entry1.name , entry2.name)
- assert_equals(entry1.size , entry2.size)
- assert_equals(entry1.localHeaderOffset, entry2.localHeaderOffset)
- end
-
- def compareCDirEntryHeaders(entry1, entry2)
- compareLocalEntryHeaders(entry1, entry2)
- assert_equals(entry1.comment, entry2.comment)
- end
-
- def writeToFile(localFileName, centralFileName, entry)
- File.open(localFileName, "wb") { |f| entry.writeLocalEntry(f) }
- File.open(centralFileName, "wb") { |f| entry.writeCDirEntry(f) }
- end
-
- def readFromFile(localFileName, centralFileName)
- localEntry = nil
- cdirEntry = nil
- File.open(localFileName, "rb") { |f| localEntry = ZipEntry.readLocalEntry(f) }
- File.open(centralFileName, "rb") { |f| cdirEntry = ZipEntry.readCDirEntry(f) }
- return [localEntry, cdirEntry]
- end
-end
-
-
-module DecompressorTests
- # expects @refText and @decompressor
-
- def test_readEverything
- assert_equals(@refText, @decompressor.read)
- end
-
- def test_readInChunks
- chunkSize = 5
- while (decompressedChunk = @decompressor.read(chunkSize))
- assert_equals(@refText.slice!(0, chunkSize), decompressedChunk)
- end
- assert_equals(0, @refText.size)
- end
-end
-
-class InflaterTest < RUNIT::TestCase
- include DecompressorTests
-
- def setup
- @file = File.new("file1.txt.deflatedData", "rb")
- @refText=""
- File.open("file1.txt") { |f| @refText = f.read }
- @decompressor = Inflater.new(@file)
- end
-
- def teardown
- @file.close
- end
-end
-
-
-class PassThruDecompressorTest < RUNIT::TestCase
- include DecompressorTests
- TEST_FILE="file1.txt"
- def setup
- @file = File.new(TEST_FILE)
- @refText=""
- File.open(TEST_FILE) { |f| @refText = f.read }
- @decompressor = PassThruDecompressor.new(@file, File.size(TEST_FILE))
- end
-
- def teardown
- @file.close
- end
-end
-
-
-module AssertEntry
- def assertNextEntry(filename, zis)
- assertEntry(filename, zis, zis.getNextEntry.name)
- end
-
- def assertEntry(filename, zis, entryName)
- assert_equals(filename, entryName)
- assertEntryContentsForStream(filename, zis, entryName)
- end
-
- def assertEntryContentsForStream(filename, zis, entryName)
- File.open(filename, "rb") {
- |file|
- expected = file.read
- actual = zis.read
- if (expected != actual)
- if (expected.length > 400 || actual.length > 400)
- zipEntryFilename=entryName+".zipEntry"
- File.open(zipEntryFilename, "wb") { |file| file << actual }
- fail("File '#{filename}' is different from '#{zipEntryFilename}'")
- else
- assert_equals(expected, actual)
- end
- end
- }
- end
-
- def AssertEntry.assertContents(filename, aString)
- fileContents = ""
- File.open(filename, "rb") { |f| fileContents = f.read }
- if (fileContents != aString)
- if (expected.length > 400 || actual.length > 400)
- stringFile = filename + ".other"
- File.open(stringFile, "wb") { |f| f << aString }
- fail("File '#{filename}' is different from contents of string stored in '#{stringFile}'")
- else
- assert_equals(expected, actual)
- end
- end
- end
-
- def assertStreamContents(zis, testZipFile)
- assert(zis != nil)
- testZipFile.entryNames.each {
- |entryName|
- assertNextEntry(entryName, zis)
- }
- assert_equals(nil, zis.getNextEntry)
- end
-
- def assertTestZipContents(testZipFile)
- ZipInputStream.open(testZipFile.zipName) {
- |zis|
- assertStreamContents(zis, testZipFile)
- }
- end
-
- def assertEntryContents(zipFile, entryName, filename = entryName.to_s)
- zis = zipFile.getInputStream(entryName)
- assertEntryContentsForStream(filename, zis, entryName)
- ensure
- zis.close if zis
- end
-end
-
-
-
-class ZipInputStreamTest < RUNIT::TestCase
- include AssertEntry
-
- def test_new
- zis = ZipInputStream.new(TestZipFile::TEST_ZIP2.zipName)
- assertStreamContents(zis, TestZipFile::TEST_ZIP2)
- zis.close
- end
-
- def test_openWithBlock
- ZipInputStream.open(TestZipFile::TEST_ZIP2.zipName) {
- |zis|
- assertStreamContents(zis, TestZipFile::TEST_ZIP2)
- }
- end
-
- def test_openWithoutBlock
- zis = ZipInputStream.open(TestZipFile::TEST_ZIP2.zipName)
- assertStreamContents(zis, TestZipFile::TEST_ZIP2)
- end
-
- def test_incompleteReads
- ZipInputStream.open(TestZipFile::TEST_ZIP2.zipName) {
- |zis|
- entry = zis.getNextEntry
- assert_equals(TestZipFile::TEST_ZIP2.entryNames[0], entry.name)
- assert zis.gets.length > 0
- entry = zis.getNextEntry
- assert_equals(TestZipFile::TEST_ZIP2.entryNames[1], entry.name)
- assert_equals(0, entry.size)
- assert_equals(nil, zis.gets)
- entry = zis.getNextEntry
- assert_equals(TestZipFile::TEST_ZIP2.entryNames[2], entry.name)
- assert zis.gets.length > 0
- entry = zis.getNextEntry
- assert_equals(TestZipFile::TEST_ZIP2.entryNames[3], entry.name)
- assert zis.gets.length > 0
- }
- end
-
-end
-
-class TestFiles
- RANDOM_ASCII_FILE1 = "randomAscii1.txt"
- RANDOM_ASCII_FILE2 = "randomAscii2.txt"
- RANDOM_ASCII_FILE3 = "randomAscii3.txt"
- RANDOM_BINARY_FILE1 = "randomBinary1.bin"
- RANDOM_BINARY_FILE2 = "randomBinary2.bin"
-
- EMPTY_TEST_DIR = "emptytestdir"
-
- ASCII_TEST_FILES = [ RANDOM_ASCII_FILE1, RANDOM_ASCII_FILE2, RANDOM_ASCII_FILE3 ]
- BINARY_TEST_FILES = [ RANDOM_BINARY_FILE1, RANDOM_BINARY_FILE2 ]
- TEST_DIRECTORIES = [ EMPTY_TEST_DIR ]
- TEST_FILES = [ ASCII_TEST_FILES, BINARY_TEST_FILES, EMPTY_TEST_DIR ].flatten!
-
- def TestFiles.createTestFiles(recreate)
- if (recreate ||
- ! (TEST_FILES.inject(true) { |accum, element| accum && File.exists?(element) }))
-
- ASCII_TEST_FILES.each_with_index {
- |filename, index|
- createRandomAscii(filename, 1E4 * (index+1))
- }
-
- BINARY_TEST_FILES.each_with_index {
- |filename, index|
- createRandomBinary(filename, 1E4 * (index+1))
- }
-
- ensureDir(EMPTY_TEST_DIR)
- end
- end
-
- private
- def TestFiles.createRandomAscii(filename, size)
- File.open(filename, "wb") {
- |file|
- while (file.tell < size)
- file << rand
- end
- }
- end
-
- def TestFiles.createRandomBinary(filename, size)
- File.open(filename, "wb") {
- |file|
- while (file.tell < size)
- file << rand.to_a.pack("V")
- end
- }
- end
-
- def TestFiles.ensureDir(name)
- if File.exists?(name)
- return if File.stat(name).directory?
- File.delete(name)
- end
- Dir.mkdir(name)
- end
-
-end
-
-# For representation and creation of
-# test data
-class TestZipFile
- attr_accessor :zipName, :entryNames, :comment
-
- def initialize(zipName, entryNames, comment = "")
- @zipName=zipName
- @entryNames=entryNames
- @comment = comment
- end
-
- def TestZipFile.createTestZips(recreate)
- files = Dir.entries(".")
- if (recreate ||
- ! (files.index(TEST_ZIP1.zipName) &&
- files.index(TEST_ZIP2.zipName) &&
- files.index(TEST_ZIP3.zipName) &&
- files.index(TEST_ZIP4.zipName) &&
- files.index("empty.txt") &&
- files.index("short.txt") &&
- files.index("longAscii.txt") &&
- files.index("longBinary.bin") ))
- raise "failed to create test zip '#{TEST_ZIP1.zipName}'" unless
- system("zip #{TEST_ZIP1.zipName} ziptest.rb")
- raise "failed to remove entry from '#{TEST_ZIP1.zipName}'" unless
- system("zip #{TEST_ZIP1.zipName} -d ziptest.rb")
-
- File.open("empty.txt", "w") {}
-
- File.open("short.txt", "w") { |file| file << "ABCDEF" }
- ziptestTxt=""
- File.open("ziptest.rb") { |file| ziptestTxt=file.read }
- File.open("longAscii.txt", "w") {
- |file|
- while (file.tell < 1E5)
- file << ziptestTxt
- end
- }
-
- testBinaryPattern=""
- File.open("empty.zip") { |file| testBinaryPattern=file.read }
- testBinaryPattern *= 4
-
- File.open("longBinary.bin", "wb") {
- |file|
- while (file.tell < 3E5)
- file << testBinaryPattern << rand
- end
- }
- raise "failed to create test zip '#{TEST_ZIP2.zipName}'" unless
- system("zip #{TEST_ZIP2.zipName} #{TEST_ZIP2.entryNames.join(' ')}")
-
- # without bash system interprets everything after echo as parameters to
- # echo including | zip -z ...
- raise "failed to add comment to test zip '#{TEST_ZIP2.zipName}'" unless
- system("bash -c \"echo #{TEST_ZIP2.comment} | zip -z #{TEST_ZIP2.zipName}\"")
-
- raise "failed to create test zip '#{TEST_ZIP3.zipName}'" unless
- system("zip #{TEST_ZIP3.zipName} #{TEST_ZIP3.entryNames.join(' ')}")
-
- raise "failed to create test zip '#{TEST_ZIP4.zipName}'" unless
- system("zip #{TEST_ZIP4.zipName} #{TEST_ZIP4.entryNames.join(' ')}")
- end
- rescue
- raise $!.to_s +
- "\n\nziptest.rb requires the Info-ZIP program 'zip' in the path\n" +
- "to create test data. If you don't have it you can download\n" +
- "the necessary test files at http://sf.net/projects/rubyzip."
- end
-
- TEST_ZIP1 = TestZipFile.new("empty.zip", [])
- TEST_ZIP2 = TestZipFile.new("4entry.zip", %w{ longAscii.txt empty.txt short.txt longBinary.bin},
- "my zip comment")
- TEST_ZIP3 = TestZipFile.new("test1.zip", %w{ file1.txt })
- TEST_ZIP4 = TestZipFile.new("zipWithDir.zip", [ "file1.txt",
- TestFiles::EMPTY_TEST_DIR])
-end
-
-
-class AbstractOutputStreamTest < RUNIT::TestCase
- class TestOutputStream
- include AbstractOutputStream
-
- attr_accessor :buffer
-
- def initialize
- @buffer = ""
- end
-
- def << (data)
- @buffer << data
- self
- end
- end
-
- def setup
- @outputStream = TestOutputStream.new
-
- @origCommaSep = $,
- @origOutputSep = $\
- end
-
- def teardown
- $, = @origCommaSep
- $\ = @origOutputSep
- end
-
- def test_write
- count = @outputStream.write("a little string")
- assert_equals("a little string", @outputStream.buffer)
- assert_equals("a little string".length, count)
-
- count = @outputStream.write(". a little more")
- assert_equals("a little string. a little more", @outputStream.buffer)
- assert_equals(". a little more".length, count)
- end
-
- def test_print
- $\ = nil # record separator set to nil
- @outputStream.print("hello")
- assert_equals("hello", @outputStream.buffer)
-
- @outputStream.print(" world.")
- assert_equals("hello world.", @outputStream.buffer)
-
- @outputStream.print(" You ok ", "out ", "there?")
- assert_equals("hello world. You ok out there?", @outputStream.buffer)
-
- $\ = "\n"
- @outputStream.print
- assert_equals("hello world. You ok out there?\n", @outputStream.buffer)
-
- @outputStream.print("I sure hope so!")
- assert_equals("hello world. You ok out there?\nI sure hope so!\n", @outputStream.buffer)
-
- $, = "X"
- @outputStream.buffer = ""
- @outputStream.print("monkey", "duck", "zebra")
- assert_equals("monkeyXduckXzebra\n", @outputStream.buffer)
-
- $\ = nil
- @outputStream.buffer = ""
- @outputStream.print(20)
- assert_equals("20", @outputStream.buffer)
- end
-
- def test_printf
- @outputStream.printf("%d %04x", 123, 123)
- assert_equals("123 007b", @outputStream.buffer)
- end
-
- def test_putc
- @outputStream.putc("A")
- assert_equals("A", @outputStream.buffer)
- @outputStream.putc(65)
- assert_equals("AA", @outputStream.buffer)
- end
-
- def test_puts
- @outputStream.puts
- assert_equals("\n", @outputStream.buffer)
-
- @outputStream.puts("hello", "world")
- assert_equals("\nhello\nworld\n", @outputStream.buffer)
-
- @outputStream.buffer = ""
- @outputStream.puts("hello\n", "world\n")
- assert_equals("hello\nworld\n", @outputStream.buffer)
-
- @outputStream.buffer = ""
- @outputStream.puts(["hello\n", "world\n"])
- assert_equals("hello\nworld\n", @outputStream.buffer)
-
- @outputStream.buffer = ""
- @outputStream.puts(["hello\n", "world\n"], "bingo")
- assert_equals("hello\nworld\nbingo\n", @outputStream.buffer)
-
- @outputStream.buffer = ""
- @outputStream.puts(16, 20, 50, "hello")
- assert_equals("16\n20\n50\nhello\n", @outputStream.buffer)
- end
-end
-
-
-module CrcTest
- def runCrcTest(compressorClass)
- str = "Here's a nice little text to compute the crc for! Ho hum, it is nice nice nice nice indeed."
- fakeOut = AbstractOutputStreamTest::TestOutputStream.new
-
- deflater = compressorClass.new(fakeOut)
- deflater << str
- assert_equals(0x919920fc, deflater.crc)
- end
-end
-
-
-
-class PassThruCompressorTest < RUNIT::TestCase
- include CrcTest
-
- def test_size
- File.open("dummy.txt", "wb") {
- |file|
- compressor = PassThruCompressor.new(file)
-
- assert_equals(0, compressor.size)
-
- t1 = "hello world"
- t2 = ""
- t3 = "bingo"
-
- compressor << t1
- assert_equals(compressor.size, t1.size)
-
- compressor << t2
- assert_equals(compressor.size, t1.size + t2.size)
-
- compressor << t3
- assert_equals(compressor.size, t1.size + t2.size + t3.size)
- }
- end
-
- def test_crc
- runCrcTest(PassThruCompressor)
- end
-end
-
-class DeflaterTest < RUNIT::TestCase
- include CrcTest
-
- def test_outputOperator
- txt = loadFile("ziptest.rb")
- deflate(txt, "deflatertest.bin")
- inflatedTxt = inflate("deflatertest.bin")
- assert_equals(txt, inflatedTxt)
- end
-
- private
- def loadFile(fileName)
- txt = nil
- File.open(fileName, "rb") { |f| txt = f.read }
- end
-
- def deflate(data, fileName)
- File.open(fileName, "wb") {
- |file|
- deflater = Deflater.new(file)
- deflater << data
- deflater.finish
- assert_equals(deflater.size, data.size)
- file << "trailing data for zlib with -MAX_WBITS"
- }
- end
-
- def inflate(fileName)
- txt = nil
- File.open(fileName, "rb") {
- |file|
- inflater = Inflater.new(file)
- txt = inflater.read
- }
- end
-
- def test_crc
- runCrcTest(Deflater)
- end
-end
-
-class ZipOutputStreamTest < RUNIT::TestCase
- include AssertEntry
-
- TEST_ZIP = TestZipFile::TEST_ZIP2.clone
- TEST_ZIP.zipName = "output.zip"
-
- def test_new
- zos = ZipOutputStream.new(TEST_ZIP.zipName)
- zos.comment = TEST_ZIP.comment
- writeTestZip(zos)
- zos.close
- assertTestZipContents(TEST_ZIP)
- end
-
- def test_open
- ZipOutputStream.open(TEST_ZIP.zipName) {
- |zos|
- zos.comment = TEST_ZIP.comment
- writeTestZip(zos)
- }
- assertTestZipContents(TEST_ZIP)
- end
-
- def test_writingToClosedStream
- assertIOErrorInClosedStream { |zos| zos << "hello world" }
- assertIOErrorInClosedStream { |zos| zos.puts "hello world" }
- assertIOErrorInClosedStream { |zos| zos.write "hello world" }
- end
-
- def test_cannotOpenFile
- name = TestFiles::EMPTY_TEST_DIR
- begin
- zos = ZipOutputStream.open(name)
- rescue Exception
- assert($!.kind_of?(Errno::EISDIR) || # Linux
- $!.kind_of?(Errno::EEXIST) || # Windows/cygwin
- $!.kind_of?(Errno::EACCES), # Windows
- "Expected Errno::EISDIR (or on win/cygwin: Errno::EEXIST), but was: #{$!.type}")
- end
- end
-
- def assertIOErrorInClosedStream
- assert_exception(IOError) {
- zos = ZipOutputStream.new("test_putOnClosedStream.zip")
- zos.close
- yield zos
- }
- end
-
- def writeTestZip(zos)
- TEST_ZIP.entryNames.each {
- |entryName|
- zos.putNextEntry(entryName)
- File.open(entryName, "rb") { |f| zos.write(f.read) }
- }
- end
-end
-
-
-
-module Enumerable
- def compareEnumerables(otherEnumerable)
- otherAsArray = otherEnumerable.to_a
- index=0
- each_with_index {
- |element, index|
- return false unless yield(element, otherAsArray[index])
- }
- return index+1 == otherAsArray.size
- end
-end
-
-
-class ZipCentralDirectoryEntryTest < RUNIT::TestCase
-
- def test_readFromStream
- File.open("testDirectory.bin", "rb") {
- |file|
- entry = ZipEntry.readCDirEntry(file)
-
- assert_equals("longAscii.txt", entry.name)
- assert_equals(ZipEntry::DEFLATED, entry.compressionMethod)
- assert_equals(106490, entry.size)
- assert_equals(3784, entry.compressedSize)
- assert_equals(0xfcd1799c, entry.crc)
- assert_equals("", entry.comment)
-
- entry = ZipEntry.readCDirEntry(file)
- assert_equals("empty.txt", entry.name)
- assert_equals(ZipEntry::STORED, entry.compressionMethod)
- assert_equals(0, entry.size)
- assert_equals(0, entry.compressedSize)
- assert_equals(0x0, entry.crc)
- assert_equals("", entry.comment)
-
- entry = ZipEntry.readCDirEntry(file)
- assert_equals("short.txt", entry.name)
- assert_equals(ZipEntry::STORED, entry.compressionMethod)
- assert_equals(6, entry.size)
- assert_equals(6, entry.compressedSize)
- assert_equals(0xbb76fe69, entry.crc)
- assert_equals("", entry.comment)
-
- entry = ZipEntry.readCDirEntry(file)
- assert_equals("longBinary.bin", entry.name)
- assert_equals(ZipEntry::DEFLATED, entry.compressionMethod)
- assert_equals(1000024, entry.size)
- assert_equals(70847, entry.compressedSize)
- assert_equals(0x10da7d59, entry.crc)
- assert_equals("", entry.comment)
-
- entry = ZipEntry.readCDirEntry(file)
- assert_equals(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
-
- def test_ReadEntryFromTruncatedZipFile
- fragment=""
- File.open("testDirectory.bin") { |f| fragment = f.read(12) } # cdir entry header is at least 46 bytes
- fragment.extend(IOizeString)
- entry = ZipEntry.new
- entry.readCDirEntry(fragment)
- fail "ZipError expected"
- rescue ZipError
- end
-
-end
-
-class ZipCentralDirectoryTest < RUNIT::TestCase
-
- def test_readFromStream
- File.open(TestZipFile::TEST_ZIP2.zipName, "rb") {
- |zipFile|
- cdir = ZipCentralDirectory.readFromStream(zipFile)
-
- assert_equals(TestZipFile::TEST_ZIP2.entryNames.size, cdir.size)
- assert(cdir.compareEnumerables(TestZipFile::TEST_ZIP2.entryNames) {
- |cdirEntry, testEntryName|
- cdirEntry.name == testEntryName
- })
- assert_equals(TestZipFile::TEST_ZIP2.comment, cdir.comment)
- }
- end
-
- def test_readFromInvalidStream
- File.open("ziptest.rb", "rb") {
- |zipFile|
- cdir = ZipCentralDirectory.new
- cdir.readFromStream(zipFile)
- }
- fail "ZipError expected!"
- rescue ZipError
- end
-
- def test_ReadFromTruncatedZipFile
- fragment=""
- File.open("testDirectory.bin") { |f| fragment = f.read }
- fragment.slice!(12) # removed part of first cdir entry. eocd structure still complete
- fragment.extend(IOizeString)
- entry = ZipCentralDirectory.new
- entry.readFromStream(fragment)
- fail "ZipError expected"
- rescue ZipError
- end
-
- def test_writeToStream
- entries = [ ZipEntry.new("file.zip", "flimse", "myComment", "somethingExtra"),
- ZipEntry.new("file.zip", "secondEntryName"),
- ZipEntry.new("file.zip", "lastEntry.txt", "Has a comment too") ]
- cdir = ZipCentralDirectory.new(entries, "my zip comment")
- File.open("cdirtest.bin", "wb") { |f| cdir.writeToStream(f) }
- cdirReadback = ZipCentralDirectory.new
- File.open("cdirtest.bin", "rb") { |f| cdirReadback.readFromStream(f) }
-
- assert_equals(cdir.entries, cdirReadback.entries)
- end
-
- def test_equality
- cdir1 = ZipCentralDirectory.new([ ZipEntry.new("file.zip", "flimse", nil,
- "somethingExtra"),
- ZipEntry.new("file.zip", "secondEntryName"),
- ZipEntry.new("file.zip", "lastEntry.txt") ],
- "my zip comment")
- cdir2 = ZipCentralDirectory.new([ ZipEntry.new("file.zip", "flimse", nil,
- "somethingExtra"),
- ZipEntry.new("file.zip", "secondEntryName"),
- ZipEntry.new("file.zip", "lastEntry.txt") ],
- "my zip comment")
- cdir3 = ZipCentralDirectory.new([ ZipEntry.new("file.zip", "flimse", nil,
- "somethingExtra"),
- ZipEntry.new("file.zip", "secondEntryName"),
- ZipEntry.new("file.zip", "lastEntry.txt") ],
- "comment?")
- cdir4 = ZipCentralDirectory.new([ ZipEntry.new("file.zip", "flimse", nil,
- "somethingExtra"),
- ZipEntry.new("file.zip", "lastEntry.txt") ],
- "comment?")
- assert_equals(cdir1, cdir1)
- assert_equals(cdir1, cdir2)
-
- assert(cdir1 != cdir3)
- assert(cdir2 != cdir3)
- assert(cdir2 != cdir3)
- assert(cdir3 != cdir4)
-
- assert(cdir3 != "hello")
- end
-end
-
-
-class BasicZipFileTest < RUNIT::TestCase
- include AssertEntry
-
- def setup
- @zipFile = ZipFile.new(TestZipFile::TEST_ZIP2.zipName)
- @testEntryNameIndex=0
- end
-
- def nextTestEntryName
- retVal=TestZipFile::TEST_ZIP2.entryNames[@testEntryNameIndex]
- @testEntryNameIndex+=1
- return retVal
- end
-
- def test_entries
- assert_equals(TestZipFile::TEST_ZIP2.entryNames, @zipFile.entries.map {|e| e.name} )
- end
-
- def test_each
- @zipFile.each {
- |entry|
- assert_equals(nextTestEntryName, entry.name)
- }
- assert_equals(4, @testEntryNameIndex)
- end
-
- def test_foreach
- ZipFile.foreach(TestZipFile::TEST_ZIP2.zipName) {
- |entry|
- assert_equals(nextTestEntryName, entry.name)
- }
- assert_equals(4, @testEntryNameIndex)
- end
-
- def test_getInputStream
- @zipFile.each {
- |entry|
- assertEntry(nextTestEntryName, @zipFile.getInputStream(entry),
- entry.name)
- }
- assert_equals(4, @testEntryNameIndex)
- end
-
- def test_getInputStreamBlock
- fileAndEntryName = @zipFile.entries.first.name
- @zipFile.getInputStream(fileAndEntryName) {
- |zis|
- assertEntryContentsForStream(fileAndEntryName,
- zis,
- fileAndEntryName)
- }
- end
-end
-
-class CommonZipFileFixture < RUNIT::TestCase
- include AssertEntry
-
- EMPTY_FILENAME = "emptyZipFile.zip"
-
- TEST_ZIP = TestZipFile::TEST_ZIP2.clone
- TEST_ZIP.zipName = "4entry_copy.zip"
-
- def setup
- File.delete(EMPTY_FILENAME) if File.exists?(EMPTY_FILENAME)
- File.copy(TestZipFile::TEST_ZIP2.zipName, TEST_ZIP.zipName)
- end
-end
-
-class ZipFileTest < CommonZipFileFixture
-
- def test_createFromScratch
- comment = "a short comment"
-
- zf = ZipFile.new(EMPTY_FILENAME, ZipFile::CREATE)
- zf.comment = comment
- zf.close
-
- zfRead = ZipFile.new(EMPTY_FILENAME)
- assert_equals(comment, zfRead.comment)
- assert_equals(0, zfRead.entries.length)
- end
-
- def test_add
- srcFile = "ziptest.rb"
- entryName = "newEntryName.rb"
- assert(File.exists? srcFile)
- zf = ZipFile.new(EMPTY_FILENAME, ZipFile::CREATE)
- zf.add(entryName, srcFile)
- zf.close
-
- zfRead = ZipFile.new(EMPTY_FILENAME)
- assert_equals("", zfRead.comment)
- assert_equals(1, zfRead.entries.length)
- assert_equals(entryName, zfRead.entries.first.name)
- AssertEntry.assertContents(srcFile,
- zfRead.getInputStream(entryName) { |zis| zis.read })
- end
-
- def test_addExistingEntryName
- assert_exception(ZipEntryExistsError) {
- ZipFile.open(TEST_ZIP.zipName) {
- |zf|
- zf.add(zf.entries.first.name, "ziptest.rb")
- }
- }
- end
-
- def test_addExistingEntryNameReplace
- gotCalled = false
- replacedEntry = nil
- ZipFile.open(TEST_ZIP.zipName) {
- |zf|
- replacedEntry = zf.entries.first.name
- zf.add(replacedEntry, "ziptest.rb") { gotCalled = true; true }
- }
- assert(gotCalled)
- ZipFile.open(TEST_ZIP.zipName) {
- |zf|
- assertContains(zf, replacedEntry, "ziptest.rb")
- }
- end
-
- def test_addDirectory
- ZipFile.open(TEST_ZIP.zipName) {
- |zf|
- zf.add(TestFiles::EMPTY_TEST_DIR, TestFiles::EMPTY_TEST_DIR)
- }
- ZipFile.open(TEST_ZIP.zipName) {
- |zf|
- dirEntry = zf.entries.detect { |e| e.name == TestFiles::EMPTY_TEST_DIR+"/" }
- assert(dirEntry.isDirectory)
- }
- end
-
- def test_remove
- entryToRemove, *remainingEntries = TEST_ZIP.entryNames
-
- File.copy(TestZipFile::TEST_ZIP2.zipName, TEST_ZIP.zipName)
-
- zf = ZipFile.new(TEST_ZIP.zipName)
- assert(zf.entries.map { |e| e.name }.include?(entryToRemove))
- zf.remove(entryToRemove)
- assert(! zf.entries.map { |e| e.name }.include?(entryToRemove))
- assert_equals(zf.entries.map {|x| x.name }.sort, remainingEntries.sort)
- zf.close
-
- zfRead = ZipFile.new(TEST_ZIP.zipName)
- assert(! zfRead.entries.map { |e| e.name }.include?(entryToRemove))
- assert_equals(zfRead.entries.map {|x| x.name }.sort, remainingEntries.sort)
- zfRead.close
- end
-
-
- def test_rename
- entryToRename, *remainingEntries = TEST_ZIP.entryNames
-
- zf = ZipFile.new(TEST_ZIP.zipName)
- assert(zf.entries.map { |e| e.name }.include? entryToRename)
-
- newName = "changed name"
- assert(! zf.entries.map { |e| e.name }.include?(newName))
-
- zf.rename(entryToRename, newName)
- assert(zf.entries.map { |e| e.name }.include? newName)
-
- zf.close
-
- zfRead = ZipFile.new(TEST_ZIP.zipName)
- assert(zfRead.entries.map { |e| e.name }.include? newName)
- zfRead.close
- end
-
- def test_renameToExistingEntry
- oldEntries = nil
- ZipFile.open(TEST_ZIP.zipName) { |zf| oldEntries = zf.entries }
-
- assert_exception(ZipEntryExistsError) {
- ZipFile.open(TEST_ZIP.zipName) {
- |zf|
- zf.rename(zf.entries[0], zf.entries[1].name)
- }
- }
-
- ZipFile.open(TEST_ZIP.zipName) {
- |zf|
- assert_equals(oldEntries.map{ |e| e.name }, zf.entries.map{ |e| e.name })
- }
- end
-
- def test_renameToExistingEntryOverwrite
- oldEntries = nil
- ZipFile.open(TEST_ZIP.zipName) { |zf| oldEntries = zf.entries }
-
- gotCalled = false
- ZipFile.open(TEST_ZIP.zipName) {
- |zf|
- zf.rename(zf.entries[0], zf.entries[1].name) { gotCalled = true; true }
- }
-
- assert(gotCalled)
- oldEntries.delete_at(0)
- ZipFile.open(TEST_ZIP.zipName) {
- |zf|
- assert_equals(oldEntries.map{ |e| e.name },
- zf.entries.map{ |e| e.name })
- }
- end
-
- def test_renameNonEntry
- nonEntry = "bogusEntry"
- targetEntry = "targetEntryName"
- zf = ZipFile.new(TEST_ZIP.zipName)
- assert(! zf.entries.include?(nonEntry))
- assert_exception(ZipNoSuchEntryError) {
- zf.rename(nonEntry, targetEntry)
- }
- zf.commit
- assert(! zf.entries.include?(targetEntry))
- ensure
- zf.close
- end
-
- def test_renameEntryToExistingEntry
- entry1, entry2, *remaining = TEST_ZIP.entryNames
- zf = ZipFile.new(TEST_ZIP.zipName)
- assert_exception(ZipEntryExistsError) {
- zf.rename(entry1, entry2)
- }
- ensure
- zf.close
- end
-
- def test_replace
- unchangedEntries = TEST_ZIP.entryNames.dup
- entryToReplace = unchangedEntries.delete_at(2)
- newEntrySrcFilename = "ziptest.rb"
-
- zf = ZipFile.new(TEST_ZIP.zipName)
- zf.replace(entryToReplace, newEntrySrcFilename)
-
- zf.close
-
- zfRead = ZipFile.new(TEST_ZIP.zipName)
- AssertEntry::assertContents(newEntrySrcFilename,
- zfRead.getInputStream(entryToReplace) { |is| is.read })
- zfRead.close
- end
-
- def test_replaceNonEntry
- entryToReplace = "nonExistingEntryname"
- ZipFile.open(TEST_ZIP.zipName) {
- |zf|
- assert_exception(ZipNoSuchEntryError) {
- zf.replace(entryToReplace, "ziptest.rb")
- }
- }
- end
-
- def test_commit
- newName = "renamedFirst"
- zf = ZipFile.new(TEST_ZIP.zipName)
- oldName = zf.entries.first
- zf.rename(oldName, newName)
- zf.commit
-
- zfRead = ZipFile.new(TEST_ZIP.zipName)
- assert(zfRead.entries.detect { |e| e.name == newName } != nil)
- assert(zfRead.entries.detect { |e| e.name == oldName } == nil)
- zfRead.close
-
- zf.close
- end
-
- # This test tests that after commit, you
- # can delete the file you used to add the entry to the zip file
- # with
- def test_commitUseZipEntry
- File.copy(TestFiles::RANDOM_ASCII_FILE1, "okToDelete.txt")
- zf = ZipFile.open(TEST_ZIP.zipName)
- zf.add("okToDelete.txt", "okToDelete.txt")
- assertContains(zf, "okToDelete.txt")
- zf.commit
- File.move("okToDelete.txt", "okToDeleteMoved.txt")
- assertContains(zf, "okToDelete.txt", "okToDeleteMoved.txt")
- end
-
-# def test_close
-# zf = ZipFile.new(TEST_ZIP.zipName)
-# zf.close
-# assert_exception(IOError) {
-# zf.extract(TEST_ZIP.entryNames.first, "hullubullu")
-# }
-# end
-
- def test_compound1
- renamedName = "renamedName"
- originalEntries = []
- begin
- zf = ZipFile.new(TEST_ZIP.zipName)
- originalEntries = zf.entries.dup
-
- assertNotContains(zf, TestFiles::RANDOM_ASCII_FILE1)
- zf.add(TestFiles::RANDOM_ASCII_FILE1,
- TestFiles::RANDOM_ASCII_FILE1)
- assertContains(zf, TestFiles::RANDOM_ASCII_FILE1)
-
- zf.rename(zf.entries[0], renamedName)
- assertContains(zf, renamedName)
-
- TestFiles::BINARY_TEST_FILES.each {
- |filename|
- zf.add(filename, filename)
- assertContains(zf, filename)
- }
-
- assertContains(zf, originalEntries.last.to_s)
- zf.remove(originalEntries.last.to_s)
- assertNotContains(zf, originalEntries.last.to_s)
-
- ensure
- zf.close
- end
- begin
- zfRead = ZipFile.new(TEST_ZIP.zipName)
- assertContains(zfRead, TestFiles::RANDOM_ASCII_FILE1)
- assertContains(zfRead, renamedName)
- TestFiles::BINARY_TEST_FILES.each {
- |filename|
- assertContains(zfRead, filename)
- }
- assertNotContains(zfRead, originalEntries.last.to_s)
- ensure
- zfRead.close
- end
- end
-
- def test_compound2
- begin
- zf = ZipFile.new(TEST_ZIP.zipName)
- originalEntries = zf.entries.dup
-
- originalEntries.each {
- |entry|
- zf.remove(entry)
- assertNotContains(zf, entry)
- }
- assert(zf.entries.empty?)
-
- TestFiles::ASCII_TEST_FILES.each {
- |filename|
- zf.add(filename, filename)
- assertContains(zf, filename)
- }
- assert_equals(zf.entries.map { |e| e.name }, TestFiles::ASCII_TEST_FILES)
-
- zf.rename(TestFiles::ASCII_TEST_FILES[0], "newName")
- assertNotContains(zf, TestFiles::ASCII_TEST_FILES[0])
- assertContains(zf, "newName")
- ensure
- zf.close
- end
- begin
- zfRead = ZipFile.new(TEST_ZIP.zipName)
- asciiTestFiles = TestFiles::ASCII_TEST_FILES.dup
- asciiTestFiles.shift
- asciiTestFiles.each {
- |filename|
- assertContains(zf, filename)
- }
-
- assertContains(zf, "newName")
- ensure
- zfRead.close
- end
- end
-
- private
- def assertContains(zf, entryName, filename = entryName)
- assert(zf.entries.detect { |e| e.name == entryName} != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}")
- assertEntryContents(zf, entryName, filename) if File.exists?(filename)
- end
-
- def assertNotContains(zf, entryName)
- assert(zf.entries.detect { |e| e.name == entryName} == nil, "entry #{entryName} in #{zf.entries.join(', ')} in zip file #{zf}")
- end
-end
-
-class ZipFileExtractTest < CommonZipFileFixture
- EXTRACTED_FILENAME = "extEntry"
- ENTRY_TO_EXTRACT, *REMAINING_ENTRIES = TEST_ZIP.entryNames.reverse
-
- def setup
- super
- File.delete(EXTRACTED_FILENAME) if File.exists?(EXTRACTED_FILENAME)
- end
-
- def test_extract
- ZipFile.open(TEST_ZIP.zipName) {
- |zf|
- zf.extract(ENTRY_TO_EXTRACT, EXTRACTED_FILENAME)
-
- assert(File.exists? EXTRACTED_FILENAME)
- AssertEntry::assertContents(EXTRACTED_FILENAME,
- zf.getInputStream(ENTRY_TO_EXTRACT) { |is| is.read })
- }
- end
-
- def test_extractExists
- writtenText = "written text"
- File.open(EXTRACTED_FILENAME, "w") { |f| f.write(writtenText) }
-
- assert_exception(ZipDestinationFileExistsError) {
- ZipFile.open(TEST_ZIP.zipName) {
- |zf|
- zf.extract(zf.entries.first, EXTRACTED_FILENAME)
- }
- }
- File.open(EXTRACTED_FILENAME, "r") {
- |f|
- assert_equals(writtenText, f.read)
- }
- end
-
- def test_extractExistsOverwrite
- writtenText = "written text"
- File.open(EXTRACTED_FILENAME, "w") { |f| f.write(writtenText) }
-
- gotCalled = false
- ZipFile.open(TEST_ZIP.zipName) {
- |zf|
- zf.extract(zf.entries.first, EXTRACTED_FILENAME) { gotCalled = true; true }
- }
-
- assert(gotCalled)
- File.open(EXTRACTED_FILENAME, "r") {
- |f|
- assert(writtenText != f.read)
- }
- end
-
- def test_extractNonEntry
- zf = ZipFile.new(TEST_ZIP.zipName)
- assert_exception(ZipNoSuchEntryError) { zf.extract("nonExistingEntry", "nonExistingEntry") }
- ensure
- zf.close if zf
- end
-
- def test_extractNonEntry2
- outFile = "outfile"
- assert_exception(ZipNoSuchEntryError) {
- zf = ZipFile.new(TEST_ZIP.zipName)
- nonEntry = "hotdog-diddelidoo"
- assert(! zf.entries.include?(nonEntry))
- zf.extract(nonEntry, outFile)
- zf.close
- }
- assert(! File.exists?(outFile))
- end
-
-end
-
-class ZipFileExtractDirectoryTest < CommonZipFileFixture
- TEST_OUT_NAME = "emptyOutDir"
-
- def openZip(&aProc)
- assert(aProc != nil)
- ZipFile.open(TestZipFile::TEST_ZIP4.zipName, &aProc)
- end
-
- def extractTestDir(&aProc)
- openZip {
- |zf|
- zf.extract(TestFiles::EMPTY_TEST_DIR, TEST_OUT_NAME, &aProc)
- }
- end
-
- def setup
- super
-
- Dir.rmdir(TEST_OUT_NAME) if File.directory? TEST_OUT_NAME
- File.delete(TEST_OUT_NAME) if File.exists? TEST_OUT_NAME
- end
-
- def test_extractDirectory
- extractTestDir
- assert(File.directory? TEST_OUT_NAME)
- end
-
- def test_extractDirectoryExistsAsDir
- Dir.mkdir TEST_OUT_NAME
- extractTestDir
- assert(File.directory? TEST_OUT_NAME)
- end
-
- def test_extractDirectoryExistsAsFile
- File.open(TEST_OUT_NAME, "w") { |f| f.puts "something" }
- assert_exception(ZipDestinationFileExistsError) { extractTestDir }
- end
-
- def test_extractDirectoryExistsAsFileOverwrite
- File.open(TEST_OUT_NAME, "w") { |f| f.puts "something" }
- gotCalled = false
- extractTestDir {
- |entry, destPath|
- gotCalled = true
- assert_equals(TEST_OUT_NAME, destPath)
- assert(entry.isDirectory)
- true
- }
- assert(gotCalled)
- assert(File.directory? TEST_OUT_NAME)
- end
-end
-
-
-TestFiles::createTestFiles(ARGV.index("recreate") != nil ||
- ARGV.index("recreateonly") != nil)
-TestZipFile::createTestZips(ARGV.index("recreate") != nil ||
- ARGV.index("recreateonly") != nil)
-exit if ARGV.index("recreateonly") != nil
-
-#require 'runit/cui/testrunner'
-#RUNIT::CUI::TestRunner.run(ZipFileTest.suite)
-
-# Copyright (C) 2002 Thomas Sondergaard
-# rubyzip is free software; you can redistribute it and/or
-# modify it under the terms of the ruby license.
View
BIN spec/data/generated/5entry.zip
Binary file not shown.
View
0 spec/data/generated/empty.txt
No changes.
View
BIN spec/data/generated/empty.zip
Binary file not shown.
View
0 spec/data/generated/empty_chmod640.txt
No changes.
View
4,512 spec/data/generated/longAscii.txt
0 additions, 4,512 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
BIN spec/data/generated/longBinary.bin
Binary file not shown.
View
1 spec/data/generated/randomAscii1.txt
@@ -1 +0,0 @@
-0.7429565701171660.8997290194612910.7718325912676470.2950949474578220.09517785842025890.27036319513590.3461326749358780.468212760315940.07448675019615050.8795210734675990.2258931406174380.4258029704926030.4767662641489850.6258495667289250.5323998809010980.3843176489224630.8622645706088850.4301070061366790.9195051220331180.8518866423411970.698054829037720.6714498696362290.07939297715383180.8497137925195650.4230098249865350.1498921038883270.6815396525862780.555888259309620.8755817452623650.2007131207657290.4157243074475650.2151411699905860.2799291642089620.5966741156735390.5430233076649420.8497192884491970.5472184896997030.4183164020481670.01049238673935680.5472076915274130.6496706629215140.4754491805773770.1513169254090730.5366441968884180.0722683138912060.7349200686999330.3107534357470920.8564783416155370.7620940382531090.9421752128913140.06570422049527210.9349417706712490.3899085358898240.5782845339921920.6182354587476020.3060001768997230.3806304199415570.2932110314177740.60521055185360.02988504714490790.01551239826120920.6537472959246490.3329571544439420.2279478306407840.2685132576076720.2522200224207520.8819611862165790.2908012014468370.2613068753980250.8128824005960570.9819795624558250.8878257181023420.152398456653840.8427958174141060.661394944262910.5488818525967470.6217281762155970.973619889720870.9128376532613660.6024480961944240.05755988262808920.5865545916180010.395094141626940.1048060852090390.8887116327258920.6402106979817580.9788006202901930.9165608462614010.4369365287305740.6725604456327790.254990698490010.2966940933124290.4245319337642050.04524350762526230.0747067864794050.4652294738245610.08809119307884650.4142871578398840.05621945520918210.370723753764620.406404325310860.3970760635789410.1378060248680190.09780683703433710.9429320904359590.907564655660590.6140639969074140.5311377067477850.2107113681876150.3820682079583020.8766005560638150.1308505054780680.885277359996950.3520554895356820.981727343625160.2262869692855870.7764772126928690.7625692109521390.3880477631105320.339978689641240.007462677657261160.6209256441696330.9192190851051970.3969967653787510.1181319624659420.1237587137052430.8015029059412180.05352889290054450.6622942342202020.1292464691679540.7816432919512420.1419499806511520.2312170803575610.2091872258655420.2243485754649760.9877648551377910.3403621300993140.5895733928048610.1280232883564320.3382866247385930.8305007585687290.6029587593756880.2288724403993770.849720126925540.01577454583182580.581724480211110.9190664595269230.8225377098248940.8825412943368720.3027516801976550.7344417762820110.7361536741555960.1810852211314810.8965809860546220.3990187207260210.7181858139480910.2832411248262410.1392146803330240.3672260825129370.5673073097074730.6660720710750410.8812783210011290.414074891125250.1724030714952410.4148779277976980.6899803252347570.9203697909117050.5177583821423850.6252400932847370.473725787601270.02266643313981850.6591888723501930.6921746690270430.07485013859217150.5322212089618060.6308299883812130.7101122821588260.7845400943484090.8114042459573550.5425422668919930.005542372430190620.9457348977265160.3367140933173670.1106653786747680.4055897565727960.3226891377702940.3649609689151380.4834207888892910.6208194664683380.05612364756715360.6998121121002370.4601860676094280.386812572804020.7918762176126970.9375428832312890.8946689827861340.5491705657422240.4565526208146930.3270248242702950.6664792908340890.8524605783748110.07640318010911640.9053643333580220.4251160928378540.2145240343931340.0720832698398670.7248106359766740.8843077508778770.1874426896893660.7400795794985560.4077458568806550.214806726307040.6499819941323730.2957823604173030.8915216517331510.8138585291515730.4586202871719050.8137625850837940.4453588416359470.343196975841530.7832612234655030.3126744659164380.454745701722640.6849840035766850.08206426277047970.09327462787049280.6631702998331730.8022383511351830.6597611013671390.7058965245295530.925842252099450.3243311772621180.983465669005380.8262443596112740.4438261960835290.5151416403257330.5026868278625330.7488818339920.6393498144880390.9455800409191040.3779998745871360.9456587076899370.7862690544655530.3445816517375250.5790881154869870.3899435548297350.8344426883793910.325878482955960.3003522972145890.1537286010539850.9126335752865280.2697318400535030.6459211037655530.2005992863375020.00361574318187730.6407396617384510.7484146108685710.09988701340851110.8557486396474380.7111333642683110.1620196698419110.3481331338866950.8025814344631760.6812031341243130.7868931619019290.9156106518926510.97030533779490.6557295737859210.320904094629490.4629847867501950.4151747281356690.1921863023920580.8726875755254040.7378864439878850.8300791055025630.2575954984062190.4667997790616190.1876404487655970.297154111334990.2791287663987930.7566563329826020.2937769033927480.8243484782087250.3928907438688370.7835835789109890.3854473118903850.353268736308450.006465029601784190.5852548911742150.9536840462275580.8511450457518320.6770198637135190.4036989332708080.222146597801820.194140563130010.8428913763806360.06114808620049180.04690267901762290.1153539157705060.03503899649100650.9723920492202710.1017148918477510.4813969262466710.1347464067512820.6399784278836460.8915080244681460.8307461801644050.498948439919170.6750270423372410.7200928372752180.2924003212494490.7402595575301360.6519740261136740.2597998329158420.3639191479106940.3981517211388540.8209414505921810.9123175237054850.9409885032284630.5741294165935730.7492911098789470.7582171960404080.0928828842552530.8329820651268060.9578186724691090.4859014140092540.1960487351113790.02131855232597450.7654497571603340.5668598026041250.8874685508678750.2999103474057570.3460631121128840.4365524377037030.5895387487716650.7227652426305440.5904353654990220.5141375304564720.8045472846154730.4155327372654130.2207026104132330.5450790872418690.2490121606575870.7240775966176990.6595706049652710.8118387290759440.2207436707842970.0153821297596630.174596363034430.847937310068420.05411853416437630.4605764760224470.455870803908590.6739113022537770.5836991530443160.4525234623356040.5932983573053180.8225443735801990.7278991248188650.6563888254031020.8186818170270710.4813383356116240.1453905131585790.5779739813762390.06114175425178950.4862101471760030.8470168294746490.03470410535620480.1193574379644440.2400629556607990.4625351905185370.2200809795987340.0316369837540650.06995481354149370.3587890384106460.8270975910205820.7656888557483370.2043360251295420.7999694514068540.777255150555810.6160416394671120.5693201401076980.6327583120898890.7489037756732780.253238079675760.4994062515825970.3805437980354270.2772430530442490.778264210230320.6196881793648350.9532026603708020.9407508364923920.5404176839177930.8124459983573220.9454288820574780.677569333967040.6347106976148030.3880849836966660.2496718229871170.0189165777424140.09419961742629470.5316496106146440.3404674179850760.1985633443505020.1792206637178940.270008419218070.6291270981590460.2903309341269180.8442596559844590.4367743374049920.6250138554665440.3957983241206970.0808718622407120.9686291411916680.3783534447553480.9556149253740240.90327628747770.1819231393465880.234002409047550.3997474407880170.1730835679672170.2733513975597230.2431319787686810.8748402897484940.3606881148770690.8952284421258560.3340407465231490.1945914727791130.908103884617420.3332202530432260.8078966835889670.5679111427357280.5774777242249260.4396837704751070.9814634019416930.03550255206244330.9515708182455590.05566884917480690.2199789756956470.3977079097525610.5800514541267220.03321289604449130.524613618385290.1961950621312710.8997431957500840.2241910311834050.1357104038170850.7436488756828330.1312302198504870.2000221540961240.2088380807729640.8492073988597510.4588458892501220.5938649336712270.01343879505601790.4322203746486420.6975825521090950.8065276990761640.4437001566954350.8409279671542190.1325038022620020.3864642441256140.9126846650848350.2892233004180690.8703801097948160.4834957578955110.4178720621833510.7394812785145420.7460974912900610.3011748689586070.1529852378980040.02270111541473850.6217663095937160.1547725360550060.2080836277356770.9666139449728840.1830585907638940.817343884118110.2889617775450630.9170963562929680.5800092636458480.3699396360470150.2070531785248820.03449678973424870.9912222293306010.2462922739919660.2430724301007730.7930977142268940.06289844402893220.06255959785543420.5997575138085940.8181003114550290.6944611724935620.1063134762935870.6307742647333930.1982418050869540.667604498482950.6062442905737220.6545207440986190.1638538051960020.4748873389712670.6585997290395910.05659927924609750.1146970665640610.5864800617049380.3207847064517450.2671755609412160.5000176291460680.2781758638308960.4909021764828590.6565486050600210.7366676829762320.8977738547190590.2298200991282260.2164194623274380.6271569473723220.5915569359678140.2909080753768050.4472225673497010.2817069356833730.401700959231940.5100965634423650.3126772340632680.1981598484783120.5200638298793960.9001155269510770.3997226248270070.8096332000075060.8243270264144360.03210769498027620.8637720850769590.3868118890658890.43011995375470.1393705516851150.896093857693760.2139024076758280.06141749374257740.6052464392517710.7256423874813070.4483816981092620.1045382340086080.2803296263824150.3524709080562020.1218112490075850.7107733207510390.3724719483670110.09817139953452590.8050009653698550.8385107172662940.7524651021767070.002934435220198870.1322339524680880.3987927978164820.4920719525556080.9845975080047740.0419148927260250.2856402563378580.09205429415481970.04535911242254280.2670774349658150.06779597565153580.9054186374485780.9141880004742530.9231178923362210.4969936115014930.5394931379452910.3917681978519730.4335341835824550.9249650118809630.1108987507553230.5171859748134780.9701416633568380.7101196702849770.4350081353887470.5153022914360610.7535908287634940.9384516934774790.4645915859810230.8939601703187950.3716537704808190.8004574106168480.9930827183990870.7325406317472560.4070823524694890.2308176169811910.8367305727118260.7892053471954960.9101687452439850.484702892082471
View
1 spec/data/generated/randomAscii2.txt
@@ -1 +0,0 @@
-0.560827086984630.9485629346654730.725269437238660.4174137793353950.2976776239944370.2838063207107110.8572705525456330.8167955094656190.6065725424215090.7444728733160710.2139601942395180.9496360138114350.6613913779531860.7812941525254450.9002175169151320.8978727550112380.7876080894857670.6755169998427850.4243982466572680.1743108775190820.9747557578943930.7946427261454050.6043091743492430.3721613438423760.6640046161711260.7771483884742930.4481306474936660.6363489144232890.9712456594310080.6060252907078040.93408982352210.6032383002718290.2841423338202830.9720021785566920.6456737824260830.008371578574941970.847377719637940.04904415435056310.9168950360327470.5235836960625370.8951331626298460.669678809971560.8408111122598080.2977576906694320.4404223732594880.479524998717210.5964456932878380.1449663367592420.9494610372710830.9226969709384950.9122067449526260.199874772805030.5551698359356380.5758243959867230.4479338713757330.2532898824160210.1808054303831080.4657313069783730.4842248187199850.5200869024497530.4975814632153350.4665270015213270.5037407672209770.4127718915780870.5722107456408330.2293339297215370.1830597333627450.4867403682265760.6285094164000470.4089998174782480.2665994436045410.9738164780592340.7204246924944470.6658128962229210.5704931643594880.6418372703072420.2208359142846890.6347644817999110.5087639193865140.6864122299647230.2096443400520520.7660706458068290.7011699686910910.5865737918963750.8163176626344180.8236559547319290.4123701917292110.2916519668029650.335305970113610.9466765260204710.2323345384153130.6182201867119380.1893765285950210.3133790539963780.1532526982922690.3658533658455320.7597516939324390.4258478786645250.8724469052966520.152852451192670.1499226200867660.1391096301453470.7750621616248480.9574363598268320.005159839723099750.7140276811132740.2590102238853280.4081503704907540.356965335630190.4690684180316170.9136996760433060.931062416793750.0440535791548680.5134628289607130.7893692111096710.8448637398602290.1729522447030.4186566436203650.4177779871503530.2399854629661320.6827313618348370.833409350968810.9526469635177370.464499255591720.02706771613307430.7607115802615340.09345419699998660.5923850557667510.8791771440820090.63747151740530.05556148089874020.4268746617804650.7902293048358530.9312890045644190.4974634165879570.6090683784538780.1075033954712910.6093379132124980.7979952054170680.2777570462216060.128011078951110.6863193206380290.4341119247770360.869133034954250.6784563354402620.4504738984955910.489685004036960.2895637813854420.5517971053467050.9592305929399330.03874022055163120.5432432675779850.3895037806507540.2510233613014230.7237856867994590.6504553343509540.8356037693564270.107601703645680.4972034058502430.6953056091943910.5274228635359910.195271691360950.940347720684550.4322094255420970.8864959448863510.02992371812110040.9771509688035780.4157397143994880.2264556345468620.4531022035260210.5049554541340570.400556273273020.9296945423621640.2494755029560790.2479885742244150.518067663951210.9658727561315240.8085076278321380.6598332472486480.04340068474747660.2392712126052750.8436181458645060.7840023438062840.8248126107500070.7406072242461780.6021524838321520.9718911090804120.3117289926879950.5460164297267990.6112883335242720.2404064506689190.558229468004420.2980619869493960.258037328269860.9807116038148340.6874608034807960.6867670646343990.553137593502850.9140505290375110.6507477497430370.9696985227819790.3493865320941290.7227970358246070.4927113005336820.06416993367723940.9113019930860480.8733641561173240.2222150410053310.8074371814013870.6563107322926160.2940291351690570.3574036754730320.870049433522030.2525398158947320.4785193596093210.3618249708983950.805708317694710.1302776160293580.6890205984366640.05704440992857220.880729952712940.9299077862929360.9745521054154190.686636009667640.5531525951905630.4697000346014430.2847770664701640.1377102612099540.830131404395650.4872854141555910.227529675489990.811036746465820.42846521068680.006780965905610060.03466878219423970.6661426882024710.8677281930483380.04600976984748540.2328062676505680.9701721117522380.1279761815613110.1821043631905190.2834907834835090.0001903076187448340.01876912511078430.7672595635653950.3357754857219640.8850480443524550.9793025989743650.4818783793099740.7191518149812990.0584906064236670.6496500252167750.2117082431796720.4720546759080720.8668839654858760.1756602824039990.002607398892657820.5935264832983930.443991976828370.9361161017925190.3027087473568340.594803419653020.1098133651660780.3621231980795340.08804409118240960.8116954968804020.1115829394703640.1739089408958740.6660444983627430.9546192890590390.4940560750849450.4237594081535060.1603124776971250.2003432644316280.8304982296692080.7284682959461930.1021875381594210.8679561534546420.6831676885636480.06906217932677820.7919508189716410.6468130492249480.6013873790335250.9390569140022790.5836496535187790.2949918435949430.8257792763151810.3946417111086070.3306562811388810.9217000415111690.0214591675874780.2710786350756960.2049206936037160.9366714917561520.8650997893155370.5666181240787910.5055489339980350.9738259922462070.9994750828504180.5731887974874750.6213214163357290.5114571586469190.6874779939410020.5763979341196610.1106014638169880.3292350902577640.9137784836711790.8072005424109980.3615253621262580.7900994786333250.6126621333637360.1444492567203930.3868359268577220.7456554288168940.6651542206246230.767517599146140.947261446015330.3471907594735220.965464159262780.3324185698984870.7172446807793880.1842512451134260.4567038442359040.3275822423499050.4413724335216730.2738557962999220.07405840645218120.8671203690110410.5468530734872890.5725568478637530.8483645305154790.8510005452000830.536072634069930.5591290770442380.2975266693151550.9060061528293380.6858599873285370.3801818857123340.237704115121350.264569841106940.1341001075093510.7036251819095280.385777339792660.8048560752485410.8303861895212870.2072456022506970.6178382101854480.3628277856352130.5920828709532310.1896540964925170.7409040648798390.6363267072158860.9184064860168610.6502180595165830.9073315475315320.3831280674719840.4240992120884030.006073823576048910.3771745095310290.9369572484414340.9857512760158690.205443993992040.9903226659227110.5691464394008670.0671566068643730.293643397235180.401666733484390.6510137209243460.9223531437444520.9533307976161660.9035670651294520.470339327902390.364413408850240.335662180913770.6903538846270580.1559115929832650.1723276022187040.3872019368752720.3972423420592120.03961051495065240.0009098931030961930.2752921296691620.8151424597313130.8840424471615180.3749714647022820.9492361653560940.8497379933287090.52291866166430.9106375572093710.1129854771752680.3566857443407380.28528970473460.1475401639340640.9215660863743170.9244981027824090.09036256732594190.836545699817730.2798404837725250.4053131514193090.9221621495843290.3533008187478210.5918901187440040.4646451760130750.1047100587475960.1987525739097350.114670816194660.8693302706609660.5736032898134750.2431127701756890.9755468989968360.04504164571055750.4204481042260350.2867948481643550.9042912428344320.132114193598190.6551269762408830.3830416527813690.8831557379364510.009300992734446840.470415750652380.3807688970308970.5502319024697170.685646571664080.4086917998494410.0519994897237190.297419312412510.4119585529464270.688911153842040.9038806565961150.04338954278088380.4722153399214830.6505333180286780.2745145325493960.7837938034002030.0797589164398710.4835267599988490.9182283407038760.6241594623847040.106895357183090.2651053568709510.8452195497806620.2350053264357010.1010401551885110.7346350494883020.5814016589763210.6063976170081160.2337667679150640.1752768138213970.1178903385709180.1131556260694580.2446891797962190.2694549024833740.1353124503008460.7083217256836130.7450365991226230.7538635638047670.03515329246193380.7402433273166010.1396958239661890.6340623361500210.2657164929755050.3161078492985240.9711923562939290.4176374773338430.9769242651859220.5899548473557370.06685799048081550.7487074493843070.3916419286109990.660278542618120.2164357728249160.8993093139616470.3916352555553290.6694772471543210.6441562720642550.4231093127991640.609602360653420.785334020100870.8801819120986060.1373048118196690.4277870844394320.8911716910953230.4106864362886510.8293763684256070.6060776747625670.185199991461470.471859124861710.4691871557498780.2846495870555220.5459351013878980.2809811866953190.09265249975818050.5563889636398570.6706525258245780.5197020269885830.8394974024013690.01336192686973630.2498344211359430.7063180769406090.1620760502104920.7446631993429040.4363462738284790.0743671401274950.317133485186310.6248990125053980.8043636754846370.1569408024255570.5770550467870530.7196630734501970.4008611913275740.683572192154980.2249030201112710.5355357585271020.1088399717885740.5331815346756130.04253216735699970.7381344086539790.6776483191782180.872292993300240.2653367128901440.3386284511003460.7164680186831470.74203548012080.7135441457796380.5281557694290330.8791702915814220.627255391267520.3602000267698440.1545539163745350.2378646301860420.1280984686059610.4351850548538710.5750647633847690.9207608875603820.873883939513830.7123806298031460.9510966308162620.09655367445654250.1884694411056820.4770436553930910.3987870846410540.844946631008960.661581599252970.4626001164439520.8662036003467850.1564093465351320.6330536337145550.6693010047637190.290932216432630.2778400637324740.04268283668903250.1756481275145890.7601533033868340.9978124786007650.1596268696129670.247478940849110.5109630157107520.6562632897487010.1729797711303120.19275280532470.4040977433214140.5150506308958080.8768276154018110.2465653975536030.4862215875164990.3028852421692620.9926340842883820.02883906856562930.5431416037013240.9734799865160640.9953395170428560.007884643359429290.1802488800531080.01880424254636480.561136227135490.2021323194487130.2163149634083810.5971090421659440.7352385430196960.2056146920397730.5678272049549440.335433153749890.9322645119158770.716460212917680.9402042182137120.313340530687060.6806904215313770.2152849690072830.4529093739703290.721274414121150.9721859272031030.6060363312430420.5996598345957120.7059560526085660.4370546384858440.1522507376807730.06665552539786910.1387654229034350.6370710479942670.9449996487761680.980572710835670.9560567101716560.3428072421458260.6348933617413330.9483236462242360.313563491074820.7401805040643560.5268318062555130.5582371677218520.6365190181419710.9423877980352050.7925106631432660.08360948923919110.0228911569257850.005430264813392040.8051967892467690.6333085719858660.6018619240410440.8305534859049910.03509465500339650.9023960748954250.9591516626071280.1716811134691620.5338418356659310.4021361496798840.7924936334144090.7549205100603350.5690518192419750.8016218125269270.761515704245820.5582458373077860.2624748403196070.9199294816911350.8981548210269020.7775198336739030.6654814772858970.1089924014202790.2258910606343270.9219494409093890.4502005103482420.4231078062716550.5895189154947780.2459967958972720.07493866303466020.2389611039576290.9969372302155320.5034606373815930.09120633752552340.2001682365705850.3012127502815050.9124530154626240.2123425784560240.7992355891634520.1814643201211520.9417242574990420.8068761031488470.3438525573127110.5135919692662630.09333811593192440.8927834523002470.3650391495973080.07862441870889260.9130030322736860.2600844715278120.3009882830346490.1406869019920640.9497823037668360.9463812974419250.008772742444138730.6661917507730350.4146745827544340.1639663567294650.66372326283130.5799328926741380.2431461930330650.9770914295174220.9688916551534940.5682697756415320.1135816068114420.9682347716142260.8854883024648570.3283658574275390.9665527225828380.5014570386186730.7280629413934440.3896142841394580.3329662672038930.3256344694908260.9573761226730780.897080868844920.1901777560723080.5479725774649910.02209537643580790.2987989251375810.6301073874397050.8186519925112640.6202452635220020.204384695871520.0630827186796650.2998583203230610.8974009384076290.5567598117921160.6237200813177270.5754912439156880.09033798931437550.4731804472512510.6718310355515910.9632111799606920.4308837804167730.6960699168098820.9455630621459590.4625823399681020.2967042624396720.8643190876676840.7204116824878780.691028833052690.3051451354753040.841326756651180.0002649619687371540.7348102997189020.3697720468351840.4888230605038040.08298102975049350.7507769946675730.0437123282673650.101365189049180.2686589441817130.3149524838136740.7278265108965750.9800604060067440.7071665444341520.9481893161406760.2594794480437220.9145309658096870.4582766308274210.2163952018268870.4913914465872040.5694871693917740.7906454805998180.4253570771434340.8290836495009540.2019469646102560.2585212606187310.2299324590922620.4097105685843120.1098589821929620.1087715695184190.4612567817600040.6591319358890530.4808481840939780.9141030314661540.5556562556740810.8168651853195640.5894311406657220.2864696253469380.6910142552500250.9357932069707150.479433555812640.5508139405066630.6817408280952290.2788171447981470.9512294989514080.5230578957379310.09135242342021670.7969763945287550.4511089857535380.5425146753403340.1309387944747620.7240117494059780.8853579990634060.2169651288338550.9190914879037120.9279088821379140.9754430720582430.3240256946653970.1389012621923280.2872633461675580.6723400266729770.2395419687106660.6385625571983430.3240154082662420.1832732004860410.7981827445344850.8773831356019210.9788049243228570.4609640760955870.9876072927122240.2782271229531220.3413815879046440.008812188246264730.6807700865702120.273307554891340.4723632951874910.9190202594494890.1312889757603810.9624081611316160.2194408133173780.6645704026079370.7866369141860750.6897183415285640.4368155195437960.694177047473310.7371702365295340.6161514491440430.3126047263378920.5029706381865880.9288795159152030.1661920834481180.8434397944150680.8073691926496780.03453279124296740.2127236878099140.7022894800782650.2185564782858250.8038845956327710.1006199894283940.3733176871765860.0550932746579780.9606798208084510.4346575490317060.2440207227320020.5786817829203420.510754305894790.2807241807010460.5410781327874680.8626800954843830.9429852334541450.3045496646592170.6993180958480570.3638411910074390.5986255234222530.4781888600931610.7377262018253540.8302049412852260.1484218501061290.3727501778138810.4479614205936480.1945006354873240.1371403849349390.3740359484317970.2280051447434870.4462917880095090.1190790460710890.218790764055380.004801718436738820.9458884188382750.1019205810180330.7979911844930050.1470528967373470.2527614909876070.4831257738491340.6545088491676390.4043149724925610.4635471188848740.67065157951050.1558411506114230.6241976290789030.243043240336790.7227424767981450.104175972360490.6036947979856620.8481943282647430.5031910362334830.5000399105092320.5344692875373790.6429737754356930.1516014096477640.3345384525581750.8190304495352580.2172183261500930.5745718639453490.279792957499760.3866865881628620.8489615914259390.8451383827775650.1510554987687280.281485042726110.8074078305552860.2510352631743630.3742775510057270.5389078799600170.08954450546878880.385919002516820.04545458564130180.7198885498823970.4798768522853150.9809110487266870.6368603305541910.5570413520758460.2841003889993430.05496890391855010.1830821179639320.314403339295930.5790133934913180.6094402296437320.7613734758935350.8263417429094650.4686656963351260.0333563928024370.659823392209780.8949378646957160.9284166724467880.6231866302979190.4677374261787570.1945528660727840.8219372980973690.2053117953548740.3695371743894080.7135930219845740.4114924346282360.9748717935313760.5097258505315550.4499236566508230.7296821980215970.2847568930085580.3572847058241290.6764594270688120.6392714707755560.8196002480270250.2530842758724870.5160764285462040.7208800585131980.1176789780565260.3368936987021840.3727286251868450.9927133180379040.4485739376058890.4336508182427740.4614046885531860.04525947716537740.01783325468983870.6262045216927230.02582450574978870.9410986832633560.3921178656743420.5739124981851150.116460024273260.3030313395718370.9324749194439290.7350321970358820.9681752732386990.8810246787217630.6756181399143490.6071663232919720.2126633428961030.542881792885830.7293410439649640.001062140985270910.8153111236571490.8682795311215930.5799498145381280.3321317029511590.6407034860278490.7323479194868160.7470214305551030.8690851567814570.9535742496213050.553984476517970.8961106691489730.5253752947034150.9388821961937530.869131578229340.6136730457140220.42232684981830.9786470759297230.1251314552185880.6350835085213510.3496779102916150.9193839254471630.2211012230015720.480275322838330.9096810244307690.1139333427391270.2344407909518680.4053560876473420.7930291416473550.4692989799931680.401911302352740.1603300329526750.4730428219942050.7505410982633220.8090821306576120.6769373850514230.9200018221665670.6303197369063180.03787936917544930.9777143779554380.3417980776910580.02017853837258010.7873447406740740.993660145352310.2599384555592550.6983008448537550.09993012477637480.8425768357081290.4227675164304240.5940039133339070.6598465308463070.2135709396271490.4183335349354230.826568847563630.9449389789040510.9735110376325630.1826918498689910.5950639749189860.1967780994416020.655856230344740.3004899511265540.2657694103964290.3247164906661270.3110759212518670.8772517849577230.8165843054089050.7766026653651940.7181929974322090.779241599500460.1572789831213570.1480964397494160.366770177405720.8847369919628870.8860224819754050.4659846162748350.4652387323522510.2379286023056280.849782359605690.9743753886481750.2156112058003450.7529200613575950.4907757765704690.4836820500535970.1480904311995470.6173564744852020.03006431210614140.3235902563012740.8700047567212330.6014311562514590.4250594895405010.4995989183341130.7638805068821250.4378246078284560.2889918234797560.4608028838932740.7392317072927190.3372712599998710.2409687484832570.6836620216209660.03257672367940480.4058238341961350.8883638083494080.5576677619657940.8136234858191440.4916200699910610.7382697337313880.2424290031766430.20648080125140.3533669167527410.9652386197901180.08607766355089910.154942549308040.01396424456383690.1499497670139050.9826549107965060.6913351090541990.1088382158225140.7471295792077080.7194667010878550.8336670733700270.4443611888822890.9252086856006680.7320113140035470.5220319384464380.6531643739104910.7041746072678960.2247352779720730.4618979320536260.9772160147100680.2046359993865640.3036921245793790.3151681088814920.2928092558326880.4083054116076730.8484768688012180.06341282660126610.3496316856558340.6909825465059840.9410241899278610.955725772324970.9316000999037770.2418590250306110.518521448232450.4166333928846390.840279998038440.1964356291473910.4027767134027610.6418948735497430.8571112295365040.4277331853493070.2530105919982910.03875167027173930.1282123757120760.1220645592941860.6293032335524190.5973997343471770.2154676589842190.5656927226413640.3953160369782790.6864090494707230.3247338022209740.8436330172210850.707478972286850.779459808618920.5238485441844110.1015152299215540.8059528015837690.9905633114255410.6663920979503750.5793498184439120.4390371409954140.8302621840542520.01448189217559060.2794543582616550.6639140666520680.2319458369505770.9839244312011890.3744458343662830.9647955367694510.7291647005450910.6352339889725140.1627915330280780.03854172497976420.7000988815599930.7282560439257570.1541996259019410.4283514941899250.6694731283322750.7134961447746790.1823914804023260.6499195075835770.3697666212110460.03574998932308350.9368726424882370.9018408395928420.6678719373175480.9928011817415370.05035370596838430.7111481811783660.9211216202870440.6700440701913720.1456025311402320.01673191172197740.6804137122931950.5487197121715670.05468222340822520.7720913728381960.2803529286609590.004216526324114180.4971516974194730.04119196128581770.8024793178696410.8907411519188640.9614403366824140.6587148074692450.3275105432412640.256319922163560.2836565752140610.879256286611650.501632629718430.1017205011380780.1246521552375070.7508342895530650.5786674881103080.9982389137943850.8906386581384290.8882609412316550.468202227940460.370130046387790.8409341274608470.747987442967005
View
1 spec/data/generated/randomAscii3.txt
@@ -1 +0,0 @@
-0.3948998668656810.4059651176922780.09302887845568660.004816352942495720.4656174389918920.2460653046885150.4044461541220980.1163648776810190.5840010460932210.7765241462307320.5351068134305050.01506818489324910.9029171920121080.9589043327144170.5518167898934170.4100202410448350.85841600199410.03331278565929070.9983435804438460.1393227061219460.03887244662609430.928531782922230.5416402587691630.5532866459926240.1117862208262160.4573626700178950.6755734560788650.7440443891265550.07206217234037880.7718029865809780.7334947782910250.01036184295361720.05068184957111950.8742721961824640.4785484605667930.3040169831700340.2795120303485420.7556088437559840.1491150203453950.9363613180208730.9962245953387550.1653556785178180.3865489599893010.7774545144785650.4007450917106160.2674124099182070.6314115136311080.2140444813714720.8201879821564770.1728314695188520.02837014782146130.1719305704013010.4758108259836880.04928724797355420.2004996605632060.194692354818750.03424115691423690.8485652533285880.2706235058276810.1258205592027010.9397328580734880.8216222806926650.5147601668280010.1690642799539690.02878119092630560.1829407387361260.6041019332051630.8135428126910510.3874672748329190.9639059330200890.9281769069409940.1709541438956720.4031397481823410.9873403448466390.4925451966922810.636663869151410.8967512990036040.8479470520925660.2675555627616470.7376643044065280.2578898583648520.3086270160978790.5995458609890820.7141854223449480.0440372446141670.7114204818745480.436131777407010.2058291190644480.99084364448710.2737653566801580.979919739520440.8233665056565070.6469425216214050.1104080529658480.8526831361462320.621802754316610.1729793053284340.4847643945565150.8432670479653320.5657123714292650.9435374114239860.8420346037298430.9855730169711460.6977440684218390.4427612414838550.448212716300140.5074072343049430.8173266968561810.8018631854935910.01568899758339830.1924967957097970.8606662813880660.8019928703100570.6178988931006550.8203975242642480.1779689290308330.5251728744648760.8459107394870920.8052221211826480.4923590895417510.3882236235554720.7596555626512210.3767639168049480.8628615960956140.7584927720021470.2586226212089650.05565205858738710.04248355425094760.2943128094506170.8229144427185460.7456924602150230.8914936328649240.02568910967130830.5818684228751920.206944389856080.2743347740844270.1323906019164140.1818801550135670.3264838887761580.4906354071005720.2717311983526870.7253638028421850.7691587739096070.7680004150862710.8274238514566140.7620210443209040.4748600375361920.041514307443020.942206662021550.1083224915031360.6771317727854530.396003732222920.252756635595780.7662563789107590.2604412210933690.9815495169778740.3220851457353890.7827522541344360.3569967082729220.3115335567532820.2071843528599450.1518763360359690.7224273375639110.9154223937267440.4131566619627760.5730096642873010.429897774041150.08411388401524910.2233804072508260.04327336988090980.08796655125944530.4038034232832590.09309679305275360.6837795143580830.2139312468970590.5448565960556450.4852854898041310.6838118354481170.9403725861674420.1228859143025010.2632171123651730.4817326055647610.9573501331332510.5508954995277520.7354491576208670.03883010777598910.7397601585378880.9481113825698470.464501146450040.9346176521204410.6050450571285930.8588278399381430.1461890689432180.03455776335275570.08095565455823150.8385279921953480.5124872685619770.5826685790656690.8369143456360570.9795471436564520.9632978389806040.07014683019681590.9961901221667520.6682511423879880.3995357892697530.4776298254611640.4065091753740780.6842008598279340.8194679792353460.1643586862333460.5807182857960820.3512863312817480.3671302370609670.7664362978606270.5670141622323560.3000076491158170.4363934079243630.09504270686708560.8433089719311050.6108327767096060.5641327844695730.337506365714940.3864920328684630.7784053662595110.1155492596244730.9770106453241430.8581300341886910.9045561768822870.9521251558740420.3756387873557050.7012208769795720.8932861630638050.9261810001962340.01671471247190080.9431202850502150.9294190850511120.001491109264748710.2050216270919180.2250309349644620.3571036145835660.1417957865451810.2463857587516570.626890691268180.7960543769545290.8355768715533590.9763169871999840.5489536245670780.1311800850519330.5467622243004080.3707915034188190.07025082845722850.5790022076439020.9222593259774510.9570509125370890.8586887501216150.6871156351503140.540911806991210.3873326242775770.7251879099483930.7897964937046340.3050680772100330.2762580574262620.599579181873170.2442563990131580.3594368580670370.5165182484425820.9547179642637140.7931350396644030.786886269566870.2890710637907950.6834094370947430.4988812843904280.8293569681611160.1361643497973640.371074401325170.140389857184410.7539059251964740.06285820233514770.1303158071243090.8713485159719960.3582441980965170.02101585999518050.8975467280236250.3671640696310210.150560188144810.6252951580782070.8913061094805390.1119237263990890.4538473326331490.6092593180479710.4300747480404280.797368303617470.6296201969365710.3204583722020930.6549674984869130.2942280396005550.524665746975260.3549907605791110.7269037845822490.5185923362958790.7770538714085290.01438005338837880.1043790267186520.3365623900399320.3281695102894660.4574719389206610.9960177723155420.2895436121480520.844447309141030.8626662493031750.4158794726976870.4935311156888740.4933409970996660.7975173624382480.5467245762245140.1956193556848420.6137753779808270.7482526411356870.7200205967270350.01197156348582810.7497583356373320.4036343939292080.1040393494441080.07509545951503260.3205097829751760.6504588710357570.9461642492467890.2857779625429120.5482288823684770.1581773067066750.2609856666566170.1388776663865690.8828386967219310.7381057302509530.2790730393568060.2456098907806430.3241190606241840.9624209595517320.8469300723413970.2688875920647270.3053422061395090.8889007924636540.3159911682300240.7496815672609680.3242642724871590.967985911957960.2431504537313250.755587466800120.474953764942070.393769183201810.07945814864133560.7960091247158780.8835658804155050.3315147689423080.2715271287272810.796461958001270.1137374346803130.3311280507608720.2386972126353490.2316855323583760.7843861003350510.9257235710303420.04134024369936170.3194895692256380.7330856485594950.03146848366019440.4282939558480.7189718921197860.6151290177136670.9386229909915760.982783360835830.05841856072703910.7446282378682580.08542014510730180.4116698165525290.9722031295070030.3992376126847470.1762346718634280.03812985332001060.4207347620268810.3665880534822710.1362348770243740.3142235032793860.9868042729041940.7047984948446740.5278740775383940.513251856342760.4927644034001470.4104017174543230.9195393602845540.8083546191137820.7250673646810080.3368504081641970.6281918947906980.4255999604511970.8492497474677890.1645259210249110.097182675358540.4831994743648370.06412151346447660.2321745081030810.825184683501680.5269666443359710.926408883774590.2548411787884730.9877203033508820.118025130931690.2013559214539380.9195488649641880.5320299214319610.874420265829730.4580344645028460.4245958873294540.7790337248278150.2230195331063410.965273182579130.9101329690784750.6498420853918580.8457940157228610.4303612192108460.8359757358842090.3809423796056730.5863339547520060.2903744118941240.9372118445923540.8611223401104890.5332761425159370.4871433640404690.6348425489748530.2155197740797780.1249380659659730.200148644320590.3600534150095470.8729137671651260.002845220237241760.905186090726760.7701238027998110.1550933512214850.5082249543092890.2274654240321210.7094755018036250.7226318690125720.7834477353702760.7236556822672530.9727882183648560.779457423584760.4689907992226590.2552318970681410.7512486968873790.8879442481753090.2655626668336860.2016545533269050.4706665959099710.7993565012088430.8511371573365050.7462321626239590.9243661083980570.9043963501629280.6495089437855120.9636989351581820.8311160530052140.8632136555194920.7449914919657310.193928592477030.1746376940254420.2295858351568250.9551495037782890.2567301717964650.9416570877945520.8654232886751760.5603879080895570.7693994783328290.09264044924501790.7234402559719770.02854744880242080.1462853624894070.03229439404510890.1832800463321980.8735558527750730.4709961726460490.1992528799374350.5386462194470930.5719132326763090.4648466430229280.635250720674640.9423090228509080.6228003146901740.572229228370490.09310332548798390.6396269463519870.2627569408046930.4685090545463120.8601549810306970.8019035412022470.3261342199336410.702221762243680.9310240434222290.8871038946269630.3517497242866260.4494083588435630.1536086728664030.7503919874120090.8894685826004410.9624742895474330.8910066045593940.01971000925270550.2567145266103640.08832014066540630.6294412280888290.5464962313609380.03065563488338810.9039986166632580.6633778559675190.9116540662188930.4405642344430150.5880132650144240.8559693797940360.7513792564069490.4140110071090.7253170813602440.05716224529784910.840239946476140.7894527225306780.7786311613794180.4335955129368170.6031252270430790.7386478528666830.9744281835870690.2318069868668650.2335397618814540.1138665804703320.0789134429305440.137862905163470.90936085098290.610688518808390.382439286217190.6628920628792820.3791525098343710.4986545036639130.5049993905380160.4362610894769280.497690650465920.5597991892459480.8856439483584710.4145186164546250.6451476473573990.9616036706993220.6304995172922050.717942767703930.7872845925285330.07963804331523750.9588643591315770.3937974239391150.9432765167540510.8069038868560140.6161475905194290.5128336758787870.222637539240460.2888378218909740.1374842859024930.1331203721381370.9628250907203990.07287079631519080.6060878888695770.04142132215738270.7280039117913650.2111513057485460.3799982098754090.6303000634576830.4013820062114870.2676795037375170.663703264307580.9102676766756760.2409199559894810.02199417524788220.9442981614706590.8383307185153420.3719405418725930.3233709602634320.1599480881367150.2830392756602590.9384111360422340.8354708500579540.9010257222497240.9644182160598880.8506936935233180.9668053666151950.6533880361147510.05378048099656740.2544127728311160.1375042437616070.3518605755718250.872019615921350.09141795603703260.469867926817970.6404325502629510.5763380935942470.174665560428970.8273825568135390.4291589501181940.1947523325562880.05268027702758820.5892361156293130.6074716186454420.350727097216760.4700560011307090.9486544509264360.6296113880972620.8006117382573870.7811614071108370.5072869823362690.1421317530521720.1461563007669660.354833096798750.9096997304365950.1342961168105810.5594036146397020.7350526369992220.7233400605810020.4306272116344860.3532583449788690.3854753568398590.09191172619460240.8677746033038610.2331715650553460.5559875244310620.1698146099297570.1955178193315210.5491578905056030.3605211706193460.4579061171315720.1103977865953360.9744932375045990.2492689104150480.5786875110460050.3400356390623510.4346010679513660.75070910254550.7079023079905020.8635935318986920.3424627095271030.04351612102194750.151507925353170.6824001784873250.6186351477957080.1710696382208580.06783273621357320.3080480751609410.8952859923047810.3317230968209220.7814285568774810.5697546790755770.29487678820680.4270687399004460.2978233006394820.8350260860004070.6959025185849530.3343723606090710.8851525177985220.3644899462878650.8755025712006360.2578570763749970.2129462483297090.487447598247080.01035000752556370.1589663835731620.7011840269733290.1937952785666940.8093404448596940.8928764608620940.6256845045872980.5582672110005230.1346142696875490.3008133686793980.5640441492269010.5255421393779440.2900886219313290.4876609695604130.7774585318724980.3399053998058680.6306729330377210.581015844405060.7816986784896460.8278326066908960.002119022291036110.7307195206444030.9420324970406780.01520897401250960.680836963583860.9502232517468730.8450610890628590.8783405733041340.6581824950279730.1769684452669510.1154995608280070.5036614325889510.3155982600185060.7310843800922430.9374393922232220.7850832343786560.7726050281619620.1625718555825230.1290893751753920.9481697971045750.353033848221060.9728467440746970.4662296229662550.9606183620737280.2657615204091210.8182294616618440.2292271727578820.7961492543797780.9485459480582060.4871782666837140.1680630263973660.9906872482156150.03911241551710410.01816667545812570.3478270750016590.268014932199370.2420318662348910.6598949540277630.690532539611950.01837568248253370.8142974604872960.5093738771161630.1719687173688360.03350598782966230.2328462599973850.7126839677639480.7863995159352040.8662364687241260.1775538186875540.1275876563856790.33295478599310.4251401700944370.916539099032680.7964949419569920.7188291019728580.8873680944653560.6813054270899420.04682160863843820.6531448466141570.693950292460870.1784281383789680.1748675537273520.1616684159896810.05189613576687970.5430786953077380.8694854196951370.662732196424830.3482249214230180.03815728686793140.03776188028220770.5712709320479060.5293412904274360.06377108609293820.5502798634283220.2857836978926890.3288801651058010.0885628228366880.7318858881808020.344940774873250.9572031516660480.7154096180178710.8924838158319850.1716869493441830.1429796981043110.4480140976067270.9512594377305860.6040834424956170.3831462973839130.1265162307945720.4631863251262360.3048040436879190.07541772500140750.146867214120920.6880157583197180.1244618655110870.588382854352990.9138075743327780.4380032722689970.9019156530401010.8225725118457940.05675942542422120.4855368917628750.2919384550350060.719618181742690.1933082413504630.8511726996203570.3266013850553440.6912040625555330.8185862641376940.4091642984470620.05765140273230630.9136090745718930.0105966936080720.9815493045516840.818200374557460.7426753136727890.3459583769766150.9475565180516480.6356432035389370.3473424996103040.08385584079864720.1662071961111160.3218356250416280.3096471751258930.5731626905742420.7917382745793710.8295025724100030.006184595147445960.2849492680416280.01329002176540610.5083960809389290.6667481600992360.1529511644071650.4707381879818580.9014450167062620.9223059337101460.01955947971022890.7901447887789830.9753511892266850.1572641767018690.8907293883889940.5243766929564840.3683503829350070.7125032834465080.9303234488321240.3743345918154660.9969209129620690.4195616613850180.423440105247040.4899066846218150.3409909113748940.376022708086410.9418941519752940.7537303025546530.6895105327587740.953526663012630.02704565361741110.5677758403330160.3791402547562240.375239282615490.9697963107255370.8389758655114030.2825199541265990.2621205614469060.1196687582319450.7071399778942520.601503006556610.177405670747790.9238328018467580.1467772058592450.3492920443169570.3032254358824260.0008818838824173890.6698985254028120.2351468140217260.2841603250595980.8269526660055850.5798601438395080.1445824901494450.5308889299101680.4986735317175630.3125578622311550.2687356627312810.3041443880260020.6688322264238410.9704787241283560.3880344572770910.6520294462826050.8250785795079290.5837624847891520.9138376094636260.1869825458566860.3949984562488780.8948130532754850.3582950788835220.9445451091192950.5926629492624410.9032247093547260.8400170656427640.1213627955435440.4594398715835290.2717926691473230.05845666073416980.266332050770630.8952012602266370.3091424469767140.7940348567274550.9624517606256790.7569894278278050.411689933051720.995395804900780.3627648808559670.7260268689893550.5797901634796560.5919217498184990.8172698607764090.5751101943936390.2857327791022050.6093260609957720.1725706444952450.8509366158922730.2969757682030550.3626178262270670.1619065768964560.1107676646194990.3777838813579490.2409700012111510.8727106360814380.7555073734965250.2596615424845010.7677624350403310.2017070021270270.2934129988698130.1360579844435780.5663045625483960.9644736270419160.5376681197485840.477152972189480.5462526996901720.2002690556261870.71656804874430.9654639827323860.8277681487031320.8893786270454450.6892372921098170.2185519326041390.8648754112115710.06567570782183760.5853402286693240.9460360301279170.03071561265448160.2674844933995420.1360637538885280.9165046593475730.6632755732789310.2490467939531220.5227246798284540.6475258773096010.7526026746869370.1205345521149590.1902720562337920.08395974002872790.3851841186602540.2996590190792960.01622184037093610.8295638321501090.8319940403067340.9737377424606150.2951456376615810.5799662850542720.3092781488813750.8467371201475320.6141533701178580.02353055393052840.2868818975555520.3946107286039980.6966209407068110.3172841726458440.5369754813491220.4361399021083590.5244684931551380.9990276384982390.5784650254272280.3703279218417930.1650579105821080.2106312559826330.3247616060362520.3375948190210250.4590118553703290.6221805462389490.3527795857658070.1238940886452980.0909530816474230.5987954855109030.1878127239601880.04312298890981150.4121240466831370.5966611716895640.2654133634397290.2471075198817660.344868832845820.6674862772415390.5194708000157820.1641714921992860.9954884377722940.7864887846073360.2397510167248670.3071249018445070.6767454985034090.2175717768995080.6379855281202050.3069529352690850.00888177324404360.6533811863451240.8867651744421480.8953423348803920.1854263134731010.5480643902917780.8323856354045160.4841255288481690.8202976561957410.7827099140957360.06492561495048490.3543407844397210.7008880390372860.03415399562233160.1993639955331660.5482978799605750.8418498411528940.9948891046348750.4858493686217570.4215776284459540.4950985773997420.5132223648300260.9549358879993340.6493698343012430.9329853300607750.6115868791738940.6047141355010590.2697685220065220.8628290265119070.4806658274516680.8403116078539130.3011625421702130.830712274935640.5043067159348350.6684343565356830.3450262359987090.1511499126683160.7725514057200940.1875869917872580.9745611576903370.789747358342250.2565051130126950.8179886492379250.02685365260777290.3013019696810650.3833905491456660.2791157949248260.9395310757438260.1363304496803430.8455221567763550.4105413119593620.2404294214636580.68457947604030.8341122857918990.8955283644681460.1100574180687790.7937516735149690.8659475286497710.4441037286624740.3163925022371420.05005608184909530.5074720141115520.9305505419366980.6724219962004840.5529858540332490.2656650664101520.8421810123108160.6320338110451460.8498677203354880.09193718033107420.1900250345047670.3388605540552670.6325895053002020.4505257015208980.3505794190262460.1652660294121120.0474916801113940.5001470759918650.3858181099050940.9557659111451050.2521198295671610.1668432564162990.9772958119069080.4434187324708940.9104565781893050.9049841428274570.7483844836213160.3673709894013820.5156607450637470.140514159540190.8392501265984950.8524351437589390.6024207620194630.2907171375494680.863137926743080.1310508783038510.04728363912159180.07200119158450250.7230430469321810.452670835060410.371135627317660.08144100844522930.3138388779900340.8842014349841850.8204648118984280.2749167773102070.5410723331731720.6781025088676030.8378757042042470.5870013496376750.4859064398383710.3640980965856550.3898018540285210.6305461765083350.2619331954077330.9171218998947710.7163771870550960.9734449531738910.2364704752395130.2415671019185560.02905452430854580.6768832231867570.1201591215569680.03622900037734610.7750727760290410.3089516967558490.7360198933217560.5644203072997720.8015304231543970.3507542545999690.3636400480171820.525950739684750.4713774711629320.4634915002836180.3894165636234720.5046689675943140.958274460859820.6269907513925670.5063256612174380.2951295805657050.3898386925582470.7736925471503480.9422870252350.01562822065235060.4888261100234710.1811765005490390.150189408617420.9192991810427540.2814447792480370.04369095215871950.9993082907724010.6988191836445540.4050321754859670.2703529005535410.7600964222229110.2878992740617010.02484306916410450.3676680243743470.1344951404390440.06953504197730790.5698441129501750.4436457627462080.6625265767216040.5945093201140680.9402120333201010.1248145293745640.2330544810221950.3238404516037180.9241138656609970.9492123447294320.2957250062256720.7563576356738770.7813153757785060.04502932223393450.04752365529620.8336452658059590.8337868019449080.8210916885125410.3197002891050580.004243873783288720.4424632805026930.9987004534940890.1379966152234910.9825293690601910.4348173829567570.05908771728118420.4871248618430540.08394244117313220.3197316294812680.4172955948424680.8349872597070690.6322833004575290.687572337483390.8220668787489360.8188570317793560.4796294375105280.7516629939956980.1560710380025490.3986398717255650.2303338816069490.831522199763370.6155655708939180.03735343945982430.639335816524560.9953000177795350.8735843349278150.9662849564240170.4924506764545150.03157999305256690.02141405471793490.2449401982348860.1141314886881770.5634927979528830.09906129393455710.720047661258620.05867602727210670.6433548866780390.7356919752281020.05673336099818980.5925207546703580.4350300540696950.5860856063818010.7299961010130130.1600835244987570.09142118354122220.6458292556615970.6282321369354950.4643451988534560.6308774707204850.6111425218957460.7010828368350480.6460408263429270.7804005958595590.7018198948178420.4458103330812680.2394573066535540.2789926315542920.9357371812903880.9538842816956090.001329117361846150.04433154819966480.7792457397819120.7131872438980520.7677534135040560.5907255572263190.8616526625311020.008302862767303850.2961812905612730.7365253520388820.8541761248684780.5672306141205670.7776409502756750.3562172200141340.7411108170348610.07271245468571670.1225862170580690.1996339222849820.7274773407326020.5554932330693040.3987370702832920.4668437869631450.9803038308009370.8110077088031380.05849229942646010.9749060216330730.03620139498698660.8378944675247910.5450191278740770.5830668472560460.6724571064925270.5279867056159420.8512988701062180.9879079462030140.8235977768107960.2065831612938230.4132855853979290.5555276301342120.9252344470196780.4235094810209520.1398962032871350.9318616681552590.4045011229678740.05623138959837810.5750042063931450.1217966804379340.8947215151481650.9127032300961540.7630873347330370.8108153130713770.4558309149744660.5290071639044780.7072524906226850.7122122649989010.3185788271072790.4997023916065780.5690051151029550.413295835074330.6631924871720250.361055809144790.8893578215560530.2810363227107610.7588142541661740.6652002319106660.8072405922645270.229702696377440.3455474520534530.1539600870327610.2175299616978880.1580040128517270.3376112390950640.1229603595755260.4862389449582180.5371106193944230.5633726765990040.2285562458550680.3275145061426330.2214707216058040.1081523564633170.2039717701100150.9137772651114480.4600610426820730.5728191809732140.3679223507177750.3528709485968770.9026988607751590.7102517228257680.5626079260578820.3371723243567570.4013677227989290.2205390545889880.4154314706045380.6819796083069130.1047192281797340.7555665881579250.2497177924043170.990362337562680.03409652935243270.2206374957440210.3867303147646460.09872665623248630.9874284826519350.7345371852082490.2479863769644090.1630673827044990.1761318554737180.6772570029916420.3810802936599080.4779959706308750.6848499659820480.8848136028120320.7747411321186850.0510505275872960.304109845614480.7243849985923720.2462550454726610.4210484452936710.7958940362834080.4492888240738260.4090454417663010.9812367932828320.4758007467634230.3077310363007020.742647060835380.303605972465840.9945517473659440.8690225786105890.08460868687143870.6552024680536640.2388763339091390.2839651958270990.3338182463572610.008532872959097550.8761134404961480.9882719176273050.5133267365988650.1937231844816320.3196891752036770.12689929238110.4644580160593760.2655109638769560.07798373672405690.896261021808640.7478335101510130.7639795488118730.8015563879464580.2253776234483990.8119846613004130.4803920765112860.4339553425388030.6864214661385370.06376105435919820.2414665299843650.08481187010731250.4725114641219920.7970509376473070.007687672038539820.1789829888591060.4300442135009370.6516573190931270.08862302152115150.6776223152694280.1109755160277170.956057139632980.593284657415610.9920681643152750.2805865261993730.08736283656752060.2782950331370420.8068944596727270.9513012901030750.740391259235960.6446486773816250.1338247798427590.01522043253032050.1804878633928610.6529980586641330.6476494639235140.9004474914340450.003941065891755470.8433424005354030.5535088149065030.7138721358362620.9340406646012080.4400001682667990.2506774629014070.8395663738510440.2679604037794660.518051471684520.398373433590690.3559356467955830.4099604115430610.8416062584563970.219118354909510.06297949415626150.7298512133121630.01432198811863920.9328211958819230.7175071386788180.04582452874063750.9247403663618660.8126374718129810.975548215727460.5079812271414360.8238580816102830.3431584601101730.7041837583792840.02630742882571970.04869625439912020.3248656453801290.3784988145175930.6312303872911850.3754431605764650.4830559783420020.742798239607160.9329392020893940.3900242038689380.9130644559709110.1117333766076280.05243770449410420.7954732334786380.1075314218052920.4630348933623170.8233928741357440.436744230304520.7457643023930770.5321197229241640.7225642450304780.7754345772962770.2532255868072190.8258076121560740.2979380911248360.8099018811189170.7215622439674550.1446833262022850.3813755329575840.5817956102146270.7745680663899020.4205228504544310.8740108655101330.4820412473893960.5071816126847430.08618626012203380.7717540527598670.6376751733282870.3437019402758380.4341665817295530.360531887841390.2885286643815010.2367515402455050.6690238107838870.330639232502760.6743342039148020.4834685959031080.3592767947126150.4491028179724580.4137015159932410.5753514225840210.8742623945210130.2594185856227550.2477756313718420.1502105919063390.3493368741689360.5860858835784780.56342617417540.1443674568677260.6523196021698570.9710221182307270.2038674849398920.6951969070611340.8963777898314560.5993478497869450.8415148484688520.1570596423302430.9252960248332210.6517926120114460.3963322552204940.3033818573546550.7695375638181560.8261023244549370.5602427325134690.869827258328930.5260447853304350.8676109914527960.7923820697319820.01412237732037210.6468407883938240.4653767975787120.2077737788619040.8371253363080740.7610506446588340.4629759329474480.2158032192542750.09414148845198590.1969121421257680.4973482937286470.0002200494972774970.6041992106296460.582942434178060.150544807951370.7319471402571260.121139959462960.6676501666656770.3587246022295220.4188279801947930.183889895762040.3374020164867810.6092488995155180.9454934224612240.0415324771809280.4065278211810610.9131100884527750.8145258122832480.6165448213315320.3171016229501830.7406059619625810.3669162700417370.64677132032710.7799875724537160.199933534885590.5454930425087130.1552113573204980.8240786509007360.8425460613216810.1424954678354530.1956823427535960.9652043998179130.3544472019351360.3561161963919980.2667063943746990.9453245268832610.07386193555855540.4084212848496290.5202815165027750.7142605878851590.2053211051369150.3090052132300220.7958639076409030.4206260532618150.4367148650704460.5879387062353160.4158342354867680.7291043559717530.699993770691570.4876870890817310.003095222504123530.2180163026909380.009157232780251820.007034083850922190.2402353124506330.6894730385153150.007685835374293460.7052498643977870.7286955974676380.8355531016648440.008603241950065790.0340948444990850.2590387096391870.2563039038315270.1161158372233210.3600917274426170.003453576643961510.2929182533434950.309187354810180.8541701843663290.0444914116187050.6670130764977070.5445212743172810.174095815881070.1797653696863470.3010738131971750.7420984921792540.1092405844903280.5770588129380370.526438698256250.4166561695648760.994729398779240.5345281996049650.3061408974218310.5259943221695490.9048470664089420.261554607153460.6584549850890780.477539188073820.594213845375970.1592070833925780.2440438986409640.8768405476863180.1193581963338850.006721639588412210.3066372673682160.6263003897434190.358792368275340.6321725130558620.9801312841777570.6985120830653340.4761854815322340.5821377357950370.2470568935384420.6239650777210560.6614099779649640.7805191959656320.2722363499640790.7900855204183880.4036037849559270.8036168093996390.9563601090975090.9907468457762080.9563904229976850.5496558705771480.8070066337438040.5527153519798960.3433949836505280.6812270331392380.6902480799341440.6049951776126690.9313824308379240.704218347633530.1293840669391610.6386672033268750.2354182319253780.9791021144947410.2172437772089130.1990808697615950.5218460200373750.5669517851802290.008022863346797030.2219779161165010.663921687825510.6374684978461570.6515940155065830.5102463478895190.5679764064239320.4435700072044370.1174905224360680.5730752332339310.121628637576850.05200977251793550.5482331883227950.03243118026760040.4516455999909610.5610540661744910.460290107557840.9747941648492130.219070225310360.9650092897109040.1983662744106550.2048336193138850.8353047222982850.2749456804901690.7554074855243310.8400440616067380.2088958351845780.2764901303475930.8339788941415520.352313121757560.50684075777620.8231024939850330.807765918166250.4480737809153880.6838428429298750.586478530144890.477579273747620.8641866611680680.7293810115511870.2105320507901150.5977438239143550.2540385178176950.4964171203722030.4057825282652220.3824289008754450.7985254092761930.6076419890974240.743534367763590.4061368101049850.1015333680035310.1242980662546160.8881794882179540.9261704524526820.1958828373472790.7743434715607110.0321636719500910.7957815806903030.6093053571360860.3931186508543330.1074807309554080.3719999778526510.8974800363967190.5073188600111450.9063979107720770.2169072522334280.6121549800796360.2457440146659330.4751767564723850.04346962582741480.7340007757984560.5205801224403330.0796800835356590.1561427723846240.963755436153760.6124336935654020.872471533288910.05356009592835550.816989826022470.477260414152350.6991759493757550.1561687934064930.2197712233155440.664270781547740.1198766068838930.9323460681084420.5192217914663780.08773094011037120.7024996127868890.367660543154980.02368671125005630.3702452205882670.264786332828190.4899289211399650.3822099388219470.7630246954812710.6435386244243860.3164109132152150.1638916499818840.2060728324409850.5974059112537790.5018207699638290.0576707668758970.1880592210266150.420826212683424
View
BIN spec/data/generated/randomBinary1.bin
Binary file not shown.
View
BIN spec/data/generated/randomBinary2.bin
Binary file not shown.
View
1 spec/data/generated/short.txt
@@ -1 +0,0 @@
-ABCDEF
View
BIN spec/data/generated/test1.zip
Binary file not shown.
View
BIN spec/data/generated/zipWithDir.zip
Binary file not shown.
View
7 spec/data/notzippedruby.rb
@@ -1,7 +0,0 @@
-#!/usr/bin/env ruby
-
-class NotZippedRuby
- def returnTrue
- true
- end
-end
View
BIN spec/data/rubycode.zip
Binary file not shown.
View
BIN spec/data/rubycode2.zip
Binary file not shown.
View
BIN spec/data/testDirectory.bin
Binary file not shown.
View
BIN spec/data/zipWithDirs.zip
Binary file not shown.
View
157 spec/gentestfiles.rb
@@ -1,157 +0,0 @@
-#!/usr/bin/env ruby
-
-$VERBOSE = true
-
-class TestFiles
- RANDOM_ASCII_FILE1 = "data/generated/randomAscii1.txt"
- RANDOM_ASCII_FILE2 = "data/generated/randomAscii2.txt"
- RANDOM_ASCII_FILE3 = "data/generated/randomAscii3.txt"
- RANDOM_BINARY_FILE1 = "data/generated/randomBinary1.bin"
- RANDOM_BINARY_FILE2 = "data/generated/randomBinary2.bin"
-
- EMPTY_TEST_DIR = "data/generated/emptytestdir"
-
- ASCII_TEST_FILES = [ RANDOM_ASCII_FILE1, RANDOM_ASCII_FILE2, RANDOM_ASCII_FILE3 ]
- BINARY_TEST_FILES = [ RANDOM_BINARY_FILE1, RANDOM_BINARY_FILE2 ]
- TEST_DIRECTORIES = [ EMPTY_TEST_DIR ]
- TEST_FILES = [ ASCII_TEST_FILES, BINARY_TEST_FILES, EMPTY_TEST_DIR ].flatten!
-
- def TestFiles.create_test_files(recreate)
- if (recreate ||
- ! (TEST_FILES.inject(true) { |accum, element| accum && File.exists?(element) }))
-
- Dir.mkdir "data/generated" rescue Errno::EEXIST
-
- ASCII_TEST_FILES.each_with_index {
- |filename, index|
- create_random_ascii(filename, 1E4 * (index+1))
- }
-
- BINARY_TEST_FILES.each_with_index {
- |filename, index|
- create_random_binary(filename, 1E4 * (index+1))
- }
-
- ensure_dir(EMPTY_TEST_DIR)
- end
- end
-
- private
- def TestFiles.create_random_ascii(filename, size)
- File.open(filename, "wb") {
- |file|
- while (file.tell < size)
- file << rand
- end
- }
- end
-
- def TestFiles.create_random_binary(filename, size)
- File.open(filename, "wb") {
- |file|
- while (file.tell < size)
- file << [rand].pack("V")
- end
- }
- end
-
- def TestFiles.ensure_dir(name)
- if File.exists?(name)
- return if File.stat(name).directory?
- File.delete(name)
- end
- Dir.mkdir(name)
- end
-
-end
-
-
-
-# For representation and creation of
-# test data
-class TestZipFile
- attr_accessor :zip_name, :entry_names, :comment
-
- def initialize(zip_name, entry_names, comment = "")
- @zip_name=zip_name
- @entry_names=entry_names
- @comment = comment
- end
-
- def TestZipFile.create_test_zips(recreate)
- files = Dir.entries("data/generated")
- if (recreate ||
- ! (files.index(File.basename(TEST_ZIP1.zip_name)) &&
- files.index(File.basename(TEST_ZIP2.zip_name)) &&
- files.index(File.basename(TEST_ZIP3.zip_name)) &&
- files.index(File.basename(TEST_ZIP4.zip_name)) &&
- files.index("empty.txt") &&
- files.index("empty_chmod640.txt") &&
- files.index("short.txt") &&
- files.index("longAscii.txt") &&
- files.index("longBinary.bin") ))
- raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless
- system("zip #{TEST_ZIP1.zip_name} data/file2.txt")
- raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" unless
- system("zip #{TEST_ZIP1.zip_name} -d data/file2.txt")
-
- File.open("data/generated/empty.txt", "w") {}
- File.open("data/generated/empty_chmod640.txt", "w") { |f| f.chmod(0640) }
-
- File.open("data/generated/short.txt", "w") { |file| file << "ABCDEF" }
- ziptestTxt=""
- File.open("data/file2.txt") { |file| ziptestTxt=file.read }
- File.open("data/generated/longAscii.txt", "w") {
- |file|
- while (file.tell < 1E5)
- file << ziptestTxt
- end
- }
-
- testBinaryPattern=""
- File.open("data/generated/empty.zip") { |file| testBinaryPattern=file.read }
- testBinaryPattern *= 4
-
- File.open("data/generated/longBinary.bin", "wb") {
- |file|
- while (file.tell < 3E5)
- file << testBinaryPattern << rand << "\0"
- end
- }
- raise "failed to create test zip '#{TEST_ZIP2.zip_name}'" unless
- system("zip #{TEST_ZIP2.zip_name} #{TEST_ZIP2.entry_names.join(' ')}")
-
- # without bash system interprets everything after echo as parameters to
- # echo including | zip -z ...
- raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless
- system("bash -c \"echo #{TEST_ZIP2.comment} | zip -z #{TEST_ZIP2.zip_name}\"")
-
- raise "failed to create test zip '#{TEST_ZIP3.zip_name}'" unless
- system("zip #{TEST_ZIP3.zip_name} #{TEST_ZIP3.entry_names.join(' ')}")
-
- raise "failed to create test zip '#{TEST_ZIP4.zip_name}'" unless
- system("zip #{TEST_ZIP4.zip_name} #{TEST_ZIP4.entry_names.join(' ')}")
- end
- rescue
- raise $!.to_s +
- "\n\nziptest.rb requires the Info-ZIP program 'zip' in the path\n" +
- "to create test data. If you don't have it you can download\n" +
- "the necessary test files at http://sf.net/projects/rubyzip."
- end
-
- TEST_ZIP1 = TestZipFile.new("data/generated/empty.zip", [])
- TEST_ZIP2 = TestZipFile.new("data/generated/5entry.zip", %w{ data/generated/longAscii.txt data/generated/empty.txt data/generated/empty_chmod640.txt data/generated/short.txt data/generated/longBinary.bin},
- "my zip comment")
- TEST_ZIP3 = TestZipFile.new("data/generated/test1.zip", %w{ data/file1.txt })
- TEST_ZIP4 = TestZipFile.new("data/generated/zipWithDir.zip", [ "data/file1.txt",
- TestFiles::EMPTY_TEST_DIR])
-end
-
-
-END {
- TestFiles::create_test_files(ARGV.index("recreate") != nil ||
- ARGV.index("recreateonly") != nil)
- TestZipFile::create_test_zips(ARGV.index("recreate") != nil ||
- ARGV.index("recreateonly") != nil)
- exit if ARGV.index("recreateonly") != nil
-}
View
BIN spec/localEntryHeader.bin
Binary file not shown.
View
45 spec/spec_helper.rb
@@ -1,45 +0,0 @@
-require 'rspec'
-
-require 'gentestfiles'
-require 'zip/zip'
-
-Dir.chdir(File.dirname(__FILE__))
-
-module IOizeString
- attr_reader :tell
-
- def read(count = nil)
- @tell ||= 0
- count = size unless count
- retVal = slice(@tell, count)
- @tell += count
- return retVal
- end
-
- def seek(index, offset)
- @tell ||= 0
- case offset
- when IO::SEEK_END
- newPos = size + index
- when IO::SEEK_SET
- newPos = index
- when IO::SEEK_CUR
- newPos = @tell + index
- else
- raise "Error in test method IOizeString::seek"
- end
- if (newPos < 0 || newPos >= size)
- raise Errno::EINVAL
- else
- @tell=newPos
- end
- end
-
- def reset
- @tell = 0
- end
-end
-
-Rspec.configure do |c|
- include Zip
-end
View
97 spec/zip_entry_spec.rb
@@ -1,97 +0,0 @@
-require 'spec_helper'
-
-describe ZipEntry do
- describe "read local entry HeaderOfFirstTestZipEntry" do
- before do
- @file = File.open(TestZipFile::TEST_ZIP3.zip_name, "rb")
- @entry = ZipEntry.read_local_entry(@file)
- end
-
- it "should set compression method to deflated" do
- @entry.compression_method.should == ZipEntry::DEFLATED
- end
-
- it "should set entry name correctly" do
- @entry.name.should == TestZipFile::TEST_ZIP3.entry_names[0]
- end
-
- it "should set entry size correctly" do
- File.size(TestZipFile::TEST_ZIP3.entry_names[0]).should == @entry.size
- end
-
- it "should not be a directory" do
- @entry.is_directory.should be_false
- end
- end
-
- describe "read dateTime" do
- before do
- @file = File.open("data/rubycode.zip","rb")
- @entry = ZipEntry.read_local_entry(@file)
- end
-
- it "should set the entry name" do
- @entry.name.should == "zippedruby1.rb"
- end
-
- it "should set the time" do
- @entry.time.should == Time.at(1019261638)
- end
- end
-
- it "should read local entry from non zipfile" do
- @file = File.open("data/file2.txt")
- ZipEntry.read_local_entry(@file).should be_nil
- end
-
- it "should throw ZipError reading from truncated zip" do
- 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 = ZipEntry.new
- proc { entry.read_local_entry(zipFragment) }.should raise_error ZipError
- end
-
- it "should write entry" do
- entry = ZipEntry.new("file.zip", "entryName", "my little comment",
- "thisIsSomeExtraInformation", 100, 987654,
- ZipEntry::DEFLATED, 400)
- write_to_file("localEntryHeader.bin", "centralEntryHeader.bin", entry)
- entryReadLocal, entryReadCentral = read_from_file("localEntryHeader.bin", "centralEntryHeader.bin")
- compare_local_entry_headers(entry, entryReadLocal)
- compare_c_dir_entry_headers(entry, entryReadCentral)
- end
-
- private
- def compare_local_entry_headers(entry1, entry2)
- entry1.compressed_size.should == entry2.compressed_size
- entry1.crc.should == entry2.crc
- entry1.extra.should == entry2.extra
- entry1.compression_method.should == entry2.compression_method
- entry1.name.should == entry2.name
- entry1.size.should == entry2.size
- entry1.localHeaderOffset.should == entry2.localHeaderOffset
- end
-
- def compare_c_dir_entry_headers(entry1, entry2)
- compare_local_entry_headers(entry1, entry2)
- entry1.comment.should == entry2.comment
- end
-
- def write_to_file(localFileName, centralFileName, entry)
- File.open(localFileName, "wb") { |f| entry.write_local_entry(f) }
- File.open(centralFileName, "wb") { |f| entry.write_c_dir_entry(f) }
- end
-
- def read_from_file(localFileName, centralFileName)
- localEntry = nil
- cdirEntry = nil
- File.open(localFileName, "rb") { |f| localEntry = ZipEntry.read_local_entry(f) }
- File.open(centralFileName, "rb") { |f| cdirEntry = ZipEntry.read_c_dir_entry(f) }
- return [localEntry, cdirEntry]
- end
-end
-
-# Copyright (C) 2002-2005 Thomas Sondergaard
-# rubyzip is free software; you can redistribute it and/or
-# modify it under the terms of the ruby license.
View
9 test/alltests.rb
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+
+$VERBOSE = true
+
+require 'stdrubyexttest'
+require 'ioextrastest'
+require 'ziptest'
+require 'zipfilesystemtest'
+require 'ziprequiretest'
View
87 test/ziptest.rb
@@ -176,6 +176,93 @@ def reset
end
end
+class ZipLocalEntryTest < Test::Unit::TestCase
+ def test_read_local_entryHeaderOfFirstTestZipEntry
+ File.open(TestZipFile::TEST_ZIP3.zip_name, "rb") {
+ |file|
+ entry = ZipEntry.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(ZipEntry::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.is_directory)
+ }
+ end
+
+ def test_readDateTime
+ File.open("data/rubycode.zip", "rb") {
+ |file|
+ entry = ZipEntry.read_local_entry(file)
+ assert_equal("zippedruby1.rb", entry.name)
+ assert_equal(Time.at(1019261638), entry.time)
+ }
+ end
+
+ def test_read_local_entryFromNonZipFile
+ File.open("data/file2.txt") {
+ |file|
+ assert_equal(nil, ZipEntry.read_local_entry(file))
+ }
+ end
+
+ 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 = ZipEntry.new
+ entry.read_local_entry(zipFragment)
+ fail "ZipError expected"
+ rescue ZipError
+ end
+
+ def test_writeEntry
+ entry = ZipEntry.new("file.zip", "entryName", "my little comment",
+ "thisIsSomeExtraInformation", 100, 987654,
+ ZipEntry::DEFLATED, 400)
+ write_to_file("localEntryHeader.bin", "centralEntryHeader.bin", entry)
+ entryReadLocal, entryReadCentral = read_from_file("localEntryHeader.bin", "centralEntryHeader.bin")
+ compare_local_entry_headers(entry, entryReadLocal)
+ compare_c_dir_entry_headers(entry, entryReadCentral)
+ end
+
+ private
+ def compare_local_entry_headers(entry1, entry2)
+ assert_equal(entry1.compressed_size , entry2.compressed_size)
+ assert_equal(entry1.crc , entry2.crc)
+ assert_equal(entry1.extra , entry2.extra)
+ assert_equal(entry1.compression_method, entry2.compression_method)
+ assert_equal(entry1.name , entry2.name)
+ assert_equal(entry1.size , entry2.size)
+ assert_equal(entry1.localHeaderOffset, entry2.localHeaderOffset)
+ end
+
+ def compare_c_dir_entry_headers(entry1, entry2)
+ compare_local_entry_headers(entry1, entry2)
+ assert_equal(entry1.comment, entry2.comment)
+ end
+
+ def write_to_file(localFileName, centralFileName, entry)
+ File.open(localFileName, "wb") { |f| entry.write_local_entry(f) }
+ File.open(centralFileName, "wb") { |f| entry.write_c_dir_entry(f) }
+ end
+
+ def read_from_file(localFileName, centralFileName)
+ localEntry = nil
+ cdirEntry = nil
+ File.open(localFileName, "rb") { |f| localEntry = ZipEntry.read_local_entry(f) }
+ File.open(centralFileName, "rb") { |f| cdirEntry = ZipEntry.read_c_dir_entry(f) }
+ return [localEntry, cdirEntry]
+ end
+end
+
+
module DecompressorTests
# expects @refText, @refLines and @decompressor

0 comments on commit 8f64fe1

Please sign in to comment.
Something went wrong with that request. Please try again.