[macruby-changes] [4883] MacRuby/trunk/spec/macruby

source_changes at macosforge.org source_changes at macosforge.org
Thu Nov 4 19:07:21 PDT 2010


Revision: 4883
          http://trac.macosforge.org/projects/ruby/changeset/4883
Author:   lsansonetti at apple.com
Date:     2010-11-04 19:07:19 -0700 (Thu, 04 Nov 2010)
Log Message:
-----------
add tests for the new C array support

Modified Paths:
--------------
    MacRuby/trunk/spec/macruby/fixtures/method.m
    MacRuby/trunk/spec/macruby/fixtures/method.rb
    MacRuby/trunk/spec/macruby/language/objc_method_spec.rb

Modified: MacRuby/trunk/spec/macruby/fixtures/method.m
===================================================================
--- MacRuby/trunk/spec/macruby/fixtures/method.m	2010-11-05 02:06:13 UTC (rev 4882)
+++ MacRuby/trunk/spec/macruby/fixtures/method.m	2010-11-05 02:07:19 UTC (rev 4883)
@@ -385,6 +385,29 @@
     return NSEqualRanges([o methodReturningNSRange], NSMakeRange(0, 42));
 }
 
+#if 0
+// Apparently the current objc compiler doesn't like methods returning arrays.
+- (int[10])methodReturningAry
+{
+    int i, buf[10];
+    for (i = 0; i < 10; i++) {
+	buf[i] = i + 100;
+    }
+    return buf;
+}
+
++ (BOOL)testMethodReturningAry:(TestMethod *)o
+{
+    int i, buf[10] = [o methodReturningAry];
+    for (i = 0; i < 10; o++) {
+	if (buf[i] != i + 100) {
+	    return NO;
+	}
+    }
+    return YES;
+}
+#endif
+
 - (BOOL)methodAcceptingSelf:(id)obj
 {
     return obj == self;
@@ -720,6 +743,26 @@
     return ptr == NULL;
 }
 
+- (BOOL)methodAcceptingAry:(int[10])ary
+{
+    int i;
+    for (i = 0; i < 10; i++) {
+	if (ary[i] != i + 100) {
+	    return NO;
+	}
+    }
+    return YES;
+}
+
++ (BOOL)testMethodAcceptingAry:(TestMethod *)o
+{
+    int i, ary[10];
+    for (i = 0; i < 10; i++) {
+	ary[i] = i + 100;
+    }    
+    return [o methodAcceptingAry:ary];
+}
+
 typedef struct {
     CGFloat f1;
     CGFloat f2;

Modified: MacRuby/trunk/spec/macruby/fixtures/method.rb
===================================================================
--- MacRuby/trunk/spec/macruby/fixtures/method.rb	2010-11-05 02:06:13 UTC (rev 4882)
+++ MacRuby/trunk/spec/macruby/fixtures/method.rb	2010-11-05 02:07:19 UTC (rev 4883)
@@ -59,6 +59,7 @@
   def methodAcceptingObjPtr2(a); super; end
   def methodAcceptingInt(a, float:a2, double:a3, short:a4, NSPoint:a5,
                          NSRect:a6, char:a7); super; end
+  def methodAcceptingAry(a); super; end
 end
 
 class TestInformalProtocolMethod

Modified: MacRuby/trunk/spec/macruby/language/objc_method_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/language/objc_method_spec.rb	2010-11-05 02:06:13 UTC (rev 4882)
+++ MacRuby/trunk/spec/macruby/language/objc_method_spec.rb	2010-11-05 02:07:19 UTC (rev 4883)
@@ -443,6 +443,30 @@
     lambda { @o.methodAcceptingAnonymousStructure(NSRange.new(42, 4200)) }.should raise_error(TypeError)
   end
 
+  it "accepting C arrays should be given an Array" do
+    a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+    @o.methodAcceptingAry(a).should == 0
+    a.map! { |x| 100 + x }
+    @o.methodAcceptingAry(a).should == 1
+    a[0] = 42
+    @o.methodAcceptingAry(a).should == 0
+
+    a[0] = 'booh'
+    lambda { @o.methodAcceptingAry(a) }.should raise_error(ArgumentError)
+
+    lambda { @o.methodAcceptingAry([1, 2, 3]) }.should raise_error(ArgumentError)
+    lambda { @o.methodAcceptingAry([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) }.should raise_error(ArgumentError)
+    lambda { @o.methodAcceptingAry(nil) }.should raise_error(TypeError)
+    lambda { @o.methodAcceptingAry(42) }.should raise_error(TypeError)
+    lambda { @o.methodAcceptingAry("foo") }.should raise_error(TypeError)
+
+    o = Object.new
+    def o.to_ary
+      [100, 101, 102, 103, 104, 105, 106, 107, 108, 109]
+    end
+    @o.methodAcceptingAry(o).should == 1
+  end
+
   it "can be retrieved as a Method object" do
     o = NSString.method(:hash)
     o.class.should == Method
@@ -687,6 +711,11 @@
     @o.methodAcceptingInt(42, float:42, double:42, short:42, NSPoint:NSPoint.new(42, 42), NSRect:NSRect.new(NSPoint.new(42, 42), NSSize.new(42, 42)), char:42).should == 1
     TestMethodOverride.testMethodAcceptingComplexTypes(@o).should == 1
   end
+
+  it "can overwrite an Objective-C method accepting a C array" do
+    @o.methodAcceptingAry([100, 101, 102, 103, 104, 105, 106, 107, 108, 109]).should == 1
+    TestMethodOverride.testMethodAcceptingAry(@o).should == 1
+  end
 end
 
 describe "A pure MacRuby method" do
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101104/90548bdc/attachment.html>


More information about the macruby-changes mailing list