Commits

Ronald Oussoren  committed fae636d

- Add code to convert NSNumbers created with [NSNumber numberWithBool:] to
Python bool objects (on Python 2.3).
- Enable 'long long' tests in test_methods, and add a testcase with NSPoints.

  • Participants
  • Parent commits be8707c

Comments (0)

Files changed (3)

File pyobjc/Lib/objc/test/test_methods.py

 ULONGLONG_NUMBERS=[0, 44, (1L<<36)+4]
 FLOAT_NUMBERS = [ makeCFloat(0.1), makeCFloat(100.0) ]
 DOUBLE_NUMBERS = [ 1.5, 3.5, 1e10, 1.99e10 ]
+OBJECTS = [ "hello", 1.0, range(4), lambda x: 10 ]
+DUMMY_OBJECTS = [ (0xabcd, 0xfedcba), (1, 1), (-10, -10), (-4, -5), (0, 0), (10, 20) ]
+POINTS=[ (1.0, 2.0), (1e10, 2e10), (-0.5, 0.5) ]
 
 class MyPyClass:
     def __init__(self):
     def reset(self):
         self.idx = 0
 
-    def longFunc(self):
+    def idFunc(self):
         i = self.idx
         self.idx += 1
-        return LONG_NUMBERS[i]
-    longFunc = objc.selector(longFunc, signature='l@:')
-
-    def ulongFunc(self):
-        i = self.idx
-        self.idx += 1
-        return ULONG_NUMBERS[i]
-    ulongFunc = objc.selector(ulongFunc, signature='L@:')
+        return OBJECTS[i]
 
 class MyOCClass (objc.lookUpClass('NSObject')):
     def __init__(self):
         self.idx += 1
         return DOUBLE_NUMBERS[i]
     doubleFunc = objc.selector(doubleFunc, signature='d@:')
-        
+
+    def idFunc(self):
+        i = self.idx
+        self.idx += 1
+        return OBJECTS[i]
+
+    def dummyFunc(self):
+        i = self.idx
+        self.idx += 1
+        return DUMMY_OBJECTS[i]
+    dummyFunc = objc.selector(dummyFunc, signature=OC_TestClass1.dummyFunc.signature)
+
+    def nspointFunc(self):
+        i = self.idx
+        self.idx += 1
+        return POINTS[i]
+    nspointFunc = objc.selector(nspointFunc, signature=OC_TestClass1.nspointFunc.signature)
+
 class OCPyTestSimpleCalls(unittest.TestCase):
     #
     # Test argument passing of single basic values by reference.
         self.ocobj.reset()
 
         for o in LONGLONG_NUMBERS:
-            #self.assertEquals(self.obj.callInstanceLongLongFuncOf_(self.ocobj), o)
-            pass
+            self.assertEquals(self.obj.callInstanceLongLongFuncOf_(self.ocobj), o)
 
     def testILongLong(self):
         self.pyobj.reset()
         self.ocobj.reset()
 
         for o in ULONGLONG_NUMBERS:
-            #self.assertEquals(self.obj.callInstanceUnsignedLongLongFuncOf_(self.ocobj), o)
-            pass
+            self.assertEquals(self.obj.callInstanceUnsignedLongLongFuncOf_(self.ocobj), o)
 
     def testIULongLong(self):
         self.pyobj.reset()
         for o in FLOAT_NUMBERS:
             self.assertEquals(self.obj.callInstanceFloatFuncOf_(self.ocobj), o)
 
+    def testIFloat(self):
+        self.pyobj.reset()
+        self.ocobj.reset()
+
+        for o in FLOAT_NUMBERS:
+            self.assertEquals(self.obj.invokeInstanceFloatFuncOf_(self.ocobj), o)
+
+    def testCDouble(self):
+        self.pyobj.reset()
+        self.ocobj.reset()
+
+        for o in DOUBLE_NUMBERS:
+            self.assertEquals(self.obj.callInstanceDoubleFuncOf_(self.ocobj), o)
+
     def testIDouble(self):
         self.pyobj.reset()
         self.ocobj.reset()
         for o in DOUBLE_NUMBERS:
             self.assertEquals(self.obj.invokeInstanceDoubleFuncOf_(self.ocobj), o)
 
+    def testCId(self):
+        self.pyobj.reset()
+        self.ocobj.reset()
+
+        for o in OBJECTS:
+            self.assertEquals(self.obj.callInstanceIdFuncOf_(self.ocobj), o)
+
+    def testIId(self):
+        self.pyobj.reset()
+        self.ocobj.reset()
+
+        for o in OBJECTS:
+            self.assertEquals(self.obj.invokeInstanceIdFuncOf_(self.ocobj), o)
+
+    def testCId2(self):
+        self.pyobj.reset()
+        self.ocobj.reset()
+
+        for o in OBJECTS:
+            self.assertEquals(self.obj.callInstanceIdFuncOf_(self.pyobj), o)
+
+    def testIId2(self):
+        self.pyobj.reset()
+        self.ocobj.reset()
+
+        for o in OBJECTS:
+            self.assertEquals(self.obj.invokeInstanceIdFuncOf_(self.pyobj), o)
+
+    def testCStruct1(self):
+        self.pyobj.reset()
+        self.ocobj.reset()
+
+        for o in DUMMY_OBJECTS:
+            self.assertEquals(self.obj.callInstanceDummyFuncOf_(self.ocobj), o)
+
+    def testIStruct1(self):
+        self.pyobj.reset()
+        self.ocobj.reset()
+
+        for o in DUMMY_OBJECTS:
+            self.assertEquals(self.obj.invokeInstanceDummyFuncOf_(self.ocobj), o)
+
+    def testCNSPoint(self):
+        self.pyobj.reset()
+        self.ocobj.reset()
+
+        for o in POINTS:
+            self.assertEquals(self.obj.callInstanceNSPointFuncOf_(self.ocobj), o)
+
+    def testINSPoint(self):
+        self.pyobj.reset()
+        self.ocobj.reset()
+
+        for o in POINTS:
+            self.assertEquals(self.obj.invokeInstanceNSPointFuncOf_(self.ocobj), o)
+
 
 def suite():
     suite = unittest.TestSuite()

