pr-zlib 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +2 -0
- data/MANIFEST +18 -0
- data/README +42 -0
- data/Rakefile +88 -0
- data/bin/minizip.rb +173 -0
- data/examples/example_rbzlib.rb +385 -0
- data/lib/pr/rbzlib.rb +5067 -0
- data/lib/pr/zlib.rb +1550 -0
- data/pr-zlib.gemspec +28 -0
- data/test/test_rbzlib.rb +136 -0
- data/test/test_rbzlib_bytef.rb +79 -0
- data/test/test_rbzlib_posf.rb +59 -0
- data/test/test_zlib.rb +163 -0
- data/test/test_zlib_deflate.rb +58 -0
- data/test/test_zlib_gzip_file.rb +96 -0
- data/test/test_zlib_gzip_reader.rb +184 -0
- data/test/test_zlib_gzip_writer.rb +188 -0
- data/test/test_zlib_inflate.rb +58 -0
- data/test/test_zlib_zstream.rb +149 -0
- metadata +94 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_zlib_deflate.rb
|
3
|
+
#
|
4
|
+
# Test case for the Zlib::Deflate class.
|
5
|
+
########################################################################
|
6
|
+
require 'rubygems'
|
7
|
+
gem 'test-unit'
|
8
|
+
|
9
|
+
require 'pr/zlib'
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
class TC_Zlib_Deflate < Test::Unit::TestCase
|
13
|
+
def self.startup
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@deflate = Zlib::Deflate.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_deflate_run_singleton_basic
|
21
|
+
assert_respond_to(Zlib::Deflate, :deflate_run)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_deflate_singleton_basic
|
25
|
+
assert_respond_to(Zlib::Deflate, :deflate)
|
26
|
+
end
|
27
|
+
|
28
|
+
#def test_initialize_copy_basic
|
29
|
+
#assert_respond_to(@deflate, :initialize_copy)
|
30
|
+
#end
|
31
|
+
|
32
|
+
def test_deflate_basic
|
33
|
+
assert_respond_to(@deflate, :deflate)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_append_basic
|
37
|
+
assert_respond_to(@deflate, :<<)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_flush_basic
|
41
|
+
assert_respond_to(@deflate, :flush)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_params_basic
|
45
|
+
assert_respond_to(@deflate, :params)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_set_dictionary_basic
|
49
|
+
assert_respond_to(@deflate, :set_dictionary)
|
50
|
+
end
|
51
|
+
|
52
|
+
def teardown
|
53
|
+
@deflate = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.shutdown
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_zlib_gzip_file.rb
|
3
|
+
#
|
4
|
+
# Test case for the Zlib::GzipFile base class.
|
5
|
+
########################################################################
|
6
|
+
require 'rubygems'
|
7
|
+
gem 'test-unit'
|
8
|
+
|
9
|
+
require 'pr/zlib'
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
class TC_Zlib_GzipFile < Test::Unit::TestCase
|
13
|
+
def self.startup
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@gz_file = Zlib::GzipFile.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_gzip_file_constants
|
21
|
+
assert_equal(Zlib::GzipFile::GZ_MAGIC1, 0x1f)
|
22
|
+
assert_equal(Zlib::GzipFile::GZ_MAGIC2, 0x8b)
|
23
|
+
assert_equal(Zlib::GzipFile::GZ_METHOD_DEFLATE, 8)
|
24
|
+
assert_equal(Zlib::GzipFile::GZ_FLAG_MULTIPART, 0x2)
|
25
|
+
assert_equal(Zlib::GzipFile::GZ_FLAG_EXTRA, 0x4)
|
26
|
+
assert_equal(Zlib::GzipFile::GZ_FLAG_ORIG_NAME, 0x8)
|
27
|
+
assert_equal(Zlib::GzipFile::GZ_FLAG_COMMENT, 0x10)
|
28
|
+
assert_equal(Zlib::GzipFile::GZ_FLAG_ENCRYPT, 0x20)
|
29
|
+
assert_equal(Zlib::GzipFile::GZ_FLAG_UNKNOWN_MASK, 0xc0)
|
30
|
+
assert_equal(Zlib::GzipFile::GZ_EXTRAFLAG_FAST, 0x4)
|
31
|
+
assert_equal(Zlib::GzipFile::GZ_EXTRAFLAG_SLOW, 0x2)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_gzfile_is_finished
|
35
|
+
assert_respond_to(@gz_file, :GZFILE_IS_FINISHED)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_gzfile_close_basic
|
39
|
+
assert_respond_to(@gz_file, :gzfile_close)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_to_io_basic
|
43
|
+
assert_respond_to(@gz_file, :to_io)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_crc_basic
|
47
|
+
assert_respond_to(@gz_file, :crc)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_mtime_basic
|
51
|
+
assert_respond_to(@gz_file, :mtime)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_level_basic
|
55
|
+
assert_respond_to(@gz_file, :level)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_os_code_basic
|
59
|
+
assert_respond_to(@gz_file, :os_code)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_orig_name_basic
|
63
|
+
assert_respond_to(@gz_file, :orig_name)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_comment_basic
|
67
|
+
assert_respond_to(@gz_file, :comment)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_close_basic
|
71
|
+
assert_respond_to(@gz_file, :close)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_finish_basic
|
75
|
+
assert_respond_to(@gz_file, :finish)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_is_closed_basic
|
79
|
+
assert_respond_to(@gz_file, :closed?)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_sync_get_basic
|
83
|
+
assert_respond_to(@gz_file, :sync)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_sync_set_basic
|
87
|
+
assert_respond_to(@gz_file, :sync=)
|
88
|
+
end
|
89
|
+
|
90
|
+
def teardown
|
91
|
+
@gz_file = nil
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.shutdown
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_zlib_gzip_reader.rb
|
3
|
+
#
|
4
|
+
# Tests for the GzipReader class.
|
5
|
+
########################################################################
|
6
|
+
require 'rubygems'
|
7
|
+
gem 'test-unit'
|
8
|
+
|
9
|
+
require 'test/unit'
|
10
|
+
require 'fileutils'
|
11
|
+
require 'pr/zlib'
|
12
|
+
|
13
|
+
class TC_GzipReader < Test::Unit::TestCase
|
14
|
+
def self.startup
|
15
|
+
Dir.chdir('test') if File.basename(Dir.pwd) != 'test'
|
16
|
+
File.open('test.txt', 'wb'){ |fh| fh.puts 'Test file' }
|
17
|
+
system('gzip *.txt')
|
18
|
+
@@gz_file = 'test.txt.gz'
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup
|
22
|
+
@handle = File.open(@@gz_file)
|
23
|
+
@gz_reader = Zlib::GzipReader.new(@handle)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_constructor_expected_errors
|
27
|
+
assert_raise(ArgumentError){ Zlib::GzipReader.new }
|
28
|
+
assert_raise(NoMethodError){ Zlib::GzipReader.new(1) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_lineno_get_basic
|
32
|
+
assert_respond_to(@gz_reader, :lineno)
|
33
|
+
assert_nothing_raised{ @gz_reader.lineno }
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_lineno_get
|
37
|
+
assert_kind_of(Fixnum, @gz_reader.lineno)
|
38
|
+
assert_equal(0, @gz_reader.lineno)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_lineno_set_basic
|
42
|
+
assert_respond_to(@gz_reader, :lineno=)
|
43
|
+
assert_nothing_raised{ @gz_reader.lineno = 0 }
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_lineno_set
|
47
|
+
assert_kind_of(Fixnum, @gz_reader.lineno = 0)
|
48
|
+
assert_equal(0, @gz_reader.lineno = 0)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_eof_basic
|
52
|
+
assert_respond_to(@gz_reader, :eof)
|
53
|
+
assert_nothing_raised{ @gz_reader.eof }
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_pos_basic
|
57
|
+
assert_respond_to(@gz_reader, :pos)
|
58
|
+
assert_nothing_raised{ @gz_reader.pos }
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_pos
|
62
|
+
assert_kind_of(Fixnum, @gz_reader.pos)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_rewind_basic
|
66
|
+
assert_respond_to(@gz_reader, :rewind)
|
67
|
+
assert_nothing_raised{ @gz_reader.rewind }
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_rewind
|
71
|
+
assert_equal(0, @gz_reader.rewind)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_unused_basic
|
75
|
+
assert_respond_to(@gz_reader, :unused)
|
76
|
+
assert_nothing_raised{ @gz_reader.unused }
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_unused
|
80
|
+
assert_nil(@gz_reader.unused)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_read_basic
|
84
|
+
assert_respond_to(@gz_reader, :read)
|
85
|
+
assert_nothing_raised{ @gz_reader.read }
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_read
|
89
|
+
assert_equal("Test file\n", @gz_reader.read)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_read_with_length
|
93
|
+
assert_equal("Test", @gz_reader.read(4))
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_read_expected_errors
|
97
|
+
assert_raise(ArgumentError){ @gz_reader.read(-1) }
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_getc_basic
|
101
|
+
assert_respond_to(@gz_reader, :getc)
|
102
|
+
assert_nothing_raised{ @gz_reader.getc }
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_getc
|
106
|
+
assert_equal(84, @gz_reader.getc)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_readchar_basic
|
110
|
+
assert_respond_to(@gz_reader, :readchar)
|
111
|
+
assert_nothing_raised{ @gz_reader.readchar }
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_readchar
|
115
|
+
assert_equal(84, @gz_reader.readchar)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_each_byte_basic
|
119
|
+
assert_respond_to(@gz_reader, :each_byte)
|
120
|
+
assert_nothing_raised{ @gz_reader.each_byte{} }
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_each_byte
|
124
|
+
assert_nil(@gz_reader.each_byte{})
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_ungetc_basic
|
128
|
+
assert_respond_to(@gz_reader, :ungetc)
|
129
|
+
assert_nothing_raised{ @gz_reader.ungetc(99) }
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_ungetc
|
133
|
+
assert_nil(@gz_reader.ungetc(99))
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_gets_basic
|
137
|
+
assert_respond_to(@gz_reader, :gets)
|
138
|
+
assert_nothing_raised{ @gz_reader.gets }
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_gets
|
142
|
+
assert_equal("Test file\n", @gz_reader.gets)
|
143
|
+
omit('Skipping $_ test')
|
144
|
+
assert_equal("Test file\n", $_)
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_readline_basic
|
148
|
+
assert_respond_to(@gz_reader, :readline)
|
149
|
+
assert_nothing_raised{ @gz_reader.readline }
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_readline
|
153
|
+
assert_equal("Test file\n", @gz_reader.readline)
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_each_basic
|
157
|
+
assert_respond_to(@gz_reader, :each)
|
158
|
+
assert_nothing_raised{ @gz_reader.each{} }
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_each
|
162
|
+
assert_not_nil(@gz_reader.each{})
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_readlines_basic
|
166
|
+
assert_respond_to(@gz_reader, :readlines)
|
167
|
+
assert_nothing_raised{ @gz_reader.readlines }
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_readlines
|
171
|
+
assert_equal(["Test file\n"], @gz_reader.readlines)
|
172
|
+
end
|
173
|
+
|
174
|
+
def teardown
|
175
|
+
@handle.close if @handle && !@handle.closed?
|
176
|
+
@handle = nil
|
177
|
+
@gz_reader = nil
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.shutdown
|
181
|
+
File.delete(@@gz_file) if File.exists?(@@gz_file)
|
182
|
+
@@gz_file = nil
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_zlib_gzip_writer.rb
|
3
|
+
#
|
4
|
+
# Test case for the Zlib::GzipWriter class.
|
5
|
+
########################################################################
|
6
|
+
require 'rubygems'
|
7
|
+
gem 'test-unit'
|
8
|
+
|
9
|
+
require 'pr/zlib'
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
class TC_Zlib_GzipWriter < Test::Unit::TestCase
|
13
|
+
def self.startup
|
14
|
+
@@file = 'gzip_writer_test.gz'
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup
|
18
|
+
@handle = File.new(@@file, 'w')
|
19
|
+
@writer = Zlib::GzipWriter.new(@handle)
|
20
|
+
@time = Time.now
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_constructor
|
24
|
+
assert_nothing_raised{ @writer = Zlib::GzipWriter.new(@handle) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_constructor_expected_errors
|
28
|
+
assert_raise(ArgumentError){ Zlib::GzipWriter.new }
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_level
|
32
|
+
assert_respond_to(@writer, :level)
|
33
|
+
assert_equal(Z_DEFAULT_COMPRESSION, @writer.level)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_mtime_get_basic
|
37
|
+
assert_respond_to(@writer, :mtime)
|
38
|
+
assert_nothing_raised{ @writer.mtime }
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_mtime_get
|
42
|
+
assert_kind_of(Time, @writer.mtime)
|
43
|
+
assert_equal(Time.at(0), @writer.mtime)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_mtime_set_basic
|
47
|
+
assert_respond_to(@writer, :mtime=)
|
48
|
+
assert_nothing_raised{ @writer.mtime = @time }
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_mtime_set
|
52
|
+
assert_equal(@time, @writer.mtime = @time)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_orig_name_get_basic
|
56
|
+
assert_respond_to(@writer, :orig_name)
|
57
|
+
assert_nothing_raised{ @writer.orig_name }
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_orig_name_get
|
61
|
+
assert_nil(@writer.orig_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_orig_name_set_basic
|
65
|
+
assert_respond_to(@writer, :orig_name=)
|
66
|
+
assert_nothing_raised{ @writer.orig_name = 'test' }
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_orig_name_set
|
70
|
+
assert_equal('test', @writer.orig_name = 'test')
|
71
|
+
assert_equal('test', @writer.orig_name)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_comment_get_basic
|
75
|
+
assert_respond_to(@writer, :comment)
|
76
|
+
assert_nothing_raised{ @writer.comment }
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_comment_get
|
80
|
+
assert_nil(@writer.comment)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_comment_set_basic
|
84
|
+
assert_respond_to(@writer, :comment=)
|
85
|
+
assert_nothing_raised{ @writer.comment = 'test' }
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_comment_set
|
89
|
+
assert_equal('test', @writer.comment = 'test')
|
90
|
+
assert_equal('test', @writer.comment)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_pos_basic
|
94
|
+
assert_respond_to(@writer, :pos)
|
95
|
+
assert_nothing_raised{ @writer.pos }
|
96
|
+
assert_kind_of(Fixnum, @writer.pos)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_pos
|
100
|
+
assert_equal(0, @writer.pos)
|
101
|
+
assert_nothing_raised{ @writer.write('test') }
|
102
|
+
assert_equal(4, @writer.pos)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_tell_alias
|
106
|
+
assert_true(Zlib::GzipWriter.instance_method(:pos) == Zlib::GzipWriter.instance_method(:tell))
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_open_basic
|
110
|
+
assert_respond_to(Zlib::GzipWriter, :open)
|
111
|
+
assert_nothing_raised{ Zlib::GzipWriter.open(@@file){} }
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_flush_basic
|
115
|
+
assert_respond_to(@writer, :flush)
|
116
|
+
assert_nothing_raised{ @writer.flush }
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_flush
|
120
|
+
assert_equal(@writer, @writer.flush)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_write_basic
|
124
|
+
assert_respond_to(@writer, :write)
|
125
|
+
assert_nothing_raised{ @writer.write('test') }
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_write
|
129
|
+
assert_equal(4, @writer.write('test'))
|
130
|
+
assert_equal(3, @writer.write(999))
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_write_expected_errors
|
134
|
+
assert_raise(ArgumentError){ @writer.write }
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_putc_basic
|
138
|
+
assert_respond_to(@writer, :putc)
|
139
|
+
assert_nothing_raised{ @writer.putc(97) }
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_putc
|
143
|
+
assert_equal(97, @writer.putc(97))
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_putc_expected_errors
|
147
|
+
assert_raise(ArgumentError){ @writer.putc }
|
148
|
+
assert_raise(NoMethodError){ @writer.putc('a') }
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_append_basic
|
152
|
+
assert_respond_to(@writer, :<<)
|
153
|
+
assert_nothing_raised{ @writer << 'test' }
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_append_expected_errors
|
157
|
+
assert_raise(ArgumentError){ @writer.send(:<<) }
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_printf_basic
|
161
|
+
assert_respond_to(@writer, :printf)
|
162
|
+
assert_nothing_raised{ @writer.printf('%s', 'test') }
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_printf_expected_errors
|
166
|
+
assert_raise(ArgumentError){ @writer.printf }
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_puts_basic
|
170
|
+
assert_respond_to(@writer, :puts)
|
171
|
+
assert_nothing_raised{ @writer.puts('test') }
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_puts_expected_errors
|
175
|
+
assert_raise(ArgumentError){ @writer.puts }
|
176
|
+
assert_raise(ArgumentError){ @writer.puts('test1', 'test2') }
|
177
|
+
end
|
178
|
+
|
179
|
+
def teardown
|
180
|
+
@handle.close if @handle && !@handle.closed?
|
181
|
+
@handle = nil
|
182
|
+
@time = nil
|
183
|
+
end
|
184
|
+
|
185
|
+
def self.shutdown
|
186
|
+
File.delete(@@file) if File.exists?(@@file)
|
187
|
+
end
|
188
|
+
end
|