[macruby-changes] [3252] MacRuby/trunk/spec/macruby
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jan 11 17:33:09 PST 2010
Revision: 3252
http://trac.macosforge.org/projects/ruby/changeset/3252
Author: ernest.prabhakar at gmail.com
Date: 2010-01-11 17:33:08 -0800 (Mon, 11 Jan 2010)
Log Message:
-----------
Added cancel handler and :READ spec for Dispatch::Source
Modified Paths:
--------------
MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb
MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/source_tags.txt
Modified: MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb 2010-01-12 01:33:06 UTC (rev 3251)
+++ MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb 2010-01-12 01:33:08 UTC (rev 3252)
@@ -85,7 +85,6 @@
src << 42
@q.sync { }
@flag.should == true
-
end
it "passes data to source in event handler" do
@@ -111,6 +110,14 @@
@i.should == 42
end
+ it "runs cancel handler when cancelled" do
+ @i = 0
+ src = Dispatch::Source.new(@type, 0, 0, @q) {|s| @i = 21}
+ src.on_cancel { @i = 42 }
+ src.cancel!
+ @q.sync { }
+ @i.should == 42
+ end
end
describe :DATA_OR do
@@ -159,7 +166,7 @@
src.suspended?.should == false
end
- it "fires with event mask on process event" do
+ it "fires on process event with event mask data" do
@i = 0
src = Dispatch::Source.new(@type, $$, @mask, @q) { |s| @i = s.data }
Signal.trap(@signal, "IGNORE")
@@ -182,7 +189,7 @@
src.should be_kind_of(Dispatch::Source)
end
- it "fires with signal count on signal" do
+ it "fires on signal with signal count data" do
@i = 0
src = Dispatch::Source.new(@type, @signal, 0, @q) { |s| @i = s.data }
Signal.trap(@signal, "IGNORE")
@@ -192,43 +199,75 @@
@i.should == 1
src.cancel!
end
- end
-
- describe :READ do
+ end
+
+ describe "file:" do
before :each do
- @type = Dispatch::Source::READ
+ @filename = "/var/tmp/gcd_spec_source-#{$$}"
+ @msg = "#{$$}: #{Time.now}"
end
+
+ describe :READ do
+ before :each do
+ @type = Dispatch::Source::READ
+ end
- it "returns an instance of Dispatch::Source" do
- src = Dispatch::Source.new(@type, 0, 0, @q) { }
- src.should be_kind_of(Dispatch::Source)
- end
- end
+ it "returns an instance of Dispatch::Source" do
+ src = Dispatch::Source.new(@type, $stdin.to_i, 0, @q) { }
+ src.should be_kind_of(Dispatch::Source)
+ end
+
+ it "fires with data on estimate of readable bytes" do
+ @result = ""
+ File.delete(@filename) if File.exist?(@filename)
+ File.open(@filename, "w") {|f| f.puts @msg}
+ file = File.open(@filename, "r")
+ src = Dispatch::Source.new(@type, file.to_i, 0, @q) do |s|
+ begin
+ puts "Reading #{s.data} bytes"
+ @result << file.read_nonblock(s.data-1)
+ puts "#{@result}: #{s.data}"
+ rescue Exception => error
+ puts "OOPS!: #{error}"
+ src.cancel!
+ end
+ end
+ src.on_cancel { file.close } #is this a race condition?
+ while (@result.size < @msg.size) do; end
+ @q.sync { }
+ @result.should == @msg
+ end
+ end
+ describe :WRITE do
+ before :each do
+ @type = Dispatch::Source::WRITE
+ end
- describe :WRITE do
- before :each do
- @type = Dispatch::Source::WRITE
- end
+ it "returns an instance of Dispatch::Source" do
+ src = Dispatch::Source.new(@type, $stdout.to_i, 0, @q) { }
+ src.should be_kind_of(Dispatch::Source)
+ end
+ end
- it "returns an instance of Dispatch::Source" do
- src = Dispatch::Source.new(@type, 0, 0, @q) { }
- src.should be_kind_of(Dispatch::Source)
- end
- end
+ describe :VNODE do
+ before :each do
+ @type = Dispatch::Source::VNODE
+ @mask = Dispatch::Source::VNODE_WRITE
+ end
- describe :VNODE do
- before :each do
- @type = Dispatch::Source::VNODE
+ it "returns an instance of Dispatch::Source" do
+ src = Dispatch::Source.new(@type, $stdout.to_i, @mask, @q) { }
+ src.should be_kind_of(Dispatch::Source)
+ end
end
-
- it "returns an instance of Dispatch::Source" do
- src = Dispatch::Source.new(@type, 0, 0, @q) { }
- src.should be_kind_of(Dispatch::Source)
- end
- end
-
+
+ end
end
+
+ end
+
+ describe "Dispatch::Timer" do
+ end
- end
end
Modified: MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/source_tags.txt
===================================================================
--- MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/source_tags.txt 2010-01-12 01:33:06 UTC (rev 3251)
+++ MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/source_tags.txt 2010-01-12 01:33:08 UTC (rev 3252)
@@ -0,0 +1 @@
+fails:Dispatch::Source of type file: READ fires with data on estimate of readable bytes
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100111/dc0e0112/attachment.html>
More information about the macruby-changes
mailing list