pr-zlib 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/pr-zlib.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+
3
+ spec = Gem::Specification.new do |gem|
4
+ gem.name = 'pr-zlib'
5
+ gem.version = '1.0.0'
6
+ gem.authors = ['Park Heesob', 'Daniel Berger']
7
+ gem.email = 'phasis@gmail.com'
8
+ gem.homepage = 'http://www.rubyforge.org/projects/pure'
9
+ gem.rubyforge_project = 'pure'
10
+ gem.platform = Gem::Platform::RUBY
11
+ gem.summary = 'Pure Ruby version of the zlib library'
12
+ gem.test_files = Dir['test/*.rb']
13
+ gem.has_rdoc = true
14
+ gem.files = Dir["**/*"].reject{ |f| f.include?('SVN') }
15
+ gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
16
+
17
+ gem.add_dependency('test-unit', '>= 2.0.2')
18
+
19
+ gem.description = <<-EOF
20
+ The pr-zlib library is a pure Ruby implementation of both the zlib C
21
+ library, and the Ruby zlib interface that ships as part of the standard
22
+ library.
23
+ EOF
24
+ end
25
+
26
+ if $0 == __FILE__
27
+ Gem::Builder.new(spec).build
28
+ end
@@ -0,0 +1,136 @@
1
+ ########################################################################
2
+ # test_rbzlib.rb
3
+ #
4
+ # Test case for the Rbzlib module.
5
+ ########################################################################
6
+ require 'rubygems'
7
+ gem 'test-unit'
8
+
9
+ require 'pr/rbzlib'
10
+ require 'test/unit'
11
+
12
+ class TC_Rbzlib < Test::Unit::TestCase
13
+ include Rbzlib
14
+
15
+ def setup
16
+ @fixnum = 7
17
+ @buffer = 0.chr * 16
18
+ end
19
+
20
+ def test_version
21
+ assert_equal('1.2.3', ZLIB_VERSION)
22
+ end
23
+
24
+ def test_fixnum_ord
25
+ assert_respond_to(7, :ord)
26
+ assert_equal(7, 7.ord)
27
+ end
28
+
29
+ def test_misc_constants
30
+ assert_equal(9, MAX_MEM_LEVEL)
31
+ assert_equal(8, DEF_MEM_LEVEL)
32
+ assert_equal(15, MAX_WBITS)
33
+ assert_equal(MAX_WBITS, DEF_WBITS)
34
+ assert_equal(0, STORED_BLOCK)
35
+ assert_equal(1, STATIC_TREES)
36
+ assert_equal(2, DYN_TREES)
37
+ assert_equal(3, MIN_MATCH)
38
+ assert_equal(258, MAX_MATCH)
39
+ assert_equal(0x20, PRESET_DICT)
40
+ assert_equal(65521, BASE)
41
+ assert_equal(5552, NMAX)
42
+ assert_equal(0, OS_CODE)
43
+ assert_equal(1, SEEK_CUR)
44
+ assert_equal(2, SEEK_END)
45
+ end
46
+
47
+ def test_sync_contants
48
+ assert_equal(0, Z_NO_FLUSH)
49
+ assert_equal(1, Z_PARTIAL_FLUSH)
50
+ assert_equal(2, Z_SYNC_FLUSH)
51
+ assert_equal(3, Z_FULL_FLUSH)
52
+ assert_equal(4, Z_FINISH)
53
+ assert_equal(5, Z_BLOCK)
54
+ end
55
+
56
+ def test_stream_constants
57
+ assert_equal(0, Z_OK)
58
+ assert_equal(1, Z_STREAM_END)
59
+ assert_equal(2, Z_NEED_DICT)
60
+ assert_equal(-1, Z_ERRNO)
61
+ assert_equal(-1, Z_EOF)
62
+ assert_equal(-2, Z_STREAM_ERROR)
63
+ assert_equal(-3, Z_DATA_ERROR)
64
+ assert_equal(-4, Z_MEM_ERROR)
65
+ assert_equal(-5, Z_BUF_ERROR)
66
+ assert_equal(-6, Z_VERSION_ERROR)
67
+ assert_equal(16384, Z_BUFSIZE)
68
+ end
69
+
70
+ def test_compression_constants
71
+ assert_equal(0, Z_NO_COMPRESSION)
72
+ assert_equal(1, Z_BEST_SPEED)
73
+ assert_equal(9, Z_BEST_COMPRESSION)
74
+ assert_equal(-1, Z_DEFAULT_COMPRESSION)
75
+ assert_equal(8, Z_DEFLATED)
76
+ end
77
+
78
+ def test_encoding_constants
79
+ assert_equal(1, Z_FILTERED)
80
+ assert_equal(2, Z_HUFFMAN_ONLY)
81
+ assert_equal(3, Z_RLE)
82
+ assert_equal(4, Z_FIXED)
83
+ assert_equal(0, Z_DEFAULT_STRATEGY)
84
+ end
85
+
86
+ def test_crc_constants
87
+ assert_equal(0x01, ASCII_FLAG)
88
+ assert_equal(0x02, HEAD_CRC)
89
+ assert_equal(0x04, EXTRA_FIELD)
90
+ assert_equal(0x08, ORIG_NAME)
91
+ assert_equal(0x10, COMMENT_)
92
+ assert_equal(0xE0, RESERVED)
93
+ end
94
+
95
+ def test_zError
96
+ assert_respond_to(self, :zError)
97
+ assert_equal('stream end', self.zError(Z_STREAM_END))
98
+ end
99
+
100
+ def test_zlibVersion
101
+ assert_respond_to(self, :zlibVersion)
102
+ assert_equal(ZLIB_VERSION, self.zlibVersion)
103
+ end
104
+
105
+ def test_z_error
106
+ assert_respond_to(self, :z_error)
107
+ assert_raise(RuntimeError){ self.z_error('hello') }
108
+ end
109
+
110
+ def test_adler32
111
+ assert_respond_to(Rbzlib, :adler32)
112
+ assert_equal(1, Rbzlib.adler32(32, nil))
113
+ assert_equal(0, Rbzlib.adler32(0, @buffer))
114
+ assert_equal(1048577, Rbzlib.adler32(1, @buffer))
115
+ assert_equal(10485770, Rbzlib.adler32(10, @buffer))
116
+ assert_equal(33554464, Rbzlib.adler32(32, @buffer))
117
+ end
118
+
119
+ def test_adler32_expected_errors
120
+ assert_raise(ArgumentError){ Rbzlib.adler32 }
121
+ assert_raise(ArgumentError){ Rbzlib.adler32('test') }
122
+ end
123
+
124
+ def test_get_crc_table
125
+ assert_respond_to(Rbzlib, :get_crc_table)
126
+ end
127
+
128
+ def test_gz_open
129
+ assert_respond_to(Rbzlib, :gz_open)
130
+ end
131
+
132
+ def teardown
133
+ @fixnum = 0
134
+ @buffer = nil
135
+ end
136
+ end
@@ -0,0 +1,79 @@
1
+ ########################################################################
2
+ # test_rbzlib_bytef.rb
3
+ #
4
+ # Test case for the Zlib::Bytef class.
5
+ ########################################################################
6
+ require 'rubygems'
7
+ gem 'test-unit'
8
+
9
+ require 'pr/rbzlib'
10
+ require 'test/unit'
11
+
12
+ class TC_Rbzlib_Bytef < Test::Unit::TestCase
13
+ def setup
14
+ @buffer = 0.chr * 32
15
+ @bytef = Rbzlib::Bytef.new(@buffer)
16
+ end
17
+
18
+ def test_buffer_get
19
+ assert_respond_to(@bytef, :buffer)
20
+ assert_equal(@buffer, @bytef.buffer)
21
+ end
22
+
23
+ def test_buffer_set
24
+ assert_respond_to(@bytef, :buffer=)
25
+ assert_nothing_raised{ @bytef.buffer = 0.chr * 8 }
26
+ assert_equal(0.chr * 8, @bytef.buffer)
27
+ end
28
+
29
+ def test_length
30
+ assert_respond_to(@bytef, :length)
31
+ assert_equal(32, @bytef.length)
32
+ end
33
+
34
+ def test_increment
35
+ assert_respond_to(@bytef, :+)
36
+ assert_nothing_raised{ @bytef + 1 }
37
+ assert_equal(1, @bytef.offset)
38
+ end
39
+
40
+ def test_decrement
41
+ assert_respond_to(@bytef, :-)
42
+ assert_nothing_raised{ @bytef - 1 }
43
+ assert_equal(-1, @bytef.offset)
44
+ end
45
+
46
+ def test_aref
47
+ assert_respond_to(@bytef, :[])
48
+ assert_nothing_raised{ @bytef[1] }
49
+ assert_equal(0, @bytef[1])
50
+ end
51
+
52
+ def test_aset
53
+ assert_respond_to(@bytef, :[]=)
54
+ assert_nothing_raised{ @bytef[1] = 1.chr }
55
+ assert_equal(1, @bytef[1])
56
+ end
57
+
58
+ def test_get
59
+ assert_respond_to(@bytef, :get)
60
+ assert_nothing_raised{ @bytef.get }
61
+ assert_equal(0, @bytef.get)
62
+ end
63
+
64
+ def test_set
65
+ assert_respond_to(@bytef, :set)
66
+ assert_nothing_raised{ @bytef.set('a') }
67
+ assert_equal(97, @bytef.get)
68
+ end
69
+
70
+ def test_current
71
+ assert_respond_to(@bytef, :current)
72
+ assert_equal(@buffer, @bytef.current)
73
+ end
74
+
75
+ def teardown
76
+ @bytef = nil
77
+ @buffer = nil
78
+ end
79
+ end
@@ -0,0 +1,59 @@
1
+ ########################################################################
2
+ # test_rbzlib_posf.rb
3
+ #
4
+ # Test case for the Zlib::Posf class.
5
+ ########################################################################
6
+ require 'rubygems'
7
+ gem 'test-unit'
8
+
9
+ require 'pr/rbzlib'
10
+ require 'test/unit'
11
+
12
+ class TC_Rbzlib_Posf < Test::Unit::TestCase
13
+ def setup
14
+ @buffer = 0.chr * 32
15
+ @posf = Rbzlib::Posf.new(@buffer)
16
+ end
17
+
18
+ def test_increment
19
+ assert_respond_to(@posf, :+)
20
+ assert_nothing_raised{ @posf + 4 }
21
+ assert_equal(8, @posf.offset)
22
+ end
23
+
24
+ def test_decrement
25
+ assert_respond_to(@posf, :-)
26
+ assert_nothing_raised{ @posf - 4 }
27
+ assert_equal(-8, @posf.offset)
28
+ end
29
+
30
+ def test_aref
31
+ assert_respond_to(@posf, :[])
32
+ assert_nothing_raised{ @posf[2] }
33
+ assert_equal(0, @posf[2])
34
+ end
35
+
36
+ def test_aset
37
+ assert_respond_to(@posf, :[]=)
38
+ assert_nothing_raised{ @posf[2] = 7 }
39
+ assert_equal(7, @posf[2])
40
+ assert_equal("\a\000", @posf.buffer[4,2])
41
+ end
42
+
43
+ def test_get
44
+ assert_respond_to(@posf, :get)
45
+ assert_nothing_raised{ @posf.get }
46
+ assert_equal(0, @posf.get)
47
+ end
48
+
49
+ def test_set
50
+ assert_respond_to(@posf, :set)
51
+ assert_nothing_raised{ @posf.set(4) }
52
+ assert_equal("\004\000", @posf.buffer[0,2])
53
+ end
54
+
55
+ def teardown
56
+ @posf = nil
57
+ @buffer = nil
58
+ end
59
+ end
data/test/test_zlib.rb ADDED
@@ -0,0 +1,163 @@
1
+ ########################################################################
2
+ # test_zlib.rb
3
+ #
4
+ # Test case for the Zlib module.
5
+ ########################################################################
6
+ require 'rubygems'
7
+ gem 'test-unit'
8
+
9
+ require 'test/unit'
10
+ require 'pr/zlib'
11
+
12
+ class TC_Zlib < Test::Unit::TestCase
13
+ def self.startup
14
+ end
15
+
16
+ def setup
17
+ @zstream_funcs = Zlib::ZStreamFuncs.new
18
+ end
19
+
20
+ def test_ruby_zlib_version
21
+ assert_equal('0.6.0', Zlib::VERSION)
22
+ assert_equal('0.6.0', Zlib::RUBY_ZLIB_VERSION)
23
+ end
24
+
25
+ def test_zlib_version
26
+ assert_equal('1.2.3', Zlib::ZLIB_VERSION)
27
+ assert_equal('1.0.0', Zlib::PR_ZLIB_VERSION)
28
+ end
29
+
30
+ def test_zlib_included_constants
31
+ assert_not_nil(Zlib::BINARY)
32
+ assert_not_nil(Zlib::ASCII)
33
+ assert_not_nil(Zlib::UNKNOWN)
34
+ end
35
+
36
+ def test_zlib_included_compression_constants
37
+ assert_not_nil(Zlib::NO_COMPRESSION)
38
+ assert_not_nil(Zlib::BEST_SPEED)
39
+ assert_not_nil(Zlib::BEST_COMPRESSION)
40
+ assert_not_nil(Zlib::DEFAULT_COMPRESSION)
41
+ end
42
+
43
+ def test_zlib_included_encoding_constants
44
+ assert_not_nil(Zlib::FILTERED)
45
+ assert_not_nil(Zlib::HUFFMAN_ONLY)
46
+ assert_not_nil(Zlib::DEFAULT_STRATEGY)
47
+ assert_not_nil(Zlib::MAX_WBITS)
48
+ assert_not_nil(Zlib::DEF_MEM_LEVEL)
49
+ assert_not_nil(Zlib::MAX_MEM_LEVEL)
50
+ assert_not_nil(Zlib::NO_FLUSH)
51
+ assert_not_nil(Zlib::SYNC_FLUSH)
52
+ assert_not_nil(Zlib::FULL_FLUSH)
53
+ assert_not_nil(Zlib::FINISH)
54
+ end
55
+
56
+ def test_zlib_os_constants
57
+ assert_equal(0x00, Zlib::OS_MSDOS)
58
+ assert_equal(0x01, Zlib::OS_AMIGA)
59
+ assert_equal(0x02, Zlib::OS_VMS)
60
+ assert_equal(0x03, Zlib::OS_UNIX)
61
+ assert_equal(0x05, Zlib::OS_ATARI)
62
+ assert_equal(0x06, Zlib::OS_OS2)
63
+ assert_equal(0x07, Zlib::OS_MACOS)
64
+ assert_equal(0x0a, Zlib::OS_TOPS20)
65
+ assert_equal(0x0b, Zlib::OS_WIN32)
66
+ end
67
+
68
+ def test_zlib_zstream_flag_constants
69
+ assert_equal(0x1, Zlib::ZSTREAM_FLAG_READY)
70
+ assert_equal(0x2, Zlib::ZSTREAM_FLAG_IN_STREAM)
71
+ assert_equal(0x4, Zlib::ZSTREAM_FLAG_FINISHED)
72
+ assert_equal(0x8, Zlib::ZSTREAM_FLAG_CLOSING)
73
+ assert_equal(0x10, Zlib::ZSTREAM_FLAG_UNUSED)
74
+ end
75
+
76
+ def test_zlib_zstream_buffer_constants
77
+ assert_equal(1024, Zlib::ZSTREAM_INITIAL_BUFSIZE)
78
+ assert_equal(16384, Zlib::ZSTREAM_AVAIL_OUT_STEP_MAX)
79
+ assert_equal(2048, Zlib::ZSTREAM_AVAIL_OUT_STEP_MIN)
80
+ end
81
+
82
+ def test_zlib_version_module_function
83
+ assert_respond_to(Zlib, :zlib_version)
84
+ end
85
+
86
+ def test_adler32_module_function_basic
87
+ assert_respond_to(Zlib, :adler32)
88
+ assert_nothing_raised{ Zlib.adler32 }
89
+ end
90
+
91
+ def test_adler32_module_function
92
+ assert_equal(1, Zlib.adler32)
93
+ assert_equal(73204161, Zlib.adler32('test'))
94
+ assert_equal(1, Zlib.adler32(nil, 3))
95
+ assert_equal(73728451, Zlib.adler32('test', 3))
96
+ end
97
+
98
+ def test_crc32_module_function_basic
99
+ assert_respond_to(Zlib, :crc32)
100
+ assert_nothing_raised{ Zlib.crc32 }
101
+ end
102
+
103
+ def test_crc32_module_function
104
+ assert_equal(0, Zlib.crc32)
105
+ assert_equal(3632233996, Zlib.crc32('test'))
106
+ assert_equal(0, Zlib.crc32(nil, 3))
107
+ assert_equal(3402289634, Zlib.crc32('test', 3))
108
+ end
109
+
110
+ def test_crc_table_module_function_basic
111
+ assert_respond_to(Zlib, :crc_table)
112
+ assert_nothing_raised{ Zlib.crc_table }
113
+ assert_kind_of(Array, Zlib.crc_table)
114
+ end
115
+
116
+ def test_zstream_funcs_struct
117
+ assert_kind_of(Zlib::ZStreamFuncs, @zstream_funcs)
118
+ assert_respond_to(@zstream_funcs, :reset)
119
+ assert_respond_to(@zstream_funcs, :end)
120
+ assert_respond_to(@zstream_funcs, :run)
121
+ end
122
+
123
+ def test_error_class
124
+ assert_not_nil(Zlib::Error)
125
+ assert_kind_of(StandardError, Zlib::Error.new)
126
+ end
127
+
128
+ def test_stream_end_class
129
+ assert_not_nil(Zlib::StreamEnd)
130
+ assert_kind_of(Zlib::Error, Zlib::StreamEnd.new)
131
+ end
132
+
133
+ def test_need_dict_class
134
+ assert_kind_of(Zlib::Error, Zlib::NeedDict.new)
135
+ end
136
+
137
+ def test_data_error_class
138
+ assert_kind_of(Zlib::Error, Zlib::DataError.new)
139
+ end
140
+
141
+ def test_stream_error_class
142
+ assert_kind_of(Zlib::Error, Zlib::StreamError.new)
143
+ end
144
+
145
+ def test_mem_error_class
146
+ assert_kind_of(Zlib::Error, Zlib::MemError.new)
147
+ end
148
+
149
+ def test_buf_error_class
150
+ assert_kind_of(Zlib::Error, Zlib::BufError.new)
151
+ end
152
+
153
+ def test_version_error_class
154
+ assert_kind_of(Zlib::Error, Zlib::VersionError.new)
155
+ end
156
+
157
+ def teardown
158
+ @zstream_funcs = nil
159
+ end
160
+
161
+ def self.shutdown
162
+ end
163
+ end