Class: TestZipFile
- Inherits:
-
Object
- Object
- TestZipFile
- Defined in:
- lib/hotplate/gems/rubyzip-1.1.7/test/gentestfiles.rb
Overview
For representation and creation of test data
Constant Summary collapse
- TEST_ZIP1 =
TestZipFile.new("test/data/generated/empty.zip", [])
- TEST_ZIP2 =
TestZipFile.new("test/data/generated/5entry.zip", %w{ test/data/generated/longAscii.txt test/data/generated/empty.txt test/data/generated/empty_chmod640.txt test/data/generated/short.txt test/data/generated/longBinary.bin}, "my zip comment")
- TEST_ZIP3 =
TestZipFile.new("test/data/generated/test1.zip", %w{ test/data/file1.txt })
- TEST_ZIP4 =
TestZipFile.new("test/data/generated/zipWithDir.zip", ["test/data/file1.txt", TestFiles::EMPTY_TEST_DIR])
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#entry_names ⇒ Object
Returns the value of attribute entry_names.
-
#zip_name ⇒ Object
Returns the value of attribute zip_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(zip_name, entry_names, comment = "") ⇒ TestZipFile
constructor
A new instance of TestZipFile.
Constructor Details
#initialize(zip_name, entry_names, comment = "") ⇒ TestZipFile
Returns a new instance of TestZipFile.
69 70 71 72 73 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/gentestfiles.rb', line 69 def initialize(zip_name, entry_names, comment = "") @zip_name=zip_name @entry_names=entry_names @comment = comment end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
67 68 69 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/gentestfiles.rb', line 67 def comment @comment end |
#entry_names ⇒ Object
Returns the value of attribute entry_names.
67 68 69 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/gentestfiles.rb', line 67 def entry_names @entry_names end |
#zip_name ⇒ Object
Returns the value of attribute zip_name.
67 68 69 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/gentestfiles.rb', line 67 def zip_name @zip_name end |
Class Method Details
.create_test_zips ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/gentestfiles.rb', line 75 def TestZipFile.create_test_zips raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} test/data/file2.txt") raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} -d test/data/file2.txt") File.open("test/data/generated/empty.txt", "w") {} File.open("test/data/generated/empty_chmod640.txt", "w") {} ::File.chmod(0640, "test/data/generated/empty_chmod640.txt") File.open("test/data/generated/short.txt", "w") { |file| file << "ABCDEF" } ziptestTxt="" File.open("test/data/file2.txt") { |file| ziptestTxt=file.read } File.open("test/data/generated/longAscii.txt", "w") do |file| while (file.tell < 1E5) file << ziptestTxt end end testBinaryPattern="" File.open("test/data/generated/empty.zip") { |file| testBinaryPattern=file.read } testBinaryPattern *= 4 File.open("test/data/generated/longBinary.bin", "wb") do |file| while (file.tell < 6E5) file << testBinaryPattern << rand << "\0" end end raise "failed to create test zip '#{TEST_ZIP2.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP2.zip_name} #{TEST_ZIP2.entry_names.join(' ')}") if RUBY_PLATFORM =~ /mswin|mingw|cygwin/ raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("echo #{TEST_ZIP2.comment}| /usr/bin/zip -z #{TEST_ZIP2.zip_name}\"") else # 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} | /usr/bin/zip -z #{TEST_ZIP2.zip_name}\"") end raise "failed to create test zip '#{TEST_ZIP3.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP3.zip_name} #{TEST_ZIP3.entry_names.join(' ')}") raise "failed to create test zip '#{TEST_ZIP4.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP4.zip_name} #{TEST_ZIP4.entry_names.join(' ')}") rescue # If there are any Windows developers wanting to use a command line zip.exe # to help create the following files, there's a free one available from # http://stahlworks.com/dev/index.php?tool=zipunzip # that works with the above code 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 |