File pyobjc/Lib/objc/test/testbndl.m

 - (double)doubleFunc;
 - (char*)charpFunc;
 - (id)idFunc;
+- (NSPoint)nspointFunc;
 
 /* returns of complex values */
 - (struct dummy)dummyFunc;
 	}
 }
 
+- (NSPoint)nspointFunc
+{
+	NSPoint p = { 1.0, 2.0 };
+	return p;
+}
+
 - (struct dummy)dummyFunc
 {
 	struct dummy res;
 -(float)callInstanceFloatFuncOf:(OC_TestClass1*)arg;
 -(double)callInstanceDoubleFuncOf:(OC_TestClass1*)arg;
 
+-(id)callInstanceIdFuncOf:(OC_TestClass1*)arg;
+-(struct dummy)callInstanceDummyFuncOf:(OC_TestClass1*)arg;
+-(NSPoint)callInstanceNSPointFuncOf:(OC_TestClass1*)arg;
+
 /* "NSInvocation" calls */
 -(long )invokeInstanceLongFuncOf:(OC_TestClass1*)arg;
 -(unsigned long)invokeInstanceUnsignedLongFuncOf:(OC_TestClass1*)arg;
 -(float)invokeInstanceFloatFuncOf:(OC_TestClass1*)arg;
 -(double)invokeInstanceDoubleFuncOf:(OC_TestClass1*)arg;
 
+-(id)invokeInstanceIdFuncOf:(OC_TestClass1*)arg;
+-(struct dummy)invokeInstanceDummyFuncOf:(OC_TestClass1*)arg;
+-(NSPoint)invokeInstanceNSPointFuncOf:(OC_TestClass1*)arg;
+
 @end
 
 
 	return [arg doubleFunc];
 }
 
+-(id)callInstanceIdFuncOf:(OC_TestClass1*)arg
+{
+	return [arg idFunc];
+}
+
+-(struct dummy)callInstanceDummyFuncOf:(OC_TestClass1*)arg
+{
+	struct dummy x = [arg dummyFunc];
+	printf("%d, %d\n", x.f1, x.f2);
+	return x;
+}
+
+-(NSPoint)callInstanceNSPointFuncOf:(OC_TestClass1*)arg
+{
+	return [arg nspointFunc];
+}
+
 
 -(long long)invokeInstanceLongLongFuncOf:(OC_TestClass1*)arg
 {
 	return res;
 }
 
+-(id)invokeInstanceIdFuncOf:(OC_TestClass1*)arg
+{
+	id res;
+	NSInvocation* inv;
+
+	SETUP_INVOCATION(inv, arg, @selector(idFunc))
+	
+	[arg forwardInvocation:inv];
+	[inv getReturnValue:&res];
+	return res;
+}
+
+-(struct dummy)invokeInstanceDummyFuncOf:(OC_TestClass1*)arg
+{
+	struct dummy res;
+	NSInvocation* inv;
+
+	SETUP_INVOCATION(inv, arg, @selector(dummyFunc))
+	
+	[arg forwardInvocation:inv];
+	[inv getReturnValue:&res];
+	return res;
+}
+
+-(NSPoint)invokeInstanceNSPointFuncOf:(OC_TestClass1*)arg
+{
+	NSPoint res;
+	NSInvocation* inv;
+
+	SETUP_INVOCATION(inv, arg, @selector(nspointFunc))
+	
+	[arg forwardInvocation:inv];
+	[inv getReturnValue:&res];
+	return res;
+}
+
 @end
 
 

File pyobjc/Modules/objc/objc_support.m

 #import <Foundation/NSData.h> 
 #import <Foundation/NSValue.h> 
 
+#ifdef MACOSX
+#include <CoreFoundation/CFNumber.h>
+#endif
+
 
 /*
  * Category on NSObject to make sure that every object supports 
 	char        buf[objc_sizeof_type(typestr)];
 
 	[self getValue:buf];
+
+#ifdef MACOSX
+	/* NSNumber seems to be toll-free bridged to CFNumber,
+	 * this check allows us to return the proper python objects
+	 * for boolean True and False values.
+	 */
+	if (kCFBooleanTrue == (CFBooleanRef)self) {
+		return PyBool_FromLong(1);
+	} else if (kCFBooleanFalse == (CFBooleanRef)self) {
+		return PyBool_FromLong(0);
+	}
+#endif
 	return pythonify_c_value(typestr, buf);
 }