Skip to content

Commit

Permalink
This a pull of Jirapong's commits 24b069c and 2926dd7 for fixing Gzip…
Browse files Browse the repository at this point in the history
…File#finish. My commit is the code review.
  • Loading branch information
Shri Borde committed Apr 2, 2009
1 parent 2926dd7 commit ec7270c
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 68 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Expand Up @@ -5,32 +5,31 @@
describe 'Zlib::GzipFile#close' do
before(:each) do
@io = StringIO.new
@gzip_writer = Zlib::GzipWriter.new @io
end

it 'closes the io' do
Zlib::GzipWriter.wrap @io do |gzio|
gzio.close

gzio.closed?.should == true
end
it 'closes the GzipFile' do
@gzip_writer.close
@gzip_writer.closed?.should be_true
end

it 'calls the close method of the associated IO object' do
Zlib::GzipWriter.wrap @io do |gzio|
gzio.close

@io.closed?.should == true
end
it 'closes the IO object' do
@gzip_writer.close
@io.closed?.should be_true
end

it 'returns the associated IO object' do
Zlib::GzipWriter.wrap @io do |gzio|
gzio.close.should eql(@io)
end
@gzip_writer.close.should eql(@io)
end

after do
@io.close unless @io.closed?
it 'raises Zlib::GzipFile::Error if called multiple times' do
@gzip_writer.close
lambda { @gzip_writer.close }.should raise_error(Zlib::GzipFile::Error)
end

it 'raises Zlib::GzipFile::Error if called after Zlib#finish' do
@gzip_writer.finish
lambda { @gzip_writer.close }.should raise_error(Zlib::GzipFile::Error)
end
end

Expand Up @@ -5,23 +5,42 @@
describe 'Zlib::GzipFile#comment' do
before :each do
@io = StringIO.new
@gzip_writer = Zlib::GzipWriter.new @io
end

it 'is nil by default' do
@gzip_writer.comment.should be_nil
end

it 'returns the name' do
Zlib::GzipWriter.wrap @io do |gzio|
gzio.comment = 'name'
@gzip_writer.comment = 'comment'
@gzip_writer.comment.should == 'comment'
end
end

gzio.comment.should == 'name'
end
describe 'Zlib::GzipFile#comment=' do
before :each do
@io = StringIO.new
@gzip_writer = Zlib::GzipWriter.new @io
end

it 'returns the argument' do
c = 'comment'
(@gzip_writer.comment = c).should equal(c)
end

it 'raises TypeError if argument is nil' do
lambda { @gzip_writer.comment = nil }.should raise_error(TypeError)
end

it 'raises TypeError if argument is not a String' do
m = mock("comment").should_receive(:to_s).any_number_of_times.and_return("comment")
lambda { @gzip_writer.comment = m }.should raise_error(TypeError)
end

it 'raises an error on a closed stream' do
Zlib::GzipWriter.wrap @io do |gzio|
gzio.close

lambda { gzio.comment }.should \
raise_error(Zlib::GzipFile::Error, 'closed gzip stream')
end
@gzip_writer.close
lambda { @gzip_writer.comment = 'comment' }.should raise_error(Zlib::GzipFile::Error)
end
end

Expand Up @@ -5,31 +5,25 @@
describe 'Zlib::GzipFile#finish' do
before(:each) do
@io = StringIO.new
@gzip_writer = Zlib::GzipWriter.new @io
end

it 'closes the io' do
Zlib::GzipWriter.wrap @io do |gzio|
gzio.finish

gzio.closed?.should == true
end
it 'closes the GzipFile' do
@gzip_writer.finish
@gzip_writer.closed?.should be_true
end

it 'never calls the close method of the associated IO object' do
Zlib::GzipWriter.wrap @io do |gzio|
gzio.finish

@io.closed?.should == false
end
it 'does not close the IO object' do
@gzip_writer.finish
@io.closed?.should be_false
end

it 'returns the associated IO object' do
Zlib::GzipWriter.wrap @io do |gzio|
gzio.finish.should eql(@io)
end
@gzip_writer.finish.should eql(@io)
end

after do
@io.close
it 'raises Zlib::GzipFile::Error if called multiple times' do
@gzip_writer.finish
lambda { @gzip_writer.finish }.should raise_error(Zlib::GzipFile::Error)
end
end

