hotplate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +1 -0
  4. data/bin/toast +2 -0
  5. data/hotplate.gemspec +30 -0
  6. data/lib/hotplate/cli/build.rb +51 -0
  7. data/lib/hotplate/cli/init.rb +64 -0
  8. data/lib/hotplate/cli/main.rb +39 -0
  9. data/lib/hotplate/gems/rubyzip-1.1.7/README.md +271 -0
  10. data/lib/hotplate/gems/rubyzip-1.1.7/Rakefile +19 -0
  11. data/lib/hotplate/gems/rubyzip-1.1.7/TODO +15 -0
  12. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/central_directory.rb +208 -0
  13. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/compressor.rb +10 -0
  14. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/constants.rb +63 -0
  15. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/encryption.rb +11 -0
  16. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/null_encryption.rb +45 -0
  17. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/traditional_encryption.rb +99 -0
  18. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/decompressor.rb +13 -0
  19. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/deflater.rb +32 -0
  20. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/dos_time.rb +49 -0
  21. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/entry.rb +696 -0
  22. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/entry_set.rb +86 -0
  23. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/errors.rb +16 -0
  24. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/generic.rb +43 -0
  25. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb +92 -0
  26. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/old_unix.rb +45 -0
  27. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/universal_time.rb +47 -0
  28. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/unix.rb +38 -0
  29. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/zip64.rb +67 -0
  30. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/zip64_placeholder.rb +16 -0
  31. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field.rb +101 -0
  32. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/file.rb +436 -0
  33. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb +626 -0
  34. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/inflater.rb +66 -0
  35. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/input_stream.rb +164 -0
  36. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras/abstract_input_stream.rb +115 -0
  37. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras/abstract_output_stream.rb +45 -0
  38. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras.rb +38 -0
  39. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_compressor.rb +15 -0
  40. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_decompressor.rb +27 -0
  41. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_input_stream.rb +10 -0
  42. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/output_stream.rb +190 -0
  43. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/pass_thru_compressor.rb +23 -0
  44. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/pass_thru_decompressor.rb +41 -0
  45. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/streamable_directory.rb +15 -0
  46. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/streamable_stream.rb +56 -0
  47. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/version.rb +3 -0
  48. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip.rb +63 -0
  49. data/lib/hotplate/gems/rubyzip-1.1.7/samples/example.rb +91 -0
  50. data/lib/hotplate/gems/rubyzip-1.1.7/samples/example_filesystem.rb +33 -0
  51. data/lib/hotplate/gems/rubyzip-1.1.7/samples/example_recursive.rb +48 -0
  52. data/lib/hotplate/gems/rubyzip-1.1.7/samples/gtkRubyzip.rb +86 -0
  53. data/lib/hotplate/gems/rubyzip-1.1.7/samples/qtzip.rb +101 -0
  54. data/lib/hotplate/gems/rubyzip-1.1.7/samples/write_simple.rb +13 -0
  55. data/lib/hotplate/gems/rubyzip-1.1.7/samples/zipfind.rb +74 -0
  56. data/lib/hotplate/gems/rubyzip-1.1.7/test/basic_zip_file_test.rb +64 -0
  57. data/lib/hotplate/gems/rubyzip-1.1.7/test/central_directory_entry_test.rb +73 -0
  58. data/lib/hotplate/gems/rubyzip-1.1.7/test/central_directory_test.rb +104 -0
  59. data/lib/hotplate/gems/rubyzip-1.1.7/test/crypto/null_encryption_test.rb +53 -0
  60. data/lib/hotplate/gems/rubyzip-1.1.7/test/crypto/traditional_encryption_test.rb +80 -0
  61. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/WarnInvalidDate.zip +0 -0
  62. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file1.txt +46 -0
  63. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file1.txt.deflatedData +0 -0
  64. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file2.txt +1504 -0
  65. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/foo/bar/baz/foo.txt +0 -0
  66. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/foo.txt +0 -0
  67. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/food.txt +0 -0
  68. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest.zip +0 -0
  69. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/mimetype +1 -0
  70. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/notzippedruby.rb +7 -0
  71. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/ntfs.zip +0 -0
  72. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/rubycode.zip +0 -0
  73. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/rubycode2.zip +0 -0
  74. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/testDirectory.bin +0 -0
  75. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zip64-sample.zip +0 -0
  76. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zipWithDirs.zip +0 -0
  77. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zipWithEncryption.zip +0 -0
  78. data/lib/hotplate/gems/rubyzip-1.1.7/test/deflater_test.rb +67 -0
  79. data/lib/hotplate/gems/rubyzip-1.1.7/test/encryption_test.rb +42 -0
  80. data/lib/hotplate/gems/rubyzip-1.1.7/test/entry_set_test.rb +138 -0
  81. data/lib/hotplate/gems/rubyzip-1.1.7/test/entry_test.rb +165 -0
  82. data/lib/hotplate/gems/rubyzip-1.1.7/test/errors_test.rb +36 -0
  83. data/lib/hotplate/gems/rubyzip-1.1.7/test/extra_field_test.rb +78 -0
  84. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_extract_directory_test.rb +56 -0
  85. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_extract_test.rb +90 -0
  86. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_split_test.rb +60 -0
  87. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_test.rb +559 -0
  88. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/dir_iterator_test.rb +62 -0
  89. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/directory_test.rb +131 -0
  90. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_mutating_test.rb +100 -0
  91. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_nonmutating_test.rb +514 -0
  92. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_stat_test.rb +66 -0
  93. data/lib/hotplate/gems/rubyzip-1.1.7/test/gentestfiles.rb +134 -0
  94. data/lib/hotplate/gems/rubyzip-1.1.7/test/inflater_test.rb +14 -0
  95. data/lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb +170 -0
  96. data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/abstract_input_stream_test.rb +103 -0
  97. data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/abstract_output_stream_test.rb +106 -0
  98. data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/fake_io_test.rb +18 -0
  99. data/lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb +156 -0
  100. data/lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb +129 -0
  101. data/lib/hotplate/gems/rubyzip-1.1.7/test/pass_thru_compressor_test.rb +31 -0
  102. data/lib/hotplate/gems/rubyzip-1.1.7/test/pass_thru_decompressor_test.rb +15 -0
  103. data/lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb +92 -0
  104. data/lib/hotplate/gems/rubyzip-1.1.7/test/test_helper.rb +228 -0
  105. data/lib/hotplate/gems/rubyzip-1.1.7/test/unicode_file_names_and_comments_test.rb +52 -0
  106. data/lib/hotplate/gems/rubyzip-1.1.7/test/zip64_full_test.rb +53 -0
  107. data/lib/hotplate/gems/rubyzip-1.1.7/test/zip64_support_test.rb +15 -0
  108. data/lib/hotplate/java/build.gradle +38 -0
  109. data/lib/hotplate/java/gradle/wrapper/gradle-wrapper.jar +0 -0
  110. data/lib/hotplate/java/gradle/wrapper/gradle-wrapper.properties +6 -0
  111. data/lib/hotplate/java/gradlew +164 -0
  112. data/lib/hotplate/java/gradlew.bat +90 -0
  113. data/lib/hotplate/java/template.java +25 -0
  114. data/lib/hotplate/version.rb +3 -0
  115. data/lib/hotplate.rb +2 -0
  116. metadata +186 -0
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $VERBOSE = true
4
+
5
+ class TestFiles
6
+ RANDOM_ASCII_FILE1 = "test/data/generated/randomAscii1.txt"
7
+ RANDOM_ASCII_FILE2 = "test/data/generated/randomAscii2.txt"
8
+ RANDOM_ASCII_FILE3 = "test/data/generated/randomAscii3.txt"
9
+ RANDOM_BINARY_FILE1 = "test/data/generated/randomBinary1.bin"
10
+ RANDOM_BINARY_FILE2 = "test/data/generated/randomBinary2.bin"
11
+
12
+ EMPTY_TEST_DIR = "test/data/generated/emptytestdir"
13
+
14
+ ASCII_TEST_FILES = [RANDOM_ASCII_FILE1, RANDOM_ASCII_FILE2, RANDOM_ASCII_FILE3]
15
+ BINARY_TEST_FILES = [RANDOM_BINARY_FILE1, RANDOM_BINARY_FILE2]
16
+ TEST_DIRECTORIES = [EMPTY_TEST_DIR]
17
+ TEST_FILES = [ASCII_TEST_FILES, BINARY_TEST_FILES, EMPTY_TEST_DIR].flatten!
18
+
19
+ class << self
20
+ def create_test_files
21
+ Dir.mkdir "test/data/generated" unless Dir.exist?('test/data/generated')
22
+
23
+ ASCII_TEST_FILES.each_with_index do |filename, index|
24
+ create_random_ascii(filename, 1E4 * (index+1))
25
+ end
26
+
27
+ BINARY_TEST_FILES.each_with_index do |filename, index|
28
+ create_random_binary(filename, 1E4 * (index+1))
29
+ end
30
+
31
+ ensure_dir(EMPTY_TEST_DIR)
32
+ end
33
+
34
+ private
35
+
36
+ def create_random_ascii(filename, size)
37
+ File.open(filename, "wb") do |file|
38
+ while (file.tell < size)
39
+ file << rand
40
+ end
41
+ end
42
+ end
43
+
44
+ def create_random_binary(filename, size)
45
+ File.open(filename, "wb") do |file|
46
+ while (file.tell < size)
47
+ file << [rand].pack("V")
48
+ end
49
+ end
50
+ end
51
+
52
+ def ensure_dir(name)
53
+ if File.exist?(name)
54
+ return if File.stat(name).directory?
55
+ File.delete(name)
56
+ end
57
+ Dir.mkdir(name)
58
+ end
59
+
60
+ end
61
+ end
62
+
63
+
64
+ # For representation and creation of
65
+ # test data
66
+ class TestZipFile
67
+ attr_accessor :zip_name, :entry_names, :comment
68
+
69
+ def initialize(zip_name, entry_names, comment = "")
70
+ @zip_name=zip_name
71
+ @entry_names=entry_names
72
+ @comment = comment
73
+ end
74
+
75
+ def TestZipFile.create_test_zips
76
+ raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} test/data/file2.txt")
77
+ raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} -d test/data/file2.txt")
78
+
79
+ File.open("test/data/generated/empty.txt", "w") {}
80
+ File.open("test/data/generated/empty_chmod640.txt", "w") {}
81
+ ::File.chmod(0640, "test/data/generated/empty_chmod640.txt")
82
+
83
+ File.open("test/data/generated/short.txt", "w") { |file| file << "ABCDEF" }
84
+ ziptestTxt=""
85
+ File.open("test/data/file2.txt") { |file| ziptestTxt=file.read }
86
+ File.open("test/data/generated/longAscii.txt", "w") do |file|
87
+ while (file.tell < 1E5)
88
+ file << ziptestTxt
89
+ end
90
+ end
91
+
92
+ testBinaryPattern=""
93
+ File.open("test/data/generated/empty.zip") { |file| testBinaryPattern=file.read }
94
+ testBinaryPattern *= 4
95
+
96
+ File.open("test/data/generated/longBinary.bin", "wb") do |file|
97
+ while (file.tell < 6E5)
98
+ file << testBinaryPattern << rand << "\0"
99
+ end
100
+ end
101
+
102
+ raise "failed to create test zip '#{TEST_ZIP2.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP2.zip_name} #{TEST_ZIP2.entry_names.join(' ')}")
103
+
104
+ if RUBY_PLATFORM =~ /mswin|mingw|cygwin/
105
+ 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}\"")
106
+ else
107
+ # without bash system interprets everything after echo as parameters to
108
+ # echo including | zip -z ...
109
+ 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}\"")
110
+ end
111
+
112
+ raise "failed to create test zip '#{TEST_ZIP3.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP3.zip_name} #{TEST_ZIP3.entry_names.join(' ')}")
113
+
114
+ raise "failed to create test zip '#{TEST_ZIP4.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP4.zip_name} #{TEST_ZIP4.entry_names.join(' ')}")
115
+ rescue
116
+ # If there are any Windows developers wanting to use a command line zip.exe
117
+ # to help create the following files, there's a free one available from
118
+ # http://stahlworks.com/dev/index.php?tool=zipunzip
119
+ # that works with the above code
120
+ raise $!.to_s +
121
+ "\n\nziptest.rb requires the Info-ZIP program 'zip' in the path\n" +
122
+ "to create test data. If you don't have it you can download\n" +
123
+ "the necessary test files at http://sf.net/projects/rubyzip."
124
+ end
125
+
126
+ TEST_ZIP1 = TestZipFile.new("test/data/generated/empty.zip", [])
127
+ 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},
128
+ "my zip comment")
129
+ TEST_ZIP3 = TestZipFile.new("test/data/generated/test1.zip", %w{ test/data/file1.txt })
130
+ TEST_ZIP4 = TestZipFile.new("test/data/generated/zipWithDir.zip", ["test/data/file1.txt",
131
+ TestFiles::EMPTY_TEST_DIR])
132
+ end
133
+
134
+
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+ class InflaterTest < MiniTest::Test
3
+ include DecompressorTests
4
+
5
+ def setup
6
+ super
7
+ @file = File.new("test/data/file1.txt.deflatedData", "rb")
8
+ @decompressor = ::Zip::Inflater.new(@file)
9
+ end
10
+
11
+ def teardown
12
+ @file.close
13
+ end
14
+ end
@@ -0,0 +1,170 @@
1
+ require 'test_helper'
2
+
3
+ class ZipInputStreamTest < MiniTest::Test
4
+ include AssertEntry
5
+
6
+ def test_new
7
+ zis = ::Zip::InputStream.new(TestZipFile::TEST_ZIP2.zip_name)
8
+ assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
9
+ assert_equal(true, zis.eof?)
10
+ zis.close
11
+ end
12
+
13
+ def test_openWithBlock
14
+ ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
15
+ |zis|
16
+ assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
17
+ assert_equal(true, zis.eof?)
18
+ }
19
+ end
20
+
21
+ def test_openWithoutBlock
22
+ zis = ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, "rb"))
23
+ assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
24
+ end
25
+
26
+ def test_openBufferWithBlock
27
+ ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, "rb")) do |zis|
28
+ assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
29
+ assert_equal(true, zis.eof?)
30
+ end
31
+ end
32
+
33
+ def test_open_string_io_without_block
34
+ string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
35
+ zis = ::Zip::InputStream.open(string_io)
36
+ assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
37
+ end
38
+
39
+ def test_open_string_io_with_block
40
+ string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
41
+ ::Zip::InputStream.open(string_io) do |zis|
42
+ assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
43
+ assert_equal(true, zis.eof?)
44
+ end
45
+ end
46
+
47
+ def test_openBufferWithoutBlock
48
+ zis = ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
49
+ assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
50
+ end
51
+
52
+ def test_incompleteReads
53
+ ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
54
+ |zis|
55
+ entry = zis.get_next_entry # longAscii.txt
56
+ assert_equal(false, zis.eof?)
57
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
58
+ assert zis.gets.length > 0
59
+ assert_equal(false, zis.eof?)
60
+ entry = zis.get_next_entry # empty.txt
61
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
62
+ assert_equal(0, entry.size)
63
+ assert_equal(nil, zis.gets)
64
+ assert_equal(true, zis.eof?)
65
+ entry = zis.get_next_entry # empty_chmod640.txt
66
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
67
+ assert_equal(0, entry.size)
68
+ assert_equal(nil, zis.gets)
69
+ assert_equal(true, zis.eof?)
70
+ entry = zis.get_next_entry # short.txt
71
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
72
+ assert zis.gets.length > 0
73
+ entry = zis.get_next_entry # longBinary.bin
74
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
75
+ assert zis.gets.length > 0
76
+ }
77
+ end
78
+
79
+ def test_incomplete_reads_from_string_io
80
+ string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
81
+ ::Zip::InputStream.open(string_io) do |zis|
82
+ entry = zis.get_next_entry # longAscii.txt
83
+ assert_equal(false, zis.eof?)
84
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
85
+ assert zis.gets.length > 0
86
+ assert_equal(false, zis.eof?)
87
+ entry = zis.get_next_entry # empty.txt
88
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
89
+ assert_equal(0, entry.size)
90
+ assert_equal(nil, zis.gets)
91
+ assert_equal(true, zis.eof?)
92
+ entry = zis.get_next_entry # empty_chmod640.txt
93
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
94
+ assert_equal(0, entry.size)
95
+ assert_equal(nil, zis.gets)
96
+ assert_equal(true, zis.eof?)
97
+ entry = zis.get_next_entry # short.txt
98
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
99
+ assert zis.gets.length > 0
100
+ entry = zis.get_next_entry # longBinary.bin
101
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
102
+ assert zis.gets.length > 0
103
+ end
104
+ end
105
+
106
+ def test_read_with_number_of_bytes_returns_nil_at_eof
107
+ ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
108
+ entry = zis.get_next_entry # longAscii.txt
109
+ zis.read(entry.size)
110
+ assert_equal(true, zis.eof?)
111
+ assert_nil(zis.read(1))
112
+ assert_nil(zis.read(1))
113
+ end
114
+ end
115
+
116
+ def test_rewind
117
+ ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
118
+ |zis|
119
+ e = zis.get_next_entry
120
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], e.name)
121
+
122
+ # Do a little reading
123
+ buf = ""
124
+ buf << zis.read(100)
125
+ assert_equal(100, zis.pos)
126
+ buf << (zis.gets || "")
127
+ buf << (zis.gets || "")
128
+ assert_equal(false, zis.eof?)
129
+
130
+ zis.rewind
131
+
132
+ buf2 = ""
133
+ buf2 << zis.read(100)
134
+ buf2 << (zis.gets || "")
135
+ buf2 << (zis.gets || "")
136
+
137
+ assert_equal(buf, buf2)
138
+
139
+ zis.rewind
140
+ assert_equal(false, zis.eof?)
141
+ assert_equal(0, zis.pos)
142
+
143
+ assert_entry(e.name, zis, e.name)
144
+ }
145
+ end
146
+
147
+ def test_mix_read_and_gets
148
+ ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
149
+ |zis|
150
+ zis.get_next_entry
151
+ assert_equal("#!/usr/bin/env ruby", zis.gets.chomp)
152
+ assert_equal(false, zis.eof?)
153
+ assert_equal("", zis.gets.chomp)
154
+ assert_equal(false, zis.eof?)
155
+ assert_equal("$VERBOSE =", zis.read(10))
156
+ assert_equal(false, zis.eof?)
157
+ }
158
+ end
159
+
160
+ def test_ungetc
161
+ ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
162
+ zis.get_next_entry
163
+ first_line = zis.gets.chomp
164
+ first_line.reverse.bytes.each { |b| zis.ungetc(b) }
165
+ assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
166
+ assert_equal("$VERBOSE =", zis.read(10))
167
+ end
168
+ end
169
+
170
+ end
@@ -0,0 +1,103 @@
1
+ require 'test_helper'
2
+ require 'zip/ioextras'
3
+
4
+ class AbstractInputStreamTest < MiniTest::Test
5
+ # AbstractInputStream subclass that provides a read method
6
+
7
+ TEST_LINES = ["Hello world#{$/}",
8
+ "this is the second line#{$/}",
9
+ "this is the last line"]
10
+ TEST_STRING = TEST_LINES.join
11
+ class TestAbstractInputStream
12
+ include ::Zip::IOExtras::AbstractInputStream
13
+
14
+ def initialize(aString)
15
+ super()
16
+ @contents = aString
17
+ @readPointer = 0
18
+ end
19
+
20
+ def sysread(charsToRead, buf = nil)
21
+ retVal=@contents[@readPointer, charsToRead]
22
+ @readPointer+=charsToRead
23
+ return retVal
24
+ end
25
+
26
+ def produce_input
27
+ sysread(100)
28
+ end
29
+
30
+ def input_finished?
31
+ @contents[@readPointer] == nil
32
+ end
33
+ end
34
+
35
+ def setup
36
+ @io = TestAbstractInputStream.new(TEST_STRING)
37
+ end
38
+
39
+ def test_gets
40
+ assert_equal(TEST_LINES[0], @io.gets)
41
+ assert_equal(1, @io.lineno)
42
+ assert_equal(TEST_LINES[0].length, @io.pos)
43
+ assert_equal(TEST_LINES[1], @io.gets)
44
+ assert_equal(2, @io.lineno)
45
+ assert_equal(TEST_LINES[2], @io.gets)
46
+ assert_equal(3, @io.lineno)
47
+ assert_equal(nil, @io.gets)
48
+ assert_equal(4, @io.lineno)
49
+ end
50
+
51
+ def test_getsMultiCharSeperator
52
+ assert_equal("Hell", @io.gets("ll"))
53
+ assert_equal("o world#{$/}this is the second l", @io.gets("d l"))
54
+ end
55
+
56
+ LONG_LINES = [
57
+ 'x'*48 + "\r\n",
58
+ 'y'*49 + "\r\n",
59
+ 'rest',
60
+ ]
61
+
62
+ def test_getsMulitCharSeperator_split
63
+ io = TestAbstractInputStream.new(LONG_LINES.join)
64
+ assert_equal(LONG_LINES[0], io.gets("\r\n"))
65
+ assert_equal(LONG_LINES[1], io.gets("\r\n"))
66
+ assert_equal(LONG_LINES[2], io.gets("\r\n"))
67
+ end
68
+
69
+ def test_getsWithSepAndIndex
70
+ io = TestAbstractInputStream.new(LONG_LINES.join)
71
+ assert_equal('x', io.gets("\r\n", 1))
72
+ assert_equal('x'*47 + "\r", io.gets("\r\n", 48))
73
+ assert_equal("\n", io.gets(nil, 1))
74
+ assert_equal('yy', io.gets(nil, 2))
75
+ end
76
+
77
+ def test_getsWithIndex
78
+ assert_equal(TEST_LINES[0], @io.gets(100))
79
+ assert_equal('this', @io.gets(4))
80
+ end
81
+
82
+ def test_each_line
83
+ lineNumber=0
84
+ @io.each_line {
85
+ |line|
86
+ assert_equal(TEST_LINES[lineNumber], line)
87
+ lineNumber+=1
88
+ }
89
+ end
90
+
91
+ def test_readlines
92
+ assert_equal(TEST_LINES, @io.readlines)
93
+ end
94
+
95
+ def test_readline
96
+ test_gets
97
+ begin
98
+ @io.readline
99
+ fail "EOFError expected"
100
+ rescue EOFError
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,106 @@
1
+ require 'test_helper'
2
+ require 'zip/ioextras'
3
+
4
+ class AbstractOutputStreamTest < MiniTest::Test
5
+ class TestOutputStream
6
+ include ::Zip::IOExtras::AbstractOutputStream
7
+
8
+ attr_accessor :buffer
9
+
10
+ def initialize
11
+ @buffer = ""
12
+ end
13
+
14
+ def << (data)
15
+ @buffer << data
16
+ self
17
+ end
18
+ end
19
+
20
+ def setup
21
+ @output_stream = TestOutputStream.new
22
+
23
+ @origCommaSep = $,
24
+ @origOutputSep = $\
25
+ end
26
+
27
+ def teardown
28
+ $, = @origCommaSep
29
+ $\ = @origOutputSep
30
+ end
31
+
32
+ def test_write
33
+ count = @output_stream.write("a little string")
34
+ assert_equal("a little string", @output_stream.buffer)
35
+ assert_equal("a little string".length, count)
36
+
37
+ count = @output_stream.write(". a little more")
38
+ assert_equal("a little string. a little more", @output_stream.buffer)
39
+ assert_equal(". a little more".length, count)
40
+ end
41
+
42
+ def test_print
43
+ $\ = nil # record separator set to nil
44
+ @output_stream.print("hello")
45
+ assert_equal("hello", @output_stream.buffer)
46
+
47
+ @output_stream.print(" world.")
48
+ assert_equal("hello world.", @output_stream.buffer)
49
+
50
+ @output_stream.print(" You ok ", "out ", "there?")
51
+ assert_equal("hello world. You ok out there?", @output_stream.buffer)
52
+
53
+ $\ = "\n"
54
+ @output_stream.print
55
+ assert_equal("hello world. You ok out there?\n", @output_stream.buffer)
56
+
57
+ @output_stream.print("I sure hope so!")
58
+ assert_equal("hello world. You ok out there?\nI sure hope so!\n", @output_stream.buffer)
59
+
60
+ $, = "X"
61
+ @output_stream.buffer = ""
62
+ @output_stream.print("monkey", "duck", "zebra")
63
+ assert_equal("monkeyXduckXzebra\n", @output_stream.buffer)
64
+
65
+ $\ = nil
66
+ @output_stream.buffer = ""
67
+ @output_stream.print(20)
68
+ assert_equal("20", @output_stream.buffer)
69
+ end
70
+
71
+ def test_printf
72
+ @output_stream.printf("%d %04x", 123, 123)
73
+ assert_equal("123 007b", @output_stream.buffer)
74
+ end
75
+
76
+ def test_putc
77
+ @output_stream.putc("A")
78
+ assert_equal("A", @output_stream.buffer)
79
+ @output_stream.putc(65)
80
+ assert_equal("AA", @output_stream.buffer)
81
+ end
82
+
83
+ def test_puts
84
+ @output_stream.puts
85
+ assert_equal("\n", @output_stream.buffer)
86
+
87
+ @output_stream.puts("hello", "world")
88
+ assert_equal("\nhello\nworld\n", @output_stream.buffer)
89
+
90
+ @output_stream.buffer = ""
91
+ @output_stream.puts("hello\n", "world\n")
92
+ assert_equal("hello\nworld\n", @output_stream.buffer)
93
+
94
+ @output_stream.buffer = ""
95
+ @output_stream.puts(["hello\n", "world\n"])
96
+ assert_equal("hello\nworld\n", @output_stream.buffer)
97
+
98
+ @output_stream.buffer = ""
99
+ @output_stream.puts(["hello\n", "world\n"], "bingo")
100
+ assert_equal("hello\nworld\nbingo\n", @output_stream.buffer)
101
+
102
+ @output_stream.buffer = ""
103
+ @output_stream.puts(16, 20, 50, "hello")
104
+ assert_equal("16\n20\n50\nhello\n", @output_stream.buffer)
105
+ end
106
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+ require 'zip/ioextras'
3
+
4
+ class FakeIOTest < MiniTest::Test
5
+ class FakeIOUsingClass
6
+ include ::Zip::IOExtras::FakeIO
7
+ end
8
+
9
+ def test_kind_of?
10
+ obj = FakeIOUsingClass.new
11
+
12
+ assert(obj.kind_of?(Object))
13
+ assert(obj.kind_of?(FakeIOUsingClass))
14
+ assert(obj.kind_of?(IO))
15
+ assert(!obj.kind_of?(Fixnum))
16
+ assert(!obj.kind_of?(String))
17
+ end
18
+ end