summaryrefslogtreecommitdiff
path: root/spec/ruby/library/zlib/inflate
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/zlib/inflate')
-rw-r--r--spec/ruby/library/zlib/inflate/append_spec.rb60
-rw-r--r--spec/ruby/library/zlib/inflate/finish_spec.rb28
-rw-r--r--spec/ruby/library/zlib/inflate/inflate_spec.rb152
-rw-r--r--spec/ruby/library/zlib/inflate/new_spec.rb1
-rw-r--r--spec/ruby/library/zlib/inflate/set_dictionary_spec.rb21
-rw-r--r--spec/ruby/library/zlib/inflate/sync_point_spec.rb1
-rw-r--r--spec/ruby/library/zlib/inflate/sync_spec.rb1
7 files changed, 264 insertions, 0 deletions
diff --git a/spec/ruby/library/zlib/inflate/append_spec.rb b/spec/ruby/library/zlib/inflate/append_spec.rb
new file mode 100644
index 0000000000..a768a766a2
--- /dev/null
+++ b/spec/ruby/library/zlib/inflate/append_spec.rb
@@ -0,0 +1,60 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'zlib'
+
+describe "Zlib::Inflate#<<" do
+ before :all do
+ @foo_deflated = [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*')
+ end
+
+ before :each do
+ @z = Zlib::Inflate.new
+ end
+
+ after :each do
+ @z.close unless @z.closed?
+ end
+
+ it "appends data to the input stream" do
+ @z << @foo_deflated
+ @z.finish.should == 'foo'
+ end
+
+ it "treats nil argument as the end of compressed data" do
+ @z = Zlib::Inflate.new
+ @z << @foo_deflated << nil
+ @z.finish.should == 'foo'
+ end
+
+ it "just passes through the data after nil argument" do
+ @z = Zlib::Inflate.new
+ @z << @foo_deflated << nil
+ @z << "-after_nil_data"
+ @z.finish.should == 'foo-after_nil_data'
+ end
+
+ it "properly handles data in chunks" do
+ # add bytes, one by one
+ @foo_deflated.each_byte { |d| @z << d.chr}
+ @z.finish.should == "foo"
+ end
+
+ it "properly handles incomplete data" do
+ # add bytes, one by one
+ @foo_deflated[0, 5].each_byte { |d| @z << d.chr}
+ lambda { @z.finish }.should raise_error(Zlib::BufError)
+ end
+
+ it "properly handles excessive data, byte-by-byte" do
+ # add bytes, one by one
+ data = @foo_deflated * 2
+ data.each_byte { |d| @z << d.chr}
+ @z.finish.should == "foo" + @foo_deflated
+ end
+
+ it "properly handles excessive data, in one go" do
+ # add bytes, one by one
+ data = @foo_deflated * 2
+ @z << data
+ @z.finish.should == "foo" + @foo_deflated
+ end
+end
diff --git a/spec/ruby/library/zlib/inflate/finish_spec.rb b/spec/ruby/library/zlib/inflate/finish_spec.rb
new file mode 100644
index 0000000000..f6e592fb6b
--- /dev/null
+++ b/spec/ruby/library/zlib/inflate/finish_spec.rb
@@ -0,0 +1,28 @@
+require 'zlib'
+
+describe "Zlib::Inflate#finish" do
+
+ before do
+ @zeros = Zlib::Deflate.deflate("0" * 100_000)
+ @inflator = Zlib::Inflate.new
+ @chunks = []
+
+ @inflator.inflate(@zeros) do |chunk|
+ @chunks << chunk
+ break
+ end
+
+ @inflator.finish do |chunk|
+ @chunks << chunk
+ end
+ end
+
+ it "inflates chunked data" do
+ @chunks.map { |chunk| chunk.length }.should == [16384, 16384, 16384, 16384, 16384, 16384, 1696]
+ end
+
+ it "each chunk should have the same prefix" do
+ @chunks.all? { |chunk| chunk =~ /\A0+\z/ }.should be_true
+ end
+
+end
diff --git a/spec/ruby/library/zlib/inflate/inflate_spec.rb b/spec/ruby/library/zlib/inflate/inflate_spec.rb
new file mode 100644
index 0000000000..1fa16d9e98
--- /dev/null
+++ b/spec/ruby/library/zlib/inflate/inflate_spec.rb
@@ -0,0 +1,152 @@
+require 'zlib'
+require File.expand_path('../../../../spec_helper', __FILE__)
+
+describe "Zlib::Inflate#inflate" do
+
+ before :each do
+ @inflator = Zlib::Inflate.new
+ end
+ it "inflates some data" do
+ data = [120, 156, 99, 96, 128, 1, 0, 0, 10, 0, 1].pack('C*')
+ unzipped = @inflator.inflate data
+ @inflator.finish
+
+ unzipped.should == "\000" * 10
+ end
+
+ it "inflates lots of data" do
+ data = [120, 156, 237, 193, 1, 1, 0, 0] +
+ [0, 128, 144, 254, 175, 238, 8, 10] +
+ Array.new(31, 0) +
+ [24, 128, 0, 0, 1]
+
+ unzipped = @inflator.inflate data.pack('C*')
+ @inflator.finish
+
+ unzipped.should == "\000" * 32 * 1024
+ end
+
+ it "works in pass-through mode, once finished" do
+ data = [120, 156, 99, 96, 128, 1, 0, 0, 10, 0, 1]
+ @inflator.inflate data.pack('C*')
+ @inflator.finish # this is a precondition
+
+ out = @inflator.inflate('uncompressed_data')
+ out << @inflator.finish
+ out.should == 'uncompressed_data'
+
+ @inflator << ('uncompressed_data') << nil
+ @inflator.finish.should == 'uncompressed_data'
+ end
+
+end
+
+describe "Zlib::Inflate.inflate" do
+
+ it "inflates some data" do
+ data = [120, 156, 99, 96, 128, 1, 0, 0, 10, 0, 1]
+ unzipped = Zlib::Inflate.inflate data.pack('C*')
+
+ unzipped.should == "\000" * 10
+ end
+
+ it "inflates lots of data" do
+ data = [120, 156, 237, 193, 1, 1, 0, 0] +
+ [0, 128, 144, 254, 175, 238, 8, 10] +
+ Array.new(31,0) +
+ [24, 128, 0, 0, 1]
+
+ zipped = Zlib::Inflate.inflate data.pack('C*')
+
+ zipped.should == "\000" * 32 * 1024
+ end
+
+ it "properly handles data in chunks" do
+ data = [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*')
+ z = Zlib::Inflate.new
+ # add bytes, one by one
+ result = ""
+ data.each_byte { |d| result << z.inflate(d.chr)}
+ result << z.finish
+ result.should == "foo"
+ end
+
+ it "properly handles incomplete data" do
+ data = [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*')[0,5]
+ z = Zlib::Inflate.new
+ # add bytes, one by one, but not all
+ result = ""
+ data.each_byte { |d| result << z.inflate(d.chr)}
+ lambda { result << z.finish }.should raise_error(Zlib::BufError)
+ end
+
+ it "properly handles excessive data, byte-by-byte" do
+ main_data = [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*')
+ data = main_data * 2
+ result = ""
+
+ z = Zlib::Inflate.new
+ # add bytes, one by one
+ data.each_byte { |d| result << z.inflate(d.chr)}
+ result << z.finish
+
+ # the first chunk is inflated to its completion,
+ # the second chunk is just passed through.
+ result.should == "foo" + main_data
+ end
+
+ it "properly handles excessive data, in one go" do
+ main_data = [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*')
+ data = main_data * 2
+ result = ""
+
+ z = Zlib::Inflate.new
+ result << z.inflate(data)
+ result << z.finish
+
+ # the first chunk is inflated to its completion,
+ # the second chunk is just passed through.
+ result.should == "foo" + main_data
+ end
+end
+
+describe "Zlib::Inflate#inflate" do
+
+ before do
+ @zeros = Zlib::Deflate.deflate("0" * 100_000)
+ @inflator = Zlib::Inflate.new
+ @chunks = []
+ end
+
+ describe "without break" do
+
+ before do
+ @inflator.inflate(@zeros) do |chunk|
+ @chunks << chunk
+ end
+ end
+
+ it "inflates chunked data" do
+ @chunks.map { |chunk| chunk.size }.should == [16384, 16384, 16384, 16384, 16384, 16384, 1696]
+ end
+
+ it "properly handles chunked data" do
+ @chunks.all? { |chunk| chunk =~ /\A0+\z/ }.should be_true
+ end
+ end
+
+ describe "with break" do
+
+ before do
+ @inflator.inflate(@zeros) do |chunk|
+ @chunks << chunk
+ break
+ end
+ end
+
+ it "inflates chunked break" do
+ output = @inflator.inflate nil
+ (100_000 - @chunks.first.length).should == output.length
+ end
+ end
+end
diff --git a/spec/ruby/library/zlib/inflate/new_spec.rb b/spec/ruby/library/zlib/inflate/new_spec.rb
new file mode 100644
index 0000000000..6a4c1dadb4
--- /dev/null
+++ b/spec/ruby/library/zlib/inflate/new_spec.rb
@@ -0,0 +1 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
diff --git a/spec/ruby/library/zlib/inflate/set_dictionary_spec.rb b/spec/ruby/library/zlib/inflate/set_dictionary_spec.rb
new file mode 100644
index 0000000000..890815b8e6
--- /dev/null
+++ b/spec/ruby/library/zlib/inflate/set_dictionary_spec.rb
@@ -0,0 +1,21 @@
+# -*- encoding: binary -*-
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'zlib'
+
+describe "Zlib::Inflate#set_dictionary" do
+ it "sets the inflate dictionary" do
+ deflated = "x\273\024\341\003\313KLJNIMK\317\310\314\002\000\025\206\003\370"
+
+ i = Zlib::Inflate.new
+
+ begin
+ i << deflated
+ flunk 'Zlib::NeedDict not raised'
+ rescue Zlib::NeedDict
+ i.set_dictionary 'aaaaaaaaaa'
+ end
+
+ i.finish.should == 'abcdefghij'
+ end
+end
+
diff --git a/spec/ruby/library/zlib/inflate/sync_point_spec.rb b/spec/ruby/library/zlib/inflate/sync_point_spec.rb
new file mode 100644
index 0000000000..6a4c1dadb4
--- /dev/null
+++ b/spec/ruby/library/zlib/inflate/sync_point_spec.rb
@@ -0,0 +1 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
diff --git a/spec/ruby/library/zlib/inflate/sync_spec.rb b/spec/ruby/library/zlib/inflate/sync_spec.rb
new file mode 100644
index 0000000000..6a4c1dadb4
--- /dev/null
+++ b/spec/ruby/library/zlib/inflate/sync_spec.rb
@@ -0,0 +1 @@
+require File.expand_path('../../../../spec_helper', __FILE__)