This file was deleted.

@@ -1,28 +1,46 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/classes'
require 'stringio'
require 'zlib'

describe 'Zlib::GzipFile#orig_name' do
before :each do
@io = StringIO.new
@gzip_writer = Zlib::GzipWriter.new @io
end

it 'is nil by default' do
@gzip_writer.orig_name.should be_nil
end

it 'returns the name' do
Zlib::GzipWriter.wrap @io do |gzio|
gzio.orig_name = 'name'
@gzip_writer.orig_name = 'name'
@gzip_writer.orig_name.should == 'name'
end
end

gzio.orig_name.should == 'name'
end
describe 'Zlib::GzipFile#orig_name=' do
before :each do
@io = StringIO.new
@gzip_writer = Zlib::GzipWriter.new @io
end

it 'returns the argument' do
n = 'name'
(@gzip_writer.orig_name = n).should equal(n)
end

it 'raises TypeError if argument is nil' do
lambda { @gzip_writer.orig_name = nil }.should raise_error(TypeError)
end

it 'raises TypeError if argument is not a String' do
m = mock("name").should_receive(:to_s).any_number_of_times.and_return("name")
lambda { @gzip_writer.orig_name = m }.should raise_error(TypeError)
end

it 'raises an error on a closed stream' do
Zlib::GzipWriter.wrap @io do |gzio|
gzio.close

lambda { gzio.orig_name }.should \
raise_error(Zlib::GzipFile::Error, 'closed gzip stream')
end
@gzip_writer.close
lambda { @gzip_writer.orig_name = 'name' }.should raise_error(Zlib::GzipFile::Error)
end
end

22 changes: 18 additions & 4 deletions Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Zlib/zlib.cs
Expand Up @@ -636,8 +636,12 @@ public Error(string message)
}
}

internal static void Close(UnaryOpStorage/*!*/ closeStorage, GZipFile/*!*/ self, bool callClose) {
if (callClose && self._ioWrapper.CanBeClosed) {
internal static void Close(UnaryOpStorage/*!*/ closeStorage, GZipFile/*!*/ self, bool closeIO) {
if (self._isClosed) {
throw new Error("closed gzip stream");
}

if (closeIO && self._ioWrapper.CanBeClosed) {
var site = closeStorage.GetCallSite("close");
site.Target(site, self._ioWrapper.UnderlyingObject);
}
Expand Down Expand Up @@ -1101,6 +1105,9 @@ private GzipWriter(RespondToStorage/*!*/ respondToStorage, RubyContext/*!*/ cont

[RubyMethod("close")]
public static object/*!*/ Close(UnaryOpStorage/*!*/ closeStorage, RubyContext/*!*/ context, GzipWriter/*!*/ self) {
if (self._isClosed) {
throw new Error("closed gzip stream");
}
self._gzipStream.Close();
self._ioWrapper.Flush();
GZipFile.Close(closeStorage, self, true);
Expand All @@ -1116,7 +1123,10 @@ private GzipWriter(RespondToStorage/*!*/ respondToStorage, RubyContext/*!*/ cont
}

[RubyMethod("comment=")]
public static MutableString/*!*/ Comment(GzipWriter/*!*/ self, [DefaultProtocol]MutableString comment) {
public static MutableString/*!*/ Comment(GzipWriter/*!*/ self, [NotNull]MutableString/*!*/ comment) {
if (self._isClosed) {
throw new Error("closed gzip stream");
}
self._comment = comment;

return comment;
Expand Down Expand Up @@ -1151,7 +1161,11 @@ private GzipWriter(RespondToStorage/*!*/ respondToStorage, RubyContext/*!*/ cont
// mtime=(p1)

[RubyMethod("orig_name=")]
public static MutableString/*!*/ OriginalName(GzipWriter/*!*/ self, [DefaultProtocol]MutableString originalName) {
public static MutableString/*!*/ OriginalName(GzipWriter/*!*/ self, [NotNull]MutableString/*!*/ originalName) {
if (self._isClosed) {
throw new Error("closed gzip stream");
}

self._originalName = originalName;

return originalName;
Expand Down

1 comment on commit ec7270c

@Jirapong
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, this is make senses to me.

Please sign in to comment.