[macruby-changes] [3223] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Jan 8 17:32:10 PST 2010


Revision: 3223
          http://trac.macosforge.org/projects/ruby/changeset/3223
Author:   ernest.prabhakar at gmail.com
Date:     2010-01-08 17:32:07 -0800 (Fri, 08 Jan 2010)
Log Message:
-----------
Now pass all Dispatch::Source specs for ADD and OR

Modified Paths:
--------------
    MacRuby/trunk/gcd.c
    MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb

Modified: MacRuby/trunk/gcd.c
===================================================================
--- MacRuby/trunk/gcd.c	2010-01-09 00:54:17 UTC (rev 3222)
+++ MacRuby/trunk/gcd.c	2010-01-09 01:32:07 UTC (rev 3223)
@@ -892,7 +892,7 @@
 static VALUE
 rb_source_get_data(VALUE self, SEL sel)
 {
-    return LONG2NUM(dispatch_source_get_mask(RSource(self)->source));
+    return LONG2NUM(dispatch_source_get_data(RSource(self)->source));
 }
 
 /* 
@@ -1252,7 +1252,7 @@
     rb_objc_define_method(cSource, "handle", rb_source_get_handle, 0);
     rb_objc_define_method(cSource, "mask", rb_source_get_mask, 0);
     rb_objc_define_method(cSource, "data", rb_source_get_data, 0);
-    rb_objc_define_method(cSource, "merge", rb_source_merge, 1);
+    rb_objc_define_method(cSource, "<<", rb_source_merge, 1);
 
     cTimer = rb_define_class_under(mDispatch, "Timer", cSource);
     rb_objc_define_method(cTimer, "initialize", rb_timer_init, -1);

Modified: MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb	2010-01-09 00:54:17 UTC (rev 3222)
+++ MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb	2010-01-09 01:32:07 UTC (rev 3223)
@@ -42,10 +42,57 @@
         end
 
         it "returns an instance of Dispatch::Source" do
-          src = Dispatch::Source.new(@type, 0, 0, @q) { true.should == true }
+          src = Dispatch::Source.new(@type, 0, 0, @q) { }
           src.should be_kind_of(Dispatch::Source)
         end
+        
+        it "should not be suspended" do
+          src = Dispatch::Source.new(@type, 0, 0, @q) { }
+          src.suspended?.should == false
+        end
+    
+        it "fires event handler on merge" do
+          @i = 0
+          src = Dispatch::Source.new(@type, 0, 0, @q) {|s|  @i = 42}
+          src << 42
+          @q.sync { }
+          @i.should == 42
+        end        
+
+        it "passes source to event handler" do
+          src = Dispatch::Source.new(@type, 0, 0, @q) do |source|
+            source.should be_kind_of(Dispatch::Source)
+          end
+          src << 42
+          @q.sync { }
+        end        
+
+        it "passes data to source in event handler" do
+          @i = 0
+          src = Dispatch::Source.new(@type, 0, 0, @q) do |source|
+            @i = source.data
+          end
+          src << 42
+          @q.sync { }
+          @i.should == 42
+        end        
+
+
+        it "coalesces data for source in event handler" do
+          @i = 0
+          src = Dispatch::Source.new(@type, 0, 0, @q) do |source|
+            @i = source.data
+          end
+          src.suspend!
+          src << 17
+          src << 25
+          src.resume!
+          @q.sync { }
+          @i.should == 42
+        end        
+
       end
+      
 
       describe :DATA_OR do
         before :each do
@@ -53,11 +100,45 @@
         end
 
         it "returns an instance of Dispatch::Source" do
-          src = Dispatch::Source.new(@type, 0, 0, @q) { true.should == true }
+          src = Dispatch::Source.new(@type, 0, 0, @q) { }
           src.should be_kind_of(Dispatch::Source)
         end
+        
+        it "should not be suspended" do
+          src = Dispatch::Source.new(@type, 0, 0, @q) { }
+          src.suspended?.should == false
+        end
+        
+
+        it "fires event handler on merge" do
+          @i = 0
+          src = Dispatch::Source.new(@type, 0, 0, @q) {|s|  @i = 42}
+          src << 42
+          @q.sync { }
+          @i.should == 42
+        end        
+
+        it "passes source to event handler" do
+          src = Dispatch::Source.new(@type, 0, 0, @q) do |source|
+            source.should be_kind_of(Dispatch::Source)
+          end
+          src << 42
+          @q.sync { }
+        end
+        
+        it "coalesces data for source in event handler" do
+          @i = 0
+          src = Dispatch::Source.new(@type, 0, 0, @q) do |source|
+            @i = source.data
+          end
+          src.suspend!
+          src << 0b000_010
+          src << 0b101_000
+          src.resume!
+          @q.sync { }
+          @i.should == 42 #0b101_010
+        end        
       end
-
     end
     
   end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100108/9822dc29/attachment.html>


More information about the macruby-changes mailing list