Commits

Ronald Oussoren  committed 6bb9b46

Port uncommitted test change from the 2.5 branch.

  • Participants
  • Parent commits 9a1466d

Comments (0)

Files changed (2)

File pyobjc-core/Modules/objc/test/block.m

 
 #import <Foundation/Foundation.h>
 
+#if (PyObjC_BUILD_RELEASE >= 1006) && (__GNUC__ >= 4 && __GNUC_MINOR__ >= 2)
+@interface NSObject (IndirectBlockTest)
+-(double)processBlock:(double(^)(double, double))aBlock;
+@end
+#endif
+
 @interface OCTestBlock : NSObject {}
 
 #if (PyObjC_BUILD_RELEASE >= 1006) && (__GNUC__ >= 4 && __GNUC_MINOR__ >= 2)
     return block(a, b, c, d);
 }
 
+-(double)callProcessBlockOn:(NSObject*)testObject
+{
+    return [testObject processBlock:^(double a, double b) { return a*b; }];
+}
+
 #endif
 
 @end

File pyobjc-core/PyObjCTest/test_blocks.py

           </arg>
         </method>
       </class>
+      <class name='NSObject'>
+        <method selector='processBlock:'>
+          <retval type='d' />
+          <arg index='0' block='true' type='@?'>
+            <retval type='d'/>
+            <arg type='d' />
+            <arg type='d' />
+          </arg>
+        </method>
+      </class>
     </signatures>
     ''' % dict(NSRect_tp=NSRect_tp if sys.version_info[0] == 2 else NSRect_tp.decode('ascii')),
     globals(), 'PyObjCTest')
     blocksEnabled = False
 del v
 
+class BlocksHelper (objc.lookUpClass('NSObject')):
+    def processBlock_(self, block):
+        return -block(2.5, 4.0)
+
+
+
 class TestBlocks (TestCase):
     @min_os_level('10.6')
     @onlyIf(blocksEnabled, "no blocks")
         sig = objc.splitSignature(objc._block_signature(block))
         self.assertEqual(sig,  (NSRect_tp, objc._C_ID + b'?', objc._C_DBL, objc._C_DBL, objc._C_DBL, objc._C_DBL))
 
-
+    @min_os_level('10.6')
+    @onlyIf(blocksEnabled, "no blocks")
+    def testBlockArgumentToPython(self):
+        obj = OCTestBlock.alloc().init()
+        helper = BlocksHelper.alloc().init()
+        value = obj.callProcessBlockOn_(helper)
+        self.assertEqual(value, -(2.5 * 4.0))
 
 if __name__ == "__main__":
     main()